1e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom/* 2e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Copyright (C) 2007 The Android Open Source Project 3e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 4e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Licensed under the Apache License, Version 2.0 (the "License"); 5e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * you may not use this file except in compliance with the License. 6e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * You may obtain a copy of the License at 7e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 8e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * http://www.apache.org/licenses/LICENSE-2.0 9e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 10e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Unless required by applicable law or agreed to in writing, software 11e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * distributed under the License is distributed on an "AS IS" BASIS, 12e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * See the License for the specific language governing permissions and 14e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * limitations under the License. 15e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 16e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 17e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrompackage dalvik.system; 18e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 19a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamathimport java.util.HashMap; 20a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamathimport java.util.Map; 21a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath 22e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom/** 23e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Provides an interface to VM-global, Dalvik-specific features. 24e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * An application cannot create its own Runtime instance, and must obtain 25e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * one from the getRuntime method. 26e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 27e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @hide 28e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 29e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrompublic final class VMRuntime { 30e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 31e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 32e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Holds the VMRuntime singleton. 33e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 34e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom private static final VMRuntime THE_ONE = new VMRuntime(); 35e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 36a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath private static final Map<String, String> ABI_TO_INSTRUCTION_SET_MAP 37a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath = new HashMap<String, String>(); 38a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath static { 39a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("armeabi", "arm"); 40a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("armeabi-v7a", "arm"); 41a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("mips", "mips"); 4232f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("mips64", "mips64"); 43a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("x86", "x86"); 44a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("x86_64", "x86_64"); 45a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath ABI_TO_INSTRUCTION_SET_MAP.put("arm64-v8a", "arm64"); 46a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath } 47a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath 481ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin private int targetSdkVersion; 491ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin 50e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 51e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Prevents this class from being instantiated. 52e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 53e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom private VMRuntime() { 54e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 55e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 56e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 57e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns the object that represents the VM instance's Dalvik-specific 58e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * runtime environment. 59e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 60e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @return the runtime object 61e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 62e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public static VMRuntime getRuntime() { 63e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom return THE_ONE; 64e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 65e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 66e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 67e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns a copy of the VM's command-line property settings. 68e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * These are in the form "name=value" rather than "-Dname=value". 69e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 70e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native String[] properties(); 71e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 72e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 73e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns the VM's boot class path. 74e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 75e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native String bootClassPath(); 76e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 77e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 78e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns the VM's class path. 79e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 80e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native String classPath(); 81e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 82e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 83e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns the VM's version. 84e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 85e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native String vmVersion(); 86e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 87e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 8826376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom * Returns the name of the shared library providing the VM implementation. 8926376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom */ 9026376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom public native String vmLibrary(); 9126376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom 9226376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom /** 93451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz * Returns the VM's instruction set. 94451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz */ 95451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz public native String vmInstructionSet(); 96451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz 97451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz /** 98451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz * Returns whether the VM is running in 64-bit mode. 99451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz */ 100451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz public native boolean is64Bit(); 101451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz 102451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz /** 103451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz * Returns whether the VM is running with JNI checking enabled. 104451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz */ 105451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz public native boolean isCheckJniEnabled(); 106451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz 107451d99525dc8fef247e6fe6f4c714cbdf7f8b322Sebastien Hertz /** 108e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Gets the current ideal heap utilization, represented as a number 109e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * between zero and one. After a GC happens, the Dalvik heap may 110e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * be resized so that (size of live objects) / (size of heap) is 111e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * equal to this number. 112e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 113e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @return the current ideal heap utilization 114e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 115e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native float getTargetHeapUtilization(); 116e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 117e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 118e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Sets the current ideal heap utilization, represented as a number 119e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * between zero and one. After a GC happens, the Dalvik heap may 120e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * be resized so that (size of live objects) / (size of heap) is 121e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * equal to this number. 122e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 123e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * <p>This is only a hint to the garbage collector and may be ignored. 124e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 125e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @param newTarget the new suggested ideal heap utilization. 126e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This value may be adjusted internally. 127e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @return the previous ideal heap utilization 128e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @throws IllegalArgumentException if newTarget is <= 0.0 or >= 1.0 129e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 130e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public float setTargetHeapUtilization(float newTarget) { 131e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom if (newTarget <= 0.0f || newTarget >= 1.0f) { 132e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom throw new IllegalArgumentException(newTarget + 133e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom " out of range (0,1)"); 134e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 135e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /* Synchronize to make sure that only one thread gets 136e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * a given "old" value if both update at the same time. 137e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Allows for reliable save-and-restore semantics. 138e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 139e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom synchronized (this) { 140e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom float oldTarget = getTargetHeapUtilization(); 141e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom nativeSetTargetHeapUtilization(newTarget); 142e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom return oldTarget; 143e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 144e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 145e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 146e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 147e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Sets the target SDK version. Should only be called before the 148e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * app starts to run, because it may change the VM's behavior in 149e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * dangerous ways. Use 0 to mean "current" (since callers won't 150e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * necessarily know the actual current SDK version, and the 1511ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin * allocated version numbers start at 1), and 10000 to mean 1521ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin * CUR_DEVELOPMENT. 153e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 1541ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin public synchronized void setTargetSdkVersion(int targetSdkVersion) { 1551ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin this.targetSdkVersion = targetSdkVersion; 1561ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin setTargetSdkVersionNative(this.targetSdkVersion); 1571ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin } 1581ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin 1591ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin /** 1601ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin * Gets the target SDK version. See {@link #setTargetSdkVersion} for 1611ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin * special values. 1621ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin */ 1631ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin public synchronized int getTargetSdkVersion() { 1641ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin return targetSdkVersion; 1651ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin } 1661ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin 1671ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin private native void setTargetSdkVersionNative(int targetSdkVersion); 168e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 169e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 170e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It was part of a 171413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes * heap sizing API which was removed in Android 3.0 (Honeycomb). 172e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 173e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 174e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public long getMinimumHeapSize() { 175e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom return 0; 176e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 177e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 178e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 179e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It was part of a 180413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes * heap sizing API which was removed in Android 3.0 (Honeycomb). 181e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 182e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 183e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public long setMinimumHeapSize(long size) { 184e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom return 0; 185e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 186e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 187e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 188e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It used to 189e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * perform a garbage collection that cleared SoftReferences. 190e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 191e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 192e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public void gcSoftReferences() {} 193e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 194e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 195e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It is equivalent 196e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * to {@link System#runFinalization}. 197e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 198e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 199e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public void runFinalizationSync() { 200e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom System.runFinalization(); 201e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 202e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 203e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 204e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Implements setTargetHeapUtilization(). 205e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * 206e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @param newTarget the new suggested ideal heap utilization. 207e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This value may be adjusted internally. 208e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 209e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom private native void nativeSetTargetHeapUtilization(float newTarget); 210e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 211e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 212e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It was part of 213413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes * the external allocation API which was removed in Android 3.0 (Honeycomb). 214e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 215e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 216e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public boolean trackExternalAllocation(long size) { 217e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom return true; 218e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 219e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 220e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 221e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It was part of 222413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes * the external allocation API which was removed in Android 3.0 (Honeycomb). 223e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 224e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 225e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public void trackExternalFree(long size) {} 226e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 227e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 228e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This method exists for binary compatibility. It was part of 229413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes * the external allocation API which was removed in Android 3.0 (Honeycomb). 230e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 231e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom @Deprecated 232e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public long getExternalBytesAllocated() { 233e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom return 0; 234e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom } 235e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 236e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 237e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Tells the VM to enable the JIT compiler. If the VM does not have a JIT 238e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * implementation, calling this method should have no effect. 239e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 240e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native void startJitCompilation(); 241e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 242e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 243e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Tells the VM to disable the JIT compiler. If the VM does not have a JIT 244e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * implementation, calling this method should have no effect. 245e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 246e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native void disableJitCompilation(); 247e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 248e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 249e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns an array allocated in an area of the Java heap where it will never be moved. 250e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * This is used to implement native allocations on the Java heap, such as DirectByteBuffers 251e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * and Bitmaps. 252e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 253e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native Object newNonMovableArray(Class<?> componentType, int length); 254e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 255e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 25610af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers * Returns an array of at least minLength, but potentially larger. The increased size comes from 25710af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers * avoiding any padding after the array. The amount of padding varies depending on the 25810af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers * componentType and the memory allocator implementation. 25910af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers */ 26010af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers public native Object newUnpaddedArray(Class<?> componentType, int minLength); 26110af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers 26210af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers /** 263e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns the address of array[0]. This differs from using JNI in that JNI might lie and 264e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * give you the address of a copy of the array when in forcecopy mode. 265e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 266e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native long addressOf(Object array); 267e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 268e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 269e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Removes any growth limits, allowing the application to allocate 270e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * up to the maximum heap size. 271e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 272e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native void clearGrowthLimit(); 273e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 274e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom /** 275e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Returns true if either a Java debugger or native debugger is active. 276e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */ 277e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native boolean isDebuggerActive(); 278e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom 279ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier /** 280ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * Registers a native allocation so that the heap knows about it and performs GC as required. 281ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * If the number of native allocated bytes exceeds the native allocation watermark, the 282ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * function requests a concurrent GC. If the native bytes allocated exceeds a second higher 283ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * watermark, it is determined that the application is registering native allocations at an 284ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * unusually high rate and a GC is performed inside of the function to prevent memory usage 285ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * from excessively increasing. 286ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier */ 287ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier public native void registerNativeAllocation(int bytes); 288ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier 289ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier /** 290ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier * Registers a native free by reducing the number of native bytes accounted for. 291ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier */ 292ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier public native void registerNativeFree(int bytes); 293ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier 294e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native void trimHeap(); 295e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom public native void concurrentGC(); 296c8cfc667ddb82b08b889a24831a3d00cc6490bd9Brian Carlstrom 29765e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom /** 2980c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier * Let the heap know of the new process state. This can change allocation and garbage collection 2990c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier * behavior regarding trimming and compaction. 3000c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier */ 3010c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier public native void updateProcessState(int state); 3020c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier 3030c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier /** 30465e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom * Fill in dex caches with classes, fields, and methods that are 30565e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom * already loaded. Typically used after Zygote preloading. 30665e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom */ 30765e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom public native void preloadDexCaches(); 308eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison 309eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison /** 310eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison * Register application info 311eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison */ 3125e51851f6e91f6e5450435b51812e147db8b9735Dave Allison public static native void registerAppInfo(String appDir, String processName, String pkgname); 313a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath 314a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath /** 315a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath * Returns the runtime instruction set corresponding to a given ABI. Multiple 316a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath * compatible ABIs might map to the same instruction set. For example 317a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath * {@code armeabi-v7a} and {@code armeabi} might map to the instruction set {@code arm}. 318a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath * 319a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath * This influences the compilation of the applications classes. 320a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath */ 321a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath public static String getInstructionSet(String abi) { 322a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath final String instructionSet = ABI_TO_INSTRUCTION_SET_MAP.get(abi); 323a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath if (instructionSet == null) { 324a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath throw new IllegalArgumentException("Unsupported ABI: " + abi); 325a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath } 326a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath 327a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath return instructionSet; 328a607cc9c4cd4e21df39e549c14dac81c5cd18922Narayan Kamath } 32932f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath 33032f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath public static boolean is64BitInstructionSet(String instructionSet) { 33132f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath return "arm64".equals(instructionSet) || 33232f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath "x86_64".equals(instructionSet) || 33332f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath "mips64".equals(instructionSet); 33432f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath } 33532f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath 33632f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath public static boolean is64BitAbi(String abi) { 33732f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath return is64BitInstructionSet(getInstructionSet(abi)); 33832f32721e65c93a3aaf8a792b7742aabe7e29e7eNarayan Kamath } 33975c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom 34075c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom /** 34175c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom * Return false if the boot class path for the given instruction 34275c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom * set mapped from disk storage, versus being interpretted from 34375c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom * dirty pages in memory. 34475c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom */ 34575c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom public static native boolean isBootClassPathOnDisk(String instructionSet); 34675c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom 34775c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom /** 34875c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom * Returns the instruction set of the current runtime. 34975c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom */ 35075c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom public static native String getCurrentInstructionSet(); 35175c02d71f2345d9f19e9c36dd75c3d08d9f562dcBrian Carlstrom 352e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom} 353