Skip to content

Commit

Permalink
[Wisp] Remove useless list of coroutine_stack and coroutine_stack_cac…
Browse files Browse the repository at this point in the history
…he. (port to jdk17)

Summary: Remove useless code

Test Plan: all wisp tests

Reviewed-by: yulei

Issue:
#90
  • Loading branch information
ZhaiMo15 committed Jul 17, 2023
1 parent b1b43d5 commit 310449a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 43 deletions.
29 changes: 6 additions & 23 deletions src/hotspot/share/prims/unsafe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,7 @@ JVM_ENTRY(void, CoroutineSupport_switchToAndTerminate(JNIEnv* env, jclass klass,

java_dyn_CoroutineBase::set_native_coroutine(old_oop, 0);

CoroutineStack* stack = coro->stack();
stack->remove_from_list(thread->coroutine_stack_list());
if (thread->coroutine_stack_cache_size() < MaxFreeCoroutinesCacheSize) {
stack->insert_into_list(thread->coroutine_stack_cache());
thread->coroutine_stack_cache_size() ++;
} else {
CoroutineStack::free_stack(stack, thread);
}
CoroutineStack::free_stack(coro->stack(), thread);
delete coro;
JVM_END

Expand All @@ -922,19 +915,11 @@ JVM_ENTRY(jlong, CoroutineSupport_createCoroutine(JNIEnv* env, jclass klass, job
if (stack_size == 0 || stack_size < -1) {
THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "invalid stack size");
}
CoroutineStack* stack = NULL;
if (stack_size <= 0 && thread->coroutine_stack_cache_size() > 0) {
stack = thread->coroutine_stack_cache();
stack->remove_from_list(thread->coroutine_stack_cache());
thread->coroutine_stack_cache_size() --;
DEBUG_CORO_ONLY(tty->print("reused coroutine stack at %08x\n", stack->_stack_base));
} else {
stack = CoroutineStack::create_stack(thread, stack_size);
if (stack == NULL) {
THROW_0(vmSymbols::java_lang_OutOfMemoryError());
}

CoroutineStack* stack = CoroutineStack::create_stack(thread, stack_size);
if (stack == NULL) {
THROW_0(vmSymbols::java_lang_OutOfMemoryError());
}
stack->insert_into_list(thread->coroutine_stack_list());

Coroutine* coro = Coroutine::create_coroutine(thread, stack, JNIHandles::resolve(coroutine));
if (coro == NULL) {
Expand All @@ -952,9 +937,7 @@ JVM_ENTRY(jboolean, CoroutineSupport_testDisposableAndTryReleaseStack(JNIEnv* en

jboolean is_disposable = coro->is_disposable();
if (is_disposable) {
CoroutineStack* stack = coro->stack();
stack->remove_from_list(thread->coroutine_stack_list());
CoroutineStack::free_stack(stack, thread);
CoroutineStack::free_stack(coro->stack(), thread);
delete coro;
}
return is_disposable;
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2095,9 +2095,6 @@ const intx ObjectAlignmentInBytes = 8;
product(uintx, DefaultCoroutineStackSize, 128*K, \
"Default size of stack that is associated with new coroutine") \
\
product(uintx, MaxFreeCoroutinesCacheSize, 20, \
"The max number of free coroutine stacks a thread can keep") \
\
product(bool, UseWispMonitor, false, \
"yields to next coroutine when ObjectMonitor is contended") \
\
Expand Down
12 changes: 1 addition & 11 deletions src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1098,9 +1098,6 @@ JavaThread::JavaThread() :
_frames_to_pop_failed_realloc(0),

// coroutine support
_coroutine_stack_cache(nullptr),
_coroutine_stack_cache_size(0),
_coroutine_stack_list(nullptr),
_coroutine_list(nullptr),
_current_coroutine(nullptr),
_wisp_preempted(false),
Expand Down Expand Up @@ -1262,12 +1259,6 @@ JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) : JavaThread
}

JavaThread::~JavaThread() {
while (EnableCoroutine && coroutine_stack_cache() != NULL) {
CoroutineStack* stack = coroutine_stack_cache();
stack->remove_from_list(coroutine_stack_cache());
CoroutineStack::free_stack(stack, this);
}

while (EnableCoroutine && coroutine_list() != NULL) {
CoroutineStack::free_stack(coroutine_list()->stack(), this);
delete coroutine_list();
Expand Down Expand Up @@ -4150,8 +4141,7 @@ void Threads::verify() {

void JavaThread::initialize_coroutine_support() {
assert(EnableCoroutine, "EnableCoroutine isn't enable");
CoroutineStack::create_thread_stack(this)->insert_into_list(_coroutine_stack_list);
Coroutine::create_thread_coroutine(this, _coroutine_stack_list)->insert_into_list(_coroutine_list);
Coroutine::create_thread_coroutine(this, CoroutineStack::create_thread_stack(this))->insert_into_list(_coroutine_list);
}

#ifndef PRODUCT
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/runtime/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,19 +1038,13 @@ class JavaThread: public Thread {
int _frames_to_pop_failed_realloc;

// coroutine support
CoroutineStack* _coroutine_stack_cache;
uintx _coroutine_stack_cache_size;
CoroutineStack* _coroutine_stack_list;
Coroutine* _coroutine_list;
Coroutine* _current_coroutine;
bool _wisp_preempted;

intptr_t _coroutine_temp;

public:
CoroutineStack*& coroutine_stack_cache() { return _coroutine_stack_cache; }
uintx& coroutine_stack_cache_size() { return _coroutine_stack_cache_size; }
CoroutineStack*& coroutine_stack_list() { return _coroutine_stack_list; }
Coroutine*& coroutine_list() { return _coroutine_list; }
Coroutine* current_coroutine() { return _current_coroutine; }
void set_current_coroutine(Coroutine *coro) { _current_coroutine = coro; }
Expand Down

0 comments on commit 310449a

Please sign in to comment.