Skip to content

Commit aeae1d4

Browse files
committed
Add missing truffle boundaries
1 parent d41de62 commit aeae1d4

File tree

10 files changed

+93
-70
lines changed

10 files changed

+93
-70
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/PythonAbstractObject.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,6 @@ public Object getLazyPythonClass() {
602602
throw new AbstractMethodError(getClass().getCanonicalName());
603603
}
604604

605-
public Object getInternalLazyPythonClass() {
606-
CompilerDirectives.bailout("Abstract method");
607-
throw new AbstractMethodError(getClass().getCanonicalName());
608-
}
609-
610605
@ExportMessage
611606
public boolean isInstantiable(
612607
@Cached TypeNodes.IsTypeNode isTypeNode) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/DynamicObjectStorage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,12 @@ private static final class KeysIterator extends AbstractKeysIterator {
439439

440440
public KeysIterator(DynamicObject store, ReadAttributeFromDynamicObjectNode readNode) {
441441
super(store, readNode);
442-
this.keyIter = keyList(store.getShape()).iterator();
442+
this.keyIter = getIter(keyList(store.getShape()));
443+
}
444+
445+
@TruffleBoundary
446+
private static Iterator<Object> getIter(List<Object> keyList) {
447+
return keyList.iterator();
443448
}
444449

445450
@Override
@@ -494,7 +499,7 @@ public EntriesIterator(DynamicObject store, ReadAttributeFromDynamicObjectNode r
494499
this.store = store;
495500
this.readNode = readNode;
496501
this.state = 0;
497-
this.size = this.keyList.size();
502+
this.size = getListSize();
498503
}
499504

500505
public int getState() {
@@ -506,8 +511,8 @@ public void setState(int state) {
506511
}
507512

508513
@TruffleBoundary
509-
private static Iterator<Object> getList(Shape shape) {
510-
return keyList(shape).iterator();
514+
private int getListSize() {
515+
return this.keyList.size();
511516
}
512517

513518
@TruffleBoundary

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/EconomicMapStorage.java

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,32 @@ static HashingStorage setItemGeneric(EconomicMapStorage self, Object key, Object
282282
}
283283
}
284284

285+
@TruffleBoundary
286+
static boolean advance(MapCursor<DictKey, Object> cursor) {
287+
return cursor.advance();
288+
}
289+
290+
@TruffleBoundary
291+
static DictKey getDictKey(MapCursor<DictKey, Object> cursor) {
292+
return cursor.getKey();
293+
}
294+
295+
static Object getKey(MapCursor<DictKey, Object> cursor) {
296+
return getDictKey(cursor).value;
297+
}
298+
299+
@TruffleBoundary
300+
static Object getValue(MapCursor<DictKey, Object> cursor) {
301+
return cursor.getValue();
302+
}
303+
285304
@Override
286305
@ExportMessage
287306
Object forEachUntyped(ForEachNode<Object> node, Object arg) {
288307
Object result = arg;
289308
MapCursor<DictKey, Object> cursor = map.getEntries();
290-
while (cursor.advance()) {
291-
result = node.execute(cursor.getKey().value, result);
309+
while (advance(cursor)) {
310+
result = node.execute(getKey(cursor), result);
292311
}
293312
return result;
294313
}
@@ -325,8 +344,8 @@ static HashingStorage generic(EconomicMapStorage self, HashingStorage other,
325344
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
326345
HashingStorage result = other;
327346
MapCursor<DictKey, Object> cursor = self.map.getEntries();
328-
while (cursor.advance()) {
329-
result = lib.setItem(result, cursor.getKey().value, cursor.getValue());
347+
while (advance(cursor)) {
348+
result = lib.setItem(result, getKey(cursor), getValue(cursor));
330349
}
331350
return result;
332351
}
@@ -387,9 +406,9 @@ static HashingStorage clearWithSideEffect(EconomicMapStorage self,
387406
Object[] entries = new Object[self.map.size() * 2];
388407
MapCursor<DictKey, Object> cursor = self.map.getEntries();
389408
int i = 0;
390-
while (cursor.advance()) {
391-
Object key = cursor.getKey().value;
392-
Object value = cursor.getValue();
409+
while (advance(cursor)) {
410+
Object key = getKey(cursor);
411+
Object value = getValue(cursor);
393412
entries[i++] = hasSideEffect(key, lookup) ? key : null;
394413
entries[i++] = hasSideEffect(value, lookup) ? value : null;
395414
}
@@ -423,9 +442,9 @@ static boolean equalSameType(EconomicMapStorage self, EconomicMapStorage other,
423442
return false;
424443
}
425444
MapCursor<DictKey, Object> cursor = self.map.getEntries();
426-
while (cursor.advance()) {
427-
Object otherValue = other.map.get(cursor.getKey(), compareLib1, compareLib2, findProfile, gotState, state);
428-
if (otherValue != null && !compareLib1.equalsWithState(otherValue, cursor.getValue(), compareLib2, state)) {
445+
while (advance(cursor)) {
446+
Object otherValue = other.map.get(getDictKey(cursor), compareLib1, compareLib2, findProfile, gotState, state);
447+
if (otherValue != null && !compareLib1.equalsWithState(otherValue, getValue(cursor), compareLib2, state)) {
429448
return false;
430449
}
431450
}
@@ -443,9 +462,9 @@ static boolean equalGeneric(EconomicMapStorage self, HashingStorage other, Threa
443462
return false;
444463
}
445464
MapCursor<DictKey, Object> cursor = self.map.getEntries();
446-
while (cursor.advance()) {
447-
Object otherValue = selflib.getItemWithState(self, cursor.getKey().value, state);
448-
if (otherValue != null && !compareLib1.equalsWithState(otherValue, cursor.getValue(), compareLib2, state)) {
465+
while (advance(cursor)) {
466+
Object otherValue = selflib.getItemWithState(self, getKey(cursor), state);
467+
if (otherValue != null && !compareLib1.equalsWithState(otherValue, getValue(cursor), compareLib2, state)) {
449468
return false;
450469
}
451470
}
@@ -467,8 +486,8 @@ static int compareSameType(EconomicMapStorage self, EconomicMapStorage other, Th
467486
return 1;
468487
}
469488
MapCursor<DictKey, Object> cursor = self.map.getEntries();
470-
while (cursor.advance()) {
471-
if (!other.map.containsKey(cursor.getKey(), lib, lib, findProfile, gotState, state)) {
489+
while (advance(cursor)) {
490+
if (!other.map.containsKey(getDictKey(cursor), lib, lib, findProfile, gotState, state)) {
472491
return 1;
473492
}
474493
}
@@ -489,8 +508,8 @@ static int compareGeneric(EconomicMapStorage self, HashingStorage other, ThreadS
489508
return 1;
490509
}
491510
MapCursor<DictKey, Object> cursor = self.map.getEntries();
492-
while (cursor.advance()) {
493-
if (!lib.hasKeyWithState(other, cursor.getKey().value, state)) {
511+
while (advance(cursor)) {
512+
if (!lib.hasKeyWithState(other, getKey(cursor), state)) {
494513
return 1;
495514
}
496515
}
@@ -512,9 +531,9 @@ static HashingStorage intersectSameType(EconomicMapStorage self, EconomicMapStor
512531
@CachedLibrary(limit = "2") PythonObjectLibrary lib) {
513532
EconomicMapStorage result = EconomicMapStorage.create();
514533
MapCursor<DictKey, Object> cursor = self.map.getEntries();
515-
while (cursor.advance()) {
516-
if (other.map.containsKey(cursor.getKey(), lib, lib, findProfile, gotState, state)) {
517-
result.map.put(cursor.getKey(), cursor.getValue());
534+
while (advance(cursor)) {
535+
if (other.map.containsKey(getDictKey(cursor), lib, lib, findProfile, gotState, state)) {
536+
result.map.put(getDictKey(cursor), getValue(cursor));
518537
}
519538
}
520539
return result;
@@ -526,9 +545,9 @@ static HashingStorage intersectGeneric(EconomicMapStorage self, HashingStorage o
526545
@CachedLibrary("other") HashingStorageLibrary hlib) {
527546
EconomicMapStorage result = EconomicMapStorage.create();
528547
MapCursor<DictKey, Object> cursor = self.map.getEntries();
529-
while (cursor.advance()) {
530-
if (hlib.hasKey(other, cursor.getKey().value)) {
531-
result.map.put(cursor.getKey(), cursor.getValue());
548+
while (advance(cursor)) {
549+
if (hlib.hasKey(other, getKey(cursor))) {
550+
result.map.put(getDictKey(cursor), getValue(cursor));
532551
}
533552
}
534553
return result;
@@ -545,9 +564,9 @@ static HashingStorage diffSameType(EconomicMapStorage self, EconomicMapStorage o
545564
@CachedLibrary(limit = "2") PythonObjectLibrary lib) {
546565
EconomicMapStorage result = EconomicMapStorage.create();
547566
MapCursor<DictKey, Object> cursor = self.map.getEntries();
548-
while (cursor.advance()) {
549-
if (!other.map.containsKey(cursor.getKey(), lib, lib, findProfile, gotState, state)) {
550-
result.map.put(cursor.getKey(), cursor.getValue());
567+
while (advance(cursor)) {
568+
if (!other.map.containsKey(getDictKey(cursor), lib, lib, findProfile, gotState, state)) {
569+
result.map.put(getDictKey(cursor), getValue(cursor));
551570
}
552571
}
553572
return result;
@@ -559,9 +578,9 @@ static HashingStorage diffGeneric(EconomicMapStorage self, HashingStorage other,
559578
@CachedLibrary("other") HashingStorageLibrary hlib) {
560579
EconomicMapStorage result = EconomicMapStorage.create();
561580
MapCursor<DictKey, Object> cursor = self.map.getEntries();
562-
while (cursor.advance()) {
563-
if (!hlib.hasKey(other, cursor.getKey().value)) {
564-
result.map.put(cursor.getKey(), cursor.getValue());
581+
while (advance(cursor)) {
582+
if (!hlib.hasKey(other, getKey(cursor))) {
583+
result.map.put(getDictKey(cursor), getValue(cursor));
565584
}
566585
}
567586
return result;
@@ -607,9 +626,9 @@ public String toString() {
607626
builder.append("map(size=").append(length()).append(", {");
608627
String sep = "";
609628
MapCursor<DictKey, Object> cursor = map.getEntries();
610-
while (cursor.advance()) {
629+
while (advance(cursor)) {
611630
builder.append(sep);
612-
builder.append("(").append(cursor.getKey().value).append(",").append(cursor.getValue()).append(")");
631+
builder.append("(").append(getKey(cursor)).append(",").append(getValue(cursor)).append(")");
613632
sep = ",";
614633
}
615634
builder.append("})");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/PDictView.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
4747
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4848
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
49+
import com.oracle.truffle.api.CompilerDirectives;
4950
import com.oracle.truffle.api.object.Shape;
5051

5152
public abstract class PDictView extends PythonBuiltinObject {
@@ -120,9 +121,14 @@ public PDictItemIterator(Object clazz, Shape instanceShape, HashingStorageIterat
120121
super(clazz, instanceShape, iterator, hashingStorage, initialSize);
121122
}
122123

124+
@CompilerDirectives.TruffleBoundary
125+
private DictEntry nextVal() {
126+
return (DictEntry) super.next();
127+
}
128+
123129
@Override
124130
public Object next(PythonObjectFactory factory) {
125-
DictEntry value = (DictEntry) super.next();
131+
DictEntry value = nextVal();
126132
return factory.createTuple(new Object[]{value.getKey(), value.getValue()});
127133
}
128134
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ public Object next(PStringIterator self) {
184184
throw raise(StopIteration);
185185
}
186186

187+
@CompilerDirectives.TruffleBoundary
188+
private Object nextDictValue(PDictView.PBaseDictIterator<?> self) {
189+
return self.next(factory());
190+
}
191+
187192
@Specialization(guards = "!self.isExhausted()")
188193
public Object next(PDictView.PBaseDictIterator<?> self,
189194
@Cached ConditionProfile sizeChanged,
@@ -193,7 +198,7 @@ public Object next(PDictView.PBaseDictIterator<?> self,
193198
if (sizeChanged.profile(self.checkSizeChanged(storageLibrary))) {
194199
throw raise(RuntimeError, ErrorMessages.CHANGED_SIZE_DURING_ITERATION, "dictionary");
195200
}
196-
return self.next(factory());
201+
return nextDictValue(self);
197202
}
198203
self.setExhausted();
199204
throw raise(PythonErrorType.StopIteration);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/superobject/SuperObject.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
4444
import com.oracle.truffle.api.Assumption;
45+
import com.oracle.truffle.api.CompilerDirectives;
4546
import com.oracle.truffle.api.Truffle;
4647
import com.oracle.truffle.api.object.Shape;
4748

@@ -55,9 +56,14 @@ public SuperObject(Object cls, Shape instanceShape) {
5556
super(cls, instanceShape);
5657
}
5758

59+
@CompilerDirectives.TruffleBoundary
60+
private void invalidateAssumption() {
61+
neverReinitialized.invalidate();
62+
}
63+
5864
public void init(Object newType, Object newObjecttype, Object newObject) {
5965
if (this.type != null) {
60-
neverReinitialized.invalidate();
66+
invalidateAssumption();
6167
}
6268
this.type = newType;
6369
this.objecttype = newObjecttype;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PRootNode.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -43,6 +43,7 @@
4343
import com.oracle.graal.python.builtins.objects.function.Signature;
4444
import com.oracle.truffle.api.Assumption;
4545
import com.oracle.truffle.api.CompilerAsserts;
46+
import com.oracle.truffle.api.CompilerDirectives;
4647
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
4748
import com.oracle.truffle.api.Truffle;
4849
import com.oracle.truffle.api.TruffleLanguage;
@@ -131,18 +132,15 @@ public Node copy() {
131132

132133
public abstract Signature getSignature();
133134

134-
public final Assumption getDontNeedCallerFrame() {
135-
return dontNeedCallerFrame;
136-
}
135+
public abstract boolean isPythonInternal();
137136

138-
public final Assumption getDontNeedExceptionState() {
139-
return dontNeedExceptionState;
137+
@CompilerDirectives.TruffleBoundary
138+
private static boolean isPythonInternal(PRootNode rootNode) {
139+
return rootNode.isPythonInternal();
140140
}
141141

142-
public abstract boolean isPythonInternal();
143-
144142
public static boolean isPythonInternal(RootNode rootNode) {
145-
return rootNode instanceof PRootNode && ((PRootNode) rootNode).isPythonInternal();
143+
return rootNode instanceof PRootNode && isPythonInternal((PRootNode) rootNode);
146144
}
147145

148146
private static Assumption createCallerFrameAssumption() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/attributes/ReadAttributeFromObjectNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.oracle.graal.python.nodes.util.CannotCastException;
6363
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
6464
import com.oracle.graal.python.runtime.PythonOptions;
65+
import com.oracle.truffle.api.CompilerDirectives;
6566
import com.oracle.truffle.api.dsl.Cached;
6667
import com.oracle.truffle.api.dsl.Fallback;
6768
import com.oracle.truffle.api.dsl.GenerateUncached;
@@ -247,6 +248,7 @@ private static Object readNative(Object key, Object dict, HashingStorageLibrary
247248
return PNone.NO_VALUE;
248249
}
249250

251+
@CompilerDirectives.TruffleBoundary
250252
private static Object readAttributeUncached(Object object, Object key, boolean forceType) {
251253
if (object instanceof PythonObject) {
252254
PythonObject po = (PythonObject) object;

0 commit comments

Comments
 (0)