4848import com .oracle .truffle .compiler .TruffleCompilerOptionDescriptor ;
4949import com .oracle .truffle .compiler .TruffleCompilerOptionDescriptor .Type ;
5050import com .oracle .truffle .compiler .TruffleCompilerRuntime ;
51+ import com .oracle .truffle .runtime .ModulesSupport ;
5152import com .oracle .truffle .runtime .debug .JFRListener ;
5253import com .oracle .truffle .runtime .hotspot .HotSpotTruffleRuntime ;
5354import com .oracle .truffle .runtime .hotspot .libgraal .LibGraalScope .DetachAction ;
5455
56+ import java .util .function .Supplier ;
57+
5558/**
5659 * Represents a truffle compilation bundling compilable and task into a single object. Also installs
5760 * the TTY filter to forward log messages to the truffle runtime.
@@ -94,9 +97,12 @@ public String getCompilerConfigurationName(TruffleCompilerRuntime runtime) {
9497
9598 @ SuppressWarnings ("try" )
9699 private static String getCompilerConfigurationNameImpl (TruffleCompilerRuntime runtime ) {
97- try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
98- return TruffleToLibGraalCalls .getCompilerConfigurationFactoryName (getIsolateThread (), handle (runtime ));
99- }
100+ Supplier <String > action = () -> {
101+ try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
102+ return TruffleToLibGraalCalls .getCompilerConfigurationFactoryName (getIsolateThread (), handle (runtime ));
103+ }
104+ };
105+ return ModulesSupport .getJavaLangSupport ().runInPinnedVirtualThread (action );
100106 }
101107
102108 @ Override
@@ -107,12 +113,16 @@ public TruffleCompiler createCompiler(TruffleCompilerRuntime runtime) {
107113 @ SuppressWarnings ("try" )
108114 @ Override
109115 public void registerRuntime (TruffleCompilerRuntime runtime ) {
110- try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
111- runtime ().registerNativeMethods (TruffleToLibGraalCalls .class );
112- if (!registerRuntimeImpl (runtime )) {
113- throw new IllegalStateException ("Truffle with libgraal cannot be loaded in multiple class loaders. Make sure Truffle is loaded with the system class loader." );
116+ Supplier <Void > action = () -> {
117+ try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
118+ runtime ().registerNativeMethods (TruffleToLibGraalCalls .class );
119+ if (!registerRuntimeImpl (runtime )) {
120+ throw new IllegalStateException ("Truffle with libgraal cannot be loaded in multiple class loaders. Make sure Truffle is loaded with the system class loader." );
121+ }
114122 }
115- }
123+ return null ;
124+ };
125+ ModulesSupport .getJavaLangSupport ().runInPinnedVirtualThread (action );
116126 }
117127
118128 private static boolean registerRuntimeImpl (TruffleCompilerRuntime runtime ) {
@@ -135,38 +145,47 @@ private static <T extends Throwable> T sthrow(Class<T> type, Throwable t) throws
135145 @ SuppressWarnings ("try" )
136146 @ Override
137147 public TruffleCompilerOptionDescriptor [] listCompilerOptions () {
138- try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
139- byte [] binary = TruffleToLibGraalCalls .listCompilerOptions (getIsolateThread ());
140- BinaryInput input = BinaryInput .create (binary );
141- int length = input .readInt ();
142- TruffleCompilerOptionDescriptor [] descriptors = new TruffleCompilerOptionDescriptor [length ];
143- Type [] types = Type .values ();
144- for (int i = 0 ; i < length ; i ++) {
145- String name = input .readUTF ();
146- int typeOrdinal = input .readInt ();
147- boolean deprecated = input .readBoolean ();
148- String help = input .readUTF ();
149- String deprecationMessage = input .readUTF ();
150- descriptors [i ] = new TruffleCompilerOptionDescriptor (name , types [typeOrdinal ], deprecated , help , deprecationMessage );
148+ Supplier <TruffleCompilerOptionDescriptor []> action = () -> {
149+ try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
150+ byte [] binary = TruffleToLibGraalCalls .listCompilerOptions (getIsolateThread ());
151+ BinaryInput input = BinaryInput .create (binary );
152+ int length = input .readInt ();
153+ TruffleCompilerOptionDescriptor [] descriptors = new TruffleCompilerOptionDescriptor [length ];
154+ Type [] types = Type .values ();
155+ for (int i = 0 ; i < length ; i ++) {
156+ String name = input .readUTF ();
157+ int typeOrdinal = input .readInt ();
158+ boolean deprecated = input .readBoolean ();
159+ String help = input .readUTF ();
160+ String deprecationMessage = input .readUTF ();
161+ descriptors [i ] = new TruffleCompilerOptionDescriptor (name , types [typeOrdinal ], deprecated , help , deprecationMessage );
162+ }
163+ return descriptors ;
151164 }
152- return descriptors ;
153- }
165+ } ;
166+ return ModulesSupport . getJavaLangSupport (). runInPinnedVirtualThread ( action );
154167 }
155168
156169 @ SuppressWarnings ("try" )
157170 @ Override
158171 public String validateCompilerOption (String key , String value ) {
159- try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
160- return TruffleToLibGraalCalls .validateCompilerOption (getIsolateThread (), key , value );
161- }
172+ Supplier <String > action = () -> {
173+ try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
174+ return TruffleToLibGraalCalls .validateCompilerOption (getIsolateThread (), key , value );
175+ }
176+ };
177+ return ModulesSupport .getJavaLangSupport ().runInPinnedVirtualThread (action );
162178 }
163179
164180 @ SuppressWarnings ("try" )
165181 @ Override
166182 public boolean compilerOptionExists (String key ) {
167- try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
168- return TruffleToLibGraalCalls .compilerOptionExists (getIsolateThread (), key );
169- }
183+ Supplier <Boolean > action = () -> {
184+ try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
185+ return TruffleToLibGraalCalls .compilerOptionExists (getIsolateThread (), key );
186+ }
187+ };
188+ return ModulesSupport .getJavaLangSupport ().runInPinnedVirtualThread (action );
170189 }
171190
172191 @ Override
@@ -210,12 +229,15 @@ private static long initializeRuntimeImpl(TruffleCompilerRuntime runtime) {
210229 @ SuppressWarnings ("try" )
211230 @ Override
212231 public String getCompilerVersion () {
213- try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
214- return TruffleToLibGraalCalls .getCompilerVersion (getIsolateThread ());
215- } catch (UnsatisfiedLinkError linkError ) {
216- // An old libjvmcicompiler without the getReleaseVersion entry point.
217- return null ;
218- }
232+ Supplier <String > action = () -> {
233+ try (LibGraalScope scope = new LibGraalScope (DetachAction .DETACH_RUNTIME_AND_RELEASE )) {
234+ return TruffleToLibGraalCalls .getCompilerVersion (getIsolateThread ());
235+ } catch (UnsatisfiedLinkError linkError ) {
236+ // An old libjvmcicompiler without the getReleaseVersion entry point.
237+ return null ;
238+ }
239+ };
240+ return ModulesSupport .getJavaLangSupport ().runInPinnedVirtualThread (action );
219241 }
220242
221243}
0 commit comments