Skip to content

Commit

Permalink
8327501: Common ForkJoinPool prevents class unloading in some cases
Browse files Browse the repository at this point in the history
8328366: Thread.setContextClassloader from thread in FJP commonPool task no longer works after JDK-8327501

Backport-of: 53c4714aab2e072ba18631875dcaa3b2d5d22243
  • Loading branch information
shipilev committed Aug 12, 2024
1 parent 27b1e1a commit eb103b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,7 @@ public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
boolean isCommon = (pool.workerNamePrefix == null);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm == null)
return new ForkJoinWorkerThread(null, pool, true, false);
else if (isCommon)
if (sm != null && isCommon)
return newCommonWithACC(pool);
else
return newRegularWithACC(pool);
Expand Down
8 changes: 8 additions & 0 deletions test/jdk/java/util/concurrent/tck/ForkJoinPool9Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public void testCommonPoolThreadContextClassLoader() throws Throwable {
assertSame(ForkJoinPool.commonPool(), ForkJoinTask.getPool());
Thread currentThread = Thread.currentThread();

ClassLoader preexistingContextClassLoader =
currentThread.getContextClassLoader();

Stream.of(systemClassLoader, null).forEach(cl -> {
if (randomBoolean())
// should always be permitted, without effect
Expand All @@ -95,6 +98,11 @@ public void testCommonPoolThreadContextClassLoader() throws Throwable {
() -> System.getProperty("foo"),
() -> currentThread.setContextClassLoader(
classLoaderDistinctFromSystemClassLoader));
else {
currentThread.setContextClassLoader(classLoaderDistinctFromSystemClassLoader);
assertSame(currentThread.getContextClassLoader(), classLoaderDistinctFromSystemClassLoader);
currentThread.setContextClassLoader(preexistingContextClassLoader);
}
// TODO ?
// if (haveSecurityManager
// && Thread.currentThread().getClass().getSimpleName()
Expand Down

1 comment on commit eb103b0

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.