Skip to content

Commit

Permalink
Some ARM fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rickard Bäckman committed May 31, 2021
1 parent d29e238 commit 9e283a4
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 33 deletions.
5 changes: 5 additions & 0 deletions src/hotspot/cpu/aarch64/aarch64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -3648,6 +3648,8 @@ encode %{
}
}

__ post_call_nop();

// Only non uncommon_trap calls need to reinitialize ptrue.
if (Compile::current()->max_vector_size() >= 16 && uncommon_trap_request() == 0) {
__ reinitialize_ptrue();
Expand All @@ -3658,6 +3660,7 @@ encode %{
C2_MacroAssembler _masm(&cbuf);
int method_index = resolved_method_index(cbuf);
address call = __ ic_call((address)$meth$$method, method_index);
__ post_call_nop();
if (call == NULL) {
ciEnv::current()->record_failure("CodeCache is full");
return;
Expand Down Expand Up @@ -3685,6 +3688,7 @@ encode %{
CodeBlob *cb = CodeCache::find_blob(entry);
if (cb) {
address call = __ trampoline_call(Address(entry, relocInfo::runtime_call_type));
__ post_call_nop();
if (call == NULL) {
ciEnv::current()->record_failure("CodeCache is full");
return;
Expand All @@ -3697,6 +3701,7 @@ encode %{
__ stp(zr, rscratch2, Address(__ pre(sp, -2 * wordSize)));
__ blr(rscratch1);
__ bind(retaddr);
// __ post_call_nop(); -- can we have one here? do we need one?
__ add(sp, sp, 2 * wordSize);
}
if (Compile::current()->max_vector_size() >= 16) {
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,7 @@ void LIR_Assembler::call(LIR_OpJavaCall* op, relocInfo::relocType rtype) {
return;
}
add_call_info(code_offset(), op->info());
__ post_call_nop();
}


Expand All @@ -2070,6 +2071,7 @@ void LIR_Assembler::ic_call(LIR_OpJavaCall* op) {
return;
}
add_call_info(code_offset(), op->info());
__ post_call_nop();
}

void LIR_Assembler::emit_static_call_stub() {
Expand Down Expand Up @@ -2910,6 +2912,7 @@ void LIR_Assembler::rt_call(LIR_Opr result, address dest, const LIR_OprList* arg
if (info != NULL) {
add_call_info_here(info);
}
__ post_call_nop();
}

void LIR_Assembler::volatile_move_op(LIR_Opr src, LIR_Opr dest, BasicType type, CodeEmitInfo* info) {
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/cpu/aarch64/frame_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,12 @@ void frame::patch_pc(Thread* thread, address pc) {
// Either the return address is the original one or we are going to
// patch in the same address that's already there.
assert(_pc == *pc_addr || pc == *pc_addr, "must be");
DEBUG_ONLY(address old_pc = _pc;)
*pc_addr = pc;
_pc = pc; // must be set before call to get_deopt_original_pc
address original_pc = CompiledMethod::get_deopt_original_pc(this);
if (original_pc != NULL) {
assert(original_pc == _pc, "expected original PC to be stored before patching");
assert(original_pc == old_pc, "expected original PC to be stored before patching");
_deopt_state = is_deoptimized;
// leave _pc as is
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gc/shared/barrierSetNMethod.hpp"
#include "logging/log.hpp"
#include "memory/resourceArea.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/registerMap.hpp"
#include "runtime/thread.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "interpreter/oopMapCache.hpp"
#include "runtime/frame.inline.hpp"
#include "runtime/registerMap.hpp"

int InstanceStackChunkKlass::metadata_words() { return frame::sender_sp_offset; }
int InstanceStackChunkKlass::align_wiggle() { return 1; }
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/cpu/aarch64/macroAssembler_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,9 @@ class MacroAssembler: public Assembler {
// Alignment
void align(int modulus);

// nop
void post_call_nop() { nop(); }

// Stack frame creation/removal
void enter()
{
Expand Down
23 changes: 9 additions & 14 deletions src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,22 +546,12 @@ address NativeCall::trampoline_jump(CodeBuffer &cbuf, address dest) {
}

void NativePostCallNop::make_deopt() {
// TODO LOOM AARCH64
NativeDeoptInstruction::insert(addr_at(0));
// makes the first 2 bytes into UD, the rest is thrash. Make NOPs to help debugging.
set_char_at(2, 0x90);
set_char_at(3, 0x90);
set_char_at(4, 0x90);
set_char_at(5, 0x90);
set_char_at(6, 0x90);
set_char_at(7, 0x90);
}

void NativePostCallNop::patch(jint diff) {
// TODO LOOM AARCH64
assert(diff != 0, "must be");
int32_t *code_pos = (int32_t *) addr_at(displacement_offset);
*((int32_t *)(code_pos)) = (int32_t) diff;
// unsupported for now
}

void NativeDeoptInstruction::verify() {
Expand All @@ -570,7 +560,12 @@ void NativeDeoptInstruction::verify() {
// Inserts an undefined instruction at a given pc
void NativeDeoptInstruction::insert(address code_pos) {
// TODO LOOM AARCH64
*code_pos = instruction_prefix;
*(code_pos+1) = instruction_code;
ICache::invalidate_range(code_pos, instruction_size);
// 1 1 0 1 | 0 1 0 0 | 0 0 1 imm16 0 0 0 0 0
// d | 4 | 2 | 0 | 0 | 0 |
// 0xd4, 0x20, 0x00, 0x00
*code_pos = 0xd4;
*(code_pos+1) = 0x20;
*(code_pos+2) = 0x00;
*(code_pos+3) = 0x00;
ICache::invalidate_range(code_pos, 4);
}
25 changes: 9 additions & 16 deletions src/hotspot/cpu/aarch64/nativeInst_aarch64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class NativeInstruction {
return (encoding() & 0xff000000) == 0x10000000;
}

inline bool is_nop();
inline bool is_nop() const;
bool is_jump();
bool is_general_jump();
inline bool is_jump_or_nop();
Expand Down Expand Up @@ -543,7 +543,7 @@ class NativeTstRegMem: public NativeInstruction {
public:
};

inline bool NativeInstruction::is_nop() {
inline bool NativeInstruction::is_nop() const{
uint32_t insn = *(uint32_t*)addr_at(0);
return insn == 0xd503201f;
}
Expand Down Expand Up @@ -668,15 +668,8 @@ inline NativeLdSt* NativeLdSt_at(address addr) {

class NativePostCallNop: public NativeInstruction {
public:
enum Intel_specific_constants { // TODO LOOM AARCH64
instruction_code = 0x0f,
instruction_size = 8,
instruction_offset = 0,
displacement_offset = 4
};

bool check() const { return int_at(0) == 0x841f0f; }
int displacement() const { return (jint) int_at(displacement_offset); }
bool check() const { return is_nop(); }
int displacement() const { return 0; }
void patch(jint diff);
void make_deopt();
};
Expand All @@ -698,9 +691,7 @@ inline NativePostCallNop* nativePostCallNop_unsafe_at(address address) {
class NativeDeoptInstruction: public NativeInstruction {
public:
enum Intel_specific_constants { // TODO LOOM AARCH64
instruction_prefix = 0x0F,
instruction_code = 0xFF,
instruction_size = 2,
instruction_size = 4,
instruction_offset = 0,
};

Expand All @@ -710,8 +701,10 @@ class NativeDeoptInstruction: public NativeInstruction {
void verify();

static bool is_deopt_at(address instr) {
return ((*instr) & 0xFF) == NativeDeoptInstruction::instruction_prefix &&
((*(instr+1)) & 0xFF) == NativeDeoptInstruction::instruction_code;
return ((*instr) & 0xFF) == 0xd4 &&
((*(instr+1)) & 0xFF) == 0x20 &&
((*(instr+2)) & 0xFF) == 0x00 &&
((*(instr+3)) & 0xFF) == 0x00;
}

// MT-safe patching
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/cpu/arm/frame_arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ void frame::patch_pc(Thread* thread, address pc) {
tty->print_cr("patch_pc at address" INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "] ",
p2i(pc_addr), p2i(*pc_addr), p2i(pc));
}
DEBUG_ONLY(address old_pc = _pc;)
*pc_addr = pc;
_pc = pc; // must be set before call to get_deopt_original_pc
address original_pc = CompiledMethod::get_deopt_original_pc(this);
if (original_pc != NULL) {
assert(original_pc == _pc, "expected original PC to be stored before patching");
assert(original_pc == old_pc, "expected original PC to be stored before patching");
_deopt_state = is_deoptimized;
// leave _pc as is
} else {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/cpu/x86/stubGenerator_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3891,6 +3891,7 @@ class StubGenerator: public StubCodeGenerator {
StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = StubRoutines::_oop_disjoint_arraycopy_uninit;
StubRoutines::_arrayof_oop_arraycopy_uninit = StubRoutines::_oop_arraycopy_uninit;

StubRoutines::_has_word_memcpy = true;
StubRoutines::_word_memcpy_up = generate_disjoint_word_copy_up (false, "word_memcpy_up");
StubRoutines::_word_memcpy_up_nt = generate_disjoint_word_copy_up (true, "word_memcpy_up_nt");
StubRoutines::_word_memcpy_down = generate_disjoint_word_copy_down(0, "word_memcpy_down");
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/code/codeBlob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "asm/codeBuffer.hpp"
#include "compiler/compilerDefinitions.hpp"
#include "compiler/oopMap.inline.hpp"
#include "runtime/frame.hpp"
#include "runtime/handles.hpp"
#include "utilities/align.hpp"
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/oops/instanceStackChunkKlass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*
*/

#include "compiler/oopMap.inline.hpp"
#include "oops/instanceStackChunkKlass.hpp"
#include "gc/shared/gc_globals.hpp"
#include "memory/resourceArea.hpp"
Expand Down Expand Up @@ -157,7 +158,7 @@ MemcpyFnT InstanceStackChunkKlass::memcpy_fn_from_stack_to_chunk = nullptr;
MemcpyFnT InstanceStackChunkKlass::memcpy_fn_from_chunk_to_stack = nullptr;

void InstanceStackChunkKlass::resolve_memcpy_functions() {
if (UseNewCode) {
if (!StubRoutines::has_word_memcpy() || UseNewCode) {
// tty->print_cr(">> Config memcpy: default");
memcpy_fn_from_stack_to_chunk = (MemcpyFnT)InstanceStackChunkKlass::default_memcpy;
memcpy_fn_from_chunk_to_stack = (MemcpyFnT)InstanceStackChunkKlass::default_memcpy;
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/runtime/stubRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ address StubRoutines::_jlong_disjoint_arraycopy = CAST_FROM_FN_PTR(addr
address StubRoutines::_oop_disjoint_arraycopy = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy);
address StubRoutines::_oop_disjoint_arraycopy_uninit = CAST_FROM_FN_PTR(address, StubRoutines::oop_copy_uninit);

bool StubRoutines::_has_word_memcpy = false;
address StubRoutines::_word_memcpy_up = NULL; // CAST_FROM_FN_PTR(address, StubRoutines::jint_copy);
address StubRoutines::_word_memcpy_down = NULL; // CAST_FROM_FN_PTR(address, StubRoutines::jint_copy);
address StubRoutines::_word_memcpy_up_nt = NULL; // CAST_FROM_FN_PTR(address, StubRoutines::jint_copy);
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/runtime/stubRoutines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class StubRoutines: AllStatic {
static address _jlong_disjoint_arraycopy;
static address _oop_disjoint_arraycopy, _oop_disjoint_arraycopy_uninit;

static bool _has_word_memcpy;
static address _word_memcpy_up;
static address _word_memcpy_down;
static address _word_memcpy_up_nt;
Expand Down Expand Up @@ -359,6 +360,7 @@ class StubRoutines: AllStatic {
static address jint_arraycopy() { return _jint_arraycopy; }
static address jlong_arraycopy() { return _jlong_arraycopy; }

static bool has_word_memcpy() { return _has_word_memcpy; }
static address word_memcpy_up() { return _word_memcpy_up; }
static address word_memcpy_up_nt() { return _word_memcpy_up_nt; }
static address word_memcpy_down() { return _word_memcpy_down; }
Expand Down

0 comments on commit 9e283a4

Please sign in to comment.