// Note that this is run with a tiny heap. // See b/260228356 for some discussion. It's unclear if and how this reliably forces an // OOME. For now, we're keeping this around because it appears to have detected some bugs // in the past. It may need revisiting.
publicstaticvoid main(String[] args) throws Exception { // Wait for system daemons to start, so that we minimize the chances of // a system daemon still starting up if/when we run out of memory. try { Thread.sleep(100);
} catch (InterruptedException e) {
System.out.println("Unexpected interrupt:" + e);
}
finalThread[] threads = newThread[numberOfThreads]; for (int t = 0; t < threads.length; t++) {
threads[t] = newThread((t % 2 == 0) ? new ProxyRunner() : new SyncRunner());
} for (Thread t : threads) {
t.start();
}
// Now wait. for (Thread t : threads) {
t.join();
}
finish = true;
garbageThread.join();
}
privatestaticinterface SimpleInterface { // Add some primitives to force some allocation when calling. publicvoid foo(int i1, int i2, int i3, int i4, int i5, int i6);
}
privatestaticclass ProxyRunner implements Runnable { publicvoid run() { int count = totalOperations; while (count > 0) { synchronized (lockObject) { try {
inf.foo(10000 - count, 11000 - count, 12000 - count, 13000 - count, 14000 - count, 15000 - count);
} catch (OutOfMemoryError e) { // Ignore errors. This is the test for b/69121347 - see an exception // instead of native abort.
}
}
count--;
}
}
}
privatestaticclass SyncRunner implements Runnable { publicvoid run() { int count = totalOperations; while (count > 0) { synchronized (lockObject) { // "Wait" a small amount of time. long start = System.nanoTime(); long delta = 10 * 1000; // 10 us. long elapsed; do {
elapsed = System.nanoTime();
} while (elapsed - start < delta);
}
count--;
}
}
}
privatestaticclass GarbageRunner implements Runnable { publicvoid run() { while (!finish) { // Some random allocations adding up to almost 2M. for (int i = 0; i < 188; i++) { try { byte b[] = newbyte[i * 100 + 10];
} catch (OutOfMemoryError e) { // Ignore. This is just to improve chances that an OOME is thrown during // proxy invocation.
}
} try { Thread.sleep(10);
} catch (Exception e) {
System.out.println("Unexpected exception in sleep():" + e);
}
}
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.