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