Skip to content

Commit d0a6392

Browse files
committed
Fix virtual invokes in marshal module and code object
1 parent 79c2531 commit d0a6392

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7474
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
7575
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
76+
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
7677
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
7778
import com.oracle.graal.python.runtime.PythonContext;
7879
import com.oracle.graal.python.runtime.exception.PException;
@@ -248,6 +249,7 @@ abstract static class MarshallerNode extends PNodeWithState {
248249

249250
public abstract void execute(VirtualFrame frame, Object x, int version, DataOutputStream buffer);
250251

252+
@Child private CastToJavaStringNode castStrNode;
251253
@Child private MarshallerNode recursiveNode;
252254
private int depth = 0;
253255
private IsBuiltinClassProfile isBuiltinProfile;
@@ -476,12 +478,16 @@ private PTuple internStrings(Object[] values) {
476478
} else {
477479
interned = new Object[values.length];
478480
for (int i = 0; i < interned.length; i++) {
479-
if (values[i] instanceof String) {
480-
interned[i] = new InternedString((String) values[i]);
481-
} else if (values[i] instanceof PString) {
482-
interned[i] = new InternedString(((PString) values[i]).getValue());
481+
if (castStrNode == null) {
482+
CompilerDirectives.transferToInterpreterAndInvalidate();
483+
castStrNode = insert(CastToJavaStringNode.create());
484+
}
485+
Object value = values[i];
486+
String strValue = castStrNode.execute(value);
487+
if (strValue != null) {
488+
interned[i] = new InternedString(strValue);
483489
} else {
484-
interned[i] = values[i];
490+
interned[i] = value;
485491
}
486492
}
487493
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/code/PCode.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
import com.oracle.graal.python.nodes.function.GeneratorExpressionNode;
6565
import com.oracle.graal.python.nodes.generator.GeneratorFunctionRootNode;
6666
import com.oracle.graal.python.nodes.literal.SimpleLiteralNode;
67-
import com.oracle.truffle.api.CompilerDirectives;
6867
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
6968
import com.oracle.truffle.api.RootCallTarget;
7069
import com.oracle.truffle.api.interop.UnsupportedMessageException;
@@ -173,16 +172,10 @@ private static String[] extractCellVars(RootNode rootNode) {
173172
}
174173
}
175174

175+
@TruffleBoundary
176176
private static String extractFileName(RootNode rootNode) {
177177
RootNode funcRootNode = rootNodeForExtraction(rootNode);
178-
SourceSection src;
179-
if (funcRootNode instanceof PRootNode) {
180-
src = ((PRootNode) funcRootNode).getSourceSection();
181-
} else {
182-
// foreign root nodes might consider getting the source section slow-path
183-
CompilerDirectives.transferToInterpreter();
184-
src = funcRootNode.getSourceSection();
185-
}
178+
SourceSection src = funcRootNode.getSourceSection();
186179
if (src != null) {
187180
if (src.getSource().getPath() == null) {
188181
return src.getSource().getName();
@@ -205,10 +198,12 @@ private static int extractFirstLineno(RootNode rootNode) {
205198
return 1;
206199
}
207200

201+
@TruffleBoundary
208202
private static String extractName(RootNode rootNode) {
209203
return rootNode.getName();
210204
}
211205

206+
@TruffleBoundary
212207
private static int extractStackSize(RootNode rootNode) {
213208
return rootNode.getFrameDescriptor().getSize();
214209
}
@@ -477,20 +472,9 @@ public SourceSection getSourceLocation() throws UnsupportedMessageException {
477472
}
478473
}
479474

480-
private SourceSection readSourceLocation() {
481-
RootNode rootNode = getRootNode();
482-
SourceSection result;
483-
if (rootNode instanceof PRootNode) {
484-
result = ((PRootNode) rootNode).getSourceSection();
485-
} else {
486-
result = getForeignSourceSection(rootNode);
487-
}
488-
return result;
489-
}
490-
491475
@TruffleBoundary
492-
private static SourceSection getForeignSourceSection(RootNode rootNode) {
493-
return rootNode.getSourceSection();
476+
private SourceSection readSourceLocation() {
477+
return getRootNode().getSourceSection();
494478
}
495479

496480
@ExportMessage

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaStringNode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ static boolean isMaterialized(PString x) {
109109
return x.getCharSequence() instanceof String;
110110
}
111111

112+
public static CastToJavaStringNode create() {
113+
return CastToJavaStringNodeGen.create();
114+
}
115+
112116
public static CastToJavaStringNode getUncached() {
113117
return CastToJavaStringNodeGen.getUncached();
114118
}

0 commit comments

Comments
 (0)