19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/classLoaderData.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/stringTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/codeCache.hpp"
33 #include "code/dependencies.hpp"
34 #include "gc/shared/cardTableModRefBS.hpp"
35 #include "gc/shared/collectedHeap.inline.hpp"
36 #include "gc/shared/gcLocker.inline.hpp"
37 #include "gc/shared/genCollectedHeap.hpp"
38 #include "gc/shared/generation.hpp"
39 #include "gc/shared/space.hpp"
40 #include "interpreter/interpreter.hpp"
41 #include "memory/filemap.hpp"
42 #include "memory/metadataFactory.hpp"
43 #include "memory/metaspaceShared.hpp"
44 #include "memory/oopFactory.hpp"
45 #include "memory/universe.hpp"
46 #include "memory/universe.inline.hpp"
47 #include "oops/constantPool.hpp"
48 #include "oops/instanceClassLoaderKlass.hpp"
49 #include "oops/instanceKlass.hpp"
50 #include "oops/instanceMirrorKlass.hpp"
51 #include "oops/instanceRefKlass.hpp"
52 #include "oops/objArrayOop.inline.hpp"
53 #include "oops/oop.inline.hpp"
54 #include "oops/typeArrayKlass.hpp"
55 #include "prims/jvmtiRedefineClassesTrace.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/atomic.inline.hpp"
58 #include "runtime/commandLineFlagConstraintList.hpp"
59 #include "runtime/deoptimization.hpp"
60 #include "runtime/fprofiler.hpp"
61 #include "runtime/handles.inline.hpp"
62 #include "runtime/init.hpp"
63 #include "runtime/java.hpp"
64 #include "runtime/javaCalls.hpp"
65 #include "runtime/sharedRuntime.hpp"
66 #include "runtime/synchronizer.hpp"
67 #include "runtime/thread.inline.hpp"
68 #include "runtime/timer.hpp"
69 #include "runtime/vm_operations.hpp"
70 #include "services/memoryService.hpp"
71 #include "utilities/copy.hpp"
72 #include "utilities/events.hpp"
73 #include "utilities/hashtable.inline.hpp"
74 #include "utilities/macros.hpp"
75 #include "utilities/preserveException.hpp"
76 #if INCLUDE_ALL_GCS
77 #include "gc/cms/cmsCollectorPolicy.hpp"
78 #include "gc/g1/g1CollectedHeap.inline.hpp"
79 #include "gc/g1/g1CollectorPolicy.hpp"
80 #include "gc/parallel/parallelScavengeHeap.hpp"
81 #include "gc/shared/adaptiveSizePolicy.hpp"
82 #endif // INCLUDE_ALL_GCS
83 #if INCLUDE_CDS
84 #include "classfile/sharedClassUtil.hpp"
85 #endif
86
87 // Known objects
88 Klass* Universe::_boolArrayKlassObj = NULL;
89 Klass* Universe::_byteArrayKlassObj = NULL;
90 Klass* Universe::_charArrayKlassObj = NULL;
91 Klass* Universe::_intArrayKlassObj = NULL;
92 Klass* Universe::_shortArrayKlassObj = NULL;
93 Klass* Universe::_longArrayKlassObj = NULL;
94 Klass* Universe::_singleArrayKlassObj = NULL;
472 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
473 int list_length = list->length();
474 for (int i = 0; i < list_length; i++) {
475 Klass* k = list->at(i);
476 assert(k->is_klass(), "List should only hold classes");
477 EXCEPTION_MARK;
478 KlassHandle kh(THREAD, k);
479 java_lang_Class::fixup_mirror(kh, CATCH);
480 }
481 delete java_lang_Class::fixup_mirror_list();
482 java_lang_Class::set_fixup_mirror_list(NULL);
483 }
484
485 static bool has_run_finalizers_on_exit = false;
486
487 void Universe::run_finalizers_on_exit() {
488 if (has_run_finalizers_on_exit) return;
489 has_run_finalizers_on_exit = true;
490
491 // Called on VM exit. This ought to be run in a separate thread.
492 if (TraceReferenceGC) tty->print_cr("Callback to run finalizers on exit");
493 {
494 PRESERVE_EXCEPTION_MARK;
495 KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
496 JavaValue result(T_VOID);
497 JavaCalls::call_static(
498 &result,
499 finalizer_klass,
500 vmSymbols::run_finalizers_on_exit_name(),
501 vmSymbols::void_method_signature(),
502 THREAD
503 );
504 // Ignore any pending exceptions
505 CLEAR_PENDING_EXCEPTION;
506 }
507 }
508
509
510 // initialize_vtable could cause gc if
511 // 1) we specified true to initialize_vtable and
512 // 2) this ran after gc was enabled
696 // Choose the heap base address and oop encoding mode
697 // when compressed oops are used:
698 // Unscaled - Use 32-bits oops without encoding when
699 // NarrowOopHeapBaseMin + heap_size < 4Gb
700 // ZeroBased - Use zero based compressed oops with encoding when
701 // NarrowOopHeapBaseMin + heap_size < 32Gb
702 // HeapBased - Use compressed oops with heap base + encoding.
703
704 jint Universe::initialize_heap() {
705 jint status = JNI_ERR;
706
707 _collectedHeap = create_heap_ext();
708 if (_collectedHeap == NULL) {
709 _collectedHeap = create_heap();
710 }
711
712 status = _collectedHeap->initialize();
713 if (status != JNI_OK) {
714 return status;
715 }
716
717 ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
718
719 #ifdef _LP64
720 if (UseCompressedOops) {
721 // Subtract a page because something can get allocated at heap base.
722 // This also makes implicit null checking work, because the
723 // memory+1 page below heap_base needs to cause a signal.
724 // See needs_explicit_null_check.
725 // Only set the heap base for compressed oops because it indicates
726 // compressed oops for pstack code.
727 if ((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
728 // Didn't reserve heap below 4Gb. Must shift.
729 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
730 }
731 if ((uint64_t)Universe::heap()->reserved_region().end() <= OopEncodingHeapMax) {
732 // Did reserve heap below 32Gb. Can use base == 0;
733 Universe::set_narrow_oop_base(0);
734 }
735
1042 Universe::heap()->post_initialize();
1043
1044 // Initialize performance counters for metaspaces
1045 MetaspaceCounters::initialize_performance_counters();
1046 CompressedClassSpaceCounters::initialize_performance_counters();
1047
1048 MemoryService::add_metaspace_memory_pools();
1049
1050 MemoryService::set_universe_heap(Universe::heap());
1051 #if INCLUDE_CDS
1052 SharedClassUtil::initialize(CHECK_false);
1053 #endif
1054 return true;
1055 }
1056
1057
1058 void Universe::compute_base_vtable_size() {
1059 _base_vtable_size = ClassLoader::compute_Object_vtable();
1060 }
1061
1062
1063 void Universe::print() {
1064 print_on(gclog_or_tty);
1065 }
1066
1067 void Universe::print_on(outputStream* st, bool extended) {
1068 st->print_cr("Heap");
1069 if (!extended) {
1070 heap()->print_on(st);
1071 } else {
1072 heap()->print_extended_on(st);
1073 }
1074 }
1075
1076 void Universe::print_heap_at_SIGBREAK() {
1077 if (PrintHeapAtSIGBREAK) {
1078 MutexLocker hl(Heap_lock);
1079 print_on(tty);
1080 tty->cr();
1081 tty->flush();
1082 }
1083 }
1084
1085 void Universe::print_heap_before_gc(outputStream* st, bool ignore_extended) {
1086 st->print_cr("{Heap before GC invocations=%u (full %u):",
1087 heap()->total_collections(),
1088 heap()->total_full_collections());
1089 if (!PrintHeapAtGCExtended || ignore_extended) {
1090 heap()->print_on(st);
1091 } else {
1092 heap()->print_extended_on(st);
1093 }
1094 }
1095
1096 void Universe::print_heap_after_gc(outputStream* st, bool ignore_extended) {
1097 st->print_cr("Heap after GC invocations=%u (full %u):",
1098 heap()->total_collections(),
1099 heap()->total_full_collections());
1100 if (!PrintHeapAtGCExtended || ignore_extended) {
1101 heap()->print_on(st);
1102 } else {
1103 heap()->print_extended_on(st);
1104 }
1105 st->print_cr("}");
1106 }
1107
1108 void Universe::verify(VerifyOption option, const char* prefix, bool silent) {
1109 // The use of _verify_in_progress is a temporary work around for
1110 // 6320749. Don't bother with a creating a class to set and clear
1111 // it since it is only used in this method and the control flow is
1112 // straight forward.
1113 _verify_in_progress = true;
1114
1115 COMPILER2_PRESENT(
1116 assert(!DerivedPointerTable::is_active(),
1117 "DPT should not be active during verification "
1118 "(of thread stacks below)");
1119 )
1120
1121 ResourceMark rm;
1122 HandleMark hm; // Handles created during verification can be zapped
1123 _verify_count++;
1124
1125 if (!silent) gclog_or_tty->print("%s", prefix);
1126 if (!silent) gclog_or_tty->print("[Verifying ");
1127 if (!silent) gclog_or_tty->print("threads ");
1128 Threads::verify();
1129 if (!silent) gclog_or_tty->print("heap ");
1130 heap()->verify(silent, option);
1131 if (!silent) gclog_or_tty->print("syms ");
1132 SymbolTable::verify();
1133 if (!silent) gclog_or_tty->print("strs ");
1134 StringTable::verify();
1135 {
1136 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1137 if (!silent) gclog_or_tty->print("zone ");
1138 CodeCache::verify();
1139 }
1140 if (!silent) gclog_or_tty->print("dict ");
1141 SystemDictionary::verify();
1142 #ifndef PRODUCT
1143 if (!silent) gclog_or_tty->print("cldg ");
1144 ClassLoaderDataGraph::verify();
1145 #endif
1146 if (!silent) gclog_or_tty->print("metaspace chunks ");
1147 MetaspaceAux::verify_free_chunks();
1148 if (!silent) gclog_or_tty->print("hand ");
1149 JNIHandles::verify();
1150 if (!silent) gclog_or_tty->print("C-heap ");
1151 os::check_heap();
1152 if (!silent) gclog_or_tty->print("code cache ");
1153 CodeCache::verify_oops();
1154 if (!silent) gclog_or_tty->print_cr("]");
1155
1156 _verify_in_progress = false;
1157 }
1158
1159
1160 #ifndef PRODUCT
1161 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1162 assert(low_boundary < high_boundary, "bad interval");
1163
1164 // decide which low-order bits we require to be clear:
1165 size_t alignSize = MinObjAlignmentInBytes;
1166 size_t min_object_size = CollectedHeap::min_fill_size();
1167
1168 // make an inclusive limit:
1169 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1170 uintptr_t min = (uintptr_t)low_boundary;
1171 assert(min < max, "bad interval");
1172 uintptr_t diff = max ^ min;
1173
1174 // throw away enough low-order bits to make the diff vanish
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "classfile/classLoader.hpp"
27 #include "classfile/classLoaderData.hpp"
28 #include "classfile/javaClasses.hpp"
29 #include "classfile/stringTable.hpp"
30 #include "classfile/systemDictionary.hpp"
31 #include "classfile/vmSymbols.hpp"
32 #include "code/codeCache.hpp"
33 #include "code/dependencies.hpp"
34 #include "gc/shared/cardTableModRefBS.hpp"
35 #include "gc/shared/collectedHeap.inline.hpp"
36 #include "gc/shared/gcLocker.inline.hpp"
37 #include "gc/shared/genCollectedHeap.hpp"
38 #include "gc/shared/generation.hpp"
39 #include "gc/shared/gcTraceTime.inline.hpp"
40 #include "gc/shared/space.hpp"
41 #include "interpreter/interpreter.hpp"
42 #include "logging/log.hpp"
43 #include "memory/filemap.hpp"
44 #include "memory/metadataFactory.hpp"
45 #include "memory/metaspaceShared.hpp"
46 #include "memory/oopFactory.hpp"
47 #include "memory/universe.hpp"
48 #include "memory/universe.inline.hpp"
49 #include "oops/constantPool.hpp"
50 #include "oops/instanceClassLoaderKlass.hpp"
51 #include "oops/instanceKlass.hpp"
52 #include "oops/instanceMirrorKlass.hpp"
53 #include "oops/instanceRefKlass.hpp"
54 #include "oops/objArrayOop.inline.hpp"
55 #include "oops/oop.inline.hpp"
56 #include "oops/typeArrayKlass.hpp"
57 #include "prims/jvmtiRedefineClassesTrace.hpp"
58 #include "runtime/arguments.hpp"
59 #include "runtime/atomic.inline.hpp"
60 #include "runtime/commandLineFlagConstraintList.hpp"
61 #include "runtime/deoptimization.hpp"
62 #include "runtime/fprofiler.hpp"
63 #include "runtime/handles.inline.hpp"
64 #include "runtime/init.hpp"
65 #include "runtime/java.hpp"
66 #include "runtime/javaCalls.hpp"
67 #include "runtime/sharedRuntime.hpp"
68 #include "runtime/synchronizer.hpp"
69 #include "runtime/thread.inline.hpp"
70 #include "runtime/timer.hpp"
71 #include "runtime/vm_operations.hpp"
72 #include "services/memoryService.hpp"
73 #include "utilities/copy.hpp"
74 #include "utilities/events.hpp"
75 #include "utilities/hashtable.inline.hpp"
76 #include "utilities/macros.hpp"
77 #include "utilities/ostream.hpp"
78 #include "utilities/preserveException.hpp"
79 #if INCLUDE_ALL_GCS
80 #include "gc/cms/cmsCollectorPolicy.hpp"
81 #include "gc/g1/g1CollectedHeap.inline.hpp"
82 #include "gc/g1/g1CollectorPolicy.hpp"
83 #include "gc/parallel/parallelScavengeHeap.hpp"
84 #include "gc/shared/adaptiveSizePolicy.hpp"
85 #endif // INCLUDE_ALL_GCS
86 #if INCLUDE_CDS
87 #include "classfile/sharedClassUtil.hpp"
88 #endif
89
90 // Known objects
91 Klass* Universe::_boolArrayKlassObj = NULL;
92 Klass* Universe::_byteArrayKlassObj = NULL;
93 Klass* Universe::_charArrayKlassObj = NULL;
94 Klass* Universe::_intArrayKlassObj = NULL;
95 Klass* Universe::_shortArrayKlassObj = NULL;
96 Klass* Universe::_longArrayKlassObj = NULL;
97 Klass* Universe::_singleArrayKlassObj = NULL;
475 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
476 int list_length = list->length();
477 for (int i = 0; i < list_length; i++) {
478 Klass* k = list->at(i);
479 assert(k->is_klass(), "List should only hold classes");
480 EXCEPTION_MARK;
481 KlassHandle kh(THREAD, k);
482 java_lang_Class::fixup_mirror(kh, CATCH);
483 }
484 delete java_lang_Class::fixup_mirror_list();
485 java_lang_Class::set_fixup_mirror_list(NULL);
486 }
487
488 static bool has_run_finalizers_on_exit = false;
489
490 void Universe::run_finalizers_on_exit() {
491 if (has_run_finalizers_on_exit) return;
492 has_run_finalizers_on_exit = true;
493
494 // Called on VM exit. This ought to be run in a separate thread.
495 log_trace(ref)("Callback to run finalizers on exit");
496 {
497 PRESERVE_EXCEPTION_MARK;
498 KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
499 JavaValue result(T_VOID);
500 JavaCalls::call_static(
501 &result,
502 finalizer_klass,
503 vmSymbols::run_finalizers_on_exit_name(),
504 vmSymbols::void_method_signature(),
505 THREAD
506 );
507 // Ignore any pending exceptions
508 CLEAR_PENDING_EXCEPTION;
509 }
510 }
511
512
513 // initialize_vtable could cause gc if
514 // 1) we specified true to initialize_vtable and
515 // 2) this ran after gc was enabled
699 // Choose the heap base address and oop encoding mode
700 // when compressed oops are used:
701 // Unscaled - Use 32-bits oops without encoding when
702 // NarrowOopHeapBaseMin + heap_size < 4Gb
703 // ZeroBased - Use zero based compressed oops with encoding when
704 // NarrowOopHeapBaseMin + heap_size < 32Gb
705 // HeapBased - Use compressed oops with heap base + encoding.
706
707 jint Universe::initialize_heap() {
708 jint status = JNI_ERR;
709
710 _collectedHeap = create_heap_ext();
711 if (_collectedHeap == NULL) {
712 _collectedHeap = create_heap();
713 }
714
715 status = _collectedHeap->initialize();
716 if (status != JNI_OK) {
717 return status;
718 }
719 log_info(gc)("Using %s", _collectedHeap->name());
720
721 ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
722
723 #ifdef _LP64
724 if (UseCompressedOops) {
725 // Subtract a page because something can get allocated at heap base.
726 // This also makes implicit null checking work, because the
727 // memory+1 page below heap_base needs to cause a signal.
728 // See needs_explicit_null_check.
729 // Only set the heap base for compressed oops because it indicates
730 // compressed oops for pstack code.
731 if ((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
732 // Didn't reserve heap below 4Gb. Must shift.
733 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
734 }
735 if ((uint64_t)Universe::heap()->reserved_region().end() <= OopEncodingHeapMax) {
736 // Did reserve heap below 32Gb. Can use base == 0;
737 Universe::set_narrow_oop_base(0);
738 }
739
1046 Universe::heap()->post_initialize();
1047
1048 // Initialize performance counters for metaspaces
1049 MetaspaceCounters::initialize_performance_counters();
1050 CompressedClassSpaceCounters::initialize_performance_counters();
1051
1052 MemoryService::add_metaspace_memory_pools();
1053
1054 MemoryService::set_universe_heap(Universe::heap());
1055 #if INCLUDE_CDS
1056 SharedClassUtil::initialize(CHECK_false);
1057 #endif
1058 return true;
1059 }
1060
1061
1062 void Universe::compute_base_vtable_size() {
1063 _base_vtable_size = ClassLoader::compute_Object_vtable();
1064 }
1065
1066 void Universe::print_on(outputStream* st) {
1067 st->print_cr("Heap");
1068 heap()->print_on(st);
1069 }
1070
1071 void Universe::print_heap_at_SIGBREAK() {
1072 if (PrintHeapAtSIGBREAK) {
1073 MutexLocker hl(Heap_lock);
1074 print_on(tty);
1075 tty->cr();
1076 tty->flush();
1077 }
1078 }
1079
1080 void Universe::print_heap_before_gc() {
1081 LogHandle(gc, heap) log;
1082 if (log.is_trace()) {
1083 log.trace("Heap before GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1084 ResourceMark rm;
1085 heap()->print_on(log.trace_stream());
1086 }
1087 }
1088
1089 void Universe::print_heap_after_gc() {
1090 LogHandle(gc, heap) log;
1091 if (log.is_trace()) {
1092 log.trace("Heap after GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1093 ResourceMark rm;
1094 heap()->print_on(log.trace_stream());
1095 }
1096 }
1097
1098 void Universe::verify(VerifyOption option, const char* prefix) {
1099 // The use of _verify_in_progress is a temporary work around for
1100 // 6320749. Don't bother with a creating a class to set and clear
1101 // it since it is only used in this method and the control flow is
1102 // straight forward.
1103 _verify_in_progress = true;
1104
1105 COMPILER2_PRESENT(
1106 assert(!DerivedPointerTable::is_active(),
1107 "DPT should not be active during verification "
1108 "(of thread stacks below)");
1109 )
1110
1111 ResourceMark rm;
1112 HandleMark hm; // Handles created during verification can be zapped
1113 _verify_count++;
1114
1115 FormatBuffer<> title("Verifying %s", prefix);
1116 GCTraceTime(Info, gc, verify) tm(title.buffer());
1117 log_debug(gc, verify)("Threads");
1118 Threads::verify();
1119 log_debug(gc, verify)("Heap");
1120 heap()->verify(option);
1121 log_debug(gc, verify)("SymbolTable");
1122 SymbolTable::verify();
1123 log_debug(gc, verify)("StringTable");
1124 StringTable::verify();
1125 {
1126 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1127 log_debug(gc, verify)("CodeCache");
1128 CodeCache::verify();
1129 }
1130 log_debug(gc, verify)("SystemDictionary");
1131 SystemDictionary::verify();
1132 #ifndef PRODUCT
1133 log_debug(gc, verify)("ClassLoaderDataGraph");
1134 ClassLoaderDataGraph::verify();
1135 #endif
1136 log_debug(gc, verify)("MetaspaceAux");
1137 MetaspaceAux::verify_free_chunks();
1138 log_debug(gc, verify)("JNIHandles");
1139 JNIHandles::verify();
1140 log_debug(gc, verify)("C-heap");
1141 os::check_heap();
1142 log_debug(gc, verify)("CodeCache Oops");
1143 CodeCache::verify_oops();
1144
1145 _verify_in_progress = false;
1146 }
1147
1148
1149 #ifndef PRODUCT
1150 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1151 assert(low_boundary < high_boundary, "bad interval");
1152
1153 // decide which low-order bits we require to be clear:
1154 size_t alignSize = MinObjAlignmentInBytes;
1155 size_t min_object_size = CollectedHeap::min_fill_size();
1156
1157 // make an inclusive limit:
1158 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1159 uintptr_t min = (uintptr_t)low_boundary;
1160 assert(min < max, "bad interval");
1161 uintptr_t diff = max ^ min;
1162
1163 // throw away enough low-order bits to make the diff vanish
|