Mercurial > hg > graal-compiler
comparison src/share/vm/memory/universe.cpp @ 6725:da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author | coleenp |
---|---|
date | Sat, 01 Sep 2012 13:25:18 -0400 |
parents | d2a62e0f25eb |
children | aed758eda82a |
comparison
equal
deleted
inserted
replaced
6724:36d1d483d5d6 | 6725:da91efe96a93 |
---|---|
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "classfile/classLoader.hpp" | 26 #include "classfile/classLoader.hpp" |
27 #include "classfile/classLoaderData.hpp" | |
27 #include "classfile/javaClasses.hpp" | 28 #include "classfile/javaClasses.hpp" |
28 #include "classfile/symbolTable.hpp" | 29 #include "classfile/symbolTable.hpp" |
29 #include "classfile/systemDictionary.hpp" | 30 #include "classfile/systemDictionary.hpp" |
30 #include "classfile/vmSymbols.hpp" | 31 #include "classfile/vmSymbols.hpp" |
31 #include "code/codeCache.hpp" | 32 #include "code/codeCache.hpp" |
32 #include "code/dependencies.hpp" | 33 #include "code/dependencies.hpp" |
33 #include "gc_interface/collectedHeap.inline.hpp" | 34 #include "gc_interface/collectedHeap.inline.hpp" |
34 #include "interpreter/interpreter.hpp" | 35 #include "interpreter/interpreter.hpp" |
35 #include "memory/cardTableModRefBS.hpp" | 36 #include "memory/cardTableModRefBS.hpp" |
36 #include "memory/filemap.hpp" | |
37 #include "memory/gcLocker.inline.hpp" | 37 #include "memory/gcLocker.inline.hpp" |
38 #include "memory/genCollectedHeap.hpp" | 38 #include "memory/genCollectedHeap.hpp" |
39 #include "memory/genRemSet.hpp" | 39 #include "memory/genRemSet.hpp" |
40 #include "memory/generation.hpp" | 40 #include "memory/generation.hpp" |
41 #include "memory/metadataFactory.hpp" | |
42 #include "memory/metaspaceShared.hpp" | |
41 #include "memory/oopFactory.hpp" | 43 #include "memory/oopFactory.hpp" |
42 #include "memory/permGen.hpp" | |
43 #include "memory/space.hpp" | 44 #include "memory/space.hpp" |
44 #include "memory/universe.hpp" | 45 #include "memory/universe.hpp" |
45 #include "memory/universe.inline.hpp" | 46 #include "memory/universe.inline.hpp" |
46 #include "oops/arrayKlassKlass.hpp" | 47 #include "oops/constantPool.hpp" |
47 #include "oops/compiledICHolderKlass.hpp" | 48 #include "oops/instanceClassLoaderKlass.hpp" |
48 #include "oops/constMethodKlass.hpp" | |
49 #include "oops/constantPoolKlass.hpp" | |
50 #include "oops/constantPoolOop.hpp" | |
51 #include "oops/cpCacheKlass.hpp" | |
52 #include "oops/cpCacheOop.hpp" | |
53 #include "oops/instanceKlass.hpp" | 49 #include "oops/instanceKlass.hpp" |
54 #include "oops/instanceMirrorKlass.hpp" | 50 #include "oops/instanceMirrorKlass.hpp" |
55 #include "oops/instanceKlassKlass.hpp" | |
56 #include "oops/instanceRefKlass.hpp" | 51 #include "oops/instanceRefKlass.hpp" |
57 #include "oops/klassKlass.hpp" | |
58 #include "oops/klassOop.hpp" | |
59 #include "oops/methodDataKlass.hpp" | |
60 #include "oops/methodKlass.hpp" | |
61 #include "oops/objArrayKlassKlass.hpp" | |
62 #include "oops/oop.inline.hpp" | 52 #include "oops/oop.inline.hpp" |
63 #include "oops/typeArrayKlass.hpp" | 53 #include "oops/typeArrayKlass.hpp" |
64 #include "oops/typeArrayKlassKlass.hpp" | |
65 #include "prims/jvmtiRedefineClassesTrace.hpp" | 54 #include "prims/jvmtiRedefineClassesTrace.hpp" |
66 #include "runtime/aprofiler.hpp" | 55 #include "runtime/aprofiler.hpp" |
67 #include "runtime/arguments.hpp" | 56 #include "runtime/arguments.hpp" |
68 #include "runtime/deoptimization.hpp" | 57 #include "runtime/deoptimization.hpp" |
69 #include "runtime/fprofiler.hpp" | 58 #include "runtime/fprofiler.hpp" |
99 #include "gc_implementation/g1/g1CollectorPolicy.hpp" | 88 #include "gc_implementation/g1/g1CollectorPolicy.hpp" |
100 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" | 89 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp" |
101 #endif | 90 #endif |
102 | 91 |
103 // Known objects | 92 // Known objects |
104 klassOop Universe::_boolArrayKlassObj = NULL; | 93 Klass* Universe::_boolArrayKlassObj = NULL; |
105 klassOop Universe::_byteArrayKlassObj = NULL; | 94 Klass* Universe::_byteArrayKlassObj = NULL; |
106 klassOop Universe::_charArrayKlassObj = NULL; | 95 Klass* Universe::_charArrayKlassObj = NULL; |
107 klassOop Universe::_intArrayKlassObj = NULL; | 96 Klass* Universe::_intArrayKlassObj = NULL; |
108 klassOop Universe::_shortArrayKlassObj = NULL; | 97 Klass* Universe::_shortArrayKlassObj = NULL; |
109 klassOop Universe::_longArrayKlassObj = NULL; | 98 Klass* Universe::_longArrayKlassObj = NULL; |
110 klassOop Universe::_singleArrayKlassObj = NULL; | 99 Klass* Universe::_singleArrayKlassObj = NULL; |
111 klassOop Universe::_doubleArrayKlassObj = NULL; | 100 Klass* Universe::_doubleArrayKlassObj = NULL; |
112 klassOop Universe::_typeArrayKlassObjs[T_VOID+1] = { NULL /*, NULL...*/ }; | 101 Klass* Universe::_typeArrayKlassObjs[T_VOID+1] = { NULL /*, NULL...*/ }; |
113 klassOop Universe::_objectArrayKlassObj = NULL; | 102 Klass* Universe::_objectArrayKlassObj = NULL; |
114 klassOop Universe::_methodKlassObj = NULL; | |
115 klassOop Universe::_constMethodKlassObj = NULL; | |
116 klassOop Universe::_methodDataKlassObj = NULL; | |
117 klassOop Universe::_klassKlassObj = NULL; | |
118 klassOop Universe::_arrayKlassKlassObj = NULL; | |
119 klassOop Universe::_objArrayKlassKlassObj = NULL; | |
120 klassOop Universe::_typeArrayKlassKlassObj = NULL; | |
121 klassOop Universe::_instanceKlassKlassObj = NULL; | |
122 klassOop Universe::_constantPoolKlassObj = NULL; | |
123 klassOop Universe::_constantPoolCacheKlassObj = NULL; | |
124 klassOop Universe::_compiledICHolderKlassObj = NULL; | |
125 klassOop Universe::_systemObjArrayKlassObj = NULL; | |
126 oop Universe::_int_mirror = NULL; | 103 oop Universe::_int_mirror = NULL; |
127 oop Universe::_float_mirror = NULL; | 104 oop Universe::_float_mirror = NULL; |
128 oop Universe::_double_mirror = NULL; | 105 oop Universe::_double_mirror = NULL; |
129 oop Universe::_byte_mirror = NULL; | 106 oop Universe::_byte_mirror = NULL; |
130 oop Universe::_bool_mirror = NULL; | 107 oop Universe::_bool_mirror = NULL; |
133 oop Universe::_short_mirror = NULL; | 110 oop Universe::_short_mirror = NULL; |
134 oop Universe::_void_mirror = NULL; | 111 oop Universe::_void_mirror = NULL; |
135 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ }; | 112 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ }; |
136 oop Universe::_main_thread_group = NULL; | 113 oop Universe::_main_thread_group = NULL; |
137 oop Universe::_system_thread_group = NULL; | 114 oop Universe::_system_thread_group = NULL; |
138 typeArrayOop Universe::_the_empty_byte_array = NULL; | |
139 typeArrayOop Universe::_the_empty_short_array = NULL; | |
140 typeArrayOop Universe::_the_empty_int_array = NULL; | |
141 objArrayOop Universe::_the_empty_system_obj_array = NULL; | |
142 objArrayOop Universe::_the_empty_class_klass_array = NULL; | 115 objArrayOop Universe::_the_empty_class_klass_array = NULL; |
143 objArrayOop Universe::_the_array_interfaces_array = NULL; | 116 Array<Klass*>* Universe::_the_array_interfaces_array = NULL; |
144 oop Universe::_the_null_string = NULL; | 117 oop Universe::_the_null_string = NULL; |
145 oop Universe::_the_min_jint_string = NULL; | 118 oop Universe::_the_min_jint_string = NULL; |
146 LatestMethodOopCache* Universe::_finalizer_register_cache = NULL; | 119 LatestMethodOopCache* Universe::_finalizer_register_cache = NULL; |
147 LatestMethodOopCache* Universe::_loader_addClass_cache = NULL; | |
148 ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL; | 120 ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL; |
149 oop Universe::_out_of_memory_error_java_heap = NULL; | 121 oop Universe::_out_of_memory_error_java_heap = NULL; |
150 oop Universe::_out_of_memory_error_perm_gen = NULL; | 122 oop Universe::_out_of_memory_error_perm_gen = NULL; |
151 oop Universe::_out_of_memory_error_array_size = NULL; | 123 oop Universe::_out_of_memory_error_array_size = NULL; |
152 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL; | 124 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL; |
155 bool Universe::_verify_in_progress = false; | 127 bool Universe::_verify_in_progress = false; |
156 oop Universe::_null_ptr_exception_instance = NULL; | 128 oop Universe::_null_ptr_exception_instance = NULL; |
157 oop Universe::_arithmetic_exception_instance = NULL; | 129 oop Universe::_arithmetic_exception_instance = NULL; |
158 oop Universe::_virtual_machine_error_instance = NULL; | 130 oop Universe::_virtual_machine_error_instance = NULL; |
159 oop Universe::_vm_exception = NULL; | 131 oop Universe::_vm_exception = NULL; |
132 Array<int>* Universe::_the_empty_int_array = NULL; | |
133 Array<u2>* Universe::_the_empty_short_array = NULL; | |
134 Array<Klass*>* Universe::_the_empty_klass_array = NULL; | |
135 Array<Method*>* Universe::_the_empty_method_array = NULL; | |
160 | 136 |
161 // These variables are guarded by FullGCALot_lock. | 137 // These variables are guarded by FullGCALot_lock. |
162 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;) | 138 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;) |
163 debug_only(int Universe::_fullgc_alot_dummy_next = 0;) | 139 debug_only(int Universe::_fullgc_alot_dummy_next = 0;) |
164 | 140 |
165 | |
166 // Heap | 141 // Heap |
167 int Universe::_verify_count = 0; | 142 int Universe::_verify_count = 0; |
168 | 143 |
169 int Universe::_base_vtable_size = 0; | 144 int Universe::_base_vtable_size = 0; |
170 bool Universe::_bootstrapping = false; | 145 bool Universe::_bootstrapping = false; |
176 CollectedHeap* Universe::_collectedHeap = NULL; | 151 CollectedHeap* Universe::_collectedHeap = NULL; |
177 | 152 |
178 NarrowOopStruct Universe::_narrow_oop = { NULL, 0, true }; | 153 NarrowOopStruct Universe::_narrow_oop = { NULL, 0, true }; |
179 | 154 |
180 | 155 |
181 void Universe::basic_type_classes_do(void f(klassOop)) { | 156 void Universe::basic_type_classes_do(void f(Klass*)) { |
182 f(boolArrayKlassObj()); | 157 f(boolArrayKlassObj()); |
183 f(byteArrayKlassObj()); | 158 f(byteArrayKlassObj()); |
184 f(charArrayKlassObj()); | 159 f(charArrayKlassObj()); |
185 f(intArrayKlassObj()); | 160 f(intArrayKlassObj()); |
186 f(shortArrayKlassObj()); | 161 f(shortArrayKlassObj()); |
187 f(longArrayKlassObj()); | 162 f(longArrayKlassObj()); |
188 f(singleArrayKlassObj()); | 163 f(singleArrayKlassObj()); |
189 f(doubleArrayKlassObj()); | 164 f(doubleArrayKlassObj()); |
190 } | |
191 | |
192 | |
193 void Universe::system_classes_do(void f(klassOop)) { | |
194 f(methodKlassObj()); | |
195 f(constMethodKlassObj()); | |
196 f(methodDataKlassObj()); | |
197 f(klassKlassObj()); | |
198 f(arrayKlassKlassObj()); | |
199 f(objArrayKlassKlassObj()); | |
200 f(typeArrayKlassKlassObj()); | |
201 f(instanceKlassKlassObj()); | |
202 f(constantPoolKlassObj()); | |
203 f(systemObjArrayKlassObj()); | |
204 } | 165 } |
205 | 166 |
206 void Universe::oops_do(OopClosure* f, bool do_all) { | 167 void Universe::oops_do(OopClosure* f, bool do_all) { |
207 | 168 |
208 f->do_oop((oop*) &_int_mirror); | 169 f->do_oop((oop*) &_int_mirror); |
213 f->do_oop((oop*) &_char_mirror); | 174 f->do_oop((oop*) &_char_mirror); |
214 f->do_oop((oop*) &_long_mirror); | 175 f->do_oop((oop*) &_long_mirror); |
215 f->do_oop((oop*) &_short_mirror); | 176 f->do_oop((oop*) &_short_mirror); |
216 f->do_oop((oop*) &_void_mirror); | 177 f->do_oop((oop*) &_void_mirror); |
217 | 178 |
218 // It's important to iterate over these guys even if they are null, | |
219 // since that's how shared heaps are restored. | |
220 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { | 179 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { |
221 f->do_oop((oop*) &_mirrors[i]); | 180 f->do_oop((oop*) &_mirrors[i]); |
222 } | 181 } |
223 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking"); | 182 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking"); |
224 | 183 |
225 // %%% Consider moving those "shared oops" over here with the others. | |
226 f->do_oop((oop*)&_boolArrayKlassObj); | |
227 f->do_oop((oop*)&_byteArrayKlassObj); | |
228 f->do_oop((oop*)&_charArrayKlassObj); | |
229 f->do_oop((oop*)&_intArrayKlassObj); | |
230 f->do_oop((oop*)&_shortArrayKlassObj); | |
231 f->do_oop((oop*)&_longArrayKlassObj); | |
232 f->do_oop((oop*)&_singleArrayKlassObj); | |
233 f->do_oop((oop*)&_doubleArrayKlassObj); | |
234 f->do_oop((oop*)&_objectArrayKlassObj); | |
235 { | |
236 for (int i = 0; i < T_VOID+1; i++) { | |
237 if (_typeArrayKlassObjs[i] != NULL) { | |
238 assert(i >= T_BOOLEAN, "checking"); | |
239 f->do_oop((oop*)&_typeArrayKlassObjs[i]); | |
240 } else if (do_all) { | |
241 f->do_oop((oop*)&_typeArrayKlassObjs[i]); | |
242 } | |
243 } | |
244 } | |
245 f->do_oop((oop*)&_methodKlassObj); | |
246 f->do_oop((oop*)&_constMethodKlassObj); | |
247 f->do_oop((oop*)&_methodDataKlassObj); | |
248 f->do_oop((oop*)&_klassKlassObj); | |
249 f->do_oop((oop*)&_arrayKlassKlassObj); | |
250 f->do_oop((oop*)&_objArrayKlassKlassObj); | |
251 f->do_oop((oop*)&_typeArrayKlassKlassObj); | |
252 f->do_oop((oop*)&_instanceKlassKlassObj); | |
253 f->do_oop((oop*)&_constantPoolKlassObj); | |
254 f->do_oop((oop*)&_constantPoolCacheKlassObj); | |
255 f->do_oop((oop*)&_compiledICHolderKlassObj); | |
256 f->do_oop((oop*)&_systemObjArrayKlassObj); | |
257 f->do_oop((oop*)&_the_empty_byte_array); | |
258 f->do_oop((oop*)&_the_empty_short_array); | |
259 f->do_oop((oop*)&_the_empty_int_array); | |
260 f->do_oop((oop*)&_the_empty_system_obj_array); | |
261 f->do_oop((oop*)&_the_empty_class_klass_array); | 184 f->do_oop((oop*)&_the_empty_class_klass_array); |
262 f->do_oop((oop*)&_the_array_interfaces_array); | |
263 f->do_oop((oop*)&_the_null_string); | 185 f->do_oop((oop*)&_the_null_string); |
264 f->do_oop((oop*)&_the_min_jint_string); | 186 f->do_oop((oop*)&_the_min_jint_string); |
265 _finalizer_register_cache->oops_do(f); | |
266 _loader_addClass_cache->oops_do(f); | |
267 _reflect_invoke_cache->oops_do(f); | |
268 f->do_oop((oop*)&_out_of_memory_error_java_heap); | 187 f->do_oop((oop*)&_out_of_memory_error_java_heap); |
269 f->do_oop((oop*)&_out_of_memory_error_perm_gen); | 188 f->do_oop((oop*)&_out_of_memory_error_perm_gen); |
270 f->do_oop((oop*)&_out_of_memory_error_array_size); | 189 f->do_oop((oop*)&_out_of_memory_error_array_size); |
271 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit); | 190 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit); |
272 if (_preallocated_out_of_memory_error_array != (oop)NULL) { // NULL when DumpSharedSpaces | |
273 f->do_oop((oop*)&_preallocated_out_of_memory_error_array); | 191 f->do_oop((oop*)&_preallocated_out_of_memory_error_array); |
274 } | |
275 f->do_oop((oop*)&_null_ptr_exception_instance); | 192 f->do_oop((oop*)&_null_ptr_exception_instance); |
276 f->do_oop((oop*)&_arithmetic_exception_instance); | 193 f->do_oop((oop*)&_arithmetic_exception_instance); |
277 f->do_oop((oop*)&_virtual_machine_error_instance); | 194 f->do_oop((oop*)&_virtual_machine_error_instance); |
278 f->do_oop((oop*)&_main_thread_group); | 195 f->do_oop((oop*)&_main_thread_group); |
279 f->do_oop((oop*)&_system_thread_group); | 196 f->do_oop((oop*)&_system_thread_group); |
280 f->do_oop((oop*)&_vm_exception); | 197 f->do_oop((oop*)&_vm_exception); |
281 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);) | 198 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);) |
282 } | 199 } |
283 | 200 |
201 // Serialize metadata in and out of CDS archive, not oops. | |
202 void Universe::serialize(SerializeClosure* f, bool do_all) { | |
203 | |
204 f->do_ptr((void**)&_boolArrayKlassObj); | |
205 f->do_ptr((void**)&_byteArrayKlassObj); | |
206 f->do_ptr((void**)&_charArrayKlassObj); | |
207 f->do_ptr((void**)&_intArrayKlassObj); | |
208 f->do_ptr((void**)&_shortArrayKlassObj); | |
209 f->do_ptr((void**)&_longArrayKlassObj); | |
210 f->do_ptr((void**)&_singleArrayKlassObj); | |
211 f->do_ptr((void**)&_doubleArrayKlassObj); | |
212 f->do_ptr((void**)&_objectArrayKlassObj); | |
213 | |
214 { | |
215 for (int i = 0; i < T_VOID+1; i++) { | |
216 if (_typeArrayKlassObjs[i] != NULL) { | |
217 assert(i >= T_BOOLEAN, "checking"); | |
218 f->do_ptr((void**)&_typeArrayKlassObjs[i]); | |
219 } else if (do_all) { | |
220 f->do_ptr((void**)&_typeArrayKlassObjs[i]); | |
221 } | |
222 } | |
223 } | |
224 | |
225 f->do_ptr((void**)&_the_array_interfaces_array); | |
226 f->do_ptr((void**)&_the_empty_int_array); | |
227 f->do_ptr((void**)&_the_empty_short_array); | |
228 f->do_ptr((void**)&_the_empty_method_array); | |
229 f->do_ptr((void**)&_the_empty_klass_array); | |
230 _finalizer_register_cache->serialize(f); | |
231 _reflect_invoke_cache->serialize(f); | |
232 } | |
284 | 233 |
285 void Universe::check_alignment(uintx size, uintx alignment, const char* name) { | 234 void Universe::check_alignment(uintx size, uintx alignment, const char* name) { |
286 if (size < alignment || size % alignment != 0) { | 235 if (size < alignment || size % alignment != 0) { |
287 ResourceMark rm; | 236 ResourceMark rm; |
288 stringStream st; | 237 stringStream st; |
290 char* error = st.as_string(); | 239 char* error = st.as_string(); |
291 vm_exit_during_initialization(error); | 240 vm_exit_during_initialization(error); |
292 } | 241 } |
293 } | 242 } |
294 | 243 |
244 void initialize_basic_type_klass(Klass* k, TRAPS) { | |
245 Klass* ok = SystemDictionary::Object_klass(); | |
246 if (UseSharedSpaces) { | |
247 assert(k->super() == ok, "u3"); | |
248 k->restore_unshareable_info(CHECK); | |
249 } else { | |
250 k->initialize_supers(ok, CHECK); | |
251 } | |
252 k->append_to_sibling_list(); | |
253 } | |
295 | 254 |
296 void Universe::genesis(TRAPS) { | 255 void Universe::genesis(TRAPS) { |
297 ResourceMark rm; | 256 ResourceMark rm; |
257 | |
298 { FlagSetting fs(_bootstrapping, true); | 258 { FlagSetting fs(_bootstrapping, true); |
299 | 259 |
300 { MutexLocker mc(Compile_lock); | 260 { MutexLocker mc(Compile_lock); |
301 | 261 |
302 // determine base vtable size; without that we cannot create the array klasses | 262 // determine base vtable size; without that we cannot create the array klasses |
303 compute_base_vtable_size(); | 263 compute_base_vtable_size(); |
304 | 264 |
305 if (!UseSharedSpaces) { | 265 if (!UseSharedSpaces) { |
306 _klassKlassObj = klassKlass::create_klass(CHECK); | |
307 _arrayKlassKlassObj = arrayKlassKlass::create_klass(CHECK); | |
308 | |
309 _objArrayKlassKlassObj = objArrayKlassKlass::create_klass(CHECK); | |
310 _instanceKlassKlassObj = instanceKlassKlass::create_klass(CHECK); | |
311 _typeArrayKlassKlassObj = typeArrayKlassKlass::create_klass(CHECK); | |
312 | |
313 _boolArrayKlassObj = typeArrayKlass::create_klass(T_BOOLEAN, sizeof(jboolean), CHECK); | 266 _boolArrayKlassObj = typeArrayKlass::create_klass(T_BOOLEAN, sizeof(jboolean), CHECK); |
314 _charArrayKlassObj = typeArrayKlass::create_klass(T_CHAR, sizeof(jchar), CHECK); | 267 _charArrayKlassObj = typeArrayKlass::create_klass(T_CHAR, sizeof(jchar), CHECK); |
315 _singleArrayKlassObj = typeArrayKlass::create_klass(T_FLOAT, sizeof(jfloat), CHECK); | 268 _singleArrayKlassObj = typeArrayKlass::create_klass(T_FLOAT, sizeof(jfloat), CHECK); |
316 _doubleArrayKlassObj = typeArrayKlass::create_klass(T_DOUBLE, sizeof(jdouble), CHECK); | 269 _doubleArrayKlassObj = typeArrayKlass::create_klass(T_DOUBLE, sizeof(jdouble), CHECK); |
317 _byteArrayKlassObj = typeArrayKlass::create_klass(T_BYTE, sizeof(jbyte), CHECK); | 270 _byteArrayKlassObj = typeArrayKlass::create_klass(T_BYTE, sizeof(jbyte), CHECK); |
326 _typeArrayKlassObjs[T_BYTE] = _byteArrayKlassObj; | 279 _typeArrayKlassObjs[T_BYTE] = _byteArrayKlassObj; |
327 _typeArrayKlassObjs[T_SHORT] = _shortArrayKlassObj; | 280 _typeArrayKlassObjs[T_SHORT] = _shortArrayKlassObj; |
328 _typeArrayKlassObjs[T_INT] = _intArrayKlassObj; | 281 _typeArrayKlassObjs[T_INT] = _intArrayKlassObj; |
329 _typeArrayKlassObjs[T_LONG] = _longArrayKlassObj; | 282 _typeArrayKlassObjs[T_LONG] = _longArrayKlassObj; |
330 | 283 |
331 _methodKlassObj = methodKlass::create_klass(CHECK); | 284 ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data(); |
332 _constMethodKlassObj = constMethodKlass::create_klass(CHECK); | 285 |
333 _methodDataKlassObj = methodDataKlass::create_klass(CHECK); | 286 _the_array_interfaces_array = MetadataFactory::new_array<Klass*>(null_cld, 2, NULL, CHECK); |
334 _constantPoolKlassObj = constantPoolKlass::create_klass(CHECK); | 287 _the_empty_int_array = MetadataFactory::new_array<int>(null_cld, 0, CHECK); |
335 _constantPoolCacheKlassObj = constantPoolCacheKlass::create_klass(CHECK); | 288 _the_empty_short_array = MetadataFactory::new_array<u2>(null_cld, 0, CHECK); |
336 | 289 _the_empty_method_array = MetadataFactory::new_array<Method*>(null_cld, 0, CHECK); |
337 _compiledICHolderKlassObj = compiledICHolderKlass::create_klass(CHECK); | 290 _the_empty_klass_array = MetadataFactory::new_array<Klass*>(null_cld, 0, CHECK); |
338 _systemObjArrayKlassObj = objArrayKlassKlass::cast(objArrayKlassKlassObj())->allocate_system_objArray_klass(CHECK); | |
339 | |
340 _the_empty_byte_array = oopFactory::new_permanent_byteArray(0, CHECK); | |
341 _the_empty_short_array = oopFactory::new_permanent_shortArray(0, CHECK); | |
342 _the_empty_int_array = oopFactory::new_permanent_intArray(0, CHECK); | |
343 _the_empty_system_obj_array = oopFactory::new_system_objArray(0, CHECK); | |
344 | |
345 _the_array_interfaces_array = oopFactory::new_system_objArray(2, CHECK); | |
346 } | 291 } |
347 } | 292 } |
348 | 293 |
349 vmSymbols::initialize(CHECK); | 294 vmSymbols::initialize(CHECK); |
350 | 295 |
351 SystemDictionary::initialize(CHECK); | 296 SystemDictionary::initialize(CHECK); |
352 | 297 |
353 klassOop ok = SystemDictionary::Object_klass(); | 298 Klass* ok = SystemDictionary::Object_klass(); |
354 | 299 |
355 _the_null_string = StringTable::intern("null", CHECK); | 300 _the_null_string = StringTable::intern("null", CHECK); |
356 _the_min_jint_string = StringTable::intern("-2147483648", CHECK); | 301 _the_min_jint_string = StringTable::intern("-2147483648", CHECK); |
357 | 302 |
358 if (UseSharedSpaces) { | 303 if (UseSharedSpaces) { |
359 // Verify shared interfaces array. | 304 // Verify shared interfaces array. |
360 assert(_the_array_interfaces_array->obj_at(0) == | 305 assert(_the_array_interfaces_array->at(0) == |
361 SystemDictionary::Cloneable_klass(), "u3"); | 306 SystemDictionary::Cloneable_klass(), "u3"); |
362 assert(_the_array_interfaces_array->obj_at(1) == | 307 assert(_the_array_interfaces_array->at(1) == |
363 SystemDictionary::Serializable_klass(), "u3"); | 308 SystemDictionary::Serializable_klass(), "u3"); |
364 | |
365 // Verify element klass for system obj array klass | |
366 assert(objArrayKlass::cast(_systemObjArrayKlassObj)->element_klass() == ok, "u1"); | |
367 assert(objArrayKlass::cast(_systemObjArrayKlassObj)->bottom_klass() == ok, "u2"); | |
368 | |
369 // Verify super class for the classes created above | |
370 assert(Klass::cast(boolArrayKlassObj() )->super() == ok, "u3"); | |
371 assert(Klass::cast(charArrayKlassObj() )->super() == ok, "u3"); | |
372 assert(Klass::cast(singleArrayKlassObj() )->super() == ok, "u3"); | |
373 assert(Klass::cast(doubleArrayKlassObj() )->super() == ok, "u3"); | |
374 assert(Klass::cast(byteArrayKlassObj() )->super() == ok, "u3"); | |
375 assert(Klass::cast(shortArrayKlassObj() )->super() == ok, "u3"); | |
376 assert(Klass::cast(intArrayKlassObj() )->super() == ok, "u3"); | |
377 assert(Klass::cast(longArrayKlassObj() )->super() == ok, "u3"); | |
378 assert(Klass::cast(constantPoolKlassObj() )->super() == ok, "u3"); | |
379 assert(Klass::cast(systemObjArrayKlassObj())->super() == ok, "u3"); | |
380 } else { | 309 } else { |
381 // Set up shared interfaces array. (Do this before supers are set up.) | 310 // Set up shared interfaces array. (Do this before supers are set up.) |
382 _the_array_interfaces_array->obj_at_put(0, SystemDictionary::Cloneable_klass()); | 311 _the_array_interfaces_array->at_put(0, SystemDictionary::Cloneable_klass()); |
383 _the_array_interfaces_array->obj_at_put(1, SystemDictionary::Serializable_klass()); | 312 _the_array_interfaces_array->at_put(1, SystemDictionary::Serializable_klass()); |
384 | 313 } |
385 // Set element klass for system obj array klass | 314 |
386 objArrayKlass::cast(_systemObjArrayKlassObj)->set_element_klass(ok); | 315 initialize_basic_type_klass(boolArrayKlassObj(), CHECK); |
387 objArrayKlass::cast(_systemObjArrayKlassObj)->set_bottom_klass(ok); | 316 initialize_basic_type_klass(charArrayKlassObj(), CHECK); |
388 | 317 initialize_basic_type_klass(singleArrayKlassObj(), CHECK); |
389 // Set super class for the classes created above | 318 initialize_basic_type_klass(doubleArrayKlassObj(), CHECK); |
390 Klass::cast(boolArrayKlassObj() )->initialize_supers(ok, CHECK); | 319 initialize_basic_type_klass(byteArrayKlassObj(), CHECK); |
391 Klass::cast(charArrayKlassObj() )->initialize_supers(ok, CHECK); | 320 initialize_basic_type_klass(shortArrayKlassObj(), CHECK); |
392 Klass::cast(singleArrayKlassObj() )->initialize_supers(ok, CHECK); | 321 initialize_basic_type_klass(intArrayKlassObj(), CHECK); |
393 Klass::cast(doubleArrayKlassObj() )->initialize_supers(ok, CHECK); | 322 initialize_basic_type_klass(longArrayKlassObj(), CHECK); |
394 Klass::cast(byteArrayKlassObj() )->initialize_supers(ok, CHECK); | |
395 Klass::cast(shortArrayKlassObj() )->initialize_supers(ok, CHECK); | |
396 Klass::cast(intArrayKlassObj() )->initialize_supers(ok, CHECK); | |
397 Klass::cast(longArrayKlassObj() )->initialize_supers(ok, CHECK); | |
398 Klass::cast(constantPoolKlassObj() )->initialize_supers(ok, CHECK); | |
399 Klass::cast(systemObjArrayKlassObj())->initialize_supers(ok, CHECK); | |
400 Klass::cast(boolArrayKlassObj() )->set_super(ok); | |
401 Klass::cast(charArrayKlassObj() )->set_super(ok); | |
402 Klass::cast(singleArrayKlassObj() )->set_super(ok); | |
403 Klass::cast(doubleArrayKlassObj() )->set_super(ok); | |
404 Klass::cast(byteArrayKlassObj() )->set_super(ok); | |
405 Klass::cast(shortArrayKlassObj() )->set_super(ok); | |
406 Klass::cast(intArrayKlassObj() )->set_super(ok); | |
407 Klass::cast(longArrayKlassObj() )->set_super(ok); | |
408 Klass::cast(constantPoolKlassObj() )->set_super(ok); | |
409 Klass::cast(systemObjArrayKlassObj())->set_super(ok); | |
410 } | |
411 | |
412 Klass::cast(boolArrayKlassObj() )->append_to_sibling_list(); | |
413 Klass::cast(charArrayKlassObj() )->append_to_sibling_list(); | |
414 Klass::cast(singleArrayKlassObj() )->append_to_sibling_list(); | |
415 Klass::cast(doubleArrayKlassObj() )->append_to_sibling_list(); | |
416 Klass::cast(byteArrayKlassObj() )->append_to_sibling_list(); | |
417 Klass::cast(shortArrayKlassObj() )->append_to_sibling_list(); | |
418 Klass::cast(intArrayKlassObj() )->append_to_sibling_list(); | |
419 Klass::cast(longArrayKlassObj() )->append_to_sibling_list(); | |
420 Klass::cast(constantPoolKlassObj() )->append_to_sibling_list(); | |
421 Klass::cast(systemObjArrayKlassObj())->append_to_sibling_list(); | |
422 } // end of core bootstrapping | 323 } // end of core bootstrapping |
423 | 324 |
325 // Maybe this could be lifted up now that object array can be initialized | |
326 // during the bootstrapping. | |
327 | |
328 // OLD | |
424 // Initialize _objectArrayKlass after core bootstraping to make | 329 // Initialize _objectArrayKlass after core bootstraping to make |
425 // sure the super class is set up properly for _objectArrayKlass. | 330 // sure the super class is set up properly for _objectArrayKlass. |
426 _objectArrayKlassObj = instanceKlass:: | 331 // --- |
332 // NEW | |
333 // Since some of the old system object arrays have been converted to | |
334 // ordinary object arrays, _objectArrayKlass will be loaded when | |
335 // SystemDictionary::initialize(CHECK); is run. See the extra check | |
336 // for Object_klass_loaded in objArrayKlassKlass::allocate_objArray_klass_impl. | |
337 _objectArrayKlassObj = InstanceKlass:: | |
427 cast(SystemDictionary::Object_klass())->array_klass(1, CHECK); | 338 cast(SystemDictionary::Object_klass())->array_klass(1, CHECK); |
339 // OLD | |
428 // Add the class to the class hierarchy manually to make sure that | 340 // Add the class to the class hierarchy manually to make sure that |
429 // its vtable is initialized after core bootstrapping is completed. | 341 // its vtable is initialized after core bootstrapping is completed. |
342 // --- | |
343 // New | |
344 // Have already been initialized. | |
430 Klass::cast(_objectArrayKlassObj)->append_to_sibling_list(); | 345 Klass::cast(_objectArrayKlassObj)->append_to_sibling_list(); |
431 | 346 |
432 // Compute is_jdk version flags. | 347 // Compute is_jdk version flags. |
433 // Only 1.3 or later has the java.lang.Shutdown class. | 348 // Only 1.3 or later has the java.lang.Shutdown class. |
434 // Only 1.4 or later has the java.lang.CharSequence interface. | 349 // Only 1.4 or later has the java.lang.CharSequence interface. |
435 // Only 1.5 or later has the java.lang.management.MemoryUsage class. | 350 // Only 1.5 or later has the java.lang.management.MemoryUsage class. |
436 if (JDK_Version::is_partially_initialized()) { | 351 if (JDK_Version::is_partially_initialized()) { |
437 uint8_t jdk_version; | 352 uint8_t jdk_version; |
438 klassOop k = SystemDictionary::resolve_or_null( | 353 Klass* k = SystemDictionary::resolve_or_null( |
439 vmSymbols::java_lang_management_MemoryUsage(), THREAD); | 354 vmSymbols::java_lang_management_MemoryUsage(), THREAD); |
440 CLEAR_PENDING_EXCEPTION; // ignore exceptions | 355 CLEAR_PENDING_EXCEPTION; // ignore exceptions |
441 if (k == NULL) { | 356 if (k == NULL) { |
442 k = SystemDictionary::resolve_or_null( | 357 k = SystemDictionary::resolve_or_null( |
443 vmSymbols::java_lang_CharSequence(), THREAD); | 358 vmSymbols::java_lang_CharSequence(), THREAD); |
477 "will not force all objects to relocate"); | 392 "will not force all objects to relocate"); |
478 size = FullGCALotDummies; | 393 size = FullGCALotDummies; |
479 } else { | 394 } else { |
480 size = FullGCALotDummies * 2; | 395 size = FullGCALotDummies * 2; |
481 } | 396 } |
482 objArrayOop naked_array = oopFactory::new_system_objArray(size, CHECK); | 397 objArrayOop naked_array = oopFactory::new_objArray(SystemDictionary::Object_klass(), size, CHECK); |
483 objArrayHandle dummy_array(THREAD, naked_array); | 398 objArrayHandle dummy_array(THREAD, naked_array); |
484 int i = 0; | 399 int i = 0; |
485 while (i < size) { | 400 while (i < size) { |
486 if (!UseConcMarkSweepGC) { | |
487 // Allocate dummy in old generation | 401 // Allocate dummy in old generation |
488 oop dummy = instanceKlass::cast(SystemDictionary::Object_klass())->allocate_instance(CHECK); | 402 oop dummy = InstanceKlass::cast(SystemDictionary::Object_klass())->allocate_instance(CHECK); |
489 dummy_array->obj_at_put(i++, dummy); | |
490 } | |
491 // Allocate dummy in permanent generation | |
492 oop dummy = instanceKlass::cast(SystemDictionary::Object_klass())->allocate_permanent_instance(CHECK); | |
493 dummy_array->obj_at_put(i++, dummy); | 403 dummy_array->obj_at_put(i++, dummy); |
494 } | 404 } |
495 { | 405 { |
496 // Only modify the global variable inside the mutex. | 406 // Only modify the global variable inside the mutex. |
497 // If we had a race to here, the other dummy_array instances | 407 // If we had a race to here, the other dummy_array instances |
504 assert(i == _fullgc_alot_dummy_array->length(), "just checking"); | 414 assert(i == _fullgc_alot_dummy_array->length(), "just checking"); |
505 } | 415 } |
506 #endif | 416 #endif |
507 } | 417 } |
508 | 418 |
509 | 419 // CDS support for patching vtables in metadata in the shared archive. |
420 // All types inherited from Metadata have vtables, but not types inherited | |
421 // from MetaspaceObj, because the latter does not have virtual functions. | |
422 // If the metadata type has a vtable, it cannot be shared in the read-only | |
423 // section of the CDS archive, because the vtable pointer is patched. | |
510 static inline void* dereference(void* addr) { | 424 static inline void* dereference(void* addr) { |
511 return *(void**)addr; | 425 return *(void**)addr; |
512 } | 426 } |
513 | 427 |
514 static inline void add_vtable(void** list, int* n, void* o, int count) { | 428 static inline void add_vtable(void** list, int* n, void* o, int count) { |
518 list[(*n)++] = vtable; | 432 list[(*n)++] = vtable; |
519 } | 433 } |
520 | 434 |
521 void Universe::init_self_patching_vtbl_list(void** list, int count) { | 435 void Universe::init_self_patching_vtbl_list(void** list, int count) { |
522 int n = 0; | 436 int n = 0; |
523 { klassKlass o; add_vtable(list, &n, &o, count); } | 437 { InstanceKlass o; add_vtable(list, &n, &o, count); } |
524 { arrayKlassKlass o; add_vtable(list, &n, &o, count); } | 438 { instanceClassLoaderKlass o; add_vtable(list, &n, &o, count); } |
525 { objArrayKlassKlass o; add_vtable(list, &n, &o, count); } | |
526 { instanceKlassKlass o; add_vtable(list, &n, &o, count); } | |
527 { instanceKlass o; add_vtable(list, &n, &o, count); } | |
528 { instanceMirrorKlass o; add_vtable(list, &n, &o, count); } | 439 { instanceMirrorKlass o; add_vtable(list, &n, &o, count); } |
529 { instanceRefKlass o; add_vtable(list, &n, &o, count); } | 440 { instanceRefKlass o; add_vtable(list, &n, &o, count); } |
530 { typeArrayKlassKlass o; add_vtable(list, &n, &o, count); } | |
531 { typeArrayKlass o; add_vtable(list, &n, &o, count); } | 441 { typeArrayKlass o; add_vtable(list, &n, &o, count); } |
532 { methodKlass o; add_vtable(list, &n, &o, count); } | |
533 { constMethodKlass o; add_vtable(list, &n, &o, count); } | |
534 { constantPoolKlass o; add_vtable(list, &n, &o, count); } | |
535 { constantPoolCacheKlass o; add_vtable(list, &n, &o, count); } | |
536 { objArrayKlass o; add_vtable(list, &n, &o, count); } | 442 { objArrayKlass o; add_vtable(list, &n, &o, count); } |
537 { methodDataKlass o; add_vtable(list, &n, &o, count); } | 443 { Method o; add_vtable(list, &n, &o, count); } |
538 { compiledICHolderKlass o; add_vtable(list, &n, &o, count); } | 444 { ConstantPool o; add_vtable(list, &n, &o, count); } |
539 #ifndef PRODUCT | 445 } |
540 // In non-product builds CHeapObj is derived from AllocatedObj, | |
541 // so symbols in CDS archive should have their vtable pointer patched. | |
542 { Symbol o; add_vtable(list, &n, &o, count); } | |
543 #endif | |
544 } | |
545 | |
546 | |
547 class FixupMirrorClosure: public ObjectClosure { | |
548 public: | |
549 virtual void do_object(oop obj) { | |
550 if (obj->is_klass()) { | |
551 EXCEPTION_MARK; | |
552 KlassHandle k(THREAD, klassOop(obj)); | |
553 // We will never reach the CATCH below since Exceptions::_throw will cause | |
554 // the VM to exit if an exception is thrown during initialization | |
555 java_lang_Class::fixup_mirror(k, CATCH); | |
556 // This call unconditionally creates a new mirror for k, | |
557 // and links in k's component_mirror field if k is an array. | |
558 // If k is an objArray, k's element type must already have | |
559 // a mirror. In other words, this closure must process | |
560 // the component type of an objArray k before it processes k. | |
561 // This works because the permgen iterator presents arrays | |
562 // and their component types in order of creation. | |
563 } | |
564 } | |
565 }; | |
566 | 446 |
567 void Universe::initialize_basic_type_mirrors(TRAPS) { | 447 void Universe::initialize_basic_type_mirrors(TRAPS) { |
568 if (UseSharedSpaces) { | |
569 assert(_int_mirror != NULL, "already loaded"); | |
570 assert(_void_mirror == _mirrors[T_VOID], "consistently loaded"); | |
571 } else { | |
572 | |
573 assert(_int_mirror==NULL, "basic type mirrors already initialized"); | 448 assert(_int_mirror==NULL, "basic type mirrors already initialized"); |
574 _int_mirror = | 449 _int_mirror = |
575 java_lang_Class::create_basic_type_mirror("int", T_INT, CHECK); | 450 java_lang_Class::create_basic_type_mirror("int", T_INT, CHECK); |
576 _float_mirror = | 451 _float_mirror = |
577 java_lang_Class::create_basic_type_mirror("float", T_FLOAT, CHECK); | 452 java_lang_Class::create_basic_type_mirror("float", T_FLOAT, CHECK); |
597 _mirrors[T_BOOLEAN] = _bool_mirror; | 472 _mirrors[T_BOOLEAN] = _bool_mirror; |
598 _mirrors[T_CHAR] = _char_mirror; | 473 _mirrors[T_CHAR] = _char_mirror; |
599 _mirrors[T_LONG] = _long_mirror; | 474 _mirrors[T_LONG] = _long_mirror; |
600 _mirrors[T_SHORT] = _short_mirror; | 475 _mirrors[T_SHORT] = _short_mirror; |
601 _mirrors[T_VOID] = _void_mirror; | 476 _mirrors[T_VOID] = _void_mirror; |
602 //_mirrors[T_OBJECT] = instanceKlass::cast(_object_klass)->java_mirror(); | 477 //_mirrors[T_OBJECT] = InstanceKlass::cast(_object_klass)->java_mirror(); |
603 //_mirrors[T_ARRAY] = instanceKlass::cast(_object_klass)->java_mirror(); | 478 //_mirrors[T_ARRAY] = InstanceKlass::cast(_object_klass)->java_mirror(); |
604 } | |
605 } | 479 } |
606 | 480 |
607 void Universe::fixup_mirrors(TRAPS) { | 481 void Universe::fixup_mirrors(TRAPS) { |
608 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, | 482 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, |
609 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply | 483 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply |
610 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note | 484 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note |
611 // that the number of objects allocated at this point is very small. | 485 // that the number of objects allocated at this point is very small. |
612 assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded"); | 486 assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded"); |
613 | 487 HandleMark hm(THREAD); |
614 // Cache the start of the static fields | 488 // Cache the start of the static fields |
615 instanceMirrorKlass::init_offset_of_static_fields(); | 489 instanceMirrorKlass::init_offset_of_static_fields(); |
616 | 490 |
617 FixupMirrorClosure blk; | 491 GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list(); |
618 Universe::heap()->permanent_object_iterate(&blk); | 492 int list_length = list->length(); |
619 } | 493 for (int i = 0; i < list_length; i++) { |
620 | 494 Klass* k = list->at(i); |
495 assert(k->is_klass(), "List should only hold classes"); | |
496 EXCEPTION_MARK; | |
497 KlassHandle kh(THREAD, k); | |
498 java_lang_Class::fixup_mirror(kh, CATCH); | |
499 } | |
500 delete java_lang_Class::fixup_mirror_list(); | |
501 java_lang_Class::set_fixup_mirror_list(NULL); | |
502 } | |
621 | 503 |
622 static bool has_run_finalizers_on_exit = false; | 504 static bool has_run_finalizers_on_exit = false; |
623 | 505 |
624 void Universe::run_finalizers_on_exit() { | 506 void Universe::run_finalizers_on_exit() { |
625 if (has_run_finalizers_on_exit) return; | 507 if (has_run_finalizers_on_exit) return; |
648 // 1) we specified true to initialize_vtable and | 530 // 1) we specified true to initialize_vtable and |
649 // 2) this ran after gc was enabled | 531 // 2) this ran after gc was enabled |
650 // In case those ever change we use handles for oops | 532 // In case those ever change we use handles for oops |
651 void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) { | 533 void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) { |
652 // init vtable of k and all subclasses | 534 // init vtable of k and all subclasses |
653 Klass* ko = k_h()->klass_part(); | 535 Klass* ko = k_h(); |
654 klassVtable* vt = ko->vtable(); | 536 klassVtable* vt = ko->vtable(); |
655 if (vt) vt->initialize_vtable(false, CHECK); | 537 if (vt) vt->initialize_vtable(false, CHECK); |
656 if (ko->oop_is_instance()) { | 538 if (ko->oop_is_instance()) { |
657 instanceKlass* ik = (instanceKlass*)ko; | 539 InstanceKlass* ik = (InstanceKlass*)ko; |
658 for (KlassHandle s_h(THREAD, ik->subklass()); s_h() != NULL; s_h = (THREAD, s_h()->klass_part()->next_sibling())) { | 540 for (KlassHandle s_h(THREAD, ik->subklass()); s_h() != NULL; s_h = (THREAD, s_h()->next_sibling())) { |
659 reinitialize_vtable_of(s_h, CHECK); | 541 reinitialize_vtable_of(s_h, CHECK); |
660 } | 542 } |
661 } | 543 } |
662 } | 544 } |
663 | 545 |
664 | 546 |
665 void initialize_itable_for_klass(klassOop k, TRAPS) { | 547 void initialize_itable_for_klass(Klass* k, TRAPS) { |
666 instanceKlass::cast(k)->itable()->initialize_itable(false, CHECK); | 548 InstanceKlass::cast(k)->itable()->initialize_itable(false, CHECK); |
667 } | 549 } |
668 | 550 |
669 | 551 |
670 void Universe::reinitialize_itables(TRAPS) { | 552 void Universe::reinitialize_itables(TRAPS) { |
671 SystemDictionary::classes_do(initialize_itable_for_klass, CHECK); | 553 SystemDictionary::classes_do(initialize_itable_for_klass, CHECK); |
756 "oop size is not not a multiple of HeapWord size"); | 638 "oop size is not not a multiple of HeapWord size"); |
757 TraceTime timer("Genesis", TraceStartupTime); | 639 TraceTime timer("Genesis", TraceStartupTime); |
758 GC_locker::lock(); // do not allow gc during bootstrapping | 640 GC_locker::lock(); // do not allow gc during bootstrapping |
759 JavaClasses::compute_hard_coded_offsets(); | 641 JavaClasses::compute_hard_coded_offsets(); |
760 | 642 |
761 // Get map info from shared archive file. | |
762 if (DumpSharedSpaces) | |
763 UseSharedSpaces = false; | |
764 | |
765 FileMapInfo* mapinfo = NULL; | |
766 if (UseSharedSpaces) { | |
767 mapinfo = NEW_C_HEAP_OBJ(FileMapInfo, mtInternal); | |
768 memset(mapinfo, 0, sizeof(FileMapInfo)); | |
769 | |
770 // Open the shared archive file, read and validate the header. If | |
771 // initialization files, shared spaces [UseSharedSpaces] are | |
772 // disabled and the file is closed. | |
773 | |
774 if (mapinfo->initialize()) { | |
775 FileMapInfo::set_current_info(mapinfo); | |
776 } else { | |
777 assert(!mapinfo->is_open() && !UseSharedSpaces, | |
778 "archive file not closed or shared spaces not disabled."); | |
779 } | |
780 } | |
781 | |
782 jint status = Universe::initialize_heap(); | 643 jint status = Universe::initialize_heap(); |
783 if (status != JNI_OK) { | 644 if (status != JNI_OK) { |
784 return status; | 645 return status; |
785 } | 646 } |
786 | 647 |
787 // We have a heap so create the methodOop caches before | 648 // Create memory for metadata. Must be after initializing heap for |
788 // CompactingPermGenGen::initialize_oops() tries to populate them. | 649 // DumpSharedSpaces. |
650 ClassLoaderData::init_null_class_loader_data(); | |
651 | |
652 // We have a heap so create the Method* caches before | |
653 // Metaspace::initialize_shared_spaces() tries to populate them. | |
789 Universe::_finalizer_register_cache = new LatestMethodOopCache(); | 654 Universe::_finalizer_register_cache = new LatestMethodOopCache(); |
790 Universe::_loader_addClass_cache = new LatestMethodOopCache(); | |
791 Universe::_reflect_invoke_cache = new ActiveMethodOopsCache(); | 655 Universe::_reflect_invoke_cache = new ActiveMethodOopsCache(); |
792 | 656 |
793 if (UseSharedSpaces) { | 657 if (UseSharedSpaces) { |
794 | |
795 // Read the data structures supporting the shared spaces (shared | 658 // Read the data structures supporting the shared spaces (shared |
796 // system dictionary, symbol table, etc.). After that, access to | 659 // system dictionary, symbol table, etc.). After that, access to |
797 // the file (other than the mapped regions) is no longer needed, and | 660 // the file (other than the mapped regions) is no longer needed, and |
798 // the file is closed. Closing the file does not affect the | 661 // the file is closed. Closing the file does not affect the |
799 // currently mapped regions. | 662 // currently mapped regions. |
800 | 663 MetaspaceShared::initialize_shared_spaces(); |
801 CompactingPermGenGen::initialize_oops(); | 664 StringTable::create_table(); |
802 mapinfo->close(); | |
803 | |
804 } else { | 665 } else { |
805 SymbolTable::create_table(); | 666 SymbolTable::create_table(); |
806 StringTable::create_table(); | 667 StringTable::create_table(); |
807 ClassLoader::create_package_info_table(); | 668 ClassLoader::create_package_info_table(); |
808 } | 669 } |
990 ThreadLocalAllocBuffer::startup_initialization(); | 851 ThreadLocalAllocBuffer::startup_initialization(); |
991 } | 852 } |
992 return JNI_OK; | 853 return JNI_OK; |
993 } | 854 } |
994 | 855 |
856 | |
857 // Reserve the Java heap, which is now the same for all GCs. | |
858 ReservedSpace Universe::reserve_heap(size_t heap_size, size_t alignment) { | |
859 // Add in the class metaspace area so the classes in the headers can | |
860 // be compressed the same as instances. | |
861 size_t total_reserved = heap_size + ClassMetaspaceSize; | |
862 char* addr = Universe::preferred_heap_base(total_reserved, Universe::UnscaledNarrowOop); | |
863 | |
864 ReservedHeapSpace total_rs(total_reserved, alignment, UseLargePages, addr); | |
865 | |
866 if (UseCompressedOops) { | |
867 if (addr != NULL && !total_rs.is_reserved()) { | |
868 // Failed to reserve at specified address - the requested memory | |
869 // region is taken already, for example, by 'java' launcher. | |
870 // Try again to reserver heap higher. | |
871 addr = Universe::preferred_heap_base(total_reserved, Universe::ZeroBasedNarrowOop); | |
872 | |
873 ReservedHeapSpace total_rs0(total_reserved, alignment, | |
874 UseLargePages, addr); | |
875 | |
876 if (addr != NULL && !total_rs0.is_reserved()) { | |
877 // Failed to reserve at specified address again - give up. | |
878 addr = Universe::preferred_heap_base(total_reserved, Universe::HeapBasedNarrowOop); | |
879 assert(addr == NULL, ""); | |
880 | |
881 ReservedHeapSpace total_rs1(total_reserved, alignment, | |
882 UseLargePages, addr); | |
883 total_rs = total_rs1; | |
884 } else { | |
885 total_rs = total_rs0; | |
886 } | |
887 } | |
888 } | |
889 | |
890 if (!total_rs.is_reserved()) { | |
891 vm_exit_during_initialization(err_msg("Could not reserve enough space for object heap %d bytes", total_reserved)); | |
892 return total_rs; | |
893 } | |
894 | |
895 // Split the reserved space into main Java heap and a space for classes | |
896 // so that they can be compressed using the same algorithm as compressed oops | |
897 ReservedSpace heap_rs = total_rs.first_part(heap_size); | |
898 ReservedSpace class_rs = total_rs.last_part(heap_size, alignment); | |
899 Metaspace::initialize_class_space(class_rs); | |
900 return heap_rs; | |
901 } | |
902 | |
903 | |
995 // It's the caller's repsonsibility to ensure glitch-freedom | 904 // It's the caller's repsonsibility to ensure glitch-freedom |
996 // (if required). | 905 // (if required). |
997 void Universe::update_heap_info_at_gc() { | 906 void Universe::update_heap_info_at_gc() { |
998 _heap_capacity_at_last_gc = heap()->capacity(); | 907 _heap_capacity_at_last_gc = heap()->capacity(); |
999 _heap_used_at_last_gc = heap()->used(); | 908 _heap_used_at_last_gc = heap()->used(); |
1024 Universe::_fully_initialized = true; | 933 Universe::_fully_initialized = true; |
1025 EXCEPTION_MARK; | 934 EXCEPTION_MARK; |
1026 { ResourceMark rm; | 935 { ResourceMark rm; |
1027 Interpreter::initialize(); // needed for interpreter entry points | 936 Interpreter::initialize(); // needed for interpreter entry points |
1028 if (!UseSharedSpaces) { | 937 if (!UseSharedSpaces) { |
938 HandleMark hm(THREAD); | |
1029 KlassHandle ok_h(THREAD, SystemDictionary::Object_klass()); | 939 KlassHandle ok_h(THREAD, SystemDictionary::Object_klass()); |
1030 Universe::reinitialize_vtable_of(ok_h, CHECK_false); | 940 Universe::reinitialize_vtable_of(ok_h, CHECK_false); |
1031 Universe::reinitialize_itables(CHECK_false); | 941 Universe::reinitialize_itables(CHECK_false); |
1032 } | 942 } |
1033 } | 943 } |
1034 | 944 |
1035 klassOop k; | 945 HandleMark hm(THREAD); |
946 Klass* k; | |
1036 instanceKlassHandle k_h; | 947 instanceKlassHandle k_h; |
1037 if (!UseSharedSpaces) { | |
1038 // Setup preallocated empty java.lang.Class array | 948 // Setup preallocated empty java.lang.Class array |
1039 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false); | 949 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::Class_klass(), 0, CHECK_false); |
950 | |
1040 // Setup preallocated OutOfMemoryError errors | 951 // Setup preallocated OutOfMemoryError errors |
1041 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false); | 952 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_OutOfMemoryError(), true, CHECK_false); |
1042 k_h = instanceKlassHandle(THREAD, k); | 953 k_h = instanceKlassHandle(THREAD, k); |
1043 Universe::_out_of_memory_error_java_heap = k_h->allocate_permanent_instance(CHECK_false); | 954 Universe::_out_of_memory_error_java_heap = k_h->allocate_instance(CHECK_false); |
1044 Universe::_out_of_memory_error_perm_gen = k_h->allocate_permanent_instance(CHECK_false); | 955 Universe::_out_of_memory_error_perm_gen = k_h->allocate_instance(CHECK_false); |
1045 Universe::_out_of_memory_error_array_size = k_h->allocate_permanent_instance(CHECK_false); | 956 Universe::_out_of_memory_error_array_size = k_h->allocate_instance(CHECK_false); |
1046 Universe::_out_of_memory_error_gc_overhead_limit = | 957 Universe::_out_of_memory_error_gc_overhead_limit = |
1047 k_h->allocate_permanent_instance(CHECK_false); | 958 k_h->allocate_instance(CHECK_false); |
1048 | 959 |
1049 // Setup preallocated NullPointerException | 960 // Setup preallocated NullPointerException |
1050 // (this is currently used for a cheap & dirty solution in compiler exception handling) | 961 // (this is currently used for a cheap & dirty solution in compiler exception handling) |
1051 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false); | 962 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false); |
1052 Universe::_null_ptr_exception_instance = instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | 963 Universe::_null_ptr_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); |
1053 // Setup preallocated ArithmeticException | 964 // Setup preallocated ArithmeticException |
1054 // (this is currently used for a cheap & dirty solution in compiler exception handling) | 965 // (this is currently used for a cheap & dirty solution in compiler exception handling) |
1055 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false); | 966 k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false); |
1056 Universe::_arithmetic_exception_instance = instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | 967 Universe::_arithmetic_exception_instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false); |
1057 // Virtual Machine Error for when we get into a situation we can't resolve | 968 // Virtual Machine Error for when we get into a situation we can't resolve |
1058 k = SystemDictionary::resolve_or_fail( | 969 k = SystemDictionary::resolve_or_fail( |
1059 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false); | 970 vmSymbols::java_lang_VirtualMachineError(), true, CHECK_false); |
1060 bool linked = instanceKlass::cast(k)->link_class_or_fail(CHECK_false); | 971 bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false); |
1061 if (!linked) { | 972 if (!linked) { |
1062 tty->print_cr("Unable to link/verify VirtualMachineError class"); | 973 tty->print_cr("Unable to link/verify VirtualMachineError class"); |
1063 return false; // initialization failed | 974 return false; // initialization failed |
1064 } | 975 } |
1065 Universe::_virtual_machine_error_instance = | 976 Universe::_virtual_machine_error_instance = |
1066 instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | 977 InstanceKlass::cast(k)->allocate_instance(CHECK_false); |
1067 | 978 |
1068 Universe::_vm_exception = instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | 979 Universe::_vm_exception = InstanceKlass::cast(k)->allocate_instance(CHECK_false); |
1069 | 980 |
1070 } | |
1071 if (!DumpSharedSpaces) { | 981 if (!DumpSharedSpaces) { |
1072 // These are the only Java fields that are currently set during shared space dumping. | 982 // These are the only Java fields that are currently set during shared space dumping. |
1073 // We prefer to not handle this generally, so we always reinitialize these detail messages. | 983 // We prefer to not handle this generally, so we always reinitialize these detail messages. |
1074 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false); | 984 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false); |
1075 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg()); | 985 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg()); |
1076 | 986 |
1077 msg = java_lang_String::create_from_str("PermGen space", CHECK_false); | 987 msg = java_lang_String::create_from_str("Metadata space", CHECK_false); |
1078 java_lang_Throwable::set_message(Universe::_out_of_memory_error_perm_gen, msg()); | 988 java_lang_Throwable::set_message(Universe::_out_of_memory_error_perm_gen, msg()); |
1079 | 989 |
1080 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); | 990 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); |
1081 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg()); | 991 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg()); |
1082 | 992 |
1086 msg = java_lang_String::create_from_str("/ by zero", CHECK_false); | 996 msg = java_lang_String::create_from_str("/ by zero", CHECK_false); |
1087 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg()); | 997 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg()); |
1088 | 998 |
1089 // Setup the array of errors that have preallocated backtrace | 999 // Setup the array of errors that have preallocated backtrace |
1090 k = Universe::_out_of_memory_error_java_heap->klass(); | 1000 k = Universe::_out_of_memory_error_java_heap->klass(); |
1091 assert(k->klass_part()->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error"); | 1001 assert(k->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error"); |
1092 k_h = instanceKlassHandle(THREAD, k); | 1002 k_h = instanceKlassHandle(THREAD, k); |
1093 | 1003 |
1094 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0; | 1004 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0; |
1095 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(k_h(), len, CHECK_false); | 1005 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(k_h(), len, CHECK_false); |
1096 for (int i=0; i<len; i++) { | 1006 for (int i=0; i<len; i++) { |
1097 oop err = k_h->allocate_permanent_instance(CHECK_false); | 1007 oop err = k_h->allocate_instance(CHECK_false); |
1098 Handle err_h = Handle(THREAD, err); | 1008 Handle err_h = Handle(THREAD, err); |
1099 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false); | 1009 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false); |
1100 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h()); | 1010 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h()); |
1101 } | 1011 } |
1102 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len; | 1012 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len; |
1104 | 1014 |
1105 | 1015 |
1106 // Setup static method for registering finalizers | 1016 // Setup static method for registering finalizers |
1107 // The finalizer klass must be linked before looking up the method, in | 1017 // The finalizer klass must be linked before looking up the method, in |
1108 // case it needs to get rewritten. | 1018 // case it needs to get rewritten. |
1109 instanceKlass::cast(SystemDictionary::Finalizer_klass())->link_class(CHECK_false); | 1019 InstanceKlass::cast(SystemDictionary::Finalizer_klass())->link_class(CHECK_false); |
1110 methodOop m = instanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method( | 1020 Method* m = InstanceKlass::cast(SystemDictionary::Finalizer_klass())->find_method( |
1111 vmSymbols::register_method_name(), | 1021 vmSymbols::register_method_name(), |
1112 vmSymbols::register_method_signature()); | 1022 vmSymbols::register_method_signature()); |
1113 if (m == NULL || !m->is_static()) { | 1023 if (m == NULL || !m->is_static()) { |
1114 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), | 1024 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), |
1115 "java.lang.ref.Finalizer.register", false); | 1025 "java.lang.ref.Finalizer.register", false); |
1129 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), | 1039 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), |
1130 "java.lang.reflect.Method.invoke", false); | 1040 "java.lang.reflect.Method.invoke", false); |
1131 } | 1041 } |
1132 Universe::_reflect_invoke_cache->init(k_h(), m, CHECK_false); | 1042 Universe::_reflect_invoke_cache->init(k_h(), m, CHECK_false); |
1133 | 1043 |
1134 // Setup method for registering loaded classes in class loader vector | |
1135 instanceKlass::cast(SystemDictionary::ClassLoader_klass())->link_class(CHECK_false); | |
1136 m = instanceKlass::cast(SystemDictionary::ClassLoader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature()); | |
1137 if (m == NULL || m->is_static()) { | |
1138 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), | |
1139 "java.lang.ClassLoader.addClass", false); | |
1140 } | |
1141 Universe::_loader_addClass_cache->init( | |
1142 SystemDictionary::ClassLoader_klass(), m, CHECK_false); | |
1143 | |
1144 // The folowing is initializing converter functions for serialization in | 1044 // The folowing is initializing converter functions for serialization in |
1145 // JVM.cpp. If we clean up the StrictMath code above we may want to find | 1045 // JVM.cpp. If we clean up the StrictMath code above we may want to find |
1146 // a better solution for this as well. | 1046 // a better solution for this as well. |
1147 initialize_converter_functions(); | 1047 initialize_converter_functions(); |
1148 | 1048 |
1154 } | 1054 } |
1155 | 1055 |
1156 // ("weak") refs processing infrastructure initialization | 1056 // ("weak") refs processing infrastructure initialization |
1157 Universe::heap()->post_initialize(); | 1057 Universe::heap()->post_initialize(); |
1158 | 1058 |
1059 // Initialize performance counters for metaspaces | |
1060 MetaspaceCounters::initialize_performance_counters(); | |
1061 | |
1159 GC_locker::unlock(); // allow gc after bootstrapping | 1062 GC_locker::unlock(); // allow gc after bootstrapping |
1160 | 1063 |
1161 MemoryService::set_universe_heap(Universe::_collectedHeap); | 1064 MemoryService::set_universe_heap(Universe::_collectedHeap); |
1162 return true; | 1065 return true; |
1163 } | 1066 } |
1202 // holding the CodeCache_lock. | 1105 // holding the CodeCache_lock. |
1203 | 1106 |
1204 CallSiteDepChange changes(call_site(), method_handle()); | 1107 CallSiteDepChange changes(call_site(), method_handle()); |
1205 | 1108 |
1206 // Compute the dependent nmethods that have a reference to a | 1109 // Compute the dependent nmethods that have a reference to a |
1207 // CallSite object. We use instanceKlass::mark_dependent_nmethod | 1110 // CallSite object. We use InstanceKlass::mark_dependent_nmethod |
1208 // directly instead of CodeCache::mark_for_deoptimization because we | 1111 // directly instead of CodeCache::mark_for_deoptimization because we |
1209 // want dependents on the call site class only not all classes in | 1112 // want dependents on the call site class only not all classes in |
1210 // the ContextStream. | 1113 // the ContextStream. |
1211 int marked = 0; | 1114 int marked = 0; |
1212 { | 1115 { |
1213 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | 1116 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
1214 instanceKlass* call_site_klass = instanceKlass::cast(call_site->klass()); | 1117 InstanceKlass* call_site_klass = InstanceKlass::cast(call_site->klass()); |
1215 marked = call_site_klass->mark_dependent_nmethods(changes); | 1118 marked = call_site_klass->mark_dependent_nmethods(changes); |
1216 } | 1119 } |
1217 if (marked > 0) { | 1120 if (marked > 0) { |
1218 // At least one nmethod has been marked for deoptimization | 1121 // At least one nmethod has been marked for deoptimization |
1219 VM_Deoptimize op; | 1122 VM_Deoptimize op; |
1361 if (!silent) gclog_or_tty->print("zone "); | 1264 if (!silent) gclog_or_tty->print("zone "); |
1362 CodeCache::verify(); | 1265 CodeCache::verify(); |
1363 } | 1266 } |
1364 if (!silent) gclog_or_tty->print("dict "); | 1267 if (!silent) gclog_or_tty->print("dict "); |
1365 SystemDictionary::verify(); | 1268 SystemDictionary::verify(); |
1269 #ifndef PRODUCT | |
1270 if (!silent) gclog_or_tty->print("cldg "); | |
1271 ClassLoaderDataGraph::verify(); | |
1272 #endif | |
1366 if (!silent) gclog_or_tty->print("hand "); | 1273 if (!silent) gclog_or_tty->print("hand "); |
1367 JNIHandles::verify(); | 1274 JNIHandles::verify(); |
1368 if (!silent) gclog_or_tty->print("C-heap "); | 1275 if (!silent) gclog_or_tty->print("C-heap "); |
1369 os::check_heap(); | 1276 os::check_heap(); |
1370 if (!silent) gclog_or_tty->print("code cache "); | 1277 if (!silent) gclog_or_tty->print("code cache "); |
1431 uintptr_t Universe::verify_oop_bits() { | 1338 uintptr_t Universe::verify_oop_bits() { |
1432 verify_oop_mask(); | 1339 verify_oop_mask(); |
1433 return _verify_oop_data[1]; | 1340 return _verify_oop_data[1]; |
1434 } | 1341 } |
1435 | 1342 |
1436 | |
1437 uintptr_t Universe::verify_klass_mask() { | |
1438 /* $$$ | |
1439 // A klass can never live in the new space. Since the new and old | |
1440 // spaces can change size, we must settle for bounds-checking against | |
1441 // the bottom of the world, plus the smallest possible new and old | |
1442 // space sizes that may arise during execution. | |
1443 size_t min_new_size = Universe::new_size(); // in bytes | |
1444 size_t min_old_size = Universe::old_size(); // in bytes | |
1445 calculate_verify_data(_verify_klass_data, | |
1446 (HeapWord*)((uintptr_t)_new_gen->low_boundary + min_new_size + min_old_size), | |
1447 _perm_gen->high_boundary); | |
1448 */ | |
1449 // Why doesn't the above just say that klass's always live in the perm | |
1450 // gen? I'll see if that seems to work... | |
1451 MemRegion permanent_reserved; | |
1452 switch (Universe::heap()->kind()) { | |
1453 default: | |
1454 // ???: What if a CollectedHeap doesn't have a permanent generation? | |
1455 ShouldNotReachHere(); | |
1456 break; | |
1457 case CollectedHeap::GenCollectedHeap: | |
1458 case CollectedHeap::G1CollectedHeap: { | |
1459 SharedHeap* sh = (SharedHeap*) Universe::heap(); | |
1460 permanent_reserved = sh->perm_gen()->reserved(); | |
1461 break; | |
1462 } | |
1463 #ifndef SERIALGC | |
1464 case CollectedHeap::ParallelScavengeHeap: { | |
1465 ParallelScavengeHeap* psh = (ParallelScavengeHeap*) Universe::heap(); | |
1466 permanent_reserved = psh->perm_gen()->reserved(); | |
1467 break; | |
1468 } | |
1469 #endif // SERIALGC | |
1470 } | |
1471 calculate_verify_data(_verify_klass_data, | |
1472 permanent_reserved.start(), | |
1473 permanent_reserved.end()); | |
1474 | |
1475 return _verify_klass_data[0]; | |
1476 } | |
1477 | |
1478 | |
1479 | |
1480 uintptr_t Universe::verify_klass_bits() { | |
1481 verify_klass_mask(); | |
1482 return _verify_klass_data[1]; | |
1483 } | |
1484 | |
1485 | |
1486 uintptr_t Universe::verify_mark_mask() { | 1343 uintptr_t Universe::verify_mark_mask() { |
1487 return markOopDesc::lock_mask_in_place; | 1344 return markOopDesc::lock_mask_in_place; |
1488 } | 1345 } |
1489 | |
1490 | |
1491 | 1346 |
1492 uintptr_t Universe::verify_mark_bits() { | 1347 uintptr_t Universe::verify_mark_bits() { |
1493 intptr_t mask = verify_mark_mask(); | 1348 intptr_t mask = verify_mark_mask(); |
1494 intptr_t bits = (intptr_t)markOopDesc::prototype(); | 1349 intptr_t bits = (intptr_t)markOopDesc::prototype(); |
1495 assert((bits & ~mask) == 0, "no stray header bits"); | 1350 assert((bits & ~mask) == 0, "no stray header bits"); |
1501 void Universe::compute_verify_oop_data() { | 1356 void Universe::compute_verify_oop_data() { |
1502 verify_oop_mask(); | 1357 verify_oop_mask(); |
1503 verify_oop_bits(); | 1358 verify_oop_bits(); |
1504 verify_mark_mask(); | 1359 verify_mark_mask(); |
1505 verify_mark_bits(); | 1360 verify_mark_bits(); |
1506 verify_klass_mask(); | 1361 } |
1507 verify_klass_bits(); | 1362 |
1508 } | 1363 |
1509 | 1364 void CommonMethodOopCache::init(Klass* k, Method* m, TRAPS) { |
1510 | |
1511 void CommonMethodOopCache::init(klassOop k, methodOop m, TRAPS) { | |
1512 if (!UseSharedSpaces) { | 1365 if (!UseSharedSpaces) { |
1513 _klass = k; | 1366 _klass = k; |
1514 } | 1367 } |
1515 #ifndef PRODUCT | 1368 #ifndef PRODUCT |
1516 else { | 1369 else { |
1524 } | 1377 } |
1525 | 1378 |
1526 | 1379 |
1527 ActiveMethodOopsCache::~ActiveMethodOopsCache() { | 1380 ActiveMethodOopsCache::~ActiveMethodOopsCache() { |
1528 if (_prev_methods != NULL) { | 1381 if (_prev_methods != NULL) { |
1529 for (int i = _prev_methods->length() - 1; i >= 0; i--) { | |
1530 jweak method_ref = _prev_methods->at(i); | |
1531 if (method_ref != NULL) { | |
1532 JNIHandles::destroy_weak_global(method_ref); | |
1533 } | |
1534 } | |
1535 delete _prev_methods; | 1382 delete _prev_methods; |
1536 _prev_methods = NULL; | 1383 _prev_methods = NULL; |
1537 } | 1384 } |
1538 } | 1385 } |
1539 | 1386 |
1540 | 1387 |
1541 void ActiveMethodOopsCache::add_previous_version(const methodOop method) { | 1388 void ActiveMethodOopsCache::add_previous_version(Method* const method) { |
1542 assert(Thread::current()->is_VM_thread(), | 1389 assert(Thread::current()->is_VM_thread(), |
1543 "only VMThread can add previous versions"); | 1390 "only VMThread can add previous versions"); |
1391 | |
1392 // Only append the previous method if it is executing on the stack. | |
1393 if (method->on_stack()) { | |
1544 | 1394 |
1545 if (_prev_methods == NULL) { | 1395 if (_prev_methods == NULL) { |
1546 // This is the first previous version so make some space. | 1396 // This is the first previous version so make some space. |
1547 // Start with 2 elements under the assumption that the class | 1397 // Start with 2 elements under the assumption that the class |
1548 // won't be redefined much. | 1398 // won't be redefined much. |
1549 _prev_methods = new (ResourceObj::C_HEAP, mtClass) GrowableArray<jweak>(2, true); | 1399 _prev_methods = new (ResourceObj::C_HEAP, mtClass) GrowableArray<Method*>(2, true); |
1550 } | 1400 } |
1551 | 1401 |
1552 // RC_TRACE macro has an embedded ResourceMark | 1402 // RC_TRACE macro has an embedded ResourceMark |
1553 RC_TRACE(0x00000100, | 1403 RC_TRACE(0x00000100, |
1554 ("add: %s(%s): adding prev version ref for cached method @%d", | 1404 ("add: %s(%s): adding prev version ref for cached method @%d", |
1555 method->name()->as_C_string(), method->signature()->as_C_string(), | 1405 method->name()->as_C_string(), method->signature()->as_C_string(), |
1556 _prev_methods->length())); | 1406 _prev_methods->length())); |
1557 | 1407 |
1558 methodHandle method_h(method); | 1408 _prev_methods->append(method); |
1559 jweak method_ref = JNIHandles::make_weak_global(method_h); | 1409 } |
1560 _prev_methods->append(method_ref); | 1410 |
1561 | 1411 |
1562 // Using weak references allows previous versions of the cached | 1412 // Since the caller is the VMThread and we are at a safepoint, this is a good |
1563 // method to be GC'ed when they are no longer needed. Since the | 1413 // time to clear out unused method references. |
1564 // caller is the VMThread and we are at a safepoint, this is a good | 1414 |
1565 // time to clear out unused weak references. | 1415 if (_prev_methods == NULL) return; |
1566 | 1416 |
1567 for (int i = _prev_methods->length() - 1; i >= 0; i--) { | 1417 for (int i = _prev_methods->length() - 1; i >= 0; i--) { |
1568 jweak method_ref = _prev_methods->at(i); | 1418 Method* method = _prev_methods->at(i); |
1569 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); | 1419 assert(method != NULL, "weak method ref was unexpectedly cleared"); |
1570 if (method_ref == NULL) { | 1420 |
1421 if (!method->on_stack()) { | |
1422 // This method isn't running anymore so remove it | |
1571 _prev_methods->remove_at(i); | 1423 _prev_methods->remove_at(i); |
1572 // Since we are traversing the array backwards, we don't have to | 1424 MetadataFactory::free_metadata(method->method_holder()->class_loader_data(), method); |
1573 // do anything special with the index. | |
1574 continue; // robustness | |
1575 } | |
1576 | |
1577 methodOop m = (methodOop)JNIHandles::resolve(method_ref); | |
1578 if (m == NULL) { | |
1579 // this method entry has been GC'ed so remove it | |
1580 JNIHandles::destroy_weak_global(method_ref); | |
1581 _prev_methods->remove_at(i); | |
1582 } else { | 1425 } else { |
1583 // RC_TRACE macro has an embedded ResourceMark | 1426 // RC_TRACE macro has an embedded ResourceMark |
1584 RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive", | 1427 RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive", |
1585 m->name()->as_C_string(), m->signature()->as_C_string(), i)); | 1428 method->name()->as_C_string(), method->signature()->as_C_string(), i)); |
1586 } | 1429 } |
1587 } | 1430 } |
1588 } // end add_previous_version() | 1431 } // end add_previous_version() |
1589 | 1432 |
1590 | 1433 |
1591 bool ActiveMethodOopsCache::is_same_method(const methodOop method) const { | 1434 bool ActiveMethodOopsCache::is_same_method(Method* const method) const { |
1592 instanceKlass* ik = instanceKlass::cast(klass()); | 1435 InstanceKlass* ik = InstanceKlass::cast(klass()); |
1593 methodOop check_method = ik->method_with_idnum(method_idnum()); | 1436 Method* check_method = ik->method_with_idnum(method_idnum()); |
1594 assert(check_method != NULL, "sanity check"); | 1437 assert(check_method != NULL, "sanity check"); |
1595 if (check_method == method) { | 1438 if (check_method == method) { |
1596 // done with the easy case | 1439 // done with the easy case |
1597 return true; | 1440 return true; |
1598 } | 1441 } |
1599 | 1442 |
1600 if (_prev_methods != NULL) { | 1443 if (_prev_methods != NULL) { |
1601 // The cached method has been redefined at least once so search | 1444 // The cached method has been redefined at least once so search |
1602 // the previous versions for a match. | 1445 // the previous versions for a match. |
1603 for (int i = 0; i < _prev_methods->length(); i++) { | 1446 for (int i = 0; i < _prev_methods->length(); i++) { |
1604 jweak method_ref = _prev_methods->at(i); | 1447 check_method = _prev_methods->at(i); |
1605 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); | |
1606 if (method_ref == NULL) { | |
1607 continue; // robustness | |
1608 } | |
1609 | |
1610 check_method = (methodOop)JNIHandles::resolve(method_ref); | |
1611 if (check_method == method) { | 1448 if (check_method == method) { |
1612 // a previous version matches | 1449 // a previous version matches |
1613 return true; | 1450 return true; |
1614 } | 1451 } |
1615 } | 1452 } |
1618 // either no previous versions or no previous version matched | 1455 // either no previous versions or no previous version matched |
1619 return false; | 1456 return false; |
1620 } | 1457 } |
1621 | 1458 |
1622 | 1459 |
1623 methodOop LatestMethodOopCache::get_methodOop() { | 1460 Method* LatestMethodOopCache::get_Method() { |
1624 instanceKlass* ik = instanceKlass::cast(klass()); | 1461 InstanceKlass* ik = InstanceKlass::cast(klass()); |
1625 methodOop m = ik->method_with_idnum(method_idnum()); | 1462 Method* m = ik->method_with_idnum(method_idnum()); |
1626 assert(m != NULL, "sanity check"); | 1463 assert(m != NULL, "sanity check"); |
1627 return m; | 1464 return m; |
1628 } | 1465 } |
1629 | 1466 |
1630 | 1467 |