publicstaticvoid doTest() throws Exception { // Use a list to ensure objects must be allocated.
ArrayList<Object> l = new ArrayList<>(100);
setupGcCallback();
enableGcTracking(true);
run(l);
enableGcTracking(false);
// Run a blocking GC before doing the next run to ensure that if any concurrent GC was in // flight when we disabled GC-tracking, then it finishes and the gc-thread would not spuriously // increment gc-finish count.
Runtime.getRuntime().gc(); // Fetch gc counts as that also resets them.
getGcStarts();
getGcFinishes();
// Note: the reporting will not depend on the heap layout (which could be unstable). Walking // the tag table should give us a stable output order. for (int i = 10; i <= 1000; i *= 10) {
allocate(l, i);
}
l.clear();
Runtime.getRuntime().gc();
printStats();
Runtime.getRuntime().gc();
printStats();
}
privatestaticvoid allocate(ArrayList<Object> l, long tag) {
Object obj = new Object();
l.add(obj);
}
privatestaticvoid printStats() {
System.out.println("---"); int s = getGcStarts(); int f = getGcFinishes();
System.out.println((s > 0) + " " + (f > 0));
}
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.