--- old/src/hotspot/cpu/aarch64/frame_aarch64.cpp 2020-02-19 21:27:28.190950408 -0500 +++ new/src/hotspot/cpu/aarch64/frame_aarch64.cpp 2020-02-19 21:27:26.482931492 -0500 @@ -76,16 +76,14 @@ // 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 @@ 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 @@ // 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 @@ // 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 @@ // 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 @@ // 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) { --- old/src/hotspot/cpu/arm/frame_arm.cpp 2020-02-19 21:27:34.283017876 -0500 +++ new/src/hotspot/cpu/arm/frame_arm.cpp 2020-02-19 21:27:32.584999071 -0500 @@ -63,18 +63,13 @@ 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_excl(fp, sp); if (_cb != NULL ) { @@ -118,7 +113,7 @@ 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 @@ // 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 @@ // 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 @@ // 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 @@ // 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) { --- old/src/hotspot/cpu/ppc/frame_ppc.cpp 2020-02-19 21:27:40.374085334 -0500 +++ new/src/hotspot/cpu/ppc/frame_ppc.cpp 2020-02-19 21:27:38.686066639 -0500 @@ -62,18 +62,15 @@ } // 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 @@ // 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; } --- old/src/hotspot/cpu/s390/frame_s390.cpp 2020-02-19 21:27:46.447152592 -0500 +++ new/src/hotspot/cpu/s390/frame_s390.cpp 2020-02-19 21:27:44.766133975 -0500 @@ -66,18 +66,15 @@ } // 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 @@ // 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; } --- old/src/hotspot/cpu/sparc/frame_sparc.cpp 2020-02-19 21:27:52.615220902 -0500 +++ new/src/hotspot/cpu/sparc/frame_sparc.cpp 2020-02-19 21:27:50.914202064 -0500 @@ -185,14 +185,12 @@ } // 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 @@ // 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 @@ 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 @@ // 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()); } --- old/src/hotspot/cpu/x86/frame_x86.cpp 2020-02-19 21:27:58.685288127 -0500 +++ new/src/hotspot/cpu/x86/frame_x86.cpp 2020-02-19 21:27:57.000269466 -0500 @@ -63,21 +63,19 @@ } // 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 @@ 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 @@ // 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 @@ // 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 @@ // 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 @@ // 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) { --- old/src/hotspot/os/linux/os_linux.cpp 2020-02-19 21:28:04.792355762 -0500 +++ new/src/hotspot/os/linux/os_linux.cpp 2020-02-19 21:28:03.079336790 -0500 @@ -717,7 +717,6 @@ 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; --- old/src/hotspot/os/solaris/os_solaris.cpp 2020-02-19 21:28:10.929423729 -0500 +++ new/src/hotspot/os/solaris/os_solaris.cpp 2020-02-19 21:28:09.236404979 -0500 @@ -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 @@ -539,13 +539,6 @@ 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 } --- old/src/hotspot/os/solaris/os_solaris.hpp 2020-02-19 21:28:17.061491640 -0500 +++ new/src/hotspot/os/solaris/os_solaris.hpp 2020-02-19 21:28:15.356472758 -0500 @@ -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 @@ 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); --- old/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp 2020-02-19 21:28:23.087558378 -0500 +++ new/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp 2020-02-19 21:28:21.434540071 -0500 @@ -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. * Copyright (c) 2012, 2018 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -266,7 +266,7 @@ if (thread != NULL) { // Handle ALL stack overflow variations here - if (sig == SIGSEGV && thread->on_local_stack(addr)) { + if (sig == SIGSEGV && thread->is_in_full_stack(addr)) { // stack overflow // // If we are in a yellow zone and we are inside java, we disable the yellow zone and --- old/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp 2020-02-19 21:28:29.096624927 -0500 +++ new/src/hotspot/os_cpu/bsd_x86/os_bsd_x86.cpp 2020-02-19 21:28:27.425606421 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -520,7 +520,7 @@ address addr = (address) info->si_addr; // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { if (thread->thread_state() == _thread_in_Java) { --- old/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp 2020-02-19 21:28:35.181692319 -0500 +++ new/src/hotspot/os_cpu/bsd_zero/os_bsd_zero.cpp 2020-02-19 21:28:33.463673292 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -177,7 +177,7 @@ address addr = (address) info->si_addr; // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { thread->disable_stack_yellow_reserved_zone(); --- old/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp 2020-02-19 21:28:41.265759699 -0500 +++ new/src/hotspot/os_cpu/linux_aarch64/os_linux_aarch64.cpp 2020-02-19 21:28:39.570740927 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -293,7 +293,7 @@ // Handle ALL stack overflow variations here if (sig == SIGSEGV) { // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { if (thread->thread_state() == _thread_in_Java) { --- old/src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp 2020-02-19 21:28:47.362827223 -0500 +++ new/src/hotspot/os_cpu/linux_arm/os_linux_arm.cpp 2020-02-19 21:28:45.685808650 -0500 @@ -336,7 +336,7 @@ return 1; } // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { thread->disable_stack_yellow_reserved_zone(); --- old/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp 2020-02-19 21:28:53.515895367 -0500 +++ new/src/hotspot/os_cpu/linux_ppc/os_linux_ppc.cpp 2020-02-19 21:28:51.806876440 -0500 @@ -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. * Copyright (c) 2012, 2019 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -326,7 +326,7 @@ } // Check if fault address is within thread stack. - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { if (thread->thread_state() == _thread_in_Java) { --- old/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp 2020-02-19 21:28:59.584962581 -0500 +++ new/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp 2020-02-19 21:28:57.896943886 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2019 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -321,7 +321,7 @@ address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target. // Check if fault address is within thread stack. - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { if (thread->thread_state() == _thread_in_Java) { --- old/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp 2020-02-19 21:29:05.711030426 -0500 +++ new/src/hotspot/os_cpu/linux_s390/thread_linux_s390.cpp 2020-02-19 21:29:03.994011410 -0500 @@ -63,7 +63,7 @@ if (ret_frame.is_interpreted_frame()) { frame::z_ijava_state* istate = ret_frame.ijava_state_unchecked(); - if (on_local_stack((address)istate)) { + if (is_in_full_stack((address)istate)) { return false; } const Method *m = (const Method*)(istate->method); --- old/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp 2020-02-19 21:29:11.762097440 -0500 +++ new/src/hotspot/os_cpu/linux_sparc/os_linux_sparc.cpp 2020-02-19 21:29:10.080078812 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 20209, 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 @@ -326,7 +326,7 @@ JavaThread* thread, address* stub) { // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { thread->disable_stack_yellow_reserved_zone(); --- old/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp 2020-02-19 21:29:17.833164676 -0500 +++ new/src/hotspot/os_cpu/linux_x86/os_linux_x86.cpp 2020-02-19 21:29:16.144145971 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -359,7 +359,7 @@ address addr = (address) info->si_addr; // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { if (thread->thread_state() == _thread_in_Java) { --- old/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp 2020-02-19 21:29:23.898231846 -0500 +++ new/src/hotspot/os_cpu/linux_zero/os_linux_zero.cpp 2020-02-19 21:29:22.215213207 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -173,7 +173,7 @@ address addr = (address) info->si_addr; // check if fault address is within thread stack - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { // stack overflow if (thread->in_stack_yellow_reserved_zone(addr)) { thread->disable_stack_yellow_reserved_zone(); --- old/src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp 2020-02-19 21:29:29.984299359 -0500 +++ new/src/hotspot/os_cpu/solaris_sparc/os_solaris_sparc.cpp 2020-02-19 21:29:28.285280473 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -120,12 +120,12 @@ } if (thread->is_Java_thread()) { - if (!valid_stack_address(thread, (address)suspect)) { + if (!thread->is_in_full_stack((address)suspect)) { DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");) return false; } address _sp = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS); - if (!valid_stack_address(thread, _sp) || + if (!thread->is_in_full_stack(_sp) || !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) { DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");) return false; --- old/src/hotspot/os_cpu/solaris_x86/os_solaris_x86.cpp 2020-02-19 21:29:36.073367042 -0500 +++ new/src/hotspot/os_cpu/solaris_x86/os_solaris_x86.cpp 2020-02-19 21:29:34.371348123 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -140,11 +140,11 @@ } if (thread->is_Java_thread()) { - if (!valid_stack_address(thread, (address)suspect)) { + if (!thread->is_in_full_stack((address)suspect)) { DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");) return false; } - if (!valid_stack_address(thread, (address) suspect->uc_mcontext.gregs[REG_SP])) { + if (!thread->is_in_full_stack((address) suspect->uc_mcontext.gregs[REG_SP])) { DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");) return false; } --- old/src/hotspot/os_cpu/solaris_x86/thread_solaris_x86.cpp 2020-02-19 21:29:42.162434724 -0500 +++ new/src/hotspot/os_cpu/solaris_x86/thread_solaris_x86.cpp 2020-02-19 21:29:40.464415850 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -84,12 +84,12 @@ // If sp and fp are nonsense just leave them out - if (!jt->on_local_stack((address)ret_sp)) { + if (!jt->is_in_full_stack((address)ret_sp)) { ret_sp = NULL; ret_fp = NULL; } else { // sp is reasonable is fp reasonable? - if ((address)ret_fp >= jt->stack_base() || ret_fp < ret_sp) { + if (!jt->is_in_stack_range_incl((address)ret_fp, ret_sp)) { ret_fp = NULL; } } @@ -102,4 +102,3 @@ } void JavaThread::cache_global_variables() { } - --- old/src/hotspot/share/runtime/frame.cpp 2020-02-19 21:29:48.273502652 -0500 +++ new/src/hotspot/share/runtime/frame.cpp 2020-02-19 21:29:46.586483900 -0500 @@ -231,8 +231,7 @@ bool frame::is_entry_frame_valid(JavaThread* thread) const { // Validate the JavaCallWrapper an entry frame must have address jcw = (address)entry_frame_call_wrapper(); - bool jcw_safe = (jcw < thread->stack_base()) && (jcw > (address)fp()); // less than stack base - if (!jcw_safe) { + if (!thread->is_in_stack_range_excl(jcw, (address)fp())) { return false; } @@ -1284,17 +1283,17 @@ intptr_t* v1 = _values.at(max_index).location; if (thread == Thread::current()) { - while (!thread->is_in_stack((address)v0)) { + while (!thread->is_in_live_stack((address)v0)) { v0 = _values.at(++min_index).location; } - while (!thread->is_in_stack((address)v1)) { + while (!thread->is_in_live_stack((address)v1)) { v1 = _values.at(--max_index).location; } } else { - while (!thread->on_local_stack((address)v0)) { + while (!thread->is_in_full_stack((address)v0)) { v0 = _values.at(++min_index).location; } - while (!thread->on_local_stack((address)v1)) { + while (!thread->is_in_full_stack((address)v1)) { v1 = _values.at(--max_index).location; } } --- old/src/hotspot/share/runtime/handles.cpp 2020-02-19 21:29:54.439571190 -0500 +++ new/src/hotspot/share/runtime/handles.cpp 2020-02-19 21:29:52.752552438 -0500 @@ -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 @@ -51,7 +51,7 @@ } else { \ _thread = Thread::current(); \ } \ - assert (_thread->is_in_stack((address)this), "not on stack?"); \ + assert (_thread->is_in_live_stack((address)this), "not on stack?");\ _thread->metadata_handles()->push((Metadata*)_value); \ } else { \ _thread = NULL; \ @@ -68,7 +68,7 @@ } else { \ _thread = Thread::current(); \ } \ - assert (_thread->is_in_stack((address)this), "not on stack?"); \ + assert (_thread->is_in_live_stack((address)this), "not on stack?");\ _thread->metadata_handles()->push((Metadata*)_value); \ } else { \ _thread = NULL; \ --- old/src/hotspot/share/runtime/handles.inline.hpp 2020-02-19 21:30:00.515638728 -0500 +++ new/src/hotspot/share/runtime/handles.inline.hpp 2020-02-19 21:29:58.807619743 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -59,7 +59,7 @@ if (obj != NULL) { \ assert(((Metadata*)obj)->is_valid(), "obj is valid"); \ assert(_thread == Thread::current(), "thread must be current"); \ - assert (_thread->is_in_stack((address)this), "not on stack?"); \ + assert (_thread->is_in_live_stack((address)this), "not on stack?");\ _thread->metadata_handles()->push((Metadata*)obj); \ } \ } \ --- old/src/hotspot/share/runtime/jniHandles.cpp 2020-02-19 21:30:06.623706622 -0500 +++ new/src/hotspot/share/runtime/jniHandles.cpp 2020-02-19 21:30:04.922687715 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -265,8 +265,7 @@ // as the java command executable, in which case, this type of handle // is not permitted. return (thr->has_last_Java_frame() && - (void*)handle < (void*)thr->stack_base() && - (void*)handle >= (void*)thr->last_Java_sp()); + thr->is_in_stack_range_incl((address)handle, (address)thr->last_Java_sp())); } --- old/src/hotspot/share/runtime/os.cpp 2020-02-19 21:30:12.707774249 -0500 +++ new/src/hotspot/share/runtime/os.cpp 2020-02-19 21:30:11.028755586 -0500 @@ -1114,7 +1114,7 @@ } // If the addr is in the stack region for this thread then report that // and print thread info - if (thread->on_local_stack(addr)) { + if (thread->is_in_full_stack(addr)) { st->print_cr(INTPTR_FORMAT " is pointing into the stack for thread: " INTPTR_FORMAT, p2i(addr), p2i(thread)); if (verbose) thread->print_on(st); --- old/src/hotspot/share/runtime/thread.cpp 2020-02-19 21:30:18.807842054 -0500 +++ new/src/hotspot/share/runtime/thread.cpp 2020-02-19 21:30:17.088822947 -0500 @@ -1018,20 +1018,13 @@ } #endif // ASSERT -// Check for adr in the live portion of our stack. -bool Thread::is_in_stack(address adr) const { - assert(Thread::current() == this, "is_in_stack can only be called from current thread"); - address end = os::current_stack_pointer(); - return (stack_base() > adr && adr >= end); -} - // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being // used for compilation in the future. If that change is made, the need for these methods // should be revisited, and they should be removed if possible. bool Thread::is_lock_owned(address adr) const { - return on_local_stack(adr); + return is_in_full_stack(adr); } bool Thread::set_as_starting_thread() { @@ -1818,15 +1811,6 @@ return reguard_stack(os::current_stack_pointer()); } - -// Check for adr in the usable portion of this thread's stack. -bool JavaThread::is_in_usable_stack(address adr) const { - size_t stack_guard_size = os::uses_stack_guard_pages() ? JavaThread::stack_guard_zone_size() : 0; - size_t usable_stack_size = _stack_size - stack_guard_size; - - return ((stack_base() > adr) && (adr >= (stack_base() - usable_stack_size))); -} - void JavaThread::block_if_vm_exited() { if (_terminated == _vm_exited) { // _vm_exited is set at safepoint, and Threads_lock is never released --- old/src/hotspot/share/runtime/thread.hpp 2020-02-19 21:30:24.946910293 -0500 +++ new/src/hotspot/share/runtime/thread.hpp 2020-02-19 21:30:23.235891274 -0500 @@ -684,17 +684,43 @@ // jvmtiRedefineClasses support void metadata_handles_do(void f(Metadata*)); + private: + + // Check if address is within the given range of this thread's + // stack: stack_base() > adr >/>= limit + // The check is inclusive of limit if passed true, else exclusive. + bool is_in_stack_range(address adr, address limit, bool inclusive) const { + assert(stack_base() > limit && limit >= stack_end(), "limit is outside of stack"); + return stack_base() > adr && (inclusive ? adr >= limit : adr > limit); + } + + public: // Used by fast lock support virtual bool is_lock_owned(address adr) const; - // Check if address is in the live stack of this thread (not just for locks). - // Warning: can only be called by the current thread on itself. - bool is_in_stack(address adr) const; + // Check if address is within the given range of this thread's + // stack: stack_base() > adr >= limit + bool is_in_stack_range_incl(address adr, address limit) const { + return is_in_stack_range(adr, limit, true); + } - // Check if address in the stack mapped to this thread. Used mainly in + // Check if address is within the given range of this thread's + // stack: stack_base() > adr > limit + bool is_in_stack_range_excl(address adr, address limit) const { + return is_in_stack_range(adr, limit, false); + } + + // Check if address is in the stack mapped to this thread. Used mainly in // error reporting (so has to include guard zone) and frame printing. - bool on_local_stack(address adr) const { - return (_stack_base > adr && adr >= stack_end()); + bool is_in_full_stack(address adr) const { + return is_in_stack_range_incl(adr, stack_end()); + } + + // Check if address is in the live stack of this thread (not just for locks). + // Warning: can only be called by the current thread on itself. + bool is_in_live_stack(address adr) const { + assert(Thread::current() == this, "is_in_live_stack can only be called from current thread"); + return is_in_stack_range_incl(adr, os::current_stack_pointer()); } // Sets this thread as starting thread. Returns failure if thread @@ -1649,7 +1675,7 @@ assert(_stack_reserved_zone_size == 0, "This should be called only once."); _stack_reserved_zone_size = s; } - address stack_reserved_zone_base() { + address stack_reserved_zone_base() const { return (address)(stack_end() + (stack_red_zone_size() + stack_yellow_zone_size() + stack_reserved_zone_size())); } @@ -1732,8 +1758,10 @@ // Check if address is in the usable part of the stack (excludes protected // guard pages). Can be applied to any thread and is an approximation for - // using is_in_stack when the query has to happen from another thread. - bool is_in_usable_stack(address adr) const; + // using is_in_live_stack when the query has to happen from another thread. + bool is_in_usable_stack(address adr) const { + return is_in_stack_range_incl(adr, stack_reserved_zone_base()); + } // Misc. accessors/mutators void set_do_not_unlock(void) { _do_not_unlock_if_synchronized = true; } --- old/src/hotspot/share/runtime/unhandledOops.cpp 2020-02-19 21:30:31.034977964 -0500 +++ new/src/hotspot/share/runtime/unhandledOops.cpp 2020-02-19 21:30:29.353959279 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -58,7 +58,7 @@ static Thread* unhandled_oop_print = NULL; void UnhandledOops::register_unhandled_oop(oop* op, address pc) { - if (!_thread->is_in_stack((address)op)) + if (!_thread->is_in_live_stack((address)op)) return; _level++; @@ -96,7 +96,7 @@ // oop list. All oops given are assumed to be on the list. If not, // there's a bug in the unhandled oop detector. void UnhandledOops::unregister_unhandled_oop(oop* op) { - if (!_thread->is_in_stack((address)op)) return; + if (!_thread->is_in_live_stack((address)op)) return; if (unhandled_oop_print == _thread) { for (int i=0; i < _level; i++) tty->print(" "); @@ -117,7 +117,7 @@ // If an entry is on the unhandled oop list but isn't on the stack // anymore, it must not have gotten unregistered properly and it's a bug // in the unhandled oop generator. - if(!_thread->is_in_stack((address)entry._oop_ptr)) { + if(!_thread->is_in_live_stack((address)entry._oop_ptr)) { tty->print_cr("oop_ptr is " INTPTR_FORMAT, p2i(entry._oop_ptr)); tty->print_cr("thread is " INTPTR_FORMAT " from pc " INTPTR_FORMAT, p2i(_thread), p2i(entry._pc)); --- old/src/hotspot/share/utilities/vmError.cpp 2020-02-19 21:30:37.125045658 -0500 +++ new/src/hotspot/share/utilities/vmError.cpp 2020-02-19 21:30:35.413026628 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -251,7 +251,7 @@ if (t && t->is_Java_thread()) { // Catch very first native frame by using stack address. // For JavaThread stack_base and stack_size should be set. - if (!t->on_local_stack((address)(fr.real_fp() + 1))) { + if (!t->is_in_full_stack((address)(fr.real_fp() + 1))) { break; } if (fr.is_java_frame() || fr.is_native_frame() || fr.is_runtime_frame()) {