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"
27 * public native float getTargetHeapUtilization()
29 * Gets the current ideal heap utilization, represented as a number
30 * between zero and one.
32 static void Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization(
33 const u4* args, JValue* pResult)
35 UNUSED_PARAMETER(args);
37 RETURN_FLOAT(dvmGetTargetHeapUtilization());
41 * native float nativeSetTargetHeapUtilization()
43 * Sets the current ideal heap utilization, represented as a number
44 * between zero and one. Returns the old utilization.
46 * Note that this is NOT static.
48 static void Dalvik_dalvik_system_VMRuntime_nativeSetTargetHeapUtilization(
49 const u4* args, JValue* pResult)
51 dvmSetTargetHeapUtilization(dvmU4ToFloat(args[1]));
57 * public native void gcSoftReferences()
59 * Does a GC and forces collection of SoftReferences that are
60 * not strongly-reachable.
62 static void Dalvik_dalvik_system_VMRuntime_gcSoftReferences(const u4* args,
65 dvmCollectGarbage(true);
71 * public native void runFinalizationSync()
73 * Does not return until any pending finalizers have been called.
74 * This may or may not happen in the context of the calling thread.
75 * No exceptions will escape.
77 * Used by zygote, which doesn't have a HeapWorker thread.
79 static void Dalvik_dalvik_system_VMRuntime_runFinalizationSync(const u4* args,
82 dvmRunFinalizationSync();
88 * public native void startJitCompilation()
90 * Callback function from the framework to indicate that an app has gone
91 * through the startup phase and it is time to enable the JIT compiler.
93 static void Dalvik_dalvik_system_VMRuntime_startJitCompilation(const u4* args,
97 if (gDvm.executionMode == kExecutionModeJit &&
98 gDvmJit.disableJit == false) {
99 dvmLockMutex(&gDvmJit.compilerLock);
100 gDvmJit.alreadyEnabledViaFramework = true;
101 pthread_cond_signal(&gDvmJit.compilerQueueActivity);
102 dvmUnlockMutex(&gDvmJit.compilerLock);
109 * public native void disableJitCompilation()
111 * Callback function from the framework to indicate that a VM instance wants to
112 * permanently disable the JIT compiler. Currently only the system server uses
113 * this interface when it detects system-wide safe mode is enabled.
115 static void Dalvik_dalvik_system_VMRuntime_disableJitCompilation(const u4* args,
118 #if defined(WITH_JIT)
119 if (gDvm.executionMode == kExecutionModeJit) {
120 gDvmJit.disableJit = true;
126 static void Dalvik_dalvik_system_VMRuntime_newNonMovableArray(const u4* args,
129 ClassObject* elementClass = (ClassObject*) args[1];
130 int length = args[2];
131 ArrayObject* newArray;
133 if (elementClass == NULL) {
134 dvmThrowException("Ljava/lang/NullPointerException;", NULL);
138 dvmThrowException("Ljava/lang/NegativeArraySizeException;", NULL);
142 // TODO: right now, we don't have a copying collector, so there's no need
143 // to do anything special here, but we ought to pass the non-movability
144 // through to the allocator.
145 newArray = dvmAllocObjectArray(elementClass, length, ALLOC_DEFAULT);
146 if (newArray == NULL) {
147 assert(dvmCheckException(dvmThreadSelf()));
150 dvmReleaseTrackedAlloc((Object*) newArray, NULL);
152 RETURN_PTR(newArray);
155 static void Dalvik_dalvik_system_VMRuntime_addressOf(const u4* args,
158 ArrayObject* array = (ArrayObject*) args[1];
159 if (!dvmIsArray(array)) {
160 dvmThrowException("Ljava/lang/IllegalArgumentException;", NULL);
163 // TODO: we should also check that this is a non-movable array.
164 s8 result = (uintptr_t) array->contents;
168 static void Dalvik_dalvik_system_VMRuntime_clearGrowthLimit(const u4* args,
171 dvmClearGrowthLimit();
175 const DalvikNativeMethod dvm_dalvik_system_VMRuntime[] = {
176 { "getTargetHeapUtilization", "()F",
177 Dalvik_dalvik_system_VMRuntime_getTargetHeapUtilization },
178 { "nativeSetTargetHeapUtilization", "(F)V",
179 Dalvik_dalvik_system_VMRuntime_nativeSetTargetHeapUtilization },
180 { "gcSoftReferences", "()V",
181 Dalvik_dalvik_system_VMRuntime_gcSoftReferences },
182 { "runFinalizationSync", "()V",
183 Dalvik_dalvik_system_VMRuntime_runFinalizationSync },
184 { "startJitCompilation", "()V",
185 Dalvik_dalvik_system_VMRuntime_startJitCompilation },
186 { "disableJitCompilation", "()V",
187 Dalvik_dalvik_system_VMRuntime_disableJitCompilation },
188 { "newNonMovableArray", "(Ljava/lang/Class;I)Ljava/lang/Object;",
189 Dalvik_dalvik_system_VMRuntime_newNonMovableArray },
190 { "addressOf", "(Ljava/lang/Object;)J",
191 Dalvik_dalvik_system_VMRuntime_addressOf },
192 { "clearGrowthLimit", "()V",
193 Dalvik_dalvik_system_VMRuntime_clearGrowthLimit },
194 { NULL, NULL, NULL },