|
42 | 42 | import com.oracle.graal.python.runtime.PythonOptions;
|
43 | 43 | import com.oracle.truffle.api.CompilerAsserts;
|
44 | 44 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
| 45 | +import com.oracle.truffle.api.dsl.Bind; |
45 | 46 | import com.oracle.truffle.api.dsl.Cached;
|
46 | 47 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
47 | 48 | import com.oracle.truffle.api.dsl.Specialization;
|
@@ -92,24 +93,31 @@ public void setLazyPythonClass(Object cls,
|
92 | 93 |
|
93 | 94 | @ExportMessage
|
94 | 95 | public static class GetLazyPythonClass {
|
95 |
| - public static boolean hasInitialClass(PythonObject self, DynamicObjectLibrary dylib) { |
96 |
| - return (dylib.getShapeFlags(self) & CLASS_CHANGED_FLAG) == 0; |
| 96 | + public static boolean hasInitialClass(Shape shape) { |
| 97 | + return (shape.getFlags() & CLASS_CHANGED_FLAG) == 0; |
97 | 98 | }
|
98 | 99 |
|
99 | 100 | public static Object getInitialClass(PythonObject self) {
|
100 | 101 | return self.initialPythonClass;
|
101 | 102 | }
|
102 | 103 |
|
103 | 104 | @SuppressWarnings("unused")
|
104 |
| - @Specialization(guards = {"klass != null", "self.getShape() == cachedShape", "hasInitialClass(self, dylib)"}, limit = "1", assumptions = "singleContextAssumption()") |
| 105 | + @Specialization(guards = {"klass != null", "self.getShape() == cachedShape", "hasInitialClass(cachedShape)"}, limit = "1", assumptions = "singleContextAssumption()") |
105 | 106 | public static Object getConstantClass(PythonObject self,
|
106 |
| - @Shared("dylib") @CachedLibrary(limit = "4") DynamicObjectLibrary dylib, |
107 | 107 | @Cached("self.getShape()") Shape cachedShape,
|
108 | 108 | @Cached(value = "getInitialClass(self)", weak = true) Object klass) {
|
109 | 109 | return klass;
|
110 | 110 | }
|
111 | 111 |
|
112 |
| - @Specialization(replaces = "getConstantClass") |
| 112 | + @SuppressWarnings("unused") |
| 113 | + @Specialization(guards = "hasInitialClass(self.getShape())") |
| 114 | + public static Object getClass(PythonObject self, |
| 115 | + @Bind("getInitialClass(self)") Object klass) { |
| 116 | + assert klass != null; |
| 117 | + return klass; |
| 118 | + } |
| 119 | + |
| 120 | + @Specialization(guards = "!hasInitialClass(self.getShape())", replaces = "getConstantClass") |
113 | 121 | public static Object getPythonClass(PythonObject self,
|
114 | 122 | @Shared("dylib") @CachedLibrary(limit = "4") DynamicObjectLibrary dylib) {
|
115 | 123 | return dylib.getOrDefault(self, CLASS, self.initialPythonClass);
|
|
0 commit comments