Skip to content

Commit fd331ff

Browse files
committed
8325469: Freeze/Thaw code can crash in the presence of OSR frames
Reviewed-by: rpressler, dlong
1 parent 9fd7802 commit fd331ff

16 files changed

+265
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ inline int frame::frame_size() const {
241241

242242
inline int frame::compiled_frame_stack_argsize() const {
243243
assert(cb()->is_nmethod(), "");
244-
return (cb()->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
244+
return (cb()->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
245245
}
246246

247247
inline void frame::interpreted_frame_oop_map(InterpreterOopMap* mask) const {

src/hotspot/cpu/aarch64/stackChunkFrameStream_aarch64.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ template <ChunkFrames frame_kind>
3535
inline bool StackChunkFrameStream<frame_kind>::is_in_frame(void* p0) const {
3636
assert(!is_done(), "");
3737
intptr_t* p = (intptr_t*)p0;
38-
int argsize = is_compiled() ? (_cb->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord : 0;
38+
int argsize = is_compiled() ? (_cb->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord : 0;
3939
int frame_size = _cb->frame_size() + argsize;
4040
return p == sp() - frame::sender_sp_offset || ((p - unextended_sp()) >= 0 && (p - unextended_sp()) < frame_size);
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ inline void frame::set_saved_oop_result(RegisterMap* map, oop obj) {
369369

370370
inline int frame::compiled_frame_stack_argsize() const {
371371
assert(cb()->is_nmethod(), "");
372-
return (cb()->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
372+
return (cb()->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
373373
}
374374

375375
inline void frame::interpreted_frame_oop_map(InterpreterOopMap* mask) const {

src/hotspot/cpu/ppc/stackChunkFrameStream_ppc.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ inline bool StackChunkFrameStream<frame_kind>::is_in_frame(void* p0) const {
3535
assert(!is_done(), "");
3636
assert(is_compiled(), "");
3737
intptr_t* p = (intptr_t*)p0;
38-
int argsize = (_cb->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
38+
int argsize = (_cb->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
3939
int frame_size = _cb->frame_size() + (argsize > 0 ? argsize + frame::metadata_words_at_top : 0);
4040
return (p - unextended_sp()) >= 0 && (p - unextended_sp()) < frame_size;
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ inline int frame::frame_size() const {
232232

233233
inline int frame::compiled_frame_stack_argsize() const {
234234
assert(cb()->is_nmethod(), "");
235-
return (cb()->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
235+
return (cb()->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
236236
}
237237

238238
inline void frame::interpreted_frame_oop_map(InterpreterOopMap* mask) const {

src/hotspot/cpu/riscv/stackChunkFrameStream_riscv.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <ChunkFrames frame_kind>
3434
inline bool StackChunkFrameStream<frame_kind>::is_in_frame(void* p0) const {
3535
assert(!is_done(), "");
3636
intptr_t* p = (intptr_t*)p0;
37-
int argsize = is_compiled() ? (_cb->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord : 0;
37+
int argsize = is_compiled() ? (_cb->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord : 0;
3838
int frame_size = _cb->frame_size() + argsize;
3939
return p == sp() - 2 || ((p - unextended_sp()) >= 0 && (p - unextended_sp()) < frame_size);
4040
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ inline int frame::frame_size() const {
227227

228228
inline int frame::compiled_frame_stack_argsize() const {
229229
assert(cb()->is_nmethod(), "");
230-
return (cb()->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
230+
return (cb()->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord;
231231
}
232232

233233
inline void frame::interpreted_frame_oop_map(InterpreterOopMap* mask) const {

src/hotspot/cpu/x86/stackChunkFrameStream_x86.inline.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ template <ChunkFrames frame_kind>
3434
inline bool StackChunkFrameStream<frame_kind>::is_in_frame(void* p0) const {
3535
assert(!is_done(), "");
3636
intptr_t* p = (intptr_t*)p0;
37-
int argsize = is_compiled() ? (_cb->as_nmethod()->method()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord : 0;
37+
int argsize = is_compiled() ? (_cb->as_nmethod()->num_stack_arg_slots() * VMRegImpl::stack_slot_size) >> LogBytesPerWord : 0;
3838
int frame_size = _cb->frame_size() + argsize;
3939
return p == sp() - frame::sender_sp_offset || ((p - unextended_sp()) >= 0 && (p - unextended_sp()) < frame_size);
4040
}

src/hotspot/share/code/nmethod.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,7 @@ nmethod::nmethod(
12301230
init_defaults();
12311231
_comp_level = CompLevel_none;
12321232
_entry_bci = InvocationEntryBci;
1233+
_num_stack_arg_slots = _method->constMethod()->num_stack_arg_slots();
12331234
// We have no exception handler or deopt handler make the
12341235
// values something that will never match a pc like the nmethod vtable entry
12351236
_exception_offset = 0;
@@ -1374,12 +1375,13 @@ nmethod::nmethod(
13741375
assert_locked_or_safepoint(CodeCache_lock);
13751376

13761377
init_defaults();
1377-
_entry_bci = entry_bci;
1378-
_compile_id = compile_id;
1379-
_compiler_type = type;
1380-
_comp_level = comp_level;
1381-
_orig_pc_offset = orig_pc_offset;
1382-
_gc_epoch = CodeCache::gc_epoch();
1378+
_entry_bci = entry_bci;
1379+
_num_stack_arg_slots = entry_bci != InvocationEntryBci ? 0 : _method->constMethod()->num_stack_arg_slots();
1380+
_compile_id = compile_id;
1381+
_compiler_type = type;
1382+
_comp_level = comp_level;
1383+
_orig_pc_offset = orig_pc_offset;
1384+
_gc_epoch = CodeCache::gc_epoch();
13831385

13841386
// Section offsets
13851387
_consts_offset = content_offset() + code_buffer->total_offset_of(code_buffer->consts());

src/hotspot/share/code/nmethod.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ class nmethod : public CodeBlob {
243243

244244
int _compile_id; // which compilation made this nmethod
245245

246+
int _num_stack_arg_slots; // Number of arguments passed on the stack
247+
246248
CompilerType _compiler_type; // which compiler made this nmethod (u1)
247249

248250
bool _is_unlinked;
@@ -792,6 +794,10 @@ class nmethod : public CodeBlob {
792794
nmethod* osr_link() const { return _osr_link; }
793795
void set_osr_link(nmethod *n) { _osr_link = n; }
794796

797+
int num_stack_arg_slots(bool rounded = true) const {
798+
return rounded ? align_up(_num_stack_arg_slots, 2) : _num_stack_arg_slots;
799+
}
800+
795801
// Verify calls to dead methods have been cleaned.
796802
void verify_clean_inline_caches();
797803

0 commit comments

Comments
 (0)