privatestaticvoid runDebuggee() {
System.out.println("Running debuggee");
ClassLoader loader = new TestClassLoader(); for (int index = 0; index < NUM_CLASSES; index++) { try { if (index < NUM_ALT_CLASSES) { Class.forName(CLASS_NAME_ALT_PREFIX + index, true, loader);
} else { Class.forName(CLASS_NAME_PREFIX + index, true, loader);
}
} catch (Exception e) { thrownew RuntimeException("Failed to create Sample class", e);
}
}
loader = null;
// Do a short delay to make sure that the debug agent is done processing all // ClassPrepare events. Otherwise the debug agent might still be holding on to // a reference to a class, which will prevent it from unloading during the GC. try { Thread.sleep(5000);
} catch (InterruptedException e) {
}
// Trigger class unloading
ClassUnloadCommon.triggerUnloading();
// We rely on JVMTI to post all pending ObjectFree events at VM shutdown. // It will trigger the JDWP agent to synthesize expected ClassUnloadEvents events.
System.out.println("Exiting debuggee");
}
privatestaticvoid runDebugger() throws Exception {
System.out.println("Running debugger");
HashSet<String> unloadedSampleClasses = new HashSet<>();
HashSet<String> unloadedSampleClasses_alt = new HashSet<>();
VirtualMachine vm = null;
vm = connectAndLaunchVM();
ClassUnloadRequest classUnloadRequest = vm.eventRequestManager().createClassUnloadRequest();
classUnloadRequest.addClassFilter(CLASS_NAME_PREFIX + "*");
classUnloadRequest.enable();
// The unloaded class should always match CLASS_NAME_PREFIX. if (className.indexOf(CLASS_NAME_PREFIX) == -1) { thrownew RuntimeException("FAILED: Unexpected unloaded class: " + className);
}
// Unloaded classes with ALT names should only occur on the classUnloadRequest_alt. if (event.request() == classUnloadRequest_alt) {
unloadedSampleClasses_alt.add(className); if (className.indexOf(CLASS_NAME_ALT_PREFIX) == -1) { thrownew RuntimeException("FAILED: non-alt class unload event for classUnloadRequest_alt.");
}
} else {
unloadedSampleClasses.add(className);
}
// If the unloaded class matches the ALT prefix, then we should have // unload events in this EventSet for each of the two ClassUnloadRequesta. int expectedEventSetSize; if (className.indexOf(CLASS_NAME_ALT_PREFIX) != -1) {
expectedEventSetSize = 2;
} else {
expectedEventSetSize = 1;
} if (eventSet.size() != expectedEventSetSize) { thrownew RuntimeException("FAILED: Unexpected eventSet size: " + eventSet.size());
}
}
/* Dump debuggee output. */
Process p = vm.process();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String line = in.readLine(); while (line != null) {
System.out.println("stdout: " + line);
line = in.readLine();
}
line = err.readLine(); while (line != null) {
System.out.println("stderr: " + line);
line = err.readLine();
}
if (unloadedSampleClasses.size() != NUM_CLASSES) { thrownew RuntimeException("Wrong number of class unload events: expected " + NUM_CLASSES + " got " + unloadedSampleClasses.size());
} if (unloadedSampleClasses_alt.size() != NUM_ALT_CLASSES) { thrownew RuntimeException("Wrong number of alt class unload events: expected " + NUM_ALT_CLASSES + " got " + unloadedSampleClasses_alt.size());
}
}
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.