< prev index next >

src/hotspot/share/classfile/stringTable.cpp

Print this page

 936 oop StringTable::lookup_shared(const jchar* name, int len) {
 937   StringWrapper wrapped_name(name, len);
 938   // len is required but is already part of StringWrapper, so 0 is used
 939   return _shared_table.lookup(wrapped_name, java_lang_String::hash_code(name, len), 0);
 940 }
 941 
 942 // This is called BEFORE we enter the CDS safepoint. We can allocate heap objects.
 943 // This should be called when we know no more strings will be added (which will be easy
 944 // to guarantee because CDS runs with a single Java thread. See JDK-8253495.)
 945 void StringTable::allocate_shared_strings_array(TRAPS) {
 946   if (!CDSConfig::is_dumping_heap()) {
 947     return;
 948   }
 949   assert(CDSConfig::allow_only_single_java_thread(), "No more interned strings can be added");
 950 
 951   if (_items_count > (size_t)max_jint) {
 952     fatal("Too many strings to be archived: %zu", _items_count);
 953   }
 954 
 955   int total = (int)_items_count;
 956   size_t single_array_size = objArrayOopDesc::object_size(total);
 957 
 958   log_info(aot)("allocated string table for %d strings", total);
 959 
 960   if (!ArchiveHeapWriter::is_too_large_to_archive(single_array_size)) {
 961     // The entire table can fit in a single array
 962     objArrayOop array = oopFactory::new_objArray(vmClasses::Object_klass(), total, CHECK);
 963     _shared_strings_array = OopHandle(Universe::vm_global(), array);
 964     log_info(aot)("string table array (single level) length = %d", total);
 965   } else {
 966     // Split the table in two levels of arrays.
 967     int primary_array_length = (total + _secondary_array_max_length - 1) / _secondary_array_max_length;
 968     size_t primary_array_size = objArrayOopDesc::object_size(primary_array_length);
 969     size_t secondary_array_size = objArrayOopDesc::object_size(_secondary_array_max_length);
 970 
 971     if (ArchiveHeapWriter::is_too_large_to_archive(secondary_array_size)) {
 972       // This can only happen if you have an extremely large number of classes that
 973       // refer to more than 16384 * 16384 = 26M interned strings! Not a practical concern
 974       // but bail out for safety.
 975       log_error(aot)("Too many strings to be archived: %zu", _items_count);
 976       MetaspaceShared::unrecoverable_writing_error();
 977     }
 978 
 979     objArrayOop primary = oopFactory::new_objArray(vmClasses::Object_klass(), primary_array_length, CHECK);
 980     objArrayHandle primaryHandle(THREAD, primary);
 981     _shared_strings_array = OopHandle(Universe::vm_global(), primary);
 982 
 983     log_info(aot)("string table array (primary) length = %d", primary_array_length);
 984     for (int i = 0; i < primary_array_length; i++) {
 985       int len;
 986       if (total > _secondary_array_max_length) {
 987         len = _secondary_array_max_length;
 988       } else {
 989         len = total;
 990       }
 991       total -= len;
 992 
 993       objArrayOop secondary = oopFactory::new_objArray(vmClasses::Object_klass(), len, CHECK);
 994       primaryHandle()->obj_at_put(i, secondary);
 995 
 996       log_info(aot)("string table array (secondary)[%d] length = %d", i, len);
 997       assert(!ArchiveHeapWriter::is_too_large_to_archive(secondary), "sanity");
 998     }
 999 
1000     assert(total == 0, "must be");
1001     _is_two_dimensional_shared_strings_array = true;
1002   }
1003 }
1004 
1005 #ifndef PRODUCT
1006 void StringTable::verify_secondary_array_index_bits() {
1007   int max;
1008   for (max = 1; ; max++) {
1009     size_t next_size = objArrayOopDesc::object_size(1 << (max + 1));
1010     if (ArchiveHeapWriter::is_too_large_to_archive(next_size)) {
1011       break;
1012     }
1013   }
1014   // Currently max is 17 for +UseCompressedOops, 16 for -UseCompressedOops.
1015   // When we add support for Shenandoah (which has a smaller mininum region size than G1),
1016   // max will become 15/14.
1017   //
1018   // We use _secondary_array_index_bits==14 as that will be the eventual value, and will
1019   // make testing easier.
1020   assert(_secondary_array_index_bits <= max,
1021          "_secondary_array_index_bits (%d) must be smaller than max possible value (%d)",
1022          _secondary_array_index_bits, max);
1023 }
1024 #endif // PRODUCT
1025 
1026 // This is called AFTER we enter the CDS safepoint.
1027 //
1028 // For each shared string:
1029 // [1] Store it into _shared_strings_array. Encode its position as a 32-bit index.

 936 oop StringTable::lookup_shared(const jchar* name, int len) {
 937   StringWrapper wrapped_name(name, len);
 938   // len is required but is already part of StringWrapper, so 0 is used
 939   return _shared_table.lookup(wrapped_name, java_lang_String::hash_code(name, len), 0);
 940 }
 941 
 942 // This is called BEFORE we enter the CDS safepoint. We can allocate heap objects.
 943 // This should be called when we know no more strings will be added (which will be easy
 944 // to guarantee because CDS runs with a single Java thread. See JDK-8253495.)
 945 void StringTable::allocate_shared_strings_array(TRAPS) {
 946   if (!CDSConfig::is_dumping_heap()) {
 947     return;
 948   }
 949   assert(CDSConfig::allow_only_single_java_thread(), "No more interned strings can be added");
 950 
 951   if (_items_count > (size_t)max_jint) {
 952     fatal("Too many strings to be archived: %zu", _items_count);
 953   }
 954 
 955   int total = (int)_items_count;
 956   size_t single_array_size = refArrayOopDesc::object_size(total);
 957 
 958   log_info(aot)("allocated string table for %d strings", total);
 959 
 960   if (!ArchiveHeapWriter::is_too_large_to_archive(single_array_size)) {
 961     // The entire table can fit in a single array
 962     objArrayOop array = oopFactory::new_objArray(vmClasses::Object_klass(), total, CHECK);
 963     _shared_strings_array = OopHandle(Universe::vm_global(), array);
 964     log_info(aot)("string table array (single level) length = %d", total);
 965   } else {
 966     // Split the table in two levels of arrays.
 967     int primary_array_length = (total + _secondary_array_max_length - 1) / _secondary_array_max_length;
 968     size_t primary_array_size = refArrayOopDesc::object_size(primary_array_length);
 969     size_t secondary_array_size = refArrayOopDesc::object_size(_secondary_array_max_length);
 970 
 971     if (ArchiveHeapWriter::is_too_large_to_archive(secondary_array_size)) {
 972       // This can only happen if you have an extremely large number of classes that
 973       // refer to more than 16384 * 16384 = 26M interned strings! Not a practical concern
 974       // but bail out for safety.
 975       log_error(aot)("Too many strings to be archived: %zu", _items_count);
 976       MetaspaceShared::unrecoverable_writing_error();
 977     }
 978 
 979     objArrayOop primary = oopFactory::new_objArray(vmClasses::Object_klass(), primary_array_length, CHECK);
 980     objArrayHandle primaryHandle(THREAD, primary);
 981     _shared_strings_array = OopHandle(Universe::vm_global(), primary);
 982 
 983     log_info(aot)("string table array (primary) length = %d", primary_array_length);
 984     for (int i = 0; i < primary_array_length; i++) {
 985       int len;
 986       if (total > _secondary_array_max_length) {
 987         len = _secondary_array_max_length;
 988       } else {
 989         len = total;
 990       }
 991       total -= len;
 992 
 993       objArrayOop secondary = oopFactory::new_objArray(vmClasses::Object_klass(), len, CHECK);
 994       primaryHandle()->obj_at_put(i, secondary);
 995 
 996       log_info(aot)("string table array (secondary)[%d] length = %d", i, len);
 997       assert(!ArchiveHeapWriter::is_too_large_to_archive(secondary), "sanity");
 998     }
 999 
1000     assert(total == 0, "must be");
1001     _is_two_dimensional_shared_strings_array = true;
1002   }
1003 }
1004 
1005 #ifndef PRODUCT
1006 void StringTable::verify_secondary_array_index_bits() {
1007   int max;
1008   for (max = 1; ; max++) {
1009     size_t next_size = refArrayOopDesc::object_size(1 << (max + 1));
1010     if (ArchiveHeapWriter::is_too_large_to_archive(next_size)) {
1011       break;
1012     }
1013   }
1014   // Currently max is 17 for +UseCompressedOops, 16 for -UseCompressedOops.
1015   // When we add support for Shenandoah (which has a smaller mininum region size than G1),
1016   // max will become 15/14.
1017   //
1018   // We use _secondary_array_index_bits==14 as that will be the eventual value, and will
1019   // make testing easier.
1020   assert(_secondary_array_index_bits <= max,
1021          "_secondary_array_index_bits (%d) must be smaller than max possible value (%d)",
1022          _secondary_array_index_bits, max);
1023 }
1024 #endif // PRODUCT
1025 
1026 // This is called AFTER we enter the CDS safepoint.
1027 //
1028 // For each shared string:
1029 // [1] Store it into _shared_strings_array. Encode its position as a 32-bit index.
< prev index next >