Skip to content

Commit 7dd4567

Browse files
committed
[GR-26173] Fix blacklist violations on JDK15
PullRequest: graalpython/1319
2 parents e1eaacd + 18b44da commit 7dd4567

File tree

21 files changed

+167
-203
lines changed

21 files changed

+167
-203
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/bytes/ByteArrayBuiltins.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
8686
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
8787
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
88+
import com.oracle.graal.python.util.PythonUtils;
8889
import com.oracle.truffle.api.dsl.Cached;
8990
import com.oracle.truffle.api.dsl.Fallback;
9091
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
@@ -317,13 +318,13 @@ public static Object repr(PByteArray self,
317318
SequenceStorage store = self.getSequenceStorage();
318319
byte[] bytes = getBytes.execute(store);
319320
int len = lenNode.execute(store);
320-
StringBuilder sb = BytesUtils.newStringBuilder();
321+
StringBuilder sb = PythonUtils.newStringBuilder();
321322
String typeName = getNameNode.execute(lib.getLazyPythonClass(self));
322-
BytesUtils.sbAppend(sb, typeName);
323-
BytesUtils.sbAppend(sb, '(');
323+
PythonUtils.append(sb, typeName);
324+
PythonUtils.append(sb, '(');
324325
BytesUtils.reprLoop(sb, bytes, len);
325-
BytesUtils.sbAppend(sb, ')');
326-
return BytesUtils.sbToString(sb);
326+
PythonUtils.append(sb, ')');
327+
return PythonUtils.sbToString(sb);
327328
}
328329
}
329330

@@ -725,9 +726,9 @@ public int alloc(PByteArray byteArray,
725726

726727
protected static Object commonReduce(int proto, byte[] bytes, int len, Object clazz, Object dict,
727728
PythonObjectFactory factory) {
728-
StringBuilder sb = BytesUtils.newStringBuilder();
729+
StringBuilder sb = PythonUtils.newStringBuilder();
729730
BytesUtils.repr(sb, bytes, len);
730-
String str = BytesUtils.sbToString(sb);
731+
String str = PythonUtils.sbToString(sb);
731732
Object contents;
732733
if (proto < 3) {
733734
contents = factory.createTuple(new Object[]{str, "latin-1"});

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
import com.oracle.graal.python.util.PythonUtils;
127127
import com.oracle.truffle.api.CompilerAsserts;
128128
import com.oracle.truffle.api.CompilerDirectives;
129+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
129130
import com.oracle.truffle.api.dsl.Cached;
130131
import com.oracle.truffle.api.dsl.CachedContext;
131132
import com.oracle.truffle.api.dsl.Fallback;
@@ -264,9 +265,9 @@ public static Object repr(PBytes self,
264265
SequenceStorage store = self.getSequenceStorage();
265266
byte[] bytes = getBytes.execute(store);
266267
int len = lenNode.execute(store);
267-
StringBuilder sb = BytesUtils.newStringBuilder();
268+
StringBuilder sb = PythonUtils.newStringBuilder();
268269
BytesUtils.reprLoop(sb, bytes, len);
269-
return BytesUtils.sbToString(sb);
270+
return PythonUtils.sbToString(sb);
270271
}
271272
}
272273

@@ -2021,6 +2022,7 @@ public static ExpectIntNode createExpectIntNode() {
20212022
}
20222023

20232024
@Override
2025+
@TruffleBoundary
20242026
protected List<byte[]> splitWhitespace(byte[] bytes, int len, int maxsplit) {
20252027
int i, j, maxcount = maxsplit;
20262028
List<byte[]> list = new ArrayList<>();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesUtils.java

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.oracle.graal.python.nodes.PRaiseNode;
4040
import com.oracle.graal.python.runtime.PythonCore;
4141
import com.oracle.graal.python.runtime.PythonParser.ParserErrorCallback;
42+
import com.oracle.graal.python.util.PythonUtils;
4243
import com.oracle.truffle.api.CompilerAsserts;
4344
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4445

@@ -340,31 +341,6 @@ public static byte[] fromStringAndEncoding(PythonCore core, String source, Strin
340341
}
341342
}
342343

343-
@TruffleBoundary
344-
public static StringBuilder newStringBuilder() {
345-
return new StringBuilder();
346-
}
347-
348-
@TruffleBoundary
349-
public static StringBuilder newStringBuilder(int capacity) {
350-
return new StringBuilder(capacity);
351-
}
352-
353-
@TruffleBoundary
354-
public static String sbToString(StringBuilder sb) {
355-
return sb.toString();
356-
}
357-
358-
@TruffleBoundary
359-
public static void sbAppend(StringBuilder sb, char c) {
360-
sb.append(c);
361-
}
362-
363-
@TruffleBoundary
364-
public static void sbAppend(StringBuilder sb, String s) {
365-
sb.append(s);
366-
}
367-
368344
@TruffleBoundary(allowInlining = true)
369345
public static Object doAsciiString(String str) {
370346
byte[] bytes = unicodeEscape(str);
@@ -377,18 +353,18 @@ public static Object doAsciiString(String str) {
377353
}
378354
boolean useDoubleQuotes = hasSingleQuote && !hasDoubleQuote;
379355
char quote = useDoubleQuotes ? '"' : '\'';
380-
StringBuilder sb = newStringBuilder(bytes.length + 2);
381-
sbAppend(sb, quote);
356+
StringBuilder sb = PythonUtils.newStringBuilder(bytes.length + 2);
357+
PythonUtils.append(sb, quote);
382358
for (int i = 0; i < bytes.length; i++) {
383359
char c = (char) bytes[i];
384360
if (c == '\'' && !useDoubleQuotes) {
385-
sbAppend(sb, "\\'");
361+
PythonUtils.append(sb, "\\'");
386362
} else {
387-
sbAppend(sb, c);
363+
PythonUtils.append(sb, c);
388364
}
389365
}
390-
sbAppend(sb, quote);
391-
return sbToString(sb);
366+
PythonUtils.append(sb, quote);
367+
return PythonUtils.sbToString(sb);
392368
}
393369

394370
@TruffleBoundary(allowInlining = true)
@@ -407,32 +383,32 @@ public static char figureOutQuote(byte[] bytes, int len) {
407383

408384
public static void reprLoop(StringBuilder sb, byte[] bytes, int len) {
409385
char quote = figureOutQuote(bytes, len);
410-
sbAppend(sb, 'b');
411-
sbAppend(sb, quote);
386+
PythonUtils.append(sb, 'b');
387+
PythonUtils.append(sb, quote);
412388
for (int i = 0; i < len; i++) {
413389
byteRepr(sb, bytes[i], quote == '\'');
414390
}
415-
sbAppend(sb, quote);
391+
PythonUtils.append(sb, quote);
416392
}
417393

418394
@TruffleBoundary
419395
private static void byteRepr(StringBuilder sb, byte b, boolean isSingleQuote) {
420396
if (b == '\t') {
421-
sbAppend(sb, "\\t");
397+
PythonUtils.append(sb, "\\t");
422398
} else if (b == '\n') {
423-
sbAppend(sb, "\\n");
399+
PythonUtils.append(sb, "\\n");
424400
} else if (b == '\r') {
425-
sbAppend(sb, "\\r");
401+
PythonUtils.append(sb, "\\r");
426402
} else if (b == '\'') {
427-
sbAppend(sb, isSingleQuote ? "\\'" : "\'");
403+
PythonUtils.append(sb, isSingleQuote ? "\\'" : "\'");
428404
} else if (b > 31 && b <= 126) {
429405
char chr = (char) b;
430406
if (chr == '\\') {
431-
sbAppend(sb, '\\');
407+
PythonUtils.append(sb, '\\');
432408
}
433-
sbAppend(sb, chr);
409+
PythonUtils.append(sb, chr);
434410
} else {
435-
sbAppend(sb, String.format("\\x%02x", b));
411+
PythonUtils.append(sb, String.format("\\x%02x", b));
436412
}
437413
}
438414

@@ -449,11 +425,11 @@ public static String bytesRepr(byte[] bytes, int length) {
449425
len = bytes.length;
450426
}
451427

452-
StringBuilder sb = newStringBuilder();
453-
sbAppend(sb, "b'");
428+
StringBuilder sb = PythonUtils.newStringBuilder();
429+
PythonUtils.append(sb, "b'");
454430
repr(sb, bytes, len);
455-
sbAppend(sb, "'");
456-
return sbToString(sb);
431+
PythonUtils.append(sb, "'");
432+
return PythonUtils.sbToString(sb);
457433
}
458434

459435
@TruffleBoundary(transferToInterpreterOnException = false)

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/common/PEMap.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5050
import com.oracle.graal.python.util.BiFunction;
5151
import com.oracle.graal.python.util.PythonUtils;
52+
import com.oracle.truffle.api.CompilerAsserts;
5253
import com.oracle.truffle.api.CompilerDirectives;
5354
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
5455
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -801,6 +802,7 @@ private Object getValue(int index) {
801802

802803
@Override
803804
public String toString() {
805+
CompilerAsserts.neverPartOfCompilation();
804806
StringBuilder builder = new StringBuilder();
805807
builder.append(isSet ? "set(size=" : "map(size=").append(size()).append(", {");
806808
String sep = "";

0 commit comments

Comments
 (0)