8339687: Rearrange reachabilityFence()s in jdk.test.lib.util.ForceGC
Reviewed-by: dholmes, smarks, kbarrett
This commit is contained in:
parent
d9fdf69c34
commit
51b85a1f69
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -78,29 +78,30 @@ public class ForceGC {
|
||||
ReferenceQueue<Object> queue = new ReferenceQueue<>();
|
||||
Object obj = new Object();
|
||||
PhantomReference<Object> ref = new PhantomReference<>(obj, queue);
|
||||
obj = null;
|
||||
Reference.reachabilityFence(obj);
|
||||
Reference.reachabilityFence(ref);
|
||||
try {
|
||||
obj = null;
|
||||
|
||||
int retries = (int)(timeout / 200);
|
||||
for (; retries >= 0; retries--) {
|
||||
if (booleanSupplier.getAsBoolean()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
// The remove() will always block for the specified milliseconds
|
||||
// if the reference has already been removed from the queue.
|
||||
// But it is fine. For most cases, the 1st GC is sufficient
|
||||
// to trigger and complete the cleanup.
|
||||
queue.remove(200L);
|
||||
} catch (InterruptedException ie) {
|
||||
// ignore, the loop will try again
|
||||
int retries = (int) (timeout / 200);
|
||||
for (; retries >= 0; retries--) {
|
||||
if (booleanSupplier.getAsBoolean()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
System.gc();
|
||||
|
||||
try {
|
||||
// The remove() will always block for the specified milliseconds
|
||||
// if the reference has already been removed from the queue.
|
||||
// But it is fine. For most cases, the 1st GC is sufficient
|
||||
// to trigger and complete the cleanup.
|
||||
queue.remove(200L);
|
||||
} catch (InterruptedException ie) {
|
||||
// ignore, the loop will try again
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
Reference.reachabilityFence(ref);
|
||||
}
|
||||
|
||||
return booleanSupplier.getAsBoolean();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user