Skip to content

Commit fc8078a

Browse files
committed
8263375: Support stack watermarks in Zero VM
Backport-of: 857a930bde8b53f77a23737f4ca6ff8f3da2af66
1 parent 759cbcb commit fc8078a

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

src/hotspot/cpu/zero/frame_zero.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "runtime/frame.inline.hpp"
3535
#include "runtime/handles.inline.hpp"
3636
#include "runtime/signature.hpp"
37+
#include "runtime/stackWatermarkSet.hpp"
3738
#include "vmreg_zero.inline.hpp"
3839

3940
#ifdef ASSERT
@@ -82,10 +83,15 @@ frame frame::sender(RegisterMap* map) const {
8283
// sender_for_xxx methods update this accordingly.
8384
map->set_include_argument_oops(false);
8485

85-
if (is_entry_frame())
86-
return sender_for_entry_frame(map);
87-
else
88-
return sender_for_nonentry_frame(map);
86+
frame result = zeroframe()->is_entry_frame() ?
87+
sender_for_entry_frame(map) :
88+
sender_for_nonentry_frame(map);
89+
90+
if (map->process_frames()) {
91+
StackWatermarkSet::on_iteration(map->thread(), result);
92+
}
93+
94+
return result;
8995
}
9096

9197
BasicObjectLock* frame::interpreter_frame_monitor_begin() const {

src/hotspot/cpu/zero/vm_version_zero.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
class VM_Version : public Abstract_VM_Version {
3333
public:
3434
static void initialize();
35+
36+
constexpr static bool supports_stack_watermark_barrier() { return true; }
3537
};
3638

3739
#endif // CPU_ZERO_VM_VERSION_ZERO_HPP

src/hotspot/cpu/zero/zeroInterpreter_zero.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,18 @@ void ZeroInterpreter::main_loop(int recurse, TRAPS) {
200200
}
201201
fixup_after_potential_safepoint();
202202

203+
// If we are unwinding, notify the stack watermarks machinery.
204+
// Should do this before resetting the frame anchor.
205+
if (istate->msg() == BytecodeInterpreter::return_from_method ||
206+
istate->msg() == BytecodeInterpreter::do_osr) {
207+
stack_watermark_unwind_check(thread);
208+
} else {
209+
assert(istate->msg() == BytecodeInterpreter::call_method ||
210+
istate->msg() == BytecodeInterpreter::more_monitors ||
211+
istate->msg() == BytecodeInterpreter::throwing_exception,
212+
"Should be one of these otherwise");
213+
}
214+
203215
// Clear the frame anchor
204216
thread->reset_last_Java_frame();
205217

@@ -436,6 +448,10 @@ int ZeroInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) {
436448
thread->set_thread_state(_thread_in_Java);
437449
fixup_after_potential_safepoint();
438450

451+
// Notify the stack watermarks machinery that we are unwinding.
452+
// Should do this before resetting the frame anchor.
453+
stack_watermark_unwind_check(thread);
454+
439455
// Clear the frame anchor
440456
thread->reset_last_Java_frame();
441457

@@ -869,3 +885,13 @@ address ZeroInterpreter::remove_activation_early_entry(TosState state) {
869885
bool ZeroInterpreter::contains(address pc) {
870886
return false; // make frame::print_value_on work
871887
}
888+
889+
void ZeroInterpreter::stack_watermark_unwind_check(JavaThread* thread) {
890+
// If frame pointer is in the danger zone, notify the runtime that
891+
// it needs to act before continuing the unwinding.
892+
uintptr_t fp = (uintptr_t)thread->last_Java_fp();
893+
uintptr_t watermark = thread->poll_data()->get_polling_word();
894+
if (fp > watermark) {
895+
InterpreterRuntime::at_unwind(thread);
896+
}
897+
}

src/hotspot/cpu/zero/zeroInterpreter_zero.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
static int empty_entry(Method* method, intptr_t UNUSED, TRAPS);
4040
static int Reference_get_entry(Method* method, intptr_t UNUSED, TRAPS);
4141

42+
// Stack watermark machinery
43+
static void stack_watermark_unwind_check(JavaThread* thread);
44+
4245
public:
4346
// Main loop of normal_entry
4447
static void main_loop(int recurse, TRAPS);

src/hotspot/share/interpreter/zero/bytecodeInterpreter.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
There really shouldn't be any handles remaining to trash but this is cheap
108108
in relation to a safepoint.
109109
*/
110-
#define SAFEPOINT \
110+
#define RETURN_SAFEPOINT \
111111
if (SafepointMechanism::should_process(THREAD)) { \
112112
HandleMarkCleaner __hmc(THREAD); \
113113
CALL_VM(SafepointMechanism::process_if_requested_with_exit_check(THREAD, true /* check asyncs */), \
@@ -1336,36 +1336,22 @@ void BytecodeInterpreter::run(interpreterState istate) {
13361336
CASE(_areturn):
13371337
CASE(_ireturn):
13381338
CASE(_freturn):
1339-
{
1340-
// Allow a safepoint before returning to frame manager.
1341-
SAFEPOINT;
1342-
1343-
goto handle_return;
1344-
}
1345-
13461339
CASE(_lreturn):
13471340
CASE(_dreturn):
1348-
{
1341+
CASE(_return): {
13491342
// Allow a safepoint before returning to frame manager.
1350-
SAFEPOINT;
1343+
RETURN_SAFEPOINT;
13511344
goto handle_return;
13521345
}
13531346

13541347
CASE(_return_register_finalizer): {
1355-
13561348
oop rcvr = LOCALS_OBJECT(0);
13571349
VERIFY_OOP(rcvr);
13581350
if (rcvr->klass()->has_finalizer()) {
13591351
CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);
13601352
}
13611353
goto handle_return;
13621354
}
1363-
CASE(_return): {
1364-
1365-
// Allow a safepoint before returning to frame manager.
1366-
SAFEPOINT;
1367-
goto handle_return;
1368-
}
13691355

13701356
/* Array access byte-codes */
13711357

0 commit comments

Comments
 (0)