Skip to content

Commit 2e472fe

Browse files
committedJan 10, 2024
8322294: Cleanup NativePostCallNop
Reviewed-by: mdoerr, aph
1 parent 88dafe5 commit 2e472fe

30 files changed

+86
-149
lines changed
 

‎src/hotspot/cpu/aarch64/frame_aarch64.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@
156156
static void verify_deopt_original_pc( CompiledMethod* nm, intptr_t* unextended_sp);
157157
#endif
158158

159-
const ImmutableOopMap* get_oop_map() const;
160-
161159
public:
162160
// Constructors
163161

‎src/hotspot/cpu/aarch64/frame_aarch64.inline.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -359,20 +359,6 @@ inline int frame::sender_sp_ret_address_offset() {
359359
return frame::sender_sp_offset - frame::return_addr_offset;
360360
}
361361

362-
inline const ImmutableOopMap* frame::get_oop_map() const {
363-
if (_cb == nullptr) return nullptr;
364-
if (_cb->oop_maps() != nullptr) {
365-
NativePostCallNop* nop = nativePostCallNop_at(_pc);
366-
if (nop != nullptr && nop->displacement() != 0) {
367-
int slot = ((nop->displacement() >> 24) & 0xff);
368-
return _cb->oop_map_for_slot(slot, _pc);
369-
}
370-
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
371-
return oop_map;
372-
}
373-
return nullptr;
374-
}
375-
376362
//------------------------------------------------------------------------------
377363
// frame::sender
378364
inline frame frame::sender(RegisterMap* map) const {

‎src/hotspot/cpu/aarch64/nativeInst_aarch64.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -560,18 +560,23 @@ static bool is_movk_to_zr(uint32_t insn) {
560560
}
561561
#endif
562562

563-
void NativePostCallNop::patch(jint diff) {
563+
bool NativePostCallNop::patch(int32_t oopmap_slot, int32_t cb_offset) {
564+
if (((oopmap_slot & 0xff) != oopmap_slot) || ((cb_offset & 0xffffff) != cb_offset)) {
565+
return false; // cannot encode
566+
}
567+
uint32_t data = ((uint32_t)oopmap_slot << 24) | cb_offset;
564568
#ifdef ASSERT
565-
assert(diff != 0, "must be");
569+
assert(data != 0, "must be");
566570
uint32_t insn1 = uint_at(4);
567571
uint32_t insn2 = uint_at(8);
568572
assert (is_movk_to_zr(insn1) && is_movk_to_zr(insn2), "must be");
569573
#endif
570574

571-
uint32_t lo = diff & 0xffff;
572-
uint32_t hi = (uint32_t)diff >> 16;
575+
uint32_t lo = data & 0xffff;
576+
uint32_t hi = data >> 16;
573577
Instruction_aarch64::patch(addr_at(4), 20, 5, lo);
574578
Instruction_aarch64::patch(addr_at(8), 20, 5, hi);
579+
return true; // successfully encoded
575580
}
576581

577582
void NativeDeoptInstruction::verify() {

‎src/hotspot/cpu/aarch64/nativeInst_aarch64.hpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -691,16 +691,20 @@ class NativePostCallNop: public NativeInstruction {
691691
return (insns & 0xffe0001fffffffff) == 0xf280001fd503201f;
692692
}
693693

694-
jint displacement() const {
694+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const {
695695
uint64_t movk_insns = *(uint64_t*)addr_at(4);
696696
uint32_t lo = (movk_insns >> 5) & 0xffff;
697697
uint32_t hi = (movk_insns >> (5 + 32)) & 0xffff;
698-
uint32_t result = (hi << 16) | lo;
699-
700-
return (jint)result;
698+
uint32_t data = (hi << 16) | lo;
699+
if (data == 0) {
700+
return false; // no information encoded
701+
}
702+
cb_offset = (data & 0xffffff);
703+
oopmap_slot = (data >> 24) & 0xff;
704+
return true; // decoding succeeded
701705
}
702706

703-
void patch(jint diff);
707+
bool patch(int32_t oopmap_slot, int32_t cb_offset);
704708
void make_deopt();
705709
};
706710

‎src/hotspot/cpu/arm/frame_arm.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,6 @@
9999
}
100100
#endif
101101

102-
const ImmutableOopMap* get_oop_map() const;
103-
104102
public:
105103
// Constructors
106104

‎src/hotspot/cpu/arm/frame_arm.inline.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -218,20 +218,6 @@ inline int frame::frame_size() const {
218218
return sender_sp() - sp();
219219
}
220220

221-
inline const ImmutableOopMap* frame::get_oop_map() const {
222-
if (_cb == nullptr) return nullptr;
223-
if (_cb->oop_maps() != nullptr) {
224-
NativePostCallNop* nop = nativePostCallNop_at(_pc);
225-
if (nop != nullptr && nop->displacement() != 0) {
226-
int slot = ((nop->displacement() >> 24) & 0xff);
227-
return _cb->oop_map_for_slot(slot, _pc);
228-
}
229-
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
230-
return oop_map;
231-
}
232-
return nullptr;
233-
}
234-
235221
inline int frame::compiled_frame_stack_argsize() const {
236222
Unimplemented();
237223
return 0;

‎src/hotspot/cpu/arm/nativeInst_arm_32.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,6 @@ void NativePostCallNop::make_deopt() {
341341
NativeDeoptInstruction::insert(addr_at(0));
342342
}
343343

344-
void NativePostCallNop::patch(jint diff) {
345-
// unsupported for now
346-
}
347-
348344
void NativeDeoptInstruction::verify() {
349345
}
350346

‎src/hotspot/cpu/arm/nativeInst_arm_32.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,8 @@ inline NativeCall* nativeCall_before(address return_address) {
438438
class NativePostCallNop: public NativeInstruction {
439439
public:
440440
bool check() const { return is_nop(); }
441-
int displacement() const { return 0; }
442-
void patch(jint diff);
441+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const { return false; }
442+
bool patch(int32_t oopmap_slot, int32_t cb_offset) { return false; }
443443
void make_deopt();
444444
};
445445

‎src/hotspot/cpu/ppc/frame_ppc.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,6 @@
400400

401401
public:
402402

403-
const ImmutableOopMap* get_oop_map() const;
404-
405403
// Constructors
406404
inline frame(intptr_t* sp, intptr_t* fp, address pc);
407405
inline frame(intptr_t* sp, address pc, intptr_t* unextended_sp = nullptr, intptr_t* fp = nullptr, CodeBlob* cb = nullptr);

‎src/hotspot/cpu/ppc/frame_ppc.inline.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -361,20 +361,6 @@ inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) {
361361
*result_adr = obj;
362362
}
363363

364-
inline const ImmutableOopMap* frame::get_oop_map() const {
365-
if (_cb == nullptr) return nullptr;
366-
if (_cb->oop_maps() != nullptr) {
367-
NativePostCallNop* nop = nativePostCallNop_at(_pc);
368-
if (nop != nullptr && nop->displacement() != 0) {
369-
int slot = ((nop->displacement() >> 24) & 0xff);
370-
return _cb->oop_map_for_slot(slot, _pc);
371-
}
372-
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
373-
return oop_map;
374-
}
375-
return nullptr;
376-
}
377-
378364
inline int frame::compiled_frame_stack_argsize() const {
379365
assert(cb()->is_compiled(), "");
380366
return (cb()->as_compiled_method()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;

‎src/hotspot/cpu/ppc/nativeInst_ppc.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,6 @@ void NativePostCallNop::make_deopt() {
429429
NativeDeoptInstruction::insert(addr_at(0));
430430
}
431431

432-
void NativePostCallNop::patch(jint diff) {
433-
// unsupported for now
434-
}
435-
436432
void NativeDeoptInstruction::verify() {
437433
}
438434

‎src/hotspot/cpu/ppc/nativeInst_ppc.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@ class NativeMovRegMem: public NativeInstruction {
508508
class NativePostCallNop: public NativeInstruction {
509509
public:
510510
bool check() const { return is_nop(); }
511-
int displacement() const { return 0; }
512-
void patch(jint diff);
511+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const { return false; }
512+
bool patch(int32_t oopmap_slot, int32_t cb_offset) { return false; }
513513
void make_deopt();
514514
};
515515

‎src/hotspot/cpu/riscv/frame_riscv.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@
189189
static void verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp);
190190
#endif
191191

192-
const ImmutableOopMap* get_oop_map() const;
193-
194192
public:
195193
// Constructors
196194

‎src/hotspot/cpu/riscv/frame_riscv.inline.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,6 @@ inline int frame::sender_sp_ret_address_offset() {
345345
return frame::sender_sp_offset - frame::return_addr_offset;
346346
}
347347

348-
inline const ImmutableOopMap* frame::get_oop_map() const {
349-
if (_cb == nullptr) return nullptr;
350-
if (_cb->oop_maps() != nullptr) {
351-
NativePostCallNop* nop = nativePostCallNop_at(_pc);
352-
if (nop != nullptr && nop->displacement() != 0) {
353-
int slot = ((nop->displacement() >> 24) & 0xff);
354-
return _cb->oop_map_for_slot(slot, _pc);
355-
}
356-
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
357-
return oop_map;
358-
}
359-
return nullptr;
360-
}
361-
362348
//------------------------------------------------------------------------------
363349
// frame::sender
364350
frame frame::sender(RegisterMap* map) const {

‎src/hotspot/cpu/riscv/nativeInst_riscv.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -451,16 +451,27 @@ void NativePostCallNop::make_deopt() {
451451
NativeDeoptInstruction::insert(addr_at(0));
452452
}
453453

454-
int NativePostCallNop::displacement() const {
454+
bool NativePostCallNop::decode(int32_t& oopmap_slot, int32_t& cb_offset) const {
455455
// Discard the high 32 bits
456-
return (int)(intptr_t)MacroAssembler::get_target_of_li32(addr_at(4));
456+
int32_t data = (int32_t)(intptr_t)MacroAssembler::get_target_of_li32(addr_at(4));
457+
if (data == 0) {
458+
return false; // no information encoded
459+
}
460+
cb_offset = (data & 0xffffff);
461+
oopmap_slot = (data >> 24) & 0xff;
462+
return true; // decoding succeeded
457463
}
458464

459-
void NativePostCallNop::patch(jint diff) {
460-
assert(diff != 0, "must be");
465+
bool NativePostCallNop::patch(int32_t oopmap_slot, int32_t cb_offset) {
466+
if (((oopmap_slot & 0xff) != oopmap_slot) || ((cb_offset & 0xffffff) != cb_offset)) {
467+
return false; // cannot encode
468+
}
469+
int32_t data = (oopmap_slot << 24) | cb_offset;
470+
assert(data != 0, "must be");
461471
assert(is_lui_to_zr_at(addr_at(4)) && is_addiw_to_zr_at(addr_at(8)), "must be");
462472

463-
MacroAssembler::patch_imm_in_li32(addr_at(4), diff);
473+
MacroAssembler::patch_imm_in_li32(addr_at(4), data);
474+
return true; // successfully encoded
464475
}
465476

466477
void NativeDeoptInstruction::verify() {

‎src/hotspot/cpu/riscv/nativeInst_riscv.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ class NativePostCallNop: public NativeInstruction {
591591
// an addiw as well.
592592
return is_nop() && is_lui_to_zr_at(addr_at(4));
593593
}
594-
int displacement() const;
595-
void patch(jint diff);
594+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const;
595+
bool patch(int32_t oopmap_slot, int32_t cb_offset);
596596
void make_deopt();
597597
};
598598

‎src/hotspot/cpu/s390/frame_s390.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,6 @@
465465

466466
// Initialize frame members (_pc and _sp must be given)
467467
inline void setup();
468-
const ImmutableOopMap* get_oop_map() const;
469468

470469
// Constructors
471470

‎src/hotspot/cpu/s390/frame_s390.inline.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,6 @@ inline intptr_t* frame::real_fp() const {
292292
return fp();
293293
}
294294

295-
inline const ImmutableOopMap* frame::get_oop_map() const {
296-
if (_cb == nullptr) return nullptr;
297-
if (_cb->oop_maps() != nullptr) {
298-
NativePostCallNop* nop = nativePostCallNop_at(_pc);
299-
if (nop != nullptr && nop->displacement() != 0) {
300-
int slot = ((nop->displacement() >> 24) & 0xff);
301-
return _cb->oop_map_for_slot(slot, _pc);
302-
}
303-
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
304-
return oop_map;
305-
}
306-
return nullptr;
307-
}
308-
309295
inline int frame::compiled_frame_stack_argsize() const {
310296
Unimplemented();
311297
return 0;

‎src/hotspot/cpu/s390/nativeInst_s390.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,8 @@ class NativeGeneralJump: public NativeInstruction {
657657
class NativePostCallNop: public NativeInstruction {
658658
public:
659659
bool check() const { Unimplemented(); return false; }
660-
int displacement() const { return 0; }
661-
void patch(jint diff) { Unimplemented(); }
660+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const { return false; }
661+
bool patch(int32_t oopmap_slot, int32_t cb_offset) { Unimplemented(); return false; }
662662
void make_deopt() { Unimplemented(); }
663663
};
664664

‎src/hotspot/cpu/x86/frame_x86.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@
149149
static void verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp);
150150
#endif
151151

152-
const ImmutableOopMap* get_oop_map() const;
153-
154152
public:
155153
// Constructors
156154

‎src/hotspot/cpu/x86/frame_x86.inline.hpp

-14
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,6 @@ inline int frame::sender_sp_ret_address_offset() {
343343
return frame::sender_sp_offset - frame::return_addr_offset;
344344
}
345345

346-
inline const ImmutableOopMap* frame::get_oop_map() const {
347-
if (_cb == nullptr) return nullptr;
348-
if (_cb->oop_maps() != nullptr) {
349-
NativePostCallNop* nop = nativePostCallNop_at(_pc);
350-
if (nop != nullptr && nop->displacement() != 0) {
351-
int slot = ((nop->displacement() >> 24) & 0xff);
352-
return _cb->oop_map_for_slot(slot, _pc);
353-
}
354-
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
355-
return oop_map;
356-
}
357-
return nullptr;
358-
}
359-
360346
//------------------------------------------------------------------------------
361347
// frame::sender
362348

‎src/hotspot/cpu/x86/nativeInst_x86.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,15 @@ void NativePostCallNop::make_deopt() {
684684
ICache::invalidate_range(instr_addr, instruction_size);
685685
}
686686

687-
void NativePostCallNop::patch(jint diff) {
688-
assert(diff != 0, "must be");
687+
bool NativePostCallNop::patch(int32_t oopmap_slot, int32_t cb_offset) {
688+
if (((oopmap_slot & 0xff) != oopmap_slot) || ((cb_offset & 0xffffff) != cb_offset)) {
689+
return false; // cannot encode
690+
}
691+
int32_t data = (oopmap_slot << 24) | cb_offset;
692+
assert(data != 0, "must be");
689693
int32_t *code_pos = (int32_t *) addr_at(displacement_offset);
690-
*((int32_t *)(code_pos)) = (int32_t) diff;
694+
*((int32_t *)(code_pos)) = (int32_t) data;
695+
return true; // successfully encoded
691696
}
692697

693698
void NativeDeoptInstruction::verify() {

‎src/hotspot/cpu/x86/nativeInst_x86.hpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,16 @@ class NativePostCallNop: public NativeInstruction {
735735
};
736736

737737
bool check() const { return int_at(0) == 0x841f0f; }
738-
int displacement() const { return (jint) int_at(displacement_offset); }
739-
void patch(jint diff);
738+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const {
739+
int32_t data = int_at(displacement_offset);
740+
if (data == 0) {
741+
return false; // no information encoded
742+
}
743+
cb_offset = (data & 0xffffff);
744+
oopmap_slot = (data >> 24) & 0xff;
745+
return true; // decoding succeeded
746+
}
747+
bool patch(int32_t oopmap_slot, int32_t cb_offset);
740748
void make_deopt();
741749
};
742750

‎src/hotspot/cpu/zero/frame_zero.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
align_wiggle = 1
4545
};
4646

47-
const ImmutableOopMap* get_oop_map() const;
48-
4947
// Constructor
5048
public:
5149
frame(ZeroFrame* zeroframe, intptr_t* sp);

‎src/hotspot/cpu/zero/frame_zero.inline.hpp

-5
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,6 @@ inline intptr_t* frame::unextended_sp() const {
176176
return (intptr_t *) -1;
177177
}
178178

179-
inline const ImmutableOopMap* frame::get_oop_map() const {
180-
Unimplemented();
181-
return nullptr;
182-
}
183-
184179
inline int frame::compiled_frame_stack_argsize() const {
185180
Unimplemented();
186181
return 0;

‎src/hotspot/cpu/zero/nativeInst_zero.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ inline NativeGeneralJump* nativeGeneralJump_at(address address) {
214214
class NativePostCallNop: public NativeInstruction {
215215
public:
216216
bool check() const { Unimplemented(); return false; }
217-
int displacement() const { Unimplemented(); return 0; }
218-
void patch(jint diff) { Unimplemented(); }
217+
bool decode(int32_t& oopmap_slot, int32_t& cb_offset) const { Unimplemented(); return false; }
218+
bool patch(int32_t oopmap_slot, int32_t cb_offset) { Unimplemented(); return false; }
219219
void make_deopt() { Unimplemented(); }
220220
};
221221

‎src/hotspot/share/code/codeCache.inline.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ inline CodeBlob* CodeCache::find_blob_fast(void* pc) {
3737
inline CodeBlob* CodeCache::find_blob_and_oopmap(void* pc, int& slot) {
3838
NativePostCallNop* nop = nativePostCallNop_at((address) pc);
3939
CodeBlob* cb;
40-
if (nop != nullptr && nop->displacement() != 0) {
41-
int offset = (nop->displacement() & 0xffffff);
40+
int offset;
41+
if (nop != nullptr && nop->decode(slot, offset)) {
4242
cb = (CodeBlob*) ((address) pc - offset);
43-
slot = ((nop->displacement() >> 24) & 0xff);
4443
assert(cb == CodeCache::find_blob(pc), "must be");
4544
} else {
4645
cb = CodeCache::find_blob(pc);
@@ -52,9 +51,12 @@ inline CodeBlob* CodeCache::find_blob_and_oopmap(void* pc, int& slot) {
5251

5352
inline int CodeCache::find_oopmap_slot_fast(void* pc) {
5453
NativePostCallNop* nop = nativePostCallNop_at((address) pc);
55-
return (nop != nullptr && nop->displacement() != 0)
56-
? ((nop->displacement() >> 24) & 0xff)
57-
: -1;
54+
int oopmap_slot;
55+
int cb_offset;
56+
if (nop != nullptr && nop->decode(oopmap_slot, cb_offset)) {
57+
return oopmap_slot;
58+
}
59+
return -1;
5860
}
5961

6062
#endif // SHARE_VM_COMPILER_CODECACHE_INLINE_HPP

‎src/hotspot/share/code/nmethod.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -1137,10 +1137,7 @@ static void install_post_call_nop_displacement(nmethod* nm, address pc) {
11371137
int oopmap_slot = nm->oop_maps()->find_slot_for_offset(int((intptr_t) pc - (intptr_t) nm->code_begin()));
11381138
if (oopmap_slot < 0) { // this can happen at asynchronous (non-safepoint) stackwalks
11391139
log_debug(codecache)("failed to find oopmap for cb: " INTPTR_FORMAT " offset: %d", cbaddr, (int) offset);
1140-
} else if (((oopmap_slot & 0xff) == oopmap_slot) && ((offset & 0xffffff) == offset)) {
1141-
jint value = (oopmap_slot << 24) | (jint) offset;
1142-
nop->patch(value);
1143-
} else {
1140+
} else if (!nop->patch(oopmap_slot, offset)) {
11441141
log_debug(codecache)("failed to encode %d %d", oopmap_slot, (int) offset);
11451142
}
11461143
}

‎src/hotspot/share/runtime/frame.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class frame {
9090
void assert_offset() const { assert(_frame_index >= 0, "Using offset with a non-chunk frame"); assert_on_heap(); }
9191
void assert_absolute() const { assert(_frame_index == -1, "Using absolute addresses with a chunk frame"); }
9292

93+
const ImmutableOopMap* get_oop_map() const;
94+
9395
public:
9496
// Constructors
9597
frame();

‎src/hotspot/share/runtime/frame.inline.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,19 @@ inline CodeBlob* frame::get_cb() const {
104104
return _cb;
105105
}
106106

107+
inline const ImmutableOopMap* frame::get_oop_map() const {
108+
if (_cb == nullptr || _cb->oop_maps() == nullptr) return nullptr;
109+
110+
NativePostCallNop* nop = nativePostCallNop_at(_pc);
111+
int oopmap_slot;
112+
int cb_offset;
113+
if (nop != nullptr && nop->decode(oopmap_slot, cb_offset)) {
114+
return _cb->oop_map_for_slot(oopmap_slot, _pc);
115+
}
116+
const ImmutableOopMap* oop_map = OopMapSet::find_map(this);
117+
return oop_map;
118+
}
119+
107120
inline int frame::interpreter_frame_monitor_size_in_bytes() {
108121
// Number of bytes for a monitor.
109122
return frame::interpreter_frame_monitor_size() * wordSize;

0 commit comments

Comments
 (0)
Please sign in to comment.