Skip to content

Commit c4910f7

Browse files
authored
Update (2023.03.06)
29691: LA port of 8299089: Instrument global jni handles with tag to make them distinguishable 29690: LA port of 8299312: Clean up BarrierSetNMethod
1 parent 4fa2aca commit c4910f7

File tree

6 files changed

+65
-62
lines changed

6 files changed

+65
-62
lines changed

src/hotspot/cpu/loongarch/gc/shared/barrierSetAssembler_loongarch.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2018, 2022, Loongson Technology. All rights reserved.
3+
* Copyright (c) 2018, 2023, Loongson Technology. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -167,7 +167,9 @@ void BarrierSetAssembler::obj_equals(MacroAssembler* masm,
167167

168168
void BarrierSetAssembler::try_resolve_jobject_in_native(MacroAssembler* masm, Register jni_env,
169169
Register obj, Register tmp, Label& slowpath) {
170-
__ clear_jweak_tag(obj);
170+
STATIC_ASSERT(JNIHandles::tag_mask == 3);
171+
__ addi_d(AT, R0, ~(int)JNIHandles::tag_mask);
172+
__ andr(obj, obj, AT);
171173
__ ld_d(obj, Address(obj, 0));
172174
}
173175

@@ -261,7 +263,7 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm, Label* slo
261263
// instruction patching is synchronized with global icache_flush() by
262264
// the write hart on riscv. So here we can do a plain conditional
263265
// branch with no fencing.
264-
Address thread_disarmed_addr(TREG, in_bytes(bs_nm->thread_disarmed_offset()));
266+
Address thread_disarmed_addr(TREG, in_bytes(bs_nm->thread_disarmed_guard_value_offset()));
265267
__ ld_wu(SCR2, thread_disarmed_addr);
266268
break;
267269
}
@@ -286,7 +288,7 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm, Label* slo
286288
__ slli_d(SCR2, SCR2, 32);
287289
__ orr(SCR1, SCR1, SCR2);
288290
// Compare the global values with the thread-local values
289-
Address thread_disarmed_and_epoch_addr(TREG, in_bytes(bs_nm->thread_disarmed_offset()));
291+
Address thread_disarmed_and_epoch_addr(TREG, in_bytes(bs_nm->thread_disarmed_guard_value_offset()));
290292
__ ld_d(SCR2, thread_disarmed_and_epoch_addr);
291293
break;
292294
}

src/hotspot/cpu/loongarch/gc/shared/barrierSetNMethod_loongarch.cpp

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2019, 2022, Loongson Technology. All rights reserved.
3+
* Copyright (c) 2019, 2023, Loongson Technology. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -161,33 +161,12 @@ static NativeNMethodBarrier* native_nmethod_barrier(nmethod* nm) {
161161
return barrier;
162162
}
163163

164-
void BarrierSetNMethod::disarm(nmethod* nm) {
164+
void BarrierSetNMethod::set_guard_value(nmethod* nm, int value) {
165165
if (!supports_entry_barrier(nm)) {
166166
return;
167167
}
168168

169-
// The patching epoch is incremented before the nmethod is disarmed. Disarming
170-
// is performed with a release store. In the nmethod entry barrier, the values
171-
// are read in the opposite order, such that the load of the nmethod guard
172-
// acquires the patching epoch. This way, the guard is guaranteed to block
173-
// entries to the nmethod, util it has safely published the requirement for
174-
// further fencing by mutators, before they are allowed to enter.
175-
BarrierSetAssembler* bs_asm = BarrierSet::barrier_set()->barrier_set_assembler();
176-
bs_asm->increment_patching_epoch();
177-
178-
// Disarms the nmethod guard emitted by BarrierSetAssembler::nmethod_entry_barrier.
179-
// Symmetric "LD.W; DBAR" is in the nmethod barrier.
180-
NativeNMethodBarrier* barrier = native_nmethod_barrier(nm);
181-
182-
barrier->set_value(nm, disarmed_value());
183-
}
184-
185-
void BarrierSetNMethod::arm(nmethod* nm, int arm_value) {
186-
if (!supports_entry_barrier(nm)) {
187-
return;
188-
}
189-
190-
if (arm_value == disarmed_value()) {
169+
if (value == disarmed_guard_value()) {
191170
// The patching epoch is incremented before the nmethod is disarmed. Disarming
192171
// is performed with a release store. In the nmethod entry barrier, the values
193172
// are read in the opposite order, such that the load of the nmethod guard
@@ -199,14 +178,14 @@ void BarrierSetNMethod::arm(nmethod* nm, int arm_value) {
199178
}
200179

201180
NativeNMethodBarrier* barrier = native_nmethod_barrier(nm);
202-
barrier->set_value(nm, arm_value);
181+
barrier->set_value(nm, value);
203182
}
204183

205-
bool BarrierSetNMethod::is_armed(nmethod* nm) {
184+
int BarrierSetNMethod::guard_value(nmethod* nm) {
206185
if (!supports_entry_barrier(nm)) {
207-
return false;
186+
return disarmed_guard_value();
208187
}
209188

210189
NativeNMethodBarrier* barrier = native_nmethod_barrier(nm);
211-
return barrier->get_value(nm) != disarmed_value();
190+
return barrier->get_value(nm);
212191
}

src/hotspot/cpu/loongarch/loongarch_64.ad

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,7 @@ void MachPrologNode::format( PhaseRegAlloc *ra_, outputStream* st ) const {
20532053
st->print("\n\t");
20542054
st->print("ld_d T1, guard, 0\n\t");
20552055
st->print("dbar 0\n\t");
2056-
st->print("ld_d T2, TREG, thread_disarmed_offset\n\t");
2056+
st->print("ld_d T2, TREG, thread_disarmed_guard_value_offset\n\t");
20572057
st->print("beq T1, T2, skip\n\t");
20582058
st->print("\n\t");
20592059
st->print("jalr #nmethod_entry_barrier_stub\n\t");

src/hotspot/cpu/loongarch/macroAssembler_loongarch.cpp

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,32 +2447,62 @@ void MacroAssembler::load_byte_map_base(Register reg) {
24472447
li(reg, (uint64_t)byte_map_base);
24482448
}
24492449

2450-
void MacroAssembler::clear_jweak_tag(Register possibly_jweak) {
2451-
const int32_t inverted_jweak_mask = ~static_cast<int32_t>(JNIHandles::weak_tag_mask);
2452-
STATIC_ASSERT(inverted_jweak_mask == -2); // otherwise check this code
2453-
// The inverted mask is sign-extended
2454-
li(AT, inverted_jweak_mask);
2455-
andr(possibly_jweak, AT, possibly_jweak);
2456-
}
2457-
24582450
void MacroAssembler::resolve_jobject(Register value,
24592451
Register thread,
24602452
Register tmp) {
24612453
assert_different_registers(value, thread, tmp);
2462-
Label done, not_weak;
2463-
beq(value, R0, done); // Use NULL as-is.
2464-
li(AT, JNIHandles::weak_tag_mask); // Test for jweak tag.
2465-
andr(AT, value, AT);
2466-
beq(AT, R0, not_weak);
2454+
Label done, tagged, weak_tagged;
2455+
2456+
beqz(value, done); // Use NULL as-is.
2457+
// Test for tag.
2458+
andi(AT, value, JNIHandles::tag_mask);
2459+
bnez(AT, tagged);
2460+
2461+
// Resolve local handle
2462+
access_load_at(T_OBJECT, IN_NATIVE | AS_RAW, value, Address(value, 0), tmp, thread);
2463+
verify_oop(value);
2464+
b(done);
2465+
2466+
bind(tagged);
2467+
// Test for jweak tag.
2468+
andi(AT, value, JNIHandles::TypeTag::weak_global);
2469+
bnez(AT, weak_tagged);
2470+
2471+
// Resolve global handle
2472+
access_load_at(T_OBJECT, IN_NATIVE, value,
2473+
Address(value, -JNIHandles::TypeTag::global), tmp, thread);
2474+
verify_oop(value);
2475+
b(done);
2476+
2477+
bind(weak_tagged);
24672478
// Resolve jweak.
24682479
access_load_at(T_OBJECT, IN_NATIVE | ON_PHANTOM_OOP_REF,
2469-
value, Address(value, -JNIHandles::weak_tag_value), tmp, thread);
2480+
value, Address(value, -JNIHandles::TypeTag::weak_global), tmp, thread);
24702481
verify_oop(value);
2471-
b(done);
2472-
bind(not_weak);
2473-
// Resolve (untagged) jobject.
2474-
access_load_at(T_OBJECT, IN_NATIVE, value, Address(value, 0), tmp, thread);
2482+
bind(done);
2483+
}
2484+
2485+
void MacroAssembler::resolve_global_jobject(Register value, Register tmp1, Register tmp2) {
2486+
assert_different_registers(value, tmp1, tmp2);
2487+
Label done;
2488+
2489+
beqz(value, done); // Use NULL as-is.
2490+
2491+
#ifdef ASSERT
2492+
{
2493+
Label valid_global_tag;
2494+
andi(AT, value, JNIHandles::TypeTag::global); // Test for global tag.
2495+
bnez(AT, valid_global_tag);
2496+
stop("non global jobject using resolve_global_jobject");
2497+
bind(valid_global_tag);
2498+
}
2499+
#endif
2500+
2501+
// Resolve global handle
2502+
access_load_at(T_OBJECT, IN_NATIVE, value,
2503+
Address(value, -JNIHandles::TypeTag::global), tmp1, tmp2);
24752504
verify_oop(value);
2505+
24762506
bind(done);
24772507
}
24782508

src/hotspot/cpu/loongarch/macroAssembler_loongarch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,8 @@ class MacroAssembler: public Assembler {
237237
void reset_last_Java_frame(bool clear_fp);
238238

239239
// jobjects
240-
void clear_jweak_tag(Register possibly_jweak);
241240
void resolve_jobject(Register value, Register thread, Register tmp);
241+
void resolve_global_jobject(Register value, Register tmp1, Register tmp2);
242242

243243
// C 'boolean' to Java boolean: x == 0 ? 0 : 1
244244
void c2bool(Register x);

src/hotspot/cpu/loongarch/stubGenerator_loongarch_64.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,7 @@ class StubGenerator: public StubCodeGenerator {
31203120

31213121
if (bs_asm->nmethod_patching_type() == NMethodPatchingType::conc_instruction_and_data_patch) {
31223122
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
3123-
Address thread_epoch_addr(TREG, in_bytes(bs_nm->thread_disarmed_offset()) + 4);
3123+
Address thread_epoch_addr(TREG, in_bytes(bs_nm->thread_disarmed_guard_value_offset()) + 4);
31243124
__ lea(SCR1, ExternalAddress(bs_asm->patching_epoch_addr()));
31253125
__ ld_wu(SCR1, SCR1, 0);
31263126
__ st_w(SCR1, thread_epoch_addr);
@@ -4936,17 +4936,9 @@ class StubGenerator: public StubCodeGenerator {
49364936
__ move(c_rarg0, TREG);
49374937
__ call_VM_leaf(CAST_FROM_FN_PTR(address, JfrIntrinsicSupport::write_checkpoint), 1);
49384938
__ reset_last_Java_frame(true);
4939-
49404939
// A0 is jobject handle result, unpack and process it through a barrier.
4941-
Label null_jobject;
4942-
__ beqz(A0, null_jobject);
4943-
4944-
DecoratorSet decorators = ACCESS_READ | IN_NATIVE;
4945-
BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
49464940
// For zBarrierSet, tmp1 shall not be SCR1 or same as dst
4947-
bs->load_at(_masm, decorators, T_OBJECT, A0, Address(A0, 0), /* tmp1 */ SCR2, noreg);
4948-
4949-
__ bind(null_jobject);
4941+
__ resolve_global_jobject(A0, SCR2, noreg);
49504942

49514943
__ leave();
49524944
__ jr(RA);

0 commit comments

Comments
 (0)