@@ -43,6 +43,8 @@ public class SharedArchiveConsistency {
43
43
public static boolean shareAuto ; // true == -Xshare:auto
44
44
// false == -Xshare:on
45
45
46
+ private static int genericHeaderMinVersion ; // minimum supported CDS version
47
+ private static int currentCDSArchiveVersion ; // current CDS version in java process
46
48
// The following should be consistent with the enum in the C++ MetaspaceShared class
47
49
public static String [] shared_region_name = {
48
50
"rw" , // ReadWrite
@@ -104,6 +106,9 @@ public static void main(String... args) throws Exception {
104
106
throw new RuntimeException ("Arg must be 'on' or 'auto'" );
105
107
}
106
108
shareAuto = args [0 ].equals ("auto" );
109
+ genericHeaderMinVersion = CDSArchiveUtils .getGenericHeaderMinVersion ();
110
+ currentCDSArchiveVersion = CDSArchiveUtils .getCurrentCDSArchiveVersion ();
111
+
107
112
String jarFile = JarBuilder .getOrCreateHelloJar ();
108
113
109
114
// dump (appcds.jsa created)
@@ -158,7 +163,7 @@ public static void main(String... args) throws Exception {
158
163
}
159
164
160
165
// modify _magic, test should fail
161
- System .out .println ("\n 2c . Corrupt _magic, should fail\n " );
166
+ System .out .println ("\n 2b . Corrupt _magic, should fail\n " );
162
167
String modMagic = startNewArchive ("modify-magic" );
163
168
copiedJsa = CDSArchiveUtils .copyArchiveFile (orgJsaFile , modMagic );
164
169
CDSArchiveUtils .modifyHeaderIntField (copiedJsa , CDSArchiveUtils .offsetMagic (), -1 );
@@ -170,23 +175,26 @@ public static void main(String... args) throws Exception {
170
175
}
171
176
172
177
// modify _version, test should fail
173
- System .out .println ("\n 2d . Corrupt _version, should fail\n " );
178
+ System .out .println ("\n 2c . Corrupt _version, should fail\n " );
174
179
String modVersion = startNewArchive ("modify-version" );
180
+ int version = currentCDSArchiveVersion + 1 ;
175
181
copiedJsa = CDSArchiveUtils .copyArchiveFile (orgJsaFile , modVersion );
176
- CDSArchiveUtils .modifyHeaderIntField (copiedJsa , CDSArchiveUtils .offsetVersion (), 0x3FFFFFFF );
182
+ CDSArchiveUtils .modifyHeaderIntField (copiedJsa , CDSArchiveUtils .offsetVersion (), version );
177
183
output = shareAuto ? TestCommon .execAuto (execArgs ) : TestCommon .execCommon (execArgs );
178
- output .shouldContain ("The shared archive file has the wrong version" );
179
- output .shouldNotContain ("Checksum verification failed" );
184
+ output .shouldContain ("The shared archive file has the wrong version" )
185
+ .shouldContain ("_version expected: " + currentCDSArchiveVersion )
186
+ .shouldContain ("actual: " + version );
180
187
if (shareAuto ) {
181
188
output .shouldContain (HELLO_WORLD );
182
189
}
183
190
184
- System .out .println ("\n 2e . Corrupt _version, should fail\n " );
191
+ System .out .println ("\n 2d . Corrupt _version, should fail\n " );
185
192
String modVersion2 = startNewArchive ("modify-version2" );
186
193
copiedJsa = CDSArchiveUtils .copyArchiveFile (orgJsaFile , modVersion2 );
187
- CDSArchiveUtils .modifyHeaderIntField (copiedJsa , CDSArchiveUtils .offsetVersion (), 0x00000000 );
194
+ version = genericHeaderMinVersion - 1 ;
195
+ CDSArchiveUtils .modifyHeaderIntField (copiedJsa , CDSArchiveUtils .offsetVersion (), version );
188
196
output = shareAuto ? TestCommon .execAuto (execArgs ) : TestCommon .execCommon (execArgs );
189
- output .shouldContain ("Cannot handle shared archive file version 0 . Must be at least 12" );
197
+ output .shouldContain ("Cannot handle shared archive file version " + version + " . Must be at least " + genericHeaderMinVersion );
190
198
output .shouldNotContain ("Checksum verification failed" );
191
199
if (shareAuto ) {
192
200
output .shouldContain (HELLO_WORLD );
0 commit comments