Package dalvik.system
Class VMRuntime
- java.lang.Object
-
- dalvik.system.VMRuntime
-
public final class VMRuntime extends Object
Provides an interface to VM-global, Dalvik-specific features. An application cannot create its own Runtime instance, and must obtain one from the getRuntime method.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description longaddressOf(Object array)Returns the address of array[0].StringbootClassPath()Returns the VM's boot class path.voidclampGrowthLimit()Make the current growth limit the new non growth limit capacity by releasing pages which are after the growth limit but before the non growth limit capacity.StringclassPath()Returns the VM's class path.voidclearGrowthLimit()Removes any growth limits, allowing the application to allocate up to the maximum heap size.voidconcurrentGC()voiddisableJitCompilation()Tells the VM to disable the JIT compiler.voidgcSoftReferences()Deprecated.static StringgetCurrentInstructionSet()Returns the instruction set of the current runtime.longgetExternalBytesAllocated()Deprecated.static StringgetInstructionSet(String abi)Returns the runtime instruction set corresponding to a given ABI.longgetMinimumHeapSize()Deprecated.static VMRuntimegetRuntime()Returns the object that represents the VM instance's Dalvik-specific runtime environment.floatgetTargetHeapUtilization()Gets the current ideal heap utilization, represented as a number between zero and one.intgetTargetSdkVersion()Gets the target SDK version.booleanis64Bit()Returns whether the VM is running in 64-bit mode.static booleanis64BitAbi(String abi)static booleanis64BitInstructionSet(String instructionSet)static booleanisBootClassPathOnDisk(String instructionSet)Return false if the boot class path for the given instruction set mapped from disk storage, versus being interpretted from dirty pages in memory.booleanisCheckJniEnabled()Returns whether the VM is running with JNI checking enabled.booleanisDebuggerActive()Returns true if either a Java debugger or native debugger is active.ObjectnewNonMovableArray(Class<?> componentType, int length)Returns an array allocated in an area of the Java heap where it will never be moved.ObjectnewUnpaddedArray(Class<?> componentType, int minLength)Returns an array of at least minLength, but potentially larger.voidpreloadDexCaches()Fill in dex caches with classes, fields, and methods that are already loaded.String[]properties()Returns a copy of the VM's command-line property settings.static voidregisterAppInfo(String appDir, String processName, String pkgname)Register application infovoidregisterNativeAllocation(int bytes)Registers a native allocation so that the heap knows about it and performs GC as required.voidregisterNativeFree(int bytes)Registers a native free by reducing the number of native bytes accounted for.voidrequestConcurrentGC()voidrequestHeapTrim()static voidrunFinalization(long timeout)Wait for objects to be finalized.voidrunFinalizationSync()Deprecated.voidrunHeapTasks()longsetMinimumHeapSize(long size)Deprecated.floatsetTargetHeapUtilization(float newTarget)Sets the current ideal heap utilization, represented as a number between zero and one.voidsetTargetSdkVersion(int targetSdkVersion)Sets the target SDK version.voidstartHeapTaskProcessor()voidstartJitCompilation()Tells the VM to enable the JIT compiler.voidstopHeapTaskProcessor()booleantrackExternalAllocation(long size)Deprecated.voidtrackExternalFree(long size)Deprecated.voidtrimHeap()voidupdateProcessState(int state)Let the heap know of the new process state.StringvmInstructionSet()Returns the VM's instruction set.StringvmLibrary()Returns the name of the shared library providing the VM implementation.StringvmVersion()Returns the VM's version.
-
-
-
Method Detail
-
getRuntime
public static VMRuntime getRuntime()
Returns the object that represents the VM instance's Dalvik-specific runtime environment.- Returns:
- the runtime object
-
properties
public String[] properties()
Returns a copy of the VM's command-line property settings. These are in the form "name=value" rather than "-Dname=value".
-
bootClassPath
public String bootClassPath()
Returns the VM's boot class path.
-
classPath
public String classPath()
Returns the VM's class path.
-
vmVersion
public String vmVersion()
Returns the VM's version.
-
vmLibrary
public String vmLibrary()
Returns the name of the shared library providing the VM implementation.
-
vmInstructionSet
public String vmInstructionSet()
Returns the VM's instruction set.
-
is64Bit
public boolean is64Bit()
Returns whether the VM is running in 64-bit mode.
-
isCheckJniEnabled
public boolean isCheckJniEnabled()
Returns whether the VM is running with JNI checking enabled.
-
getTargetHeapUtilization
public float getTargetHeapUtilization()
Gets the current ideal heap utilization, represented as a number between zero and one. After a GC happens, the Dalvik heap may be resized so that (size of live objects) / (size of heap) is equal to this number.- Returns:
- the current ideal heap utilization
-
setTargetHeapUtilization
public float setTargetHeapUtilization(float newTarget)
Sets the current ideal heap utilization, represented as a number between zero and one. After a GC happens, the Dalvik heap may be resized so that (size of live objects) / (size of heap) is equal to this number.This is only a hint to the garbage collector and may be ignored.
- Parameters:
newTarget- the new suggested ideal heap utilization. This value may be adjusted internally.- Returns:
- the previous ideal heap utilization
- Throws:
IllegalArgumentException- if newTarget is <= 0.0 or >= 1.0
-
setTargetSdkVersion
public void setTargetSdkVersion(int targetSdkVersion)
Sets the target SDK version. Should only be called before the app starts to run, because it may change the VM's behavior in dangerous ways. Use 0 to mean "current" (since callers won't necessarily know the actual current SDK version, and the allocated version numbers start at 1), and 10000 to mean CUR_DEVELOPMENT.
-
getTargetSdkVersion
public int getTargetSdkVersion()
Gets the target SDK version. SeesetTargetSdkVersion(int)for special values.
-
getMinimumHeapSize
@Deprecated public long getMinimumHeapSize()
Deprecated.This method exists for binary compatibility. It was part of a heap sizing API which was removed in Android 3.0 (Honeycomb).
-
setMinimumHeapSize
@Deprecated public long setMinimumHeapSize(long size)
Deprecated.This method exists for binary compatibility. It was part of a heap sizing API which was removed in Android 3.0 (Honeycomb).
-
gcSoftReferences
@Deprecated public void gcSoftReferences()
Deprecated.This method exists for binary compatibility. It used to perform a garbage collection that cleared SoftReferences.
-
runFinalizationSync
@Deprecated public void runFinalizationSync()
Deprecated.This method exists for binary compatibility. It is equivalent toSystem.runFinalization().
-
trackExternalAllocation
@Deprecated public boolean trackExternalAllocation(long size)
Deprecated.This method exists for binary compatibility. It was part of the external allocation API which was removed in Android 3.0 (Honeycomb).
-
trackExternalFree
@Deprecated public void trackExternalFree(long size)
Deprecated.This method exists for binary compatibility. It was part of the external allocation API which was removed in Android 3.0 (Honeycomb).
-
getExternalBytesAllocated
@Deprecated public long getExternalBytesAllocated()
Deprecated.This method exists for binary compatibility. It was part of the external allocation API which was removed in Android 3.0 (Honeycomb).
-
startJitCompilation
public void startJitCompilation()
Tells the VM to enable the JIT compiler. If the VM does not have a JIT implementation, calling this method should have no effect.
-
disableJitCompilation
public void disableJitCompilation()
Tells the VM to disable the JIT compiler. If the VM does not have a JIT implementation, calling this method should have no effect.
-
newNonMovableArray
public Object newNonMovableArray(Class<?> componentType, int length)
Returns an array allocated in an area of the Java heap where it will never be moved. This is used to implement native allocations on the Java heap, such as DirectByteBuffers and Bitmaps.
-
newUnpaddedArray
public Object newUnpaddedArray(Class<?> componentType, int minLength)
Returns an array of at least minLength, but potentially larger. The increased size comes from avoiding any padding after the array. The amount of padding varies depending on the componentType and the memory allocator implementation.
-
addressOf
public long addressOf(Object array)
Returns the address of array[0]. This differs from using JNI in that JNI might lie and give you the address of a copy of the array when in forcecopy mode.
-
clearGrowthLimit
public void clearGrowthLimit()
Removes any growth limits, allowing the application to allocate up to the maximum heap size.
-
clampGrowthLimit
public void clampGrowthLimit()
Make the current growth limit the new non growth limit capacity by releasing pages which are after the growth limit but before the non growth limit capacity.
-
isDebuggerActive
public boolean isDebuggerActive()
Returns true if either a Java debugger or native debugger is active.
-
registerNativeAllocation
public void registerNativeAllocation(int bytes)
Registers a native allocation so that the heap knows about it and performs GC as required. If the number of native allocated bytes exceeds the native allocation watermark, the function requests a concurrent GC. If the native bytes allocated exceeds a second higher watermark, it is determined that the application is registering native allocations at an unusually high rate and a GC is performed inside of the function to prevent memory usage from excessively increasing.
-
registerNativeFree
public void registerNativeFree(int bytes)
Registers a native free by reducing the number of native bytes accounted for.
-
runFinalization
public static void runFinalization(long timeout)
Wait for objects to be finalized. If finalization takes longer than timeout, then the function returns before all objects are finalized.- Parameters:
timeout- timeout in nanoseconds of the maximum time to wait until all pending finalizers are run. If timeout is 0, then there is no timeout. Note that the timeout does not stop the finalization process, it merely stops the wait.- See Also:
Object.wait(long,int)
-
requestConcurrentGC
public void requestConcurrentGC()
-
concurrentGC
public void concurrentGC()
-
requestHeapTrim
public void requestHeapTrim()
-
trimHeap
public void trimHeap()
-
startHeapTaskProcessor
public void startHeapTaskProcessor()
-
stopHeapTaskProcessor
public void stopHeapTaskProcessor()
-
runHeapTasks
public void runHeapTasks()
-
updateProcessState
public void updateProcessState(int state)
Let the heap know of the new process state. This can change allocation and garbage collection behavior regarding trimming and compaction.
-
preloadDexCaches
public void preloadDexCaches()
Fill in dex caches with classes, fields, and methods that are already loaded. Typically used after Zygote preloading.
-
registerAppInfo
public static void registerAppInfo(String appDir, String processName, String pkgname)
Register application info
-
getInstructionSet
public static String getInstructionSet(String abi)
Returns the runtime instruction set corresponding to a given ABI. Multiple compatible ABIs might map to the same instruction set. For examplearmeabi-v7aandarmeabimight map to the instruction setarm. This influences the compilation of the applications classes.
-
is64BitInstructionSet
public static boolean is64BitInstructionSet(String instructionSet)
-
is64BitAbi
public static boolean is64BitAbi(String abi)
-
isBootClassPathOnDisk
public static boolean isBootClassPathOnDisk(String instructionSet)
Return false if the boot class path for the given instruction set mapped from disk storage, versus being interpretted from dirty pages in memory.
-
getCurrentInstructionSet
public static String getCurrentInstructionSet()
Returns the instruction set of the current runtime.
-
-