use of dalvik.system.VMRuntime in project android_frameworks_base by ParanoidAndroid.
the class ZygoteInit method preloadResources.
/**
* 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();
Debug.startAllocCounting();
try {
System.gc();
runtime.runFinalizationSync();
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(runtime, 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(runtime, ar);
ar.recycle();
Log.i(TAG, "...preloaded " + N + " resources in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
} else {
Log.i(TAG, "Preload resources disabled, skipped.");
}
mResources.finishPreloading();
} catch (RuntimeException e) {
Log.w(TAG, "Failure preloading resources", e);
} finally {
Debug.stopAllocCounting();
}
}
use of dalvik.system.VMRuntime in project robovm by robovm.
the class MemoryTest method testSetShortArray.
public void testSetShortArray() {
short[] values = { 0x0001, 0x0020, 0x0300, 0x4000 };
short[] swappedValues = { 0x0100, 0x2000, 0x0003, 0x0040 };
int scale = SizeOf.SHORT;
VMRuntime runtime = VMRuntime.getRuntime();
byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, scale * values.length + 1);
long base_ptr = runtime.addressOf(array);
for (long ptr_offset = 0; ptr_offset < 2; ++ptr_offset) {
// To test aligned and unaligned accesses.
long ptr = base_ptr + ptr_offset;
Arrays.fill(array, (byte) 0);
// Regular copy.
Memory.pokeShortArray(ptr, values, 0, values.length, false);
assertShortsEqual(values, ptr, false);
assertShortsEqual(swappedValues, ptr, true);
// Swapped copy.
Memory.pokeShortArray(ptr, values, 0, values.length, true);
assertShortsEqual(values, ptr, true);
assertShortsEqual(swappedValues, ptr, false);
// Swapped copies of slices (to ensure we test non-zero offsets).
for (int i = 0; i < values.length; ++i) {
Memory.pokeShortArray(ptr + i * scale, values, i, 1, true);
}
assertShortsEqual(values, ptr, true);
assertShortsEqual(swappedValues, ptr, false);
}
}
use of dalvik.system.VMRuntime in project robovm by robovm.
the class MemoryTest method testSetLongArray.
public void testSetLongArray() {
long[] values = { 0x1020304050607080L, 0xffeeddccbbaa9988L };
long[] swappedValues = new long[values.length];
for (int i = 0; i < values.length; ++i) {
swappedValues[i] = Long.reverseBytes(values[i]);
}
int scale = SizeOf.LONG;
VMRuntime runtime = VMRuntime.getRuntime();
byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, scale * values.length + 1);
long base_ptr = runtime.addressOf(array);
for (long ptr_offset = 0; ptr_offset < 2; ++ptr_offset) {
// To test aligned and unaligned accesses.
long ptr = base_ptr + ptr_offset;
Arrays.fill(array, (byte) 0);
// Regular copy.
Memory.pokeLongArray(ptr, values, 0, values.length, false);
assertLongsEqual(values, ptr, false);
assertLongsEqual(swappedValues, ptr, true);
// Swapped copy.
Memory.pokeLongArray(ptr, values, 0, values.length, true);
assertLongsEqual(values, ptr, true);
assertLongsEqual(swappedValues, ptr, false);
// Swapped copies of slices (to ensure we test non-zero offsets).
for (int i = 0; i < values.length; ++i) {
Memory.pokeLongArray(ptr + i * scale, values, i, 1, true);
}
assertLongsEqual(values, ptr, true);
assertLongsEqual(swappedValues, ptr, false);
}
}
use of dalvik.system.VMRuntime in project XobotOS by xamarin.
the class ZygoteInit method preloadResources.
/**
* 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();
Debug.startAllocCounting();
try {
System.gc();
runtime.runFinalizationSync();
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(runtime, ar);
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(runtime, ar);
Log.i(TAG, "...preloaded " + N + " resources in " + (SystemClock.uptimeMillis() - startTime) + "ms.");
}
mResources.finishPreloading();
} catch (RuntimeException e) {
Log.w(TAG, "Failure preloading resources", e);
} finally {
Debug.stopAllocCounting();
}
}
use of dalvik.system.VMRuntime in project robovm by robovm.
the class System method initSystemProperties.
private static void initSystemProperties() {
VMRuntime runtime = VMRuntime.getRuntime();
Properties p = new Properties();
String projectUrl = "http://www.robovm.org/";
String projectName = "RoboVM";
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");
// RoboVM note: Android uses getenv("JAVA_HOME") here with "/system" as fallback.
p.put("java.home", VM.resourcesPath());
// RoboVM note: Use value of $TMPDIR if set. Otherwise use /tmp as Android does.
String tmpdir = getenv("TMPDIR");
p.put("java.io.tmpdir", tmpdir != null ? tmpdir : "/tmp");
String ldLibraryPath = getenv("LD_LIBRARY_PATH");
if (ldLibraryPath != null) {
p.put("java.library.path", ldLibraryPath);
}
p.put("java.specification.name", "RoboVM 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", "RoboVM");
p.put("java.vm.specification.name", "RoboVM 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", "RoboVM 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");
try {
StructPasswd passwd = Libcore.os.getpwuid(Libcore.os.getuid());
p.put("user.home", passwd.pw_dir);
p.put("user.name", passwd.pw_name);
} catch (ErrnoException exception) {
// RoboVM note: Start change. Fall back to environment variables. getpwuid() fails on the iOS simulator.
String home = getenv("HOME");
String user = getenv("USER");
p.put("user.home", home != null ? home : "");
p.put("user.name", user != null ? user : "");
// RoboVM note: End change.
}
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());
p.put("android.icu.cldr.version", ICU.getCldrVersion());
parsePropertyAssignments(p, specialProperties());
parsePropertyAssignments(p, robovmSpecialProperties());
// user.home, user.dir and user.name values on iOS.
if (p.getProperty("os.name").contains("iOS")) {
// On iOS we want user.home and user.dir to point to the app's data
// container root dir. This is the dir $HOME points to. We also set
// user.name to $USER or hardcode 'mobile' if $USER isn't set (iOS
// simulator).
String home = getenv("HOME");
String user = getenv("USER");
p.put("user.home", home != null ? home : "");
p.put("user.dir", home != null ? home : "/");
p.put("user.name", user != null ? user : "mobile");
}
// RoboVM note: End change.
// Override built-in properties with settings from the command line.
parsePropertyAssignments(p, runtime.properties());
systemProperties = p;
}
Aggregations