Skip to content
Permalink
Browse files
8263375: Support stack watermarks in Zero VM
Backport-of: 857a930bde8b53f77a23737f4ca6ff8f3da2af66
  • Loading branch information
shipilev committed Sep 20, 2021
1 parent 759cbcb commit fc8078a09a0596613dcb8b8e3c4d862f754b0f90
@@ -34,6 +34,7 @@
#include "runtime/frame.inline.hpp"
#include "runtime/handles.inline.hpp"
#include "runtime/signature.hpp"
#include "runtime/stackWatermarkSet.hpp"
#include "vmreg_zero.inline.hpp"

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

if (is_entry_frame())
return sender_for_entry_frame(map);
else
return sender_for_nonentry_frame(map);
frame result = zeroframe()->is_entry_frame() ?
sender_for_entry_frame(map) :
sender_for_nonentry_frame(map);

if (map->process_frames()) {
StackWatermarkSet::on_iteration(map->thread(), result);
}

return result;
}

BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
@@ -32,6 +32,8 @@
class VM_Version : public Abstract_VM_Version {
public:
static void initialize();

constexpr static bool supports_stack_watermark_barrier() { return true; }
};

#endif // CPU_ZERO_VM_VERSION_ZERO_HPP
@@ -200,6 +200,18 @@ void ZeroInterpreter::main_loop(int recurse, TRAPS) {
}
fixup_after_potential_safepoint();

// If we are unwinding, notify the stack watermarks machinery.
// Should do this before resetting the frame anchor.
if (istate->msg() == BytecodeInterpreter::return_from_method ||
istate->msg() == BytecodeInterpreter::do_osr) {
stack_watermark_unwind_check(thread);
} else {
assert(istate->msg() == BytecodeInterpreter::call_method ||
istate->msg() == BytecodeInterpreter::more_monitors ||
istate->msg() == BytecodeInterpreter::throwing_exception,
"Should be one of these otherwise");
}

// Clear the frame anchor
thread->reset_last_Java_frame();

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

// Notify the stack watermarks machinery that we are unwinding.
// Should do this before resetting the frame anchor.
stack_watermark_unwind_check(thread);

// Clear the frame anchor
thread->reset_last_Java_frame();

@@ -869,3 +885,13 @@ address ZeroInterpreter::remove_activation_early_entry(TosState state) {
bool ZeroInterpreter::contains(address pc) {
return false; // make frame::print_value_on work
}

void ZeroInterpreter::stack_watermark_unwind_check(JavaThread* thread) {
// If frame pointer is in the danger zone, notify the runtime that
// it needs to act before continuing the unwinding.
uintptr_t fp = (uintptr_t)thread->last_Java_fp();
uintptr_t watermark = thread->poll_data()->get_polling_word();
if (fp > watermark) {
InterpreterRuntime::at_unwind(thread);
}
}
@@ -39,6 +39,9 @@
static int empty_entry(Method* method, intptr_t UNUSED, TRAPS);
static int Reference_get_entry(Method* method, intptr_t UNUSED, TRAPS);

// Stack watermark machinery
static void stack_watermark_unwind_check(JavaThread* thread);

public:
// Main loop of normal_entry
static void main_loop(int recurse, TRAPS);
@@ -107,7 +107,7 @@
There really shouldn't be any handles remaining to trash but this is cheap
in relation to a safepoint.
*/
#define SAFEPOINT \
#define RETURN_SAFEPOINT \
if (SafepointMechanism::should_process(THREAD)) { \
HandleMarkCleaner __hmc(THREAD); \
CALL_VM(SafepointMechanism::process_if_requested_with_exit_check(THREAD, true /* check asyncs */), \
@@ -1336,36 +1336,22 @@ void BytecodeInterpreter::run(interpreterState istate) {
CASE(_areturn):
CASE(_ireturn):
CASE(_freturn):
{
// Allow a safepoint before returning to frame manager.
SAFEPOINT;

goto handle_return;
}

CASE(_lreturn):
CASE(_dreturn):
{
CASE(_return): {
// Allow a safepoint before returning to frame manager.
SAFEPOINT;
RETURN_SAFEPOINT;
goto handle_return;
}

CASE(_return_register_finalizer): {

oop rcvr = LOCALS_OBJECT(0);
VERIFY_OOP(rcvr);
if (rcvr->klass()->has_finalizer()) {
CALL_VM(InterpreterRuntime::register_finalizer(THREAD, rcvr), handle_exception);
}
goto handle_return;
}
CASE(_return): {

// Allow a safepoint before returning to frame manager.
SAFEPOINT;
goto handle_return;
}

/* Array access byte-codes */

1 comment on commit fc8078a

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on fc8078a Sep 20, 2021

Please sign in to comment.