Java Code Examples for dalvik.system.VMRuntime#getRuntime()

The following examples show how to use dalvik.system.VMRuntime#getRuntime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZygoteInit.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Runs several special GCs to try to clean up a few generations of
 * softly- and final-reachable objects, along with any other garbage.
 * This is only useful just before a fork().
 */
/*package*/ static void gcAndFinalize() {
    final VMRuntime runtime = VMRuntime.getRuntime();

    /* runFinalizationSync() lets finalizers be called in Zygote,
     * which doesn't have a HeapWorker thread.
     */
    System.gc();
    runtime.runFinalizationSync();
    System.gc();
}
 
Example 2
Source File: TypedArray.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void resize(int len) {
    mLength = len;
    final int dataLen = len * STYLE_NUM_ENTRIES;
    final int indicesLen = len + 1;
    final VMRuntime runtime = VMRuntime.getRuntime();
    if (mDataAddress == 0 || mData.length < dataLen) {
        mData = (int[]) runtime.newNonMovableArray(int.class, dataLen);
        mDataAddress = runtime.addressOf(mData);
        mIndices = (int[]) runtime.newNonMovableArray(int.class, indicesLen);
        mIndicesAddress = runtime.addressOf(mIndices);
    }
}
 
Example 3
Source File: System.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
private static Properties initUnchangeableSystemProperties() {
    VMRuntime runtime = VMRuntime.getRuntime();
    Properties p = new Properties();

    // Set non-static properties.
    p.put("java.boot.class.path", runtime.bootClassPath());
    p.put("java.class.path", runtime.classPath());

    // TODO: does this make any sense? Should we just leave java.home unset?
    String javaHome = getenv("JAVA_HOME");
    if (javaHome == null) {
        javaHome = "/system";
    }
    p.put("java.home", javaHome);

    p.put("java.vm.version", runtime.vmVersion());

    try {
        StructPasswd passwd = Libcore.os.getpwuid(Libcore.os.getuid());
        p.put("user.name", passwd.pw_name);
    } catch (ErrnoException exception) {
        throw new AssertionError(exception);
    }

    StructUtsname info = Libcore.os.uname();
    p.put("os.arch", info.machine);
    if (p.get("os.name") != null && !p.get("os.name").equals(info.sysname)) {
        logE("Wrong compile-time assumption for os.name: " + p.get("os.name") + " vs " +
                info.sysname);
        p.put("os.name", info.sysname);
    }
    p.put("os.version", info.release);

    // Android-added: Undocumented properties that exist only on Android.
    p.put("android.icu.library.version", ICU.getIcuVersion());
    p.put("android.icu.unicode.version", ICU.getUnicodeVersion());
    p.put("android.icu.cldr.version", ICU.getCldrVersion());

    // Property override for ICU4J : this is the location of the ICU4C data. This
    // is prioritized over the properties in ICUConfig.properties. The issue with using
    // that is that it doesn't play well with jarjar and it needs complicated build rules
    // to change its default value.
    String icuDataPath = TimeZoneDataFiles.generateIcuDataPath();
    p.put("android.icu.impl.ICUBinary.dataPath", icuDataPath);

    parsePropertyAssignments(p, specialProperties());

    // Override built-in properties with settings from the command line.
    // Note: it is not possible to override hardcoded values.
    parsePropertyAssignments(p, runtime.properties());


    // Set static hardcoded properties.
    // These come last, as they must be guaranteed to agree with what a backend compiler
    // may assume when compiling the boot image on Android.
    for (String[] pair : AndroidHardcodedSystemProperties.STATIC_PROPERTIES) {
        if (p.containsKey(pair[0])) {
            logE("Ignoring command line argument: -D" + pair[0]);
        }
        if (pair[1] == null) {
            p.remove(pair[0]);
        } else {
            p.put(pair[0], pair[1]);
        }
    }

    return p;
}
 
Example 4
Source File: ZygoteInit.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Load in commonly used resources, so they can be shared across
 * processes.
 *
 * These tend to be a few Kbytes, but are frequently in the 20-40K
 * range, and occasionally even larger.
 */
private static void preloadResources() {
    final VMRuntime runtime = VMRuntime.getRuntime();

    try {
        mResources = Resources.getSystem();
        mResources.startPreloading();
        if (PRELOAD_RESOURCES) {
            Log.i(TAG, "Preloading resources...");

            long startTime = SystemClock.uptimeMillis();
            TypedArray ar = mResources.obtainTypedArray(
                    com.android.internal.R.array.preloaded_drawables);
            int N = preloadDrawables(ar);
            ar.recycle();
            Log.i(TAG, "...preloaded " + N + " resources in "
                    + (SystemClock.uptimeMillis()-startTime) + "ms.");

            startTime = SystemClock.uptimeMillis();
            ar = mResources.obtainTypedArray(
                    com.android.internal.R.array.preloaded_color_state_lists);
            N = preloadColorStateLists(ar);
            ar.recycle();
            Log.i(TAG, "...preloaded " + N + " resources in "
                    + (SystemClock.uptimeMillis()-startTime) + "ms.");

            if (mResources.getBoolean(
                    com.android.internal.R.bool.config_freeformWindowManagement)) {
                startTime = SystemClock.uptimeMillis();
                ar = mResources.obtainTypedArray(
                        com.android.internal.R.array.preloaded_freeform_multi_window_drawables);
                N = preloadDrawables(ar);
                ar.recycle();
                Log.i(TAG, "...preloaded " + N + " resource in "
                        + (SystemClock.uptimeMillis() - startTime) + "ms.");
            }
        }
        mResources.finishPreloading();
    } catch (RuntimeException e) {
        Log.w(TAG, "Failure preloading resources", e);
    }
}
 
Example 5
Source File: DdmHandleHello.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private Chunk handleHELO(Chunk request) {
    if (false)
        return createFailChunk(123, "This is a test");

    /*
     * Process the request.
     */
    ByteBuffer in = wrapChunk(request);

    int serverProtoVers = in.getInt();
    if (false)
        Log.v("ddm-hello", "Server version is " + serverProtoVers);

    /*
     * Create a response.
     */
    String vmName = System.getProperty("java.vm.name", "?");
    String vmVersion = System.getProperty("java.vm.version", "?");
    String vmIdent = vmName + " v" + vmVersion;

    //String appName = android.app.ActivityThread.currentPackageName();
    //if (appName == null)
    //    appName = "unknown";
    String appName = DdmHandleAppName.getAppName();

    VMRuntime vmRuntime = VMRuntime.getRuntime();
    String instructionSetDescription =
        vmRuntime.is64Bit() ? "64-bit" : "32-bit";
    String vmInstructionSet = vmRuntime.vmInstructionSet();
    if (vmInstructionSet != null && vmInstructionSet.length() > 0) {
      instructionSetDescription += " (" + vmInstructionSet + ")";
    }
    String vmFlags = "CheckJNI="
        + (vmRuntime.isCheckJniEnabled() ? "true" : "false");
    boolean isNativeDebuggable = vmRuntime.isNativeDebuggable();

    ByteBuffer out = ByteBuffer.allocate(28
                        + vmIdent.length() * 2
                        + appName.length() * 2
                        + instructionSetDescription.length() * 2
                        + vmFlags.length() * 2
                        + 1);
    out.order(ChunkHandler.CHUNK_ORDER);
    out.putInt(DdmServer.CLIENT_PROTOCOL_VERSION);
    out.putInt(android.os.Process.myPid());
    out.putInt(vmIdent.length());
    out.putInt(appName.length());
    putString(out, vmIdent);
    putString(out, appName);
    out.putInt(UserHandle.myUserId());
    out.putInt(instructionSetDescription.length());
    putString(out, instructionSetDescription);
    out.putInt(vmFlags.length());
    putString(out, vmFlags);
    out.put((byte)(isNativeDebuggable ? 1 : 0));

    Chunk reply = new Chunk(CHUNK_HELO, out);

    /*
     * Take the opportunity to inform DDMS if we are waiting for a
     * debugger to attach.
     */
    if (Debug.waitingForDebugger())
        sendWAIT(0);

    return reply;
}