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;
501 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
502 int list_length = list->length();
503 for (int i = 0; i < list_length; i++) {
504 Klass* k = list->at(i);
505 assert(k->is_klass(), "List should only hold classes");
506 EXCEPTION_MARK;
507 KlassHandle kh(THREAD, k);
508 java_lang_Class::fixup_mirror(kh, CATCH);
509 }
510 delete java_lang_Class::fixup_mirror_list();
511 java_lang_Class::set_fixup_mirror_list(NULL);
512 }
513
514 static bool has_run_finalizers_on_exit = false;
515
516 void Universe::run_finalizers_on_exit() {
517 if (has_run_finalizers_on_exit) return;
518 has_run_finalizers_on_exit = true;
519
520 // Called on VM exit. This ought to be run in a separate thread.
521 if (TraceReferenceGC) tty->print_cr("Callback to run finalizers on exit");
522 {
523 PRESERVE_EXCEPTION_MARK;
524 KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
525 JavaValue result(T_VOID);
526 JavaCalls::call_static(
527 &result,
528 finalizer_klass,
529 vmSymbols::run_finalizers_on_exit_name(),
530 vmSymbols::void_method_signature(),
531 THREAD
532 );
533 // Ignore any pending exceptions
534 CLEAR_PENDING_EXCEPTION;
535 }
536 }
537
538
539 // initialize_vtable could cause gc if
540 // 1) we specified true to initialize_vtable and
541 // 2) this ran after gc was enabled
724 // Choose the heap base address and oop encoding mode
725 // when compressed oops are used:
726 // Unscaled - Use 32-bits oops without encoding when
727 // NarrowOopHeapBaseMin + heap_size < 4Gb
728 // ZeroBased - Use zero based compressed oops with encoding when
729 // NarrowOopHeapBaseMin + heap_size < 32Gb
730 // HeapBased - Use compressed oops with heap base + encoding.
731
732 jint Universe::initialize_heap() {
733 jint status = JNI_ERR;
734
735 _collectedHeap = create_heap_ext();
736 if (_collectedHeap == NULL) {
737 _collectedHeap = create_heap();
738 }
739
740 status = _collectedHeap->initialize();
741 if (status != JNI_OK) {
742 return status;
743 }
744
745 ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
746
747 #ifdef _LP64
748 if (UseCompressedOops) {
749 // Subtract a page because something can get allocated at heap base.
750 // This also makes implicit null checking work, because the
751 // memory+1 page below heap_base needs to cause a signal.
752 // See needs_explicit_null_check.
753 // Only set the heap base for compressed oops because it indicates
754 // compressed oops for pstack code.
755 if ((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
756 // Didn't reserve heap below 4Gb. Must shift.
757 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
758 }
759 if ((uint64_t)Universe::heap()->reserved_region().end() <= OopEncodingHeapMax) {
760 // Did reserve heap below 32Gb. Can use base == 0;
761 Universe::set_narrow_oop_base(0);
762 }
763
1059 Universe::heap()->post_initialize();
1060
1061 // Initialize performance counters for metaspaces
1062 MetaspaceCounters::initialize_performance_counters();
1063 CompressedClassSpaceCounters::initialize_performance_counters();
1064
1065 MemoryService::add_metaspace_memory_pools();
1066
1067 MemoryService::set_universe_heap(Universe::heap());
1068 #if INCLUDE_CDS
1069 SharedClassUtil::initialize(CHECK_false);
1070 #endif
1071 return true;
1072 }
1073
1074
1075 void Universe::compute_base_vtable_size() {
1076 _base_vtable_size = ClassLoader::compute_Object_vtable();
1077 }
1078
1079
1080 void Universe::print() {
1081 print_on(gclog_or_tty);
1082 }
1083
1084 void Universe::print_on(outputStream* st, bool extended) {
1085 st->print_cr("Heap");
1086 if (!extended) {
1087 heap()->print_on(st);
1088 } else {
1089 heap()->print_extended_on(st);
1090 }
1091 }
1092
1093 void Universe::print_heap_at_SIGBREAK() {
1094 if (PrintHeapAtSIGBREAK) {
1095 MutexLocker hl(Heap_lock);
1096 print_on(tty);
1097 tty->cr();
1098 tty->flush();
1099 }
1100 }
1101
1102 void Universe::print_heap_before_gc(outputStream* st, bool ignore_extended) {
1103 st->print_cr("{Heap before GC invocations=%u (full %u):",
1104 heap()->total_collections(),
1105 heap()->total_full_collections());
1106 if (!PrintHeapAtGCExtended || ignore_extended) {
1107 heap()->print_on(st);
1108 } else {
1109 heap()->print_extended_on(st);
1110 }
1111 }
1112
1113 void Universe::print_heap_after_gc(outputStream* st, bool ignore_extended) {
1114 st->print_cr("Heap after GC invocations=%u (full %u):",
1115 heap()->total_collections(),
1116 heap()->total_full_collections());
1117 if (!PrintHeapAtGCExtended || ignore_extended) {
1118 heap()->print_on(st);
1119 } else {
1120 heap()->print_extended_on(st);
1121 }
1122 st->print_cr("}");
1123 }
1124
1125 void Universe::verify(VerifyOption option, const char* prefix, bool silent) {
1126 // The use of _verify_in_progress is a temporary work around for
1127 // 6320749. Don't bother with a creating a class to set and clear
1128 // it since it is only used in this method and the control flow is
1129 // straight forward.
1130 _verify_in_progress = true;
1131
1132 COMPILER2_PRESENT(
1133 assert(!DerivedPointerTable::is_active(),
1134 "DPT should not be active during verification "
1135 "(of thread stacks below)");
1136 )
1137
1138 ResourceMark rm;
1139 HandleMark hm; // Handles created during verification can be zapped
1140 _verify_count++;
1141
1142 if (!silent) gclog_or_tty->print("%s", prefix);
1143 if (!silent) gclog_or_tty->print("[Verifying ");
1144 if (!silent) gclog_or_tty->print("threads ");
1145 Threads::verify();
1146 if (!silent) gclog_or_tty->print("heap ");
1147 heap()->verify(silent, option);
1148 if (!silent) gclog_or_tty->print("syms ");
1149 SymbolTable::verify();
1150 if (!silent) gclog_or_tty->print("strs ");
1151 StringTable::verify();
1152 {
1153 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1154 if (!silent) gclog_or_tty->print("zone ");
1155 CodeCache::verify();
1156 }
1157 if (!silent) gclog_or_tty->print("dict ");
1158 SystemDictionary::verify();
1159 #ifndef PRODUCT
1160 if (!silent) gclog_or_tty->print("cldg ");
1161 ClassLoaderDataGraph::verify();
1162 #endif
1163 if (!silent) gclog_or_tty->print("metaspace chunks ");
1164 MetaspaceAux::verify_free_chunks();
1165 if (!silent) gclog_or_tty->print("hand ");
1166 JNIHandles::verify();
1167 if (!silent) gclog_or_tty->print("C-heap ");
1168 os::check_heap();
1169 if (!silent) gclog_or_tty->print("code cache ");
1170 CodeCache::verify_oops();
1171 if (!silent) gclog_or_tty->print_cr("]");
1172
1173 _verify_in_progress = false;
1174 }
1175
1176
1177 #ifndef PRODUCT
1178 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1179 assert(low_boundary < high_boundary, "bad interval");
1180
1181 // decide which low-order bits we require to be clear:
1182 size_t alignSize = MinObjAlignmentInBytes;
1183 size_t min_object_size = CollectedHeap::min_fill_size();
1184
1185 // make an inclusive limit:
1186 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1187 uintptr_t min = (uintptr_t)low_boundary;
1188 assert(min < max, "bad interval");
1189 uintptr_t diff = max ^ min;
1190
1191 // 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.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;
504 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
505 int list_length = list->length();
506 for (int i = 0; i < list_length; i++) {
507 Klass* k = list->at(i);
508 assert(k->is_klass(), "List should only hold classes");
509 EXCEPTION_MARK;
510 KlassHandle kh(THREAD, k);
511 java_lang_Class::fixup_mirror(kh, CATCH);
512 }
513 delete java_lang_Class::fixup_mirror_list();
514 java_lang_Class::set_fixup_mirror_list(NULL);
515 }
516
517 static bool has_run_finalizers_on_exit = false;
518
519 void Universe::run_finalizers_on_exit() {
520 if (has_run_finalizers_on_exit) return;
521 has_run_finalizers_on_exit = true;
522
523 // Called on VM exit. This ought to be run in a separate thread.
524 log_trace(ref)("Callback to run finalizers on exit");
525 {
526 PRESERVE_EXCEPTION_MARK;
527 KlassHandle finalizer_klass(THREAD, SystemDictionary::Finalizer_klass());
528 JavaValue result(T_VOID);
529 JavaCalls::call_static(
530 &result,
531 finalizer_klass,
532 vmSymbols::run_finalizers_on_exit_name(),
533 vmSymbols::void_method_signature(),
534 THREAD
535 );
536 // Ignore any pending exceptions
537 CLEAR_PENDING_EXCEPTION;
538 }
539 }
540
541
542 // initialize_vtable could cause gc if
543 // 1) we specified true to initialize_vtable and
544 // 2) this ran after gc was enabled
727 // Choose the heap base address and oop encoding mode
728 // when compressed oops are used:
729 // Unscaled - Use 32-bits oops without encoding when
730 // NarrowOopHeapBaseMin + heap_size < 4Gb
731 // ZeroBased - Use zero based compressed oops with encoding when
732 // NarrowOopHeapBaseMin + heap_size < 32Gb
733 // HeapBased - Use compressed oops with heap base + encoding.
734
735 jint Universe::initialize_heap() {
736 jint status = JNI_ERR;
737
738 _collectedHeap = create_heap_ext();
739 if (_collectedHeap == NULL) {
740 _collectedHeap = create_heap();
741 }
742
743 status = _collectedHeap->initialize();
744 if (status != JNI_OK) {
745 return status;
746 }
747 log_info(gc)("Using %s", _collectedHeap->name());
748
749 ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
750
751 #ifdef _LP64
752 if (UseCompressedOops) {
753 // Subtract a page because something can get allocated at heap base.
754 // This also makes implicit null checking work, because the
755 // memory+1 page below heap_base needs to cause a signal.
756 // See needs_explicit_null_check.
757 // Only set the heap base for compressed oops because it indicates
758 // compressed oops for pstack code.
759 if ((uint64_t)Universe::heap()->reserved_region().end() > UnscaledOopHeapMax) {
760 // Didn't reserve heap below 4Gb. Must shift.
761 Universe::set_narrow_oop_shift(LogMinObjAlignmentInBytes);
762 }
763 if ((uint64_t)Universe::heap()->reserved_region().end() <= OopEncodingHeapMax) {
764 // Did reserve heap below 32Gb. Can use base == 0;
765 Universe::set_narrow_oop_base(0);
766 }
767
1063 Universe::heap()->post_initialize();
1064
1065 // Initialize performance counters for metaspaces
1066 MetaspaceCounters::initialize_performance_counters();
1067 CompressedClassSpaceCounters::initialize_performance_counters();
1068
1069 MemoryService::add_metaspace_memory_pools();
1070
1071 MemoryService::set_universe_heap(Universe::heap());
1072 #if INCLUDE_CDS
1073 SharedClassUtil::initialize(CHECK_false);
1074 #endif
1075 return true;
1076 }
1077
1078
1079 void Universe::compute_base_vtable_size() {
1080 _base_vtable_size = ClassLoader::compute_Object_vtable();
1081 }
1082
1083 void Universe::print_on(outputStream* st) {
1084 st->print_cr("Heap");
1085 heap()->print_on(st);
1086 }
1087
1088 void Universe::print_heap_at_SIGBREAK() {
1089 if (PrintHeapAtSIGBREAK) {
1090 MutexLocker hl(Heap_lock);
1091 print_on(tty);
1092 tty->cr();
1093 tty->flush();
1094 }
1095 }
1096
1097 void Universe::print_heap_before_gc() {
1098 LogHandle(gc, heap) log;
1099 if (log.is_trace()) {
1100 log.trace("Heap before 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::print_heap_after_gc() {
1107 LogHandle(gc, heap) log;
1108 if (log.is_trace()) {
1109 log.trace("Heap after GC invocations=%u (full %u):", heap()->total_collections(), heap()->total_full_collections());
1110 ResourceMark rm;
1111 heap()->print_on(log.trace_stream());
1112 }
1113 }
1114
1115 void Universe::verify(VerifyOption option, const char* prefix) {
1116 // The use of _verify_in_progress is a temporary work around for
1117 // 6320749. Don't bother with a creating a class to set and clear
1118 // it since it is only used in this method and the control flow is
1119 // straight forward.
1120 _verify_in_progress = true;
1121
1122 COMPILER2_PRESENT(
1123 assert(!DerivedPointerTable::is_active(),
1124 "DPT should not be active during verification "
1125 "(of thread stacks below)");
1126 )
1127
1128 ResourceMark rm;
1129 HandleMark hm; // Handles created during verification can be zapped
1130 _verify_count++;
1131
1132 FormatBuffer<> title("Verifying %s", prefix);
1133 GCTraceTime(Info, gc, verify) tm(title.buffer());
1134 log_debug(gc, verify)("Threads");
1135 Threads::verify();
1136 log_debug(gc, verify)("Heap");
1137 heap()->verify(option);
1138 log_debug(gc, verify)("SymbolTable");
1139 SymbolTable::verify();
1140 log_debug(gc, verify)("StringTable");
1141 StringTable::verify();
1142 {
1143 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1144 log_debug(gc, verify)("CodeCache");
1145 CodeCache::verify();
1146 }
1147 log_debug(gc, verify)("SystemDictionary");
1148 SystemDictionary::verify();
1149 #ifndef PRODUCT
1150 log_debug(gc, verify)("ClassLoaderDataGraph");
1151 ClassLoaderDataGraph::verify();
1152 #endif
1153 log_debug(gc, verify)("MetaspaceAux");
1154 MetaspaceAux::verify_free_chunks();
1155 log_debug(gc, verify)("JNIHandles");
1156 JNIHandles::verify();
1157 log_debug(gc, verify)("C-heap");
1158 os::check_heap();
1159 log_debug(gc, verify)("CodeCache Oops");
1160 CodeCache::verify_oops();
1161
1162 _verify_in_progress = false;
1163 }
1164
1165
1166 #ifndef PRODUCT
1167 void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1168 assert(low_boundary < high_boundary, "bad interval");
1169
1170 // decide which low-order bits we require to be clear:
1171 size_t alignSize = MinObjAlignmentInBytes;
1172 size_t min_object_size = CollectedHeap::min_fill_size();
1173
1174 // make an inclusive limit:
1175 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1176 uintptr_t min = (uintptr_t)low_boundary;
1177 assert(min < max, "bad interval");
1178 uintptr_t diff = max ^ min;
1179
1180 // throw away enough low-order bits to make the diff vanish
|