Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions test/lib/jdk/test/whitebox/WhiteBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
package jdk.test.whitebox;

import java.lang.management.MemoryUsage;
import java.lang.ref.Reference;
import java.lang.reflect.Executable;
import java.lang.reflect.InaccessibleObjectException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -434,6 +438,53 @@ public void clearInlineCaches(boolean preserve_static_stubs) {
// Force Full GC
public native void fullGC();

// Infrastructure for waitForReferenceProcessing()
private static volatile Method waitForReferenceProcessingMethod = null;

private static Method getWaitForReferenceProcessingMethod() {
Method wfrp = waitForReferenceProcessingMethod;
if (wfrp == null) {
try {
wfrp = Reference.class.getDeclaredMethod("waitForReferenceProcessing");
wfrp.setAccessible(true);
assert wfrp.getReturnType() == Boolean.class;
Class<?>[] ev = wfrp.getExceptionTypes();
assert ev.length == 1;
assert ev[0] == InterruptedException.class;
waitForReferenceProcessingMethod = wfrp;
} catch (InaccessibleObjectException e) {
throw new RuntimeException("Need to add @modules java.base/java.lang.ref:open to test?", e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
return wfrp;
}

/**
* Wait for reference processing, via Reference.waitForReferenceProcessing().
* Callers of this method will need the
* @modules java.base/java.lang.ref:open
* jtreg tag.
*
* This method should usually be called after a call to WhiteBox.fullGC().
*/
public boolean waitForReferenceProcessing() throws InterruptedException {
try {
Method wfrp = getWaitForReferenceProcessingMethod();
return (Boolean) wfrp.invoke(null);
} catch (IllegalAccessException e) {
throw new RuntimeException("Shouldn't happen, we call setAccessible()", e);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
if (cause instanceof InterruptedException) {
throw (InterruptedException) cause;
} else {
throw new RuntimeException(e);
}
}
}

// Returns true if the current GC supports concurrent collection control.
public native boolean supportsConcurrentGCBreakpoints();

Expand Down