Skip to content

Commit 9583e36

Browse files
Alan BatemanpronfiskAndrew HaleyRickard Bäckman
committed
8284161: Implementation of Virtual Threads (Preview)
Co-authored-by: Ron Pressler <[email protected]> Co-authored-by: Alan Bateman <[email protected]> Co-authored-by: Erik Österlund <[email protected]> Co-authored-by: Andrew Haley <[email protected]> Co-authored-by: Rickard Bäckman <[email protected]> Co-authored-by: Markus Grönlund <[email protected]> Co-authored-by: Leonid Mesnik <[email protected]> Co-authored-by: Serguei Spitsyn <[email protected]> Co-authored-by: Chris Plummer <[email protected]> Co-authored-by: Coleen Phillimore <[email protected]> Co-authored-by: Robbin Ehn <[email protected]> Co-authored-by: Stefan Karlsson <[email protected]> Co-authored-by: Thomas Schatzl <[email protected]> Co-authored-by: Sergey Kuksenko <[email protected]> Reviewed-by: lancea, eosterlund, rehn, sspitsyn, stefank, tschatzl, dfuchs, lmesnik, dcubed, kevinw, amenkov, dlong, mchung, psandoz, bpb, coleenp, smarks, egahlin, mseledtsov, coffeys, darcy
1 parent 5212535 commit 9583e36

File tree

1,133 files changed

+95870
-8270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,133 files changed

+95870
-8270
lines changed

make/data/hotspot-symbols/symbols-unix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ JVM_ConstantPoolGetSize
4646
JVM_ConstantPoolGetStringAt
4747
JVM_ConstantPoolGetTagAt
4848
JVM_ConstantPoolGetUTF8At
49+
JVM_CurrentCarrierThread
4950
JVM_CurrentThread
51+
JVM_SetCurrentThread
5052
JVM_CurrentTimeMillis
5153
JVM_DefineClass
5254
JVM_DefineClassWithSource
@@ -120,6 +122,7 @@ JVM_GetMethodTypeAnnotations
120122
JVM_GetNanoTimeAdjustment
121123
JVM_GetNestHost
122124
JVM_GetNestMembers
125+
JVM_GetNextThreadIdOffset
123126
JVM_GetPermittedSubclasses
124127
JVM_GetPrimitiveArrayElement
125128
JVM_GetProperties
@@ -135,6 +138,7 @@ JVM_GetVmArguments
135138
JVM_Halt
136139
JVM_HasReferencePendingList
137140
JVM_HoldsLock
141+
JVM_GetStackTrace
138142
JVM_IHashCode
139143
JVM_InitClassName
140144
JVM_InitStackTraceElement
@@ -150,6 +154,7 @@ JVM_IsDumpingClassList
150154
JVM_IsFinalizationEnabled
151155
JVM_IsHiddenClass
152156
JVM_IsInterface
157+
JVM_IsPreviewEnabled
153158
JVM_IsPrimitiveClass
154159
JVM_IsRecord
155160
JVM_IsSameClassPackage
@@ -182,15 +187,19 @@ JVM_RawMonitorEnter
182187
JVM_RawMonitorExit
183188
JVM_ReferenceClear
184189
JVM_ReferenceRefersTo
190+
JVM_RegisterContinuationMethods
185191
JVM_RegisterLambdaProxyClassForArchiving
186192
JVM_RegisterSignal
187193
JVM_ReleaseUTF
188194
JVM_ReportFinalizationComplete
189195
JVM_ResumeThread
196+
JVM_ExtentLocalCache
197+
JVM_SetExtentLocalCache
190198
JVM_SetArrayElement
191199
JVM_SetClassSigners
192200
JVM_SetNativeThreadName
193201
JVM_SetPrimitiveArrayElement
202+
JVM_SetStackWalkContinuation
194203
JVM_SetThreadPriority
195204
JVM_Sleep
196205
JVM_StartThread
@@ -210,3 +219,10 @@ JVM_AddReadsModule
210219
JVM_DefineArchivedModules
211220
JVM_DefineModule
212221
JVM_SetBootLoaderUnnamedModule
222+
223+
# Virtual thread notifications for JVMTI
224+
JVM_VirtualThreadMountBegin
225+
JVM_VirtualThreadMountEnd
226+
JVM_VirtualThreadUnmountBegin
227+
JVM_VirtualThreadUnmountEnd
228+
#

make/test/BuildMicrobenchmark.gmk

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ $(eval $(call SetupJavaCompilation, BUILD_JDK_MICROBENCHMARK, \
9595
SRC := $(MICROBENCHMARK_SRC), \
9696
BIN := $(MICROBENCHMARK_CLASSES), \
9797
JAVAC_FLAGS := --add-exports java.base/sun.security.util=ALL-UNNAMED \
98-
--add-exports java.base/sun.invoke.util=ALL-UNNAMED, \
99-
JAVA_FLAGS := --add-modules jdk.unsupported --limit-modules java.management, \
98+
--add-exports java.base/sun.invoke.util=ALL-UNNAMED \
99+
--add-exports java.base/jdk.internal.vm=ALL-UNNAMED \
100+
--enable-preview, \
101+
JAVA_FLAGS := --add-modules jdk.unsupported --limit-modules java.management \
102+
--add-exports java.base/jdk.internal.vm=ALL-UNNAMED \
103+
--enable-preview, \
100104
))
101105

102106
$(BUILD_JDK_MICROBENCHMARK): $(JMH_COMPILE_JARS)

make/test/JtregNativeHotspot.gmk

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -148,8 +148,10 @@ BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libNoFramePointer := $(NO_FRAMEPOINTER_CFLA
148148
# Optimization -O3 needed, HIGH == -O3
149149
BUILD_HOTSPOT_JTREG_LIBRARIES_OPTIMIZATION_libNoFramePointer := HIGH
150150

151-
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS := -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
152-
BUILD_HOTSPOT_JTREG_EXECUTABLES_CFLAGS := -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
151+
JVMTI_COMMON_INCLUDES=-I$(TOPDIR)/test/lib/jdk/test/lib/jvmti
152+
153+
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS := -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS $(JVMTI_COMMON_INCLUDES)
154+
BUILD_HOTSPOT_JTREG_EXECUTABLES_CFLAGS := -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS $(JVMTI_COMMON_INCLUDES)
153155

154156
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libProcessUtils := $(VM_SHARE_INCLUDES)
155157

@@ -346,6 +348,7 @@ BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libvminit001 := $(NSK_JVMTI_AGENT_INCLUDES)
346348
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libsuspendthrd001 := $(NSK_JVMTI_AGENT_INCLUDES)
347349
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libsuspendthrd002 := $(NSK_JVMTI_AGENT_INCLUDES)
348350
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libsuspendthrd003 := $(NSK_JVMTI_AGENT_INCLUDES)
351+
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libsuspendvthr001 := $(NSK_JVMTI_AGENT_INCLUDES)
349352
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libdeclcls002 := $(NSK_JVMTI_AGENT_INCLUDES)
350353
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libdeclcls003 := $(NSK_JVMTI_AGENT_INCLUDES)
351354
BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libdeclcls001 := $(NSK_JVMTI_AGENT_INCLUDES)
@@ -1012,6 +1015,7 @@ else
10121015
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libsuspendthrd001 += -lpthread
10131016
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libsuspendthrd002 += -lpthread
10141017
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libsuspendthrd003 += -lpthread
1018+
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libsuspendvthr001 += -lpthread
10151019
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libdeclcls002 += -lpthread
10161020
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libdeclcls003 += -lpthread
10171021
BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libdeclcls001 += -lpthread

src/hotspot/cpu/aarch64/aarch64.ad

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3829,6 +3829,8 @@ encode %{
38293829
}
38303830
}
38313831

3832+
__ post_call_nop();
3833+
38323834
// Only non uncommon_trap calls need to reinitialize ptrue.
38333835
if (Compile::current()->max_vector_size() > 0 && uncommon_trap_request() == 0) {
38343836
__ reinitialize_ptrue();
@@ -3842,7 +3844,9 @@ encode %{
38423844
if (call == NULL) {
38433845
ciEnv::current()->record_failure("CodeCache is full");
38443846
return;
3845-
} else if (Compile::current()->max_vector_size() > 0) {
3847+
}
3848+
__ post_call_nop();
3849+
if (Compile::current()->max_vector_size() > 0) {
38463850
__ reinitialize_ptrue();
38473851
}
38483852
%}
@@ -3870,6 +3874,7 @@ encode %{
38703874
ciEnv::current()->record_failure("CodeCache is full");
38713875
return;
38723876
}
3877+
__ post_call_nop();
38733878
} else {
38743879
Label retaddr;
38753880
__ adr(rscratch2, retaddr);
@@ -3878,6 +3883,7 @@ encode %{
38783883
__ stp(zr, rscratch2, Address(__ pre(sp, -2 * wordSize)));
38793884
__ blr(rscratch1);
38803885
__ bind(retaddr);
3886+
__ post_call_nop();
38813887
__ add(sp, sp, 2 * wordSize);
38823888
}
38833889
if (Compile::current()->max_vector_size() > 0) {

src/hotspot/cpu/aarch64/abstractInterpreter_aarch64.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ void AbstractInterpreter::layout_activation(Method* method,
123123
// It is also guaranteed to be walkable even though it is in a
124124
// skeletal state
125125

126-
int max_locals = method->max_locals() * Interpreter::stackElementWords;
127-
int extra_locals = (method->max_locals() - method->size_of_parameters()) *
128-
Interpreter::stackElementWords;
126+
const int max_locals = method->max_locals() * Interpreter::stackElementWords;
127+
const int params = method->size_of_parameters() * Interpreter::stackElementWords;
128+
const int extra_locals = max_locals - params;
129129

130130
#ifdef ASSERT
131131
assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable");
@@ -144,12 +144,9 @@ void AbstractInterpreter::layout_activation(Method* method,
144144
// align the incoming parameters with the caller's temporary
145145
// expression stack. For other types of caller frame it doesn't
146146
// matter.
147-
intptr_t* locals;
148-
if (caller->is_interpreted_frame()) {
149-
locals = caller->interpreter_frame_last_sp() + caller_actual_parameters - 1;
150-
} else {
151-
locals = interpreter_frame->sender_sp() + max_locals - 1;
152-
}
147+
intptr_t* const locals = caller->is_interpreted_frame()
148+
? caller->interpreter_frame_last_sp() + caller_actual_parameters - 1
149+
: interpreter_frame->sender_sp() + max_locals - 1;
153150

154151
#ifdef ASSERT
155152
if (caller->is_interpreted_frame()) {
@@ -171,14 +168,10 @@ void AbstractInterpreter::layout_activation(Method* method,
171168
// All frames but the initial (oldest) interpreter frame we fill in have
172169
// a value for sender_sp that allows walking the stack but isn't
173170
// truly correct. Correct the value here.
174-
if (extra_locals != 0 &&
175-
interpreter_frame->sender_sp() ==
176-
interpreter_frame->interpreter_frame_sender_sp()) {
177-
interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() +
178-
extra_locals);
171+
if (extra_locals != 0 && interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp()) {
172+
interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
179173
}
180-
*interpreter_frame->interpreter_frame_cache_addr() =
181-
method->constants()->cache();
182-
*interpreter_frame->interpreter_frame_mirror_addr() =
183-
method->method_holder()->java_mirror();
174+
175+
*interpreter_frame->interpreter_frame_cache_addr() = method->constants()->cache();
176+
*interpreter_frame->interpreter_frame_mirror_addr() = method->method_holder()->java_mirror();
184177
}

src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,7 @@ int LIR_Assembler::emit_unwind_handler() {
438438
__ unlock_object(r5, r4, r0, *stub->entry());
439439
}
440440
__ bind(*stub->continuation());
441+
__ dec_held_monitor_count(rthread);
441442
}
442443

443444
if (compilation()->env()->dtrace_method_probes()) {
@@ -2037,6 +2038,7 @@ void LIR_Assembler::call(LIR_OpJavaCall* op, relocInfo::relocType rtype) {
20372038
return;
20382039
}
20392040
add_call_info(code_offset(), op->info());
2041+
__ post_call_nop();
20402042
}
20412043

20422044

@@ -2047,6 +2049,7 @@ void LIR_Assembler::ic_call(LIR_OpJavaCall* op) {
20472049
return;
20482050
}
20492051
add_call_info(code_offset(), op->info());
2052+
__ post_call_nop();
20502053
}
20512054

20522055
void LIR_Assembler::emit_static_call_stub() {
@@ -2571,7 +2574,18 @@ void LIR_Assembler::emit_lock(LIR_OpLock* op) {
25712574
} else {
25722575
Unimplemented();
25732576
}
2577+
if (op->code() == lir_lock) {
2578+
// If deoptimization happens in Runtime1::monitorenter, inc_held_monitor_count after backing from slowpath
2579+
// will be skipped. Solution is:
2580+
// 1. Increase only in fastpath
2581+
// 2. Runtime1::monitorenter increase count after locking
2582+
__ inc_held_monitor_count(rthread);
2583+
}
25742584
__ bind(*op->stub()->continuation());
2585+
if (op->code() == lir_unlock) {
2586+
// unlock in slowpath is JRT_Leaf stub, no deoptimization can happen
2587+
__ dec_held_monitor_count(rthread);
2588+
}
25752589
}
25762590

25772591
void LIR_Assembler::emit_load_klass(LIR_OpLoadKlass* op) {
@@ -2899,6 +2913,7 @@ void LIR_Assembler::rt_call(LIR_Opr result, address dest, const LIR_OprList* arg
28992913
if (info != NULL) {
29002914
add_call_info_here(info);
29012915
}
2916+
__ post_call_nop();
29022917
}
29032918

29042919
void LIR_Assembler::volatile_move_op(LIR_Opr src, LIR_Opr dest, BasicType type, CodeEmitInfo* info) {

src/hotspot/cpu/aarch64/c1_LIRGenerator_aarch64.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2014, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -338,6 +338,17 @@ void LIRGenerator::do_MonitorExit(MonitorExit* x) {
338338
monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
339339
}
340340

341+
void LIRGenerator::do_continuation_doYield(Intrinsic* x) {
342+
BasicTypeList signature(0);
343+
CallingConvention* cc = frame_map()->java_calling_convention(&signature, true);
344+
345+
const LIR_Opr result_reg = result_register_for(x->type());
346+
address entry = StubRoutines::cont_doYield();
347+
LIR_Opr result = rlock_result(x);
348+
CodeEmitInfo* info = state_for(x, x->state());
349+
__ call_runtime(entry, LIR_OprFact::illegalOpr, result_reg, cc->args(), info);
350+
__ move(result_reg, result);
351+
}
341352

342353
void LIRGenerator::do_NegateOp(NegateOp* x) {
343354

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*
23+
*/
24+
25+
#ifndef CPU_AARCH64_CONTINUATIONENTRY_AARCH64_INLINE_HPP
26+
#define CPU_AARCH64_CONTINUATIONENTRY_AARCH64_INLINE_HPP
27+
28+
#include "runtime/continuationEntry.hpp"
29+
30+
#include "code/codeCache.hpp"
31+
#include "runtime/frame.inline.hpp"
32+
#include "runtime/registerMap.hpp"
33+
34+
inline frame ContinuationEntry::to_frame() const {
35+
static CodeBlob* cb = CodeCache::find_blob_fast(entry_pc());
36+
assert(cb != nullptr, "");
37+
assert(cb->as_compiled_method()->method()->is_continuation_enter_intrinsic(), "");
38+
return frame(entry_sp(), entry_sp(), entry_fp(), entry_pc(), cb);
39+
}
40+
41+
inline intptr_t* ContinuationEntry::entry_fp() const {
42+
return (intptr_t*)((address)this + size());
43+
}
44+
45+
inline void ContinuationEntry::update_register_map(RegisterMap* map) const {
46+
intptr_t** fp = (intptr_t**)(bottom_sender_sp() - frame::sender_sp_offset);
47+
frame::update_map_with_saved_link(map, fp);
48+
}
49+
50+
51+
#endif // CPU_AARCH64_CONTINUATIONENTRY_AARCH64_INLINE_HPP

0 commit comments

Comments
 (0)