Skip to content
Permalink
Browse files

8238988: Rename thread "in stack" methods and add in_stack_range

Reviewed-by: coleenp, dcubed
  • Loading branch information
David Holmes
David Holmes committed Feb 24, 2020
1 parent 533649b commit bd028945bdcd5609e0476484e6b59fb8ecd64094
Showing with 126 additions and 184 deletions.
  1. +8 −20 src/hotspot/cpu/aarch64/frame_aarch64.cpp
  2. +7 −23 src/hotspot/cpu/arm/frame_arm.cpp
  3. +4 −7 src/hotspot/cpu/ppc/frame_ppc.cpp
  4. +4 −7 src/hotspot/cpu/s390/frame_s390.cpp
  5. +7 −19 src/hotspot/cpu/sparc/frame_sparc.cpp
  6. +9 −21 src/hotspot/cpu/x86/frame_x86.cpp
  7. +0 −1 src/hotspot/os/linux/os_linux.cpp
  8. +0 −7 src/hotspot/os/solaris/os_solaris.cpp
  9. +1 −2 src/hotspot/os/solaris/os_solaris.hpp
  10. +2 −2 src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp
  11. +2 −2 src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp
  12. +2 −2 src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp
  13. +2 −2 src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp
  14. +1 −1 src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp
  15. +2 −2 src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp
  16. +2 −2 src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp
  17. +1 −1 src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp
  18. +2 −2 src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp
  19. +2 −2 src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp
  20. +2 −2 src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp
  21. +3 −3 src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp
  22. +3 −3 src/hotspot/os_cpu/solaris_x86/os_solaris_x86.cpp
  23. +3 −4 src/hotspot/os_cpu/solaris_x86/thread_solaris_x86.cpp
  24. +5 −6 src/hotspot/share/runtime/frame.cpp
  25. +3 −3 src/hotspot/share/runtime/handles.cpp
  26. +2 −2 src/hotspot/share/runtime/handles.inline.hpp
  27. +2 −3 src/hotspot/share/runtime/jniHandles.cpp
  28. +1 −1 src/hotspot/share/runtime/os.cpp
  29. +1 −17 src/hotspot/share/runtime/thread.cpp
  30. +36 −9 src/hotspot/share/runtime/thread.hpp
  31. +5 −4 src/hotspot/share/runtime/unhandledOops.cpp
  32. +2 −2 src/hotspot/share/utilities/vmError.cpp
@@ -76,16 +76,14 @@ bool frame::safe_for_sender(JavaThread *thread) {

// So unextended sp must be within the stack but we need not to check
// that unextended sp >= sp

bool unextended_sp_safe = (unextended_sp < thread->stack_base());

if (!unextended_sp_safe) {
if (!thread->is_in_full_stack(unextended_sp)) {
return false;
}

// an fp must be within the stack and above (but not equal) sp
// second evaluation on fp+ is added to handle situation where fp is -1
bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
bool fp_safe = thread->is_in_stack_range_excl(fp, sp) &&
thread->is_in_full_stack(fp + (return_addr_offset * sizeof(void*)));

// We know sp/unextended_sp are safe only fp is questionable here

@@ -147,7 +145,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

sender_sp = _unextended_sp + _cb->frame_size();
// Is sender_sp safe?
if ((address)sender_sp >= thread->stack_base()) {
if (!thread->is_in_full_stack((address)sender_sp)) {
return false;
}
sender_unextended_sp = sender_sp;
@@ -164,9 +162,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp
// is really a frame pointer.

bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);

if (!saved_fp_safe) {
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
return false;
}

@@ -201,9 +197,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

// Could be the call_stub
if (StubRoutines::returns_to_call_stub(sender_pc)) {
bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);

if (!saved_fp_safe) {
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
return false;
}

@@ -214,9 +208,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// Validate the JavaCallWrapper an entry frame must have
address jcw = (address)sender.entry_frame_call_wrapper();

bool jcw_safe = (jcw < thread->stack_base()) && (jcw > (address)sender.fp());

return jcw_safe;
return thread->is_in_stack_range_excl(jcw, (address)sender.fp());
}

CompiledMethod* nm = sender_blob->as_compiled_method_or_null();
@@ -557,11 +549,7 @@ bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
// validate locals

address locals = (address) *interpreter_frame_locals_addr();

if (locals >= thread->stack_base() || locals < (address) fp()) return false;

// We'd have to be pretty unlucky to be mislead at this point
return true;
return thread->is_in_stack_range_incl(locals, (address)fp());
}

BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
@@ -63,18 +63,13 @@ bool frame::safe_for_sender(JavaThread *thread) {
return false;
}

bool unextended_sp_safe = (unextended_sp != NULL &&
(unextended_sp < thread->stack_base()) &&
(unextended_sp >= sp));
if (!unextended_sp_safe) {
if (!thread->is_in_stack_range_incl(unextended_sp, sp)) {
return false;
}

// We know sp/unextended_sp are safe. Only fp is questionable here.

bool fp_safe = (fp != NULL &&
(fp < thread->stack_base()) &&
fp >= sp);
bool fp_safe = thread->is_in_stack_range_incl(fp, sp);

if (_cb != NULL ) {

@@ -118,7 +113,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

sender_sp = _unextended_sp + _cb->frame_size();
// Is sender_sp safe?
if ((address)sender_sp >= thread->stack_base()) {
if (!thread->is_in_full_stack((address)sender_sp)) {
return false;
}
// With our calling conventions, the return_address should
@@ -141,9 +136,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// is really a frame pointer.

intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset + link_offset);
bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);

if (!saved_fp_safe) {
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
return false;
}

@@ -171,9 +164,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// Could be the call_stub
if (StubRoutines::returns_to_call_stub(sender_pc)) {
intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset + link_offset);
bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);

if (!saved_fp_safe) {
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
return false;
}

@@ -184,9 +175,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// Validate the JavaCallWrapper an entry frame must have
address jcw = (address)sender.entry_frame_call_wrapper();

bool jcw_safe = (jcw < thread->stack_base()) && (jcw > (address)sender.fp());

return jcw_safe;
return thread->is_in_stack_range_excl(jcw, (address)sender.fp());
}

// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
@@ -493,12 +482,7 @@ bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
// validate locals

address locals = (address) *interpreter_frame_locals_addr();

if (locals >= thread->stack_base() || locals < (address) fp()) return false;

// We'd have to be pretty unlucky to be mislead at this point

return true;
return thread->is_in_stack_range_incl(locals, (address)fp());
}

BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
@@ -62,18 +62,15 @@ bool frame::safe_for_sender(JavaThread *thread) {
}

// Unextended sp must be within the stack
bool unextended_sp_safe = (unextended_sp < thread->stack_base());

if (!unextended_sp_safe) {
if (!thread->is_in_full_stack(unextended_sp)) {
return false;
}

// An fp must be within the stack and above (but not equal) sp.
bool fp_safe = (fp < thread->stack_base()) && (fp > sp);
bool fp_safe = thread->is_in_stack_range_excl(fp, sp);
// An interpreter fp must be within the stack and above (but not equal) sp.
// Moreover, it must be at least the size of the ijava_state structure.
bool fp_interp_safe = (fp < thread->stack_base()) && (fp > sp) &&
((fp - sp) >= ijava_state_size);
bool fp_interp_safe = fp_safe && ((fp - sp) >= ijava_state_size);

// We know sp/unextended_sp are safe, only fp is questionable here

@@ -132,7 +129,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

// sender_fp must be within the stack and above (but not
// equal) current frame's fp.
if (sender_fp >= thread->stack_base() || sender_fp <= fp) {
if (!thread->is_in_stack_range_excl(sender_fp, fp)) {
return false;
}

@@ -66,18 +66,15 @@ bool frame::safe_for_sender(JavaThread *thread) {
}

// Unextended sp must be within the stack
bool unextended_sp_safe = (unextended_sp < thread->stack_base());

if (!unextended_sp_safe) {
if (!thread->is_in_full_stack(unextended_sp)) {
return false;
}

// An fp must be within the stack and above (but not equal) sp.
bool fp_safe = (fp < thread->stack_base()) && (fp > sp);
bool fp_safe = thread->is_in_stack_range_excl(fp, sp);
// An interpreter fp must be within the stack and above (but not equal) sp.
// Moreover, it must be at least the size of the z_ijava_state structure.
bool fp_interp_safe = (fp < thread->stack_base()) && (fp > sp) &&
((fp - sp) >= z_ijava_state_size);
bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size);

// We know sp/unextended_sp are safe, only fp is questionable here

@@ -136,7 +133,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

// sender_fp must be within the stack and above (but not
// equal) current frame's fp.
if (sender_fp >= thread->stack_base() || sender_fp <= fp) {
if (!thread->is_in_stack_range_excl(sender_fp, fp)) {
return false;
}

@@ -185,14 +185,12 @@ bool frame::safe_for_sender(JavaThread *thread) {
}

// unextended sp must be within the stack and above or equal sp
bool unextended_sp_safe = (_UNEXTENDED_SP < thread->stack_base()) &&
(_UNEXTENDED_SP >= _SP);

if (!unextended_sp_safe) return false;
if (!thread->is_in_stack_range_incl(_UNEXTENDED_SP, _SP)) {
return false;
}

// an fp must be within the stack and above (but not equal) sp
bool fp_safe = (_FP < thread->stack_base()) &&
(_FP > _SP);
bool fp_safe = thread->is_in_stack_range_excl(_FP, _SP);

// We know sp/unextended_sp are safe only fp is questionable here

@@ -251,10 +249,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

// an fp must be within the stack and above (but not equal) current frame's _FP

bool sender_fp_safe = (sender_fp < thread->stack_base()) &&
(sender_fp > _FP);

if (!sender_fp_safe) {
if (!thread->is_in_stack_range_excl(sender_fp, _FP)) {
return false;
}

@@ -276,12 +271,9 @@ bool frame::safe_for_sender(JavaThread *thread) {

if (sender.is_entry_frame()) {
// Validate the JavaCallWrapper an entry frame must have

address jcw = (address)sender.entry_frame_call_wrapper();

bool jcw_safe = (jcw < thread->stack_base()) && (jcw > sender_fp);

return jcw_safe;
return thread->is_in_stack_range_excl(jcw, sender_fp);
}

// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
@@ -670,11 +662,7 @@ bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
// validate locals

address locals = (address) *interpreter_frame_locals_addr();

if (locals >= thread->stack_base() || locals < (address) fp()) return false;

// We'd have to be pretty unlucky to be mislead at this point
return true;
return thread->is_in_stack_range_incl(locals, (address)fp());
}


@@ -63,21 +63,19 @@ bool frame::safe_for_sender(JavaThread *thread) {
}

// unextended sp must be within the stack and above or equal sp
bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&
(unextended_sp >= sp);

if (!unextended_sp_safe) {
if (!thread->is_in_stack_range_incl(unextended_sp, sp)) {
return false;
}

// an fp must be within the stack and above (but not equal) sp
// second evaluation on fp+ is added to handle situation where fp is -1
bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
bool fp_safe = thread->is_in_stack_range_excl(fp, sp) &&
thread->is_in_full_stack(fp + (return_addr_offset * sizeof(void*)));

// We know sp/unextended_sp are safe only fp is questionable here

// If the current frame is known to the code cache then we can attempt to
// to construct the sender and do some validation of it. This goes a long way
// construct the sender and do some validation of it. This goes a long way
// toward eliminating issues when we get in frame construction code

if (_cb != NULL ) {
@@ -134,7 +132,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

sender_sp = _unextended_sp + _cb->frame_size();
// Is sender_sp safe?
if ((address)sender_sp >= thread->stack_base()) {
if (!thread->is_in_full_stack((address)sender_sp)) {
return false;
}
sender_unextended_sp = sender_sp;
@@ -152,9 +150,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
// is really a frame pointer.

bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);

if (!saved_fp_safe) {
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
return false;
}

@@ -189,9 +185,7 @@ bool frame::safe_for_sender(JavaThread *thread) {

// Could be the call_stub
if (StubRoutines::returns_to_call_stub(sender_pc)) {
bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);

if (!saved_fp_safe) {
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
return false;
}

@@ -202,9 +196,7 @@ bool frame::safe_for_sender(JavaThread *thread) {
// Validate the JavaCallWrapper an entry frame must have
address jcw = (address)sender.entry_frame_call_wrapper();

bool jcw_safe = (jcw < thread->stack_base()) && (jcw > (address)sender.fp());

return jcw_safe;
return thread->is_in_stack_range_excl(jcw, (address)sender.fp());
}

CompiledMethod* nm = sender_blob->as_compiled_method_or_null();
@@ -544,11 +536,7 @@ bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
// validate locals

address locals = (address) *interpreter_frame_locals_addr();

if (locals >= thread->stack_base() || locals < (address) fp()) return false;

// We'd have to be pretty unlucky to be mislead at this point
return true;
return thread->is_in_stack_range_incl(locals, (address)fp());
}

BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
@@ -718,7 +718,6 @@ void os::Linux::expand_stack_to(address bottom) {
bool os::Linux::manually_expand_stack(JavaThread * t, address addr) {
assert(t!=NULL, "just checking");
assert(t->osthread()->expanding_stack(), "expand should be set");
assert(t->stack_base() != NULL, "stack_base was not initialized");

if (t->is_in_usable_stack(addr)) {
sigset_t mask_all, old_sigset;
@@ -539,13 +539,6 @@ void os::breakpoint() {
BREAKPOINT;
}

bool os::Solaris::valid_stack_address(Thread* thread, address sp) {
address stackStart = (address)thread->stack_base();
address stackEnd = (address)(stackStart - (address)thread->stack_size());
if (sp < stackStart && sp >= stackEnd) return true;
return false;
}

extern "C" void breakpoint() {
// use debugger to set breakpoint here
}
@@ -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.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -119,7 +119,6 @@ class Solaris {

static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo

static bool valid_stack_address(Thread* thread, address sp);
static bool valid_ucontext(Thread* thread, const ucontext_t* valid, const ucontext_t* suspect);
static const ucontext_t* get_valid_uc_in_signal_handler(Thread* thread,
const ucontext_t* uc);

0 comments on commit bd02894

Please sign in to comment.