1 /*
2 * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 *
48 class Universe: AllStatic {
49 // Ugh. Universe is much too friendly.
50 friend class SerialFullGC;
51 friend class oopDesc;
52 friend class ClassLoader;
53 friend class SystemDictionary;
54 friend class VMStructs;
55 friend class VM_PopulateDumpSharedSpace;
56 friend class Metaspace;
57 friend class AOTMetaspace;
58 friend class vmClasses;
59
60 friend jint universe_init();
61 friend void universe2_init();
62 friend bool universe_post_init();
63 friend void universe_post_module_init();
64
65 private:
66 // Known classes in the VM
67 static TypeArrayKlass* _typeArrayKlasses[T_LONG+1];
68 static ObjArrayKlass* _objectArrayKlass;
69 // Special int-Array that represents filler objects that are used by GC to overwrite
70 // dead objects. References to them are generally an error.
71 static Klass* _fillerArrayKlass;
72
73 // Known objects in the VM
74 static OopHandle _main_thread_group; // Reference to the main thread group object
75 static OopHandle _system_thread_group; // Reference to the system thread group object
76
77 static OopHandle _the_empty_class_array; // Canonicalized obj array of type java.lang.Class
78 static OopHandle _the_null_string; // A cache of "null" as a Java string
79 static OopHandle _the_min_jint_string; // A cache of "-2147483648" as a Java string
80
81 static OopHandle _the_null_sentinel; // A unique object pointer unused except as a sentinel for null.
82
83 // preallocated error objects (no backtrace)
84 static OopHandle _out_of_memory_errors;
85 static OopHandle _class_init_stack_overflow_error;
86
87 // preallocated cause message for delayed StackOverflowError
88 static OopHandle _delayed_stack_overflow_error_message;
112 static OopHandle _reference_pending_list;
113
114 // The particular choice of collected heap.
115 static CollectedHeap* _collectedHeap;
116
117 static intptr_t _non_oop_bits;
118
119 // array of dummy objects used with +FullGCAlot
120 DEBUG_ONLY(static OopHandle _fullgc_alot_dummy_array;)
121 DEBUG_ONLY(static int _fullgc_alot_dummy_next;)
122
123 // Compiler/dispatch support
124 static int _base_vtable_size; // Java vtbl size of klass Object (in words)
125
126 // Initialization
127 static bool _bootstrapping; // true during genesis
128 static bool _module_initialized; // true after call_initPhase2 called
129 static bool _fully_initialized; // true after universe_init and initialize_vtables called
130
131 // the array of preallocated errors with backtraces
132 static objArrayOop preallocated_out_of_memory_errors();
133
134 static objArrayOop out_of_memory_errors();
135 // generate an out of memory error; if possible using an error with preallocated backtrace;
136 // otherwise return the given default error.
137 static oop gen_out_of_memory_error(oop default_err);
138
139 static OopStorage* _vm_weak;
140 static OopStorage* _vm_global;
141
142 static jint initialize_heap();
143 static void initialize_tlab();
144 static void initialize_basic_type_mirrors(TRAPS);
145 static void fixup_mirrors(TRAPS);
146
147 static void compute_base_vtable_size(); // compute vtable size of class Object
148
149 static void genesis(TRAPS); // Create the initial world
150
151 // Mirrors for primitive classes (created eagerly)
152 static oop check_mirror(oop m) {
153 assert(m != nullptr, "mirror not initialized");
154 return m;
168 #if INCLUDE_CDS_JAVA_HEAP
169 // Each slot i stores an index that can be used to restore _basic_type_mirrors[i]
170 // from the archive heap using HeapShared::get_root(int)
171 static int _archived_basic_type_mirror_indices[T_VOID+1];
172 #endif
173
174 public:
175 static void calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) PRODUCT_RETURN;
176 static void set_verify_data(uintptr_t mask, uintptr_t bits) PRODUCT_RETURN;
177
178 // Known classes in the VM
179 static TypeArrayKlass* boolArrayKlass() { return typeArrayKlass(T_BOOLEAN); }
180 static TypeArrayKlass* byteArrayKlass() { return typeArrayKlass(T_BYTE); }
181 static TypeArrayKlass* charArrayKlass() { return typeArrayKlass(T_CHAR); }
182 static TypeArrayKlass* intArrayKlass() { return typeArrayKlass(T_INT); }
183 static TypeArrayKlass* shortArrayKlass() { return typeArrayKlass(T_SHORT); }
184 static TypeArrayKlass* longArrayKlass() { return typeArrayKlass(T_LONG); }
185 static TypeArrayKlass* floatArrayKlass() { return typeArrayKlass(T_FLOAT); }
186 static TypeArrayKlass* doubleArrayKlass() { return typeArrayKlass(T_DOUBLE); }
187
188 static ObjArrayKlass* objectArrayKlass() {
189 ObjArrayKlass* k = _objectArrayKlass;
190 assert(k != nullptr, "Object array klass should be initialized; too early?");
191 return k;
192 }
193
194 static Klass* fillerArrayKlass() {
195 Klass* k = _fillerArrayKlass;
196 assert(k != nullptr, "Filler array class should be initialized; too early?");
197 return k;
198 }
199
200 static TypeArrayKlass* typeArrayKlass(BasicType t) {
201 assert((uint)t >= T_BOOLEAN, "range check for type: %s", type2name(t));
202 assert((uint)t < T_LONG+1, "range check for type: %s", type2name(t));
203 TypeArrayKlass* k = _typeArrayKlasses[t];
204 assert(k != nullptr, "Type array class should be initialized; too early?");
205 return k;
206 }
207
208 // Known objects in the VM
209 static oop int_mirror();
236 static oop the_min_jint_string();
237
238 static oop null_ptr_exception_instance();
239 static oop arithmetic_exception_instance();
240 static oop internal_error_instance();
241 static oop array_index_out_of_bounds_exception_instance();
242 static oop array_store_exception_instance();
243 static oop class_cast_exception_instance();
244 static oop preempted_exception_instance();
245 static oop vm_exception() { return internal_error_instance(); }
246
247 static Array<Klass*>* the_array_interfaces_array() { return _the_array_interfaces_array; }
248 static uintx the_array_interfaces_bitmap() { return _the_array_interfaces_bitmap; }
249
250 static Method* finalizer_register_method();
251 static Method* loader_addClass_method();
252 static Method* throw_illegal_access_error();
253 static Method* throw_no_such_method_error();
254 static Method* do_stack_walk_method();
255
256 static oop the_null_sentinel();
257 static address the_null_sentinel_addr() { return (address) &_the_null_sentinel; }
258
259 // Function to initialize these
260 static void initialize_known_methods(JavaThread* current);
261
262 static void create_preallocated_out_of_memory_errors(TRAPS);
263
264 // Reference pending list manipulation. Access is protected by
265 // Heap_lock. The getter, setter and predicate require the caller
266 // owns the lock. Swap is used by parallel non-concurrent reference
267 // processing threads, where some higher level controller owns
268 // Heap_lock, so requires the lock is locked, but not necessarily by
269 // the current thread.
270 static oop reference_pending_list();
271 static void clear_reference_pending_list();
272 static bool has_reference_pending_list();
273 static oop swap_reference_pending_list(oop list);
274
275 static Array<int>* the_empty_int_array() { return _the_empty_int_array; }
|
1 /*
2 * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 *
48 class Universe: AllStatic {
49 // Ugh. Universe is much too friendly.
50 friend class SerialFullGC;
51 friend class oopDesc;
52 friend class ClassLoader;
53 friend class SystemDictionary;
54 friend class VMStructs;
55 friend class VM_PopulateDumpSharedSpace;
56 friend class Metaspace;
57 friend class AOTMetaspace;
58 friend class vmClasses;
59
60 friend jint universe_init();
61 friend void universe2_init();
62 friend bool universe_post_init();
63 friend void universe_post_module_init();
64
65 private:
66 // Known classes in the VM
67 static TypeArrayKlass* _typeArrayKlasses[T_LONG+1];
68 static RefArrayKlass* _objectArrayKlass;
69 // Special int-Array that represents filler objects that are used by GC to overwrite
70 // dead objects. References to them are generally an error.
71 static Klass* _fillerArrayKlass;
72
73 // Known objects in the VM
74 static OopHandle _main_thread_group; // Reference to the main thread group object
75 static OopHandle _system_thread_group; // Reference to the system thread group object
76
77 static OopHandle _the_empty_class_array; // Canonicalized obj array of type java.lang.Class
78 static OopHandle _the_null_string; // A cache of "null" as a Java string
79 static OopHandle _the_min_jint_string; // A cache of "-2147483648" as a Java string
80
81 static OopHandle _the_null_sentinel; // A unique object pointer unused except as a sentinel for null.
82
83 // preallocated error objects (no backtrace)
84 static OopHandle _out_of_memory_errors;
85 static OopHandle _class_init_stack_overflow_error;
86
87 // preallocated cause message for delayed StackOverflowError
88 static OopHandle _delayed_stack_overflow_error_message;
112 static OopHandle _reference_pending_list;
113
114 // The particular choice of collected heap.
115 static CollectedHeap* _collectedHeap;
116
117 static intptr_t _non_oop_bits;
118
119 // array of dummy objects used with +FullGCAlot
120 DEBUG_ONLY(static OopHandle _fullgc_alot_dummy_array;)
121 DEBUG_ONLY(static int _fullgc_alot_dummy_next;)
122
123 // Compiler/dispatch support
124 static int _base_vtable_size; // Java vtbl size of klass Object (in words)
125
126 // Initialization
127 static bool _bootstrapping; // true during genesis
128 static bool _module_initialized; // true after call_initPhase2 called
129 static bool _fully_initialized; // true after universe_init and initialize_vtables called
130
131 // the array of preallocated errors with backtraces
132 static refArrayOop preallocated_out_of_memory_errors();
133
134 static refArrayOop out_of_memory_errors();
135 // generate an out of memory error; if possible using an error with preallocated backtrace;
136 // otherwise return the given default error.
137 static oop gen_out_of_memory_error(oop default_err);
138
139 static OopStorage* _vm_weak;
140 static OopStorage* _vm_global;
141
142 static jint initialize_heap();
143 static void initialize_tlab();
144 static void initialize_basic_type_mirrors(TRAPS);
145 static void fixup_mirrors(TRAPS);
146
147 static void compute_base_vtable_size(); // compute vtable size of class Object
148
149 static void genesis(TRAPS); // Create the initial world
150
151 // Mirrors for primitive classes (created eagerly)
152 static oop check_mirror(oop m) {
153 assert(m != nullptr, "mirror not initialized");
154 return m;
168 #if INCLUDE_CDS_JAVA_HEAP
169 // Each slot i stores an index that can be used to restore _basic_type_mirrors[i]
170 // from the archive heap using HeapShared::get_root(int)
171 static int _archived_basic_type_mirror_indices[T_VOID+1];
172 #endif
173
174 public:
175 static void calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) PRODUCT_RETURN;
176 static void set_verify_data(uintptr_t mask, uintptr_t bits) PRODUCT_RETURN;
177
178 // Known classes in the VM
179 static TypeArrayKlass* boolArrayKlass() { return typeArrayKlass(T_BOOLEAN); }
180 static TypeArrayKlass* byteArrayKlass() { return typeArrayKlass(T_BYTE); }
181 static TypeArrayKlass* charArrayKlass() { return typeArrayKlass(T_CHAR); }
182 static TypeArrayKlass* intArrayKlass() { return typeArrayKlass(T_INT); }
183 static TypeArrayKlass* shortArrayKlass() { return typeArrayKlass(T_SHORT); }
184 static TypeArrayKlass* longArrayKlass() { return typeArrayKlass(T_LONG); }
185 static TypeArrayKlass* floatArrayKlass() { return typeArrayKlass(T_FLOAT); }
186 static TypeArrayKlass* doubleArrayKlass() { return typeArrayKlass(T_DOUBLE); }
187
188 static RefArrayKlass* objectArrayKlass() {
189 RefArrayKlass* k = _objectArrayKlass;
190 assert(k != nullptr, "Object array klass should be initialized; too early?");
191 return k;
192 }
193
194 static Klass* fillerArrayKlass() {
195 Klass* k = _fillerArrayKlass;
196 assert(k != nullptr, "Filler array class should be initialized; too early?");
197 return k;
198 }
199
200 static TypeArrayKlass* typeArrayKlass(BasicType t) {
201 assert((uint)t >= T_BOOLEAN, "range check for type: %s", type2name(t));
202 assert((uint)t < T_LONG+1, "range check for type: %s", type2name(t));
203 TypeArrayKlass* k = _typeArrayKlasses[t];
204 assert(k != nullptr, "Type array class should be initialized; too early?");
205 return k;
206 }
207
208 // Known objects in the VM
209 static oop int_mirror();
236 static oop the_min_jint_string();
237
238 static oop null_ptr_exception_instance();
239 static oop arithmetic_exception_instance();
240 static oop internal_error_instance();
241 static oop array_index_out_of_bounds_exception_instance();
242 static oop array_store_exception_instance();
243 static oop class_cast_exception_instance();
244 static oop preempted_exception_instance();
245 static oop vm_exception() { return internal_error_instance(); }
246
247 static Array<Klass*>* the_array_interfaces_array() { return _the_array_interfaces_array; }
248 static uintx the_array_interfaces_bitmap() { return _the_array_interfaces_bitmap; }
249
250 static Method* finalizer_register_method();
251 static Method* loader_addClass_method();
252 static Method* throw_illegal_access_error();
253 static Method* throw_no_such_method_error();
254 static Method* do_stack_walk_method();
255
256 static Method* is_substitutable_method();
257 static Method* value_object_hash_code_method();
258
259 static oop the_null_sentinel();
260 static address the_null_sentinel_addr() { return (address) &_the_null_sentinel; }
261
262 // Function to initialize these
263 static void initialize_known_methods(JavaThread* current);
264
265 static void create_preallocated_out_of_memory_errors(TRAPS);
266
267 // Reference pending list manipulation. Access is protected by
268 // Heap_lock. The getter, setter and predicate require the caller
269 // owns the lock. Swap is used by parallel non-concurrent reference
270 // processing threads, where some higher level controller owns
271 // Heap_lock, so requires the lock is locked, but not necessarily by
272 // the current thread.
273 static oop reference_pending_list();
274 static void clear_reference_pending_list();
275 static bool has_reference_pending_list();
276 static oop swap_reference_pending_list(oop list);
277
278 static Array<int>* the_empty_int_array() { return _the_empty_int_array; }
|