privatestaticvoid ensureTestWatcherInitialized() { try { // Make sure the TestWatcher class can be found from the Object <init> function.
addToBootClassLoader(LISTENER_LOCATION); // Load TestWatcher from the bootclassloader and make sure it is initialized. Class<?> testwatcher_class = Class.forName("art.test.TestWatcher", true, null);
doEnableReporting = testwatcher_class.getDeclaredMethod("EnableReporting");
doDisableReporting = testwatcher_class.getDeclaredMethod("DisableReporting");
} catch (Exception e) { thrownew Error("Exception while making testwatcher", e);
}
}
// NB This function will cause 2 objects of type "Ljava/nio/HeapCharBuffer;" and // "Ljava/nio/HeapCharBuffer;" to be allocated each time it is called. privatestaticvoid safePrintln(Object o) {
DisableReporting();
System.out.println("\t" + o);
EnableReporting();
}
publicstaticvoid doTest() {
safePrintln("Initializing and loading the TestWatcher class that will (eventually) be " + "notified of object allocations"); // Make sure the TestWatcher class is initialized before we do anything else.
ensureTestWatcherInitialized();
safePrintln("Allocating an j.l.Object before redefining Object class"); // Make sure these aren't shown.
Object o = new Object();
safePrintln("Allocating a Transform before redefining Object class");
Transform t = new Transform();
// Redefine the Object Class.
safePrintln("Redefining the Object class to add a hook into the <init> method");
addMemoryTrackingCall(Object.class, Thread.currentThread());
safePrintln("Allocating an j.l.Object after redefining Object class");
Object o2 = new Object();
safePrintln("Allocating a Transform after redefining Object class");
Transform t2 = new Transform();
// This shouldn't cause the Object constructor to be run.
safePrintln("Allocating an int[] after redefining Object class"); int[] abc = newint[12];
// Try adding stuff to an array list.
safePrintln("Allocating an array list");
ArrayList<Object> al = new ArrayList<>();
safePrintln("Adding a bunch of stuff to the array list");
al.add(new Object());
al.add(new Object());
al.add(o2);
al.add(o);
al.add(t);
al.add(t2);
al.add(new Transform());
// Try adding stuff to a LinkedList
safePrintln("Allocating a linked list");
LinkedList<Object> ll = new LinkedList<>();
safePrintln("Adding a bunch of stuff to the linked list");
ll.add(new Object());
ll.add(new Object());
ll.add(o2);
ll.add(o);
ll.add(t);
ll.add(t2);
ll.add(new Transform());
// Try making an exception.
safePrintln("Throwing from down 4 stack frames"); try {
throwFrom(4);
} catch (Exception e) {
safePrintln("Exception caught.");
}
safePrintln("Finishing test!");
}
// This is from 929-search/search.cc privatestaticnativevoid addToBootClassLoader(String s); // This is from 980-redefine-object/redef_object.cc // It will add a call to Lart/test/TestWatcher;->NotifyConstructed()V in the Object <init>()V // function. privatestaticnativevoid addMemoryTrackingCall(Class c, Thread thr);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.12 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.