Skip to content

Commit f25e719

Browse files
committed
8268717: Upstream: 8268673: Stack walk across optimized entry frame on fresh native thread fails
Reviewed-by: mcimadamore, erikj
1 parent 22ebd19 commit f25e719

12 files changed

Lines changed: 198 additions & 1 deletion

File tree

make/test/JtregNativeJdk.gmk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ BUILD_JDK_JTREG_EXECUTABLES_CFLAGS_exeJliLaunchTest := \
5353
-I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS_TYPE)/native/libjli \
5454
-I$(TOPDIR)/src/java.base/$(OPENJDK_TARGET_OS)/native/libjli
5555

56+
BUILD_JDK_JTREG_LIBRARIES_LDFLAGS_libAsyncStackWalk := $(LIBCXX)
57+
5658
# Platform specific setup
5759
ifeq ($(call isTargetOs, windows), true)
5860
BUILD_JDK_JTREG_EXCLUDE += libDirectIO.c libInheritedChannel.c exelauncher.c
@@ -63,6 +65,7 @@ ifeq ($(call isTargetOs, windows), true)
6365
BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeJliLaunchTest := $(WIN_LIB_JLI)
6466
BUILD_JDK_JTREG_EXECUTABLES_LIBS_exeCallerAccessTest := jvm.lib
6567
BUILD_JDK_JTREG_EXECUTABLES_LIBS_exerevokeall := advapi32.lib
68+
BUILD_JDK_JTREG_LIBRARIES_CFLAGS_libAsyncStackWalk := /EHsc
6669
else
6770
BUILD_JDK_JTREG_LIBRARIES_LIBS_libstringPlatformChars := -ljava
6871
BUILD_JDK_JTREG_LIBRARIES_LIBS_libDirectIO := -ljava

src/hotspot/cpu/aarch64/frame_aarch64.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ JavaFrameAnchor* OptimizedEntryBlob::jfa_for_frame(const frame& frame) const {
367367
return nullptr;
368368
}
369369

370+
bool frame::optimized_entry_frame_is_first() const {
371+
ShouldNotCallThis();
372+
return false;
373+
}
374+
370375
frame frame::sender_for_optimized_entry_frame(RegisterMap* map) const {
371376
ShouldNotCallThis();
372377
return {};

src/hotspot/cpu/arm/frame_arm.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ frame frame::sender_for_entry_frame(RegisterMap* map) const {
313313
return fr;
314314
}
315315

316+
bool frame::optimized_entry_frame_is_first() const {
317+
ShouldNotCallThis();
318+
return false;
319+
}
320+
316321
//------------------------------------------------------------------------------
317322
// frame::verify_deopt_original_pc
318323
//

src/hotspot/cpu/ppc/frame_ppc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ frame frame::sender_for_entry_frame(RegisterMap *map) const {
197197
return fr;
198198
}
199199

200+
bool frame::optimized_entry_frame_is_first() const {
201+
ShouldNotCallThis();
202+
return false;
203+
}
204+
200205
frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
201206
// Pass callers initial_caller_sp as unextended_sp.
202207
return frame(sender_sp(), sender_pc(), (intptr_t*)get_ijava_state()->sender_sp);

src/hotspot/cpu/s390/frame_s390.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ frame frame::sender_for_entry_frame(RegisterMap *map) const {
208208
return fr;
209209
}
210210

211+
bool frame::optimized_entry_frame_is_first() const {
212+
ShouldNotCallThis();
213+
return false;
214+
}
215+
211216
frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
212217
// Pass callers sender_sp as unextended_sp.
213218
return frame(sender_sp(), sender_pc(), (intptr_t*)(ijava_state()->sender_sp));

src/hotspot/cpu/x86/frame_x86.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,20 @@ JavaFrameAnchor* OptimizedEntryBlob::jfa_for_frame(const frame& frame) const {
358358
return reinterpret_cast<JavaFrameAnchor*>(reinterpret_cast<char*>(frame.unextended_sp()) + in_bytes(jfa_sp_offset()));
359359
}
360360

361+
bool frame::optimized_entry_frame_is_first() const {
362+
assert(is_optimized_entry_frame(), "must be optimzed entry frame");
363+
OptimizedEntryBlob* blob = _cb->as_optimized_entry_blob();
364+
JavaFrameAnchor* jfa = blob->jfa_for_frame(*this);
365+
return jfa->last_Java_sp() == NULL;
366+
}
367+
361368
frame frame::sender_for_optimized_entry_frame(RegisterMap* map) const {
362369
assert(map != NULL, "map must be set");
363370
OptimizedEntryBlob* blob = _cb->as_optimized_entry_blob();
364371
// Java frame called from C; skip all C frames and return top C
365372
// frame of that chunk as the sender
366373
JavaFrameAnchor* jfa = blob->jfa_for_frame(*this);
374+
assert(!optimized_entry_frame_is_first(), "must have a frame anchor to go back to");
367375
assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
368376
// Since we are walking the stack now this nested anchor is obviously walkable
369377
// even if it wasn't when it was stacked.

src/hotspot/cpu/zero/frame_zero.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ frame frame::sender_for_entry_frame(RegisterMap *map) const {
6161
return frame(zeroframe()->next(), sender_sp());
6262
}
6363

64+
bool frame::optimized_entry_frame_is_first() const {
65+
ShouldNotCallThis();
66+
return false;
67+
}
68+
6469
frame frame::sender_for_nonentry_frame(RegisterMap *map) const {
6570
assert(zeroframe()->is_interpreter_frame() ||
6671
zeroframe()->is_fake_stub_frame(), "wrong type of frame");

src/hotspot/share/prims/whitebox.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,7 @@ WB_ENTRY(void, WB_VerifyFrames(JNIEnv* env, jobject wb, jboolean log, jboolean u
23062306
tty_token = ttyLocker::hold_tty();
23072307
tty->print_cr("[WhiteBox::VerifyFrames] Walking Frames");
23082308
}
2309+
ResourceMark rm; // for verify
23092310
for (StackFrameStream fst(JavaThread::current(), update_map, true); !fst.is_done(); fst.next()) {
23102311
frame* current_frame = fst.current();
23112312
if (log) {

src/hotspot/share/runtime/frame.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ class frame {
342342

343343
// tells whether there is another chunk of Delta stack above
344344
bool entry_frame_is_first() const;
345+
bool optimized_entry_frame_is_first() const;
345346

346347
// Safepoints
347348

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ inline bool frame::is_stub_frame() const {
5050
}
5151

5252
inline bool frame::is_first_frame() const {
53-
return is_entry_frame() && entry_frame_is_first();
53+
return (is_entry_frame() && entry_frame_is_first())
54+
// Optimized entry frames are only present on certain platforms
55+
|| (is_optimized_entry_frame() && optimized_entry_frame_is_first());
5456
}
5557

5658
inline bool frame::is_optimized_entry_frame() const {

0 commit comments

Comments
 (0)