Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate creation of InnocuousThreads - to facilitate use of java.lang.ref.Cleaner #77788 #77789

Merged
merged 3 commits into from
Sep 16, 2021
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ private void debugThreadGroups(final ThreadGroup caller, final ThreadGroup targe
private static final Permission MODIFY_THREAD_PERMISSION = new RuntimePermission("modifyThread");
private static final Permission MODIFY_ARBITRARY_THREAD_PERMISSION = new ThreadPermission("modifyArbitraryThread");

// Returns true if the given thread is an instance of the JDK's InnocuousThread.
private static boolean isInnocuousThread(Thread t) {
final Class<?> c = t.getClass();
return c.getModule() == Object.class.getModule() && c.getName().equals("jdk.internal.misc.InnocuousThread");
}

protected void checkThreadAccess(Thread t) {
Objects.requireNonNull(t);

Expand All @@ -166,7 +172,7 @@ protected void checkThreadAccess(Thread t) {

if (target == null) {
return; // its a dead thread, do nothing.
} else if (source.parentOf(target) == false) {
} else if (source.parentOf(target) == false && isInnocuousThread(t) == false) {
checkPermission(MODIFY_ARBITRARY_THREAD_PERMISSION);
}
}
Expand Down