staticint $noinline$runHotMethod(boolean doComputation) { if (doComputation) { for (int i = 0; i < 100000; i++) {
staticValue1 += staticValue2;
}
} return staticValue1;
}
static { // Make $noinline$runHotMethod hot so it gets compiled. The // regression used to be that the JIT would incorrectly update the // resolution entrypoint of the method. The entrypoint needs to stay // the resolution entrypoint otherwise other threads may incorrectly // execute static methods of the class while the class is still being // initialized. for (int i = 0; i < 10; i++) {
$noinline$runHotMethod(true);
}
// Start another thread that will invoke a static method of InnerInitialized. newThread(new Runnable() { publicvoid run() { for (int i = 0; i < 100000; i++) {
$noinline$runInternalHotMethod(false);
} // Give some time for the JIT compiler to compile $noinline$runInternalHotMethod. // Only compiled code invoke the entrypoint of an ArtMethod. try { Thread.sleep(1000);
} catch (Exception e) {
} int value = $noinline$runInternalHotMethod(true); if (value != 42) { thrownew Error("Expected 42, got " + value);
}
}
publicint $noinline$runInternalHotMethod(boolean invokeStaticMethod) { if (invokeStaticMethod) { // The bug used to be here: the compiled code of $noinline$runInternalHotMethod // would invoke the entrypoint of $noinline$runHotMethod, which was incorrectly // updated to the JIT entrypoint and therefore not hitting the resolution // trampoline which would have waited for the class to be initialized. return $noinline$runHotMethod(false);
} return0;
}
}).start(); // Give some time for the JIT compiler to compile runHotMethod, and also for the // other thread to invoke $noinline$runHotMethod. // This wait should be longer than the other thread's wait to make sure the other // thread hits the $noinline$runHotMethod call before the initialization of // InnerInitialized is finished. try { Thread.sleep(5000);
} catch (Exception e) {
}
staticValue1 = 42;
}
}
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.