// 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) { final TestWatcher reporter = new TestWatcher();
Method say_hi_method;
Method private_say_hi_method; // Figure out if we can even JIT at all. finalboolean has_jit = hasJit(); try {
say_hi_method = Transform.class.getDeclaredMethod( "sayHi", int.class, Consumer.class, Runnable.class);
private_say_hi_method = Transform.class.getDeclaredMethod( "privateSayHi", int.class, Consumer.class, Runnable.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 we need to go around again due to jit code being GCd.
Runnable do_redefinition = () -> { if (has_jit &&
(Main.isInterpretedFunction(say_hi_method, true) ||
Main.isInterpretedFunction(private_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;
reporter.accept("transforming calling function");
doCommonClassRedefinition(Transform.class, CLASS_BYTES, DEX_BYTES);
}
}; do { // Run ensureJitCompiled here since it might get GCd
ensureJitCompiled(Transform.class, "sayHi");
ensureJitCompiled(Transform.class, "privateSayHi"); // We want to make sure sayHi method gets deoptimized. So we cannot allow any runtime frames // between sayHi and the run method where the transformation is happening. If the run method // is interpreted there will be a runtime frame to transition from JIT to interpreted code. // So ensure the run method is JITed too, so we don't loop for a long time in the hope of // getting the run method JITed.
ensureJitCompiled(do_redefinition.getClass(), "run"); // Clear output.
reporter.clear();
t.sayHi(2, reporter, () -> { reporter.accept("Not doing anything here"); });
t.sayHi(2, reporter, do_redefinition);
t.sayHi(2, reporter, () -> { reporter.accept("Not doing anything here"); });
} while(retry);
System.out.println(reporter.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.