mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8276422: Add command-line option to disable finalization
Co-authored-by: David Holmes <dholmes@openjdk.org> Co-authored-by: Brent Christian <bchristi@openjdk.org> Reviewed-by: dholmes, kbarrett, bchristi
This commit is contained in:
parent
ec7cb6d5d3
commit
d7ad546758
13 changed files with 265 additions and 17 deletions
|
@ -61,9 +61,17 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
|||
return queue;
|
||||
}
|
||||
|
||||
static final boolean ENABLED = isFinalizationEnabled();
|
||||
|
||||
private static native boolean isFinalizationEnabled();
|
||||
|
||||
/* Invoked by VM */
|
||||
static void register(Object finalizee) {
|
||||
new Finalizer(finalizee);
|
||||
if (ENABLED) {
|
||||
new Finalizer(finalizee);
|
||||
} else {
|
||||
throw new InternalError("unexpected call to Finalizer::register when finalization is disabled");
|
||||
}
|
||||
}
|
||||
|
||||
private void runFinalizer(JavaLangAccess jla) {
|
||||
|
@ -130,7 +138,7 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
|||
|
||||
/* Called by Runtime.runFinalization() */
|
||||
static void runFinalization() {
|
||||
if (VM.initLevel() == 0) {
|
||||
if (VM.initLevel() == 0 || ! ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -182,14 +190,16 @@ final class Finalizer extends FinalReference<Object> { /* Package-private; must
|
|||
}
|
||||
|
||||
static {
|
||||
ThreadGroup tg = Thread.currentThread().getThreadGroup();
|
||||
for (ThreadGroup tgn = tg;
|
||||
tgn != null;
|
||||
tg = tgn, tgn = tg.getParent());
|
||||
Thread finalizer = new FinalizerThread(tg);
|
||||
finalizer.setPriority(Thread.MAX_PRIORITY - 2);
|
||||
finalizer.setDaemon(true);
|
||||
finalizer.start();
|
||||
if (ENABLED) {
|
||||
ThreadGroup tg = Thread.currentThread().getThreadGroup();
|
||||
for (ThreadGroup tgn = tg;
|
||||
tgn != null;
|
||||
tg = tgn, tgn = tg.getParent());
|
||||
Thread finalizer = new FinalizerThread(tg);
|
||||
finalizer.setPriority(Thread.MAX_PRIORITY - 2);
|
||||
finalizer.setDaemon(true);
|
||||
finalizer.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue