use of dalvik.system.VMRuntime in project XobotOS by xamarin.
the class ZygoteInit method gc.
/**
* 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 gc() {
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();
runtime.runFinalizationSync();
System.gc();
runtime.runFinalizationSync();
}
use of dalvik.system.VMRuntime in project XobotOS by xamarin.
the class MemoryBlock method allocate.
public static MemoryBlock allocate(int byteCount) {
VMRuntime runtime = VMRuntime.getRuntime();
byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, byteCount);
int address = (int) runtime.addressOf(array);
return new NonMovableHeapBlock(array, address, byteCount);
}
use of dalvik.system.VMRuntime in project XobotOS by xamarin.
the class System method initSystemProperties.
private static void initSystemProperties() {
VMRuntime runtime = VMRuntime.getRuntime();
Properties p = new Properties();
String projectUrl = "http://www.android.com/";
String projectName = "The Android Project";
p.put("java.boot.class.path", runtime.bootClassPath());
p.put("java.class.path", runtime.classPath());
// None of these four are meaningful on Android, but these keys are guaranteed
// to be present for System.getProperty. For java.class.version, we use the maximum
// class file version that dx currently supports.
p.put("java.class.version", "50.0");
p.put("java.compiler", "");
p.put("java.ext.dirs", "");
p.put("java.version", "0");
p.put("java.home", getenv("JAVA_HOME", "/system"));
p.put("java.io.tmpdir", "/tmp");
p.put("java.library.path", getenv("LD_LIBRARY_PATH"));
p.put("java.specification.name", "Dalvik Core Library");
p.put("java.specification.vendor", projectName);
p.put("java.specification.version", "0.9");
p.put("java.vendor", projectName);
p.put("java.vendor.url", projectUrl);
p.put("java.vm.name", "Dalvik");
p.put("java.vm.specification.name", "Dalvik Virtual Machine Specification");
p.put("java.vm.specification.vendor", projectName);
p.put("java.vm.specification.version", "0.9");
p.put("java.vm.vendor", projectName);
p.put("java.vm.version", runtime.vmVersion());
p.put("file.separator", "/");
p.put("line.separator", "\n");
p.put("path.separator", ":");
p.put("java.runtime.name", "Android Runtime");
p.put("java.runtime.version", "0.9");
p.put("java.vm.vendor.url", projectUrl);
p.put("file.encoding", "UTF-8");
p.put("user.language", "en");
p.put("user.region", "US");
p.put("user.home", getenv("HOME", ""));
p.put("user.name", getenv("USER", ""));
StructUtsname info = Libcore.os.uname();
p.put("os.arch", info.machine);
p.put("os.name", info.sysname);
p.put("os.version", info.release);
// Undocumented Android-only properties.
p.put("android.icu.library.version", ICU.getIcuVersion());
p.put("android.icu.unicode.version", ICU.getUnicodeVersion());
// TODO: it would be nice to have this but currently it causes circularity.
// p.put("android.tzdata.version", ZoneInfoDB.getVersion());
parsePropertyAssignments(p, specialProperties());
// Override built-in properties with settings from the command line.
parsePropertyAssignments(p, runtime.properties());
systemProperties = p;
}
use of dalvik.system.VMRuntime in project android_frameworks_base by ResurrectionRemix.
the class ZygoteInit method preloadClasses.
/**
* Performs Zygote process initialization. Loads and initializes
* commonly used classes.
*
* Most classes only cause a few hundred bytes to be allocated, but
* a few will allocate a dozen Kbytes (in one case, 500+K).
*/
private static void preloadClasses() {
final VMRuntime runtime = VMRuntime.getRuntime();
InputStream is;
try {
is = new FileInputStream(PRELOADED_CLASSES);
} catch (FileNotFoundException e) {
Log.e(TAG, "Couldn't find " + PRELOADED_CLASSES + ".");
return;
}
Log.i(TAG, "Preloading classes...");
long startTime = SystemClock.uptimeMillis();
// Drop root perms while running static initializers.
final int reuid = Os.getuid();
final int regid = Os.getgid();
// We need to drop root perms only if we're already root. In the case of "wrapped"
// processes (see WrapperInit), this function is called from an unprivileged uid
// and gid.
boolean droppedPriviliges = false;
if (reuid == ROOT_UID && regid == ROOT_GID) {
try {
Os.setregid(ROOT_GID, UNPRIVILEGED_GID);
Os.setreuid(ROOT_UID, UNPRIVILEGED_UID);
} catch (ErrnoException ex) {
throw new RuntimeException("Failed to drop root", ex);
}
droppedPriviliges = true;
}
// Alter the target heap utilization. With explicit GCs this
// is not likely to have any effect.
float defaultUtilization = runtime.getTargetHeapUtilization();
runtime.setTargetHeapUtilization(0.8f);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(is), 256);
int count = 0;
String line;
while ((line = br.readLine()) != null) {
// Skip comments and blank lines.
line = line.trim();
if (line.startsWith("#") || line.equals("")) {
continue;
}
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, line);
try {
if (false) {
Log.v(TAG, "Preloading " + line + "...");
}
// Load and explicitly initialize the given class. Use
// Class.forName(String, boolean, ClassLoader) to avoid repeated stack lookups
// (to derive the caller's class-loader). Use true to force initialization, and
// null for the boot classpath class-loader (could as well cache the
// class-loader of this class in a variable).
Class.forName(line, true, null);
count++;
} catch (ClassNotFoundException e) {
Log.w(TAG, "Class not found for preloading: " + line);
} catch (UnsatisfiedLinkError e) {
Log.w(TAG, "Problem preloading " + line + ": " + e);
} catch (Throwable t) {
Log.e(TAG, "Error preloading " + line + ".", t);
if (t instanceof Error) {
throw (Error) t;
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
throw new RuntimeException(t);
}
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
}
Log.i(TAG, "...preloaded " + count + " classes in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
} catch (IOException e) {
Log.e(TAG, "Error reading " + PRELOADED_CLASSES + ".", e);
} finally {
IoUtils.closeQuietly(is);
// Restore default.
runtime.setTargetHeapUtilization(defaultUtilization);
// Fill in dex caches with classes, fields, and methods brought in by preloading.
Trace.traceBegin(Trace.TRACE_TAG_DALVIK, "PreloadDexCaches");
runtime.preloadDexCaches();
Trace.traceEnd(Trace.TRACE_TAG_DALVIK);
// Bring back root. We'll need it later if we're in the zygote.
if (droppedPriviliges) {
try {
Os.setreuid(ROOT_UID, ROOT_UID);
Os.setregid(ROOT_GID, ROOT_GID);
} catch (ErrnoException ex) {
throw new RuntimeException("Failed to restore root", ex);
}
}
}
}
use of dalvik.system.VMRuntime in project android_frameworks_base by ResurrectionRemix.
the class DdmHandleHello method handleHELO.
/*
* Handle introductory packet. This is called during JNI_CreateJavaVM
* before frameworks native methods are registered, so be careful not
* to call any APIs that depend on frameworks native code.
*/
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;
}
Aggregations