Skip to content

Commit 6bb5b29

Browse files
committed
[GR-38085] Make Sulong bytecode-based OSR the default.
PullRequest: graal/11603
2 parents 2849fa6 + a825ee1 commit 6bb5b29

File tree

10 files changed

+103
-28
lines changed

10 files changed

+103
-28
lines changed

sulong/mx.sulong/mx_sulong_benchmarks.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,6 @@ def hosting_registry(self):
737737
native_vm_registry.add_vm(GccVm('O3', ['-O3']), _suite)
738738
native_vm_registry.add_vm(ClangVm('O3', ['-O3']), _suite)
739739
native_vm_registry.add_vm(SulongVm('default', []), _suite, 10)
740-
native_vm_registry.add_vm(SulongVm('default-osr-bytecode', ['--llvm.OSR=BYTECODE']), _suite, 10)
741740

742741
native_polybench_vm_registry = VmRegistry("NativePolybench", known_host_registries=[java_vm_registry])
743742
native_polybench_vm_registry.add_vm(PolybenchVm('debug-aux-engine-cache',

sulong/projects/com.oracle.truffle.llvm.nativemode/src/com/oracle/truffle/llvm/nativemode/NativeConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -54,19 +54,21 @@ public class NativeConfiguration implements Configuration {
5454
private final Loader loader;
5555
private final LLVMIntrinsicProvider intrinsicProvider;
5656
private final PlatformCapability<?> platformCapability;
57+
protected final Key languageOptions;
5758

5859
protected NativeConfiguration(LLVMLanguage language, ContextExtension.Registry ctxExtRegistry, Key key) {
5960
loader = new DefaultLoader();
6061
intrinsicProvider = new BasicIntrinsicsProvider(language);
6162
platformCapability = BasicPlatformCapability.create(key.loadCxxLibraries);
63+
this.languageOptions = key;
6264
if (key.enableNFI) {
6365
ctxExtRegistry.register(NativeContextExtension.class, new NFIContextExtension.Factory());
6466
}
6567
}
6668

6769
@Override
6870
public NodeFactory createNodeFactory(LLVMLanguage language, DataLayout dataLayout) {
69-
return new BasicNodeFactory(language, dataLayout);
71+
return new BasicNodeFactory(language, dataLayout, languageOptions);
7072
}
7173

7274
@Override

sulong/projects/com.oracle.truffle.llvm.nativemode/src/com/oracle/truffle/llvm/nativemode/NativeConfigurationFactory.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates.
2+
* Copyright (c) 2016, 2022, Oracle and/or its affiliates.
33
*
44
* All rights reserved.
55
*
@@ -38,20 +38,20 @@
3838

3939
import com.oracle.truffle.llvm.runtime.ContextExtension;
4040
import com.oracle.truffle.llvm.runtime.LLVMLanguage;
41+
import com.oracle.truffle.llvm.runtime.config.CommonLanguageOptions;
4142
import com.oracle.truffle.llvm.runtime.config.Configuration;
4243
import com.oracle.truffle.llvm.runtime.config.ConfigurationFactory;
43-
import com.oracle.truffle.llvm.runtime.options.SulongEngineOption;
44+
4445
import org.graalvm.options.OptionValues;
4546

4647
public class NativeConfigurationFactory implements ConfigurationFactory<Key> {
4748

48-
public static final class Key {
49+
public static final class Key extends CommonLanguageOptions {
4950

50-
final boolean loadCxxLibraries;
5151
final boolean enableNFI;
5252

5353
public Key(OptionValues options) {
54-
this.loadCxxLibraries = options.get(SulongEngineOption.LOAD_CXX_LIBRARIES);
54+
super(options);
5555
this.enableNFI = options.get(SulongNativeOption.ENABLE_NFI);
5656
}
5757

@@ -61,13 +61,12 @@ public boolean equals(Object o) {
6161
return false;
6262
}
6363
Key other = (Key) o;
64-
return this.loadCxxLibraries == other.loadCxxLibraries && this.enableNFI == other.enableNFI;
64+
return this.enableNFI == other.enableNFI && super.equals(other);
6565
}
6666

6767
@Override
6868
public int hashCode() {
69-
int hash = 7;
70-
hash = 71 * hash + (this.loadCxxLibraries ? 1 : 0);
69+
int hash = super.hashCode();
7170
hash = 71 * hash + (this.enableNFI ? 1 : 0);
7271
return hash;
7372
}

sulong/projects/com.oracle.truffle.llvm.parser.factories/src/com/oracle/truffle/llvm/parser/factories/BasicNodeFactory.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@
346346
import com.oracle.truffle.llvm.runtime.nodes.vector.LLVMShuffleVectorNodeFactory.LLVMShuffleI32VectorNodeGen;
347347
import com.oracle.truffle.llvm.runtime.nodes.vector.LLVMShuffleVectorNodeFactory.LLVMShuffleI64VectorNodeGen;
348348
import com.oracle.truffle.llvm.runtime.nodes.vector.LLVMShuffleVectorNodeFactory.LLVMShuffleI8VectorNodeGen;
349+
import com.oracle.truffle.llvm.runtime.options.SulongEngineOption;
349350
import com.oracle.truffle.llvm.runtime.pointer.LLVMManagedPointer;
350351
import com.oracle.truffle.llvm.runtime.pointer.LLVMNativePointer;
351352
import com.oracle.truffle.llvm.runtime.types.AggregateType;
@@ -370,17 +371,27 @@
370371
import java.util.regex.Matcher;
371372
import java.util.regex.Pattern;
372373

374+
import com.oracle.truffle.llvm.runtime.config.CommonLanguageOptions;
375+
373376
public class BasicNodeFactory implements NodeFactory {
377+
374378
protected final LLVMLanguage language;
375379
protected DataLayout dataLayout;
376380

377381
protected final Type vaListType;
378382

379-
public BasicNodeFactory(LLVMLanguage language, DataLayout dataLayout) {
383+
protected final CommonLanguageOptions engineOptions;
384+
385+
public BasicNodeFactory(LLVMLanguage language, DataLayout dataLayout, CommonLanguageOptions engineOptions) {
380386
this.language = language;
381387
this.dataLayout = dataLayout;
382-
383388
this.vaListType = language.getActiveConfiguration().getCapability(PlatformCapability.class).getVAListType();
389+
this.engineOptions = engineOptions;
390+
}
391+
392+
@Override
393+
public boolean isCfgOsrEnabled() {
394+
return engineOptions.osrMode == SulongEngineOption.OSRMode.CFG;
384395
}
385396

386397
@Override
@@ -1133,7 +1144,7 @@ public RootNode createFunction(int exceptionValueSlot, LLVMBasicBlockNode[] allF
11331144
LLVMSourceLocation location, LLVMFunction rootFunction) {
11341145
LLVMUniquesRegionAllocNode uniquesRegionAllocNode = uniquesRegion.isEmpty() ? null
11351146
: LLVMUniquesRegionAllocNodeGen.create(createAlloca(uniquesRegion.getSize(), uniquesRegion.getAlignment()));
1136-
LLVMDispatchBasicBlockNode body = LLVMDispatchBasicBlockNodeGen.create(exceptionValueSlot, allFunctionNodes, loopSuccessorSlot, debugInfo);
1147+
LLVMDispatchBasicBlockNode body = LLVMDispatchBasicBlockNodeGen.create(exceptionValueSlot, allFunctionNodes, loopSuccessorSlot, debugInfo, engineOptions.osrMode);
11371148
body.setSourceLocation(LLVMSourceLocation.orDefault(location));
11381149
LLVMStackAccess stackAccess = createStackAccess();
11391150
LLVMFunctionRootNode functionRoot = LLVMFunctionRootNodeGen.create(uniquesRegionAllocNode, stackAccess, copyArgumentsToFrame, body, frameDescriptor);

sulong/projects/com.oracle.truffle.llvm.parser/src/com/oracle/truffle/llvm/parser/LazyToTruffleConverterImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private RootCallTarget generateCallTarget() {
221221
info.setBlocks(blockNodes);
222222

223223
int loopSuccessorSlot = -1;
224-
if (options.get(SulongEngineOption.OSR_MODE) == SulongEngineOption.OSRMode.CFG && !options.get(SulongEngineOption.AOTCacheStore)) {
224+
if (nodeFactory.isCfgOsrEnabled() && !options.get(SulongEngineOption.AOTCacheStore)) {
225225
LLVMControlFlowGraph cfg = new LLVMControlFlowGraph(method.getBlocks().toArray(FunctionDefinition.EMPTY));
226226
cfg.build();
227227

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/LLVMContext.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public final class LLVMContext {
184184
@CompilationFinal Object freeGlobalsBlockFunction;
185185
@CompilationFinal Object allocateGlobalsBlockFunction;
186186
@CompilationFinal Object protectGlobalsBlockFunction;
187-
@CompilationFinal SulongEngineOption.OSRMode osrMode = null;
188187

189188
protected boolean initialized;
190189
protected boolean cleanupNecessary;
@@ -615,14 +614,6 @@ public Object getFreeReadOnlyGlobalsBlockFunction() {
615614
return freeGlobalsBlockFunction;
616615
}
617616

618-
public SulongEngineOption.OSRMode getOSRMode() {
619-
if (osrMode == null) {
620-
CompilerDirectives.transferToInterpreterAndInvalidate();
621-
this.osrMode = env.getOptions().get(SulongEngineOption.OSR_MODE);
622-
}
623-
return osrMode;
624-
}
625-
626617
public Object getProtectReadOnlyGlobalsBlockFunction() {
627618
if (protectGlobalsBlockFunction == null) {
628619
CompilerDirectives.transferToInterpreterAndInvalidate();

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/NodeFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
*/
6767
public interface NodeFactory {
6868

69+
boolean isCfgOsrEnabled();
70+
6971
LLVMExpressionNode createInsertElement(Type resultType, LLVMExpressionNode vector, LLVMExpressionNode element, LLVMExpressionNode index);
7072

7173
LLVMExpressionNode createExtractElement(Type resultType, LLVMExpressionNode vector, LLVMExpressionNode index);
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (c) 2022, Oracle and/or its affiliates.
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without modification, are
7+
* permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this list of
10+
* conditions and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of
13+
* conditions and the following disclaimer in the documentation and/or other materials provided
14+
* with the distribution.
15+
*
16+
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to
17+
* endorse or promote products derived from this software without specific prior written
18+
* permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
21+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22+
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28+
* OF THE POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
package com.oracle.truffle.llvm.runtime.config;
31+
32+
import org.graalvm.options.OptionValues;
33+
34+
import com.oracle.truffle.llvm.runtime.options.SulongEngineOption;
35+
import com.oracle.truffle.llvm.runtime.options.SulongEngineOption.OSRMode;
36+
37+
/**
38+
* Options that are per language instance. If these options are different, they prevent code
39+
* sharing. Different Sulong configurations (e.g. native, managed) should subclass this, potentially
40+
* adding more configuration specific options that should also be per language instance.
41+
*/
42+
public abstract class CommonLanguageOptions {
43+
44+
public final boolean loadCxxLibraries;
45+
public final OSRMode osrMode;
46+
47+
protected CommonLanguageOptions(OptionValues options) {
48+
this.loadCxxLibraries = options.get(SulongEngineOption.LOAD_CXX_LIBRARIES);
49+
this.osrMode = options.get(SulongEngineOption.OSR_MODE);
50+
}
51+
52+
@Override
53+
public boolean equals(Object o) {
54+
if (!(o instanceof CommonLanguageOptions)) {
55+
return false;
56+
}
57+
CommonLanguageOptions other = (CommonLanguageOptions) o;
58+
return this.loadCxxLibraries == other.loadCxxLibraries && this.osrMode == other.osrMode;
59+
}
60+
61+
@Override
62+
public int hashCode() {
63+
int hash = 7;
64+
hash = 71 * hash + (this.loadCxxLibraries ? 1 : 0);
65+
hash = 71 * hash + this.osrMode.hashCode();
66+
return hash;
67+
}
68+
}

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/nodes/control/LLVMDispatchBasicBlockNode.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import com.oracle.truffle.api.CompilerAsserts;
3333
import com.oracle.truffle.api.CompilerDirectives;
34+
import com.oracle.truffle.api.TruffleSafepoint;
3435
import com.oracle.truffle.api.dsl.Specialization;
3536
import com.oracle.truffle.api.frame.VirtualFrame;
3637
import com.oracle.truffle.api.instrumentation.StandardTags;
@@ -39,7 +40,6 @@
3940
import com.oracle.truffle.api.nodes.ExplodeLoop;
4041
import com.oracle.truffle.api.nodes.ExplodeLoop.LoopExplosionKind;
4142
import com.oracle.truffle.api.nodes.LoopNode;
42-
import com.oracle.truffle.llvm.runtime.LLVMContext;
4343
import com.oracle.truffle.llvm.runtime.except.LLVMUserException;
4444
import com.oracle.truffle.llvm.runtime.nodes.api.LLVMControlFlowNode;
4545
import com.oracle.truffle.llvm.runtime.nodes.api.LLVMExpressionNode;
@@ -61,13 +61,15 @@ public abstract class LLVMDispatchBasicBlockNode extends LLVMExpressionNode impl
6161

6262
private final int loopSuccessorSlot;
6363

64+
private final SulongEngineOption.OSRMode osrMode;
6465
@CompilerDirectives.CompilationFinal private Object osrMetadata;
6566

66-
public LLVMDispatchBasicBlockNode(int exceptionValueSlot, LLVMBasicBlockNode[] bodyNodes, int loopSuccessorSlot, LocalVariableDebugInfo debugInfo) {
67+
public LLVMDispatchBasicBlockNode(int exceptionValueSlot, LLVMBasicBlockNode[] bodyNodes, int loopSuccessorSlot, LocalVariableDebugInfo debugInfo, SulongEngineOption.OSRMode osrMode) {
6768
this.exceptionValueSlot = exceptionValueSlot;
6869
this.bodyNodes = bodyNodes;
6970
this.loopSuccessorSlot = loopSuccessorSlot;
7071
this.debugInfo = debugInfo;
72+
this.osrMode = osrMode;
7173
}
7274

7375
@Override
@@ -98,8 +100,9 @@ private Object dispatchFromBasicBlock(VirtualFrame frame, int bci, Counters coun
98100
CompilerAsserts.partialEvaluationConstant(basicBlockIndex);
99101
if (CompilerDirectives.hasNextTier()) {
100102
if (basicBlockIndex <= counters.previousBasicBlockIndex) {
103+
TruffleSafepoint.poll(this);
101104
counters.backEdgeCounter++;
102-
if (CompilerDirectives.inInterpreter() && LLVMContext.get(this).getOSRMode() == SulongEngineOption.OSRMode.BYTECODE && BytecodeOSRNode.pollOSRBackEdge(this)) {
105+
if (CompilerDirectives.inInterpreter() && osrMode == SulongEngineOption.OSRMode.BYTECODE && BytecodeOSRNode.pollOSRBackEdge(this)) {
103106
returnValue = BytecodeOSRNode.tryOSR(this, basicBlockIndex, counters, null, frame);
104107
if (returnValue != null) {
105108
break outer;

sulong/projects/com.oracle.truffle.llvm.runtime/src/com/oracle/truffle/llvm/runtime/options/SulongEngineOption.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public final class SulongEngineOption {
105105
@Option(name = "llvm.OSR",
106106
category = OptionCategory.EXPERT,
107107
help = "Mode to use for on-stack-replacement of loops.")
108-
public static final OptionKey<OSRMode> OSR_MODE = new OptionKey<>(OSRMode.CFG);
108+
public static final OptionKey<OSRMode> OSR_MODE = new OptionKey<>(OSRMode.BYTECODE);
109109

110110
public enum OSRMode {
111111
CFG,

0 commit comments

Comments
 (0)