Skip to content

Commit 5022d2d

Browse files
committed
don't create PJSONScanner/PJSONEncoder on fast path
1 parent 00785fa commit 5022d2d

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONModuleBuiltins.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
278278
}
279279

280280
@Specialization
281+
@TruffleBoundary
281282
protected PJSONEncoder doNew(Object cls, Object markers, Object defaultFn, Object encoder, Object indent, String keySeparator, String itemSeparator, boolean sortKeys, boolean skipKeys,
282283
boolean allowNan,
283284
@Cached PythonObjectFactory factory) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/PJSONEncoder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.IdentityHashMap;
4444

4545
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
46+
import com.oracle.truffle.api.CompilerAsserts;
4647
import com.oracle.truffle.api.object.Shape;
4748

4849
public final class PJSONEncoder extends PythonBuiltinObject {
@@ -69,6 +70,7 @@ public enum FastEncode {
6970
public PJSONEncoder(Object cls, Shape instanceShape, Object markers, Object defaultFn, Object encoder, Object indent, String keySeparator, String itemSeparator, boolean sortKeys, boolean skipKeys,
7071
boolean allowNan, FastEncode fastEncode) {
7172
super(cls, instanceShape);
73+
CompilerAsserts.neverPartOfCompilation();
7274
this.markers = markers;
7375
this.defaultFn = defaultFn;
7476
this.encoder = encoder;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/PJSONScanner.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.HashMap;
4444

4545
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
46+
import com.oracle.truffle.api.CompilerAsserts;
4647
import com.oracle.truffle.api.object.Shape;
4748

4849
public final class PJSONScanner extends PythonBuiltinObject {
@@ -57,6 +58,7 @@ public final class PJSONScanner extends PythonBuiltinObject {
5758

5859
public PJSONScanner(Object cls, Shape instanceShape, boolean strict, Object objectHook, Object objectPairsHook, Object parseFloat, Object parseInt, Object parseConstant) {
5960
super(cls, instanceShape);
61+
CompilerAsserts.neverPartOfCompilation();
6062
this.memo = new HashMap<>();
6163
this.strict = strict;
6264
this.objectHook = objectHook;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
import com.oracle.graal.python.util.OverflowException;
164164
import com.oracle.graal.python.util.PythonUtils;
165165
import com.oracle.truffle.api.Assumption;
166+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
166167
import com.oracle.truffle.api.RootCallTarget;
167168
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
168169
import com.oracle.truffle.api.dsl.Cached;
@@ -1096,11 +1097,14 @@ public final PProperty createProperty(Object cls) {
10961097
}
10971098

10981099
// JSON
1100+
// (not created on fast path, thus TruffleBoundary)
10991101

1102+
@TruffleBoundary
11001103
public final PJSONScanner createJSONScanner(Object clazz, boolean strict, Object objectHook, Object objectPairsHook, Object parseFloat, Object parseInt, Object parseConstant) {
11011104
return trace(new PJSONScanner(clazz, getShape(clazz), strict, objectHook, objectPairsHook, parseFloat, parseInt, parseConstant));
11021105
}
11031106

1107+
@TruffleBoundary
11041108
public final PJSONEncoder createJSONEncoder(Object clazz, Object markers, Object defaultFn, Object encoder, Object indent, String keySeparator, String itemSeparator, boolean sortKeys,
11051109
boolean skipKeys, boolean allowNan, FastEncode fastEncode) {
11061110
return trace(new PJSONEncoder(clazz, getShape(clazz), markers, defaultFn, encoder, indent, keySeparator, itemSeparator, sortKeys, skipKeys, allowNan, fastEncode));

0 commit comments

Comments
 (0)