Skip to content

Commit 97d1535

Browse files
committed
[GR-68660] Improve Truffle startup on HotSpot.
PullRequest: graal/21875
2 parents 4447c7c + 307e0d6 commit 97d1535

File tree

23 files changed

+493
-560
lines changed

23 files changed

+493
-560
lines changed

substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/api/SubstrateTruffleRuntime.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ public final class SubstrateTruffleRuntime extends OptimizedTruffleRuntime {
128128
@Platforms(Platform.HOSTED_ONLY.class)
129129
public SubstrateTruffleRuntime() {
130130
super(new SubstrateTruffleCompilationSupport(), List.of());
131-
/* Ensure the factory class gets initialized. */
132-
super.getLoopNodeFactory();
133131
}
134132

135133
@Override

truffle/mx.truffle/mx_truffle.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ def subgroup(self):
9090

9191
def extraVmArgs(self):
9292
extraVmArgs = super(JMHRunnerTruffleBenchmarkSuite, self).extraVmArgs()
93-
extraVmArgs.extend(_open_module_exports_args())
9493
# com.oracle.truffle.api.benchmark.InterpreterCallBenchmark$BenchmarkState needs DefaultTruffleRuntime
9594
extraVmArgs.append('--add-exports=org.graalvm.truffle/com.oracle.truffle.api.impl=ALL-UNNAMED')
9695
return extraVmArgs
@@ -179,26 +178,6 @@ def checkLinks(javadocDir):
179178
if err:
180179
mx.abort('There are wrong references in Javadoc')
181180

182-
def _open_module_exports_args():
183-
"""
184-
Gets the VM args for exporting all Truffle API packages on JDK9 or later.
185-
The default Truffle moduleInfo is opened but closed version is deployed into graalvm.
186-
To run benchmarks on the graalvm we need to open the closed Truffle packages.
187-
"""
188-
assert mx.get_jdk().javaCompliance >= '1.9'
189-
truffle_api_dist = mx.distribution('TRUFFLE_API')
190-
truffle_api_module_name = truffle_api_dist.moduleInfo['name']
191-
module_info_open_exports = getattr(truffle_api_dist, 'moduleInfo')['exports']
192-
args = []
193-
for export in module_info_open_exports:
194-
if ' to ' in export: # Qualified exports
195-
package, targets = export.split(' to ')
196-
targets = targets.replace(' ', '')
197-
else: # Unqualified exports
198-
package = export
199-
targets = 'ALL-UNNAMED'
200-
args.append('--add-exports=' + truffle_api_module_name + '/' + package + '=' + targets)
201-
return args
202181

203182
def enable_truffle_native_access(vmArgs):
204183
"""
@@ -1990,7 +1969,6 @@ def clean(self, forBuild=False):
19901969
mx.rmtree(self.out_dir, ignore_errors=True)
19911970

19921971

1993-
19941972
mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmTruffleLibrary(
19951973
suite=_suite,
19961974
name='Truffle API',

truffle/mx.truffle/suite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@
744744
"TRUFFLE_API",
745745
"mx:JMH_1_21",
746746
"TRUFFLE_JCODINGS",
747+
"TRUFFLE_RUNTIME",
747748
],
748749
"requires" : [
749750
"jdk.unsupported", # sun.misc.Unsafe
@@ -1730,7 +1731,6 @@
17301731
],
17311732
"uses" : [
17321733
"com.oracle.truffle.api.impl.TruffleLocator",
1733-
"com.oracle.truffle.runtime.LoopNodeFactory",
17341734
"com.oracle.truffle.runtime.TruffleTypes",
17351735
"com.oracle.truffle.runtime.EngineCacheSupport",
17361736
"com.oracle.truffle.runtime.jfr.EventFactory.Provider",

truffle/src/com.oracle.truffle.api.library/snapshot.sigtest

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ meth public abstract java.lang.Object readDelegateExport(java.lang.Object)
124124

125125
CLSS public abstract com.oracle.truffle.api.library.LibraryFactory<%0 extends com.oracle.truffle.api.library.Library>
126126
cons protected init(java.lang.Class<{com.oracle.truffle.api.library.LibraryFactory%0}>,java.util.List<com.oracle.truffle.api.library.Message>)
127+
anno 0 java.lang.Deprecated(boolean forRemoval=false, java.lang.String since="")
128+
cons protected init(java.lang.Class<{com.oracle.truffle.api.library.LibraryFactory%0}>,java.util.List<com.oracle.truffle.api.library.Message>,boolean)
127129
meth protected !varargs com.oracle.truffle.api.utilities.FinalBitSet createMessageBitSet(com.oracle.truffle.api.library.Message[])
128130
meth protected abstract java.lang.Class<?> getDefaultClass(java.lang.Object)
129131
meth protected abstract java.lang.Object genericDispatch(com.oracle.truffle.api.library.Library,java.lang.Object,com.oracle.truffle.api.library.Message,java.lang.Object[],int) throws java.lang.Exception
@@ -155,12 +157,10 @@ CLSS public abstract com.oracle.truffle.api.library.Message
155157
cons protected !varargs init(java.lang.Class<? extends com.oracle.truffle.api.library.Library>,java.lang.String,int,boolean,java.lang.Class<?>,java.lang.Class<?>[])
156158
cons protected !varargs init(java.lang.Class<? extends com.oracle.truffle.api.library.Library>,java.lang.String,int,java.lang.Class<?>,java.lang.Class<?>[])
157159
meth protected final java.lang.Object clone() throws java.lang.CloneNotSupportedException
158-
meth public final boolean equals(java.lang.Object)
159160
meth public final boolean isDeprecated()
160161
meth public final com.oracle.truffle.api.library.LibraryFactory<?> getFactory()
161162
meth public final int getId()
162163
meth public final int getParameterCount()
163-
meth public final int hashCode()
164164
meth public final java.lang.Class<? extends com.oracle.truffle.api.library.Library> getLibraryClass()
165165
meth public final java.lang.Class<?> getParameterType(int)
166166
meth public final java.lang.Class<?> getReceiverType()
@@ -173,7 +173,7 @@ meth public final java.util.List<java.lang.Class<?>> getParameterTypes()
173173
meth public static com.oracle.truffle.api.library.Message resolve(java.lang.Class<? extends com.oracle.truffle.api.library.Library>,java.lang.String)
174174
meth public static com.oracle.truffle.api.library.Message resolve(java.lang.Class<? extends com.oracle.truffle.api.library.Library>,java.lang.String,boolean)
175175
supr java.lang.Object
176-
hfds deprecated,hash,id,library,libraryClass,parameterCount,parameterTypes,parameterTypesArray,qualifiedName,returnType,simpleName
176+
hfds deprecated,id,library,libraryClass,parameterCount,parameterTypesArray,qualifiedName,returnType,simpleName
177177

178178
CLSS public abstract com.oracle.truffle.api.library.ReflectionLibrary
179179
cons protected init()
@@ -282,3 +282,8 @@ CLSS public abstract interface !annotation java.lang.annotation.Target
282282
intf java.lang.annotation.Annotation
283283
meth public abstract java.lang.annotation.ElementType[] value()
284284

285+
CLSS public abstract interface !annotation jdk.internal.vm.annotation.AOTSafeClassInitializer
286+
anno 0 java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy value=RUNTIME)
287+
anno 0 java.lang.annotation.Target(java.lang.annotation.ElementType[] value=[TYPE])
288+
intf java.lang.annotation.Annotation
289+

truffle/src/com.oracle.truffle.api.library/src/com/oracle/truffle/api/library/LibraryFactory.java

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private static void removeClassesLoadedDuringImageBuild(Map<? extends Class<?>,
171171
final Map<String, Message> nameToMessages;
172172
@CompilationFinal private volatile T uncachedDispatch;
173173

174-
final DynamicDispatchLibrary dispatchLibrary;
174+
private final DynamicDispatchLibrary dispatchLibrary;
175175

176176
DefaultExportProvider[] beforeBuiltinDefaultExports;
177177
DefaultExportProvider[] afterBuiltinDefaultExports;
@@ -180,9 +180,35 @@ private static void removeClassesLoadedDuringImageBuild(Map<? extends Class<?>,
180180
* Constructor for generated subclasses. Do not sub-class {@link LibraryFactory} manually.
181181
*
182182
* @since 19.0
183+
* @deprecated new versions of the library generator won't use this constructor anymore
183184
*/
184185
@SuppressWarnings("unchecked")
186+
@Deprecated
185187
protected LibraryFactory(Class<T> libraryClass, List<Message> messages) {
188+
this(libraryClass, messages, isDynamicDispatchEnabled(libraryClass));
189+
}
190+
191+
private static boolean isDynamicDispatchEnabled(Class<?> libraryClass) {
192+
if (libraryClass == DynamicDispatchLibrary.class) {
193+
return false;
194+
} else {
195+
GenerateLibrary annotation = libraryClass.getAnnotation(GenerateLibrary.class);
196+
boolean dynamicDispatchEnabled = annotation == null || annotation.dynamicDispatchEnabled();
197+
if (dynamicDispatchEnabled) {
198+
return true;
199+
} else {
200+
return false;
201+
}
202+
}
203+
}
204+
205+
/**
206+
* Constructor for generated subclasses. Do not sub-class {@link LibraryFactory} manually.
207+
*
208+
* @since 26.0
209+
*/
210+
@SuppressWarnings("unchecked")
211+
protected LibraryFactory(Class<T> libraryClass, List<Message> messages, boolean dynamicDispatchEnabled) {
186212
assert this.getClass().getName().endsWith(LibraryExport.GENERATED_CLASS_SUFFIX);
187213
this.libraryClass = libraryClass;
188214
this.messages = Collections.unmodifiableList(messages);
@@ -193,18 +219,7 @@ protected LibraryFactory(Class<T> libraryClass, List<Message> messages) {
193219
messagesMap.putIfAbsent(message.getSimpleName(), message);
194220
}
195221
this.nameToMessages = messagesMap;
196-
if (libraryClass == DynamicDispatchLibrary.class) {
197-
this.dispatchLibrary = null;
198-
} else {
199-
GenerateLibrary annotation = libraryClass.getAnnotation(GenerateLibrary.class);
200-
boolean dynamicDispatchEnabled = annotation == null || libraryClass.getAnnotation(GenerateLibrary.class).dynamicDispatchEnabled();
201-
if (dynamicDispatchEnabled) {
202-
this.dispatchLibrary = LibraryFactory.resolve(DynamicDispatchLibrary.class).getUncached();
203-
} else {
204-
this.dispatchLibrary = null;
205-
}
206-
}
207-
222+
this.dispatchLibrary = dynamicDispatchEnabled ? LibraryFactory.resolve(DynamicDispatchLibrary.class).getUncached() : null;
208223
initDefaultExports();
209224
}
210225

truffle/src/com.oracle.truffle.api.library/src/com/oracle/truffle/api/library/Message.java

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,10 @@
4141
package com.oracle.truffle.api.library;
4242

4343
import java.lang.reflect.Method;
44-
import java.util.Arrays;
45-
import java.util.Collections;
4644
import java.util.List;
4745
import java.util.Objects;
4846

47+
import com.oracle.truffle.api.CompilerDirectives;
4948
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5049
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
5150

@@ -71,13 +70,11 @@
7170
public abstract class Message {
7271

7372
private final String simpleName;
74-
private final String qualifiedName;
73+
private String qualifiedName; // lazy init
7574
private final int id;
76-
private final int hash;
7775
private final boolean deprecated;
7876
private final Class<?> returnType;
7977
private final Class<? extends Library> libraryClass;
80-
private final List<Class<?>> parameterTypes;
8178
@CompilationFinal(dimensions = 1) private final Class<?>[] parameterTypesArray;
8279
private final int parameterCount;
8380
@CompilationFinal LibraryFactory<Library> library;
@@ -104,15 +101,13 @@ private Message(Class<? extends Library> libraryClass, int id, String messageNam
104101
Objects.requireNonNull(messageName);
105102
Objects.requireNonNull(returnType);
106103
this.libraryClass = libraryClass;
107-
this.simpleName = messageName.intern();
104+
assert messageName.intern() == messageName : "message name must already be interned";
105+
this.simpleName = messageName;
108106
this.returnType = returnType;
109107
this.parameterTypesArray = parameterTypes;
110-
this.parameterTypes = Collections.unmodifiableList(Arrays.asList(parameterTypes));
111-
this.qualifiedName = (getLibraryName() + "." + simpleName + parameters(parameterTypes)).intern();
112108
this.deprecated = deprecated;
113109
this.id = id;
114110
this.parameterCount = parameterTypes.length;
115-
this.hash = qualifiedName.hashCode();
116111
}
117112

118113
private static String parameters(Class<?>... parameterTypes) {
@@ -150,6 +145,10 @@ public final int getId() {
150145
* @since 19.0
151146
*/
152147
public final String getQualifiedName() {
148+
if (qualifiedName == null) {
149+
CompilerDirectives.transferToInterpreterAndInvalidate();
150+
qualifiedName = (getLibraryName() + "." + getSimpleName() + parameters(parameterTypesArray)).intern();
151+
}
153152
return qualifiedName;
154153
}
155154

@@ -208,7 +207,7 @@ public final Class<?> getReceiverType() {
208207
* @since 19.0
209208
*/
210209
public final List<Class<?>> getParameterTypes() {
211-
return parameterTypes;
210+
return List.of(parameterTypesArray);
212211
}
213212

214213
/**
@@ -256,26 +255,6 @@ public final LibraryFactory<?> getFactory() {
256255
return library;
257256
}
258257

259-
/**
260-
* {@inheritDoc}
261-
*
262-
* @since 19.0
263-
*/
264-
@Override
265-
public final boolean equals(Object obj) {
266-
return this == obj;
267-
}
268-
269-
/**
270-
* {@inheritDoc}
271-
*
272-
* @since 19.0
273-
*/
274-
@Override
275-
public final int hashCode() {
276-
return hash;
277-
}
278-
279258
/**
280259
* {@inheritDoc}
281260
*

truffle/src/com.oracle.truffle.api.object/src/com/oracle/truffle/api/object/LayoutImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ record Key(
170170
int implicitCastFlags,
171171
LayoutStrategy strategy) {
172172

173+
// letting Java generate hashcodes has slow startup
174+
@Override
175+
public int hashCode() {
176+
return Objects.hash(type, implicitCastFlags, strategy);
177+
}
178+
173179
@Override
174180
public boolean equals(Object obj) {
175181
if (this == obj) {

0 commit comments

Comments
 (0)