|
35 | 35 | import java.lang.reflect.Modifier; |
36 | 36 | import java.nio.charset.CharsetDecoder; |
37 | 37 | import java.nio.charset.CoderResult; |
| 38 | +import java.security.AccessControlContext; |
| 39 | +import java.security.Permission; |
38 | 40 | import java.util.Map; |
39 | 41 | import java.util.concurrent.ConcurrentHashMap; |
40 | 42 | import java.util.concurrent.ConcurrentMap; |
|
46 | 48 | import java.util.concurrent.locks.ReentrantLock; |
47 | 49 | import java.util.function.Consumer; |
48 | 50 |
|
| 51 | +import org.graalvm.compiler.phases.common.LazyValue; |
49 | 52 | import org.graalvm.compiler.serviceprovider.GraalUnsafeAccess; |
50 | 53 | import org.graalvm.compiler.serviceprovider.JavaVersionUtil; |
51 | 54 | import org.graalvm.nativeimage.ImageSingletons; |
@@ -354,12 +357,70 @@ public static int getCommonPoolParallelism() { |
354 | 357 | @TargetElement(onlyWith = JDK8OrEarlier.class) |
355 | 358 | static native ForkJoinPool makeCommonPool(); |
356 | 359 |
|
| 360 | + @Alias // |
| 361 | + @TargetElement(onlyWith = JDK11OrLater.class) // |
| 362 | + public static native AccessControlContext contextWithPermissions(Permission... perms); |
| 363 | + |
357 | 364 | @Alias // |
358 | 365 | @TargetElement(onlyWith = JDK11OrLater.class) // |
359 | 366 | Target_java_util_concurrent_ForkJoinPool(byte forCommonPoolOnly) { |
360 | 367 | } |
361 | 368 | } |
362 | 369 |
|
| 370 | +/** |
| 371 | + * Since AccessControlContextFeature replaces all AccessControlContext objects with |
| 372 | + * NO_CONTEXT_SINGLETON, we need to reinitialize them in runtime. |
| 373 | + */ |
| 374 | +@TargetClass(className = "java.util.concurrent.ForkJoinPool$DefaultForkJoinWorkerThreadFactory", onlyWith = JDK11OrLater.class) |
| 375 | +@SuppressWarnings("unused") // |
| 376 | +final class Target_java_util_concurrent_ForkJoinPool_DefaultForkJoinWorkerThreadFactory { |
| 377 | + @Alias @InjectAccessors(DefaultForkJoinWorkerThreadFactoryAcc.class) static AccessControlContext ACC; |
| 378 | +} |
| 379 | + |
| 380 | +class DefaultForkJoinWorkerThreadFactoryAcc { |
| 381 | + static LazyValue<AccessControlContext> acc = new LazyValue<>(() -> AccessControllerUtil.contextWithPermissions( |
| 382 | + new RuntimePermission("getClassLoader"), |
| 383 | + new RuntimePermission("setContextClassLoader"))); |
| 384 | + |
| 385 | + static AccessControlContext get() { |
| 386 | + return acc.get(); |
| 387 | + } |
| 388 | +} |
| 389 | + |
| 390 | +@TargetClass(className = "java.util.concurrent.ForkJoinPool$InnocuousForkJoinWorkerThreadFactory", onlyWith = JDK11OrLater.class) |
| 391 | +@SuppressWarnings("unused") // |
| 392 | +final class Target_java_util_concurrent_ForkJoinPool_InnocuousForkJoinWorkerThreadFactory { |
| 393 | + @Alias @InjectAccessors(InnocuousForkJoinWorkerThreadFactoryAcc.class) static AccessControlContext ACC; |
| 394 | +} |
| 395 | + |
| 396 | +class InnocuousForkJoinWorkerThreadFactoryAcc { |
| 397 | + static LazyValue<AccessControlContext> acc = new LazyValue<>(() -> AccessControllerUtil.contextWithPermissions( |
| 398 | + new RuntimePermission("modifyThread"), |
| 399 | + new RuntimePermission("enableContextClassLoaderOverride"), |
| 400 | + new RuntimePermission("modifyThreadGroup"), |
| 401 | + new RuntimePermission("getClassLoader"), |
| 402 | + new RuntimePermission("setContextClassLoader"))); |
| 403 | + |
| 404 | + static AccessControlContext get() { |
| 405 | + return acc.get(); |
| 406 | + } |
| 407 | +} |
| 408 | + |
| 409 | +@TargetClass(className = "java.util.Calendar$CalendarAccessControlContext") |
| 410 | +@SuppressWarnings("unused") // |
| 411 | +final class Target_java_util_Calendar_CalendarAccessControlContext { |
| 412 | + @Alias @InjectAccessors(CalendarAccessControlContextAcc.class) static AccessControlContext INSTANCE; |
| 413 | +} |
| 414 | + |
| 415 | +class CalendarAccessControlContextAcc { |
| 416 | + static LazyValue<AccessControlContext> acc = new LazyValue<>(() -> AccessControllerUtil.contextWithPermissions( |
| 417 | + new RuntimePermission("accessClassInPackage.sun.util.calendar"))); |
| 418 | + |
| 419 | + static AccessControlContext get() { |
| 420 | + return acc.get(); |
| 421 | + } |
| 422 | +} |
| 423 | + |
363 | 424 | /** |
364 | 425 | * An injected field to replace ForkJoinPool.common. |
365 | 426 | * |
|
0 commit comments