105
105
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetBaseClassNodeGen ;
106
106
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetBaseClassesNodeGen ;
107
107
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetInstanceShapeNodeGen ;
108
+ import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetItemsizeNodeGen ;
108
109
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetMroStorageNodeGen ;
109
110
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetNameNodeGen ;
110
111
import com .oracle .graal .python .builtins .objects .type .TypeNodesFactory .GetSolidBaseNodeGen ;
128
129
import com .oracle .graal .python .nodes .truffle .PythonTypes ;
129
130
import com .oracle .graal .python .nodes .util .CastToJavaStringNode ;
130
131
import com .oracle .graal .python .runtime .PythonContext ;
132
+ import com .oracle .graal .python .runtime .PythonOptions ;
131
133
import com .oracle .graal .python .runtime .exception .PException ;
132
134
import com .oracle .graal .python .runtime .sequence .PSequence ;
133
135
import com .oracle .graal .python .runtime .sequence .storage .MroSequenceStorage ;
@@ -1498,26 +1500,33 @@ public static GetInstanceShape create() {
1498
1500
}
1499
1501
1500
1502
@ GenerateUncached
1503
+ @ ImportStatic (PythonOptions .class )
1501
1504
public abstract static class GetItemsizeNode extends Node {
1505
+ // We cannot easily use options here
1506
+ static final int MAX_RECURSION_DEPTH = 4 ;
1502
1507
1503
- public abstract Long execute (Object cls );
1508
+ public final long execute (Object cls ) {
1509
+ return execute (cls , 0 );
1510
+ }
1511
+
1512
+ public abstract long execute (Object cls , int depth );
1504
1513
1505
1514
@ Specialization
1506
- static Long getItemsizeType (PythonBuiltinClassType cls ) {
1515
+ static long getItemsizeType (PythonBuiltinClassType cls , @ SuppressWarnings ( "unused" ) int depth ) {
1507
1516
return getBuiltinTypeItemsize (cls );
1508
1517
}
1509
1518
1510
1519
@ Specialization
1511
- static Long getItemsizeManaged (PythonBuiltinClass cls ) {
1512
- return getItemsizeType (cls .getType ());
1520
+ static long getItemsizeManaged (PythonBuiltinClass cls , @ SuppressWarnings ( "unused" ) int depth ) {
1521
+ return getItemsizeType (cls .getType (), depth );
1513
1522
}
1514
1523
1515
- @ Specialization
1516
- static Long getItemsizeManaged (PythonClass cls ,
1517
- @ Cached ConditionProfile hasValueProfile ,
1518
- @ Cached ReadAttributeFromObjectNode readNode ,
1519
- @ Cached WriteAttributeToObjectNode writeNode ,
1520
- @ Cached GetBaseClassNode getBaseNode ,
1524
+ @ Specialization ( guards = "depth < MAX_RECURSION_DEPTH" )
1525
+ static long getItemsizeManagedRecursiveNode (PythonClass cls , @ SuppressWarnings ( "unused" ) int depth ,
1526
+ @ Shared ( "hasVal" ) @ Cached ConditionProfile hasValueProfile ,
1527
+ @ Shared ( "read" ) @ Cached ReadAttributeFromObjectNode readNode ,
1528
+ @ Shared ( "write" ) @ Cached WriteAttributeToObjectNode writeNode ,
1529
+ @ Shared ( "getBase" ) @ Cached GetBaseClassNode getBaseNode ,
1521
1530
@ Cached GetItemsizeNode baseItemsizeNode ) {
1522
1531
Object itemsize = readNode .execute (cls , TYPE_ITEMSIZE );
1523
1532
if (hasValueProfile .profile (itemsize != PNone .NO_VALUE )) {
@@ -1526,13 +1535,22 @@ static Long getItemsizeManaged(PythonClass cls,
1526
1535
1527
1536
Object base = getBaseNode .execute (cls );
1528
1537
assert base != null ;
1529
- itemsize = baseItemsizeNode .execute (base );
1538
+ itemsize = baseItemsizeNode .execute (base , depth + 1 );
1530
1539
writeNode .execute (cls , TYPE_ITEMSIZE , itemsize );
1531
1540
return (long ) itemsize ;
1532
1541
}
1533
1542
1543
+ @ Specialization (guards = "depth >= MAX_RECURSION_DEPTH" )
1544
+ static long getItemsizeManagedRecursiveCall (PythonClass cls , @ SuppressWarnings ("unused" ) int depth ,
1545
+ @ Shared ("hasVal" ) @ Cached ConditionProfile hasValueProfile ,
1546
+ @ Shared ("read" ) @ Cached ReadAttributeFromObjectNode readNode ,
1547
+ @ Shared ("write" ) @ Cached WriteAttributeToObjectNode writeNode ,
1548
+ @ Shared ("getBase" ) @ Cached GetBaseClassNode getBaseNode ) {
1549
+ return getItemsizeManagedRecursiveNode (cls , depth , hasValueProfile , readNode , writeNode , getBaseNode , GetItemsizeNodeGen .getUncached ());
1550
+ }
1551
+
1534
1552
@ Specialization
1535
- static Long getNative (PythonNativeClass cls ,
1553
+ static long getNative (PythonNativeClass cls , @ SuppressWarnings ( "unused" ) int depth ,
1536
1554
@ Cached GetTypeMemberNode getTpDictoffsetNode ) {
1537
1555
return (long ) getTpDictoffsetNode .execute (cls , NativeMember .TP_ITEMSIZE );
1538
1556
}
0 commit comments