Skip to content
Closed
1 change: 0 additions & 1 deletion src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,6 @@ void LIR_Assembler::rt_call(LIR_Opr result, address dest, const LIR_OprList* arg
if (info != NULL) {
add_call_info_here(info);
}
__ maybe_isb();
}

void LIR_Assembler::volatile_move_op(LIR_Opr src, LIR_Opr dest, BasicType type, CodeEmitInfo* info) {
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/cpu/aarch64/c1_Runtime1_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ int StubAssembler::call_RT(Register oop_result1, Register metadata_result, addre
pop(r0, sp);
#endif
reset_last_Java_frame(true);
maybe_isb();

// check for pending exceptions
{ Label L;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ void InterpreterMacroAssembler::call_VM_base(Register oop_result,
Label L;
ldr(rscratch1, Address(rfp, frame::interpreter_frame_last_sp_offset * wordSize));
cbz(rscratch1, L);
stop("InterpreterMacroAssembler::call_VM_leaf_base:"
stop("InterpreterMacroAssembler::call_VM_base:"
" last_sp != NULL");
bind(L);
}
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) {
__ enter();
__ lea(rscratch1, ExternalAddress(slow_case_addr));
__ blr(rscratch1);
__ maybe_isb();
__ leave();
__ ret(lr);
}
Expand Down
41 changes: 36 additions & 5 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,6 @@ void MacroAssembler::call_VM_leaf_base(address entry_point,
bind(*retaddr);

ldp(rscratch1, rmethod, Address(post(sp, 2 * wordSize)));
maybe_isb();
}

void MacroAssembler::call_VM_leaf(address entry_point, int number_of_arguments) {
Expand Down Expand Up @@ -4387,10 +4386,15 @@ void MacroAssembler::get_polling_page(Register dest, relocInfo::relocType rtype)
// Read the polling page. The address of the polling page must
// already be in r.
address MacroAssembler::read_polling_page(Register r, relocInfo::relocType rtype) {
InstructionMark im(this);
code_section()->relocate(inst_mark(), rtype);
ldrw(zr, Address(r, 0));
return inst_mark();
address mark;
{
InstructionMark im(this);
code_section()->relocate(inst_mark(), rtype);
ldrw(zr, Address(r, 0));
mark = inst_mark();
}
verify_cross_modify_fence_not_required();
return mark;
}

void MacroAssembler::adrp(Register reg1, const Address &dest, uint64_t &byte_offset) {
Expand Down Expand Up @@ -4455,6 +4459,7 @@ void MacroAssembler::build_frame(int framesize) {
sub(sp, sp, rscratch1);
}
}
verify_cross_modify_fence_not_required();
}

void MacroAssembler::remove_frame(int framesize) {
Expand Down Expand Up @@ -5315,3 +5320,29 @@ void MacroAssembler::verify_ptrue() {
stop("Error: the preserved predicate register (p7) elements are not all true");
bind(verify_ok);
}

void MacroAssembler::safepoint_isb() {
isb();
#ifndef PRODUCT
if (VerifyCrossModifyFence) {
// Clear the thread state.
strb(zr, Address(rthread, in_bytes(JavaThread::requires_cross_modify_fence_offset())));
}
#endif
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless VerifyCrossModifyFence is turned on in debug builds it will almost never be used. Please turn this on by default in AArch64 debug builds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha - Looks like your comments hadn't been made public until now.

The problem is it massively slows down a run. A tier1 test run for fastdebug went from 1h 32m 58s to
3h 43m 47s. I didn't think that would be acceptable.

#ifndef PRODUCT
void MacroAssembler::verify_cross_modify_fence_not_required() {
if (VerifyCrossModifyFence) {
// Check if thread needs a cross modify fence.
ldrb(rscratch1, Address(rthread, in_bytes(JavaThread::requires_cross_modify_fence_offset())));
Label fence_not_required;
cbz(rscratch1, fence_not_required);
// If it does then fail.
lea(rscratch1, CAST_FROM_FN_PTR(address, JavaThread::verify_cross_modify_fence_failure));
mov(c_rarg0, rthread);
blr(rscratch1);
bind(fence_not_required);
}
}
#endif
10 changes: 8 additions & 2 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1315,8 +1315,9 @@ class MacroAssembler: public Assembler {
Register zlen, Register tmp1, Register tmp2, Register tmp3,
Register tmp4, Register tmp5, Register tmp6, Register tmp7);
void mul_add(Register out, Register in, Register offs, Register len, Register k);
// ISB may be needed because of a safepoint
void maybe_isb() { isb(); }

// Place an ISB after code may have been modified due to a safepoint.
void safepoint_isb();

private:
// Return the effective address r + (r1 << ext) + offset.
Expand Down Expand Up @@ -1392,6 +1393,11 @@ class MacroAssembler: public Assembler {
}
void cache_wb(Address line);
void cache_wbsync(bool is_pre);

private:
// Check the current thread doesn't need a cross modify fence.
void verify_cross_modify_fence_not_required() PRODUCT_RETURN;

};

#ifdef ASSERT
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/cpu/aarch64/sharedRuntime_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ static void patch_callers_callsite(MacroAssembler *masm) {
__ mov(c_rarg1, lr);
__ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite)));
__ blr(rscratch1);
__ maybe_isb();

// Explicit isb required because fixup_callers_callsite may change the code
// stream.
__ safepoint_isb();

__ pop_CPU_state();
// restore sp
Expand Down Expand Up @@ -1150,7 +1153,6 @@ static void rt_call(MacroAssembler* masm, address dest) {
} else {
__ lea(rscratch1, RuntimeAddress(dest));
__ blr(rscratch1);
__ maybe_isb();
}
}

Expand Down Expand Up @@ -1857,7 +1859,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ verify_sve_vector_length();
}

// check for safepoint operation in progress and/or pending suspend requests
// Check for safepoint operation in progress and/or pending suspend requests.
{
// We need an acquire here to ensure that any subsequent load of the
// global SafepointSynchronize::_state flag is ordered after this load
Expand Down Expand Up @@ -2081,7 +2083,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
#endif
__ lea(rscratch1, RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
__ blr(rscratch1);
__ maybe_isb();

// Restore any method result value
restore_native_result(masm, ret_type, stack_slots);

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

__ reset_last_Java_frame(false);

__ maybe_isb();
__ membar(Assembler::LoadLoad | Assembler::LoadStore);

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

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

__ maybe_isb();

// r0 contains the address we are going to jump to assuming no exception got installed

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

// Set an oopmap for the call site. This oopmap will only be used if we
// are unwinding the stack. Hence, all locations will be dead.
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/cpu/aarch64/stubGenerator_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5629,7 +5629,6 @@ class StubGenerator: public StubCodeGenerator {
oop_maps->add_gc_map(the_pc - start, map);

__ reset_last_Java_frame(true);
__ maybe_isb();

if (UseSVE > 0) {
// Reinitialize the ptrue predicate register, in case the external runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,6 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
// Call the native method.
__ blr(r10);
__ bind(native_return);
__ maybe_isb();
__ get_method(rmethod);
// result potentially in r0 or v0

Expand Down Expand Up @@ -1410,7 +1409,6 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
__ mov(c_rarg0, rthread);
__ mov(rscratch2, CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans));
__ blr(rscratch2);
__ maybe_isb();
__ get_method(rmethod);
__ reinit_heapbase();
__ bind(Continue);
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/aix_ppc/orderAccess_aix_ppc.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -73,7 +73,7 @@ inline void OrderAccess::storeload() { inlasm_sync(); }
inline void OrderAccess::acquire() { inlasm_lwsync(); }
inline void OrderAccess::release() { inlasm_lwsync(); }
inline void OrderAccess::fence() { inlasm_sync(); }
inline void OrderAccess::cross_modify_fence()
inline void OrderAccess::cross_modify_fence_impl()
{ inlasm_isync(); }

#undef inlasm_sync
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/bsd_x86/orderAccess_bsd_x86.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -59,7 +59,7 @@ inline void OrderAccess::fence() {
compiler_barrier();
}

inline void OrderAccess::cross_modify_fence() {
inline void OrderAccess::cross_modify_fence_impl() {
int idx = 0;
__asm__ volatile ("cpuid " : "+a" (idx) : : "ebx", "ecx", "edx", "memory");
}
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/bsd_zero/orderAccess_bsd_zero.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright 2007, 2008, 2009 Red Hat, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -77,6 +77,6 @@ inline void OrderAccess::storeload() { FULL_MEM_BARRIER; }
inline void OrderAccess::acquire() { LIGHT_MEM_BARRIER; }
inline void OrderAccess::release() { LIGHT_MEM_BARRIER; }
inline void OrderAccess::fence() { FULL_MEM_BARRIER; }
inline void OrderAccess::cross_modify_fence() { }
inline void OrderAccess::cross_modify_fence_impl() { }

#endif // OS_CPU_BSD_ZERO_ORDERACCESS_BSD_ZERO_HPP
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2019, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -53,6 +53,8 @@ inline void OrderAccess::fence() {
FULL_MEM_BARRIER;
}

inline void OrderAccess::cross_modify_fence() { }
inline void OrderAccess::cross_modify_fence_impl() {
asm volatile("isb" : : : "memory");
}

#endif // OS_CPU_LINUX_AARCH64_ORDERACCESS_LINUX_AARCH64_HPP
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/linux_arm/orderAccess_linux_arm.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -101,6 +101,6 @@ inline void OrderAccess::storestore() { dmb_st(); }
inline void OrderAccess::storeload() { dmb_sy(); }
inline void OrderAccess::release() { dmb_sy(); }
inline void OrderAccess::fence() { dmb_sy(); }
inline void OrderAccess::cross_modify_fence() { }
inline void OrderAccess::cross_modify_fence_impl() { }

#endif // OS_CPU_LINUX_ARM_ORDERACCESS_LINUX_ARM_HPP
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/linux_ppc/orderAccess_linux_ppc.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2014 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -77,7 +77,7 @@ inline void OrderAccess::storeload() { inlasm_sync(); }
inline void OrderAccess::acquire() { inlasm_lwsync(); }
inline void OrderAccess::release() { inlasm_lwsync(); }
inline void OrderAccess::fence() { inlasm_sync(); }
inline void OrderAccess::cross_modify_fence()
inline void OrderAccess::cross_modify_fence_impl()
{ inlasm_isync(); }

#undef inlasm_sync
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/linux_s390/orderAccess_linux_s390.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -74,7 +74,7 @@ inline void OrderAccess::storeload() { inlasm_zarch_sync(); }
inline void OrderAccess::acquire() { inlasm_zarch_acquire(); }
inline void OrderAccess::release() { inlasm_zarch_release(); }
inline void OrderAccess::fence() { inlasm_zarch_sync(); }
inline void OrderAccess::cross_modify_fence() { inlasm_zarch_sync(); }
inline void OrderAccess::cross_modify_fence_impl() { inlasm_zarch_sync(); }

#undef inlasm_compiler_barrier
#undef inlasm_zarch_sync
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/linux_x86/orderAccess_linux_x86.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -55,7 +55,7 @@ inline void OrderAccess::fence() {
compiler_barrier();
}

inline void OrderAccess::cross_modify_fence() {
inline void OrderAccess::cross_modify_fence_impl() {
int idx = 0;
#ifdef AMD64
__asm__ volatile ("cpuid " : "+a" (idx) : : "ebx", "ecx", "edx", "memory");
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/linux_zero/orderAccess_linux_zero.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright 2007, 2008, 2009 Red Hat, Inc.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -78,6 +78,6 @@ inline void OrderAccess::acquire() { LIGHT_MEM_BARRIER; }
inline void OrderAccess::release() { LIGHT_MEM_BARRIER; }

inline void OrderAccess::fence() { FULL_MEM_BARRIER; }
inline void OrderAccess::cross_modify_fence() { }
inline void OrderAccess::cross_modify_fence_impl() { }

#endif // OS_CPU_LINUX_ZERO_ORDERACCESS_LINUX_ZERO_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// Included in orderAccess.hpp header file.
#include <atomic>
using std::atomic_thread_fence;
#include <intrin.h>
#include <arm64intr.h>
#include "vm_version_aarch64.hpp"
#include "runtime/vm_version.hpp"

Expand All @@ -55,6 +55,8 @@ inline void OrderAccess::fence() {
FULL_MEM_BARRIER;
}

inline void OrderAccess::cross_modify_fence() { }
inline void OrderAccess::cross_modify_fence_impl() {
__isb(_ARM64_BARRIER_SY);
}

#endif // OS_CPU_WINDOWS_AARCH64_ORDERACCESS_WINDOWS_AARCH64_HPP
4 changes: 2 additions & 2 deletions src/hotspot/os_cpu/windows_x86/orderAccess_windows_x86.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -58,7 +58,7 @@ inline void OrderAccess::fence() {
compiler_barrier();
}

inline void OrderAccess::cross_modify_fence() {
inline void OrderAccess::cross_modify_fence_impl() {
int regs[4];
__cpuid(regs, 0);
}
Expand Down
Loading