for (int i = 0; i < 10; i++) { try {
test(); return;
} catch (ScopedAssertNoGc.NoGcAssertionFailure e) { // This should rarely happen. When it happens, reset the state, delete the profile, // and try again.
reset();
sFile.delete();
}
}
// The possibility of hitting this line only exists in theory, unless the test is wrong. thrownew RuntimeException("NoGcAssertionFailure occurred 10 times");
}
privatestaticvoid test() throws Exception {
Derived1 derived1 = new Derived1();
Derived2 derived2 = new Derived2();
// This method is below the inline cache threshold.
ensureJitBaselineCompiled(sMethod1); try (ScopedAssertNoGc noGc = new ScopedAssertNoGc()) {
$noinline$method1(derived1); for (int i = 0; i < 2998; i++) {
$noinline$method1(derived2);
}
}
checkMethodHasNoInlineCache(sFile, sMethod1);
// This method is right on the inline cache threshold.
ensureJitBaselineCompiled(sMethod2); try (ScopedAssertNoGc noGc = new ScopedAssertNoGc()) {
$noinline$method2(derived1); for (int i = 0; i < 2999; i++) {
$noinline$method2(derived2);
}
}
checkMethodHasInlineCache(sFile, sMethod2, Derived1.class, Derived2.class);
// This method is above the inline cache threshold.
ensureJitBaselineCompiled(sMethod3); try (ScopedAssertNoGc noGc = new ScopedAssertNoGc()) { for (int i = 0; i < 10000; i++) {
$noinline$method3(derived1);
} for (int i = 0; i < 10000; i++) {
$noinline$method3(derived2);
}
}
checkMethodHasInlineCache(sFile, sMethod3, Derived1.class, Derived2.class);
// This method is above the JIT threshold.
ensureJitBaselineCompiled(sMethod4); try (ScopedAssertNoGc noGc = new ScopedAssertNoGc()) {
$noinline$method4(derived1);
$noinline$method4(derived2);
}
ensureMethodJitCompiled(sMethod4);
checkMethodHasInlineCache(sFile, sMethod4, Derived1.class, Derived2.class);
// This method is above the JIT threshold.
ensureJitBaselineCompiled(sMethod5); try (ScopedAssertNoGc noGc = new ScopedAssertNoGc()) {
$noinline$method5(derived1);
$noinline$method5(derived2);
}
ensureMethodJitCompiled(sMethod5); // We currently do not encode inlined inline caches.
checkMethodHasNoInlineCache(sFile, sMethod5);
}
publicstaticclass Derived1 extends Base {
@Override publicvoid f() {}
}
publicstaticclass Derived2 extends Base {
@Override publicvoid f() {}
}
privatestaticvoid checkMethodHasInlineCache(File file, Method m, Class<?>... targetTypes) {
ensureProfileProcessing(); if (!hasInlineCacheInProfile(file.getPath(), m, targetTypes)) { thrownew RuntimeException("Expected method " + m
+ " to have inline cache in the profile with target types "
+ Arrays.stream(targetTypes)
.map(Class::getName)
.collect(Collectors.joining(", ")));
}
}
privatestaticvoid checkMethodHasNoInlineCache(File file, Method m) {
ensureProfileProcessing(); if (hasInlineCacheInProfile(file.getPath(), m)) { thrownew RuntimeException( "Expected method " + m + " not to have inline cache in the profile");
}
}
// This scope is intended to guard code that doesn't expect GC to take place. Because we can't // really prevent GC in Java code (calling a native method that enters a GCCriticalSection will // cause the runtime to hang forever when transitioning from native back to Java), this is a // workaround that forces a GC at the beginning so that GC will unlikely take place within the // scope. If a GC still takes place within the scope, this will throw NoGcAssertionFailure. // // The baseline code doesn't update the inline cache if we are marking, so we use this scope to // guard calls to virtual methods for which we want inline cache to be updated. privatestaticclass ScopedAssertNoGc implements AutoCloseable { privatefinalint mLastGcNum;
public ScopedAssertNoGc() {
System.gc();
mLastGcNum = getCurrentGcNum();
}
@Override publicvoid close() throws NoGcAssertionFailure { int currentGcNum = getCurrentGcNum(); if (currentGcNum != mLastGcNum) { thrownew NoGcAssertionFailure(
String.format("GC happened within the scope (before: %d, after: %d)",
mLastGcNum, currentGcNum));
}
}
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.