Skip to content

Commit ac4dc04

Browse files
committedJul 25, 2020
8250519: [REDO] Move mirror oops from Universe into OopStorage
Redo the patch but add a null pointer check where one belongs. Reviewed-by: dcubed, iklam, dholmes
1 parent cce3929 commit ac4dc04

File tree

4 files changed

+96
-156
lines changed

4 files changed

+96
-156
lines changed
 

‎src/hotspot/share/classfile/javaClasses.cpp

+5-25
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,9 @@ void java_lang_Class::archive_basic_type_mirrors(TRAPS) {
11211121
assert(HeapShared::is_heap_object_archiving_allowed(),
11221122
"HeapShared::is_heap_object_archiving_allowed() must be true");
11231123

1124-
for (int t = 0; t <= T_VOID; t++) {
1125-
oop m = Universe::_mirrors[t];
1124+
for (int t = T_BOOLEAN; t < T_VOID+1; t++) {
1125+
BasicType bt = (BasicType)t;
1126+
oop m = Universe::_mirrors[t].resolve();
11261127
if (m != NULL) {
11271128
// Update the field at _array_klass_offset to point to the relocated array klass.
11281129
oop archived_m = HeapShared::archive_heap_object(m, THREAD);
@@ -1142,33 +1143,12 @@ void java_lang_Class::archive_basic_type_mirrors(TRAPS) {
11421143

11431144
log_trace(cds, heap, mirror)(
11441145
"Archived %s mirror object from " PTR_FORMAT " ==> " PTR_FORMAT,
1145-
type2name((BasicType)t), p2i(Universe::_mirrors[t]), p2i(archived_m));
1146+
type2name(bt), p2i(m), p2i(archived_m));
11461147

1147-
Universe::_mirrors[t] = archived_m;
1148+
Universe::replace_mirror(bt, archived_m);
11481149
}
11491150
}
1150-
1151-
assert(Universe::_mirrors[T_INT] != NULL &&
1152-
Universe::_mirrors[T_FLOAT] != NULL &&
1153-
Universe::_mirrors[T_DOUBLE] != NULL &&
1154-
Universe::_mirrors[T_BYTE] != NULL &&
1155-
Universe::_mirrors[T_BOOLEAN] != NULL &&
1156-
Universe::_mirrors[T_CHAR] != NULL &&
1157-
Universe::_mirrors[T_LONG] != NULL &&
1158-
Universe::_mirrors[T_SHORT] != NULL &&
1159-
Universe::_mirrors[T_VOID] != NULL, "sanity");
1160-
1161-
Universe::set_int_mirror(Universe::_mirrors[T_INT]);
1162-
Universe::set_float_mirror(Universe::_mirrors[T_FLOAT]);
1163-
Universe::set_double_mirror(Universe::_mirrors[T_DOUBLE]);
1164-
Universe::set_byte_mirror(Universe::_mirrors[T_BYTE]);
1165-
Universe::set_bool_mirror(Universe::_mirrors[T_BOOLEAN]);
1166-
Universe::set_char_mirror(Universe::_mirrors[T_CHAR]);
1167-
Universe::set_long_mirror(Universe::_mirrors[T_LONG]);
1168-
Universe::set_short_mirror(Universe::_mirrors[T_SHORT]);
1169-
Universe::set_void_mirror(Universe::_mirrors[T_VOID]);
11701151
}
1171-
11721152
//
11731153
// After the mirror object is successfully archived, the archived
11741154
// klass is set with _has_archived_raw_mirror flag.

‎src/hotspot/share/memory/metaspaceShared.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -714,19 +714,6 @@ static void remove_java_mirror_in_classes() {
714714
}
715715
}
716716

717-
static void clear_basic_type_mirrors() {
718-
assert(!HeapShared::is_heap_object_archiving_allowed(), "Sanity");
719-
Universe::set_int_mirror(NULL);
720-
Universe::set_float_mirror(NULL);
721-
Universe::set_double_mirror(NULL);
722-
Universe::set_byte_mirror(NULL);
723-
Universe::set_bool_mirror(NULL);
724-
Universe::set_char_mirror(NULL);
725-
Universe::set_long_mirror(NULL);
726-
Universe::set_short_mirror(NULL);
727-
Universe::set_void_mirror(NULL);
728-
}
729-
730717
static void rewrite_nofast_bytecode(const methodHandle& method) {
731718
BytecodeStream bcs(method);
732719
while (!bcs.is_last_bytecode()) {
@@ -1540,7 +1527,7 @@ char* VM_PopulateDumpSharedSpace::dump_read_only_tables() {
15401527

15411528
log_info(cds)("Removing java_mirror ... ");
15421529
if (!HeapShared::is_heap_object_archiving_allowed()) {
1543-
clear_basic_type_mirrors();
1530+
Universe::clear_basic_type_mirrors();
15441531
}
15451532
remove_java_mirror_in_classes();
15461533
log_info(cds)("done. ");
@@ -2092,7 +2079,7 @@ void ReadClosure::do_tag(int tag) {
20922079
void ReadClosure::do_oop(oop *p) {
20932080
narrowOop o = (narrowOop)nextPtr();
20942081
if (o == 0 || !HeapShared::open_archive_heap_region_mapped()) {
2095-
p = NULL;
2082+
*p = NULL;
20962083
} else {
20972084
assert(HeapShared::is_heap_object_archiving_allowed(),
20982085
"Archived heap object is not allowed");

‎src/hotspot/share/memory/universe.cpp

+70-76
Original file line numberDiff line numberDiff line change
@@ -88,25 +88,10 @@
8888
#include "utilities/ostream.hpp"
8989
#include "utilities/preserveException.hpp"
9090

91-
#define PRIMITIVE_MIRRORS_DO(func) \
92-
func(_int_mirror) \
93-
func(_float_mirror) \
94-
func(_double_mirror) \
95-
func(_byte_mirror) \
96-
func(_bool_mirror) \
97-
func(_char_mirror) \
98-
func(_long_mirror) \
99-
func(_short_mirror) \
100-
func(_void_mirror)
101-
102-
#define DEFINE_PRIMITIVE_MIRROR(m) \
103-
oop Universe::m = NULL;
104-
10591
// Known objects
106-
PRIMITIVE_MIRRORS_DO(DEFINE_PRIMITIVE_MIRROR)
10792
Klass* Universe::_typeArrayKlassObjs[T_LONG+1] = { NULL /*, NULL...*/ };
10893
Klass* Universe::_objectArrayKlassObj = NULL;
109-
oop Universe::_mirrors[T_VOID+1] = { NULL /*, NULL...*/ };
94+
OopHandle Universe::_mirrors[T_VOID+1];
11095

11196
OopHandle Universe::_main_thread_group;
11297
OopHandle Universe::_system_thread_group;
@@ -197,6 +182,35 @@ oop Universe::virtual_machine_error_instance() { return _virtual_machine_erro
197182

198183
oop Universe::the_null_sentinel() { return _the_null_sentinel.resolve(); }
199184

185+
oop Universe::int_mirror() { return check_mirror(_mirrors[T_INT].resolve()); }
186+
oop Universe::float_mirror() { return check_mirror(_mirrors[T_FLOAT].resolve()); }
187+
oop Universe::double_mirror() { return check_mirror(_mirrors[T_DOUBLE].resolve()); }
188+
oop Universe::byte_mirror() { return check_mirror(_mirrors[T_BYTE].resolve()); }
189+
oop Universe::bool_mirror() { return check_mirror(_mirrors[T_BOOLEAN].resolve()); }
190+
oop Universe::char_mirror() { return check_mirror(_mirrors[T_CHAR].resolve()); }
191+
oop Universe::long_mirror() { return check_mirror(_mirrors[T_LONG].resolve()); }
192+
oop Universe::short_mirror() { return check_mirror(_mirrors[T_SHORT].resolve()); }
193+
oop Universe::void_mirror() { return check_mirror(_mirrors[T_VOID].resolve()); }
194+
195+
oop Universe::java_mirror(BasicType t) {
196+
assert((uint)t < T_VOID+1, "range check");
197+
return check_mirror(_mirrors[t].resolve());
198+
}
199+
200+
// Used by CDS dumping
201+
void Universe::replace_mirror(BasicType t, oop new_mirror) {
202+
Universe::_mirrors[t].replace(new_mirror);
203+
}
204+
205+
// Not sure why CDS has to do this
206+
void Universe::clear_basic_type_mirrors() {
207+
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
208+
if (!is_reference_type((BasicType)i)) {
209+
Universe::_mirrors[i].replace(NULL);
210+
}
211+
}
212+
}
213+
200214
void Universe::basic_type_classes_do(void f(Klass*)) {
201215
for (int i = T_BOOLEAN; i < T_LONG+1; i++) {
202216
f(_typeArrayKlassObjs[i]);
@@ -209,16 +223,7 @@ void Universe::basic_type_classes_do(KlassClosure *closure) {
209223
}
210224
}
211225

212-
#define DO_PRIMITIVE_MIRROR(m) \
213-
f->do_oop((oop*) &m);
214-
215226
void Universe::oops_do(OopClosure* f) {
216-
PRIMITIVE_MIRRORS_DO(DO_PRIMITIVE_MIRROR);
217-
218-
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
219-
f->do_oop(&_mirrors[i]);
220-
}
221-
assert(_mirrors[0] == NULL && _mirrors[T_BOOLEAN - 1] == NULL, "checking");
222227

223228
f->do_oop(&_reference_pending_list);
224229
ThreadsSMRSupport::exiting_threads_oops_do(f);
@@ -248,29 +253,36 @@ void Universe::metaspace_pointers_do(MetaspaceClosure* it) {
248253
_do_stack_walk_cache->metaspace_pointers_do(it);
249254
}
250255

251-
#define ASSERT_MIRROR_NULL(m) \
252-
assert(m == NULL, "archived mirrors should be NULL");
253-
254-
#define SERIALIZE_MIRROR(m) \
255-
f->do_oop(&m); \
256-
if (m != NULL) { java_lang_Class::update_archived_primitive_mirror_native_pointers(m); }
257-
258256
// Serialize metadata and pointers to primitive type mirrors in and out of CDS archive
259257
void Universe::serialize(SerializeClosure* f) {
260258

259+
#if INCLUDE_CDS_JAVA_HEAP
260+
{
261+
oop mirror_oop;
262+
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
263+
if (f->reading()) {
264+
f->do_oop(&mirror_oop); // read from archive
265+
assert(oopDesc::is_oop_or_null(mirror_oop), "is oop");
266+
// Only create an OopHandle for non-null mirrors
267+
if (mirror_oop != NULL) {
268+
_mirrors[i] = OopHandle(vm_global(), mirror_oop);
269+
}
270+
} else {
271+
mirror_oop = _mirrors[i].resolve();
272+
f->do_oop(&mirror_oop); // write to archive
273+
}
274+
if (mirror_oop != NULL) { // may be null if archived heap is disabled
275+
java_lang_Class::update_archived_primitive_mirror_native_pointers(mirror_oop);
276+
}
277+
}
278+
}
279+
#endif
280+
261281
for (int i = 0; i < T_LONG+1; i++) {
262282
f->do_ptr((void**)&_typeArrayKlassObjs[i]);
263283
}
264284

265285
f->do_ptr((void**)&_objectArrayKlassObj);
266-
267-
#if INCLUDE_CDS_JAVA_HEAP
268-
DEBUG_ONLY(if (DumpSharedSpaces && !HeapShared::is_heap_object_archiving_allowed()) {
269-
PRIMITIVE_MIRRORS_DO(ASSERT_MIRROR_NULL);
270-
});
271-
PRIMITIVE_MIRRORS_DO(SERIALIZE_MIRROR);
272-
#endif
273-
274286
f->do_ptr((void**)&_the_array_interfaces_array);
275287
f->do_ptr((void**)&_the_empty_int_array);
276288
f->do_ptr((void**)&_the_empty_short_array);
@@ -284,6 +296,7 @@ void Universe::serialize(SerializeClosure* f) {
284296
_do_stack_walk_cache->serialize(f);
285297
}
286298

299+
287300
void Universe::check_alignment(uintx size, uintx alignment, const char* name) {
288301
if (size < alignment || size % alignment != 0) {
289302
vm_exit_during_initialization(
@@ -435,51 +448,32 @@ void Universe::genesis(TRAPS) {
435448
#endif
436449
}
437450

438-
#define ASSERT_MIRROR_NOT_NULL(m) \
439-
assert(m != NULL, "archived mirrors should not be NULL");
440-
441451
void Universe::initialize_basic_type_mirrors(TRAPS) {
442452
#if INCLUDE_CDS_JAVA_HEAP
443453
if (UseSharedSpaces &&
444454
HeapShared::open_archive_heap_region_mapped() &&
445-
_int_mirror != NULL) {
455+
_mirrors[T_INT].resolve() != NULL) {
446456
assert(HeapShared::is_heap_object_archiving_allowed(), "Sanity");
447-
PRIMITIVE_MIRRORS_DO(ASSERT_MIRROR_NOT_NULL);
457+
458+
// check that all mirrors are mapped also
459+
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
460+
if (!is_reference_type((BasicType)i)) {
461+
oop m = _mirrors[i].resolve();
462+
assert(m != NULL, "archived mirrors should not be NULL");
463+
}
464+
}
448465
} else
449-
// _int_mirror could be NULL if archived heap is not mapped.
466+
// _mirror[T_INT} could be NULL if archived heap is not mapped.
450467
#endif
451468
{
452-
_int_mirror =
453-
java_lang_Class::create_basic_type_mirror("int", T_INT, CHECK);
454-
_float_mirror =
455-
java_lang_Class::create_basic_type_mirror("float", T_FLOAT, CHECK);
456-
_double_mirror =
457-
java_lang_Class::create_basic_type_mirror("double", T_DOUBLE, CHECK);
458-
_byte_mirror =
459-
java_lang_Class::create_basic_type_mirror("byte", T_BYTE, CHECK);
460-
_bool_mirror =
461-
java_lang_Class::create_basic_type_mirror("boolean",T_BOOLEAN, CHECK);
462-
_char_mirror =
463-
java_lang_Class::create_basic_type_mirror("char", T_CHAR, CHECK);
464-
_long_mirror =
465-
java_lang_Class::create_basic_type_mirror("long", T_LONG, CHECK);
466-
_short_mirror =
467-
java_lang_Class::create_basic_type_mirror("short", T_SHORT, CHECK);
468-
_void_mirror =
469-
java_lang_Class::create_basic_type_mirror("void", T_VOID, CHECK);
469+
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
470+
BasicType bt = (BasicType)i;
471+
if (!is_reference_type(bt)) {
472+
oop m = java_lang_Class::create_basic_type_mirror(type2name(bt), bt, CHECK);
473+
_mirrors[i] = OopHandle(vm_global(), m);
474+
}
475+
}
470476
}
471-
472-
_mirrors[T_INT] = _int_mirror;
473-
_mirrors[T_FLOAT] = _float_mirror;
474-
_mirrors[T_DOUBLE] = _double_mirror;
475-
_mirrors[T_BYTE] = _byte_mirror;
476-
_mirrors[T_BOOLEAN] = _bool_mirror;
477-
_mirrors[T_CHAR] = _char_mirror;
478-
_mirrors[T_LONG] = _long_mirror;
479-
_mirrors[T_SHORT] = _short_mirror;
480-
_mirrors[T_VOID] = _void_mirror;
481-
//_mirrors[T_OBJECT] = _object_klass->java_mirror();
482-
//_mirrors[T_ARRAY] = _object_klass->java_mirror();
483477
}
484478

485479
void Universe::fixup_mirrors(TRAPS) {

‎src/hotspot/share/memory/universe.hpp

+19-40
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -95,18 +95,6 @@ class Universe: AllStatic {
9595
static Klass* _objectArrayKlassObj;
9696

9797
// Known objects in the VM
98-
99-
// Primitive objects
100-
static oop _int_mirror;
101-
static oop _float_mirror;
102-
static oop _double_mirror;
103-
static oop _byte_mirror;
104-
static oop _bool_mirror;
105-
static oop _char_mirror;
106-
static oop _long_mirror;
107-
static oop _short_mirror;
108-
static oop _void_mirror;
109-
11098
static OopHandle _main_thread_group; // Reference to the main thread group object
11199
static OopHandle _system_thread_group; // Reference to the system thread group object
112100

@@ -232,33 +220,24 @@ class Universe: AllStatic {
232220
}
233221

234222
// Known objects in the VM
235-
static oop int_mirror() { return check_mirror(_int_mirror); }
236-
static oop float_mirror() { return check_mirror(_float_mirror); }
237-
static oop double_mirror() { return check_mirror(_double_mirror); }
238-
static oop byte_mirror() { return check_mirror(_byte_mirror); }
239-
static oop bool_mirror() { return check_mirror(_bool_mirror); }
240-
static oop char_mirror() { return check_mirror(_char_mirror); }
241-
static oop long_mirror() { return check_mirror(_long_mirror); }
242-
static oop short_mirror() { return check_mirror(_short_mirror); }
243-
static oop void_mirror() { return check_mirror(_void_mirror); }
244-
245-
static void set_int_mirror(oop m) { _int_mirror = m; }
246-
static void set_float_mirror(oop m) { _float_mirror = m; }
247-
static void set_double_mirror(oop m) { _double_mirror = m; }
248-
static void set_byte_mirror(oop m) { _byte_mirror = m; }
249-
static void set_bool_mirror(oop m) { _bool_mirror = m; }
250-
static void set_char_mirror(oop m) { _char_mirror = m; }
251-
static void set_long_mirror(oop m) { _long_mirror = m; }
252-
static void set_short_mirror(oop m) { _short_mirror = m; }
253-
static void set_void_mirror(oop m) { _void_mirror = m; }
254-
255-
// table of same
256-
static oop _mirrors[T_VOID+1];
257-
258-
static oop java_mirror(BasicType t) {
259-
assert((uint)t < T_VOID+1, "range check");
260-
return check_mirror(_mirrors[t]);
261-
}
223+
static oop int_mirror();
224+
static oop float_mirror();
225+
static oop double_mirror();
226+
static oop byte_mirror();
227+
static oop bool_mirror();
228+
static oop char_mirror();
229+
static oop long_mirror();
230+
static oop short_mirror();
231+
static oop void_mirror();
232+
233+
// Table of primitive type mirrors, excluding T_OBJECT and T_ARRAY
234+
// but including T_VOID, hence the index including T_VOID
235+
static OopHandle _mirrors[T_VOID+1];
236+
237+
static oop java_mirror(BasicType t);
238+
static void replace_mirror(BasicType t, oop obj);
239+
static void clear_basic_type_mirrors();
240+
262241
static oop main_thread_group();
263242
static void set_main_thread_group(oop group);
264243

0 commit comments

Comments
 (0)
Please sign in to comment.