src/share/vm/memory/universe.cpp

Print this page




 112 oop Universe::_system_thread_group                    = NULL;
 113 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 114 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 115 oop Universe::_the_null_string                        = NULL;
 116 oop Universe::_the_min_jint_string                   = NULL;
 117 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 118 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 119 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 120 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 121 LatestMethodCache* Universe::_do_stack_walk_cache     = NULL;
 122 oop Universe::_out_of_memory_error_java_heap          = NULL;
 123 oop Universe::_out_of_memory_error_metaspace          = NULL;
 124 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 125 oop Universe::_out_of_memory_error_array_size         = NULL;
 126 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 127 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 128 oop Universe::_delayed_stack_overflow_error_message   = NULL;
 129 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 130 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 131 bool Universe::_verify_in_progress                    = false;

 132 oop Universe::_null_ptr_exception_instance            = NULL;
 133 oop Universe::_arithmetic_exception_instance          = NULL;
 134 oop Universe::_virtual_machine_error_instance         = NULL;
 135 oop Universe::_vm_exception                           = NULL;
 136 oop Universe::_allocation_context_notification_obj    = NULL;
 137 
 138 Array<int>* Universe::_the_empty_int_array            = NULL;
 139 Array<u2>* Universe::_the_empty_short_array           = NULL;
 140 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 141 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 142 
 143 // These variables are guarded by FullGCALot_lock.
 144 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 145 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 146 
 147 // Heap
 148 int             Universe::_verify_count = 0;
 149 
 150 // Oop verification (see MacroAssembler::verify_oop)
 151 uintptr_t       Universe::_verify_oop_mask = 0;


 652   Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
 653   Universe::_do_stack_walk_cache = new LatestMethodCache();
 654 
 655   if (UseSharedSpaces) {
 656     // Read the data structures supporting the shared spaces (shared
 657     // system dictionary, symbol table, etc.).  After that, access to
 658     // the file (other than the mapped regions) is no longer needed, and
 659     // the file is closed. Closing the file does not affect the
 660     // currently mapped regions.
 661     MetaspaceShared::initialize_shared_spaces();
 662     StringTable::create_table();
 663   } else {
 664     SymbolTable::create_table();
 665     StringTable::create_table();
 666     ClassLoader::create_package_info_table();
 667 
 668     if (DumpSharedSpaces) {
 669       MetaspaceShared::prepare_for_dumping();
 670     }
 671   }



 672 
 673   return JNI_OK;
 674 }
 675 
 676 CollectedHeap* Universe::create_heap() {
 677   assert(_collectedHeap == NULL, "Heap already created");
 678 #if !INCLUDE_ALL_GCS
 679   if (UseParallelGC) {
 680     fatal("UseParallelGC not supported in this VM.");
 681   } else if (UseG1GC) {
 682     fatal("UseG1GC not supported in this VM.");
 683   } else if (UseConcMarkSweepGC) {
 684     fatal("UseConcMarkSweepGC not supported in this VM.");
 685 #else
 686   if (UseParallelGC) {
 687     return Universe::create_heap_with_policy<ParallelScavengeHeap, GenerationSizer>();
 688   } else if (UseG1GC) {
 689     return Universe::create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>();
 690   } else if (UseConcMarkSweepGC) {
 691     return Universe::create_heap_with_policy<GenCollectedHeap, ConcurrentMarkSweepPolicy>();


1086 }
1087 
1088 void Universe::print_heap_before_gc() {
1089   LogHandle(gc, heap) log;
1090   if (log.is_trace()) {
1091     log.trace("Heap before GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1092     ResourceMark rm;
1093     heap()->print_on(log.trace_stream());
1094   }
1095 }
1096 
1097 void Universe::print_heap_after_gc() {
1098   LogHandle(gc, heap) log;
1099   if (log.is_trace()) {
1100     log.trace("Heap after GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1101     ResourceMark rm;
1102     heap()->print_on(log.trace_stream());
1103   }
1104 }
1105 


















































1106 void Universe::verify(VerifyOption option, const char* prefix) {
1107   // The use of _verify_in_progress is a temporary work around for
1108   // 6320749.  Don't bother with a creating a class to set and clear
1109   // it since it is only used in this method and the control flow is
1110   // straight forward.
1111   _verify_in_progress = true;
1112 
1113   COMPILER2_PRESENT(
1114     assert(!DerivedPointerTable::is_active(),
1115          "DPT should not be active during verification "
1116          "(of thread stacks below)");
1117   )
1118 
1119   ResourceMark rm;
1120   HandleMark hm;  // Handles created during verification can be zapped
1121   _verify_count++;
1122 
1123   FormatBuffer<> title("Verifying %s", prefix);
1124   GCTraceTime(Info, gc, verify) tm(title.buffer());

1125   log_debug(gc, verify)("Threads");
1126   Threads::verify();


1127   log_debug(gc, verify)("Heap");
1128   heap()->verify(option);


1129   log_debug(gc, verify)("SymbolTable");
1130   SymbolTable::verify();


1131   log_debug(gc, verify)("StringTable");
1132   StringTable::verify();


1133   {
1134     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1135     log_debug(gc, verify)("CodeCache");
1136     CodeCache::verify();
1137   }


1138   log_debug(gc, verify)("SystemDictionary");
1139   SystemDictionary::verify();

1140 #ifndef PRODUCT

1141   log_debug(gc, verify)("ClassLoaderDataGraph");
1142   ClassLoaderDataGraph::verify();

1143 #endif

1144   log_debug(gc, verify)("MetaspaceAux");
1145   MetaspaceAux::verify_free_chunks();


1146   log_debug(gc, verify)("JNIHandles");
1147   JNIHandles::verify();


1148   log_debug(gc, verify)("C-heap");
1149   os::check_heap();


1150   log_debug(gc, verify)("CodeCache Oops");
1151   CodeCache::verify_oops();

1152 
1153   _verify_in_progress = false;
1154 }
1155 
1156 
1157 #ifndef PRODUCT
1158 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1159   assert(low_boundary < high_boundary, "bad interval");
1160 
1161   // decide which low-order bits we require to be clear:
1162   size_t alignSize = MinObjAlignmentInBytes;
1163   size_t min_object_size = CollectedHeap::min_fill_size();
1164 
1165   // make an inclusive limit:
1166   uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1167   uintptr_t min = (uintptr_t)low_boundary;
1168   assert(min < max, "bad interval");
1169   uintptr_t diff = max ^ min;
1170 
1171   // throw away enough low-order bits to make the diff vanish




 112 oop Universe::_system_thread_group                    = NULL;
 113 objArrayOop Universe::_the_empty_class_klass_array    = NULL;
 114 Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
 115 oop Universe::_the_null_string                        = NULL;
 116 oop Universe::_the_min_jint_string                   = NULL;
 117 LatestMethodCache* Universe::_finalizer_register_cache = NULL;
 118 LatestMethodCache* Universe::_loader_addClass_cache    = NULL;
 119 LatestMethodCache* Universe::_pd_implies_cache         = NULL;
 120 LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
 121 LatestMethodCache* Universe::_do_stack_walk_cache     = NULL;
 122 oop Universe::_out_of_memory_error_java_heap          = NULL;
 123 oop Universe::_out_of_memory_error_metaspace          = NULL;
 124 oop Universe::_out_of_memory_error_class_metaspace    = NULL;
 125 oop Universe::_out_of_memory_error_array_size         = NULL;
 126 oop Universe::_out_of_memory_error_gc_overhead_limit  = NULL;
 127 oop Universe::_out_of_memory_error_realloc_objects    = NULL;
 128 oop Universe::_delayed_stack_overflow_error_message   = NULL;
 129 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL;
 130 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
 131 bool Universe::_verify_in_progress                    = false;
 132 long Universe::verify_flags                           = Universe::Verify_All;
 133 oop Universe::_null_ptr_exception_instance            = NULL;
 134 oop Universe::_arithmetic_exception_instance          = NULL;
 135 oop Universe::_virtual_machine_error_instance         = NULL;
 136 oop Universe::_vm_exception                           = NULL;
 137 oop Universe::_allocation_context_notification_obj    = NULL;
 138 
 139 Array<int>* Universe::_the_empty_int_array            = NULL;
 140 Array<u2>* Universe::_the_empty_short_array           = NULL;
 141 Array<Klass*>* Universe::_the_empty_klass_array     = NULL;
 142 Array<Method*>* Universe::_the_empty_method_array   = NULL;
 143 
 144 // These variables are guarded by FullGCALot_lock.
 145 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;)
 146 debug_only(int Universe::_fullgc_alot_dummy_next      = 0;)
 147 
 148 // Heap
 149 int             Universe::_verify_count = 0;
 150 
 151 // Oop verification (see MacroAssembler::verify_oop)
 152 uintptr_t       Universe::_verify_oop_mask = 0;


 653   Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
 654   Universe::_do_stack_walk_cache = new LatestMethodCache();
 655 
 656   if (UseSharedSpaces) {
 657     // Read the data structures supporting the shared spaces (shared
 658     // system dictionary, symbol table, etc.).  After that, access to
 659     // the file (other than the mapped regions) is no longer needed, and
 660     // the file is closed. Closing the file does not affect the
 661     // currently mapped regions.
 662     MetaspaceShared::initialize_shared_spaces();
 663     StringTable::create_table();
 664   } else {
 665     SymbolTable::create_table();
 666     StringTable::create_table();
 667     ClassLoader::create_package_info_table();
 668 
 669     if (DumpSharedSpaces) {
 670       MetaspaceShared::prepare_for_dumping();
 671     }
 672   }
 673   if (VerifySubSet[0] != '\0') {
 674     Universe::initialize_verify_flags();
 675   }
 676 
 677   return JNI_OK;
 678 }
 679 
 680 CollectedHeap* Universe::create_heap() {
 681   assert(_collectedHeap == NULL, "Heap already created");
 682 #if !INCLUDE_ALL_GCS
 683   if (UseParallelGC) {
 684     fatal("UseParallelGC not supported in this VM.");
 685   } else if (UseG1GC) {
 686     fatal("UseG1GC not supported in this VM.");
 687   } else if (UseConcMarkSweepGC) {
 688     fatal("UseConcMarkSweepGC not supported in this VM.");
 689 #else
 690   if (UseParallelGC) {
 691     return Universe::create_heap_with_policy<ParallelScavengeHeap, GenerationSizer>();
 692   } else if (UseG1GC) {
 693     return Universe::create_heap_with_policy<G1CollectedHeap, G1CollectorPolicy>();
 694   } else if (UseConcMarkSweepGC) {
 695     return Universe::create_heap_with_policy<GenCollectedHeap, ConcurrentMarkSweepPolicy>();


1090 }
1091 
1092 void Universe::print_heap_before_gc() {
1093   LogHandle(gc, heap) log;
1094   if (log.is_trace()) {
1095     log.trace("Heap before GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1096     ResourceMark rm;
1097     heap()->print_on(log.trace_stream());
1098   }
1099 }
1100 
1101 void Universe::print_heap_after_gc() {
1102   LogHandle(gc, heap) log;
1103   if (log.is_trace()) {
1104     log.trace("Heap after GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1105     ResourceMark rm;
1106     heap()->print_on(log.trace_stream());
1107   }
1108 }
1109 
1110 void Universe::initialize_verify_flags() {
1111   verify_flags = 0;
1112 
1113   size_t length = strlen(VerifySubSet);
1114   char* subset_list = (char*) os::malloc(length + 1, mtInternal);
1115   if (subset_list == NULL) {
1116     tty->print_cr("VerifySubSet: Could not allocate memory for verify-subset, skipping subset initailization.");
1117     return;
1118   }
1119   strncpy(subset_list, VerifySubSet, length + 1);
1120 
1121   char* token = strtok(subset_list, " ,");
1122   while (token != NULL) {
1123     if (strcmp(token, "threads") == 0) {
1124       verify_flags |= Verify_Threads;
1125     } else if (strcmp(token, "heap") == 0) {
1126       verify_flags |= Verify_Heap;
1127     } else if (strcmp(token, "symbol_table") == 0) {
1128       verify_flags |= Verify_SymbolTable;
1129     } else if (strcmp(token, "string_table") == 0) {
1130       verify_flags |= Verify_StringTable;
1131     } else if (strcmp(token, "codecache") == 0) {
1132       verify_flags |= Verify_CodeCache;
1133     } else if (strcmp(token, "dictionary") == 0) {
1134       verify_flags |= Verify_SystemDictionary;
1135     } else if (strcmp(token, "classloader_data_graph") == 0) {
1136       verify_flags |= Verify_ClassLoaderDataGraph;
1137     } else if (strcmp(token, "metaspace") == 0) {
1138       verify_flags |= Verify_MetaspaceAux;
1139     } else if (strcmp(token, "jni_handles") == 0) {
1140       verify_flags |= Verify_JNIHandles;
1141     } else if (strcmp(token, "c-heap") == 0) {
1142       verify_flags |= Verify_CHeap;
1143     } else if (strcmp(token, "codecache_oops") == 0) {
1144       verify_flags |= Verify_CodeCacheOops;
1145     } else {
1146       tty->print_cr("VerifySubSet: %s is unknown, skipping it.", token);
1147     } 
1148     token = strtok(NULL, " ,");
1149   }
1150   free(subset_list);
1151 }
1152 
1153 bool Universe::should_verify_subset(uint subset) {
1154   if (verify_flags & subset) {
1155     return true;
1156   }
1157   return false;
1158 }
1159 
1160 void Universe::verify(VerifyOption option, const char* prefix) {
1161   // The use of _verify_in_progress is a temporary work around for
1162   // 6320749.  Don't bother with a creating a class to set and clear
1163   // it since it is only used in this method and the control flow is
1164   // straight forward.
1165   _verify_in_progress = true;
1166 
1167   COMPILER2_PRESENT(
1168     assert(!DerivedPointerTable::is_active(),
1169          "DPT should not be active during verification "
1170          "(of thread stacks below)");
1171   )
1172 
1173   ResourceMark rm;
1174   HandleMark hm;  // Handles created during verification can be zapped
1175   _verify_count++;
1176 
1177   FormatBuffer<> title("Verifying %s", prefix);
1178   GCTraceTime(Info, gc, verify) tm(title.buffer());
1179   if (should_verify_subset(Verify_Threads)) {
1180     log_debug(gc, verify)("Threads");
1181     Threads::verify();
1182   }
1183   if (should_verify_subset(Verify_Heap)) {
1184     log_debug(gc, verify)("Heap");
1185     heap()->verify(option);
1186   }
1187   if (should_verify_subset(Verify_SymbolTable)) {
1188     log_debug(gc, verify)("SymbolTable");
1189     SymbolTable::verify();
1190   }
1191   if (should_verify_subset(Verify_StringTable)) {
1192     log_debug(gc, verify)("StringTable");
1193     StringTable::verify();
1194   }
1195   if (should_verify_subset(Verify_CodeCache)) {
1196   {
1197     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1198     log_debug(gc, verify)("CodeCache");
1199     CodeCache::verify();
1200   }
1201   }
1202   if (should_verify_subset(Verify_SystemDictionary)) {
1203     log_debug(gc, verify)("SystemDictionary");
1204     SystemDictionary::verify();
1205   }
1206 #ifndef PRODUCT
1207   if (should_verify_subset(Verify_ClassLoaderDataGraph)) {
1208     log_debug(gc, verify)("ClassLoaderDataGraph");
1209     ClassLoaderDataGraph::verify();
1210   }
1211 #endif
1212   if (should_verify_subset(Verify_MetaspaceAux)) {
1213     log_debug(gc, verify)("MetaspaceAux");
1214     MetaspaceAux::verify_free_chunks();
1215   }
1216   if (should_verify_subset(Verify_JNIHandles)) {
1217     log_debug(gc, verify)("JNIHandles");
1218     JNIHandles::verify();
1219   }
1220   if (should_verify_subset(Verify_CHeap)) {
1221     log_debug(gc, verify)("C-heap");
1222     os::check_heap();
1223   }
1224   if (should_verify_subset(Verify_CodeCacheOops)) {
1225     log_debug(gc, verify)("CodeCache Oops");
1226     CodeCache::verify_oops();
1227   }
1228 
1229   _verify_in_progress = false;
1230 }
1231 
1232 
1233 #ifndef PRODUCT
1234 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1235   assert(low_boundary < high_boundary, "bad interval");
1236 
1237   // decide which low-order bits we require to be clear:
1238   size_t alignSize = MinObjAlignmentInBytes;
1239   size_t min_object_size = CollectedHeap::min_fill_size();
1240 
1241   // make an inclusive limit:
1242   uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1243   uintptr_t min = (uintptr_t)low_boundary;
1244   assert(min < max, "bad interval");
1245   uintptr_t diff = max ^ min;
1246 
1247   // throw away enough low-order bits to make the diff vanish