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