VMRuntime.java revision 5e51851f6e91f6e5450435b51812e147db8b9735
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
19e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom/**
20e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * Provides an interface to VM-global, Dalvik-specific features.
21e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * An application cannot create its own Runtime instance, and must obtain
22e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * one from the getRuntime method.
23e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom *
24e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom * @hide
25e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom */
26e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrompublic final class VMRuntime {
27e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
28e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
29e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Holds the VMRuntime singleton.
30e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
31e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    private static final VMRuntime THE_ONE = new VMRuntime();
32e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
331ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    private int targetSdkVersion;
341ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin
35e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
36e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Prevents this class from being instantiated.
37e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
38e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    private VMRuntime() {
39e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
40e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
41e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
42e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns the object that represents the VM instance's Dalvik-specific
43e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * runtime environment.
44e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *
45e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * @return the runtime object
46e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
47e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public static VMRuntime getRuntime() {
48e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        return THE_ONE;
49e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
50e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
51e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
52e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns a copy of the VM's command-line property settings.
53e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * These are in the form "name=value" rather than "-Dname=value".
54e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
55e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native String[] properties();
56e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
57e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
58e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns the VM's boot class path.
59e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
60e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native String bootClassPath();
61e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
62e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
63e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns the VM's class path.
64e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
65e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native String classPath();
66e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
67e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
68e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns the VM's version.
69e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
70e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native String vmVersion();
71e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
72e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
7326376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom     * Returns the name of the shared library providing the VM implementation.
7426376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom     */
7526376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom    public native String vmLibrary();
7626376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom
7726376765d7333ddf04c021365a1eadd9d47feb7eBrian Carlstrom    /**
78e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Gets the current ideal heap utilization, represented as a number
79e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * between zero and one.  After a GC happens, the Dalvik heap may
80e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * be resized so that (size of live objects) / (size of heap) is
81e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * equal to this number.
82e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *
83e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * @return the current ideal heap utilization
84e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
85e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native float getTargetHeapUtilization();
86e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
87e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
88e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Sets the current ideal heap utilization, represented as a number
89e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * between zero and one.  After a GC happens, the Dalvik heap may
90e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * be resized so that (size of live objects) / (size of heap) is
91e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * equal to this number.
92e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *
93e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * <p>This is only a hint to the garbage collector and may be ignored.
94e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *
95e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * @param newTarget the new suggested ideal heap utilization.
96e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *                  This value may be adjusted internally.
97e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * @return the previous ideal heap utilization
98e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * @throws IllegalArgumentException if newTarget is &lt;= 0.0 or &gt;= 1.0
99e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
100e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public float setTargetHeapUtilization(float newTarget) {
101e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        if (newTarget <= 0.0f || newTarget >= 1.0f) {
102e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom            throw new IllegalArgumentException(newTarget +
103e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom                    " out of range (0,1)");
104e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        }
105e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        /* Synchronize to make sure that only one thread gets
106e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom         * a given "old" value if both update at the same time.
107e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom         * Allows for reliable save-and-restore semantics.
108e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom         */
109e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        synchronized (this) {
110e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom            float oldTarget = getTargetHeapUtilization();
111e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom            nativeSetTargetHeapUtilization(newTarget);
112e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom            return oldTarget;
113e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        }
114e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
115e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
116e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
117e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Sets the target SDK version. Should only be called before the
118e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * app starts to run, because it may change the VM's behavior in
119e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * dangerous ways. Use 0 to mean "current" (since callers won't
120e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * necessarily know the actual current SDK version, and the
1211ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin     * allocated version numbers start at 1), and 10000 to mean
1221ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin     * CUR_DEVELOPMENT.
123e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
1241ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    public synchronized void setTargetSdkVersion(int targetSdkVersion) {
1251ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin        this.targetSdkVersion = targetSdkVersion;
1261ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin        setTargetSdkVersionNative(this.targetSdkVersion);
1271ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    }
1281ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin
1291ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    /**
1301ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin     * Gets the target SDK version. See {@link #setTargetSdkVersion} for
1311ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin     * special values.
1321ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin     */
1331ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    public synchronized int getTargetSdkVersion() {
1341ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin        return targetSdkVersion;
1351ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    }
1361ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin
1371ec5a34b4367fd7c44266c5bdd363ea5cfac7a67Alex Klyubin    private native void setTargetSdkVersionNative(int targetSdkVersion);
138e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
139e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
140e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It was part of a
141413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes     * heap sizing API which was removed in Android 3.0 (Honeycomb).
142e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
143e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
144e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public long getMinimumHeapSize() {
145e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        return 0;
146e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
147e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
148e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
149e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It was part of a
150413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes     * heap sizing API which was removed in Android 3.0 (Honeycomb).
151e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
152e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
153e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public long setMinimumHeapSize(long size) {
154e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        return 0;
155e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
156e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
157e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
158e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It used to
159e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * perform a garbage collection that cleared SoftReferences.
160e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
161e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
162e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public void gcSoftReferences() {}
163e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
164e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
165e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It is equivalent
166e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * to {@link System#runFinalization}.
167e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
168e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
169e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public void runFinalizationSync() {
170e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        System.runFinalization();
171e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
172e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
173e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
174e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Implements setTargetHeapUtilization().
175e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *
176e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * @param newTarget the new suggested ideal heap utilization.
177e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     *                  This value may be adjusted internally.
178e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
179e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    private native void nativeSetTargetHeapUtilization(float newTarget);
180e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
181e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
182e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It was part of
183413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes     * the external allocation API which was removed in Android 3.0 (Honeycomb).
184e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
185e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
186e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public boolean trackExternalAllocation(long size) {
187e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        return true;
188e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
189e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
190e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
191e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It was part of
192413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes     * the external allocation API which was removed in Android 3.0 (Honeycomb).
193e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
194e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
195e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public void trackExternalFree(long size) {}
196e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
197e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
198e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This method exists for binary compatibility.  It was part of
199413d4592ee114eac81014af4b6347e73873ce8ceElliott Hughes     * the external allocation API which was removed in Android 3.0 (Honeycomb).
200e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
201e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    @Deprecated
202e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public long getExternalBytesAllocated() {
203e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom        return 0;
204e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    }
205e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
206e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
207e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Tells the VM to enable the JIT compiler. If the VM does not have a JIT
208e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * implementation, calling this method should have no effect.
209e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
210e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native void startJitCompilation();
211e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
212e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
213e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Tells the VM to disable the JIT compiler. If the VM does not have a JIT
214e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * implementation, calling this method should have no effect.
215e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
216e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native void disableJitCompilation();
217e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
218e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
219e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns an array allocated in an area of the Java heap where it will never be moved.
220e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * This is used to implement native allocations on the Java heap, such as DirectByteBuffers
221e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * and Bitmaps.
222e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
223e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native Object newNonMovableArray(Class<?> componentType, int length);
224e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
225e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
22610af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers     * Returns an array of at least minLength, but potentially larger. The increased size comes from
22710af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers     * avoiding any padding after the array. The amount of padding varies depending on the
22810af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers     * componentType and the memory allocator implementation.
22910af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers     */
23010af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers    public native Object newUnpaddedArray(Class<?> componentType, int minLength);
23110af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers
23210af76d5af1d87686ff9ab8d00f3dadc15a84fb7Ian Rogers    /**
233e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns the address of array[0]. This differs from using JNI in that JNI might lie and
234e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * give you the address of a copy of the array when in forcecopy mode.
235e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
236e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native long addressOf(Object array);
237e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
238e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
239e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Removes any growth limits, allowing the application to allocate
240e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * up to the maximum heap size.
241e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
242e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native void clearGrowthLimit();
243e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
244e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    /**
245e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     * Returns true if either a Java debugger or native debugger is active.
246e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom     */
247e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native boolean isDebuggerActive();
248e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom
249ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier    /**
250ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * Registers a native allocation so that the heap knows about it and performs GC as required.
251ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * If the number of native allocated bytes exceeds the native allocation watermark, the
252ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * function requests a concurrent GC. If the native bytes allocated exceeds a second higher
253ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * watermark, it is determined that the application is registering native allocations at an
254ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * unusually high rate and a GC is performed inside of the function to prevent memory usage
255ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * from excessively increasing.
256ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     */
257ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier    public native void registerNativeAllocation(int bytes);
258ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier
259ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier    /**
260ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     * Registers a native free by reducing the number of native bytes accounted for.
261ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier     */
262ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier    public native void registerNativeFree(int bytes);
263ddd074801339ef32237f38fb99b43a8844201d89Mathieu Chartier
264e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native void trimHeap();
265e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom    public native void concurrentGC();
266c8cfc667ddb82b08b889a24831a3d00cc6490bd9Brian Carlstrom
26765e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom    /**
2680c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier     * Let the heap know of the new process state. This can change allocation and garbage collection
2690c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier     * behavior regarding trimming and compaction.
2700c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier     */
2710c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier    public native void updateProcessState(int state);
2720c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier
2730c85c33c5b400c0d32cf8c77d3bca704b7cca1e7Mathieu Chartier    /**
27465e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom     * Fill in dex caches with classes, fields, and methods that are
27565e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom     * already loaded. Typically used after Zygote preloading.
27665e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom     */
27765e6acab4f777245dc73f40ecc3b42b065d21ed2Brian Carlstrom    public native void preloadDexCaches();
278eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison
279eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison    /**
280eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison     * Register application info
281eee45fe9d744ed1d9a505f020129430f4b733473Dave Allison     */
2825e51851f6e91f6e5450435b51812e147db8b9735Dave Allison    public static native void registerAppInfo(String appDir, String processName, String pkgname);
283e96f94f57430bf3060581c816cc3a148adbe91a4Brian Carlstrom}
284