Skip to content

Commit

Permalink
Revert "[Wisp] Port bug fixes and Multi-tenant support to JDK17."
Browse files Browse the repository at this point in the history
  • Loading branch information
yuleil authored Jul 12, 2023
1 parent 2923980 commit d7763c1
Show file tree
Hide file tree
Showing 59 changed files with 588 additions and 1,113 deletions.
4 changes: 2 additions & 2 deletions make/data/hotspot-symbols/symbols-unix
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ JVM_IsCDSDumpingEnabled
JVM_IsConstructorIx
JVM_IsDumpingClassList
JVM_IsHiddenClass
JVM_IsInSameNative
JVM_IsInNative
JVM_IsInterface
JVM_IsPrimitiveClass
JVM_IsRecord
Expand All @@ -164,7 +164,7 @@ JVM_LoadLibrary
JVM_LookupDefineClass
JVM_LookupLambdaProxyClassFromArchive
JVM_LogLambdaFormInvoker
JVM_MarkPreempted
JVM_MarkPreempt
JVM_MaxMemory
JVM_MaxObjectInspectionAge
JVM_MonitorNotify
Expand Down
5 changes: 0 additions & 5 deletions src/hotspot/cpu/x86/sharedRuntime_x86_64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2157,11 +2157,6 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
if (!is_critical_native) {
__ lea(c_rarg0, Address(r15_thread, in_bytes(JavaThread::jni_environment_offset())));

if (EnableCoroutine) {
__ movptr(r11, Address(r15_thread, JavaThread::coroutine_list_offset()));
__ incrementl(Address(r11, Coroutine::native_call_counter_offset()));
}

// Now set thread in native
__ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native);
}
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,10 +989,6 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
}
#endif

if (EnableCoroutine) {
__ movptr(t, Address(r15_thread, JavaThread::coroutine_list_offset()));
__ incrementl(Address(t, Coroutine::native_call_counter_offset()));
}
// Change state to native

__ movl(Address(thread, JavaThread::thread_state_offset()),
Expand Down
10 changes: 0 additions & 10 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4771,7 +4771,6 @@ int com_alibaba_wisp_engine_WispTask::_interrupted_offset = 0;
int com_alibaba_wisp_engine_WispTask::_activeCount_offset = 0;
int com_alibaba_wisp_engine_WispTask::_stealCount_offset = 0;
int com_alibaba_wisp_engine_WispTask::_stealFailureCount_offset = 0;
int com_alibaba_wisp_engine_WispTask::_preemptCount_offset = 0;

void com_alibaba_wisp_engine_WispTask::compute_offsets() {
InstanceKlass* ik = vmClasses::com_alibaba_wisp_engine_WispTask_klass();
Expand All @@ -4783,21 +4782,12 @@ void com_alibaba_wisp_engine_WispTask::compute_offsets() {
compute_offset(_activeCount_offset, ik, vmSymbols::activeCount_name(), vmSymbols::int_signature());
compute_offset(_stealCount_offset, ik, vmSymbols::stealCount_name(), vmSymbols::int_signature());
compute_offset(_stealFailureCount_offset, ik, vmSymbols::stealFailureCount_name(), vmSymbols::int_signature());
compute_offset(_preemptCount_offset, ik, vmSymbols::preemptCount_name(), vmSymbols::int_signature());
}

void com_alibaba_wisp_engine_WispTask::set_jvmParkStatus(oop obj, jint status) {
return obj->int_field_put(_jvmParkStatus_offset, status);
}

int com_alibaba_wisp_engine_WispTask::get_preemptCount(oop obj) {
return obj->int_field(_preemptCount_offset);
}

void com_alibaba_wisp_engine_WispTask::set_preemptCount(oop obj, jint count) {
obj->int_field_put(_preemptCount_offset, count);
}

int com_alibaba_wisp_engine_WispTask::get_id(oop obj) {
return obj->int_field(_id_offset);
}
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/classfile/javaClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,6 @@ class com_alibaba_wisp_engine_WispTask: AllStatic {
static int _activeCount_offset;
static int _stealCount_offset;
static int _stealFailureCount_offset;
static int _preemptCount_offset;
public:
static void set_jvmParkStatus(oop obj, jint status);
static int get_id(oop obj);
Expand All @@ -1837,8 +1836,6 @@ class com_alibaba_wisp_engine_WispTask: AllStatic {
static int get_activeCount(oop obj);
static int get_stealCount(oop obj);
static int get_stealFailureCount(oop obj);
static int get_preemptCount(oop obj);
static void set_preemptCount(oop obj, jint count);

static void compute_offsets();
};
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/classfile/vmSymbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,6 @@
template(activeCount_name, "activeCount") \
template(stealCount_name, "stealCount") \
template(stealFailureCount_name, "stealFailureCount") \
template(preemptCount_name, "preemptCount") \
template(unparkById_name, "unparkById") \
template(interruptById_name, "interruptById") \
template(interrupted_name, "interrupted") \
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/include/jvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ JNIEXPORT void JNICALL
JVM_SetNativeThreadName(JNIEnv *env, jobject jthread, jstring name);

JNIEXPORT jboolean JNICALL
JVM_IsInSameNative(JNIEnv *env, jobject jthread);
JVM_IsInNative(JNIEnv *env, jobject jthread);

/* getStackTrace() and getAllStackTraces() method */
JNIEXPORT jobjectArray JNICALL
Expand Down Expand Up @@ -1056,7 +1056,7 @@ JNIEXPORT jint JNICALL
JVM_GetProxyUnpark(JNIEnv* env, jclass clz, jintArray res);

JNIEXPORT void JNICALL
JVM_MarkPreempted(JNIEnv* env, jclass clz, jobject thread, jboolean force);
JVM_MarkPreempt(JNIEnv* env, jclass clz, jobject thread);

/*************************************************************************
PART 3: I/O and Network Support
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "jvmci/vmStructs_jvmci.hpp"
#include "oops/klassVtable.hpp"
#include "oops/objArrayKlass.hpp"
#include "runtime/coroutine.hpp"
#include "runtime/deoptimization.hpp"
#include "runtime/flags/jvmFlag.hpp"
#include "runtime/osThread.hpp"
Expand Down Expand Up @@ -191,9 +190,6 @@
nonstatic_field(JavaThread, _jni_environment, JNIEnv) \
nonstatic_field(JavaThread, _poll_data, SafepointMechanism::ThreadData) \
nonstatic_field(JavaThread, _stack_overflow_state._reserved_stack_activation, address) \
nonstatic_field(JavaThread, _current_coroutine, Coroutine*) \
nonstatic_field(Coroutine, _wisp_thread, WispThread*) \
nonstatic_field(WispThread, _thread, JavaThread*) \
\
static_field(java_lang_Class, _klass_offset, int) \
static_field(java_lang_Class, _array_klass_offset, int) \
Expand Down
35 changes: 35 additions & 0 deletions src/hotspot/share/opto/graphKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3653,6 +3653,41 @@ Node* GraphKit::insert_mem_bar_volatile(int opcode, int alias_idx, Node* precede

#define __ ideal.

void GraphKit::make_wisp_yield(ciMethod* method) {
assert(EnableCoroutine, "Coroutine is disabled");
IdealKit ideal(this, true);
Node* no_base = __ top();
Node* tls = __ thread();
const int mark_offset = in_bytes(JavaThread::wisp_preempt_offset());
Node* mark_preempt_addr = __ AddP(no_base, tls, __ ConX(mark_offset));
Node* mark_preempt_val = __ load(__ ctrl(), mark_preempt_addr, TypeInt::BYTE, T_BYTE, Compile::AliasIdxRaw);
Node* zero = __ ConI(0);

// Get base of thread-local storage area
Node* thread = _gvn.transform( new ThreadLocalNode() );

// Get method
const TypePtr* method_type = TypeMetadataPtr::make(method);
Node *method_node = _gvn.transform( ConNode::make(method_type) );

kill_dead_locals();

// For some reason, this call reads only raw memory.
__ if_then(mark_preempt_val, BoolTest::ne, zero) ; {
// Totally 8 parameters, 2 used, 6 NULL.
// make_runtime_call itself would set control node, so
// we should never pass control node here.
Node* call = make_runtime_call(RC_NARROW_MEM,
OptoRuntime::yield_method_exit_Type(),
CAST_FROM_FN_PTR(address, SharedRuntime::wisp_yield),
"wisp_yield",
TypeRawPtr::BOTTOM,
thread, method_node);
} __ end_if();
final_sync(ideal);
}


//------------------------------shared_lock------------------------------------
// Emit locking code.
FastLockNode* GraphKit::shared_lock(Node* obj) {
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/opto/graphKit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ class GraphKit : public Phase {
Node* parm4 = NULL, Node* parm5 = NULL,
Node* parm6 = NULL, Node* parm7 = NULL);

void make_wisp_yield(ciMethod* method);
Node* sign_extend_byte(Node* in);
Node* sign_extend_short(Node* in);

Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/opto/parse1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,11 @@ void Parse::return_current(Node* value) {
if (C->env()->dtrace_method_probes()) {
make_dtrace_method_exit(method());
}
// Deadlocks may happen if programs yield at return of synchronized methods.
// Because the yield may come before monitorexit.
if (EnableCoroutine && EnableCoroutineTimeSlice && (!method()->is_synchronized())) {
make_wisp_yield(method());
}
SafePointNode* exit_return = _exits.map();
exit_return->in( TypeFunc::Control )->add_req( control() );
exit_return->in( TypeFunc::I_O )->add_req( i_o () );
Expand Down
15 changes: 15 additions & 0 deletions src/hotspot/share/opto/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,21 @@ JRT_ENTRY_NO_ASYNC(void, OptoRuntime::register_finalizer(oopDesc* obj, JavaThrea
InstanceKlass::register_finalizer(instanceOop(obj), CHECK);
JRT_END


const TypeFunc *OptoRuntime::yield_method_exit_Type() {
// create input type (domain)
const Type **fields = TypeTuple::fields(2);
fields[TypeFunc::Parms+0] = TypeRawPtr::BOTTOM; // Thread-local storage
fields[TypeFunc::Parms+1] = TypeMetadataPtr::BOTTOM; // Method*; Method we are entering
const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms+2,fields);

// create result type (range)
fields = TypeTuple::fields(0);

const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+0,fields);

return TypeFunc::make(domain,range);
}
//-----------------------------------------------------------------------------

NamedCounter * volatile OptoRuntime::_named_counters = NULL;
Expand Down
39 changes: 9 additions & 30 deletions src/hotspot/share/prims/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3102,25 +3102,14 @@ JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
}
JVM_END

JVM_ENTRY(jboolean, JVM_IsInSameNative(JNIEnv* env, jobject jthread))
assert(EnableCoroutine, "coroutine not enabled");
JVM_ENTRY(jboolean, JVM_IsInNative(JNIEnv* env, jobject jthread))
assert(EnableCoroutine, "Coroutine is disabled");
oop java_thread = JNIHandles::resolve_non_null(jthread);
MutexLocker ml(thread->threadObj() == java_thread ? NULL : Threads_lock);
// We need to re-resolve the java_thread, since a GC might have happened during the
// acquire of the lock
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread));
// the thread is in native status and the native call counter isn't changed during two calls
// then return true
if (thr != NULL && thr->thread_state() == _thread_in_native) {
Coroutine* coro = thr->coroutine_list();
assert(coro != NULL, "coroutine list");
if (coro->last_native_call_counter() == coro->native_call_counter()) {
return JNI_TRUE;
} else {
coro->set_last_native_call_counter(coro->native_call_counter());
}
}
return JNI_FALSE;
return thr != NULL && thr->thread_state() == _thread_in_native;
JVM_END

JVM_ENTRY(jboolean, JVM_CheckAndClearNativeInterruptForWisp(JNIEnv* env, jobject task, jobject jthread))
Expand Down Expand Up @@ -3883,24 +3872,14 @@ JVM_ENTRY(jint, JVM_GetProxyUnpark(JNIEnv* env, jclass klass, jintArray res))
return WispThread::get_proxy_unpark(res);
JVM_END

JVM_ENTRY(void, JVM_MarkPreempted(JNIEnv* env, jclass klass, jobject threadObj, jboolean force))
JVM_ENTRY(void, JVM_MarkPreempt(JNIEnv* env, jclass klass, jobject threadObj))
assert(EnableCoroutine, "Coroutine is disabled");
JavaThread* thr = NULL;
{
//Use lock to prevent deleting thr when we do the update on it.
MutexLocker mu(Threads_lock);
thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(threadObj));
//Use lock to prevent deleting thr when we do the update on it.
MutexLocker mu(Threads_lock);
JavaThread* thr = java_lang_Thread::thread(JNIHandles::resolve_non_null(threadObj));

if (thr == NULL || thr->is_terminated() ||
thr->wisp_preempted()) { // already mark preempted, do not fire safepoint again
return;
}
thr->set_wisp_preempted(true);
}
// fire an empty safepoint to let the thread go check flag
if (force) {
VM_ForceSafepoint force_safepoint_op;
VMThread::execute(&force_safepoint_op);
if (thr != NULL && !thr->is_terminated()) {
thr->set_wisp_preempt(true);
}
JVM_END

Expand Down
71 changes: 2 additions & 69 deletions src/hotspot/share/runtime/coroutine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ Coroutine* Coroutine::create_thread_coroutine(JavaThread* thread, CoroutineStack
coro->_metadata_handles = NULL;
coro->_thread_status = JavaThreadStatus::RUNNABLE;
coro->_java_call_counter = 0;
coro->_last_native_call_counter = 0;
coro->_native_call_counter = 0;
#if defined(_WINDOWS)
coro->_last_SEH = NULL;
#endif
Expand All @@ -135,7 +133,6 @@ Coroutine* Coroutine::create_thread_coroutine(JavaThread* thread, CoroutineStack
coro->_wisp_task_id = WISP_ID_NOT_SET;
coro->_enable_steal_count = 1;
coro->_wisp_post_steal_resource_area = NULL;
coro->_is_yielding = false;
thread->set_current_coroutine(coro);
return coro;
}
Expand Down Expand Up @@ -175,8 +172,6 @@ Coroutine* Coroutine::create_coroutine(JavaThread* thread, CoroutineStack* stack
coro->_metadata_handles = NULL;
coro->_thread_status = JavaThreadStatus::RUNNABLE;
coro->_java_call_counter = 0;
coro->_last_native_call_counter = 0;
coro->_native_call_counter = 0;
#if defined(_WINDOWS)
coro->_last_SEH = NULL;
#endif
Expand All @@ -190,7 +185,6 @@ Coroutine* Coroutine::create_coroutine(JavaThread* thread, CoroutineStack* stack
// so we set `_enable_steal_count` to 1 which means this coroutine can be stolen when it starts.
coro->_enable_steal_count = 1;
coro->_wisp_post_steal_resource_area = new (mtWisp) WispResourceArea(coro, 32);
coro->_is_yielding = false;
return coro;
}

Expand Down Expand Up @@ -269,19 +263,6 @@ void Coroutine::nmethods_do(CodeBlobClosure* cf) {
frames_do(&fc);
}

class compiledMethods_do_Closure: public FrameClosure {
private:
CodeBlobClosure* _cf;
public:
compiledMethods_do_Closure(CodeBlobClosure* cf): _cf(cf) { }
void frames_do(frame* fr, RegisterMap* map) { fr->compiledMethods_do(_cf); }
};

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

class metadata_do_Closure: public FrameClosure {
private:
MetadataClosure* _f;
Expand Down Expand Up @@ -444,12 +425,11 @@ void Coroutine::print_stack_on(outputStream* st) {
java_lang_String::as_utf8_string(name, buf, sizeof(buf));
}
}
st->print(" \"%s\" #%d active=%d steal=%d steal_fail=%d preempt=%d", buf,
st->print(" \"%s\" #%d active=%d steal=%d steal_fail=%d", buf,
com_alibaba_wisp_engine_WispTask::get_id(_wisp_task),
com_alibaba_wisp_engine_WispTask::get_activeCount(_wisp_task),
com_alibaba_wisp_engine_WispTask::get_stealCount(_wisp_task),
com_alibaba_wisp_engine_WispTask::get_stealFailureCount(_wisp_task),
com_alibaba_wisp_engine_WispTask::get_preemptCount(_wisp_task));
com_alibaba_wisp_engine_WispTask::get_stealFailureCount(_wisp_task));
} // else, we're only using the JKU part
st->print("\n");

Expand Down Expand Up @@ -744,53 +724,6 @@ void WispThread::interrupt(int task_id, TRAPS) {

}

void Coroutine::after_safepoint(JavaThread* thread) {
assert(Thread::current() == thread, "sanity check");

if (!thread->safepoint_state()->is_running()) {
return;
}
Coroutine* coroutine = thread->current_coroutine();
if (thread->thread_state() != _thread_in_Java ||
// indicates we're inside compiled code or interpreter.
// rather than thread state transition.
coroutine->_is_yielding || !thread->wisp_preempted() ||
thread->has_pending_exception() || thread->has_async_exception_condition()) {
return;
}

oop wisp_task = thread->current_coroutine()->_wisp_task;
if (wisp_task != NULL) { // expose to perfCount and jstack
int cnt = com_alibaba_wisp_engine_WispTask::get_preemptCount(wisp_task);
com_alibaba_wisp_engine_WispTask::set_preemptCount(wisp_task, cnt + 1);
} else {
assert(!WispThread::wisp_booted(), "wisp_task should be non-null when wisp is enabled");
}

coroutine->_is_yielding = true;
// "yield" will immediately switch context to execute other coroutines.
// After all the runnable coroutines has been executed, we'll switch back.
//
// - The preempt mechanism should be disabled when current coroutine is calling "yield"
// - The preempt mechanism should be enabled during "other" coroutines are executing

thread->set_wisp_preempted(false);
ThreadInVMfromJava tiv(thread);
JavaValue result(T_VOID);
JavaCallArguments args;
JavaCalls::call_static(&result,
vmClasses::Thread_klass(),
vmSymbols::yield_name(),
vmSymbols::void_method_signature(),
&args,
thread);
coroutine->_is_yielding = false;

if (thread->has_pending_exception() || thread->has_async_exception_condition()) {
thread->clear_pending_exception();
}
}

EnableStealMark::EnableStealMark(Thread* thread) {
assert(JavaThread::current() == thread, "current thread check");
if (EnableSteal) {
Expand Down
Loading

0 comments on commit d7763c1

Please sign in to comment.