Skip to content

Commit

Permalink
WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
nebula-xm committed Aug 31, 2023
1 parent 6e2b72e commit 6a53a8d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
25 changes: 14 additions & 11 deletions src/hotspot/share/runtime/coroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Coroutine::~Coroutine() {
}
}

void Coroutine::frames_do(FrameClosure* fc) {
void Coroutine::frames_do(FrameClosure* fc, bool process_frames) {
switch (_state) {
case Coroutine::_created:
// the coroutine has never been run
Expand All @@ -214,7 +214,7 @@ void Coroutine::frames_do(FrameClosure* fc) {
// the contents of this coroutine have already been visited
break;
case Coroutine::_onstack:
_stack->frames_do(fc);
_stack->frames_do(fc, process_frames);
break;
case Coroutine::_dead:
// coroutine is dead, ignore
Expand Down Expand Up @@ -301,9 +301,7 @@ class oops_do_Closure: public FrameClosure {
void frames_do(frame* fr, RegisterMap* map) { fr->oops_do(_f, _cf, map); }
};

void Coroutine::oops_do(OopClosure* f, CodeBlobClosure* cf) {
oops_do_Closure fc(f, cf);
frames_do(&fc);
void Coroutine::oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf) {
if (_state == _onstack) {
assert(_handle_area != NULL, "_onstack coroutine should have _handle_area");
DEBUG_CORO_ONLY(tty->print_cr("collecting handle area %08x", _handle_area));
Expand All @@ -319,6 +317,11 @@ void Coroutine::oops_do(OopClosure* f, CodeBlobClosure* cf) {
}
}

void Coroutine::oops_do_frames(OopClosure* f, CodeBlobClosure* cf) {
oops_do_Closure fc(f, cf);
frames_do(&fc, false);
}

class nmethods_do_Closure: public FrameClosure {
private:
CodeBlobClosure* _cf;
Expand All @@ -329,7 +332,7 @@ class nmethods_do_Closure: public FrameClosure {

void Coroutine::nmethods_do(CodeBlobClosure* cf) {
nmethods_do_Closure fc(cf);
frames_do(&fc);
frames_do(&fc, true);
}

class compiledMethods_do_Closure: public FrameClosure {
Expand All @@ -342,7 +345,7 @@ class compiledMethods_do_Closure: public FrameClosure {

void Coroutine::compiledMethods_do(CodeBlobClosure* cf) {
compiledMethods_do_Closure fc(cf);
frames_do(&fc);
frames_do(&fc, true);
}

class metadata_do_Closure: public FrameClosure {
Expand All @@ -360,7 +363,7 @@ void Coroutine::metadata_do(MetadataClosure* f) {
}
}
metadata_do_Closure fc(f);
frames_do(&fc);
frames_do(&fc, true);
}

class frames_do_Closure: public FrameClosure {
Expand All @@ -373,7 +376,7 @@ class frames_do_Closure: public FrameClosure {

void Coroutine::frames_do(void f(frame*, const RegisterMap* map)) {
frames_do_Closure fc(f);
frames_do(&fc);
frames_do(&fc, true);
}

bool Coroutine::is_disposable() {
Expand Down Expand Up @@ -450,7 +453,7 @@ void CoroutineStack::free_stack(CoroutineStack* stack, JavaThread* thread) {
delete stack;
}

void CoroutineStack::frames_do(FrameClosure* fc) {
void CoroutineStack::frames_do(FrameClosure* fc, bool process_frames) {
assert(_last_sp != NULL, "CoroutineStack with NULL last_sp");

DEBUG_CORO_ONLY(tty->print_cr("frames_do stack %08x", _stack_base));
Expand All @@ -469,7 +472,7 @@ void CoroutineStack::frames_do(FrameClosure* fc) {
}
#endif

StackFrameStream fst(_thread, fr, true /* update */, true /* process_frames */);
StackFrameStream fst(_thread, fr, true /* update */, process_frames);
fst.register_map()->set_location(get_fp_reg()->as_VMReg(), (address)_last_sp);
fst.register_map()->set_include_argument_oops(false);
for(; !fst.is_done(); fst.next()) {
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/runtime/coroutine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Coroutine: public CHeapObj<mtThread>, public DoublyLinkedList<Coroutine> {
// objects of this type can only be created via static functions
Coroutine() { }

void frames_do(FrameClosure* fc);
void frames_do(FrameClosure* fc, bool process_frames);

static void set_coroutine_base(intptr_t **&base, JavaThread* thread, jobject obj, Coroutine *coro, oop coroutineObj, address coroutine_start);

Expand Down Expand Up @@ -222,7 +222,8 @@ class Coroutine: public CHeapObj<mtThread>, public DoublyLinkedList<Coroutine> {
bool in_critical(JavaThread* thread);

// GC support
void oops_do(OopClosure* f, CodeBlobClosure* cf);
void oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf);
void oops_do_frames(OopClosure* f, CodeBlobClosure* cf);
void nmethods_do(CodeBlobClosure* cf);
void compiledMethods_do(CodeBlobClosure* cf);
void metadata_do(MetadataClosure* f);
Expand Down Expand Up @@ -304,7 +305,7 @@ class CoroutineStack: public CHeapObj<mtThread>, public DoublyLinkedList<Corouti
frame last_frame(Coroutine* coro, RegisterMap& map) const;

// GC support
void frames_do(FrameClosure* fc);
void frames_do(FrameClosure* fc, bool process_frames);

static ByteSize stack_base_offset() {
return byte_offset_of(CoroutineStack, _stack_overflow_state._stack_base);
Expand Down
11 changes: 10 additions & 1 deletion src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2100,7 +2100,7 @@ void JavaThread::oops_do_no_frames(OopClosure* f, CodeBlobClosure* cf) {
CoroutineSupportLocker csl(this);
Coroutine* current = _coroutine_list;
do {
current->oops_do(f, cf);
current->oops_do_no_frames(f, cf);
current = current->next();
} while (current != _coroutine_list);
}
Expand Down Expand Up @@ -2142,6 +2142,15 @@ void JavaThread::oops_do_frames(OopClosure* f, CodeBlobClosure* cf) {
for (StackFrameStream fst(this, true /* update */, false /* process_frames */); !fst.is_done(); fst.next()) {
fst.current()->oops_do(f, cf, fst.register_map());
}

if (EnableCoroutine) {
CoroutineSupportLocker csl(this);
Coroutine* current = _coroutine_list;
do {
current->oops_do_frames(f, cf);
current = current->next();
} while (current != _coroutine_list);
}
}

#ifdef ASSERT
Expand Down

0 comments on commit 6a53a8d

Please sign in to comment.