Skip to content

Commit d183fc7

Browse files
a74nhnick-arm
authored andcommitted
8221554: aarch64 cross-modifying code
Reviewed-by: rehn, aph
1 parent f626ed6 commit d183fc7

26 files changed

+134
-49
lines changed

src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,6 @@ void LIR_Assembler::rt_call(LIR_Opr result, address dest, const LIR_OprList* arg
29222922
if (info != NULL) {
29232923
add_call_info_here(info);
29242924
}
2925-
__ maybe_isb();
29262925
}
29272926

29282927
void LIR_Assembler::volatile_move_op(LIR_Opr src, LIR_Opr dest, BasicType type, CodeEmitInfo* info) {

src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ int StubAssembler::call_RT(Register oop_result1, Register metadata_result, addre
8080
pop(r0, sp);
8181
#endif
8282
reset_last_Java_frame(true);
83-
maybe_isb();
8483

8584
// check for pending exceptions
8685
{ Label L;

src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ void InterpreterMacroAssembler::call_VM_base(Register oop_result,
16171617
Label L;
16181618
ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
16191619
cbz(rscratch1, L);
1620-
stop("InterpreterMacroAssembler::call_VM_leaf_base:"
1620+
stop("InterpreterMacroAssembler::call_VM_base:"
16211621
" last_sp != NULL");
16221622
bind(L);
16231623
}

src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
159159
__ enter();
160160
__ lea(rscratch1, ExternalAddress(slow_case_addr));
161161
__ blr(rscratch1);
162-
__ maybe_isb();
163162
__ leave();
164163
__ ret(lr);
165164
}

src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,6 @@ void MacroAssembler::call_VM_leaf_base(address entry_point,
13811381
bind(*retaddr);
13821382

13831383
ldp(rscratch1, rmethod, Address(post(sp, 2 * wordSize)));
1384-
maybe_isb();
13851384
}
13861385

13871386
void MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) {
@@ -4387,10 +4386,15 @@ void MacroAssembler::get_polling_page(Register dest, relocInfo::relocType rtype)
43874386
// Read the polling page. The address of the polling page must
43884387
// already be in r.
43894388
address MacroAssembler::read_polling_page(Register r, relocInfo::relocType rtype) {
4390-
InstructionMark im(this);
4391-
code_section()->relocate(inst_mark(), rtype);
4392-
ldrw(zr, Address(r, 0));
4393-
return inst_mark();
4389+
address mark;
4390+
{
4391+
InstructionMark im(this);
4392+
code_section()->relocate(inst_mark(), rtype);
4393+
ldrw(zr, Address(r, 0));
4394+
mark = inst_mark();
4395+
}
4396+
verify_cross_modify_fence_not_required();
4397+
return mark;
43944398
}
43954399

43964400
void MacroAssembler::adrp(Register reg1, const Address &dest, uint64_t &byte_offset) {
@@ -4455,6 +4459,7 @@ void MacroAssembler::build_frame(int framesize) {
44554459
sub(sp, sp, rscratch1);
44564460
}
44574461
}
4462+
verify_cross_modify_fence_not_required();
44584463
}
44594464

44604465
void MacroAssembler::remove_frame(int framesize) {
@@ -5315,3 +5320,29 @@ void MacroAssembler::verify_ptrue() {
53155320
stop("Error: the preserved predicate register (p7) elements are not all true");
53165321
bind(verify_ok);
53175322
}
5323+
5324+
void MacroAssembler::safepoint_isb() {
5325+
isb();
5326+
#ifndef PRODUCT
5327+
if (VerifyCrossModifyFence) {
5328+
// Clear the thread state.
5329+
strb(zr, Address(rthread, in_bytes(JavaThread::requires_cross_modify_fence_offset())));
5330+
}
5331+
#endif
5332+
}
5333+
5334+
#ifndef PRODUCT
5335+
void MacroAssembler::verify_cross_modify_fence_not_required() {
5336+
if (VerifyCrossModifyFence) {
5337+
// Check if thread needs a cross modify fence.
5338+
ldrb(rscratch1, Address(rthread, in_bytes(JavaThread::requires_cross_modify_fence_offset())));
5339+
Label fence_not_required;
5340+
cbz(rscratch1, fence_not_required);
5341+
// If it does then fail.
5342+
lea(rscratch1, CAST_FROM_FN_PTR(address, JavaThread::verify_cross_modify_fence_failure));
5343+
mov(c_rarg0, rthread);
5344+
blr(rscratch1);
5345+
bind(fence_not_required);
5346+
}
5347+
}
5348+
#endif

src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,8 +1315,9 @@ class MacroAssembler: public Assembler {
13151315
Register zlen, Register tmp1, Register tmp2, Register tmp3,
13161316
Register tmp4, Register tmp5, Register tmp6, Register tmp7);
13171317
void mul_add(Register out, Register in, Register offs, Register len, Register k);
1318-
// ISB may be needed because of a safepoint
1319-
void maybe_isb() { isb(); }
1318+
1319+
// Place an ISB after code may have been modified due to a safepoint.
1320+
void safepoint_isb();
13201321

13211322
private:
13221323
// Return the effective address r + (r1 << ext) + offset.
@@ -1392,6 +1393,11 @@ class MacroAssembler: public Assembler {
13921393
}
13931394
void cache_wb(Address line);
13941395
void cache_wbsync(bool is_pre);
1396+
1397+
private:
1398+
// Check the current thread doesn't need a cross modify fence.
1399+
void verify_cross_modify_fence_not_required() PRODUCT_RETURN;
1400+
13951401
};
13961402

13971403
#ifdef ASSERT

src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,10 @@ static void patch_callers_callsite(MacroAssembler *masm) {
373373
__ mov(c_rarg1, lr);
374374
__ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite)));
375375
__ blr(rscratch1);
376-
__ maybe_isb();
376+
377+
// Explicit isb required because fixup_callers_callsite may change the code
378+
// stream.
379+
__ safepoint_isb();
377380

378381
__ pop_CPU_state();
379382
// restore sp
@@ -1150,7 +1153,6 @@ static void rt_call(MacroAssembler* masm, address dest) {
11501153
} else {
11511154
__ lea(rscratch1, RuntimeAddress(dest));
11521155
__ blr(rscratch1);
1153-
__ maybe_isb();
11541156
}
11551157
}
11561158

@@ -1857,7 +1859,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
18571859
__ verify_sve_vector_length();
18581860
}
18591861

1860-
// check for safepoint operation in progress and/or pending suspend requests
1862+
// Check for safepoint operation in progress and/or pending suspend requests.
18611863
{
18621864
// We need an acquire here to ensure that any subsequent load of the
18631865
// global SafepointSynchronize::_state flag is ordered after this load
@@ -2081,7 +2083,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
20812083
#endif
20822084
__ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
20832085
__ blr(rscratch1);
2084-
__ maybe_isb();
2086+
20852087
// Restore any method result value
20862088
restore_native_result(masm, ret_type, stack_slots);
20872089

@@ -2787,7 +2789,6 @@ SafepointBlob* SharedRuntime::generate_handler_blob(address call_ptr, int poll_t
27872789

27882790
__ reset_last_Java_frame(false);
27892791

2790-
__ maybe_isb();
27912792
__ membar(Assembler::LoadLoad | Assembler::LoadStore);
27922793

27932794
if (UseSVE > 0 && save_vectors) {
@@ -2894,8 +2895,6 @@ RuntimeStub* SharedRuntime::generate_resolve_blob(address destination, const cha
28942895

28952896
oop_maps->add_gc_map( __ offset() - start, map);
28962897

2897-
__ maybe_isb();
2898-
28992898
// r0 contains the address we are going to jump to assuming no exception got installed
29002899

29012900
// clear last_Java_sp
@@ -3017,7 +3016,8 @@ void OptoRuntime::generate_exception_blob() {
30173016
__ mov(c_rarg0, rthread);
30183017
__ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
30193018
__ blr(rscratch1);
3020-
__ maybe_isb();
3019+
// handle_exception_C is a special VM call which does not require an explicit
3020+
// instruction sync afterwards.
30213021

30223022
// Set an oopmap for the call site. This oopmap will only be used if we
30233023
// are unwinding the stack. Hence, all locations will be dead.

src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5629,7 +5629,6 @@ class StubGenerator: public StubCodeGenerator {
56295629
oop_maps->add_gc_map(the_pc - start, map);
56305630

56315631
__ reset_last_Java_frame(true);
5632-
__ maybe_isb();
56335632

56345633
if (UseSVE > 0) {
56355634
// Reinitialize the ptrue predicate register, in case the external runtime

src/hotspot/cpu/aarch64/templateInterpreterGenerator_aarch64.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,6 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
13571357
// Call the native method.
13581358
__ blr(r10);
13591359
__ bind(native_return);
1360-
__ maybe_isb();
13611360
__ get_method(rmethod);
13621361
// result potentially in r0 or v0
13631362

@@ -1410,7 +1409,6 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
14101409
__ mov(c_rarg0, rthread);
14111410
__ mov(rscratch2, CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans));
14121411
__ blr(rscratch2);
1413-
__ maybe_isb();
14141412
__ get_method(rmethod);
14151413
__ reinit_heapbase();
14161414
__ bind(Continue);

src/hotspot/os_cpu/aix_ppc/orderAccess_aix_ppc.hpp

Lines changed: 2 additions & 2 deletions
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
* Copyright (c) 2012, 2019 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -73,7 +73,7 @@ inline void OrderAccess::storeload() { inlasm_sync(); }
7373
inline void OrderAccess::acquire() { inlasm_lwsync(); }
7474
inline void OrderAccess::release() { inlasm_lwsync(); }
7575
inline void OrderAccess::fence() { inlasm_sync(); }
76-
inline void OrderAccess::cross_modify_fence()
76+
inline void OrderAccess::cross_modify_fence_impl()
7777
{ inlasm_isync(); }
7878

7979
#undef inlasm_sync

0 commit comments

Comments
 (0)