Thu, 30 Oct 2014 13:38:00 -0700
8038268: VM Crashes in MetaspaceShared::generate_vtable_methods while creating CDS archive with limiting SharedMiscCodeSize
Summary: estimate the minimum required size for the misc code region and check if the specified misc code region size meets the minimum size requirement
Reviewed-by: jiangli, dholmes
1.1 --- a/src/share/vm/memory/metaspace.cpp Fri Oct 24 10:28:19 2014 -0700 1.2 +++ b/src/share/vm/memory/metaspace.cpp Thu Oct 30 13:38:00 2014 -0700 1.3 @@ -3155,6 +3155,16 @@ 1.4 SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment); 1.5 SharedMiscCodeSize = align_size_up(SharedMiscCodeSize, max_alignment); 1.6 1.7 + // the min_misc_code_size estimate is based on MetaspaceShared::generate_vtable_methods() 1.8 + uintx min_misc_code_size = align_size_up( 1.9 + (MetaspaceShared::num_virtuals * MetaspaceShared::vtbl_list_size) * 1.10 + (sizeof(void*) + MetaspaceShared::vtbl_method_size) + MetaspaceShared::vtbl_common_code_size, 1.11 + max_alignment); 1.12 + 1.13 + if (SharedMiscCodeSize < min_misc_code_size) { 1.14 + report_out_of_shared_space(SharedMiscCode); 1.15 + } 1.16 + 1.17 // Initialize with the sum of the shared space sizes. The read-only 1.18 // and read write metaspace chunks will be allocated out of this and the 1.19 // remainder is the misc code and data chunks.
2.1 --- a/src/share/vm/memory/metaspaceShared.hpp Fri Oct 24 10:28:19 2014 -0700 2.2 +++ b/src/share/vm/memory/metaspaceShared.hpp Thu Oct 30 13:38:00 2014 -0700 2.3 @@ -57,11 +57,16 @@ 2.4 static bool _archive_loading_failed; 2.5 public: 2.6 enum { 2.7 - vtbl_list_size = 17, // number of entries in the shared space vtable list. 2.8 - num_virtuals = 200 // maximum number of virtual functions 2.9 - // If virtual functions are added to Metadata, 2.10 - // this number needs to be increased. Also, 2.11 - // SharedMiscCodeSize will need to be increased. 2.12 + vtbl_list_size = 17, // number of entries in the shared space vtable list. 2.13 + num_virtuals = 200, // maximum number of virtual functions 2.14 + // If virtual functions are added to Metadata, 2.15 + // this number needs to be increased. Also, 2.16 + // SharedMiscCodeSize will need to be increased. 2.17 + // The following 2 sizes were based on 2.18 + // MetaspaceShared::generate_vtable_methods() 2.19 + vtbl_method_size = 16, // conservative size of the mov1 and jmp instructions 2.20 + // for the x64 platform 2.21 + vtbl_common_code_size = (1*K) // conservative size of the "common_code" for the x64 platform 2.22 }; 2.23 2.24 enum {
3.1 --- a/src/share/vm/utilities/debug.cpp Fri Oct 24 10:28:19 2014 -0700 3.2 +++ b/src/share/vm/utilities/debug.cpp Thu Oct 30 13:38:00 2014 -0700 3.3 @@ -266,17 +266,19 @@ 3.4 "native memory for metadata", 3.5 "shared read only space", 3.6 "shared read write space", 3.7 - "shared miscellaneous data space" 3.8 + "shared miscellaneous data space", 3.9 + "shared miscellaneous code space" 3.10 }; 3.11 static const char* flag[] = { 3.12 "Metaspace", 3.13 "SharedReadOnlySize", 3.14 "SharedReadWriteSize", 3.15 - "SharedMiscDataSize" 3.16 + "SharedMiscDataSize", 3.17 + "SharedMiscCodeSize" 3.18 }; 3.19 3.20 warning("\nThe %s is not large enough\n" 3.21 - "to preload requested classes. Use -XX:%s=\n" 3.22 + "to preload requested classes. Use -XX:%s=<size>\n" 3.23 "to increase the initial size of %s.\n", 3.24 name[shared_space], flag[shared_space], name[shared_space]); 3.25 exit(2);
4.1 --- a/src/share/vm/utilities/debug.hpp Fri Oct 24 10:28:19 2014 -0700 4.2 +++ b/src/share/vm/utilities/debug.hpp Thu Oct 30 13:38:00 2014 -0700 4.3 @@ -246,7 +246,8 @@ 4.4 SharedPermGen, 4.5 SharedReadOnly, 4.6 SharedReadWrite, 4.7 - SharedMiscData 4.8 + SharedMiscData, 4.9 + SharedMiscCode 4.10 }; 4.11 4.12 void report_out_of_shared_space(SharedSpaceType space_type);
5.1 --- a/test/runtime/SharedArchiveFile/LimitSharedSizes.java Fri Oct 24 10:28:19 2014 -0700 5.2 +++ b/test/runtime/SharedArchiveFile/LimitSharedSizes.java Thu Oct 30 13:38:00 2014 -0700 5.3 @@ -51,9 +51,12 @@ 5.4 // Known issue, JDK-8038422 (assert() on Windows) 5.5 // new SharedSizeTestData("-XX:SharedMiscDataSize", "500k", "miscellaneous data"), 5.6 5.7 - // This will cause a VM crash; commenting out for now; see bug JDK-8038268 5.8 - // @ignore JDK-8038268 5.9 - // new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"), 5.10 + // Too small of a misc code size should not cause a vm crash. 5.11 + // It should result in the following error message: 5.12 + // The shared miscellaneous code space is not large enough 5.13 + // to preload requested classes. Use -XX:SharedMiscCodeSize= 5.14 + // to increase the initial size of shared miscellaneous code space. 5.15 + new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"), 5.16 5.17 // these values are larger than default ones, but should 5.18 // be acceptable and not cause failure