Mercurial > hg > truffle
annotate src/share/vm/memory/universe.cpp @ 622:56aae7be60d4
6812678: macro assembler needs delayed binding of a few constants (for 6655638)
Summary: minor assembler enhancements preparing for method handles
Reviewed-by: kvn
author | jrose |
---|---|
date | Wed, 04 Mar 2009 09:58:39 -0800 |
parents | d593294016c3 |
children | 0fbdb4381b99 660978a2a31a |
rev | line source |
---|---|
0 | 1 /* |
196 | 2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 # include "incls/_precompiled.incl" | |
26 # include "incls/_universe.cpp.incl" | |
27 | |
28 // Known objects | |
29 klassOop Universe::_boolArrayKlassObj = NULL; | |
30 klassOop Universe::_byteArrayKlassObj = NULL; | |
31 klassOop Universe::_charArrayKlassObj = NULL; | |
32 klassOop Universe::_intArrayKlassObj = NULL; | |
33 klassOop Universe::_shortArrayKlassObj = NULL; | |
34 klassOop Universe::_longArrayKlassObj = NULL; | |
35 klassOop Universe::_singleArrayKlassObj = NULL; | |
36 klassOop Universe::_doubleArrayKlassObj = NULL; | |
37 klassOop Universe::_typeArrayKlassObjs[T_VOID+1] = { NULL /*, NULL...*/ }; | |
38 klassOop Universe::_objectArrayKlassObj = NULL; | |
39 klassOop Universe::_symbolKlassObj = NULL; | |
40 klassOop Universe::_methodKlassObj = NULL; | |
41 klassOop Universe::_constMethodKlassObj = NULL; | |
42 klassOop Universe::_methodDataKlassObj = NULL; | |
43 klassOop Universe::_klassKlassObj = NULL; | |
44 klassOop Universe::_arrayKlassKlassObj = NULL; | |
45 klassOop Universe::_objArrayKlassKlassObj = NULL; | |
46 klassOop Universe::_typeArrayKlassKlassObj = NULL; | |
47 klassOop Universe::_instanceKlassKlassObj = NULL; | |
48 klassOop Universe::_constantPoolKlassObj = NULL; | |
49 klassOop Universe::_constantPoolCacheKlassObj = NULL; | |
50 klassOop Universe::_compiledICHolderKlassObj = NULL; | |
51 klassOop Universe::_systemObjArrayKlassObj = NULL; | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
52 oop Universe::_int_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
53 oop Universe::_float_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
54 oop Universe::_double_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
55 oop Universe::_byte_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
56 oop Universe::_bool_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
57 oop Universe::_char_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
58 oop Universe::_long_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
59 oop Universe::_short_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
60 oop Universe::_void_mirror = NULL; |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
61 oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ }; |
0 | 62 oop Universe::_main_thread_group = NULL; |
63 oop Universe::_system_thread_group = NULL; | |
64 typeArrayOop Universe::_the_empty_byte_array = NULL; | |
65 typeArrayOop Universe::_the_empty_short_array = NULL; | |
66 typeArrayOop Universe::_the_empty_int_array = NULL; | |
67 objArrayOop Universe::_the_empty_system_obj_array = NULL; | |
68 objArrayOop Universe::_the_empty_class_klass_array = NULL; | |
69 objArrayOop Universe::_the_array_interfaces_array = NULL; | |
70 LatestMethodOopCache* Universe::_finalizer_register_cache = NULL; | |
71 LatestMethodOopCache* Universe::_loader_addClass_cache = NULL; | |
72 ActiveMethodOopsCache* Universe::_reflect_invoke_cache = NULL; | |
73 oop Universe::_out_of_memory_error_java_heap = NULL; | |
74 oop Universe::_out_of_memory_error_perm_gen = NULL; | |
75 oop Universe::_out_of_memory_error_array_size = NULL; | |
76 oop Universe::_out_of_memory_error_gc_overhead_limit = NULL; | |
77 objArrayOop Universe::_preallocated_out_of_memory_error_array = NULL; | |
78 volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0; | |
79 bool Universe::_verify_in_progress = false; | |
80 oop Universe::_null_ptr_exception_instance = NULL; | |
81 oop Universe::_arithmetic_exception_instance = NULL; | |
82 oop Universe::_virtual_machine_error_instance = NULL; | |
83 oop Universe::_vm_exception = NULL; | |
84 oop Universe::_emptySymbol = NULL; | |
85 | |
86 // These variables are guarded by FullGCALot_lock. | |
87 debug_only(objArrayOop Universe::_fullgc_alot_dummy_array = NULL;) | |
88 debug_only(int Universe::_fullgc_alot_dummy_next = 0;) | |
89 | |
90 | |
91 // Heap | |
92 int Universe::_verify_count = 0; | |
93 | |
94 int Universe::_base_vtable_size = 0; | |
95 bool Universe::_bootstrapping = false; | |
96 bool Universe::_fully_initialized = false; | |
97 | |
98 size_t Universe::_heap_capacity_at_last_gc; | |
453
c96030fff130
6684579: SoftReference processing can be made more efficient
ysr
parents:
356
diff
changeset
|
99 size_t Universe::_heap_used_at_last_gc = 0; |
0 | 100 |
101 CollectedHeap* Universe::_collectedHeap = NULL; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
102 address Universe::_heap_base = NULL; |
0 | 103 |
104 | |
105 void Universe::basic_type_classes_do(void f(klassOop)) { | |
106 f(boolArrayKlassObj()); | |
107 f(byteArrayKlassObj()); | |
108 f(charArrayKlassObj()); | |
109 f(intArrayKlassObj()); | |
110 f(shortArrayKlassObj()); | |
111 f(longArrayKlassObj()); | |
112 f(singleArrayKlassObj()); | |
113 f(doubleArrayKlassObj()); | |
114 } | |
115 | |
116 | |
117 void Universe::system_classes_do(void f(klassOop)) { | |
118 f(symbolKlassObj()); | |
119 f(methodKlassObj()); | |
120 f(constMethodKlassObj()); | |
121 f(methodDataKlassObj()); | |
122 f(klassKlassObj()); | |
123 f(arrayKlassKlassObj()); | |
124 f(objArrayKlassKlassObj()); | |
125 f(typeArrayKlassKlassObj()); | |
126 f(instanceKlassKlassObj()); | |
127 f(constantPoolKlassObj()); | |
128 f(systemObjArrayKlassObj()); | |
129 } | |
130 | |
131 void Universe::oops_do(OopClosure* f, bool do_all) { | |
132 | |
133 f->do_oop((oop*) &_int_mirror); | |
134 f->do_oop((oop*) &_float_mirror); | |
135 f->do_oop((oop*) &_double_mirror); | |
136 f->do_oop((oop*) &_byte_mirror); | |
137 f->do_oop((oop*) &_bool_mirror); | |
138 f->do_oop((oop*) &_char_mirror); | |
139 f->do_oop((oop*) &_long_mirror); | |
140 f->do_oop((oop*) &_short_mirror); | |
141 f->do_oop((oop*) &_void_mirror); | |
142 | |
143 // It's important to iterate over these guys even if they are null, | |
144 // since that's how shared heaps are restored. | |
145 for (int i = T_BOOLEAN; i < T_VOID+1; i++) { | |
146 f->do_oop((oop*) &_mirrors[i]); | |
147 } | |
148 assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking"); | |
149 | |
150 // %%% Consider moving those "shared oops" over here with the others. | |
151 f->do_oop((oop*)&_boolArrayKlassObj); | |
152 f->do_oop((oop*)&_byteArrayKlassObj); | |
153 f->do_oop((oop*)&_charArrayKlassObj); | |
154 f->do_oop((oop*)&_intArrayKlassObj); | |
155 f->do_oop((oop*)&_shortArrayKlassObj); | |
156 f->do_oop((oop*)&_longArrayKlassObj); | |
157 f->do_oop((oop*)&_singleArrayKlassObj); | |
158 f->do_oop((oop*)&_doubleArrayKlassObj); | |
159 f->do_oop((oop*)&_objectArrayKlassObj); | |
160 { | |
161 for (int i = 0; i < T_VOID+1; i++) { | |
162 if (_typeArrayKlassObjs[i] != NULL) { | |
163 assert(i >= T_BOOLEAN, "checking"); | |
164 f->do_oop((oop*)&_typeArrayKlassObjs[i]); | |
165 } else if (do_all) { | |
166 f->do_oop((oop*)&_typeArrayKlassObjs[i]); | |
167 } | |
168 } | |
169 } | |
170 f->do_oop((oop*)&_symbolKlassObj); | |
171 f->do_oop((oop*)&_methodKlassObj); | |
172 f->do_oop((oop*)&_constMethodKlassObj); | |
173 f->do_oop((oop*)&_methodDataKlassObj); | |
174 f->do_oop((oop*)&_klassKlassObj); | |
175 f->do_oop((oop*)&_arrayKlassKlassObj); | |
176 f->do_oop((oop*)&_objArrayKlassKlassObj); | |
177 f->do_oop((oop*)&_typeArrayKlassKlassObj); | |
178 f->do_oop((oop*)&_instanceKlassKlassObj); | |
179 f->do_oop((oop*)&_constantPoolKlassObj); | |
180 f->do_oop((oop*)&_constantPoolCacheKlassObj); | |
181 f->do_oop((oop*)&_compiledICHolderKlassObj); | |
182 f->do_oop((oop*)&_systemObjArrayKlassObj); | |
183 f->do_oop((oop*)&_the_empty_byte_array); | |
184 f->do_oop((oop*)&_the_empty_short_array); | |
185 f->do_oop((oop*)&_the_empty_int_array); | |
186 f->do_oop((oop*)&_the_empty_system_obj_array); | |
187 f->do_oop((oop*)&_the_empty_class_klass_array); | |
188 f->do_oop((oop*)&_the_array_interfaces_array); | |
189 _finalizer_register_cache->oops_do(f); | |
190 _loader_addClass_cache->oops_do(f); | |
191 _reflect_invoke_cache->oops_do(f); | |
192 f->do_oop((oop*)&_out_of_memory_error_java_heap); | |
193 f->do_oop((oop*)&_out_of_memory_error_perm_gen); | |
194 f->do_oop((oop*)&_out_of_memory_error_array_size); | |
195 f->do_oop((oop*)&_out_of_memory_error_gc_overhead_limit); | |
196 if (_preallocated_out_of_memory_error_array != (oop)NULL) { // NULL when DumpSharedSpaces | |
197 f->do_oop((oop*)&_preallocated_out_of_memory_error_array); | |
198 } | |
199 f->do_oop((oop*)&_null_ptr_exception_instance); | |
200 f->do_oop((oop*)&_arithmetic_exception_instance); | |
201 f->do_oop((oop*)&_virtual_machine_error_instance); | |
202 f->do_oop((oop*)&_main_thread_group); | |
203 f->do_oop((oop*)&_system_thread_group); | |
204 f->do_oop((oop*)&_vm_exception); | |
205 f->do_oop((oop*)&_emptySymbol); | |
206 debug_only(f->do_oop((oop*)&_fullgc_alot_dummy_array);) | |
207 } | |
208 | |
209 | |
210 void Universe::check_alignment(uintx size, uintx alignment, const char* name) { | |
211 if (size < alignment || size % alignment != 0) { | |
212 ResourceMark rm; | |
213 stringStream st; | |
214 st.print("Size of %s (%ld bytes) must be aligned to %ld bytes", name, size, alignment); | |
215 char* error = st.as_string(); | |
216 vm_exit_during_initialization(error); | |
217 } | |
218 } | |
219 | |
220 | |
221 void Universe::genesis(TRAPS) { | |
222 ResourceMark rm; | |
223 { FlagSetting fs(_bootstrapping, true); | |
224 | |
225 { MutexLocker mc(Compile_lock); | |
226 | |
227 // determine base vtable size; without that we cannot create the array klasses | |
228 compute_base_vtable_size(); | |
229 | |
230 if (!UseSharedSpaces) { | |
231 _klassKlassObj = klassKlass::create_klass(CHECK); | |
232 _arrayKlassKlassObj = arrayKlassKlass::create_klass(CHECK); | |
233 | |
234 _objArrayKlassKlassObj = objArrayKlassKlass::create_klass(CHECK); | |
235 _instanceKlassKlassObj = instanceKlassKlass::create_klass(CHECK); | |
236 _typeArrayKlassKlassObj = typeArrayKlassKlass::create_klass(CHECK); | |
237 | |
238 _symbolKlassObj = symbolKlass::create_klass(CHECK); | |
239 | |
240 _emptySymbol = oopFactory::new_symbol("", CHECK); | |
241 | |
242 _boolArrayKlassObj = typeArrayKlass::create_klass(T_BOOLEAN, sizeof(jboolean), CHECK); | |
243 _charArrayKlassObj = typeArrayKlass::create_klass(T_CHAR, sizeof(jchar), CHECK); | |
244 _singleArrayKlassObj = typeArrayKlass::create_klass(T_FLOAT, sizeof(jfloat), CHECK); | |
245 _doubleArrayKlassObj = typeArrayKlass::create_klass(T_DOUBLE, sizeof(jdouble), CHECK); | |
246 _byteArrayKlassObj = typeArrayKlass::create_klass(T_BYTE, sizeof(jbyte), CHECK); | |
247 _shortArrayKlassObj = typeArrayKlass::create_klass(T_SHORT, sizeof(jshort), CHECK); | |
248 _intArrayKlassObj = typeArrayKlass::create_klass(T_INT, sizeof(jint), CHECK); | |
249 _longArrayKlassObj = typeArrayKlass::create_klass(T_LONG, sizeof(jlong), CHECK); | |
250 | |
251 _typeArrayKlassObjs[T_BOOLEAN] = _boolArrayKlassObj; | |
252 _typeArrayKlassObjs[T_CHAR] = _charArrayKlassObj; | |
253 _typeArrayKlassObjs[T_FLOAT] = _singleArrayKlassObj; | |
254 _typeArrayKlassObjs[T_DOUBLE] = _doubleArrayKlassObj; | |
255 _typeArrayKlassObjs[T_BYTE] = _byteArrayKlassObj; | |
256 _typeArrayKlassObjs[T_SHORT] = _shortArrayKlassObj; | |
257 _typeArrayKlassObjs[T_INT] = _intArrayKlassObj; | |
258 _typeArrayKlassObjs[T_LONG] = _longArrayKlassObj; | |
259 | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
260 _methodKlassObj = methodKlass::create_klass(CHECK); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
261 _constMethodKlassObj = constMethodKlass::create_klass(CHECK); |
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
262 _methodDataKlassObj = methodDataKlass::create_klass(CHECK); |
0 | 263 _constantPoolKlassObj = constantPoolKlass::create_klass(CHECK); |
264 _constantPoolCacheKlassObj = constantPoolCacheKlass::create_klass(CHECK); | |
265 | |
266 _compiledICHolderKlassObj = compiledICHolderKlass::create_klass(CHECK); | |
267 _systemObjArrayKlassObj = objArrayKlassKlass::cast(objArrayKlassKlassObj())->allocate_system_objArray_klass(CHECK); | |
268 | |
481
7d7a7c599c17
6578152: fill_region_with_object has usability and safety issues
jcoomes
parents:
453
diff
changeset
|
269 _the_empty_byte_array = oopFactory::new_permanent_byteArray(0, CHECK); |
0 | 270 _the_empty_short_array = oopFactory::new_permanent_shortArray(0, CHECK); |
271 _the_empty_int_array = oopFactory::new_permanent_intArray(0, CHECK); | |
272 _the_empty_system_obj_array = oopFactory::new_system_objArray(0, CHECK); | |
273 | |
274 _the_array_interfaces_array = oopFactory::new_system_objArray(2, CHECK); | |
275 _vm_exception = oopFactory::new_symbol("vm exception holder", CHECK); | |
276 } else { | |
277 FileMapInfo *mapinfo = FileMapInfo::current_info(); | |
278 char* buffer = mapinfo->region_base(CompactingPermGenGen::md); | |
279 void** vtbl_list = (void**)buffer; | |
280 init_self_patching_vtbl_list(vtbl_list, | |
281 CompactingPermGenGen::vtbl_list_size); | |
282 } | |
283 } | |
284 | |
285 vmSymbols::initialize(CHECK); | |
286 | |
287 SystemDictionary::initialize(CHECK); | |
288 | |
289 klassOop ok = SystemDictionary::object_klass(); | |
290 | |
291 if (UseSharedSpaces) { | |
292 // Verify shared interfaces array. | |
293 assert(_the_array_interfaces_array->obj_at(0) == | |
294 SystemDictionary::cloneable_klass(), "u3"); | |
295 assert(_the_array_interfaces_array->obj_at(1) == | |
296 SystemDictionary::serializable_klass(), "u3"); | |
297 | |
298 // Verify element klass for system obj array klass | |
299 assert(objArrayKlass::cast(_systemObjArrayKlassObj)->element_klass() == ok, "u1"); | |
300 assert(objArrayKlass::cast(_systemObjArrayKlassObj)->bottom_klass() == ok, "u2"); | |
301 | |
302 // Verify super class for the classes created above | |
303 assert(Klass::cast(boolArrayKlassObj() )->super() == ok, "u3"); | |
304 assert(Klass::cast(charArrayKlassObj() )->super() == ok, "u3"); | |
305 assert(Klass::cast(singleArrayKlassObj() )->super() == ok, "u3"); | |
306 assert(Klass::cast(doubleArrayKlassObj() )->super() == ok, "u3"); | |
307 assert(Klass::cast(byteArrayKlassObj() )->super() == ok, "u3"); | |
308 assert(Klass::cast(shortArrayKlassObj() )->super() == ok, "u3"); | |
309 assert(Klass::cast(intArrayKlassObj() )->super() == ok, "u3"); | |
310 assert(Klass::cast(longArrayKlassObj() )->super() == ok, "u3"); | |
311 assert(Klass::cast(constantPoolKlassObj() )->super() == ok, "u3"); | |
312 assert(Klass::cast(systemObjArrayKlassObj())->super() == ok, "u3"); | |
313 } else { | |
314 // Set up shared interfaces array. (Do this before supers are set up.) | |
315 _the_array_interfaces_array->obj_at_put(0, SystemDictionary::cloneable_klass()); | |
316 _the_array_interfaces_array->obj_at_put(1, SystemDictionary::serializable_klass()); | |
317 | |
318 // Set element klass for system obj array klass | |
319 objArrayKlass::cast(_systemObjArrayKlassObj)->set_element_klass(ok); | |
320 objArrayKlass::cast(_systemObjArrayKlassObj)->set_bottom_klass(ok); | |
321 | |
322 // Set super class for the classes created above | |
323 Klass::cast(boolArrayKlassObj() )->initialize_supers(ok, CHECK); | |
324 Klass::cast(charArrayKlassObj() )->initialize_supers(ok, CHECK); | |
325 Klass::cast(singleArrayKlassObj() )->initialize_supers(ok, CHECK); | |
326 Klass::cast(doubleArrayKlassObj() )->initialize_supers(ok, CHECK); | |
327 Klass::cast(byteArrayKlassObj() )->initialize_supers(ok, CHECK); | |
328 Klass::cast(shortArrayKlassObj() )->initialize_supers(ok, CHECK); | |
329 Klass::cast(intArrayKlassObj() )->initialize_supers(ok, CHECK); | |
330 Klass::cast(longArrayKlassObj() )->initialize_supers(ok, CHECK); | |
331 Klass::cast(constantPoolKlassObj() )->initialize_supers(ok, CHECK); | |
332 Klass::cast(systemObjArrayKlassObj())->initialize_supers(ok, CHECK); | |
333 Klass::cast(boolArrayKlassObj() )->set_super(ok); | |
334 Klass::cast(charArrayKlassObj() )->set_super(ok); | |
335 Klass::cast(singleArrayKlassObj() )->set_super(ok); | |
336 Klass::cast(doubleArrayKlassObj() )->set_super(ok); | |
337 Klass::cast(byteArrayKlassObj() )->set_super(ok); | |
338 Klass::cast(shortArrayKlassObj() )->set_super(ok); | |
339 Klass::cast(intArrayKlassObj() )->set_super(ok); | |
340 Klass::cast(longArrayKlassObj() )->set_super(ok); | |
341 Klass::cast(constantPoolKlassObj() )->set_super(ok); | |
342 Klass::cast(systemObjArrayKlassObj())->set_super(ok); | |
343 } | |
344 | |
345 Klass::cast(boolArrayKlassObj() )->append_to_sibling_list(); | |
346 Klass::cast(charArrayKlassObj() )->append_to_sibling_list(); | |
347 Klass::cast(singleArrayKlassObj() )->append_to_sibling_list(); | |
348 Klass::cast(doubleArrayKlassObj() )->append_to_sibling_list(); | |
349 Klass::cast(byteArrayKlassObj() )->append_to_sibling_list(); | |
350 Klass::cast(shortArrayKlassObj() )->append_to_sibling_list(); | |
351 Klass::cast(intArrayKlassObj() )->append_to_sibling_list(); | |
352 Klass::cast(longArrayKlassObj() )->append_to_sibling_list(); | |
353 Klass::cast(constantPoolKlassObj() )->append_to_sibling_list(); | |
354 Klass::cast(systemObjArrayKlassObj())->append_to_sibling_list(); | |
355 } // end of core bootstrapping | |
356 | |
357 // Initialize _objectArrayKlass after core bootstraping to make | |
358 // sure the super class is set up properly for _objectArrayKlass. | |
359 _objectArrayKlassObj = instanceKlass:: | |
360 cast(SystemDictionary::object_klass())->array_klass(1, CHECK); | |
361 // Add the class to the class hierarchy manually to make sure that | |
362 // its vtable is initialized after core bootstrapping is completed. | |
363 Klass::cast(_objectArrayKlassObj)->append_to_sibling_list(); | |
364 | |
365 // Compute is_jdk version flags. | |
366 // Only 1.3 or later has the java.lang.Shutdown class. | |
367 // Only 1.4 or later has the java.lang.CharSequence interface. | |
368 // Only 1.5 or later has the java.lang.management.MemoryUsage class. | |
242 | 369 if (JDK_Version::is_partially_initialized()) { |
370 uint8_t jdk_version; | |
371 klassOop k = SystemDictionary::resolve_or_null( | |
372 vmSymbolHandles::java_lang_management_MemoryUsage(), THREAD); | |
0 | 373 CLEAR_PENDING_EXCEPTION; // ignore exceptions |
374 if (k == NULL) { | |
242 | 375 k = SystemDictionary::resolve_or_null( |
376 vmSymbolHandles::java_lang_CharSequence(), THREAD); | |
0 | 377 CLEAR_PENDING_EXCEPTION; // ignore exceptions |
378 if (k == NULL) { | |
242 | 379 k = SystemDictionary::resolve_or_null( |
380 vmSymbolHandles::java_lang_Shutdown(), THREAD); | |
0 | 381 CLEAR_PENDING_EXCEPTION; // ignore exceptions |
382 if (k == NULL) { | |
242 | 383 jdk_version = 2; |
0 | 384 } else { |
242 | 385 jdk_version = 3; |
0 | 386 } |
387 } else { | |
242 | 388 jdk_version = 4; |
0 | 389 } |
390 } else { | |
242 | 391 jdk_version = 5; |
0 | 392 } |
242 | 393 JDK_Version::fully_initialize(jdk_version); |
0 | 394 } |
395 | |
396 #ifdef ASSERT | |
397 if (FullGCALot) { | |
398 // Allocate an array of dummy objects. | |
399 // We'd like these to be at the bottom of the old generation, | |
400 // so that when we free one and then collect, | |
401 // (almost) the whole heap moves | |
402 // and we find out if we actually update all the oops correctly. | |
403 // But we can't allocate directly in the old generation, | |
404 // so we allocate wherever, and hope that the first collection | |
405 // moves these objects to the bottom of the old generation. | |
406 // We can allocate directly in the permanent generation, so we do. | |
407 int size; | |
408 if (UseConcMarkSweepGC) { | |
409 warning("Using +FullGCALot with concurrent mark sweep gc " | |
410 "will not force all objects to relocate"); | |
411 size = FullGCALotDummies; | |
412 } else { | |
413 size = FullGCALotDummies * 2; | |
414 } | |
415 objArrayOop naked_array = oopFactory::new_system_objArray(size, CHECK); | |
416 objArrayHandle dummy_array(THREAD, naked_array); | |
417 int i = 0; | |
418 while (i < size) { | |
419 if (!UseConcMarkSweepGC) { | |
420 // Allocate dummy in old generation | |
421 oop dummy = instanceKlass::cast(SystemDictionary::object_klass())->allocate_instance(CHECK); | |
422 dummy_array->obj_at_put(i++, dummy); | |
423 } | |
424 // Allocate dummy in permanent generation | |
425 oop dummy = instanceKlass::cast(SystemDictionary::object_klass())->allocate_permanent_instance(CHECK); | |
426 dummy_array->obj_at_put(i++, dummy); | |
427 } | |
428 { | |
429 // Only modify the global variable inside the mutex. | |
430 // If we had a race to here, the other dummy_array instances | |
431 // and their elements just get dropped on the floor, which is fine. | |
432 MutexLocker ml(FullGCALot_lock); | |
433 if (_fullgc_alot_dummy_array == NULL) { | |
434 _fullgc_alot_dummy_array = dummy_array(); | |
435 } | |
436 } | |
437 assert(i == _fullgc_alot_dummy_array->length(), "just checking"); | |
438 } | |
439 #endif | |
440 } | |
441 | |
442 | |
443 static inline void add_vtable(void** list, int* n, Klass* o, int count) { | |
444 list[(*n)++] = *(void**)&o->vtbl_value(); | |
445 guarantee((*n) <= count, "vtable list too small."); | |
446 } | |
447 | |
448 | |
449 void Universe::init_self_patching_vtbl_list(void** list, int count) { | |
450 int n = 0; | |
451 { klassKlass o; add_vtable(list, &n, &o, count); } | |
452 { arrayKlassKlass o; add_vtable(list, &n, &o, count); } | |
453 { objArrayKlassKlass o; add_vtable(list, &n, &o, count); } | |
454 { instanceKlassKlass o; add_vtable(list, &n, &o, count); } | |
455 { instanceKlass o; add_vtable(list, &n, &o, count); } | |
456 { instanceRefKlass o; add_vtable(list, &n, &o, count); } | |
457 { typeArrayKlassKlass o; add_vtable(list, &n, &o, count); } | |
458 { symbolKlass o; add_vtable(list, &n, &o, count); } | |
459 { typeArrayKlass o; add_vtable(list, &n, &o, count); } | |
460 { methodKlass o; add_vtable(list, &n, &o, count); } | |
461 { constMethodKlass o; add_vtable(list, &n, &o, count); } | |
462 { constantPoolKlass o; add_vtable(list, &n, &o, count); } | |
463 { constantPoolCacheKlass o; add_vtable(list, &n, &o, count); } | |
464 { objArrayKlass o; add_vtable(list, &n, &o, count); } | |
465 { methodDataKlass o; add_vtable(list, &n, &o, count); } | |
466 { compiledICHolderKlass o; add_vtable(list, &n, &o, count); } | |
467 } | |
468 | |
469 | |
470 class FixupMirrorClosure: public ObjectClosure { | |
471 public: | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
472 virtual void do_object(oop obj) { |
0 | 473 if (obj->is_klass()) { |
474 EXCEPTION_MARK; | |
475 KlassHandle k(THREAD, klassOop(obj)); | |
476 // We will never reach the CATCH below since Exceptions::_throw will cause | |
477 // the VM to exit if an exception is thrown during initialization | |
478 java_lang_Class::create_mirror(k, CATCH); | |
479 // This call unconditionally creates a new mirror for k, | |
480 // and links in k's component_mirror field if k is an array. | |
481 // If k is an objArray, k's element type must already have | |
482 // a mirror. In other words, this closure must process | |
483 // the component type of an objArray k before it processes k. | |
484 // This works because the permgen iterator presents arrays | |
485 // and their component types in order of creation. | |
486 } | |
487 } | |
488 }; | |
489 | |
490 void Universe::initialize_basic_type_mirrors(TRAPS) { | |
491 if (UseSharedSpaces) { | |
492 assert(_int_mirror != NULL, "already loaded"); | |
493 assert(_void_mirror == _mirrors[T_VOID], "consistently loaded"); | |
494 } else { | |
495 | |
496 assert(_int_mirror==NULL, "basic type mirrors already initialized"); | |
497 _int_mirror = | |
498 java_lang_Class::create_basic_type_mirror("int", T_INT, CHECK); | |
499 _float_mirror = | |
500 java_lang_Class::create_basic_type_mirror("float", T_FLOAT, CHECK); | |
501 _double_mirror = | |
502 java_lang_Class::create_basic_type_mirror("double", T_DOUBLE, CHECK); | |
503 _byte_mirror = | |
504 java_lang_Class::create_basic_type_mirror("byte", T_BYTE, CHECK); | |
505 _bool_mirror = | |
506 java_lang_Class::create_basic_type_mirror("boolean",T_BOOLEAN, CHECK); | |
507 _char_mirror = | |
508 java_lang_Class::create_basic_type_mirror("char", T_CHAR, CHECK); | |
509 _long_mirror = | |
510 java_lang_Class::create_basic_type_mirror("long", T_LONG, CHECK); | |
511 _short_mirror = | |
512 java_lang_Class::create_basic_type_mirror("short", T_SHORT, CHECK); | |
513 _void_mirror = | |
514 java_lang_Class::create_basic_type_mirror("void", T_VOID, CHECK); | |
515 | |
516 _mirrors[T_INT] = _int_mirror; | |
517 _mirrors[T_FLOAT] = _float_mirror; | |
518 _mirrors[T_DOUBLE] = _double_mirror; | |
519 _mirrors[T_BYTE] = _byte_mirror; | |
520 _mirrors[T_BOOLEAN] = _bool_mirror; | |
521 _mirrors[T_CHAR] = _char_mirror; | |
522 _mirrors[T_LONG] = _long_mirror; | |
523 _mirrors[T_SHORT] = _short_mirror; | |
524 _mirrors[T_VOID] = _void_mirror; | |
525 //_mirrors[T_OBJECT] = instanceKlass::cast(_object_klass)->java_mirror(); | |
526 //_mirrors[T_ARRAY] = instanceKlass::cast(_object_klass)->java_mirror(); | |
527 } | |
528 } | |
529 | |
530 void Universe::fixup_mirrors(TRAPS) { | |
531 // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, | |
532 // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply | |
533 // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note | |
534 // that the number of objects allocated at this point is very small. | |
535 assert(SystemDictionary::class_klass_loaded(), "java.lang.Class should be loaded"); | |
536 FixupMirrorClosure blk; | |
537 Universe::heap()->permanent_object_iterate(&blk); | |
538 } | |
539 | |
540 | |
541 static bool has_run_finalizers_on_exit = false; | |
542 | |
543 void Universe::run_finalizers_on_exit() { | |
544 if (has_run_finalizers_on_exit) return; | |
545 has_run_finalizers_on_exit = true; | |
546 | |
547 // Called on VM exit. This ought to be run in a separate thread. | |
548 if (TraceReferenceGC) tty->print_cr("Callback to run finalizers on exit"); | |
549 { | |
550 PRESERVE_EXCEPTION_MARK; | |
551 KlassHandle finalizer_klass(THREAD, SystemDictionary::finalizer_klass()); | |
552 JavaValue result(T_VOID); | |
553 JavaCalls::call_static( | |
554 &result, | |
555 finalizer_klass, | |
556 vmSymbolHandles::run_finalizers_on_exit_name(), | |
557 vmSymbolHandles::void_method_signature(), | |
558 THREAD | |
559 ); | |
560 // Ignore any pending exceptions | |
561 CLEAR_PENDING_EXCEPTION; | |
562 } | |
563 } | |
564 | |
565 | |
566 // initialize_vtable could cause gc if | |
567 // 1) we specified true to initialize_vtable and | |
568 // 2) this ran after gc was enabled | |
569 // In case those ever change we use handles for oops | |
570 void Universe::reinitialize_vtable_of(KlassHandle k_h, TRAPS) { | |
571 // init vtable of k and all subclasses | |
572 Klass* ko = k_h()->klass_part(); | |
573 klassVtable* vt = ko->vtable(); | |
574 if (vt) vt->initialize_vtable(false, CHECK); | |
575 if (ko->oop_is_instance()) { | |
576 instanceKlass* ik = (instanceKlass*)ko; | |
577 for (KlassHandle s_h(THREAD, ik->subklass()); s_h() != NULL; s_h = (THREAD, s_h()->klass_part()->next_sibling())) { | |
578 reinitialize_vtable_of(s_h, CHECK); | |
579 } | |
580 } | |
581 } | |
582 | |
583 | |
584 void initialize_itable_for_klass(klassOop k, TRAPS) { | |
585 instanceKlass::cast(k)->itable()->initialize_itable(false, CHECK); | |
586 } | |
587 | |
588 | |
589 void Universe::reinitialize_itables(TRAPS) { | |
590 SystemDictionary::classes_do(initialize_itable_for_klass, CHECK); | |
591 | |
592 } | |
593 | |
594 | |
595 bool Universe::on_page_boundary(void* addr) { | |
596 return ((uintptr_t) addr) % os::vm_page_size() == 0; | |
597 } | |
598 | |
599 | |
600 bool Universe::should_fill_in_stack_trace(Handle throwable) { | |
601 // never attempt to fill in the stack trace of preallocated errors that do not have | |
602 // backtrace. These errors are kept alive forever and may be "re-used" when all | |
603 // preallocated errors with backtrace have been consumed. Also need to avoid | |
604 // a potential loop which could happen if an out of memory occurs when attempting | |
605 // to allocate the backtrace. | |
606 return ((throwable() != Universe::_out_of_memory_error_java_heap) && | |
607 (throwable() != Universe::_out_of_memory_error_perm_gen) && | |
608 (throwable() != Universe::_out_of_memory_error_array_size) && | |
609 (throwable() != Universe::_out_of_memory_error_gc_overhead_limit)); | |
610 } | |
611 | |
612 | |
613 oop Universe::gen_out_of_memory_error(oop default_err) { | |
614 // generate an out of memory error: | |
615 // - if there is a preallocated error with backtrace available then return it wth | |
616 // a filled in stack trace. | |
617 // - if there are no preallocated errors with backtrace available then return | |
618 // an error without backtrace. | |
619 int next; | |
620 if (_preallocated_out_of_memory_error_avail_count > 0) { | |
621 next = (int)Atomic::add(-1, &_preallocated_out_of_memory_error_avail_count); | |
622 assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt"); | |
623 } else { | |
624 next = -1; | |
625 } | |
626 if (next < 0) { | |
627 // all preallocated errors have been used. | |
628 // return default | |
629 return default_err; | |
630 } else { | |
631 // get the error object at the slot and set set it to NULL so that the | |
632 // array isn't keeping it alive anymore. | |
633 oop exc = preallocated_out_of_memory_errors()->obj_at(next); | |
634 assert(exc != NULL, "slot has been used already"); | |
635 preallocated_out_of_memory_errors()->obj_at_put(next, NULL); | |
636 | |
637 // use the message from the default error | |
638 oop msg = java_lang_Throwable::message(default_err); | |
639 assert(msg != NULL, "no message"); | |
640 java_lang_Throwable::set_message(exc, msg); | |
641 | |
642 // populate the stack trace and return it. | |
643 java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(exc); | |
644 return exc; | |
645 } | |
646 } | |
647 | |
648 static intptr_t non_oop_bits = 0; | |
649 | |
650 void* Universe::non_oop_word() { | |
651 // Neither the high bits nor the low bits of this value is allowed | |
652 // to look like (respectively) the high or low bits of a real oop. | |
653 // | |
654 // High and low are CPU-specific notions, but low always includes | |
655 // the low-order bit. Since oops are always aligned at least mod 4, | |
656 // setting the low-order bit will ensure that the low half of the | |
657 // word will never look like that of a real oop. | |
658 // | |
659 // Using the OS-supplied non-memory-address word (usually 0 or -1) | |
660 // will take care of the high bits, however many there are. | |
661 | |
662 if (non_oop_bits == 0) { | |
663 non_oop_bits = (intptr_t)os::non_memory_address_word() | 1; | |
664 } | |
665 | |
666 return (void*)non_oop_bits; | |
667 } | |
668 | |
669 jint universe_init() { | |
670 assert(!Universe::_fully_initialized, "called after initialize_vtables"); | |
671 guarantee(1 << LogHeapWordSize == sizeof(HeapWord), | |
672 "LogHeapWordSize is incorrect."); | |
673 guarantee(sizeof(oop) >= sizeof(HeapWord), "HeapWord larger than oop?"); | |
674 guarantee(sizeof(oop) % sizeof(HeapWord) == 0, | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
675 "oop size is not not a multiple of HeapWord size"); |
0 | 676 TraceTime timer("Genesis", TraceStartupTime); |
677 GC_locker::lock(); // do not allow gc during bootstrapping | |
678 JavaClasses::compute_hard_coded_offsets(); | |
679 | |
680 // Get map info from shared archive file. | |
681 if (DumpSharedSpaces) | |
682 UseSharedSpaces = false; | |
683 | |
684 FileMapInfo* mapinfo = NULL; | |
685 if (UseSharedSpaces) { | |
686 mapinfo = NEW_C_HEAP_OBJ(FileMapInfo); | |
687 memset(mapinfo, 0, sizeof(FileMapInfo)); | |
688 | |
689 // Open the shared archive file, read and validate the header. If | |
690 // initialization files, shared spaces [UseSharedSpaces] are | |
691 // disabled and the file is closed. | |
692 | |
693 if (mapinfo->initialize()) { | |
694 FileMapInfo::set_current_info(mapinfo); | |
695 } else { | |
696 assert(!mapinfo->is_open() && !UseSharedSpaces, | |
697 "archive file not closed or shared spaces not disabled."); | |
698 } | |
699 } | |
700 | |
701 jint status = Universe::initialize_heap(); | |
702 if (status != JNI_OK) { | |
703 return status; | |
704 } | |
705 | |
706 // We have a heap so create the methodOop caches before | |
707 // CompactingPermGenGen::initialize_oops() tries to populate them. | |
708 Universe::_finalizer_register_cache = new LatestMethodOopCache(); | |
709 Universe::_loader_addClass_cache = new LatestMethodOopCache(); | |
710 Universe::_reflect_invoke_cache = new ActiveMethodOopsCache(); | |
711 | |
712 if (UseSharedSpaces) { | |
713 | |
714 // Read the data structures supporting the shared spaces (shared | |
715 // system dictionary, symbol table, etc.). After that, access to | |
716 // the file (other than the mapped regions) is no longer needed, and | |
717 // the file is closed. Closing the file does not affect the | |
718 // currently mapped regions. | |
719 | |
720 CompactingPermGenGen::initialize_oops(); | |
721 mapinfo->close(); | |
722 | |
723 } else { | |
724 SymbolTable::create_table(); | |
725 StringTable::create_table(); | |
726 ClassLoader::create_package_info_table(); | |
727 } | |
728 | |
729 return JNI_OK; | |
730 } | |
731 | |
732 jint Universe::initialize_heap() { | |
733 | |
734 if (UseParallelGC) { | |
735 #ifndef SERIALGC | |
736 Universe::_collectedHeap = new ParallelScavengeHeap(); | |
737 #else // SERIALGC | |
738 fatal("UseParallelGC not supported in java kernel vm."); | |
739 #endif // SERIALGC | |
740 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
741 } else if (UseG1GC) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
742 #ifndef SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
743 G1CollectorPolicy* g1p = new G1CollectorPolicy_BestRegionsFirst(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
744 G1CollectedHeap* g1h = new G1CollectedHeap(g1p); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
745 Universe::_collectedHeap = g1h; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
746 #else // SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
747 fatal("UseG1GC not supported in java kernel vm."); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
748 #endif // SERIALGC |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
749 |
0 | 750 } else { |
751 GenCollectorPolicy *gc_policy; | |
752 | |
753 if (UseSerialGC) { | |
754 gc_policy = new MarkSweepPolicy(); | |
755 } else if (UseConcMarkSweepGC) { | |
756 #ifndef SERIALGC | |
757 if (UseAdaptiveSizePolicy) { | |
758 gc_policy = new ASConcurrentMarkSweepPolicy(); | |
759 } else { | |
760 gc_policy = new ConcurrentMarkSweepPolicy(); | |
761 } | |
762 #else // SERIALGC | |
763 fatal("UseConcMarkSweepGC not supported in java kernel vm."); | |
764 #endif // SERIALGC | |
765 } else { // default old generation | |
766 gc_policy = new MarkSweepPolicy(); | |
767 } | |
768 | |
769 Universe::_collectedHeap = new GenCollectedHeap(gc_policy); | |
770 } | |
771 | |
772 jint status = Universe::heap()->initialize(); | |
773 if (status != JNI_OK) { | |
774 return status; | |
775 } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
776 if (UseCompressedOops) { |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
777 // Subtract a page because something can get allocated at heap base. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
778 // This also makes implicit null checking work, because the |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
779 // memory+1 page below heap_base needs to cause a signal. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
780 // See needs_explicit_null_check. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
781 // Only set the heap base for compressed oops because it indicates |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
782 // compressed oops for pstack code. |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
783 Universe::_heap_base = Universe::heap()->base() - os::vm_page_size(); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
0
diff
changeset
|
784 } |
0 | 785 |
786 // We will never reach the CATCH below since Exceptions::_throw will cause | |
787 // the VM to exit if an exception is thrown during initialization | |
788 | |
789 if (UseTLAB) { | |
790 assert(Universe::heap()->supports_tlab_allocation(), | |
791 "Should support thread-local allocation buffers"); | |
792 ThreadLocalAllocBuffer::startup_initialization(); | |
793 } | |
794 return JNI_OK; | |
795 } | |
796 | |
797 // It's the caller's repsonsibility to ensure glitch-freedom | |
798 // (if required). | |
799 void Universe::update_heap_info_at_gc() { | |
800 _heap_capacity_at_last_gc = heap()->capacity(); | |
801 _heap_used_at_last_gc = heap()->used(); | |
802 } | |
803 | |
804 | |
805 | |
806 void universe2_init() { | |
807 EXCEPTION_MARK; | |
808 Universe::genesis(CATCH); | |
809 // Although we'd like to verify here that the state of the heap | |
810 // is good, we can't because the main thread has not yet added | |
811 // itself to the threads list (so, using current interfaces | |
812 // we can't "fill" its TLAB), unless TLABs are disabled. | |
813 if (VerifyBeforeGC && !UseTLAB && | |
814 Universe::heap()->total_collections() >= VerifyGCStartAt) { | |
815 Universe::heap()->prepare_for_verify(); | |
816 Universe::verify(); // make sure we're starting with a clean slate | |
817 } | |
818 } | |
819 | |
820 | |
821 // This function is defined in JVM.cpp | |
822 extern void initialize_converter_functions(); | |
823 | |
824 bool universe_post_init() { | |
825 Universe::_fully_initialized = true; | |
826 EXCEPTION_MARK; | |
827 { ResourceMark rm; | |
828 Interpreter::initialize(); // needed for interpreter entry points | |
829 if (!UseSharedSpaces) { | |
830 KlassHandle ok_h(THREAD, SystemDictionary::object_klass()); | |
831 Universe::reinitialize_vtable_of(ok_h, CHECK_false); | |
832 Universe::reinitialize_itables(CHECK_false); | |
833 } | |
834 } | |
835 | |
836 klassOop k; | |
837 instanceKlassHandle k_h; | |
838 if (!UseSharedSpaces) { | |
839 // Setup preallocated empty java.lang.Class array | |
840 Universe::_the_empty_class_klass_array = oopFactory::new_objArray(SystemDictionary::class_klass(), 0, CHECK_false); | |
841 // Setup preallocated OutOfMemoryError errors | |
842 k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_OutOfMemoryError(), true, CHECK_false); | |
843 k_h = instanceKlassHandle(THREAD, k); | |
844 Universe::_out_of_memory_error_java_heap = k_h->allocate_permanent_instance(CHECK_false); | |
845 Universe::_out_of_memory_error_perm_gen = k_h->allocate_permanent_instance(CHECK_false); | |
846 Universe::_out_of_memory_error_array_size = k_h->allocate_permanent_instance(CHECK_false); | |
847 Universe::_out_of_memory_error_gc_overhead_limit = | |
848 k_h->allocate_permanent_instance(CHECK_false); | |
849 | |
850 // Setup preallocated NullPointerException | |
851 // (this is currently used for a cheap & dirty solution in compiler exception handling) | |
852 k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_NullPointerException(), true, CHECK_false); | |
853 Universe::_null_ptr_exception_instance = instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | |
854 // Setup preallocated ArithmeticException | |
855 // (this is currently used for a cheap & dirty solution in compiler exception handling) | |
856 k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_ArithmeticException(), true, CHECK_false); | |
857 Universe::_arithmetic_exception_instance = instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | |
858 // Virtual Machine Error for when we get into a situation we can't resolve | |
859 k = SystemDictionary::resolve_or_fail( | |
860 vmSymbolHandles::java_lang_VirtualMachineError(), true, CHECK_false); | |
861 bool linked = instanceKlass::cast(k)->link_class_or_fail(CHECK_false); | |
862 if (!linked) { | |
863 tty->print_cr("Unable to link/verify VirtualMachineError class"); | |
864 return false; // initialization failed | |
865 } | |
866 Universe::_virtual_machine_error_instance = | |
867 instanceKlass::cast(k)->allocate_permanent_instance(CHECK_false); | |
868 } | |
869 if (!DumpSharedSpaces) { | |
870 // These are the only Java fields that are currently set during shared space dumping. | |
871 // We prefer to not handle this generally, so we always reinitialize these detail messages. | |
872 Handle msg = java_lang_String::create_from_str("Java heap space", CHECK_false); | |
873 java_lang_Throwable::set_message(Universe::_out_of_memory_error_java_heap, msg()); | |
874 | |
875 msg = java_lang_String::create_from_str("PermGen space", CHECK_false); | |
876 java_lang_Throwable::set_message(Universe::_out_of_memory_error_perm_gen, msg()); | |
877 | |
878 msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK_false); | |
879 java_lang_Throwable::set_message(Universe::_out_of_memory_error_array_size, msg()); | |
880 | |
881 msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK_false); | |
882 java_lang_Throwable::set_message(Universe::_out_of_memory_error_gc_overhead_limit, msg()); | |
883 | |
884 msg = java_lang_String::create_from_str("/ by zero", CHECK_false); | |
885 java_lang_Throwable::set_message(Universe::_arithmetic_exception_instance, msg()); | |
886 | |
887 // Setup the array of errors that have preallocated backtrace | |
888 k = Universe::_out_of_memory_error_java_heap->klass(); | |
889 assert(k->klass_part()->name() == vmSymbols::java_lang_OutOfMemoryError(), "should be out of memory error"); | |
890 k_h = instanceKlassHandle(THREAD, k); | |
891 | |
892 int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0; | |
893 Universe::_preallocated_out_of_memory_error_array = oopFactory::new_objArray(k_h(), len, CHECK_false); | |
894 for (int i=0; i<len; i++) { | |
895 oop err = k_h->allocate_permanent_instance(CHECK_false); | |
896 Handle err_h = Handle(THREAD, err); | |
897 java_lang_Throwable::allocate_backtrace(err_h, CHECK_false); | |
898 Universe::preallocated_out_of_memory_errors()->obj_at_put(i, err_h()); | |
899 } | |
900 Universe::_preallocated_out_of_memory_error_avail_count = (jint)len; | |
901 } | |
902 | |
903 | |
904 // Setup static method for registering finalizers | |
905 // The finalizer klass must be linked before looking up the method, in | |
906 // case it needs to get rewritten. | |
907 instanceKlass::cast(SystemDictionary::finalizer_klass())->link_class(CHECK_false); | |
908 methodOop m = instanceKlass::cast(SystemDictionary::finalizer_klass())->find_method( | |
909 vmSymbols::register_method_name(), | |
910 vmSymbols::register_method_signature()); | |
911 if (m == NULL || !m->is_static()) { | |
912 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), | |
913 "java.lang.ref.Finalizer.register", false); | |
914 } | |
915 Universe::_finalizer_register_cache->init( | |
916 SystemDictionary::finalizer_klass(), m, CHECK_false); | |
917 | |
918 // Resolve on first use and initialize class. | |
919 // Note: No race-condition here, since a resolve will always return the same result | |
920 | |
921 // Setup method for security checks | |
922 k = SystemDictionary::resolve_or_fail(vmSymbolHandles::java_lang_reflect_Method(), true, CHECK_false); | |
923 k_h = instanceKlassHandle(THREAD, k); | |
924 k_h->link_class(CHECK_false); | |
925 m = k_h->find_method(vmSymbols::invoke_name(), vmSymbols::object_array_object_object_signature()); | |
926 if (m == NULL || m->is_static()) { | |
927 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), | |
928 "java.lang.reflect.Method.invoke", false); | |
929 } | |
930 Universe::_reflect_invoke_cache->init(k_h(), m, CHECK_false); | |
931 | |
932 // Setup method for registering loaded classes in class loader vector | |
933 instanceKlass::cast(SystemDictionary::classloader_klass())->link_class(CHECK_false); | |
934 m = instanceKlass::cast(SystemDictionary::classloader_klass())->find_method(vmSymbols::addClass_name(), vmSymbols::class_void_signature()); | |
935 if (m == NULL || m->is_static()) { | |
936 THROW_MSG_(vmSymbols::java_lang_NoSuchMethodException(), | |
937 "java.lang.ClassLoader.addClass", false); | |
938 } | |
939 Universe::_loader_addClass_cache->init( | |
940 SystemDictionary::classloader_klass(), m, CHECK_false); | |
941 | |
942 // The folowing is initializing converter functions for serialization in | |
943 // JVM.cpp. If we clean up the StrictMath code above we may want to find | |
944 // a better solution for this as well. | |
945 initialize_converter_functions(); | |
946 | |
947 // This needs to be done before the first scavenge/gc, since | |
948 // it's an input to soft ref clearing policy. | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
949 { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
950 MutexLocker x(Heap_lock); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
951 Universe::update_heap_info_at_gc(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
952 } |
0 | 953 |
954 // ("weak") refs processing infrastructure initialization | |
955 Universe::heap()->post_initialize(); | |
956 | |
957 GC_locker::unlock(); // allow gc after bootstrapping | |
958 | |
959 MemoryService::set_universe_heap(Universe::_collectedHeap); | |
960 return true; | |
961 } | |
962 | |
963 | |
964 void Universe::compute_base_vtable_size() { | |
965 _base_vtable_size = ClassLoader::compute_Object_vtable(); | |
966 } | |
967 | |
968 | |
969 // %%% The Universe::flush_foo methods belong in CodeCache. | |
970 | |
971 // Flushes compiled methods dependent on dependee. | |
972 void Universe::flush_dependents_on(instanceKlassHandle dependee) { | |
973 assert_lock_strong(Compile_lock); | |
974 | |
975 if (CodeCache::number_of_nmethods_with_dependencies() == 0) return; | |
976 | |
977 // CodeCache can only be updated by a thread_in_VM and they will all be | |
978 // stopped dring the safepoint so CodeCache will be safe to update without | |
979 // holding the CodeCache_lock. | |
980 | |
981 DepChange changes(dependee); | |
982 | |
983 // Compute the dependent nmethods | |
984 if (CodeCache::mark_for_deoptimization(changes) > 0) { | |
985 // At least one nmethod has been marked for deoptimization | |
986 VM_Deoptimize op; | |
987 VMThread::execute(&op); | |
988 } | |
989 } | |
990 | |
991 #ifdef HOTSWAP | |
992 // Flushes compiled methods dependent on dependee in the evolutionary sense | |
993 void Universe::flush_evol_dependents_on(instanceKlassHandle ev_k_h) { | |
994 // --- Compile_lock is not held. However we are at a safepoint. | |
995 assert_locked_or_safepoint(Compile_lock); | |
996 if (CodeCache::number_of_nmethods_with_dependencies() == 0) return; | |
997 | |
998 // CodeCache can only be updated by a thread_in_VM and they will all be | |
999 // stopped dring the safepoint so CodeCache will be safe to update without | |
1000 // holding the CodeCache_lock. | |
1001 | |
1002 // Compute the dependent nmethods | |
1003 if (CodeCache::mark_for_evol_deoptimization(ev_k_h) > 0) { | |
1004 // At least one nmethod has been marked for deoptimization | |
1005 | |
1006 // All this already happens inside a VM_Operation, so we'll do all the work here. | |
1007 // Stuff copied from VM_Deoptimize and modified slightly. | |
1008 | |
1009 // We do not want any GCs to happen while we are in the middle of this VM operation | |
1010 ResourceMark rm; | |
1011 DeoptimizationMarker dm; | |
1012 | |
1013 // Deoptimize all activations depending on marked nmethods | |
1014 Deoptimization::deoptimize_dependents(); | |
1015 | |
1016 // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies) | |
1017 CodeCache::make_marked_nmethods_not_entrant(); | |
1018 } | |
1019 } | |
1020 #endif // HOTSWAP | |
1021 | |
1022 | |
1023 // Flushes compiled methods dependent on dependee | |
1024 void Universe::flush_dependents_on_method(methodHandle m_h) { | |
1025 // --- Compile_lock is not held. However we are at a safepoint. | |
1026 assert_locked_or_safepoint(Compile_lock); | |
1027 | |
1028 // CodeCache can only be updated by a thread_in_VM and they will all be | |
1029 // stopped dring the safepoint so CodeCache will be safe to update without | |
1030 // holding the CodeCache_lock. | |
1031 | |
1032 // Compute the dependent nmethods | |
1033 if (CodeCache::mark_for_deoptimization(m_h()) > 0) { | |
1034 // At least one nmethod has been marked for deoptimization | |
1035 | |
1036 // All this already happens inside a VM_Operation, so we'll do all the work here. | |
1037 // Stuff copied from VM_Deoptimize and modified slightly. | |
1038 | |
1039 // We do not want any GCs to happen while we are in the middle of this VM operation | |
1040 ResourceMark rm; | |
1041 DeoptimizationMarker dm; | |
1042 | |
1043 // Deoptimize all activations depending on marked nmethods | |
1044 Deoptimization::deoptimize_dependents(); | |
1045 | |
1046 // Make the dependent methods not entrant (in VM_Deoptimize they are made zombies) | |
1047 CodeCache::make_marked_nmethods_not_entrant(); | |
1048 } | |
1049 } | |
1050 | |
1051 void Universe::print() { print_on(gclog_or_tty); } | |
1052 | |
1053 void Universe::print_on(outputStream* st) { | |
1054 st->print_cr("Heap"); | |
1055 heap()->print_on(st); | |
1056 } | |
1057 | |
1058 void Universe::print_heap_at_SIGBREAK() { | |
1059 if (PrintHeapAtSIGBREAK) { | |
1060 MutexLocker hl(Heap_lock); | |
1061 print_on(tty); | |
1062 tty->cr(); | |
1063 tty->flush(); | |
1064 } | |
1065 } | |
1066 | |
1067 void Universe::print_heap_before_gc(outputStream* st) { | |
1068 st->print_cr("{Heap before GC invocations=%u (full %u):", | |
1069 heap()->total_collections(), | |
1070 heap()->total_full_collections()); | |
1071 heap()->print_on(st); | |
1072 } | |
1073 | |
1074 void Universe::print_heap_after_gc(outputStream* st) { | |
1075 st->print_cr("Heap after GC invocations=%u (full %u):", | |
1076 heap()->total_collections(), | |
1077 heap()->total_full_collections()); | |
1078 heap()->print_on(st); | |
1079 st->print_cr("}"); | |
1080 } | |
1081 | |
1082 void Universe::verify(bool allow_dirty, bool silent) { | |
1083 if (SharedSkipVerify) { | |
1084 return; | |
1085 } | |
1086 | |
1087 // The use of _verify_in_progress is a temporary work around for | |
1088 // 6320749. Don't bother with a creating a class to set and clear | |
1089 // it since it is only used in this method and the control flow is | |
1090 // straight forward. | |
1091 _verify_in_progress = true; | |
1092 | |
1093 COMPILER2_PRESENT( | |
1094 assert(!DerivedPointerTable::is_active(), | |
1095 "DPT should not be active during verification " | |
1096 "(of thread stacks below)"); | |
1097 ) | |
1098 | |
1099 ResourceMark rm; | |
1100 HandleMark hm; // Handles created during verification can be zapped | |
1101 _verify_count++; | |
1102 | |
1103 if (!silent) gclog_or_tty->print("[Verifying "); | |
1104 if (!silent) gclog_or_tty->print("threads "); | |
1105 Threads::verify(); | |
1106 heap()->verify(allow_dirty, silent); | |
1107 | |
1108 if (!silent) gclog_or_tty->print("syms "); | |
1109 SymbolTable::verify(); | |
1110 if (!silent) gclog_or_tty->print("strs "); | |
1111 StringTable::verify(); | |
1112 { | |
1113 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); | |
1114 if (!silent) gclog_or_tty->print("zone "); | |
1115 CodeCache::verify(); | |
1116 } | |
1117 if (!silent) gclog_or_tty->print("dict "); | |
1118 SystemDictionary::verify(); | |
1119 if (!silent) gclog_or_tty->print("hand "); | |
1120 JNIHandles::verify(); | |
1121 if (!silent) gclog_or_tty->print("C-heap "); | |
1122 os::check_heap(); | |
1123 if (!silent) gclog_or_tty->print_cr("]"); | |
1124 | |
1125 _verify_in_progress = false; | |
1126 } | |
1127 | |
1128 // Oop verification (see MacroAssembler::verify_oop) | |
1129 | |
1130 static uintptr_t _verify_oop_data[2] = {0, (uintptr_t)-1}; | |
1131 static uintptr_t _verify_klass_data[2] = {0, (uintptr_t)-1}; | |
1132 | |
1133 | |
1134 static void calculate_verify_data(uintptr_t verify_data[2], | |
1135 HeapWord* low_boundary, | |
1136 HeapWord* high_boundary) { | |
1137 assert(low_boundary < high_boundary, "bad interval"); | |
1138 | |
1139 // decide which low-order bits we require to be clear: | |
1140 size_t alignSize = MinObjAlignmentInBytes; | |
1141 size_t min_object_size = oopDesc::header_size(); | |
1142 | |
1143 // make an inclusive limit: | |
1144 uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize; | |
1145 uintptr_t min = (uintptr_t)low_boundary; | |
1146 assert(min < max, "bad interval"); | |
1147 uintptr_t diff = max ^ min; | |
1148 | |
1149 // throw away enough low-order bits to make the diff vanish | |
1150 uintptr_t mask = (uintptr_t)(-1); | |
1151 while ((mask & diff) != 0) | |
1152 mask <<= 1; | |
1153 uintptr_t bits = (min & mask); | |
1154 assert(bits == (max & mask), "correct mask"); | |
1155 // check an intermediate value between min and max, just to make sure: | |
1156 assert(bits == ((min + (max-min)/2) & mask), "correct mask"); | |
1157 | |
1158 // require address alignment, too: | |
1159 mask |= (alignSize - 1); | |
1160 | |
1161 if (!(verify_data[0] == 0 && verify_data[1] == (uintptr_t)-1)) { | |
1162 assert(verify_data[0] == mask && verify_data[1] == bits, "mask stability"); | |
1163 } | |
1164 verify_data[0] = mask; | |
1165 verify_data[1] = bits; | |
1166 } | |
1167 | |
1168 | |
1169 // Oop verification (see MacroAssembler::verify_oop) | |
1170 #ifndef PRODUCT | |
1171 | |
1172 uintptr_t Universe::verify_oop_mask() { | |
1173 MemRegion m = heap()->reserved_region(); | |
1174 calculate_verify_data(_verify_oop_data, | |
1175 m.start(), | |
1176 m.end()); | |
1177 return _verify_oop_data[0]; | |
1178 } | |
1179 | |
1180 | |
1181 | |
1182 uintptr_t Universe::verify_oop_bits() { | |
1183 verify_oop_mask(); | |
1184 return _verify_oop_data[1]; | |
1185 } | |
1186 | |
1187 | |
1188 uintptr_t Universe::verify_klass_mask() { | |
1189 /* $$$ | |
1190 // A klass can never live in the new space. Since the new and old | |
1191 // spaces can change size, we must settle for bounds-checking against | |
1192 // the bottom of the world, plus the smallest possible new and old | |
1193 // space sizes that may arise during execution. | |
1194 size_t min_new_size = Universe::new_size(); // in bytes | |
1195 size_t min_old_size = Universe::old_size(); // in bytes | |
1196 calculate_verify_data(_verify_klass_data, | |
1197 (HeapWord*)((uintptr_t)_new_gen->low_boundary + min_new_size + min_old_size), | |
1198 _perm_gen->high_boundary); | |
1199 */ | |
1200 // Why doesn't the above just say that klass's always live in the perm | |
1201 // gen? I'll see if that seems to work... | |
1202 MemRegion permanent_reserved; | |
1203 switch (Universe::heap()->kind()) { | |
1204 default: | |
1205 // ???: What if a CollectedHeap doesn't have a permanent generation? | |
1206 ShouldNotReachHere(); | |
1207 break; | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1208 case CollectedHeap::GenCollectedHeap: |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1209 case CollectedHeap::G1CollectedHeap: { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1210 SharedHeap* sh = (SharedHeap*) Universe::heap(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1211 permanent_reserved = sh->perm_gen()->reserved(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
113
diff
changeset
|
1212 break; |
0 | 1213 } |
1214 #ifndef SERIALGC | |
1215 case CollectedHeap::ParallelScavengeHeap: { | |
1216 ParallelScavengeHeap* psh = (ParallelScavengeHeap*) Universe::heap(); | |
1217 permanent_reserved = psh->perm_gen()->reserved(); | |
1218 break; | |
1219 } | |
1220 #endif // SERIALGC | |
1221 } | |
1222 calculate_verify_data(_verify_klass_data, | |
1223 permanent_reserved.start(), | |
1224 permanent_reserved.end()); | |
1225 | |
1226 return _verify_klass_data[0]; | |
1227 } | |
1228 | |
1229 | |
1230 | |
1231 uintptr_t Universe::verify_klass_bits() { | |
1232 verify_klass_mask(); | |
1233 return _verify_klass_data[1]; | |
1234 } | |
1235 | |
1236 | |
1237 uintptr_t Universe::verify_mark_mask() { | |
1238 return markOopDesc::lock_mask_in_place; | |
1239 } | |
1240 | |
1241 | |
1242 | |
1243 uintptr_t Universe::verify_mark_bits() { | |
1244 intptr_t mask = verify_mark_mask(); | |
1245 intptr_t bits = (intptr_t)markOopDesc::prototype(); | |
1246 assert((bits & ~mask) == 0, "no stray header bits"); | |
1247 return bits; | |
1248 } | |
1249 #endif // PRODUCT | |
1250 | |
1251 | |
1252 void Universe::compute_verify_oop_data() { | |
1253 verify_oop_mask(); | |
1254 verify_oop_bits(); | |
1255 verify_mark_mask(); | |
1256 verify_mark_bits(); | |
1257 verify_klass_mask(); | |
1258 verify_klass_bits(); | |
1259 } | |
1260 | |
1261 | |
1262 void CommonMethodOopCache::init(klassOop k, methodOop m, TRAPS) { | |
1263 if (!UseSharedSpaces) { | |
1264 _klass = k; | |
1265 } | |
1266 #ifndef PRODUCT | |
1267 else { | |
1268 // sharing initilization should have already set up _klass | |
1269 assert(_klass != NULL, "just checking"); | |
1270 } | |
1271 #endif | |
1272 | |
1273 _method_idnum = m->method_idnum(); | |
1274 assert(_method_idnum >= 0, "sanity check"); | |
1275 } | |
1276 | |
1277 | |
1278 ActiveMethodOopsCache::~ActiveMethodOopsCache() { | |
1279 if (_prev_methods != NULL) { | |
1280 for (int i = _prev_methods->length() - 1; i >= 0; i--) { | |
1281 jweak method_ref = _prev_methods->at(i); | |
1282 if (method_ref != NULL) { | |
1283 JNIHandles::destroy_weak_global(method_ref); | |
1284 } | |
1285 } | |
1286 delete _prev_methods; | |
1287 _prev_methods = NULL; | |
1288 } | |
1289 } | |
1290 | |
1291 | |
1292 void ActiveMethodOopsCache::add_previous_version(const methodOop method) { | |
1293 assert(Thread::current()->is_VM_thread(), | |
1294 "only VMThread can add previous versions"); | |
1295 | |
1296 if (_prev_methods == NULL) { | |
1297 // This is the first previous version so make some space. | |
1298 // Start with 2 elements under the assumption that the class | |
1299 // won't be redefined much. | |
1300 _prev_methods = new (ResourceObj::C_HEAP) GrowableArray<jweak>(2, true); | |
1301 } | |
1302 | |
1303 // RC_TRACE macro has an embedded ResourceMark | |
1304 RC_TRACE(0x00000100, | |
1305 ("add: %s(%s): adding prev version ref for cached method @%d", | |
1306 method->name()->as_C_string(), method->signature()->as_C_string(), | |
1307 _prev_methods->length())); | |
1308 | |
1309 methodHandle method_h(method); | |
1310 jweak method_ref = JNIHandles::make_weak_global(method_h); | |
1311 _prev_methods->append(method_ref); | |
1312 | |
1313 // Using weak references allows previous versions of the cached | |
1314 // method to be GC'ed when they are no longer needed. Since the | |
1315 // caller is the VMThread and we are at a safepoint, this is a good | |
1316 // time to clear out unused weak references. | |
1317 | |
1318 for (int i = _prev_methods->length() - 1; i >= 0; i--) { | |
1319 jweak method_ref = _prev_methods->at(i); | |
1320 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); | |
1321 if (method_ref == NULL) { | |
1322 _prev_methods->remove_at(i); | |
1323 // Since we are traversing the array backwards, we don't have to | |
1324 // do anything special with the index. | |
1325 continue; // robustness | |
1326 } | |
1327 | |
1328 methodOop m = (methodOop)JNIHandles::resolve(method_ref); | |
1329 if (m == NULL) { | |
1330 // this method entry has been GC'ed so remove it | |
1331 JNIHandles::destroy_weak_global(method_ref); | |
1332 _prev_methods->remove_at(i); | |
1333 } else { | |
1334 // RC_TRACE macro has an embedded ResourceMark | |
1335 RC_TRACE(0x00000400, ("add: %s(%s): previous cached method @%d is alive", | |
1336 m->name()->as_C_string(), m->signature()->as_C_string(), i)); | |
1337 } | |
1338 } | |
1339 } // end add_previous_version() | |
1340 | |
1341 | |
1342 bool ActiveMethodOopsCache::is_same_method(const methodOop method) const { | |
1343 instanceKlass* ik = instanceKlass::cast(klass()); | |
1344 methodOop check_method = ik->method_with_idnum(method_idnum()); | |
1345 assert(check_method != NULL, "sanity check"); | |
1346 if (check_method == method) { | |
1347 // done with the easy case | |
1348 return true; | |
1349 } | |
1350 | |
1351 if (_prev_methods != NULL) { | |
1352 // The cached method has been redefined at least once so search | |
1353 // the previous versions for a match. | |
1354 for (int i = 0; i < _prev_methods->length(); i++) { | |
1355 jweak method_ref = _prev_methods->at(i); | |
1356 assert(method_ref != NULL, "weak method ref was unexpectedly cleared"); | |
1357 if (method_ref == NULL) { | |
1358 continue; // robustness | |
1359 } | |
1360 | |
1361 check_method = (methodOop)JNIHandles::resolve(method_ref); | |
1362 if (check_method == method) { | |
1363 // a previous version matches | |
1364 return true; | |
1365 } | |
1366 } | |
1367 } | |
1368 | |
1369 // either no previous versions or no previous version matched | |
1370 return false; | |
1371 } | |
1372 | |
1373 | |
1374 methodOop LatestMethodOopCache::get_methodOop() { | |
1375 instanceKlass* ik = instanceKlass::cast(klass()); | |
1376 methodOop m = ik->method_with_idnum(method_idnum()); | |
1377 assert(m != NULL, "sanity check"); | |
1378 return m; | |
1379 } | |
1380 | |
1381 | |
1382 #ifdef ASSERT | |
1383 // Release dummy object(s) at bottom of heap | |
1384 bool Universe::release_fullgc_alot_dummy() { | |
1385 MutexLocker ml(FullGCALot_lock); | |
1386 if (_fullgc_alot_dummy_array != NULL) { | |
1387 if (_fullgc_alot_dummy_next >= _fullgc_alot_dummy_array->length()) { | |
1388 // No more dummies to release, release entire array instead | |
1389 _fullgc_alot_dummy_array = NULL; | |
1390 return false; | |
1391 } | |
1392 if (!UseConcMarkSweepGC) { | |
1393 // Release dummy at bottom of old generation | |
1394 _fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL); | |
1395 } | |
1396 // Release dummy at bottom of permanent generation | |
1397 _fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL); | |
1398 } | |
1399 return true; | |
1400 } | |
1401 | |
1402 #endif // ASSERT |