|
64 | 64 | import static com.oracle.graal.python.builtins.objects.type.TypeFlags.HEAPTYPE; |
65 | 65 | import static com.oracle.graal.python.builtins.objects.type.TypeFlags.IS_ABSTRACT; |
66 | 66 | import static com.oracle.graal.python.builtins.objects.type.TypeFlags.MANAGED_DICT; |
| 67 | +import static com.oracle.graal.python.builtins.objects.type.TypeFlags.MANAGED_WEAKREF; |
67 | 68 | import static com.oracle.graal.python.builtins.objects.type.TypeFlags.MATCH_SELF; |
68 | 69 | import static com.oracle.graal.python.builtins.objects.type.TypeFlags.READY; |
69 | 70 | import static com.oracle.graal.python.builtins.objects.type.TypeFlags.SUBCLASS_FLAGS; |
|
100 | 101 | import com.oracle.graal.python.builtins.Python3Core; |
101 | 102 | import com.oracle.graal.python.builtins.PythonBuiltinClassType; |
102 | 103 | import com.oracle.graal.python.builtins.modules.WarningsModuleBuiltins; |
103 | | -import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltins.GetWeakRefsNode; |
| 104 | +import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltins.GetWeakRefDescriptorNode; |
104 | 105 | import com.oracle.graal.python.builtins.modules.WeakRefModuleBuiltinsFactory; |
105 | 106 | import com.oracle.graal.python.builtins.modules.cext.PythonCextTypeBuiltins; |
106 | 107 | import com.oracle.graal.python.builtins.objects.PNone; |
|
255 | 256 | public abstract class TypeNodes { |
256 | 257 |
|
257 | 258 | private static final int SIZEOF_PY_OBJECT_PTR = Long.BYTES; |
| 259 | + private static final long MANAGED_WEAKREF_OFFSET = -4L * SIZEOF_PY_OBJECT_PTR; |
258 | 260 |
|
259 | 261 | @GenerateUncached |
260 | 262 | @GenerateInline(false) // footprint reduction 40 -> 21 |
@@ -2212,9 +2214,9 @@ private static void addDictDescrAttribute(PythonAbstractClass[] basesArray, Pyth |
2212 | 2214 | @TruffleBoundary |
2213 | 2215 | private static void addWeakrefDescrAttribute(PythonClass pythonClass, PythonLanguage language) { |
2214 | 2216 | if (LookupAttributeInMRONode.lookupSlowPath(pythonClass, T___WEAKREF__) == PNone.NO_VALUE) { |
2215 | | - Builtin builtin = GetWeakRefsNode.class.getAnnotation(Builtin.class); |
| 2217 | + Builtin builtin = GetWeakRefDescriptorNode.class.getAnnotation(Builtin.class); |
2216 | 2218 | BuiltinFunctionRootNode rootNode = PythonLanguage.get(null).createCachedRootNode( |
2217 | | - l -> new BuiltinFunctionRootNode(l, builtin, WeakRefModuleBuiltinsFactory.GetWeakRefsNodeFactory.getInstance(), true), GetWeakRefsNode.class); |
| 2219 | + l -> new BuiltinFunctionRootNode(l, builtin, WeakRefModuleBuiltinsFactory.GetWeakRefDescriptorNodeFactory.getInstance(), true), GetWeakRefDescriptorNode.class); |
2218 | 2220 | setAttribute(T___WEAKREF__, builtin, rootNode, pythonClass, language); |
2219 | 2221 | } |
2220 | 2222 | } |
@@ -2284,7 +2286,12 @@ private static void addNativeSlots(TypeNewContext ctx, PythonManagedClass python |
2284 | 2286 | dictOffset = -1; |
2285 | 2287 | } |
2286 | 2288 | if (ctx.addWeak) { |
2287 | | - weakListOffset = slotOffset; |
| 2289 | + // The weakref pointer lives in the preheader, not after the instance slots. |
| 2290 | + weakListOffset = MANAGED_WEAKREF_OFFSET; |
| 2291 | + } |
| 2292 | + if (weakListOffset == MANAGED_WEAKREF_OFFSET) { |
| 2293 | + long flags = GetTypeFlagsNode.executeUncached(pythonClass); |
| 2294 | + SetTypeFlagsNode.executeUncached(pythonClass, flags | MANAGED_WEAKREF); |
2288 | 2295 | } |
2289 | 2296 |
|
2290 | 2297 | SetDictOffsetNode.executeUncached(pythonClass, dictOffset); |
|
0 commit comments