2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * dalvik.system.VMRuntime
21 #include "native/InternalNativePriv.h"
23 #include <cutils/array.h>
28 * public native float getTargetHeapUtilization()
30 * Gets the current ideal heap utilization, represented as a number
31 * between zero and one.
33 static void Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization(
34 const u4* args, JValue* pResult)
36 UNUSED_PARAMETER(args);
38 RETURN_FLOAT(dvmGetTargetHeapUtilization());
42 * native float nativeSetTargetHeapUtilization()
44 * Sets the current ideal heap utilization, represented as a number
45 * between zero and one. Returns the old utilization.
47 * Note that this is NOT static.
49 static void Dalvik_dalvik_system_VMRuntime_nativeSetTargetHeapUtilization(
50 const u4* args, JValue* pResult)
52 dvmSetTargetHeapUtilization(dvmU4ToFloat(args[1]));
58 * public native void runFinalizationSync()
60 * Does not return until any pending finalizers have been called.
61 * This may or may not happen in the context of the calling thread.
62 * No exceptions will escape.
64 * Used by zygote, which doesn't have a HeapWorker thread.
66 static void Dalvik_dalvik_system_VMRuntime_runFinalizationSync(const u4* args,
69 dvmRunFinalizationSync();
75 * public native void startJitCompilation()
77 * Callback function from the framework to indicate that an app has gone
78 * through the startup phase and it is time to enable the JIT compiler.
80 static void Dalvik_dalvik_system_VMRuntime_startJitCompilation(const u4* args,
84 if (gDvm.executionMode == kExecutionModeJit &&
85 gDvmJit.disableJit == false) {
86 dvmLockMutex(&gDvmJit.compilerLock);
87 gDvmJit.alreadyEnabledViaFramework = true;
88 pthread_cond_signal(&gDvmJit.compilerQueueActivity);
89 dvmUnlockMutex(&gDvmJit.compilerLock);
96 * public native void disableJitCompilation()
98 * Callback function from the framework to indicate that a VM instance wants to
99 * permanently disable the JIT compiler. Currently only the system server uses
100 * this interface when it detects system-wide safe mode is enabled.
102 static void Dalvik_dalvik_system_VMRuntime_disableJitCompilation(const u4* args,
105 #if defined(WITH_JIT)
106 if (gDvm.executionMode == kExecutionModeJit) {
107 gDvmJit.disableJit = true;
113 static void Dalvik_dalvik_system_VMRuntime_newNonMovableArray(const u4* args,
116 ClassObject* elementClass = (ClassObject*) args[1];
117 int length = args[2];
118 ArrayObject* newArray;
120 if (elementClass == NULL) {
121 dvmThrowNullPointerException(NULL);
125 dvmThrowNegativeArraySizeException(length);
129 // TODO: right now, we don't have a copying collector, so there's no need
130 // to do anything special here, but we ought to pass the non-movability
131 // through to the allocator.
132 newArray = dvmAllocObjectArray(elementClass, length, ALLOC_DEFAULT);
133 if (newArray == NULL) {
134 assert(dvmCheckException(dvmThreadSelf()));
137 dvmReleaseTrackedAlloc((Object*) newArray, NULL);
139 RETURN_PTR(newArray);
142 static void Dalvik_dalvik_system_VMRuntime_addressOf(const u4* args,
145 ArrayObject* array = (ArrayObject*) args[1];
146 if (!dvmIsArray(array)) {
147 dvmThrowIllegalArgumentException(NULL);
150 // TODO: we should also check that this is a non-movable array.
151 s8 result = (uintptr_t) array->contents;
155 static void Dalvik_dalvik_system_VMRuntime_clearGrowthLimit(const u4* args,
158 dvmClearGrowthLimit();
162 static void Dalvik_dalvik_system_VMRuntime_properties(const u4* args,
165 char** strings = (char**) arrayUnwrap(gDvm.properties);
166 int count = arraySize(gDvm.properties);
167 ArrayObject* result = dvmCreateStringArray(strings, count);
168 dvmReleaseTrackedAlloc((Object*) result, dvmThreadSelf());
172 static void returnCString(JValue* pResult, const char* s)
174 Object* result = (Object*) dvmCreateStringFromCstr(s);
175 dvmReleaseTrackedAlloc(result, dvmThreadSelf());
179 static void Dalvik_dalvik_system_VMRuntime_bootClassPath(const u4* args,
182 returnCString(pResult, gDvm.bootClassPathStr);
185 static void Dalvik_dalvik_system_VMRuntime_classPath(const u4* args,
188 returnCString(pResult, gDvm.classPathStr);
191 static void Dalvik_dalvik_system_VMRuntime_vmVersion(const u4* args,
195 sprintf(buf, "%d.%d.%d",
196 DALVIK_MAJOR_VERSION, DALVIK_MINOR_VERSION, DALVIK_BUG_VERSION);
197 returnCString(pResult, buf);
200 const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
201 { "addressOf", "(Ljava/lang/Object;)J",
202 Dalvik_dalvik_system_VMRuntime_addressOf },
203 { "bootClassPath", "()Ljava/lang/String;",
204 Dalvik_dalvik_system_VMRuntime_bootClassPath },
205 { "classPath", "()Ljava/lang/String;",
206 Dalvik_dalvik_system_VMRuntime_classPath },
207 { "clearGrowthLimit", "()V",
208 Dalvik_dalvik_system_VMRuntime_clearGrowthLimit },
209 { "disableJitCompilation", "()V",
210 Dalvik_dalvik_system_VMRuntime_disableJitCompilation },
211 { "getTargetHeapUtilization", "()F",
212 Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization },
213 { "nativeSetTargetHeapUtilization", "(F)V",
214 Dalvik_dalvik_system_VMRuntime_nativeSetTargetHeapUtilization },
215 { "newNonMovableArray", "(Ljava/lang/Class;I)Ljava/lang/Object;",
216 Dalvik_dalvik_system_VMRuntime_newNonMovableArray },
217 { "properties", "()[Ljava/lang/String;",
218 Dalvik_dalvik_system_VMRuntime_properties },
219 { "runFinalizationSync", "()V",
220 Dalvik_dalvik_system_VMRuntime_runFinalizationSync },
221 { "startJitCompilation", "()V",
222 Dalvik_dalvik_system_VMRuntime_startJitCompilation },
223 { "vmVersion", "()Ljava/lang/String;",
224 Dalvik_dalvik_system_VMRuntime_vmVersion },
225 { NULL, NULL, NULL },