// A class that we can use to keep track of the output of this test. privatestaticclass TestWatcher implements Consumer<String> { private StringBuilder sb; public TestWatcher() {
sb = new StringBuilder();
}
publicstaticvoid doTest(Transform t, TestWatcher w) { // Get the methods that need to be optimized.
Method say_hi_method; // Figure out if we can even JIT at all. finalboolean has_jit = hasJit(); try {
say_hi_method = Transform.class.getDeclaredMethod( "sayHi", Runnable.class, Consumer.class);
} catch (Exception e) {
System.out.println("Unable to find methods!");
e.printStackTrace(System.out); return;
} // Makes sure the stack is the way we want it for the test and does the redefinition. // It will set the retry boolean to true if the stack does not have a JIT-compiled // sayHi entry. This can only happen if the method gets GC'd.
Runnable do_redefinition = () -> { if (has_jit && Main.isInterpretedFunction(say_hi_method, true)) { // Try again. We are not running the right jitted methods/cannot redefine them now.
retry = true;
} else { // Actually do the redefinition. The stack looks good.
retry = false;
w.accept("transforming calling function");
Redefinition.doCommonClassRedefinition(Transform.class, CLASS_BYTES, DEX_BYTES);
}
}; // This just prints something out to show we are running the Runnable.
Runnable say_nothing = () -> { w.accept("Not doing anything here"); }; do { // Run ensureJitCompiled here since it might get GCd
ensureJitCompiled(Transform.class, "sayHi"); // Clear output.
w.clear(); // Try and redefine.
t.sayHi(say_nothing, w);
t.sayHi(do_redefinition, w);
t.sayHi(say_nothing, w);
} while (retry); // Print output of last run.
System.out.print(w.getOutput());
}
privatestaticnativeboolean hasJit();
privatestaticnativeboolean isInterpretedFunction(Method m, boolean require_deoptimizable);
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.