publicclass Test904 { publicstaticvoid run() throws Exception { // Use a list to ensure objects must be allocated.
ArrayList<Object> l = new ArrayList<>(100);
prefetchClassNames();
doTest(l);
}
// Pre-resolve class names so the strings don't have to be allocated as a side effect of // callback printing. privatestaticvoid prefetchClassNames() {
Object.class.getName();
Integer.class.getName(); Float.class.getName(); Short.class.getName(); Byte.class.getName(); Double.class.getName();
}
publicstaticvoid doTest(ArrayList<Object> l) throws Exception { // Disable the global registration from OnLoad, to get into a known state.
enableAllocationTracking(null, false);
// Enable actual logging callback.
setupObjectAllocCallback(true);
System.out.println(Arrays.toString(getTrackingEventMessages( newThread[] { Thread.currentThread(), })));
System.out.println("Tracking on same thread");
Thread test_thread = testThread(l, true, true);
l.add(newByte((byte)0));
System.out.println(Arrays.toString(getTrackingEventMessages( newThread[] { Thread.currentThread(), test_thread, })));
System.out.println("Tracking on same thread, not disabling tracking");
test_thread = testThread(l, true, false);
System.out.println(Arrays.toString(getTrackingEventMessages( newThread[] { Thread.currentThread(), test_thread, })));
System.out.println("Tracking on different thread");
test_thread = testThread(l, false, true);
l.add(newByte((byte)0));
// Disable actual logging callback and re-enable tracking, so we can keep // the event enabled and check that shutdown works correctly.
setupObjectAllocCallback(false);
privatestaticThread testThread(final ArrayList<Object> l, finalboolean sameThread, finalboolean disableTracking) throws Exception { final SimpleBarrier startBarrier = new SimpleBarrier(1); final SimpleBarrier trackBarrier = new SimpleBarrier(1); final SimpleBarrier disableBarrier = new SimpleBarrier(1);
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.