Skip to content

Commit 8b03e0a

Browse files
committed
[GR-14690] Performance optimizations mostly for single context mode
PullRequest: graalpython/545
2 parents b2b8ca7 + 33678b6 commit 8b03e0a

File tree

17 files changed

+77
-45
lines changed

17 files changed

+77
-45
lines changed

ci_common/mixins.libsonnet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ local const = import 'constants.libsonnet';
2626
linux:: linux,
2727

2828
local linuxBench = linux + {
29-
capabilities +: ["no_frequency_scaling", "tmpfs25g", "x62"],
29+
capabilities +: ["no_frequency_scaling", "tmpfs25g", "x52"],
3030
},
3131
linuxBench:: linuxBench,
3232

@@ -122,4 +122,4 @@ local const = import 'constants.libsonnet';
122122
],
123123
},
124124
bench:: bench,
125-
}
125+
}

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonMain.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
200200
case "-dump":
201201
if (wantsExperimental) {
202202
subprocessArgs.add("Dgraal.Dump=");
203+
subprocessArgs.add("Dgraal.TraceTruffleCompilation=true");
204+
subprocessArgs.add("Dgraal.TraceTruffleInlining=true");
205+
subprocessArgs.add("Dgraal.TraceTruffleTransferToInterpreter=true");
206+
subprocessArgs.add("Dgraal.TruffleBackgroundCompilation=false");
203207
inputArgs.remove("-dump");
204208
} else {
205209
unrecognized.add(arg);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/grammar/TestParserTranslator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@
5252
import java.util.Set;
5353
import java.util.stream.Collectors;
5454

55-
import org.junit.Test;
56-
5755
import com.oracle.graal.python.PythonLanguage;
5856
import com.oracle.graal.python.builtins.objects.PNone;
5957
import com.oracle.graal.python.builtins.objects.complex.PComplex;
@@ -119,9 +117,11 @@
119117
import com.oracle.truffle.api.nodes.Node;
120118
import com.oracle.truffle.api.nodes.NodeUtil;
121119
import com.oracle.truffle.api.nodes.RootNode;
122-
import com.oracle.truffle.api.profiles.BranchProfile;
120+
import com.oracle.truffle.api.profiles.ConditionProfile;
123121
import com.oracle.truffle.api.source.Source;
124122

123+
import org.junit.Test;
124+
125125
public class TestParserTranslator {
126126
PythonContext context;
127127

@@ -131,7 +131,7 @@ public TestParserTranslator() {
131131
}
132132

133133
private static class JUnitRootNode extends PRootNode {
134-
private final BranchProfile profile = BranchProfile.create();
134+
private final ConditionProfile profile = ConditionProfile.createCountingProfile();
135135
@Child private ExpressionNode body;
136136
@Child private CalleeContext calleeContext = CalleeContext.create();
137137

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ public TruffleObject getCallable() {
743743

744744
@Specialization
745745
Object doIt(VirtualFrame frame,
746-
@Cached BranchProfile customLocalsProfile,
746+
@Cached("createCountingProfile()") ConditionProfile customLocalsProfile,
747747
@Cached CExtNodes.AsPythonObjectNode asPythonObjectNode,
748748
@CachedContext(PythonLanguage.class) PythonContext ctx,
749749
@Cached PRaiseNode raiseNode) {
@@ -1475,7 +1475,7 @@ abstract static class MethodDescriptorRoot extends PRootNode {
14751475
@Child protected ReadIndexedArgumentNode readSelfNode;
14761476
@Child private CalleeContext calleeContext = CalleeContext.create();
14771477

1478-
private final BranchProfile customLocalsProfile = BranchProfile.create();
1478+
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
14791479
protected final PythonObjectFactory factory;
14801480

14811481
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/PThreadState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
import com.oracle.truffle.api.library.CachedLibrary;
8585
import com.oracle.truffle.api.library.ExportLibrary;
8686
import com.oracle.truffle.api.library.ExportMessage;
87-
import com.oracle.truffle.api.profiles.BranchProfile;
87+
import com.oracle.truffle.api.profiles.ConditionProfile;
8888
import com.oracle.truffle.llvm.spi.NativeTypeLibrary;
8989

9090
@ExportLibrary(InteropLibrary.class)
@@ -481,7 +481,7 @@ protected GetTracebackRootNode(TruffleLanguage<?> language) {
481481
@Child private GetTracebackNode getTracebackNode;
482482
@Child private CalleeContext calleeContext = CalleeContext.create();
483483

484-
private final BranchProfile profile = BranchProfile.create();
484+
private final ConditionProfile profile = ConditionProfile.createCountingProfile();
485485

486486
@Override
487487
public Object execute(VirtualFrame frame) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/PFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class PFunction extends PythonObject {
5353
private final Assumption codeStableAssumption;
5454
private final Assumption defaultsStableAssumption;
5555
private final PythonObject globals;
56-
private final PCell[] closure;
56+
@CompilationFinal(dimensions = 1) private final PCell[] closure;
5757
private final boolean isStatic;
5858
@CompilationFinal private PCode code;
5959
@CompilationFinal(dimensions = 1) private Object[] defaultValues;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ModuleRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
import com.oracle.truffle.api.frame.FrameDescriptor;
3939
import com.oracle.truffle.api.frame.FrameSlot;
4040
import com.oracle.truffle.api.frame.VirtualFrame;
41-
import com.oracle.truffle.api.profiles.BranchProfile;
41+
import com.oracle.truffle.api.profiles.ConditionProfile;
4242
import com.oracle.truffle.api.source.SourceSection;
4343

4444
public class ModuleRootNode extends PClosureRootNode {
4545
private static final Signature SIGNATURE = new Signature(false, -1, false, new String[0], new String[0]);
4646
private final String name;
4747
private final String doc;
48-
private final BranchProfile customLocalsProfile = BranchProfile.create();
48+
private final ConditionProfile customLocalsProfile = ConditionProfile.createCountingProfile();
4949
@Child private ExpressionNode body;
5050
@Child private WriteGlobalNode writeModuleDoc;
5151
@Child private CalleeContext calleeContext = CalleeContext.create();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PClosureFunctionRootNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
*/
4141
package com.oracle.graal.python.nodes;
4242

43+
import com.oracle.graal.python.PythonLanguage;
4344
import com.oracle.graal.python.builtins.objects.function.Signature;
4445
import com.oracle.graal.python.parser.ExecutionCellSlots;
4546
import com.oracle.truffle.api.Assumption;
4647
import com.oracle.truffle.api.CompilerDirectives;
47-
import com.oracle.truffle.api.TruffleLanguage;
4848
import com.oracle.truffle.api.frame.FrameDescriptor;
4949
import com.oracle.truffle.api.frame.FrameSlot;
5050

@@ -53,7 +53,7 @@ public abstract class PClosureFunctionRootNode extends PClosureRootNode {
5353
@CompilerDirectives.CompilationFinal(dimensions = 1) protected final Assumption[] cellEffectivelyFinalAssumptions;
5454
private final Signature signature;
5555

56-
protected PClosureFunctionRootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor, ExecutionCellSlots executionCellSlots, Signature signature) {
56+
protected PClosureFunctionRootNode(PythonLanguage language, FrameDescriptor frameDescriptor, ExecutionCellSlots executionCellSlots, Signature signature) {
5757
super(language, frameDescriptor, executionCellSlots.getFreeVarSlots());
5858
this.cellVarSlots = executionCellSlots.getCellVarSlots();
5959
this.cellEffectivelyFinalAssumptions = executionCellSlots.getCellVarAssumptions();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PClosureRootNode.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,69 @@
4040
*/
4141
package com.oracle.graal.python.nodes;
4242

43+
import com.oracle.graal.python.PythonLanguage;
4344
import com.oracle.graal.python.builtins.objects.cell.PCell;
4445
import com.oracle.graal.python.builtins.objects.function.PArguments;
46+
import com.oracle.truffle.api.Assumption;
4547
import com.oracle.truffle.api.CompilerDirectives;
46-
import com.oracle.truffle.api.TruffleLanguage;
4748
import com.oracle.truffle.api.frame.Frame;
4849
import com.oracle.truffle.api.frame.FrameDescriptor;
4950
import com.oracle.truffle.api.frame.FrameSlot;
5051
import com.oracle.truffle.api.frame.VirtualFrame;
5152
import com.oracle.truffle.api.nodes.ExplodeLoop;
5253

5354
public abstract class PClosureRootNode extends PRootNode {
55+
private static final PCell[] NO_CLOSURE = new PCell[0];
56+
private final Assumption singleContextAssumption;
5457
@CompilerDirectives.CompilationFinal(dimensions = 1) protected final FrameSlot[] freeVarSlots;
58+
@CompilerDirectives.CompilationFinal(dimensions = 1) protected PCell[] closure;
5559
private final int length;
5660

57-
protected PClosureRootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor, FrameSlot[] freeVarSlots) {
61+
protected PClosureRootNode(PythonLanguage language, FrameDescriptor frameDescriptor, FrameSlot[] freeVarSlots) {
5862
super(language, frameDescriptor);
63+
this.singleContextAssumption = language.singleContextAssumption;
5964
this.freeVarSlots = freeVarSlots;
6065
this.length = freeVarSlots != null ? freeVarSlots.length : 0;
6166
}
6267

6368
protected void addClosureCellsToLocals(Frame frame) {
64-
PCell[] closure = PArguments.getClosure(frame);
65-
if (closure != null) {
69+
PCell[] frameClosure = PArguments.getClosure(frame);
70+
if (frameClosure != null) {
71+
if (singleContextAssumption.isValid() && closure == null) {
72+
CompilerDirectives.transferToInterpreterAndInvalidate();
73+
closure = frameClosure;
74+
} else if (closure != NO_CLOSURE && ((!singleContextAssumption.isValid() && closure != null) || closure != frameClosure)) {
75+
CompilerDirectives.transferToInterpreterAndInvalidate();
76+
closure = NO_CLOSURE;
77+
}
6678
assert freeVarSlots != null : "closure root node: the free var slots cannot be null when the closure is not null";
67-
assert closure.length == freeVarSlots.length : "closure root node: the closure must have the same length as the free var slots array";
68-
if (freeVarSlots.length < 32) {
69-
addClosureCellsToLocalsExploded(frame, closure);
79+
assert frameClosure.length == freeVarSlots.length : "closure root node: the closure must have the same length as the free var slots array";
80+
if (closure != null && closure != NO_CLOSURE) {
81+
if (freeVarSlots.length < 32) {
82+
addClosureCellsToLocalsExploded(frame, closure);
83+
} else {
84+
addClosureCellsToLocalsLoop(frame, closure);
85+
}
7086
} else {
71-
addClosureCellsToLocalsLoop(frame, closure);
87+
if (freeVarSlots.length < 32) {
88+
addClosureCellsToLocalsExploded(frame, frameClosure);
89+
} else {
90+
addClosureCellsToLocalsLoop(frame, frameClosure);
91+
}
7292
}
7393
}
7494
}
7595

76-
protected void addClosureCellsToLocalsLoop(Frame frame, PCell[] closure) {
96+
protected void addClosureCellsToLocalsLoop(Frame frame, PCell[] frameClosure) {
7797
for (int i = 0; i < length; i++) {
78-
frame.setObject(freeVarSlots[i], closure[i]);
98+
frame.setObject(freeVarSlots[i], frameClosure[i]);
7999
}
80100
}
81101

82102
@ExplodeLoop
83-
protected void addClosureCellsToLocalsExploded(Frame frame, PCell[] closure) {
103+
protected void addClosureCellsToLocalsExploded(Frame frame, PCell[] frameClosure) {
84104
for (int i = 0; i < length; i++) {
85-
frame.setObject(freeVarSlots[i], closure[i]);
105+
frame.setObject(freeVarSlots[i], frameClosure[i]);
86106
}
87107
}
88108

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromDynamicObjectNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ protected Object readDirectFinal(DynamicObject dynamicObject, Object key,
122122
}, //
123123
assumptions = {
124124
"layoutAssumption"
125-
})
125+
}, //
126+
replaces = "readDirectFinal")
126127
protected Object readDirect(DynamicObject dynamicObject, Object key,
127128
@Cached("key") Object cachedKey,
128129
@Cached("attrKey(cachedKey)") Object attrKey,

0 commit comments

Comments
 (0)