3131 * @build sun.hotspot.WhiteBox
3232 * @compile test-classes/Hello.java
3333 * @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SharedArchiveConsistency
34+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SharedArchiveConsistency on
35+ * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI SharedArchiveConsistency auto
3536 */
3637import jdk .test .lib .process .OutputAnalyzer ;
3738import jdk .test .lib .Utils ;
@@ -69,6 +70,9 @@ public class SharedArchiveConsistency {
6970 public static int int_size ; // size of int
7071 public static long alignment ; // MetaspaceShared::core_region_alignment
7172
73+ public static boolean shareAuto ; // true == -Xshare:auto
74+ // false == -Xshare:on
75+
7276 // The following should be consistent with the enum in the C++ MetaspaceShared class
7377 public static String [] shared_region_name = {
7478 "rw" , // ReadWrite
@@ -80,6 +84,8 @@ public class SharedArchiveConsistency {
8084 "last_open_archive"
8185 };
8286
87+ public static final String HELLO_WORLD = "Hello World" ;
88+
8389 public static int num_regions = shared_region_name .length ;
8490 public static String [] matchMessages = {
8591 "Unable to use shared archive" ,
@@ -339,7 +345,7 @@ public static void setReadWritePermission(File file) throws Exception {
339345 }
340346
341347 public static void testAndCheck (String [] execArgs ) throws Exception {
342- OutputAnalyzer output = TestCommon .execCommon (execArgs );
348+ OutputAnalyzer output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
343349 String stdtxt = output .getOutput ();
344350 System .out .println ("Note: this test may fail in very rare occasions due to CRC32 checksum collision" );
345351 for (String message : matchMessages ) {
@@ -361,6 +367,14 @@ public static void testAndCheck(String[] execArgs) throws Exception {
361367 // 6) insert bytes in data begining
362368 // 7) randomly corrupt data in each region specified by shared_region_name[]
363369 public static void main (String ... args ) throws Exception {
370+ if (args .length != 1 ) {
371+ throw new RuntimeException ("One arg of 'on' or 'auto' to run the test" );
372+ }
373+ if (!args [0 ].equals ("on" ) && !args [0 ].equals ("auto" )) {
374+ throw new RuntimeException ("Arg must be 'on' or 'auto'" );
375+ }
376+ shareAuto = args [0 ].equals ("auto" );
377+
364378 // must call to get offset info first!!!
365379 getFileOffsetInfo ();
366380 Path currentRelativePath = Paths .get ("" );
@@ -380,10 +394,10 @@ public static void main(String... args) throws Exception {
380394 // VerifySharedSpaces enabled to detect inconsistencies
381395 String [] verifyExecArgs = {"-Xlog:cds" , "-XX:+VerifySharedSpaces" , "-cp" , jarFile , "Hello" };
382396
383- OutputAnalyzer output = TestCommon .execCommon (execArgs );
397+ OutputAnalyzer output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
384398
385399 try {
386- TestCommon .checkExecReturn (output , 0 , true , "Hello World" );
400+ TestCommon .checkExecReturn (output , 0 , true , HELLO_WORLD );
387401 } catch (Exception e ) {
388402 TestCommon .checkExecReturn (output , 1 , true , matchMessages [0 ]);
389403 }
@@ -397,36 +411,42 @@ public static void main(String... args) throws Exception {
397411 // modify jsa header, test should fail
398412 System .out .println ("\n 2. Corrupt header, should fail\n " );
399413 modifyJsaHeader (copyFile (orgJsaFile , "corrupt-header" ));
400- output = TestCommon .execCommon (execArgs );
414+ output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
401415 output .shouldContain ("The shared archive file has a bad magic number" );
402416 output .shouldNotContain ("Checksum verification failed" );
417+ if (shareAuto ) {
418+ output .shouldContain (HELLO_WORLD );
419+ }
403420
404421 // modify _jvm_ident, test should fail
405422 System .out .println ("\n 2a. Corrupt _jvm_ident, should fail\n " );
406423 modifyJvmIdent (copyFile (orgJsaFile , "modify-jvm-ident" ));
407- output = TestCommon .execCommon (execArgs );
424+ output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
408425 output .shouldContain ("The shared archive file was created by a different version or build of HotSpot" );
409426 output .shouldNotContain ("Checksum verification failed" );
410-
411- // use the same archive as above, but run with -Xshare:auto
412- System .out .println ("\n 2b. Corrupt _jvm_ident run with -Xshare:auto\n " );
413- output = TestCommon .execAuto (execArgs );
414- output .shouldContain ("The shared archive file was created by a different version or build of HotSpot" );
415- output .shouldContain ("Hello World" );
427+ if (shareAuto ) {
428+ output .shouldContain (HELLO_WORLD );
429+ }
416430
417431 // modify _magic, test should fail
418432 System .out .println ("\n 2c. Corrupt _magic, should fail\n " );
419433 modifyHeaderIntField (copyFile (orgJsaFile , "modify-magic" ), offset_magic , 0x00000000 );
420- output = TestCommon .execCommon (execArgs );
434+ output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
421435 output .shouldContain ("The shared archive file has a bad magic number" );
422436 output .shouldNotContain ("Checksum verification failed" );
437+ if (shareAuto ) {
438+ output .shouldContain (HELLO_WORLD );
439+ }
423440
424441 // modify _version, test should fail
425442 System .out .println ("\n 2d. Corrupt _version, should fail\n " );
426443 modifyHeaderIntField (copyFile (orgJsaFile , "modify-version" ), offset_version , 0x00000000 );
427- output = TestCommon .execCommon (execArgs );
444+ output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
428445 output .shouldContain ("The shared archive file has the wrong version" );
429446 output .shouldNotContain ("Checksum verification failed" );
447+ if (shareAuto ) {
448+ output .shouldContain (HELLO_WORLD );
449+ }
430450
431451 // modify content inside regions
432452 System .out .println ("\n 3. Corrupt Content, should fail\n " );
@@ -442,9 +462,12 @@ public static void main(String... args) throws Exception {
442462 File newJsaFile = copyFile (orgJsaFile , "header-and-content" );
443463 modifyJsaHeader (newJsaFile );
444464 modifyJsaContent (0 , newJsaFile ); // this will not be reached since failed on header change first
445- output = TestCommon .execCommon (execArgs );
465+ output = shareAuto ? TestCommon . execAuto ( execArgs ) : TestCommon .execCommon (execArgs );
446466 output .shouldContain ("The shared archive file has a bad magic number" );
447467 output .shouldNotContain ("Checksum verification failed" );
468+ if (shareAuto ) {
469+ output .shouldContain (HELLO_WORLD );
470+ }
448471
449472 // delete bytes in data section
450473 System .out .println ("\n 5. Delete bytes at beginning of data section, should fail\n " );
0 commit comments