Skip to content

Commit 2c9365d

Browse files
committed
8264271: Avoid creating non_oop_word oops
Reviewed-by: kbarrett, pliden
1 parent daeca3f commit 2c9365d

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

src/hotspot/share/code/compiledIC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void CompiledIC::internal_set_ic_destination(address entry_point, bool is_icstub
140140
return;
141141
}
142142

143-
if (cache == NULL) cache = (void*)Universe::non_oop_word();
143+
if (cache == NULL) cache = Universe::non_oop_word();
144144

145145
set_data((intptr_t)cache);
146146
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,9 +1026,9 @@ inline void nmethod::initialize_immediate_oop(oop* dest, jobject handle) {
10261026
if (handle == NULL ||
10271027
// As a special case, IC oops are initialized to 1 or -1.
10281028
handle == (jobject) Universe::non_oop_word()) {
1029-
(*dest) = cast_to_oop(handle);
1029+
*(void**)dest = handle;
10301030
} else {
1031-
(*dest) = JNIHandles::resolve_non_null(handle);
1031+
*dest = JNIHandles::resolve_non_null(handle);
10321032
}
10331033
}
10341034

@@ -2616,7 +2616,7 @@ void nmethod::print_oops(outputStream* st) {
26162616
for (oop* p = oops_begin(); p < oops_end(); p++) {
26172617
Disassembler::print_location((unsigned char*)p, (unsigned char*)oops_begin(), (unsigned char*)oops_end(), st, true, false);
26182618
st->print(PTR_FORMAT " ", *((uintptr_t*)p));
2619-
if (*p == Universe::non_oop_word()) {
2619+
if (Universe::contains_non_oop_word(p)) {
26202620
st->print_cr("NON_OOP");
26212621
continue; // skip non-oops
26222622
}
@@ -2712,23 +2712,44 @@ void nmethod::print_nul_chk_table() {
27122712
ImplicitExceptionTable(this).print(code_begin());
27132713
}
27142714

2715+
void nmethod::print_recorded_oop(int log_n, int i) {
2716+
void* value;
2717+
2718+
if (i == 0) {
2719+
value = NULL;
2720+
} else {
2721+
// Be careful around non-oop words. Don't create an oop
2722+
// with that value, or it will assert in verification code.
2723+
if (Universe::contains_non_oop_word(oop_addr_at(i))) {
2724+
value = Universe::non_oop_word();
2725+
} else {
2726+
value = oop_at(i);
2727+
}
2728+
}
2729+
2730+
tty->print("#%*d: " INTPTR_FORMAT " ", log_n, i, p2i(value));
2731+
2732+
if (value == Universe::non_oop_word()) {
2733+
tty->print("non-oop word");
2734+
} else {
2735+
if (value == 0) {
2736+
tty->print("NULL-oop");
2737+
} else {
2738+
oop_at(i)->print_value_on(tty);
2739+
}
2740+
}
2741+
2742+
tty->cr();
2743+
}
2744+
27152745
void nmethod::print_recorded_oops() {
27162746
const int n = oops_count();
27172747
const int log_n = (n<10) ? 1 : (n<100) ? 2 : (n<1000) ? 3 : (n<10000) ? 4 : 6;
27182748
tty->print("Recorded oops:");
27192749
if (n > 0) {
27202750
tty->cr();
27212751
for (int i = 0; i < n; i++) {
2722-
oop o = oop_at(i);
2723-
tty->print("#%*d: " INTPTR_FORMAT " ", log_n, i, p2i(o));
2724-
if ((void*)o == Universe::non_oop_word()) {
2725-
tty->print("non-oop word");
2726-
} else if (o == NULL) {
2727-
tty->print("NULL-oop");
2728-
} else {
2729-
o->print_value_on(tty);
2730-
}
2731-
tty->cr();
2752+
print_recorded_oop(log_n, i);
27322753
}
27332754
} else {
27342755
tty->print_cr(" <list empty>");

src/hotspot/share/code/nmethod.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ class nmethod : public CompiledMethod {
671671
void print_native_invokers();
672672
void print_handler_table();
673673
void print_nul_chk_table();
674+
void print_recorded_oop(int log_n, int index);
674675
void print_recorded_oops();
675676
void print_recorded_metadata();
676677

src/hotspot/share/code/relocInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,11 @@ oop* oop_Relocation::oop_addr() {
541541

542542

543543
oop oop_Relocation::oop_value() {
544-
oop v = *oop_addr();
545544
// clean inline caches store a special pseudo-null
546-
if (v == Universe::non_oop_word()) v = NULL;
547-
return v;
545+
if (Universe::contains_non_oop_word(oop_addr())) {
546+
return NULL;
547+
}
548+
return *oop_addr();
548549
}
549550

550551

src/hotspot/share/gc/z/zNMethod.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void ZNMethod::nmethod_oops_do_inner(nmethod* nm, OopClosure* cl) {
219219
oop* const begin = nm->oops_begin();
220220
oop* const end = nm->oops_end();
221221
for (oop* p = begin; p < end; p++) {
222-
if (*p != Universe::non_oop_word()) {
222+
if (!Universe::contains_non_oop_word(p)) {
223223
cl->do_oop(p);
224224
}
225225
}
@@ -232,7 +232,7 @@ void ZNMethod::nmethod_oops_do_inner(nmethod* nm, OopClosure* cl) {
232232
oop** const begin = oops->immediates_begin();
233233
oop** const end = oops->immediates_end();
234234
for (oop** p = begin; p < end; p++) {
235-
if (**p != Universe::non_oop_word()) {
235+
if (*p != Universe::non_oop_word()) {
236236
cl->do_oop(*p);
237237
}
238238
}

src/hotspot/share/memory/universe.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ void* Universe::non_oop_word() {
716716
return (void*)_non_oop_bits;
717717
}
718718

719+
bool Universe::contains_non_oop_word(void* p) {
720+
return *(void**)p == non_oop_word();
721+
}
722+
719723
static void initialize_global_behaviours() {
720724
CompiledICProtectionBehaviour::set_current(new DefaultICProtectionBehaviour());
721725
}

src/hotspot/share/memory/universe.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ class Universe: AllStatic {
367367
// array; this should trigger relocation in a sliding compaction collector.
368368
debug_only(static bool release_fullgc_alot_dummy();)
369369
// The non-oop pattern (see compiledIC.hpp, etc)
370-
static void* non_oop_word();
370+
static void* non_oop_word();
371+
static bool contains_non_oop_word(void* p);
371372

372373
// Oop verification (see MacroAssembler::verify_oop)
373374
static uintptr_t verify_oop_mask() PRODUCT_RETURN0;

0 commit comments

Comments
 (0)