967 assert(HeapShared::is_writing_mapping_mode(), "should not reach here");
968
969 CompileBroker::wait_for_no_active_tasks();
970
971 precond(CDSConfig::allow_only_single_java_thread());
972
973 // At this point, no more strings will be added:
974 // - There's only a single Java thread (this thread). It no longer executes Java bytecodes
975 // so JIT compilation will eventually stop.
976 // - CompileBroker has no more active tasks, so all JIT requests have been processed.
977
978 // This flag will be cleared after intern table dumping has completed, so we can run the
979 // compiler again (for future AOT method compilation, etc).
980 DEBUG_ONLY(AtomicAccess::release_store(&_disable_interning_during_cds_dump, true));
981
982 if (items_count_acquire() > (size_t)max_jint) {
983 fatal("Too many strings to be archived: %zu", items_count_acquire());
984 }
985
986 int total = (int)items_count_acquire();
987 size_t single_array_size = objArrayOopDesc::object_size(total);
988
989 log_info(aot)("allocated string table for %d strings", total);
990
991 if (!HeapShared::is_too_large_to_archive(single_array_size)) {
992 // The entire table can fit in a single array
993 objArrayOop array = oopFactory::new_objArray(vmClasses::Object_klass(), total, CHECK);
994 _shared_strings_array = OopHandle(Universe::vm_global(), array);
995 log_info(aot)("string table array (single level) length = %d", total);
996 } else {
997 // Split the table in two levels of arrays.
998 int primary_array_length = (total + _secondary_array_max_length - 1) / _secondary_array_max_length;
999 size_t primary_array_size = objArrayOopDesc::object_size(primary_array_length);
1000 size_t secondary_array_size = objArrayOopDesc::object_size(_secondary_array_max_length);
1001
1002 if (HeapShared::is_too_large_to_archive(secondary_array_size)) {
1003 // This can only happen if you have an extremely large number of classes that
1004 // refer to more than 16384 * 16384 = 26M interned strings! Not a practical concern
1005 // but bail out for safety.
1006 log_error(aot)("Too many strings to be archived: %zu", items_count_acquire());
1007 AOTMetaspace::unrecoverable_writing_error();
1008 }
1009
1010 objArrayOop primary = oopFactory::new_objArray(vmClasses::Object_klass(), primary_array_length, CHECK);
1011 objArrayHandle primaryHandle(THREAD, primary);
1012 _shared_strings_array = OopHandle(Universe::vm_global(), primary);
1013
1014 log_info(aot)("string table array (primary) length = %d", primary_array_length);
1015 for (int i = 0; i < primary_array_length; i++) {
1016 int len;
1017 if (total > _secondary_array_max_length) {
1018 len = _secondary_array_max_length;
1019 } else {
1020 len = total;
1021 }
1022 total -= len;
1023
1024 objArrayOop secondary = oopFactory::new_objArray(vmClasses::Object_klass(), len, CHECK);
1025 primaryHandle()->obj_at_put(i, secondary);
1026
1027 log_info(aot)("string table array (secondary)[%d] length = %d", i, len);
1028 assert(!HeapShared::is_too_large_to_archive(secondary), "sanity");
1029 }
1030
1031 assert(total == 0, "must be");
1032 _is_two_dimensional_shared_strings_array = true;
1033 }
1034 }
1035
1036 #ifndef PRODUCT
1037 void StringTable::verify_secondary_array_index_bits() {
1038 assert(HeapShared::is_writing_mapping_mode(), "should not reach here");
1039 int max;
1040 for (max = 1; ; max++) {
1041 size_t next_size = objArrayOopDesc::object_size(1 << (max + 1));
1042 if (HeapShared::is_too_large_to_archive(next_size)) {
1043 break;
1044 }
1045 }
1046 // Currently max is 17 for +UseCompressedOops, 16 for -UseCompressedOops.
1047 // When we add support for Shenandoah (which has a smaller mininum region size than G1),
1048 // max will become 15/14.
1049 //
1050 // We use _secondary_array_index_bits==14 as that will be the eventual value, and will
1051 // make testing easier.
1052 assert(_secondary_array_index_bits <= max,
1053 "_secondary_array_index_bits (%d) must be smaller than max possible value (%d)",
1054 _secondary_array_index_bits, max);
1055 }
1056 #endif // PRODUCT
1057
1058 // This is called AFTER we enter the CDS safepoint.
1059 //
1060 // For each shared string:
1061 // [1] Store it into _shared_strings_array. Encode its position as a 32-bit index.
|
967 assert(HeapShared::is_writing_mapping_mode(), "should not reach here");
968
969 CompileBroker::wait_for_no_active_tasks();
970
971 precond(CDSConfig::allow_only_single_java_thread());
972
973 // At this point, no more strings will be added:
974 // - There's only a single Java thread (this thread). It no longer executes Java bytecodes
975 // so JIT compilation will eventually stop.
976 // - CompileBroker has no more active tasks, so all JIT requests have been processed.
977
978 // This flag will be cleared after intern table dumping has completed, so we can run the
979 // compiler again (for future AOT method compilation, etc).
980 DEBUG_ONLY(AtomicAccess::release_store(&_disable_interning_during_cds_dump, true));
981
982 if (items_count_acquire() > (size_t)max_jint) {
983 fatal("Too many strings to be archived: %zu", items_count_acquire());
984 }
985
986 int total = (int)items_count_acquire();
987 size_t single_array_size = refArrayOopDesc::object_size(total);
988
989 log_info(aot)("allocated string table for %d strings", total);
990
991 if (!HeapShared::is_too_large_to_archive(single_array_size)) {
992 // The entire table can fit in a single array
993 objArrayOop array = oopFactory::new_objArray(vmClasses::Object_klass(), total, CHECK);
994 _shared_strings_array = OopHandle(Universe::vm_global(), array);
995 log_info(aot)("string table array (single level) length = %d", total);
996 } else {
997 // Split the table in two levels of arrays.
998 int primary_array_length = (total + _secondary_array_max_length - 1) / _secondary_array_max_length;
999 size_t primary_array_size = refArrayOopDesc::object_size(primary_array_length);
1000 size_t secondary_array_size = refArrayOopDesc::object_size(_secondary_array_max_length);
1001
1002 if (HeapShared::is_too_large_to_archive(secondary_array_size)) {
1003 // This can only happen if you have an extremely large number of classes that
1004 // refer to more than 16384 * 16384 = 26M interned strings! Not a practical concern
1005 // but bail out for safety.
1006 log_error(aot)("Too many strings to be archived: %zu", items_count_acquire());
1007 AOTMetaspace::unrecoverable_writing_error();
1008 }
1009
1010 objArrayOop primary = oopFactory::new_objArray(vmClasses::Object_klass(), primary_array_length, CHECK);
1011 objArrayHandle primaryHandle(THREAD, primary);
1012 _shared_strings_array = OopHandle(Universe::vm_global(), primary);
1013
1014 log_info(aot)("string table array (primary) length = %d", primary_array_length);
1015 for (int i = 0; i < primary_array_length; i++) {
1016 int len;
1017 if (total > _secondary_array_max_length) {
1018 len = _secondary_array_max_length;
1019 } else {
1020 len = total;
1021 }
1022 total -= len;
1023
1024 objArrayOop secondary = oopFactory::new_objArray(vmClasses::Object_klass(), len, CHECK);
1025 primaryHandle()->obj_at_put(i, secondary);
1026
1027 log_info(aot)("string table array (secondary)[%d] length = %d", i, len);
1028 assert(!HeapShared::is_too_large_to_archive(secondary), "sanity");
1029 }
1030
1031 assert(total == 0, "must be");
1032 _is_two_dimensional_shared_strings_array = true;
1033 }
1034 }
1035
1036 #ifndef PRODUCT
1037 void StringTable::verify_secondary_array_index_bits() {
1038 assert(HeapShared::is_writing_mapping_mode(), "should not reach here");
1039 int max;
1040 for (max = 1; ; max++) {
1041 size_t next_size = refArrayOopDesc::object_size(1 << (max + 1));
1042 if (HeapShared::is_too_large_to_archive(next_size)) {
1043 break;
1044 }
1045 }
1046 // Currently max is 17 for +UseCompressedOops, 16 for -UseCompressedOops.
1047 // When we add support for Shenandoah (which has a smaller mininum region size than G1),
1048 // max will become 15/14.
1049 //
1050 // We use _secondary_array_index_bits==14 as that will be the eventual value, and will
1051 // make testing easier.
1052 assert(_secondary_array_index_bits <= max,
1053 "_secondary_array_index_bits (%d) must be smaller than max possible value (%d)",
1054 _secondary_array_index_bits, max);
1055 }
1056 #endif // PRODUCT
1057
1058 // This is called AFTER we enter the CDS safepoint.
1059 //
1060 // For each shared string:
1061 // [1] Store it into _shared_strings_array. Encode its position as a 32-bit index.
|