privatestaticvoid testUnload() throws Exception { // Load a concrete class, then unload it. Get a deleted ArtMethod to test if it'll be inlined.
CHAUnloaderRetType result = doUnloadLoader();
WeakReference<ClassLoader> loader = result.cl; long methodPtr = result.methodPtr; // Check that the classloader is indeed unloaded. if (loader.get() != null) { thrownew Error("Expected class loader to be unloaded");
}
// Reuse the linear alloc used by the unloaded class loader.
reuseArenaOfMethod(methodPtr);
// Try to JIT-compile under dangerous conditions.
ensureJitCompiled(Main.class, "targetMethodForJit");
System.out.println("Done");
}
privatestaticvoid doUnloading() { // Do multiple GCs to prevent rare flakiness if some other thread is keeping the // classloader live. for (int i = 0; i < 5; ++i) {
Runtime.getRuntime().gc();
}
}
// Get a pointer to a region that shall be not used after the unloading. long artMethod = getArtMethod(lonelyMethod);
AbstractCHATester ret = null; returnnew CHAUnloaderRetType(new WeakReference(loader), ret, artMethod);
}
privatestatic CHAUnloaderRetType targetMethodForJit(int mode) throws Exception {
CHAUnloaderRetType ret = new CHAUnloaderRetType(null, null, 0); if (mode == 0) {
ret = setupLoader();
} elseif (mode == 1) { // This branch is not supposed to be executed. It shall trigger "lonelyMethod" inlining // during jit compilation of "targetMethodForJit".
ret = setupLoader();
AbstractCHATester obj = ret.obj;
obj.lonelyMethod();
} return ret;
}
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.