Skip to content

Commit f701c51

Browse files
committed
Remove context field from Marshal objects
1 parent e5c2eb1 commit f701c51

8 files changed

Lines changed: 73 additions & 77 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ private static Object doLoadBytecodeFile(Object bytecodePath, Object sourcePath,
507507
try {
508508
// get_data
509509
TruffleString strBytecodePath = PyObjectStrAsTruffleStringNode.executeUncached(bytecodePath);
510-
TruffleFile bytecodeFile = context.getEnv().getPublicTruffleFile(strBytecodePath.toJavaStringUncached());
510+
TruffleFile bytecodeFile = context.getPublicTruffleFileRelaxed(strBytecodePath);
511511
byte[] bytes = bytecodeFile.readAllBytes();
512512
// _classify_pyc
513513
if (bytes.length < 16 || !Arrays.equals(bytes, 0, 4, MAGIC_NUMBER_BYTES, 0, 4)) {
@@ -569,7 +569,7 @@ private static Object doLoadBytecodeFile(Object bytecodePath, Object sourcePath,
569569
// Fall back to Marshal's empty source.
570570
}
571571
}
572-
return MarshalModuleBuiltins.fromBytecodeFile(context, bytecodeFile, sourceFile, bytes, 16, bytes.length - 16, cacheKey);
572+
return MarshalModuleBuiltins.fromBytecodeFile(context.getLanguage(), bytecodeFile, sourceFile, bytes, 16, bytes.length - 16, cacheKey);
573573
} catch (MarshalModuleBuiltins.Marshal.MarshalError me) {
574574
throw PRaiseNode.raiseStatic(inliningTarget, me.type, me.message, me.arguments);
575575
} catch (IOException | SecurityException | UnsupportedOperationException | IllegalArgumentException e) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ static Object run(TruffleString name, Object dataObj,
475475
Object code = null;
476476

477477
try {
478-
code = MarshalModuleBuiltins.Marshal.load(context, bytes, size, 0);
478+
code = MarshalModuleBuiltins.Marshal.load(context.getLanguage(), bytes, size, 0);
479479
} catch (MarshalError | NumberFormatException e) {
480480
raiseFrozenError(inliningTarget, raiseNode, FROZEN_INVALID, name);
481481
}
@@ -542,9 +542,10 @@ static Object run(TruffleString name, boolean withData,
542542

543543
PMemoryView data = null;
544544

545+
PythonLanguage language = context.getLanguage();
545546
if (withData) {
546-
byte[] bytes = MarshalModuleBuiltins.serializeCodeUnit(inliningTarget, context, info.code);
547-
data = PyMemoryViewFromObject.getUncached().execute(null, PFactory.createBytes(context.getLanguage(inliningTarget), bytes));
547+
byte[] bytes = MarshalModuleBuiltins.serializeCodeUnit(inliningTarget, language, info.code);
548+
data = PyMemoryViewFromObject.getUncached().execute(null, PFactory.createBytes(language, bytes));
548549
}
549550

550551
Object[] returnValues = new Object[]{
@@ -553,7 +554,7 @@ static Object run(TruffleString name, boolean withData,
553554
info.origName == null ? PNone.NONE : info.origName
554555
};
555556

556-
return PFactory.createTuple(context.getLanguage(inliningTarget), returnValues);
557+
return PFactory.createTuple(language, returnValues);
557558
}
558559
}
559560

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

Lines changed: 51 additions & 54 deletions
Large diffs are not rendered by default.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public PCode execute(VirtualFrame frame, int argcount,
9494
PythonLanguage language = context.getLanguage(this);
9595
Object state = BoundaryCallContext.enter(frame, language, context, boundaryCallData);
9696
try {
97-
return createCode(language, context, argcount,
97+
return createCode(language, argcount,
9898
posonlyargcount, kwonlyargcount, nlocals, stacksize, flags, codedata,
9999
constants, names, varnames, freevars, cellvars,
100100
filename, name, qualname, firstlineno, linetable);
@@ -104,7 +104,7 @@ public PCode execute(VirtualFrame frame, int argcount,
104104
}
105105

106106
@TruffleBoundary
107-
private static PCode createCode(PythonLanguage language, PythonContext context, int argCount,
107+
private static PCode createCode(PythonLanguage language, int argCount,
108108
int positionalOnlyArgCount, int kwOnlyArgCount,
109109
int nlocals, int stacksize, int flags,
110110
byte[] codedata, Object[] constants, TruffleString[] names,
@@ -140,22 +140,22 @@ private static PCode createCode(PythonLanguage language, PythonContext context,
140140
parameterNames,
141141
kwOnlyNames);
142142
} else {
143-
ct = deserializeForBytecodeInterpreter(context, codedata, cellvars, freevars, flags);
143+
ct = deserializeForBytecodeInterpreter(language, codedata, cellvars, freevars, flags);
144144
signature = ((PRootNode) ct.getRootNode()).getSignature();
145145
}
146146
return PFactory.createCode(language, ct, signature, nlocals, stacksize, flags, constants, names, varnames, freevars, cellvars, filename, name, qualname, firstlineno, linetable);
147147
}
148148

149-
private static RootCallTarget deserializeForBytecodeInterpreter(PythonContext context, byte[] data, TruffleString[] cellvars, TruffleString[] freevars, int flags) {
150-
CodeUnit codeUnit = MarshalModuleBuiltins.deserializeCodeUnit(null, context, data);
149+
private static RootCallTarget deserializeForBytecodeInterpreter(PythonLanguage language, byte[] data, TruffleString[] cellvars, TruffleString[] freevars, int flags) {
150+
CodeUnit codeUnit = MarshalModuleBuiltins.deserializeCodeUnit(null, language, data);
151151
RootNode rootNode;
152152

153153
if (PythonOptions.ENABLE_BYTECODE_DSL_INTERPRETER) {
154154
BytecodeDSLCodeUnit code = (BytecodeDSLCodeUnit) codeUnit;
155155
if (code.flags != flags) {
156156
code = code.withFlags(flags);
157157
}
158-
rootNode = code.createRootNode(context.getLanguage(), PythonUtils.createFakeSource());
158+
rootNode = code.createRootNode(language, PythonUtils.createFakeSource());
159159
} else {
160160
BytecodeCodeUnit code = (BytecodeCodeUnit) codeUnit;
161161
if (cellvars != null && !Arrays.equals(code.cellvars, cellvars) || freevars != null && !Arrays.equals(code.freevars, freevars) || flags != code.flags) {
@@ -167,9 +167,9 @@ private static RootCallTarget deserializeForBytecodeInterpreter(PythonContext co
167167
code.variableShouldUnbox,
168168
code.generalizeInputsKeys, code.generalizeInputsIndices, code.generalizeInputsValues, code.generalizeVarsIndices, code.generalizeVarsValues);
169169
}
170-
rootNode = PBytecodeRootNode.create(context.getLanguage(), code, PythonUtils.createFakeSource(), false);
170+
rootNode = PBytecodeRootNode.create(language, code, PythonUtils.createFakeSource(), false);
171171
if (code.isGeneratorOrCoroutine()) {
172-
rootNode = new PBytecodeGeneratorFunctionRootNode(context.getLanguage(), rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name);
172+
rootNode = new PBytecodeGeneratorFunctionRootNode(language, rootNode.getFrameDescriptor(), (PBytecodeRootNode) rootNode, code.name);
173173
}
174174
}
175175
return PythonUtils.getOrCreateCallTarget(rootNode);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
import com.oracle.graal.python.pegparser.sst.UnaryOpTy;
148148
import com.oracle.graal.python.pegparser.sst.WithItemTy;
149149
import com.oracle.graal.python.pegparser.tokenizer.SourceRange;
150-
import com.oracle.graal.python.runtime.PythonContext;
151150
import com.oracle.graal.python.util.PythonUtils;
152151
import com.oracle.truffle.api.CompilerDirectives;
153152
import com.oracle.truffle.api.bytecode.BytecodeConfig;
@@ -491,9 +490,9 @@ public PBytecodeDSLRootNode createRootNode(PythonLanguage language, Source sourc
491490
}
492491

493492
@Override
494-
public byte[] createSerializedBytecode(PythonContext context) {
493+
public byte[] createSerializedBytecode(PythonLanguage language) {
495494
try {
496-
BytecodeSerializer serializer = new MarshalModuleBuiltins.PBytecodeDSLSerializer(context);
495+
BytecodeSerializer serializer = new MarshalModuleBuiltins.PBytecodeDSLSerializer(language);
497496
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
498497
nodes.serialize(new DataOutputStream(bytes), serializer);
499498
return bytes.toByteArray();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6230,7 +6230,7 @@ protected byte[] extractCode(Node node) {
62306230
*
62316231
* TODO We should revisit this when the AST interpreter is removed.
62326232
*/
6233-
return MarshalModuleBuiltins.serializeCodeUnit(null, PythonContext.get(this), co);
6233+
return MarshalModuleBuiltins.serializeCodeUnit(null, getLanguage(), co);
62346234
}
62356235

62366236
@Override

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/BytecodeDSLCodeUnit.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
import com.oracle.graal.python.PythonLanguage;
4444
import com.oracle.graal.python.compiler.CodeUnit;
45-
import com.oracle.graal.python.runtime.PythonContext;
4645
import com.oracle.truffle.api.CompilerAsserts;
4746
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4847
import com.oracle.truffle.api.nodes.RootNode;
@@ -70,7 +69,7 @@ public BytecodeDSLCodeUnit(TruffleString name, TruffleString qualname, int argCo
7069
public abstract static class BytecodeSupplier {
7170
public abstract PBytecodeDSLRootNode createRootNode(PythonLanguage language, Source source);
7271

73-
public abstract byte[] createSerializedBytecode(PythonContext context);
72+
public abstract byte[] createSerializedBytecode(PythonLanguage language);
7473
}
7574

7675
public BytecodeDSLCodeUnit withFlags(int flags) {
@@ -89,9 +88,9 @@ public PBytecodeDSLRootNode createRootNode(PythonLanguage language, Source sourc
8988
return rootNode;
9089
}
9190

92-
public byte[] getSerialized(PythonContext context) {
91+
public byte[] getSerialized(PythonLanguage language) {
9392
CompilerAsserts.neverPartOfCompilation();
94-
return supplier.createSerializedBytecode(context);
93+
return supplier.createSerializedBytecode(language);
9594
}
9695

9796
public TruffleString getDocstring() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ public static int lastiToBci(int lasti, BytecodeNode bytecodeNode) {
10371037

10381038
@Override
10391039
protected byte[] extractCode(Node node) {
1040-
return MarshalModuleBuiltins.serializeCodeUnit(node, PythonContext.get(node), co);
1040+
return MarshalModuleBuiltins.serializeCodeUnit(node, getLanguage(), co);
10411041
}
10421042

10431043
private static Object checkUnboundCell(PCell cell, int index, BytecodeNode bytecodeNode) {

0 commit comments

Comments
 (0)