Skip to content

Commit a767343

Browse files
committed
retain a strong root to a class' final storage shape
1 parent e97b957 commit a767343

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public DynamicObjectStorage(DynamicObject store, MroSequenceStorage mro) {
109109
this.mro = mro;
110110
}
111111

112+
public Shape getStoreShape() {
113+
return store.getShape();
114+
}
115+
112116
protected static Object[] keyArray(DynamicObjectStorage self) {
113117
return DynamicObjectStorage.keyArray(self.store.getShape());
114118
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/ClassBodyRootNode.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@
4141
package com.oracle.graal.python.nodes.function;
4242

4343
import com.oracle.graal.python.PythonLanguage;
44+
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
45+
import com.oracle.graal.python.builtins.objects.dict.PDict;
46+
import com.oracle.graal.python.builtins.objects.function.PArguments;
4447
import com.oracle.graal.python.builtins.objects.function.Signature;
4548
import com.oracle.graal.python.nodes.expression.ExpressionNode;
4649
import com.oracle.graal.python.parser.ExecutionCellSlots;
4750
import com.oracle.graal.python.util.PythonUtils;
51+
import com.oracle.truffle.api.CompilerDirectives;
52+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
4853
import com.oracle.truffle.api.frame.FrameDescriptor;
54+
import com.oracle.truffle.api.frame.VirtualFrame;
4955
import com.oracle.truffle.api.source.SourceSection;
5056

5157
public class ClassBodyRootNode extends FunctionRootNode {
@@ -54,4 +60,30 @@ public class ClassBodyRootNode extends FunctionRootNode {
5460
public ClassBodyRootNode(PythonLanguage language, SourceSection sourceSection, String functionName, FrameDescriptor frameDescriptor, ExpressionNode body, ExecutionCellSlots executionCellSlots) {
5561
super(language, sourceSection, functionName, false, false, frameDescriptor, body, executionCellSlots, SIGNATURE, null);
5662
}
63+
64+
/**
65+
* Used to keep the shape hierarchy of the objects created in this class body alive.
66+
*/
67+
@CompilationFinal private Object cachedShape;
68+
69+
private static final Object NO_CACHED_SHAPE = "<none>";
70+
71+
@Override
72+
public Object execute(VirtualFrame frame) {
73+
try {
74+
return super.execute(frame);
75+
} finally {
76+
if (cachedShape == null) {
77+
CompilerDirectives.transferToInterpreterAndInvalidate();
78+
cachedShape = NO_CACHED_SHAPE;
79+
Object arg = PArguments.getArgument(frame, 0);
80+
if (arg instanceof PDict) {
81+
Object storage = ((PDict) arg).getDictStorage();
82+
if (storage instanceof DynamicObjectStorage) {
83+
cachedShape = ((DynamicObjectStorage) storage).getStoreShape();
84+
}
85+
}
86+
}
87+
}
88+
}
5789
}

0 commit comments

Comments
 (0)