blob: f8be88166d2e1a6706c91db55551afb7e0b5f5ba [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"
Elliott Hughesf6a1e1e2011-10-25 16:28:04 -070018#include "debugger.h"
Elliott Hughes7ede61e2011-09-14 18:18:06 -070019#include "jni_internal.h"
20#include "object.h"
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080021#include "object_utils.h"
Elliott Hughes7ede61e2011-09-14 18:18:06 -070022#include "thread.h"
23
24#include "JniConstants.h" // Last to avoid problems with LOG redefinition.
25#include "toStringArray.h"
26
27#include <limits.h>
28
29namespace art {
30
31namespace {
32
33jfloat VMRuntime_getTargetHeapUtilization(JNIEnv*, jobject) {
34 return Heap::GetTargetHeapUtilization();
35}
36
37void VMRuntime_nativeSetTargetHeapUtilization(JNIEnv*, jobject, jfloat target) {
38 Heap::SetTargetHeapUtilization(target);
39}
40
41void VMRuntime_startJitCompilation(JNIEnv*, jobject) {
42}
43
44void VMRuntime_disableJitCompilation(JNIEnv*, jobject) {
45}
46
47jobject VMRuntime_newNonMovableArray(JNIEnv* env, jobject, jclass javaElementClass, jint length) {
Brian Carlstromb82b6872011-10-26 17:18:07 -070048 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Elliott Hughes7ede61e2011-09-14 18:18:06 -070049#ifdef MOVING_GARBAGE_COLLECTOR
50 // TODO: right now, we don't have a copying collector, so there's no need
51 // to do anything special here, but we ought to pass the non-movability
52 // through to the allocator.
53 UNIMPLEMENTED(FATAL);
54#endif
55
56 Class* element_class = Decode<Class*>(env, javaElementClass);
57 if (element_class == NULL) {
58 Thread::Current()->ThrowNewException("Ljava/lang/NullPointerException;", "element class == null");
59 return NULL;
60 }
61 if (length < 0) {
Elliott Hughes5cb5ad22011-10-02 12:13:39 -070062 Thread::Current()->ThrowNewExceptionF("Ljava/lang/NegativeArraySizeException;", "%d", length);
Elliott Hughes7ede61e2011-09-14 18:18:06 -070063 return NULL;
64 }
65
66 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
67 std::string descriptor;
68 descriptor += "[";
Ian Rogers6d4d9fc2011-11-30 16:24:48 -080069 descriptor += ClassHelper(element_class).GetDescriptor();
Elliott Hughes7ede61e2011-09-14 18:18:06 -070070 Class* array_class = class_linker->FindClass(descriptor, NULL);
71 Array* result = Array::Alloc(array_class, length);
72 if (result == NULL) {
73 return NULL;
74 }
75 return AddLocalReference<jobject>(env, result);
76}
77
78jlong VMRuntime_addressOf(JNIEnv* env, jobject, jobject javaArray) {
Brian Carlstromb82b6872011-10-26 17:18:07 -070079 ScopedThreadStateChange tsc(Thread::Current(), Thread::kRunnable);
Elliott Hughes7ede61e2011-09-14 18:18:06 -070080 Array* array = Decode<Array*>(env, javaArray);
81 if (!array->IsArrayInstance()) {
82 Thread::Current()->ThrowNewException("Ljava/lang/IllegalArgumentException;", "not an array");
83 return 0;
84 }
85 // TODO: we should also check that this is a non-movable array.
86 return reinterpret_cast<uintptr_t>(array->GetRawData());
87}
88
89void VMRuntime_clearGrowthLimit(JNIEnv*, jobject) {
90 Heap::ClearGrowthLimit();
91}
92
93jboolean VMRuntime_isDebuggerActive(JNIEnv*, jobject) {
Elliott Hughesf6a1e1e2011-10-25 16:28:04 -070094 return Dbg::IsDebuggerConnected();
Elliott Hughes7ede61e2011-09-14 18:18:06 -070095}
96
97jobjectArray VMRuntime_properties(JNIEnv* env, jobject) {
98 return toStringArray(env, Runtime::Current()->GetProperties());
99}
100
101jstring VMRuntime_bootClassPath(JNIEnv* env, jobject) {
102 return env->NewStringUTF(Runtime::Current()->GetBootClassPath().c_str());
103}
104
105jstring VMRuntime_classPath(JNIEnv* env, jobject) {
106 return env->NewStringUTF(Runtime::Current()->GetClassPath().c_str());
107}
108
109jstring VMRuntime_vmVersion(JNIEnv* env, jobject) {
110 return env->NewStringUTF(Runtime::Current()->GetVersion());
111}
112
113void VMRuntime_setTargetSdkVersion(JNIEnv* env, jobject, jint targetSdkVersion) {
114 // This is the target SDK version of the app we're about to run.
115 // Note that this value may be CUR_DEVELOPMENT (10000).
116 // Note that this value may be 0, meaning "current".
117 if (targetSdkVersion > 0 && targetSdkVersion <= 13 /* honeycomb-mr2 */) {
118 // TODO: running with CheckJNI should override this and force you to obey the strictest rules.
119 LOG(INFO) << "Turning on JNI app bug workarounds for target SDK version " << targetSdkVersion << "...";
Brian Carlstrom6a4be3a2011-10-20 16:34:03 -0700120 UNIMPLEMENTED(WARNING) << "can we get this as a command-line argument?";
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700121 //gDvmJni.work_around_app_jni_bugs = true;
122 }
123}
124
125JNINativeMethod gMethods[] = {
126 NATIVE_METHOD(VMRuntime, addressOf, "(Ljava/lang/Object;)J"),
127 NATIVE_METHOD(VMRuntime, bootClassPath, "()Ljava/lang/String;"),
128 NATIVE_METHOD(VMRuntime, classPath, "()Ljava/lang/String;"),
129 NATIVE_METHOD(VMRuntime, clearGrowthLimit, "()V"),
130 NATIVE_METHOD(VMRuntime, disableJitCompilation, "()V"),
131 NATIVE_METHOD(VMRuntime, getTargetHeapUtilization, "()F"),
132 NATIVE_METHOD(VMRuntime, isDebuggerActive, "()Z"),
133 NATIVE_METHOD(VMRuntime, nativeSetTargetHeapUtilization, "(F)V"),
134 NATIVE_METHOD(VMRuntime, newNonMovableArray, "(Ljava/lang/Class;I)Ljava/lang/Object;"),
135 NATIVE_METHOD(VMRuntime, properties, "()[Ljava/lang/String;"),
136 NATIVE_METHOD(VMRuntime, setTargetSdkVersion, "(I)V"),
137 NATIVE_METHOD(VMRuntime, startJitCompilation, "()V"),
138 NATIVE_METHOD(VMRuntime, vmVersion, "()Ljava/lang/String;"),
139};
140
141} // namespace
142
143void register_dalvik_system_VMRuntime(JNIEnv* env) {
144 jniRegisterNativeMethods(env, "dalvik/system/VMRuntime", gMethods, NELEM(gMethods));
145}
146
147} // namespace art