From 2586f36120317cd206464b1e79d3906f711487cb Mon Sep 17 00:00:00 2001 From: Alan Bateman Date: Tue, 11 Apr 2023 05:49:54 +0000 Subject: [PATCH] 8304919: Implementation of Virtual Threads Reviewed-by: lmesnik, cjplummer, psandoz, mchung, sspitsyn, jpai --- src/hotspot/share/classfile/javaClasses.cpp | 9 +- src/hotspot/share/classfile/javaClasses.hpp | 1 - src/hotspot/share/prims/jni.cpp | 2 +- src/hotspot/share/prims/jvmti.xml | 32 +- src/hotspot/share/prims/jvmtiEnv.cpp | 7 - src/hotspot/share/prims/jvmtiH.xsl | 3 +- src/hotspot/share/prims/jvmtiTagMap.cpp | 1 - src/hotspot/share/prims/stackwalk.cpp | 10 +- src/hotspot/share/runtime/threads.cpp | 1 + .../share/classes/java/lang/System.java | 13 +- .../share/classes/java/lang/Thread.java | 294 +++++++----------- .../classes/java/lang/ThreadBuilders.java | 92 ++++-- .../share/classes/java/lang/ThreadLocal.java | 82 +++-- .../classes/java/lang/VirtualThread.java | 165 ++++++---- .../java/util/concurrent/Executors.java | 8 +- .../concurrent/ThreadPerTaskExecutor.java | 31 +- .../jdk/internal/javac/PreviewFeature.java | 4 +- .../classes/jdk/internal/vm/Continuation.java | 11 +- src/java.base/share/classes/module-info.java | 7 +- src/java.base/share/native/include/jni.h | 3 +- .../share/classes/module-info.java | 5 +- src/java.se/share/data/jdwp/jdwp.spec | 12 +- .../concurrent/StructuredTaskScope.java | 6 +- .../share/classes/module-info.java | 5 +- .../classes/com/sun/jdi/ThreadReference.java | 6 +- .../sun/jdi/request/ThreadDeathRequest.java | 6 +- .../sun/jdi/request/ThreadStartRequest.java | 6 +- .../tools/example/debug/tty/TTYResources.java | 3 +- .../sun/tools/jdi/resources/jdi.properties | 4 +- src/jdk.jdi/share/man/jdb.1 | 7 +- .../share/native/libjdwp/debugInit.c | 3 +- .../jdk/jfr/consumer/RecordedThread.java | 6 +- .../management/HotSpotDiagnosticMXBean.java | 9 +- .../compiler/codecache/stress/Helper.java | 23 +- .../stress/OverloadCompileQueueTest.java | 6 + .../UnexpectedDeoptimizationAllTest.java | 6 +- .../stress/UnexpectedDeoptimizationTest.java | 6 +- .../jtreg/native_sanity/JniVersion.java | 6 +- .../Monitor/SyncOnValueBasedClassTest.java | 15 +- .../RedefineRunningMethods_Shared.java | 8 +- .../jni/IsVirtualThread/IsVirtualThread.java | 2 - ...estPrimitiveArrayCriticalWithBadParam.java | 3 +- .../vthread/JNIMonitor/JNIMonitor.java | 6 +- .../jtreg/runtime/vthread/RedefineClass.java | 6 +- .../TestObjectAllocationSampleEvent.java | 6 +- .../GetSetLocalUnsuspended.java | 3 +- .../GetOwnedMonitorInfoTest.java | 6 +- .../GetOwnedMonitorStackDepthInfoTest.java | 6 +- .../MyPackage/HeapMonitorVMEventsTest.java | 7 +- .../RedefineRunningMethods.java | 5 +- .../RedefineRunningMethodsWithBacktrace.java | 8 +- .../Breakpoint/breakpoint01/breakpoint01.java | 6 +- .../ClassLoad/classload01/classload01.java | 6 +- .../ClassPrepare/classprep01/classprep01.java | 6 +- .../Exception/exception01/exception01.java | 6 +- .../ExceptionCatch/excatch01/excatch01.java | 6 +- .../FieldAccess/fieldacc01/fieldacc01.java | 6 +- .../FieldAccess/fieldacc02/fieldacc02.java | 6 +- .../FieldAccess/fieldacc03/fieldacc03.java | 6 +- .../FieldAccess/fieldacc04/fieldacc04.java | 6 +- .../fieldmod01/fieldmod01.java | 6 +- .../fieldmod02/fieldmod02.java | 6 +- .../FramePop/framepop01/framepop01.java | 6 +- .../FramePop/framepop02/framepop02.java | 10 +- .../events/MethodEntry/mentry01/mentry01.java | 6 +- .../events/MethodEntry/mentry02/mentry02.java | 6 +- .../events/MethodExit/mexit01/mexit01.java | 6 +- .../events/MethodExit/mexit02/mexit02.java | 6 +- .../mcontenter01/mcontenter01.java | 8 +- .../mcontentered01/mcontentered01.java | 8 +- .../monitorwait01/monitorwait01.java | 8 +- .../monitorwaited01/monitorwaited01.java | 8 +- .../SingleStep/singlestep01/singlestep01.java | 6 +- .../SingleStep/singlestep03/singlestep03.java | 8 +- .../GetStackTraceNotSuspendedStressTest.java | 6 +- .../GetStackTraceSuspendedStressTest.java | 6 +- .../SetGetThreadLocalStorageStressTest.java | 6 +- .../GetAllThreads/allthr01/allthr01.java | 4 +- .../contmon01/contmon01.java | 6 +- .../contmon02/contmon02.java | 6 +- .../GetFrameCount/framecnt01/framecnt01.java | 8 +- .../GetStackTraceCurrentThreadTest.java | 6 +- .../getstacktr03/getstacktr03.java | 6 +- .../getstacktr03/libgetstacktr03.cpp | 3 +- .../getstacktr04/getstacktr04.java | 6 +- .../getstacktr05/getstacktr05.java | 6 +- .../getstacktr05/libgetstacktr05.cpp | 5 +- .../getstacktr06/getstacktr06.java | 6 +- .../getstacktr07/getstacktr07.java | 6 +- .../getstacktr08/getstacktr08.java | 6 +- .../GetThreadInfo/thrinfo01/thrinfo01.java | 6 +- .../GetThreadState/thrstat01/thrstat01.java | 6 +- .../GetThreadState/thrstat03/thrstat03.java | 6 +- .../GetThreadState/thrstat05/thrstat05.java | 6 +- .../BoundVThreadTest/BoundVThreadTest.java | 1 - .../BreakpointInYieldTest.java | 6 +- .../ContFramePopTest/ContFramePopTest.java | 4 +- .../ContStackDepthTest.java | 4 +- .../ContYieldBreakPointTest.java | 4 +- .../ContinuationTest/ContinuationTest.java | 4 +- .../GetSetLocalTest/GetSetLocalTest.java | 6 +- .../InterruptThreadTest.java | 10 +- .../MethodExitTest/MethodExitTest.java | 6 +- .../NullAsCurrentThreadTest.java | 10 +- .../PinnedTaskTest/PinnedTaskTest.java | 10 +- .../RawMonitorTest/RawMonitorTest.java | 6 +- .../RedefineRunningMethods.java | 4 +- .../SelfSuspendDisablerTest.java | 10 +- .../SuspendResume1/SuspendResume1.java | 8 +- .../SuspendResume2/SuspendResume2.java | 8 +- .../SuspendResumeAll/SuspendResumeAll.java | 8 +- .../VThreadMonitorTest.java | 6 +- .../VThreadNotifyFramePopTest.java | 4 +- .../vthread/VThreadTest/VThreadTest.java | 6 +- .../VThreadUnsupportedTest.java | 6 +- .../VirtualStackTraceTest.java | 4 +- .../VirtualThreadStartTest.java | 4 +- .../WaitNotifySuspendedVThreadTest.java | 5 +- .../vthread/premain/AgentWithVThreadTest.java | 6 +- .../jvmti/RedefineClasses/StressRedefine.java | 13 +- .../StressRedefineVirtual.java | 3 +- .../vmTestbase/nsk/share/MainWrapper.java | 13 +- .../vmTestbase/nsk/share/jdb/Launcher.java | 4 +- .../vmTestbase/nsk/share/jdi/Binder.java | 4 +- .../nsk/share/jdi/JDIThreadFactory.java | 13 +- .../nsk/share/jpda/DebugeeBinder.java | 8 +- .../nsk/share/runner/ThreadsRunner.java | 13 +- test/jdk/TEST.groups | 3 +- test/jdk/com/sun/jdi/SuspendAfterDeath.java | 4 +- test/jdk/com/sun/jdi/TestScaffold.java | 19 +- .../HotSpotDiagnosticMXBean/DumpThreads.java | 1 - .../ThreadMXBean/VirtualThreads.java | 20 +- test/jdk/java/lang/Thread/BuilderTest.java | 111 ------- .../java/lang/Thread/ThreadSleepEvent.java | 195 ++++++++++++ .../lang/Thread/ThreadSleepEventThrows.java | 96 ++++++ .../jdk/internal/event/ThreadSleepEvent.java | 71 +++++ ...Carrier.java => ActivateSpareCarrier.java} | 7 +- .../java/lang/Thread/virtual/Collectable.java | 1 - .../lang/Thread/virtual/CustomScheduler.java | 1 - .../lang/Thread/virtual/GetStackTrace.java | 5 +- .../virtual/GetStackTraceWhenRunnable.java | 3 +- .../java/lang/Thread/virtual/HoldsLock.java | 5 +- .../java/lang/Thread/virtual/JfrEvents.java | 1 - .../jdk/java/lang/Thread/virtual/Locking.java | 1 - .../virtual/ParkWithFixedThreadPool.java | 1 - .../jdk/java/lang/Thread/virtual/Parking.java | 1 - .../virtual/PreviewFeaturesNotEnabled.java | 112 ------- .../java/lang/Thread/virtual/Reflection.java | 1 - .../lang/Thread/virtual/ShutdownHook.java | 5 +- .../java/lang/Thread/virtual/StackTraces.java | 1 - .../java/lang/Thread/virtual/ThreadAPI.java | 28 +- .../lang/Thread/virtual/ThreadLocals.java | 43 --- .../Thread/virtual/TracePinnedThreads.java | 3 +- .../virtual/TraceVirtualThreadLocals.java | 88 ++++++ .../VirtualThreadPinnedEventThrows.java | 110 +++++++ .../java/lang/Thread/virtual/WaitNotify.java | 1 - .../lang/Thread/virtual/YieldQueuing.java | 3 +- .../event/VirtualThreadPinnedEvent.java} | 58 ++-- .../virtual/stress/GetStackTraceALot.java | 4 +- .../lang/Thread/virtual/stress/PinALot.java | 4 +- .../lang/Thread/virtual/stress/PingPong.java | 4 +- .../lang/Thread/virtual/stress/Skynet.java | 4 +- .../lang/Thread/virtual/stress/SleepALot.java | 4 +- .../lang/Thread/virtual/stress/TimedGet.java | 3 +- .../lang/Thread/virtual/stress/YieldALot.java | 4 +- .../ParallelTransformerLoaderTest.java | 8 +- .../ThreadMXBean/VirtualThreadDeadlocks.java | 4 +- .../ThreadMXBean/VirtualThreads.java | 24 +- test/jdk/java/lang/ref/CleanerTest.java | 5 +- test/jdk/java/net/Socket/Timeouts.java | 3 +- .../java/net/vthread/BlockingSocketOps.java | 3 - test/jdk/java/net/vthread/HttpALot.java | 1 - test/jdk/java/net/vthread/InterruptHttp.java | 3 +- .../AdaptorAsyncCloseAfterReceive.java | 1 - .../channels/vthread/BlockingChannelOps.java | 3 - .../concurrent/ExecutorService/CloseTest.java | 3 +- .../ThreadPerTaskExecutorTest.java | 2 - .../concurrent/ScopedValue/ManyBindings.java | 1 - .../concurrent/ScopedValue/ScopeValueAPI.java | 1 - .../ScopedValue/StressStackOverflow.java | 8 +- .../StructuredTaskScopeTest.java | 2 - .../StructuredThreadDumpTest.java | 1 - .../StructuredTaskScope/WithScopedValue.java | 1 - .../TestTerminatingThreadLocal.java | 4 +- .../misc/ThreadFlock/ThreadFlockTest.java | 2 - .../misc/ThreadFlock/WithScopedValue.java | 1 - .../jdk/internal/vm/Continuation/Basic.java | 28 +- .../internal/vm/Continuation/BasicExt.java | 30 +- .../vm/Continuation/ClassUnloading.java | 3 +- .../jdk/internal/vm/Continuation/Fuzz.java | 4 +- .../vm/Continuation/HumongousStack.java | 3 +- .../vm/Continuation/LiveFramesDriver.java | 3 +- .../vm/Continuation/MovingCompWindow.java | 3 +- .../jdk/internal/vm/Continuation/Scoped.java | 29 +- .../jfr/event/runtime/TestThreadEndEvent.java | 3 +- .../event/runtime/TestThreadSleepEvent.java | 3 +- .../event/runtime/TestThreadStartEvent.java | 3 +- .../runtime/TestVirtualThreadEndEvent.java | 3 +- .../runtime/TestVirtualThreadStartEvent.java | 3 +- test/jdk/jdk/jfr/jvm/TestThreadExclusion.java | 3 +- .../jfr/jvm/TestVirtualThreadExclusion.java | 3 +- .../threading/TestDeepVirtualStackTrace.java | 3 +- .../jfr/threading/TestManyVirtualThreads.java | 3 +- .../threading/TestNestedVirtualThreads.java | 3 +- .../jdk/test/lib/thread/VThreadRunner.java | 10 +- 205 files changed, 1379 insertions(+), 1342 deletions(-) create mode 100644 test/jdk/java/lang/Thread/ThreadSleepEvent.java create mode 100644 test/jdk/java/lang/Thread/ThreadSleepEventThrows.java create mode 100644 test/jdk/java/lang/Thread/java.base/jdk/internal/event/ThreadSleepEvent.java rename test/jdk/java/lang/Thread/virtual/{ActiviateSpareCarrier.java => ActivateSpareCarrier.java} (96%) delete mode 100644 test/jdk/java/lang/Thread/virtual/PreviewFeaturesNotEnabled.java create mode 100644 test/jdk/java/lang/Thread/virtual/TraceVirtualThreadLocals.java create mode 100644 test/jdk/java/lang/Thread/virtual/VirtualThreadPinnedEventThrows.java rename test/jdk/{jdk/incubator/concurrent/StructuredTaskScope/PreviewFeaturesNotEnabled.java => java/lang/Thread/virtual/java.base/jdk/internal/event/VirtualThreadPinnedEvent.java} (50%) diff --git a/src/hotspot/share/classfile/javaClasses.cpp b/src/hotspot/share/classfile/javaClasses.cpp index 8fe8f56e05e..dddfa3435ec 100644 --- a/src/hotspot/share/classfile/javaClasses.cpp +++ b/src/hotspot/share/classfile/javaClasses.cpp @@ -1498,11 +1498,9 @@ JavaThreadStatus java_lang_Thread_FieldHolder::get_thread_status(oop holder) { int java_lang_Thread_Constants::_static_VTHREAD_GROUP_offset = 0; -int java_lang_Thread_Constants::_static_NOT_SUPPORTED_CLASSLOADER_offset = 0; #define THREAD_CONSTANTS_STATIC_FIELDS_DO(macro) \ - macro(_static_VTHREAD_GROUP_offset, k, "VTHREAD_GROUP", threadgroup_signature, true); \ - macro(_static_NOT_SUPPORTED_CLASSLOADER_offset, k, "NOT_SUPPORTED_CLASSLOADER", classloader_signature, true); + macro(_static_VTHREAD_GROUP_offset, k, "VTHREAD_GROUP", threadgroup_signature, true); void java_lang_Thread_Constants::compute_offsets() { assert(_static_VTHREAD_GROUP_offset == 0, "offsets should be initialized only once"); @@ -1523,11 +1521,6 @@ oop java_lang_Thread_Constants::get_VTHREAD_GROUP() { return base->obj_field(_static_VTHREAD_GROUP_offset); } -oop java_lang_Thread_Constants::get_NOT_SUPPORTED_CLASSLOADER() { - InstanceKlass* k = vmClasses::Thread_Constants_klass(); - oop base = k->static_field_base_raw(); - return base->obj_field(_static_NOT_SUPPORTED_CLASSLOADER_offset); -} int java_lang_Thread::_holder_offset; int java_lang_Thread::_name_offset; diff --git a/src/hotspot/share/classfile/javaClasses.hpp b/src/hotspot/share/classfile/javaClasses.hpp index dd7b2b67c60..484d9ebfee1 100644 --- a/src/hotspot/share/classfile/javaClasses.hpp +++ b/src/hotspot/share/classfile/javaClasses.hpp @@ -475,7 +475,6 @@ class java_lang_Thread_Constants : AllStatic { public: static oop get_VTHREAD_GROUP(); - static oop get_NOT_SUPPORTED_CLASSLOADER(); friend class JavaClasses; }; diff --git a/src/hotspot/share/prims/jni.cpp b/src/hotspot/share/prims/jni.cpp index fcb6024bac2..9588ae995f8 100644 --- a/src/hotspot/share/prims/jni.cpp +++ b/src/hotspot/share/prims/jni.cpp @@ -102,7 +102,7 @@ #include "jfr/jfr.hpp" #endif -static jint CurrentVersion = JNI_VERSION_20; +static jint CurrentVersion = JNI_VERSION_21; #if defined(_WIN32) && !defined(USE_VECTORED_EXCEPTION_HANDLING) extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* ); diff --git a/src/hotspot/share/prims/jvmti.xml b/src/hotspot/share/prims/jvmti.xml index b0c045f9322..456876fbcb9 100644 --- a/src/hotspot/share/prims/jvmti.xml +++ b/src/hotspot/share/prims/jvmti.xml @@ -1,7 +1,7 @@