< prev index next >

src/hotspot/share/classfile/stringTable.cpp

Print this page

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

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