|
81 | 81 | import com.oracle.graal.python.builtins.objects.bytes.BytesNodes.BytesFromObject; |
82 | 82 | import com.oracle.graal.python.builtins.objects.bytes.PBytes; |
83 | 83 | import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject; |
| 84 | +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes; |
84 | 85 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromNativeSubclassNode; |
85 | 86 | import com.oracle.graal.python.builtins.objects.common.FormatNodeBase; |
86 | 87 | import com.oracle.graal.python.builtins.objects.floats.PFloat; |
|
167 | 168 | import com.oracle.truffle.api.library.CachedLibrary; |
168 | 169 | import com.oracle.truffle.api.nodes.Node; |
169 | 170 | import com.oracle.truffle.api.nodes.UnexpectedResultException; |
| 171 | +import com.oracle.truffle.api.object.Shape; |
170 | 172 | import com.oracle.truffle.api.profiles.InlinedBranchProfile; |
171 | 173 | import com.oracle.truffle.api.profiles.InlinedConditionProfile; |
172 | 174 | import com.oracle.truffle.api.profiles.InlinedIntValueProfile; |
@@ -207,42 +209,47 @@ static Object doGeneric(VirtualFrame frame, Object cls, Object x, Object baseObj |
207 | 209 | @Bind Node inliningTarget, |
208 | 210 | @Cached IntNodeInnerNode innerNode, |
209 | 211 | @Cached IsBuiltinClassExactProfile isPrimitiveIntProfile, |
| 212 | + @Cached TypeNodes.NeedsNativeAllocationNode needsNativeAllocationNode, |
| 213 | + @Cached TypeNodes.GetInstanceShape getInstanceShape, |
210 | 214 | @Cached CreateIntSubclassNode createIntSubclassNode) { |
211 | 215 | Object result = innerNode.execute(frame, inliningTarget, x, baseObj); |
212 | 216 | if (isPrimitiveIntProfile.profileClass(inliningTarget, cls, PythonBuiltinClassType.PInt)) { |
213 | 217 | return result; |
214 | 218 | } else { |
215 | | - return createIntSubclassNode.execute(inliningTarget, cls, result); |
| 219 | + assert IsSubtypeNode.getUncached().execute(cls, PythonBuiltinClassType.PInt); |
| 220 | + PInt managedInt = createIntSubclassNode.execute(inliningTarget, cls, result, getInstanceShape.execute(cls)); |
| 221 | + if (needsNativeAllocationNode.execute(inliningTarget, cls)) { |
| 222 | + // needsNativeAllocationNode acts as branch profile |
| 223 | + return CExtNodes.allocateNativePart(inliningTarget, cls, managedInt); |
| 224 | + } else { |
| 225 | + return managedInt; |
| 226 | + } |
216 | 227 | } |
217 | 228 | } |
218 | 229 |
|
219 | 230 | @GenerateInline |
220 | 231 | @GenerateCached(false) |
221 | 232 | abstract static class CreateIntSubclassNode extends Node { |
222 | | - public abstract Object execute(Node inliningTarget, Object cls, Object intObj); |
| 233 | + public abstract PInt execute(Node inliningTarget, Object cls, Object intObj, Shape shape); |
223 | 234 |
|
224 | 235 | @Specialization |
225 | | - static Object doSubclass(Object cls, int value, |
226 | | - @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) { |
227 | | - return PFactory.createInt(cls, getInstanceShape.execute(cls), value); |
| 236 | + static PInt doManagedSubclass(Object cls, int value, Shape shape) { |
| 237 | + return PFactory.createInt(cls, shape, value); |
228 | 238 | } |
229 | 239 |
|
230 | 240 | @Specialization |
231 | | - static Object doSubclass(Object cls, long value, |
232 | | - @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) { |
233 | | - return PFactory.createInt(cls, getInstanceShape.execute(cls), value); |
| 241 | + static PInt doManagedSubclass(Object cls, long value, Shape shape) { |
| 242 | + return PFactory.createInt(cls, shape, value); |
234 | 243 | } |
235 | 244 |
|
236 | 245 | @Specialization |
237 | | - static Object doSubclass(Object cls, boolean value, |
238 | | - @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) { |
239 | | - return PFactory.createInt(cls, getInstanceShape.execute(cls), PInt.intValue(value)); |
| 246 | + static PInt doManagedSubclass(Object cls, boolean value, Shape shape) { |
| 247 | + return PFactory.createInt(cls, shape, PInt.intValue(value)); |
240 | 248 | } |
241 | 249 |
|
242 | 250 | @Specialization |
243 | | - static Object doSubclass(Object cls, PInt value, |
244 | | - @Shared @Cached TypeNodes.GetInstanceShape getInstanceShape) { |
245 | | - return PFactory.createInt(cls, getInstanceShape.execute(cls), value.getValue()); |
| 251 | + static PInt doManagedSubclass(Object cls, PInt value, Shape shape) { |
| 252 | + return PFactory.createInt(cls, shape, value.getValue()); |
246 | 253 | } |
247 | 254 | } |
248 | 255 |
|
|
0 commit comments