blob: 1e95637ca6ac5c66bbdb90299550301c8bac6037 [file] [log] [blame]
Elliott Hughes7ede61e2011-09-14 18:18:06 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "class_linker.h"
18#include "jni_internal.h"
19#include "object.h"
20#include "thread.h"
21
22#include "JniConstants.h" // Last to avoid problems with LOG redefinition.
23#include "toStringArray.h"
24
25#include <limits.h>
26
27namespace art {
28
29namespace {
30
31jfloat VMRuntime_getTargetHeapUtilization(JNIEnv*, jobject) {
32 return Heap::GetTargetHeapUtilization();
33}
34
35void VMRuntime_nativeSetTargetHeapUtilization(JNIEnv*, jobject, jfloat target) {
36 Heap::SetTargetHeapUtilization(target);
37}
38
39void VMRuntime_startJitCompilation(JNIEnv*, jobject) {
40}
41
42void VMRuntime_disableJitCompilation(JNIEnv*, jobject) {
43}
44
45jobject VMRuntime_newNonMovableArray(JNIEnv* env, jobject, jclass javaElementClass, jint length) {
46#ifdef MOVING_GARBAGE_COLLECTOR
47 // TODO: right now, we don't have a copying collector, so there's no need
48 // to do anything special here, but we ought to pass the non-movability
49 // through to the allocator.
50 UNIMPLEMENTED(FATAL);
51#endif
52
53 Class* element_class = Decode<Class*>(env, javaElementClass);
54 if (element_class == NULL) {
55 Thread::Current()->ThrowNewException("Ljava/lang/NullPointerException;", "element class == null");
56 return NULL;
57 }
58 if (length < 0) {
59 Thread::Current()->ThrowNewException("Ljava/lang/NegativeArraySizeException;", "%d", length);
60 return NULL;
61 }
62
63 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
64 std::string descriptor;
65 descriptor += "[";
66 descriptor += element_class->GetDescriptor()->ToModifiedUtf8();
67 Class* array_class = class_linker->FindClass(descriptor, NULL);
68 Array* result = Array::Alloc(array_class, length);
69 if (result == NULL) {
70 return NULL;
71 }
72 return AddLocalReference<jobject>(env, result);
73}
74
75jlong VMRuntime_addressOf(JNIEnv* env, jobject, jobject javaArray) {
76 Array* array = Decode<Array*>(env, javaArray);
77 if (!array->IsArrayInstance()) {
78 Thread::Current()->ThrowNewException("Ljava/lang/IllegalArgumentException;", "not an array");
79 return 0;
80 }
81 // TODO: we should also check that this is a non-movable array.
82 return reinterpret_cast<uintptr_t>(array->GetRawData());
83}
84
85void VMRuntime_clearGrowthLimit(JNIEnv*, jobject) {
86 Heap::ClearGrowthLimit();
87}
88
89jboolean VMRuntime_isDebuggerActive(JNIEnv*, jobject) {
90 // TODO: debugger!
91 return false;
92}
93
94jobjectArray VMRuntime_properties(JNIEnv* env, jobject) {
95 return toStringArray(env, Runtime::Current()->GetProperties());
96}
97
98jstring VMRuntime_bootClassPath(JNIEnv* env, jobject) {
99 return env->NewStringUTF(Runtime::Current()->GetBootClassPath().c_str());
100}
101
102jstring VMRuntime_classPath(JNIEnv* env, jobject) {
103 return env->NewStringUTF(Runtime::Current()->GetClassPath().c_str());
104}
105
106jstring VMRuntime_vmVersion(JNIEnv* env, jobject) {
107 return env->NewStringUTF(Runtime::Current()->GetVersion());
108}
109
110void VMRuntime_setTargetSdkVersion(JNIEnv* env, jobject, jint targetSdkVersion) {
111 // This is the target SDK version of the app we're about to run.
112 // Note that this value may be CUR_DEVELOPMENT (10000).
113 // Note that this value may be 0, meaning "current".
114 if (targetSdkVersion > 0 && targetSdkVersion <= 13 /* honeycomb-mr2 */) {
115 // TODO: running with CheckJNI should override this and force you to obey the strictest rules.
116 LOG(INFO) << "Turning on JNI app bug workarounds for target SDK version " << targetSdkVersion << "...";
117 UNIMPLEMENTED(FATAL) << "can we get this as a command-line argument?";
118 //gDvmJni.work_around_app_jni_bugs = true;
119 }
120}
121
122JNINativeMethod gMethods[] = {
123 NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"),
124 NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"),
125 NATIVE_METHOD(VMRuntime, classPath, "()Ljava/lang/String;"),
126 NATIVE_METHOD(VMRuntime, clearGrowthLimit, "()V"),
127 NATIVE_METHOD(VMRuntime, disableJitCompilation, "()V"),
128 NATIVE_METHOD(VMRuntime, getTargetHeapUtilization, "()F"),
129 NATIVE_METHOD(VMRuntime, isDebuggerActive, "()Z"),
130 NATIVE_METHOD(VMRuntime, nativeSetTargetHeapUtilization, "(F)V"),
131 NATIVE_METHOD(VMRuntime, newNonMovableArray, "(Ljava/lang/Class;I)Ljava/lang/Object;"),
132 NATIVE_METHOD(VMRuntime, properties, "()[Ljava/lang/String;"),
133 NATIVE_METHOD(VMRuntime, setTargetSdkVersion, "(I)V"),
134 NATIVE_METHOD(VMRuntime, startJitCompilation, "()V"),
135 NATIVE_METHOD(VMRuntime, vmVersion, "()Ljava/lang/String;"),
136};
137
138} // namespace
139
140void register_dalvik_system_VMRuntime(JNIEnv* env) {
141 jniRegisterNativeMethods(env, "dalvik/system/VMRuntime", gMethods, NELEM(gMethods));
142}
143
144} // namespace art