JDK-8199290 : [TESTBUG] sun.hotspot.WhiteBox$WhiteBoxPermission is not copied
  • Type: Bug
  • Component: hotspot
  • Sub-Component: test
  • Affected Version: 11
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2018-03-08
  • Updated: 2022-12-27
  • Resolved: 2019-12-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 15
11.0.18Fixed 15 b02Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
JDK-8011397 fixed this problem with dozens of tests back in August 2014 but it seems we have a few tests that were created after that that don't do the right thing and so can sometimes leads to failure due to NoClassDefFoundError for WhiteBox$WhiteBoxPermission. 

To reproduce the error, add a file /tmp/foo.policy with the following contents:

    grant { 
      permission java.security.AllPermission; 
      permission sun.hotspot.WhiteBox$WhiteBoxPermission "getInstance"; 
    }; 

Then, run the following command: 

jtreg -vmoption:-Djava.security.manager -Djava.security.policy=/tmp/foo.policy \ 
    test/hotspot/jtreg/runtime/appcds/runtime/appcds/cacheObject/CheckCachedMirrorTest.java 

==========================


The problem tests only have:
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
while other whitebox using tests, which pass, have:
* @run driver ClassFileInstaller sun.hotspot.WhiteBox
*                              sun.hotspot.WhiteBox$WhiteBoxPermission

Apparently affected tests (found by grepping):

./compiler/jsr292/NonInlinedCall/InvokeTest.java: *        sun.hotspot.WhiteBox
./compiler/ciReplay/TestDumpReplay.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./compiler/rangechecks/TestExplicitRangeChecks.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./compiler/rangechecks/TestRangeCheckSmearing.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/cacheObject/CheckCachedResolvedReferences.java: * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
./runtime/appcds/cacheObject/MirrorWithReferenceFieldsTest.java: * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
./runtime/appcds/cacheObject/GCStressTest.java: * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
./runtime/appcds/cacheObject/PrimitiveTypesTest.java: * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
./runtime/appcds/cacheObject/CheckCachedMirrorTest.java: * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
./runtime/appcds/RewriteBytecodesTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/jigsaw/classpathtests/DummyClassesInBootClassPath.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/jigsaw/limitmods/LimitModsTests.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/SharedArchiveConsistency.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/customLoader/UnintendedLoadersTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/customLoader/SameNameInTwoLoadersTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/customLoader/LoaderSegregationTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/customLoader/HelloCustom.java: * @run driver ClassFileInstaller -jar WhiteBox.jar sun.hotspot.WhiteBox
./runtime/appcds/customLoader/UnloadUnregisteredLoaderTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/ClassLoaderTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/JvmtiAddPath.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/HelloExtTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/javaldr/ArrayTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/javaldr/GCSharedStringsDuringDump.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/MismatchedUseAppCDS.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/MultiProcessSharing.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/sharedStrings/SharedStringsWbTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/sharedStrings/LockSharedStrings.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/sharedStrings/InternSharedString.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/sharedStrings/ExerciseGC.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/appcds/sharedStrings/SharedStringsBasicPlus.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/JcmdDetailDiff.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/JcmdSummaryDiff.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/ReleaseNoCommit.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/MallocStressTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/MallocSiteHashOverflow.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/MallocRoundingReportTest.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/MallocTrackingVerify.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/VirtualAllocAttemptReserveMemoryAt.java: * @run main ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/VirtualAllocCommitMerge.java: * @run main ClassFileInstaller sun.hotspot.WhiteBox
./runtime/NMT/VirtualAllocCommitUncommitRecommit.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./runtime/SharedArchiveFile/SharedStrings.java: * @run driver ClassFileInstaller -jar whitebox.jar sun.hotspot.WhiteBox
./gc/metaspace/TestMetaspaceCMSCancel.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/TestSmallHeap.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/TestNumWorkerOutput.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/TestAgeOutput.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/whitebox/TestWBGC.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/g1/TestVerifyGCType.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/g1/TestGCLogMessages.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/g1/TestEagerReclaimHumongousRegionsLog.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/g1/mixedgc/TestLogging.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/g1/TestPLABOutput.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/arguments/TestMinAndInitialSurvivorRatioFlags.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/arguments/TestNewSizeFlags.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/arguments/TestNewRatioFlag.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/arguments/TestTargetSurvivorRatioFlag.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/arguments/TestSmallInitialHeapWithLargePageAndNUMA.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox
./gc/arguments/TestSurvivorRatioFlag.java: * @run driver ClassFileInstaller sun.hotspot.WhiteBox

Comments
fix request (11u). Not a clean backport because JarBuilder.java does not exist in JDK11. Changes in ClassFileInstaller.java are clean. Change fixes the repro
31-10-2022

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1432 Date: 2022-10-10 20:13:17 +0000
10-10-2022

URL: https://hg.openjdk.java.net/jdk/jdk/rev/5f91ab380656 User: iklam Date: 2019-12-16 18:22:21 +0000
16-12-2019

Here's an updated webrev. I modified ClassFileInstaller to automatically add only WhiteBoxPermission. We could add other case to addInnerClasses() if necessary. http://cr.openjdk.java.net/~iklam/jdk15/8199290-copy-whitebox-inner-cls.v01/
14-12-2019

Assigning to Ioi as he has the ClassFileInstaller fix prepared.
12-10-2018

Proposed fix for ClassFileInstaller to automatically copy all inner classes: http://cr.openjdk.java.net/~iklam/jdk12/8199290-no-whitebox-permission.v01/
04-10-2018

JDK-8011397 "fixes" this by adding "sun.hotspot.WhiteBox$WhiteBoxPermission" to every instance of "@run main ClassFileInstaller sun.hotspot.WhiteBox". This is of course unmaintainable, as new tests will be added without knowing the internals of WhiteBox. $ cd $jdk_repo/tests $ find . -name \*.java | xargs grep -l '@run.*FileInstaller.*WhiteBox' | wc 697 697 52816 $ find . -name \*.java | xargs grep -l '@run.*FileInstaller.*WhiteBox' | xargs grep -l WhiteBoxPermission | wc 627 627 48657 Forcing the tests to know the internals of test libraries is a bad idea. It's better to fix ClassFileInstaller to automatically copy all inner classes.
03-10-2018

Adding a security manager check will of course cause a failure if the permission class is not present. What I can't explain is why a few of the tests that don't copy the permission class can fail as part of a full tier1 run, yet pass otherwise.
12-03-2018

To reproduce the error: Add a file /tmp/foo.policy grant { permission java.security.AllPermission; permission sun.hotspot.WhiteBox$WhiteBoxPermission "getInstance"; }; Then, run the following command: jtreg -vmoption:-Djava.security.manager -Djava.security.policy=/tmp/foo.policy \ test/hotspot/jtreg/runtime/appcds/runtime/appcds/cacheObject/CheckCachedMirrorTest.java
09-03-2018

Making it opt-in still requires updating all the test that don't have this. Making it the default mode means cleaning up all the many tests that explicitly copy the nested classfiles. I'm still trying to understand why tests pass even without copying. Or more particularly I'm trying to understand why I saw some tests fail.
09-03-2018

ClassFileInstaller is used not only to copy WhiteBox, some tests might expect that nested classes won't be copied, making it opt-out will require analysis of all tests which use ClassFileInstaller.
08-03-2018

There's no reason for a test to want WhiteBox but not WhiteBox$WhiteBoxPermission. This inner class is an implementation detail and the tests shouldn't know about it. I think it's true for the vast majority of all classes that you use ClassFileInstaller with. The default should be copy all nested classes, and we can add a -nonestedclasses option for the rare cases where a test doesn't want this.
08-03-2018

[~dholmes], if you decide to update ClassFileInstaller to include nested classes, it'd be safer to make such behavior opt-in.
08-03-2018

I'm very tempted to update ClassFileInstaller to include nested types when copying the main type!
08-03-2018