Skip to content

Commit ac322b6

Browse files
committed
put instances of String construction behind TruffleBoundary
1 parent 4fb55ed commit ac322b6

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -907,12 +907,7 @@ Object floatFromString(VirtualFrame frame, Object cls, String arg) {
907907
}
908908

909909
private double convertBytesToDouble(VirtualFrame frame, PBytesLike arg) {
910-
return convertStringToDouble(frame, createString(getByteArray(frame, arg)), arg);
911-
}
912-
913-
@TruffleBoundary
914-
private static String createString(byte[] bytes) {
915-
return new String(bytes);
910+
return convertStringToDouble(frame, PythonUtils.newString(getByteArray(frame, arg)), arg);
916911
}
917912

918913
private double convertStringToDouble(VirtualFrame frame, String src, Object origObj) {
@@ -995,7 +990,7 @@ static boolean isHandledType(PythonObjectLibrary lib, Object o) {
995990
return convertBytesToDouble(frame, (PBytesLike) obj);
996991
} else if (lib.isBuffer(obj)) {
997992
try {
998-
return convertStringToDouble(frame, createString(lib.getBufferBytes(obj)), obj);
993+
return convertStringToDouble(frame, PythonUtils.newString(lib.getBufferBytes(obj)), obj);
999994
} catch (UnsupportedMessageException e) {
1000995
CompilerDirectives.transferToInterpreterAndInvalidate();
1001996
throw new IllegalStateException("Object claims to be a buffer but does not support getBufferBytes()");

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,12 +1716,7 @@ public Object asciiGeneric(VirtualFrame frame, Object obj,
17161716
@Cached ReprNode reprNode) {
17171717
String repr = (String) reprNode.call(frame, obj);
17181718
byte[] bytes = BytesUtils.unicodeEscape(repr);
1719-
return newString(bytes);
1720-
}
1721-
1722-
@TruffleBoundary
1723-
private static String newString(byte[] bytes) {
1724-
return new String(bytes);
1719+
return PythonUtils.newString(bytes);
17251720
}
17261721
}
17271722

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,7 @@ Object doIt(Object self, String className) {
28342834
@TypeSystemReference(PythonTypes.class)
28352835
public abstract static class PyTruffle_Type_Modified extends PythonTernaryBuiltinNode {
28362836

2837+
@TruffleBoundary
28372838
@Specialization(guards = {"isNativeClass(clazz)", "isNoValue(mroTuple)"})
28382839
Object doIt(Object clazz, String name, @SuppressWarnings("unused") PNone mroTuple) {
28392840
CyclicAssumption nativeClassStableAssumption = getContext().getNativeClassStableAssumption((PythonNativeClass) clazz, false);
@@ -2843,6 +2844,7 @@ Object doIt(Object clazz, String name, @SuppressWarnings("unused") PNone mroTupl
28432844
return PNone.NONE;
28442845
}
28452846

2847+
@TruffleBoundary
28462848
@Specialization(guards = "isNativeClass(clazz)")
28472849
Object doIt(Object clazz, String name, PTuple mroTuple,
28482850
@Cached("createClassProfile()") ValueProfile profile) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
import com.oracle.truffle.api.CompilerDirectives;
140140
import com.oracle.truffle.api.TruffleLanguage.ContextReference;
141141
import com.oracle.truffle.api.TruffleLogger;
142+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
142143
import com.oracle.truffle.api.dsl.Cached;
143144
import com.oracle.truffle.api.dsl.Cached.Exclusive;
144145
import com.oracle.truffle.api.dsl.Cached.Shared;
@@ -2777,6 +2778,7 @@ protected Object doSlowPath(Object obj, NativeMember memberName) {
27772778
return getUncachedForMember(memberName).execute(PCallCapiFunction.getUncached().call(getterFuncName, ToSulongNode.getUncached().execute(obj)));
27782779
}
27792780

2781+
@TruffleBoundary
27802782
protected String getterFuncName(NativeMember memberName) {
27812783
String name = "get_" + memberName.getMemberName();
27822784
assert NativeCAPISymbols.isValid(name) : "invalid native member getter function " + name;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public PCode getCode() {
150150
return code;
151151
}
152152

153+
@TruffleBoundary
153154
public void setCode(PCode code) {
154155
codeStableAssumption.invalidate("code changed for function " + getName());
155156
assert code != null : "code cannot be null";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ static String doStringString(String self, String table) {
959959
translatedChars[i] = translation;
960960
}
961961

962-
return new String(translatedChars);
962+
return PythonUtils.newString(translatedChars);
963963
}
964964

965965
@Specialization
@@ -1723,7 +1723,7 @@ String doCharInt(String left, int right) {
17231723
try {
17241724
char[] result = new char[right];
17251725
Arrays.fill(result, left.charAt(0));
1726-
return new String(result);
1726+
return PythonUtils.newString(result);
17271727
} catch (OutOfMemoryError e) {
17281728
throw raise(MemoryError);
17291729
}
@@ -1790,7 +1790,7 @@ private String repeatString(String left, int times, LoopConditionProfile loopPro
17901790
PythonUtils.arraycopy(result, 0, result, done, len);
17911791
done += len;
17921792
}
1793-
return new String(result);
1793+
return PythonUtils.newString(result);
17941794
} catch (OutOfMemoryError e) {
17951795
throw raise(MemoryError);
17961796
}
@@ -2151,7 +2151,7 @@ private static String zfill(String self, int width) {
21512151
chars[i] = '0';
21522152
}
21532153
self.getChars(sStart, len, chars, i);
2154-
return new String(chars);
2154+
return PythonUtils.newString(chars);
21552155
}
21562156
}
21572157

@@ -2308,7 +2308,7 @@ public String doString(String primary, PSlice slice,
23082308
newChars[j++] = primary.charAt(i);
23092309
}
23102310

2311-
return new String(newChars);
2311+
return PythonUtils.newString(newChars);
23122312
}
23132313
}
23142314

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/util/PythonUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ public static RootCallTarget getOrCreateCallTarget(RootNode rootNode) {
150150
return ct;
151151
}
152152

153+
@TruffleBoundary(allowInlining = true)
154+
public static String newString(byte[] bytes) {
155+
return new String(bytes);
156+
}
157+
153158
@TruffleBoundary(allowInlining = true)
154159
public static String newString(char[] chars) {
155160
return new String(chars);

0 commit comments

Comments
 (0)