publicclass Main { staticvolatileboolean done = false;
publicstaticvoid main(String[] args) { // Run a thread for 30 seconds, allocating memory and triggering garbage // collection. // Time is limited to 30 seconds to not make this test too long. The test used // to trigger the failure around 1 every 10 runs. Thread t = newThread() { publicvoid run() { long time = System.currentTimeMillis(); while (System.currentTimeMillis() - time < 30000) { for (int j = 0; j < 10000; j++) {
o = new Object[1000];
}
Runtime.getRuntime().gc(); Thread.yield();
}
Main.done = true;
}
Object o;
}; // Make the thread a daemon to quit early in case of an // exception thrown below.
t.setDaemon(true);
t.start();
// Run 'foo' as long as the test runs. while (!done) { double res = foo(staticMain); if (res != 529.0) { thrownew Error("Unexpected result " + res);
}
}
}
// Trigger a read barrier. This used to make the test trip on ARM64 as // the read barrier stub used to not restore the D registers. double p = main.objectField.field1;
// Initialize objects here and not in 'main' to avoid having // these objects in roots. publicstatic Main staticMain = new Main(); static {
staticMain.objectField = new Main();
}
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.