Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/memory/universe.cpp
40949 views
1
/*
2
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "cds/heapShared.hpp"
27
#include "cds/metaspaceShared.hpp"
28
#include "classfile/classLoader.hpp"
29
#include "classfile/classLoaderDataGraph.hpp"
30
#include "classfile/javaClasses.hpp"
31
#include "classfile/stringTable.hpp"
32
#include "classfile/symbolTable.hpp"
33
#include "classfile/systemDictionary.hpp"
34
#include "classfile/vmClasses.hpp"
35
#include "classfile/vmSymbols.hpp"
36
#include "code/codeBehaviours.hpp"
37
#include "code/codeCache.hpp"
38
#include "compiler/oopMap.hpp"
39
#include "gc/shared/collectedHeap.inline.hpp"
40
#include "gc/shared/gcArguments.hpp"
41
#include "gc/shared/gcConfig.hpp"
42
#include "gc/shared/gcLogPrecious.hpp"
43
#include "gc/shared/gcTraceTime.inline.hpp"
44
#include "gc/shared/oopStorageSet.hpp"
45
#include "gc/shared/stringdedup/stringDedup.hpp"
46
#include "gc/shared/tlab_globals.hpp"
47
#include "logging/log.hpp"
48
#include "logging/logStream.hpp"
49
#include "memory/metadataFactory.hpp"
50
#include "memory/metaspaceClosure.hpp"
51
#include "memory/metaspaceCounters.hpp"
52
#include "memory/metaspaceUtils.hpp"
53
#include "memory/oopFactory.hpp"
54
#include "memory/resourceArea.hpp"
55
#include "memory/universe.hpp"
56
#include "oops/compressedOops.hpp"
57
#include "oops/instanceKlass.hpp"
58
#include "oops/instanceMirrorKlass.hpp"
59
#include "oops/klass.inline.hpp"
60
#include "oops/objArrayOop.inline.hpp"
61
#include "oops/oop.inline.hpp"
62
#include "oops/oopHandle.inline.hpp"
63
#include "oops/typeArrayKlass.hpp"
64
#include "prims/resolvedMethodTable.hpp"
65
#include "runtime/arguments.hpp"
66
#include "runtime/atomic.hpp"
67
#include "runtime/flags/jvmFlagLimit.hpp"
68
#include "runtime/handles.inline.hpp"
69
#include "runtime/init.hpp"
70
#include "runtime/java.hpp"
71
#include "runtime/jniHandles.hpp"
72
#include "runtime/thread.inline.hpp"
73
#include "runtime/timerTrace.hpp"
74
#include "services/memoryService.hpp"
75
#include "utilities/align.hpp"
76
#include "utilities/autoRestore.hpp"
77
#include "utilities/debug.hpp"
78
#include "utilities/formatBuffer.hpp"
79
#include "utilities/macros.hpp"
80
#include "utilities/ostream.hpp"
81
#include "utilities/preserveException.hpp"
82
83
// Known objects
84
Klass* Universe::_typeArrayKlassObjs[T_LONG+1] = { NULL /*, NULL...*/ };
85
Klass* Universe::_objectArrayKlassObj = NULL;
86
OopHandle Universe::_mirrors[T_VOID+1];
87
88
OopHandle Universe::_main_thread_group;
89
OopHandle Universe::_system_thread_group;
90
OopHandle Universe::_the_empty_class_array;
91
OopHandle Universe::_the_null_string;
92
OopHandle Universe::_the_min_jint_string;
93
94
OopHandle Universe::_the_null_sentinel;
95
96
// _out_of_memory_errors is an objArray
97
enum OutOfMemoryInstance { _oom_java_heap,
98
_oom_c_heap,
99
_oom_metaspace,
100
_oom_class_metaspace,
101
_oom_array_size,
102
_oom_gc_overhead_limit,
103
_oom_realloc_objects,
104
_oom_retry,
105
_oom_count };
106
107
OopHandle Universe::_out_of_memory_errors;
108
OopHandle Universe::_delayed_stack_overflow_error_message;
109
OopHandle Universe::_preallocated_out_of_memory_error_array;
110
volatile jint Universe::_preallocated_out_of_memory_error_avail_count = 0;
111
112
OopHandle Universe::_null_ptr_exception_instance;
113
OopHandle Universe::_arithmetic_exception_instance;
114
OopHandle Universe::_virtual_machine_error_instance;
115
116
OopHandle Universe::_reference_pending_list;
117
118
Array<Klass*>* Universe::_the_array_interfaces_array = NULL;
119
LatestMethodCache* Universe::_finalizer_register_cache = NULL;
120
LatestMethodCache* Universe::_loader_addClass_cache = NULL;
121
LatestMethodCache* Universe::_throw_illegal_access_error_cache = NULL;
122
LatestMethodCache* Universe::_throw_no_such_method_error_cache = NULL;
123
LatestMethodCache* Universe::_do_stack_walk_cache = NULL;
124
125
bool Universe::_verify_in_progress = false;
126
long Universe::verify_flags = Universe::Verify_All;
127
128
Array<int>* Universe::_the_empty_int_array = NULL;
129
Array<u2>* Universe::_the_empty_short_array = NULL;
130
Array<Klass*>* Universe::_the_empty_klass_array = NULL;
131
Array<InstanceKlass*>* Universe::_the_empty_instance_klass_array = NULL;
132
Array<Method*>* Universe::_the_empty_method_array = NULL;
133
134
// These variables are guarded by FullGCALot_lock.
135
debug_only(OopHandle Universe::_fullgc_alot_dummy_array;)
136
debug_only(int Universe::_fullgc_alot_dummy_next = 0;)
137
138
// Heap
139
int Universe::_verify_count = 0;
140
141
// Oop verification (see MacroAssembler::verify_oop)
142
uintptr_t Universe::_verify_oop_mask = 0;
143
uintptr_t Universe::_verify_oop_bits = (uintptr_t) -1;
144
145
int Universe::_base_vtable_size = 0;
146
bool Universe::_bootstrapping = false;
147
bool Universe::_module_initialized = false;
148
bool Universe::_fully_initialized = false;
149
150
OopStorage* Universe::_vm_weak = NULL;
151
OopStorage* Universe::_vm_global = NULL;
152
153
CollectedHeap* Universe::_collectedHeap = NULL;
154
155
objArrayOop Universe::the_empty_class_array () {
156
return (objArrayOop)_the_empty_class_array.resolve();
157
}
158
159
oop Universe::main_thread_group() { return _main_thread_group.resolve(); }
160
void Universe::set_main_thread_group(oop group) { _main_thread_group = OopHandle(vm_global(), group); }
161
162
oop Universe::system_thread_group() { return _system_thread_group.resolve(); }
163
void Universe::set_system_thread_group(oop group) { _system_thread_group = OopHandle(vm_global(), group); }
164
165
oop Universe::the_null_string() { return _the_null_string.resolve(); }
166
oop Universe::the_min_jint_string() { return _the_min_jint_string.resolve(); }
167
168
oop Universe::null_ptr_exception_instance() { return _null_ptr_exception_instance.resolve(); }
169
oop Universe::arithmetic_exception_instance() { return _arithmetic_exception_instance.resolve(); }
170
oop Universe::virtual_machine_error_instance() { return _virtual_machine_error_instance.resolve(); }
171
172
oop Universe::the_null_sentinel() { return _the_null_sentinel.resolve(); }
173
174
oop Universe::int_mirror() { return check_mirror(_mirrors[T_INT].resolve()); }
175
oop Universe::float_mirror() { return check_mirror(_mirrors[T_FLOAT].resolve()); }
176
oop Universe::double_mirror() { return check_mirror(_mirrors[T_DOUBLE].resolve()); }
177
oop Universe::byte_mirror() { return check_mirror(_mirrors[T_BYTE].resolve()); }
178
oop Universe::bool_mirror() { return check_mirror(_mirrors[T_BOOLEAN].resolve()); }
179
oop Universe::char_mirror() { return check_mirror(_mirrors[T_CHAR].resolve()); }
180
oop Universe::long_mirror() { return check_mirror(_mirrors[T_LONG].resolve()); }
181
oop Universe::short_mirror() { return check_mirror(_mirrors[T_SHORT].resolve()); }
182
oop Universe::void_mirror() { return check_mirror(_mirrors[T_VOID].resolve()); }
183
184
oop Universe::java_mirror(BasicType t) {
185
assert((uint)t < T_VOID+1, "range check");
186
return check_mirror(_mirrors[t].resolve());
187
}
188
189
// Used by CDS dumping
190
void Universe::replace_mirror(BasicType t, oop new_mirror) {
191
Universe::_mirrors[t].replace(new_mirror);
192
}
193
194
void Universe::basic_type_classes_do(void f(Klass*)) {
195
for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
196
f(_typeArrayKlassObjs[i]);
197
}
198
}
199
200
void Universe::basic_type_classes_do(KlassClosure *closure) {
201
for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
202
closure->do_klass(_typeArrayKlassObjs[i]);
203
}
204
}
205
206
void LatestMethodCache::metaspace_pointers_do(MetaspaceClosure* it) {
207
it->push(&_klass);
208
}
209
210
void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
211
for (int i = 0; i < T_LONG+1; i++) {
212
it->push(&_typeArrayKlassObjs[i]);
213
}
214
it->push(&_objectArrayKlassObj);
215
216
it->push(&_the_empty_int_array);
217
it->push(&_the_empty_short_array);
218
it->push(&_the_empty_klass_array);
219
it->push(&_the_empty_instance_klass_array);
220
it->push(&_the_empty_method_array);
221
it->push(&_the_array_interfaces_array);
222
223
_finalizer_register_cache->metaspace_pointers_do(it);
224
_loader_addClass_cache->metaspace_pointers_do(it);
225
_throw_illegal_access_error_cache->metaspace_pointers_do(it);
226
_throw_no_such_method_error_cache->metaspace_pointers_do(it);
227
_do_stack_walk_cache->metaspace_pointers_do(it);
228
}
229
230
// Serialize metadata and pointers to primitive type mirrors in and out of CDS archive
231
void Universe::serialize(SerializeClosure* f) {
232
233
#if INCLUDE_CDS_JAVA_HEAP
234
{
235
oop mirror_oop;
236
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
237
if (f->reading()) {
238
f->do_oop(&mirror_oop); // read from archive
239
assert(oopDesc::is_oop_or_null(mirror_oop), "is oop");
240
// Only create an OopHandle for non-null mirrors
241
if (mirror_oop != NULL) {
242
_mirrors[i] = OopHandle(vm_global(), mirror_oop);
243
}
244
} else {
245
if (HeapShared::is_heap_object_archiving_allowed()) {
246
mirror_oop = _mirrors[i].resolve();
247
} else {
248
mirror_oop = NULL;
249
}
250
f->do_oop(&mirror_oop); // write to archive
251
}
252
if (mirror_oop != NULL) { // may be null if archived heap is disabled
253
java_lang_Class::update_archived_primitive_mirror_native_pointers(mirror_oop);
254
}
255
}
256
}
257
#endif
258
259
for (int i = 0; i < T_LONG+1; i++) {
260
f->do_ptr((void**)&_typeArrayKlassObjs[i]);
261
}
262
263
f->do_ptr((void**)&_objectArrayKlassObj);
264
f->do_ptr((void**)&_the_array_interfaces_array);
265
f->do_ptr((void**)&_the_empty_int_array);
266
f->do_ptr((void**)&_the_empty_short_array);
267
f->do_ptr((void**)&_the_empty_method_array);
268
f->do_ptr((void**)&_the_empty_klass_array);
269
f->do_ptr((void**)&_the_empty_instance_klass_array);
270
_finalizer_register_cache->serialize(f);
271
_loader_addClass_cache->serialize(f);
272
_throw_illegal_access_error_cache->serialize(f);
273
_throw_no_such_method_error_cache->serialize(f);
274
_do_stack_walk_cache->serialize(f);
275
}
276
277
278
void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
279
if (size < alignment || size % alignment != 0) {
280
vm_exit_during_initialization(
281
err_msg("Size of %s (" UINTX_FORMAT " bytes) must be aligned to " UINTX_FORMAT " bytes", name, size, alignment));
282
}
283
}
284
285
void initialize_basic_type_klass(Klass* k, TRAPS) {
286
Klass* ok = vmClasses::Object_klass();
287
#if INCLUDE_CDS
288
if (UseSharedSpaces) {
289
ClassLoaderData* loader_data = ClassLoaderData::the_null_class_loader_data();
290
assert(k->super() == ok, "u3");
291
if (k->is_instance_klass()) {
292
InstanceKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), NULL, CHECK);
293
} else {
294
ArrayKlass::cast(k)->restore_unshareable_info(loader_data, Handle(), CHECK);
295
}
296
} else
297
#endif
298
{
299
k->initialize_supers(ok, NULL, CHECK);
300
}
301
k->append_to_sibling_list();
302
}
303
304
void Universe::genesis(TRAPS) {
305
ResourceMark rm(THREAD);
306
HandleMark hm(THREAD);
307
308
{ AutoModifyRestore<bool> temporarily(_bootstrapping, true);
309
310
{ MutexLocker mc(THREAD, Compile_lock);
311
312
java_lang_Class::allocate_fixup_lists();
313
314
// determine base vtable size; without that we cannot create the array klasses
315
compute_base_vtable_size();
316
317
if (!UseSharedSpaces) {
318
for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
319
_typeArrayKlassObjs[i] = TypeArrayKlass::create_klass((BasicType)i, CHECK);
320
}
321
322
ClassLoaderData* null_cld = ClassLoaderData::the_null_class_loader_data();
323
324
_the_array_interfaces_array = MetadataFactory::new_array<Klass*>(null_cld, 2, NULL, CHECK);
325
_the_empty_int_array = MetadataFactory::new_array<int>(null_cld, 0, CHECK);
326
_the_empty_short_array = MetadataFactory::new_array<u2>(null_cld, 0, CHECK);
327
_the_empty_method_array = MetadataFactory::new_array<Method*>(null_cld, 0, CHECK);
328
_the_empty_klass_array = MetadataFactory::new_array<Klass*>(null_cld, 0, CHECK);
329
_the_empty_instance_klass_array = MetadataFactory::new_array<InstanceKlass*>(null_cld, 0, CHECK);
330
}
331
}
332
333
vmSymbols::initialize();
334
335
SystemDictionary::initialize(CHECK);
336
337
// Create string constants
338
oop s = StringTable::intern("null", CHECK);
339
_the_null_string = OopHandle(vm_global(), s);
340
s = StringTable::intern("-2147483648", CHECK);
341
_the_min_jint_string = OopHandle(vm_global(), s);
342
343
344
#if INCLUDE_CDS
345
if (UseSharedSpaces) {
346
// Verify shared interfaces array.
347
assert(_the_array_interfaces_array->at(0) ==
348
vmClasses::Cloneable_klass(), "u3");
349
assert(_the_array_interfaces_array->at(1) ==
350
vmClasses::Serializable_klass(), "u3");
351
} else
352
#endif
353
{
354
// Set up shared interfaces array. (Do this before supers are set up.)
355
_the_array_interfaces_array->at_put(0, vmClasses::Cloneable_klass());
356
_the_array_interfaces_array->at_put(1, vmClasses::Serializable_klass());
357
}
358
359
initialize_basic_type_klass(boolArrayKlassObj(), CHECK);
360
initialize_basic_type_klass(charArrayKlassObj(), CHECK);
361
initialize_basic_type_klass(floatArrayKlassObj(), CHECK);
362
initialize_basic_type_klass(doubleArrayKlassObj(), CHECK);
363
initialize_basic_type_klass(byteArrayKlassObj(), CHECK);
364
initialize_basic_type_klass(shortArrayKlassObj(), CHECK);
365
initialize_basic_type_klass(intArrayKlassObj(), CHECK);
366
initialize_basic_type_klass(longArrayKlassObj(), CHECK);
367
} // end of core bootstrapping
368
369
{
370
Handle tns = java_lang_String::create_from_str("<null_sentinel>", CHECK);
371
_the_null_sentinel = OopHandle(vm_global(), tns());
372
}
373
374
// Create a handle for reference_pending_list
375
_reference_pending_list = OopHandle(vm_global(), NULL);
376
377
// Maybe this could be lifted up now that object array can be initialized
378
// during the bootstrapping.
379
380
// OLD
381
// Initialize _objectArrayKlass after core bootstraping to make
382
// sure the super class is set up properly for _objectArrayKlass.
383
// ---
384
// NEW
385
// Since some of the old system object arrays have been converted to
386
// ordinary object arrays, _objectArrayKlass will be loaded when
387
// SystemDictionary::initialize(CHECK); is run. See the extra check
388
// for Object_klass_loaded in objArrayKlassKlass::allocate_objArray_klass_impl.
389
_objectArrayKlassObj = InstanceKlass::
390
cast(vmClasses::Object_klass())->array_klass(1, CHECK);
391
// OLD
392
// Add the class to the class hierarchy manually to make sure that
393
// its vtable is initialized after core bootstrapping is completed.
394
// ---
395
// New
396
// Have already been initialized.
397
_objectArrayKlassObj->append_to_sibling_list();
398
399
#ifdef ASSERT
400
if (FullGCALot) {
401
// Allocate an array of dummy objects.
402
// We'd like these to be at the bottom of the old generation,
403
// so that when we free one and then collect,
404
// (almost) the whole heap moves
405
// and we find out if we actually update all the oops correctly.
406
// But we can't allocate directly in the old generation,
407
// so we allocate wherever, and hope that the first collection
408
// moves these objects to the bottom of the old generation.
409
int size = FullGCALotDummies * 2;
410
411
objArrayOop naked_array = oopFactory::new_objArray(vmClasses::Object_klass(), size, CHECK);
412
objArrayHandle dummy_array(THREAD, naked_array);
413
int i = 0;
414
while (i < size) {
415
// Allocate dummy in old generation
416
oop dummy = vmClasses::Object_klass()->allocate_instance(CHECK);
417
dummy_array->obj_at_put(i++, dummy);
418
}
419
{
420
// Only modify the global variable inside the mutex.
421
// If we had a race to here, the other dummy_array instances
422
// and their elements just get dropped on the floor, which is fine.
423
MutexLocker ml(THREAD, FullGCALot_lock);
424
if (_fullgc_alot_dummy_array.is_empty()) {
425
_fullgc_alot_dummy_array = OopHandle(vm_global(), dummy_array());
426
}
427
}
428
assert(i == ((objArrayOop)_fullgc_alot_dummy_array.resolve())->length(), "just checking");
429
}
430
#endif
431
}
432
433
void Universe::initialize_basic_type_mirrors(TRAPS) {
434
#if INCLUDE_CDS_JAVA_HEAP
435
if (UseSharedSpaces &&
436
HeapShared::open_archive_heap_region_mapped() &&
437
_mirrors[T_INT].resolve() != NULL) {
438
assert(HeapShared::is_heap_object_archiving_allowed(), "Sanity");
439
440
// check that all mirrors are mapped also
441
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
442
if (!is_reference_type((BasicType)i)) {
443
oop m = _mirrors[i].resolve();
444
assert(m != NULL, "archived mirrors should not be NULL");
445
}
446
}
447
} else
448
// _mirror[T_INT} could be NULL if archived heap is not mapped.
449
#endif
450
{
451
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
452
BasicType bt = (BasicType)i;
453
if (!is_reference_type(bt)) {
454
oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
455
_mirrors[i] = OopHandle(vm_global(), m);
456
}
457
}
458
}
459
}
460
461
void Universe::fixup_mirrors(TRAPS) {
462
// Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly,
463
// but we cannot do that for classes created before java.lang.Class is loaded. Here we simply
464
// walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note
465
// that the number of objects allocated at this point is very small.
466
assert(vmClasses::Class_klass_loaded(), "java.lang.Class should be loaded");
467
HandleMark hm(THREAD);
468
469
if (!UseSharedSpaces) {
470
// Cache the start of the static fields
471
InstanceMirrorKlass::init_offset_of_static_fields();
472
}
473
474
GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list();
475
int list_length = list->length();
476
for (int i = 0; i < list_length; i++) {
477
Klass* k = list->at(i);
478
assert(k->is_klass(), "List should only hold classes");
479
java_lang_Class::fixup_mirror(k, CATCH);
480
}
481
delete java_lang_Class::fixup_mirror_list();
482
java_lang_Class::set_fixup_mirror_list(NULL);
483
}
484
485
#define assert_pll_locked(test) \
486
assert(Heap_lock->test(), "Reference pending list access requires lock")
487
488
#define assert_pll_ownership() assert_pll_locked(owned_by_self)
489
490
oop Universe::reference_pending_list() {
491
if (Thread::current()->is_VM_thread()) {
492
assert_pll_locked(is_locked);
493
} else {
494
assert_pll_ownership();
495
}
496
return _reference_pending_list.resolve();
497
}
498
499
void Universe::clear_reference_pending_list() {
500
assert_pll_ownership();
501
_reference_pending_list.replace(NULL);
502
}
503
504
bool Universe::has_reference_pending_list() {
505
assert_pll_ownership();
506
return _reference_pending_list.peek() != NULL;
507
}
508
509
oop Universe::swap_reference_pending_list(oop list) {
510
assert_pll_locked(is_locked);
511
return _reference_pending_list.xchg(list);
512
}
513
514
#undef assert_pll_locked
515
#undef assert_pll_ownership
516
517
static void reinitialize_vtables() {
518
// The vtables are initialized by starting at java.lang.Object and
519
// initializing through the subclass links, so that the super
520
// classes are always initialized first.
521
for (ClassHierarchyIterator iter(vmClasses::Object_klass()); !iter.done(); iter.next()) {
522
Klass* sub = iter.klass();
523
sub->vtable().initialize_vtable();
524
}
525
}
526
527
528
static void initialize_itable_for_klass(InstanceKlass* k) {
529
k->itable().initialize_itable();
530
}
531
532
533
static void reinitialize_itables() {
534
MutexLocker mcld(ClassLoaderDataGraph_lock);
535
ClassLoaderDataGraph::dictionary_classes_do(initialize_itable_for_klass);
536
}
537
538
539
bool Universe::on_page_boundary(void* addr) {
540
return is_aligned(addr, os::vm_page_size());
541
}
542
543
// the array of preallocated errors with backtraces
544
objArrayOop Universe::preallocated_out_of_memory_errors() {
545
return (objArrayOop)_preallocated_out_of_memory_error_array.resolve();
546
}
547
548
objArrayOop Universe::out_of_memory_errors() { return (objArrayOop)_out_of_memory_errors.resolve(); }
549
550
oop Universe::out_of_memory_error_java_heap() {
551
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_java_heap));
552
}
553
554
oop Universe::out_of_memory_error_c_heap() {
555
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_c_heap));
556
}
557
558
oop Universe::out_of_memory_error_metaspace() {
559
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_metaspace));
560
}
561
562
oop Universe::out_of_memory_error_class_metaspace() {
563
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_class_metaspace));
564
}
565
566
oop Universe::out_of_memory_error_array_size() {
567
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_array_size));
568
}
569
570
oop Universe::out_of_memory_error_gc_overhead_limit() {
571
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_gc_overhead_limit));
572
}
573
574
oop Universe::out_of_memory_error_realloc_objects() {
575
return gen_out_of_memory_error(out_of_memory_errors()->obj_at(_oom_realloc_objects));
576
}
577
578
// Throw default _out_of_memory_error_retry object as it will never propagate out of the VM
579
oop Universe::out_of_memory_error_retry() { return out_of_memory_errors()->obj_at(_oom_retry); }
580
oop Universe::delayed_stack_overflow_error_message() { return _delayed_stack_overflow_error_message.resolve(); }
581
582
583
bool Universe::should_fill_in_stack_trace(Handle throwable) {
584
// never attempt to fill in the stack trace of preallocated errors that do not have
585
// backtrace. These errors are kept alive forever and may be "re-used" when all
586
// preallocated errors with backtrace have been consumed. Also need to avoid
587
// a potential loop which could happen if an out of memory occurs when attempting
588
// to allocate the backtrace.
589
objArrayOop preallocated_oom = out_of_memory_errors();
590
for (int i = 0; i < _oom_count; i++) {
591
if (throwable() == preallocated_oom->obj_at(i)) {
592
return false;
593
}
594
}
595
return true;
596
}
597
598
599
oop Universe::gen_out_of_memory_error(oop default_err) {
600
// generate an out of memory error:
601
// - if there is a preallocated error and stack traces are available
602
// (j.l.Throwable is initialized), then return the preallocated
603
// error with a filled in stack trace, and with the message
604
// provided by the default error.
605
// - otherwise, return the default error, without a stack trace.
606
int next;
607
if ((_preallocated_out_of_memory_error_avail_count > 0) &&
608
vmClasses::Throwable_klass()->is_initialized()) {
609
next = (int)Atomic::add(&_preallocated_out_of_memory_error_avail_count, -1);
610
assert(next < (int)PreallocatedOutOfMemoryErrorCount, "avail count is corrupt");
611
} else {
612
next = -1;
613
}
614
if (next < 0) {
615
// all preallocated errors have been used.
616
// return default
617
return default_err;
618
} else {
619
JavaThread* current = JavaThread::current();
620
Handle default_err_h(current, default_err);
621
// get the error object at the slot and set set it to NULL so that the
622
// array isn't keeping it alive anymore.
623
Handle exc(current, preallocated_out_of_memory_errors()->obj_at(next));
624
assert(exc() != NULL, "slot has been used already");
625
preallocated_out_of_memory_errors()->obj_at_put(next, NULL);
626
627
// use the message from the default error
628
oop msg = java_lang_Throwable::message(default_err_h());
629
assert(msg != NULL, "no message");
630
java_lang_Throwable::set_message(exc(), msg);
631
632
// populate the stack trace and return it.
633
java_lang_Throwable::fill_in_stack_trace_of_preallocated_backtrace(exc);
634
return exc();
635
}
636
}
637
638
// Setup preallocated OutOfMemoryError errors
639
void Universe::create_preallocated_out_of_memory_errors(TRAPS) {
640
InstanceKlass* ik = vmClasses::OutOfMemoryError_klass();
641
objArrayOop oa = oopFactory::new_objArray(ik, _oom_count, CHECK);
642
objArrayHandle oom_array(THREAD, oa);
643
644
for (int i = 0; i < _oom_count; i++) {
645
oop oom_obj = ik->allocate_instance(CHECK);
646
oom_array->obj_at_put(i, oom_obj);
647
}
648
_out_of_memory_errors = OopHandle(vm_global(), oom_array());
649
650
Handle msg = java_lang_String::create_from_str("Java heap space", CHECK);
651
java_lang_Throwable::set_message(oom_array->obj_at(_oom_java_heap), msg());
652
653
msg = java_lang_String::create_from_str("C heap space", CHECK);
654
java_lang_Throwable::set_message(oom_array->obj_at(_oom_c_heap), msg());
655
656
msg = java_lang_String::create_from_str("Metaspace", CHECK);
657
java_lang_Throwable::set_message(oom_array->obj_at(_oom_metaspace), msg());
658
659
msg = java_lang_String::create_from_str("Compressed class space", CHECK);
660
java_lang_Throwable::set_message(oom_array->obj_at(_oom_class_metaspace), msg());
661
662
msg = java_lang_String::create_from_str("Requested array size exceeds VM limit", CHECK);
663
java_lang_Throwable::set_message(oom_array->obj_at(_oom_array_size), msg());
664
665
msg = java_lang_String::create_from_str("GC overhead limit exceeded", CHECK);
666
java_lang_Throwable::set_message(oom_array->obj_at(_oom_gc_overhead_limit), msg());
667
668
msg = java_lang_String::create_from_str("Java heap space: failed reallocation of scalar replaced objects", CHECK);
669
java_lang_Throwable::set_message(oom_array->obj_at(_oom_realloc_objects), msg());
670
671
msg = java_lang_String::create_from_str("Java heap space: failed retryable allocation", CHECK);
672
java_lang_Throwable::set_message(oom_array->obj_at(_oom_retry), msg());
673
674
// Setup the array of errors that have preallocated backtrace
675
int len = (StackTraceInThrowable) ? (int)PreallocatedOutOfMemoryErrorCount : 0;
676
objArrayOop instance = oopFactory::new_objArray(ik, len, CHECK);
677
_preallocated_out_of_memory_error_array = OopHandle(vm_global(), instance);
678
objArrayHandle preallocated_oom_array(THREAD, instance);
679
680
for (int i=0; i<len; i++) {
681
oop err = ik->allocate_instance(CHECK);
682
Handle err_h(THREAD, err);
683
java_lang_Throwable::allocate_backtrace(err_h, CHECK);
684
preallocated_oom_array->obj_at_put(i, err_h());
685
}
686
_preallocated_out_of_memory_error_avail_count = (jint)len;
687
}
688
689
intptr_t Universe::_non_oop_bits = 0;
690
691
void* Universe::non_oop_word() {
692
// Neither the high bits nor the low bits of this value is allowed
693
// to look like (respectively) the high or low bits of a real oop.
694
//
695
// High and low are CPU-specific notions, but low always includes
696
// the low-order bit. Since oops are always aligned at least mod 4,
697
// setting the low-order bit will ensure that the low half of the
698
// word will never look like that of a real oop.
699
//
700
// Using the OS-supplied non-memory-address word (usually 0 or -1)
701
// will take care of the high bits, however many there are.
702
703
if (_non_oop_bits == 0) {
704
_non_oop_bits = (intptr_t)os::non_memory_address_word() | 1;
705
}
706
707
return (void*)_non_oop_bits;
708
}
709
710
bool Universe::contains_non_oop_word(void* p) {
711
return *(void**)p == non_oop_word();
712
}
713
714
static void initialize_global_behaviours() {
715
CompiledICProtectionBehaviour::set_current(new DefaultICProtectionBehaviour());
716
}
717
718
jint universe_init() {
719
assert(!Universe::_fully_initialized, "called after initialize_vtables");
720
guarantee(1 << LogHeapWordSize == sizeof(HeapWord),
721
"LogHeapWordSize is incorrect.");
722
guarantee(sizeof(oop) >= sizeof(HeapWord), "HeapWord larger than oop?");
723
guarantee(sizeof(oop) % sizeof(HeapWord) == 0,
724
"oop size is not not a multiple of HeapWord size");
725
726
TraceTime timer("Genesis", TRACETIME_LOG(Info, startuptime));
727
728
initialize_global_behaviours();
729
730
GCLogPrecious::initialize();
731
732
GCConfig::arguments()->initialize_heap_sizes();
733
734
jint status = Universe::initialize_heap();
735
if (status != JNI_OK) {
736
return status;
737
}
738
739
Universe::initialize_tlab();
740
741
Metaspace::global_initialize();
742
743
// Initialize performance counters for metaspaces
744
MetaspaceCounters::initialize_performance_counters();
745
746
// Checks 'AfterMemoryInit' constraints.
747
if (!JVMFlagLimit::check_all_constraints(JVMFlagConstraintPhase::AfterMemoryInit)) {
748
return JNI_EINVAL;
749
}
750
751
// Create memory for metadata. Must be after initializing heap for
752
// DumpSharedSpaces.
753
ClassLoaderData::init_null_class_loader_data();
754
755
// We have a heap so create the Method* caches before
756
// Metaspace::initialize_shared_spaces() tries to populate them.
757
Universe::_finalizer_register_cache = new LatestMethodCache();
758
Universe::_loader_addClass_cache = new LatestMethodCache();
759
Universe::_throw_illegal_access_error_cache = new LatestMethodCache();
760
Universe::_throw_no_such_method_error_cache = new LatestMethodCache();
761
Universe::_do_stack_walk_cache = new LatestMethodCache();
762
763
#if INCLUDE_CDS
764
if (UseSharedSpaces) {
765
// Read the data structures supporting the shared spaces (shared
766
// system dictionary, symbol table, etc.). After that, access to
767
// the file (other than the mapped regions) is no longer needed, and
768
// the file is closed. Closing the file does not affect the
769
// currently mapped regions.
770
MetaspaceShared::initialize_shared_spaces();
771
StringTable::create_table();
772
} else
773
#endif
774
{
775
SymbolTable::create_table();
776
StringTable::create_table();
777
}
778
779
#if INCLUDE_CDS
780
if (Arguments::is_dumping_archive()) {
781
MetaspaceShared::prepare_for_dumping();
782
}
783
#endif
784
785
if (strlen(VerifySubSet) > 0) {
786
Universe::initialize_verify_flags();
787
}
788
789
ResolvedMethodTable::create_table();
790
791
return JNI_OK;
792
}
793
794
jint Universe::initialize_heap() {
795
assert(_collectedHeap == NULL, "Heap already created");
796
_collectedHeap = GCConfig::arguments()->create_heap();
797
798
log_info(gc)("Using %s", _collectedHeap->name());
799
return _collectedHeap->initialize();
800
}
801
802
void Universe::initialize_tlab() {
803
ThreadLocalAllocBuffer::set_max_size(Universe::heap()->max_tlab_size());
804
if (UseTLAB) {
805
ThreadLocalAllocBuffer::startup_initialization();
806
}
807
}
808
809
ReservedHeapSpace Universe::reserve_heap(size_t heap_size, size_t alignment) {
810
811
assert(alignment <= Arguments::conservative_max_heap_alignment(),
812
"actual alignment " SIZE_FORMAT " must be within maximum heap alignment " SIZE_FORMAT,
813
alignment, Arguments::conservative_max_heap_alignment());
814
815
size_t total_reserved = align_up(heap_size, alignment);
816
assert(!UseCompressedOops || (total_reserved <= (OopEncodingHeapMax - os::vm_page_size())),
817
"heap size is too big for compressed oops");
818
819
size_t page_size = os::vm_page_size();
820
if (UseLargePages && is_aligned(alignment, os::large_page_size())) {
821
page_size = os::large_page_size();
822
} else {
823
// Parallel is the only collector that might opt out of using large pages
824
// for the heap.
825
assert(!UseLargePages || UseParallelGC , "Wrong alignment to use large pages");
826
}
827
828
// Now create the space.
829
ReservedHeapSpace total_rs(total_reserved, alignment, page_size, AllocateHeapAt);
830
831
if (total_rs.is_reserved()) {
832
assert((total_reserved == total_rs.size()) && ((uintptr_t)total_rs.base() % alignment == 0),
833
"must be exactly of required size and alignment");
834
// We are good.
835
836
if (AllocateHeapAt != NULL) {
837
log_info(gc,heap)("Successfully allocated Java heap at location %s", AllocateHeapAt);
838
}
839
840
if (UseCompressedOops) {
841
CompressedOops::initialize(total_rs);
842
}
843
844
Universe::calculate_verify_data((HeapWord*)total_rs.base(), (HeapWord*)total_rs.end());
845
846
return total_rs;
847
}
848
849
vm_exit_during_initialization(
850
err_msg("Could not reserve enough space for " SIZE_FORMAT "KB object heap",
851
total_reserved/K));
852
853
// satisfy compiler
854
ShouldNotReachHere();
855
return ReservedHeapSpace(0, 0, os::vm_page_size());
856
}
857
858
OopStorage* Universe::vm_weak() {
859
return Universe::_vm_weak;
860
}
861
862
OopStorage* Universe::vm_global() {
863
return Universe::_vm_global;
864
}
865
866
void Universe::oopstorage_init() {
867
Universe::_vm_global = OopStorageSet::create_strong("VM Global", mtInternal);
868
Universe::_vm_weak = OopStorageSet::create_weak("VM Weak", mtInternal);
869
}
870
871
void universe_oopstorage_init() {
872
Universe::oopstorage_init();
873
}
874
875
void initialize_known_method(LatestMethodCache* method_cache,
876
InstanceKlass* ik,
877
const char* method,
878
Symbol* signature,
879
bool is_static, TRAPS)
880
{
881
TempNewSymbol name = SymbolTable::new_symbol(method);
882
Method* m = NULL;
883
// The klass must be linked before looking up the method.
884
if (!ik->link_class_or_fail(THREAD) ||
885
((m = ik->find_method(name, signature)) == NULL) ||
886
is_static != m->is_static()) {
887
ResourceMark rm(THREAD);
888
// NoSuchMethodException doesn't actually work because it tries to run the
889
// <init> function before java_lang_Class is linked. Print error and exit.
890
vm_exit_during_initialization(err_msg("Unable to link/verify %s.%s method",
891
ik->name()->as_C_string(), method));
892
}
893
method_cache->init(ik, m);
894
}
895
896
void Universe::initialize_known_methods(TRAPS) {
897
// Set up static method for registering finalizers
898
initialize_known_method(_finalizer_register_cache,
899
vmClasses::Finalizer_klass(),
900
"register",
901
vmSymbols::object_void_signature(), true, CHECK);
902
903
initialize_known_method(_throw_illegal_access_error_cache,
904
vmClasses::internal_Unsafe_klass(),
905
"throwIllegalAccessError",
906
vmSymbols::void_method_signature(), true, CHECK);
907
908
initialize_known_method(_throw_no_such_method_error_cache,
909
vmClasses::internal_Unsafe_klass(),
910
"throwNoSuchMethodError",
911
vmSymbols::void_method_signature(), true, CHECK);
912
913
// Set up method for registering loaded classes in class loader vector
914
initialize_known_method(_loader_addClass_cache,
915
vmClasses::ClassLoader_klass(),
916
"addClass",
917
vmSymbols::class_void_signature(), false, CHECK);
918
919
// Set up method for stack walking
920
initialize_known_method(_do_stack_walk_cache,
921
vmClasses::AbstractStackWalker_klass(),
922
"doStackWalk",
923
vmSymbols::doStackWalk_signature(), false, CHECK);
924
}
925
926
void universe2_init() {
927
EXCEPTION_MARK;
928
Universe::genesis(CATCH);
929
}
930
931
// Set after initialization of the module runtime, call_initModuleRuntime
932
void universe_post_module_init() {
933
Universe::_module_initialized = true;
934
}
935
936
bool universe_post_init() {
937
assert(!is_init_completed(), "Error: initialization not yet completed!");
938
Universe::_fully_initialized = true;
939
EXCEPTION_MARK;
940
if (!UseSharedSpaces) {
941
reinitialize_vtables();
942
reinitialize_itables();
943
}
944
945
HandleMark hm(THREAD);
946
// Setup preallocated empty java.lang.Class array for Method reflection.
947
948
objArrayOop the_empty_class_array = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_false);
949
Universe::_the_empty_class_array = OopHandle(Universe::vm_global(), the_empty_class_array);
950
951
// Setup preallocated OutOfMemoryError errors
952
Universe::create_preallocated_out_of_memory_errors(CHECK_false);
953
954
oop instance;
955
// Setup preallocated cause message for delayed StackOverflowError
956
if (StackReservedPages > 0) {
957
instance = java_lang_String::create_oop_from_str("Delayed StackOverflowError due to ReservedStackAccess annotated method", CHECK_false);
958
Universe::_delayed_stack_overflow_error_message = OopHandle(Universe::vm_global(), instance);
959
}
960
961
// Setup preallocated NullPointerException
962
// (this is currently used for a cheap & dirty solution in compiler exception handling)
963
Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_NullPointerException(), true, CHECK_false);
964
instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
965
Universe::_null_ptr_exception_instance = OopHandle(Universe::vm_global(), instance);
966
967
// Setup preallocated ArithmeticException
968
// (this is currently used for a cheap & dirty solution in compiler exception handling)
969
k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ArithmeticException(), true, CHECK_false);
970
instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
971
Universe::_arithmetic_exception_instance = OopHandle(Universe::vm_global(), instance);
972
973
// Virtual Machine Error for when we get into a situation we can't resolve
974
k = vmClasses::VirtualMachineError_klass();
975
bool linked = InstanceKlass::cast(k)->link_class_or_fail(CHECK_false);
976
if (!linked) {
977
tty->print_cr("Unable to link/verify VirtualMachineError class");
978
return false; // initialization failed
979
}
980
instance = InstanceKlass::cast(k)->allocate_instance(CHECK_false);
981
Universe::_virtual_machine_error_instance = OopHandle(Universe::vm_global(), instance);
982
983
Handle msg = java_lang_String::create_from_str("/ by zero", CHECK_false);
984
java_lang_Throwable::set_message(Universe::arithmetic_exception_instance(), msg());
985
986
Universe::initialize_known_methods(CHECK_false);
987
988
// This needs to be done before the first scavenge/gc, since
989
// it's an input to soft ref clearing policy.
990
{
991
MutexLocker x(THREAD, Heap_lock);
992
Universe::heap()->update_capacity_and_used_at_gc();
993
}
994
995
// ("weak") refs processing infrastructure initialization
996
Universe::heap()->post_initialize();
997
998
MemoryService::add_metaspace_memory_pools();
999
1000
MemoryService::set_universe_heap(Universe::heap());
1001
#if INCLUDE_CDS
1002
MetaspaceShared::post_initialize(CHECK_false);
1003
#endif
1004
return true;
1005
}
1006
1007
1008
void Universe::compute_base_vtable_size() {
1009
_base_vtable_size = ClassLoader::compute_Object_vtable();
1010
}
1011
1012
void Universe::print_on(outputStream* st) {
1013
GCMutexLocker hl(Heap_lock); // Heap_lock might be locked by caller thread.
1014
st->print_cr("Heap");
1015
heap()->print_on(st);
1016
}
1017
1018
void Universe::print_heap_at_SIGBREAK() {
1019
if (PrintHeapAtSIGBREAK) {
1020
print_on(tty);
1021
tty->cr();
1022
tty->flush();
1023
}
1024
}
1025
1026
void Universe::initialize_verify_flags() {
1027
verify_flags = 0;
1028
const char delimiter[] = " ,";
1029
1030
size_t length = strlen(VerifySubSet);
1031
char* subset_list = NEW_C_HEAP_ARRAY(char, length + 1, mtInternal);
1032
strncpy(subset_list, VerifySubSet, length + 1);
1033
char* save_ptr;
1034
1035
char* token = strtok_r(subset_list, delimiter, &save_ptr);
1036
while (token != NULL) {
1037
if (strcmp(token, "threads") == 0) {
1038
verify_flags |= Verify_Threads;
1039
} else if (strcmp(token, "heap") == 0) {
1040
verify_flags |= Verify_Heap;
1041
} else if (strcmp(token, "symbol_table") == 0) {
1042
verify_flags |= Verify_SymbolTable;
1043
} else if (strcmp(token, "string_table") == 0) {
1044
verify_flags |= Verify_StringTable;
1045
} else if (strcmp(token, "codecache") == 0) {
1046
verify_flags |= Verify_CodeCache;
1047
} else if (strcmp(token, "dictionary") == 0) {
1048
verify_flags |= Verify_SystemDictionary;
1049
} else if (strcmp(token, "classloader_data_graph") == 0) {
1050
verify_flags |= Verify_ClassLoaderDataGraph;
1051
} else if (strcmp(token, "metaspace") == 0) {
1052
verify_flags |= Verify_MetaspaceUtils;
1053
} else if (strcmp(token, "jni_handles") == 0) {
1054
verify_flags |= Verify_JNIHandles;
1055
} else if (strcmp(token, "codecache_oops") == 0) {
1056
verify_flags |= Verify_CodeCacheOops;
1057
} else if (strcmp(token, "resolved_method_table") == 0) {
1058
verify_flags |= Verify_ResolvedMethodTable;
1059
} else if (strcmp(token, "stringdedup") == 0) {
1060
verify_flags |= Verify_StringDedup;
1061
} else {
1062
vm_exit_during_initialization(err_msg("VerifySubSet: \'%s\' memory sub-system is unknown, please correct it", token));
1063
}
1064
token = strtok_r(NULL, delimiter, &save_ptr);
1065
}
1066
FREE_C_HEAP_ARRAY(char, subset_list);
1067
}
1068
1069
bool Universe::should_verify_subset(uint subset) {
1070
if (verify_flags & subset) {
1071
return true;
1072
}
1073
return false;
1074
}
1075
1076
void Universe::verify(VerifyOption option, const char* prefix) {
1077
// The use of _verify_in_progress is a temporary work around for
1078
// 6320749. Don't bother with a creating a class to set and clear
1079
// it since it is only used in this method and the control flow is
1080
// straight forward.
1081
_verify_in_progress = true;
1082
1083
COMPILER2_PRESENT(
1084
assert(!DerivedPointerTable::is_active(),
1085
"DPT should not be active during verification "
1086
"(of thread stacks below)");
1087
)
1088
1089
Thread* thread = Thread::current();
1090
ResourceMark rm(thread);
1091
HandleMark hm(thread); // Handles created during verification can be zapped
1092
_verify_count++;
1093
1094
FormatBuffer<> title("Verifying %s", prefix);
1095
GCTraceTime(Info, gc, verify) tm(title.buffer());
1096
if (should_verify_subset(Verify_Threads)) {
1097
log_debug(gc, verify)("Threads");
1098
Threads::verify();
1099
}
1100
if (should_verify_subset(Verify_Heap)) {
1101
log_debug(gc, verify)("Heap");
1102
heap()->verify(option);
1103
}
1104
if (should_verify_subset(Verify_SymbolTable)) {
1105
log_debug(gc, verify)("SymbolTable");
1106
SymbolTable::verify();
1107
}
1108
if (should_verify_subset(Verify_StringTable)) {
1109
log_debug(gc, verify)("StringTable");
1110
StringTable::verify();
1111
}
1112
if (should_verify_subset(Verify_CodeCache)) {
1113
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1114
log_debug(gc, verify)("CodeCache");
1115
CodeCache::verify();
1116
}
1117
if (should_verify_subset(Verify_SystemDictionary)) {
1118
log_debug(gc, verify)("SystemDictionary");
1119
SystemDictionary::verify();
1120
}
1121
if (should_verify_subset(Verify_ClassLoaderDataGraph)) {
1122
log_debug(gc, verify)("ClassLoaderDataGraph");
1123
ClassLoaderDataGraph::verify();
1124
}
1125
if (should_verify_subset(Verify_MetaspaceUtils)) {
1126
log_debug(gc, verify)("MetaspaceUtils");
1127
DEBUG_ONLY(MetaspaceUtils::verify();)
1128
}
1129
if (should_verify_subset(Verify_JNIHandles)) {
1130
log_debug(gc, verify)("JNIHandles");
1131
JNIHandles::verify();
1132
}
1133
if (should_verify_subset(Verify_CodeCacheOops)) {
1134
log_debug(gc, verify)("CodeCache Oops");
1135
CodeCache::verify_oops();
1136
}
1137
if (should_verify_subset(Verify_ResolvedMethodTable)) {
1138
log_debug(gc, verify)("ResolvedMethodTable Oops");
1139
ResolvedMethodTable::verify();
1140
}
1141
if (should_verify_subset(Verify_StringDedup)) {
1142
log_debug(gc, verify)("String Deduplication");
1143
StringDedup::verify();
1144
}
1145
1146
_verify_in_progress = false;
1147
}
1148
1149
1150
#ifndef PRODUCT
1151
void Universe::calculate_verify_data(HeapWord* low_boundary, HeapWord* high_boundary) {
1152
assert(low_boundary < high_boundary, "bad interval");
1153
1154
// decide which low-order bits we require to be clear:
1155
size_t alignSize = MinObjAlignmentInBytes;
1156
size_t min_object_size = CollectedHeap::min_fill_size();
1157
1158
// make an inclusive limit:
1159
uintptr_t max = (uintptr_t)high_boundary - min_object_size*wordSize;
1160
uintptr_t min = (uintptr_t)low_boundary;
1161
assert(min < max, "bad interval");
1162
uintptr_t diff = max ^ min;
1163
1164
// throw away enough low-order bits to make the diff vanish
1165
uintptr_t mask = (uintptr_t)(-1);
1166
while ((mask & diff) != 0)
1167
mask <<= 1;
1168
uintptr_t bits = (min & mask);
1169
assert(bits == (max & mask), "correct mask");
1170
// check an intermediate value between min and max, just to make sure:
1171
assert(bits == ((min + (max-min)/2) & mask), "correct mask");
1172
1173
// require address alignment, too:
1174
mask |= (alignSize - 1);
1175
1176
if (!(_verify_oop_mask == 0 && _verify_oop_bits == (uintptr_t)-1)) {
1177
assert(_verify_oop_mask == mask && _verify_oop_bits == bits, "mask stability");
1178
}
1179
_verify_oop_mask = mask;
1180
_verify_oop_bits = bits;
1181
}
1182
1183
// Oop verification (see MacroAssembler::verify_oop)
1184
1185
uintptr_t Universe::verify_oop_mask() {
1186
return _verify_oop_mask;
1187
}
1188
1189
uintptr_t Universe::verify_oop_bits() {
1190
return _verify_oop_bits;
1191
}
1192
1193
uintptr_t Universe::verify_mark_mask() {
1194
return markWord::lock_mask_in_place;
1195
}
1196
1197
uintptr_t Universe::verify_mark_bits() {
1198
intptr_t mask = verify_mark_mask();
1199
intptr_t bits = (intptr_t)markWord::prototype().value();
1200
assert((bits & ~mask) == 0, "no stray header bits");
1201
return bits;
1202
}
1203
#endif // PRODUCT
1204
1205
1206
void LatestMethodCache::init(Klass* k, Method* m) {
1207
if (!UseSharedSpaces) {
1208
_klass = k;
1209
}
1210
#ifndef PRODUCT
1211
else {
1212
// sharing initilization should have already set up _klass
1213
assert(_klass != NULL, "just checking");
1214
}
1215
#endif
1216
1217
_method_idnum = m->method_idnum();
1218
assert(_method_idnum >= 0, "sanity check");
1219
}
1220
1221
1222
Method* LatestMethodCache::get_method() {
1223
if (klass() == NULL) return NULL;
1224
InstanceKlass* ik = InstanceKlass::cast(klass());
1225
Method* m = ik->method_with_idnum(method_idnum());
1226
assert(m != NULL, "sanity check");
1227
return m;
1228
}
1229
1230
#ifdef ASSERT
1231
// Release dummy object(s) at bottom of heap
1232
bool Universe::release_fullgc_alot_dummy() {
1233
MutexLocker ml(FullGCALot_lock);
1234
objArrayOop fullgc_alot_dummy_array = (objArrayOop)_fullgc_alot_dummy_array.resolve();
1235
if (fullgc_alot_dummy_array != NULL) {
1236
if (_fullgc_alot_dummy_next >= fullgc_alot_dummy_array->length()) {
1237
// No more dummies to release, release entire array instead
1238
_fullgc_alot_dummy_array.release(Universe::vm_global());
1239
return false;
1240
}
1241
1242
// Release dummy at bottom of old generation
1243
fullgc_alot_dummy_array->obj_at_put(_fullgc_alot_dummy_next++, NULL);
1244
}
1245
return true;
1246
}
1247
1248
bool Universe::is_gc_active() {
1249
return heap()->is_gc_active();
1250
}
1251
1252
bool Universe::is_in_heap(const void* p) {
1253
return heap()->is_in(p);
1254
}
1255
1256
#endif // ASSERT
1257
1258