Skip to content

Commit

Permalink
8286666: JEP 429: Implementation of Scoped Values (Incubator)
Browse files Browse the repository at this point in the history
Reviewed-by: psandoz, dlong, alanb, mcimadamore
  • Loading branch information
Andrew Haley authored and Alan Bateman committed Dec 7, 2022
1 parent ccc69af commit 221e1a4
Show file tree
Hide file tree
Showing 61 changed files with 2,889 additions and 230 deletions.
8 changes: 6 additions & 2 deletions make/data/hotspot-symbols/symbols-unix
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ JVM_RegisterLambdaProxyClassForArchiving
JVM_RegisterSignal
JVM_ReleaseUTF
JVM_ReportFinalizationComplete
JVM_ExtentLocalCache
JVM_SetExtentLocalCache
JVM_SetArrayElement
JVM_SetClassSigners
JVM_SetNativeThreadName
Expand Down Expand Up @@ -225,4 +223,10 @@ JVM_VirtualThreadMountEnd
JVM_VirtualThreadUnmountBegin
JVM_VirtualThreadUnmountEnd
JVM_VirtualThreadHideFrames

# Scoped values
JVM_EnsureMaterializedForStackWalk_func
JVM_FindScopedValueBindings
JVM_ScopedValueCache
JVM_SetScopedValueCache
#
5 changes: 5 additions & 0 deletions src/hotspot/cpu/aarch64/aarch64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -3632,6 +3632,11 @@ encode %{
ciEnv::current()->record_failure("CodeCache is full");
return;
}
} else if (_method->intrinsic_id() == vmIntrinsicID::_ensureMaterializedForStackWalk) {
// The NOP here is purely to ensure that eliding a call to
// JVM_EnsureMaterializedForStackWalk doesn't change the code size.
__ nop();
__ block_comment("call JVM_EnsureMaterializedForStackWalk (elided)");
} else {
int method_index = resolved_method_index(cbuf);
RelocationHolder rspec = _optimized_virtual ? opt_virtual_call_Relocation::spec(method_index)
Expand Down
8 changes: 7 additions & 1 deletion src/hotspot/cpu/x86/x86_64.ad
Original file line number Diff line number Diff line change
Expand Up @@ -2164,13 +2164,19 @@ encode %{
// determine who we intended to call.
MacroAssembler _masm(&cbuf);
cbuf.set_insts_mark();
$$$emit8$primary;

if (!_method) {
$$$emit8$primary;
emit_d32_reloc(cbuf, (int) ($meth$$method - ((intptr_t) cbuf.insts_end()) - 4),
runtime_call_Relocation::spec(),
RELOC_DISP32);
} else if (_method->intrinsic_id() == vmIntrinsicID::_ensureMaterializedForStackWalk) {
// The NOP here is purely to ensure that eliding a call to
// JVM_EnsureMaterializedForStackWalk doesn't change the code size.
__ addr_nop_5();
__ block_comment("call JVM_EnsureMaterializedForStackWalk (elided)");
} else {
$$$emit8$primary;
int method_index = resolved_method_index(cbuf);
RelocationHolder rspec = _optimized_virtual ? opt_virtual_call_Relocation::spec(method_index)
: static_call_Relocation::spec(method_index);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ bool Compiler::is_intrinsic_supported(const methodHandle& method) {
case vmIntrinsics::_getModifiers:
case vmIntrinsics::_currentCarrierThread:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_extentLocalCache:
case vmIntrinsics::_scopedValueCache:
case vmIntrinsics::_dabs:
case vmIntrinsics::_dsqrt:
case vmIntrinsics::_dsqrt_strict:
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/c1/c1_LIRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,8 +1428,8 @@ void LIRGenerator::do_getObjectSize(Intrinsic* x) {
__ branch_destination(L_done->label());
}

void LIRGenerator::do_extentLocalCache(Intrinsic* x) {
do_JavaThreadField(x, JavaThread::extentLocalCache_offset());
void LIRGenerator::do_scopedValueCache(Intrinsic* x) {
do_JavaThreadField(x, JavaThread::scopedValueCache_offset());
}

// Example: Thread.currentCarrierThread()
Expand Down Expand Up @@ -2948,7 +2948,7 @@ void LIRGenerator::do_Intrinsic(Intrinsic* x) {
case vmIntrinsics::_getObjectSize: do_getObjectSize(x); break;
case vmIntrinsics::_currentCarrierThread: do_currentCarrierThread(x); break;
case vmIntrinsics::_currentThread: do_vthread(x); break;
case vmIntrinsics::_extentLocalCache: do_extentLocalCache(x); break;
case vmIntrinsics::_scopedValueCache: do_scopedValueCache(x); break;

case vmIntrinsics::_dlog: // fall through
case vmIntrinsics::_dlog10: // fall through
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/c1/c1_LIRGenerator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class LIRGenerator: public InstructionVisitor, public BlockClosure {
void do_getClass(Intrinsic* x);
void do_getObjectSize(Intrinsic* x);
void do_currentCarrierThread(Intrinsic* x);
void do_extentLocalCache(Intrinsic* x);
void do_scopedValueCache(Intrinsic* x);
void do_vthread(Intrinsic* x);
void do_JavaThreadField(Intrinsic* x, ByteSize offset);
void do_FmaIntrinsic(Intrinsic* x);
Expand Down
9 changes: 5 additions & 4 deletions src/hotspot/share/classfile/javaClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ int java_lang_Thread::_interrupted_offset;
int java_lang_Thread::_tid_offset;
int java_lang_Thread::_continuation_offset;
int java_lang_Thread::_park_blocker_offset;
int java_lang_Thread::_extentLocalBindings_offset;
int java_lang_Thread::_scopedValueBindings_offset;
JFR_ONLY(int java_lang_Thread::_jfr_epoch_offset;)

#define THREAD_FIELDS_DO(macro) \
Expand All @@ -1696,7 +1696,7 @@ JFR_ONLY(int java_lang_Thread::_jfr_epoch_offset;)
macro(_tid_offset, k, "tid", long_signature, false); \
macro(_park_blocker_offset, k, "parkBlocker", object_signature, false); \
macro(_continuation_offset, k, "cont", continuation_signature, false); \
macro(_extentLocalBindings_offset, k, "extentLocalBindings", object_signature, false);
macro(_scopedValueBindings_offset, k, "scopedValueBindings", object_signature, false);

void java_lang_Thread::compute_offsets() {
assert(_holder_offset == 0, "offsets should be initialized only once");
Expand Down Expand Up @@ -1729,8 +1729,9 @@ void java_lang_Thread::set_jvmti_thread_state(oop java_thread, JvmtiThreadState*
java_thread->address_field_put(_jvmti_thread_state_offset, (address)state);
}

void java_lang_Thread::clear_extentLocalBindings(oop java_thread) {
java_thread->obj_field_put(_extentLocalBindings_offset, NULL);
void java_lang_Thread::clear_scopedValueBindings(oop java_thread) {
assert(java_thread != NULL, "need a java_lang_Thread pointer here");
java_thread->obj_field_put(_scopedValueBindings_offset, NULL);
}

oop java_lang_Thread::holder(oop java_thread) {
Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/classfile/javaClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class java_lang_Thread : AllStatic {
static int _tid_offset;
static int _continuation_offset;
static int _park_blocker_offset;
static int _extentLocalBindings_offset;
static int _scopedValueBindings_offset;
JFR_ONLY(static int _jfr_epoch_offset;)

static void compute_offsets();
Expand Down Expand Up @@ -398,8 +398,8 @@ class java_lang_Thread : AllStatic {
static JvmtiThreadState* jvmti_thread_state(oop java_thread);
static void set_jvmti_thread_state(oop java_thread, JvmtiThreadState* state);

// Clear all extent local bindings on error
static void clear_extentLocalBindings(oop java_thread);
// Clear all scoped value bindings on error
static void clear_scopedValueBindings(oop java_thread);

// Blocker object responsible for thread parking
static oop park_blocker(oop java_thread);
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/classfile/vmIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ bool vmIntrinsics::preserves_state(vmIntrinsics::ID id) {
case vmIntrinsics::_isInstance:
case vmIntrinsics::_currentCarrierThread:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_extentLocalCache:
case vmIntrinsics::_scopedValueCache:
case vmIntrinsics::_dabs:
case vmIntrinsics::_fabs:
case vmIntrinsics::_iabs:
Expand Down Expand Up @@ -127,8 +127,8 @@ bool vmIntrinsics::can_trap(vmIntrinsics::ID id) {
case vmIntrinsics::_currentCarrierThread:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_setCurrentThread:
case vmIntrinsics::_extentLocalCache:
case vmIntrinsics::_setExtentLocalCache:
case vmIntrinsics::_scopedValueCache:
case vmIntrinsics::_setScopedValueCache:
case vmIntrinsics::_dabs:
case vmIntrinsics::_fabs:
case vmIntrinsics::_iabs:
Expand Down Expand Up @@ -265,8 +265,8 @@ bool vmIntrinsics::disabled_by_jvm_flags(vmIntrinsics::ID id) {
if (!InlineThreadNatives) return true;
break;
case vmIntrinsics::_setCurrentThread:
case vmIntrinsics::_extentLocalCache:
case vmIntrinsics::_setExtentLocalCache:
case vmIntrinsics::_scopedValueCache:
case vmIntrinsics::_setScopedValueCache:
case vmIntrinsics::_floatToRawIntBits:
case vmIntrinsics::_intBitsToFloat:
case vmIntrinsics::_doubleToRawLongBits:
Expand Down
20 changes: 13 additions & 7 deletions src/hotspot/share/classfile/vmIntrinsics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class methodHandle;
do_intrinsic(_identityHashCode, java_lang_System, identityHashCode_name, object_int_signature, F_SN) \
do_name( identityHashCode_name, "identityHashCode") \
do_intrinsic(_currentTimeMillis, java_lang_System, currentTimeMillis_name, void_long_signature, F_SN) \
\
\
do_name( currentTimeMillis_name, "currentTimeMillis") \
do_intrinsic(_nanoTime, java_lang_System, nanoTime_name, void_long_signature, F_SN) \
do_name( nanoTime_name, "nanoTime") \
Expand All @@ -286,12 +286,15 @@ class methodHandle;
do_intrinsic(_currentThread, java_lang_Thread, currentThread_name, currentThread_signature, F_SN) \
do_name( currentThread_name, "currentThread") \
do_signature(currentThread_signature, "()Ljava/lang/Thread;") \
do_intrinsic(_extentLocalCache, java_lang_Thread, extentLocalCache_name, extentLocalCache_signature, F_SN) \
do_name( extentLocalCache_name, "extentLocalCache") \
do_signature(extentLocalCache_signature, "()[Ljava/lang/Object;") \
do_intrinsic(_setExtentLocalCache, java_lang_Thread, setExtentLocalCache_name, setExtentLocalCache_signature, F_SN) \
do_name( setExtentLocalCache_name, "setExtentLocalCache") \
do_signature(setExtentLocalCache_signature, "([Ljava/lang/Object;)V") \
do_intrinsic(_scopedValueCache, java_lang_Thread, scopedValueCache_name, scopedValueCache_signature, F_SN) \
do_name( scopedValueCache_name, "scopedValueCache") \
do_signature(scopedValueCache_signature, "()[Ljava/lang/Object;") \
do_intrinsic(_setScopedValueCache, java_lang_Thread, setScopedValueCache_name, setScopedValueCache_signature, F_SN) \
do_name( setScopedValueCache_name, "setScopedValueCache") \
do_signature(setScopedValueCache_signature, "([Ljava/lang/Object;)V") \
do_intrinsic(_findScopedValueBindings, java_lang_Thread, findScopedValueBindings_name, void_object_signature, F_SN) \
do_name( findScopedValueBindings_name, "findScopedValueBindings") \
\
do_intrinsic(_setCurrentThread, java_lang_Thread, setCurrentThread_name, thread_void_signature, F_RN) \
do_name( setCurrentThread_name, "setCurrentThread") \
\
Expand Down Expand Up @@ -331,6 +334,9 @@ class methodHandle;
do_name( onSpinWait_name, "onSpinWait") \
do_alias( onSpinWait_signature, void_method_signature) \
\
do_intrinsic(_ensureMaterializedForStackWalk, java_lang_Thread, ensureMaterializedForStackWalk_name, object_void_signature, F_SN) \
do_name( ensureMaterializedForStackWalk_name, "ensureMaterializedForStackWalk") \
\
do_intrinsic(_copyOf, java_util_Arrays, copyOf_name, copyOf_signature, F_S) \
do_name( copyOf_name, "copyOf") \
do_signature(copyOf_signature, "([Ljava/lang/Object;ILjava/lang/Class;)[Ljava/lang/Object;") \
Expand Down
4 changes: 4 additions & 0 deletions src/hotspot/share/classfile/vmSymbols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
template(jdk_internal_loader_BuiltinClassLoader, "jdk/internal/loader/BuiltinClassLoader") \
template(jdk_internal_loader_ClassLoaders_AppClassLoader, "jdk/internal/loader/ClassLoaders$AppClassLoader") \
template(jdk_internal_loader_ClassLoaders_PlatformClassLoader, "jdk/internal/loader/ClassLoaders$PlatformClassLoader") \
template(jdk_incubator_concurrent_ScopedValue, "jdk/incubator/concurrent/ScopedValue") \
template(jdk_incubator_concurrent_ScopedValue_Carrier, "jdk/incubator/concurrent/ScopedValue$Carrier") \
\
/* Java runtime version access */ \
template(java_lang_VersionProps, "java/lang/VersionProps") \
Expand Down Expand Up @@ -396,6 +398,7 @@
template(group_name, "group") \
template(daemon_name, "daemon") \
template(run_method_name, "run") \
template(runWith_method_name, "runWith") \
template(interrupt_method_name, "interrupt") \
template(exit_method_name, "exit") \
template(remove_method_name, "remove") \
Expand Down Expand Up @@ -601,6 +604,7 @@
template(string_array_string_array_void_signature, "([Ljava/lang/String;[Ljava/lang/String;)V") \
template(thread_throwable_void_signature, "(Ljava/lang/Thread;Ljava/lang/Throwable;)V") \
template(thread_void_signature, "(Ljava/lang/Thread;)V") \
template(runnable_void_signature, "(Ljava/lang/Runnable;)V") \
template(threadgroup_runnable_void_signature, "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;)V") \
template(threadgroup_string_void_signature, "(Ljava/lang/ThreadGroup;Ljava/lang/String;)V") \
template(void_threadgroup_array_signature, "()[Ljava/lang/ThreadGroup;") \
Expand Down
9 changes: 7 additions & 2 deletions src/hotspot/share/include/jvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,13 @@ JNIEXPORT jobjectArray JNICALL
JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads);

JNIEXPORT jobject JNICALL
JVM_ExtentLocalCache(JNIEnv *env, jclass threadClass);
JVM_ScopedValueCache(JNIEnv *env, jclass threadClass);

JNIEXPORT void JNICALL
JVM_SetExtentLocalCache(JNIEnv *env, jclass threadClass, jobject theCache);
JVM_SetScopedValueCache(JNIEnv *env, jclass threadClass, jobject theCache);

JNIEXPORT jobject JNICALL
JVM_FindScopedValueBindings(JNIEnv *env, jclass threadClass);

JNIEXPORT jlong JNICALL
JVM_GetNextThreadIdOffset(JNIEnv *env, jclass threadClass);
Expand Down Expand Up @@ -742,6 +745,8 @@ JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls);
#define JVM_EnsureMaterializedForStackWalk(env, value) \
do {} while(0) // Nothing to do. The fact that the value escaped
// through a native method is enough.
JNIEXPORT void JNICALL
JVM_EnsureMaterializedForStackWalk_func(JNIEnv* env, jobject vthread, jobject value);

JNIEXPORT jobject JNICALL
JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls);
Expand Down
6 changes: 6 additions & 0 deletions src/hotspot/share/interpreter/interpreterRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ JRT_ENTRY(void, InterpreterRuntime::throw_StackOverflowError(JavaThread* current
CHECK);
// Increment counter for hs_err file reporting
Atomic::inc(&Exceptions::_stack_overflow_errors);
// Remove the ScopedValue bindings in case we got a StackOverflowError
// while we were trying to manipulate ScopedValue bindings.
current->clear_scopedValueBindings();
THROW_HANDLE(exception);
JRT_END

Expand All @@ -383,6 +386,9 @@ JRT_ENTRY(void, InterpreterRuntime::throw_delayed_StackOverflowError(JavaThread*
Universe::delayed_stack_overflow_error_message());
// Increment counter for hs_err file reporting
Atomic::inc(&Exceptions::_stack_overflow_errors);
// Remove the ScopedValue bindings in case we got a StackOverflowError
// while we were trying to manipulate ScopedValue bindings.
current->clear_scopedValueBindings();
THROW_HANDLE(exception);
JRT_END

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,12 +1609,12 @@ C2V_VMENTRY(void, materializeVirtualObjects, (JNIEnv* env, jobject, jobject _hs_
for (int frame_index = 0; frame_index < virtualFrames->length(); frame_index++) {
compiledVFrame* cvf = virtualFrames->at(frame_index);

GrowableArray<ScopeValue*>* extentLocals = cvf->scope()->locals();
GrowableArray<ScopeValue*>* scopedValues = cvf->scope()->locals();
StackValueCollection* locals = cvf->locals();
if (locals != NULL) {
for (int i2 = 0; i2 < locals->size(); i2++) {
StackValue* var = locals->at(i2);
if (var->type() == T_OBJECT && extentLocals->at(i2)->is_object()) {
if (var->type() == T_OBJECT && scopedValues->at(i2)->is_object()) {
jvalue val;
val.l = cast_from_oop<jobject>(locals->at(i2)->get_obj()());
cvf->update_local(T_OBJECT, i2, val);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
\
nonstatic_field(JavaThread, _threadObj, OopHandle) \
nonstatic_field(JavaThread, _vthread, OopHandle) \
nonstatic_field(JavaThread, _extentLocalCache, OopHandle) \
nonstatic_field(JavaThread, _scopedValueCache, OopHandle) \
nonstatic_field(JavaThread, _anchor, JavaFrameAnchor) \
nonstatic_field(JavaThread, _vm_result, oop) \
nonstatic_field(JavaThread, _stack_overflow_state._stack_overflow_limit, address) \
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/oops/oopHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class OopHandle {

inline oop xchg(oop new_value);

// Used only for removing handle.
oop* ptr_raw() const { return _obj; }
};

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/opto/c2compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,8 @@ bool C2Compiler::is_intrinsic_supported(const methodHandle& method, bool is_virt
case vmIntrinsics::_currentCarrierThread:
case vmIntrinsics::_currentThread:
case vmIntrinsics::_setCurrentThread:
case vmIntrinsics::_extentLocalCache:
case vmIntrinsics::_setExtentLocalCache:
case vmIntrinsics::_scopedValueCache:
case vmIntrinsics::_setScopedValueCache:
#ifdef JFR_HAVE_INTRINSICS
case vmIntrinsics::_counterTime:
case vmIntrinsics::_getEventWriter:
Expand Down

1 comment on commit 221e1a4

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.