|
52 | 52 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
53 | 53 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
|
54 | 54 | import com.oracle.graal.python.nodes.function.builtins.PythonVarargsBuiltinNode;
|
| 55 | +import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext; |
55 | 56 | import com.oracle.graal.python.util.PythonUtils;
|
56 | 57 | import com.oracle.truffle.api.dsl.Cached;
|
57 | 58 | import com.oracle.truffle.api.dsl.Fallback;
|
@@ -138,14 +139,22 @@ boolean eq(@SuppressWarnings("unused") Object self, @SuppressWarnings("unused")
|
138 | 139 |
|
139 | 140 | @Builtin(name = __MODULE__, minNumOfPositionalArgs = 1, maxNumOfPositionalArgs = 2, isGetter = true, isSetter = true)
|
140 | 141 | @GenerateNodeFactory
|
141 |
| - abstract static class GetModuleNode extends PythonBuiltinNode { |
| 142 | + abstract static class GetModuleNode extends PythonBinaryBuiltinNode { |
142 | 143 | @Specialization(guards = "isNoValue(none)", limit = "2")
|
143 | 144 | Object getModule(VirtualFrame frame, PBuiltinMethod self, @SuppressWarnings("unused") PNone none,
|
144 | 145 | @CachedLibrary(limit = "3") PythonObjectLibrary pylib,
|
145 | 146 | @CachedLibrary("self") DynamicObjectLibrary dylib) {
|
146 | 147 | Object module = dylib.getOrDefault(self, __MODULE__, PNone.NO_VALUE);
|
147 |
| - if (module == PNone.NO_VALUE) { // specialization of pylib acts as a branch profile |
148 |
| - return pylib.lookupAttribute(self.getSelf(), frame, __NAME__); |
| 148 | + if (module == PNone.NO_VALUE) { |
| 149 | + // getContext() acts as a branch profile. This indirect call is done to easily |
| 150 | + // support calls to this builtin with and without virtual frame, and because we |
| 151 | + // don't care much about the performance here anyway |
| 152 | + Object state = IndirectCallContext.enter(frame, getContext(), this); |
| 153 | + try { |
| 154 | + return pylib.lookupAttribute(self.getSelf(), null, __NAME__); |
| 155 | + } finally { |
| 156 | + IndirectCallContext.exit(frame, getContext(), state); |
| 157 | + } |
149 | 158 | } else {
|
150 | 159 | return module;
|
151 | 160 | }
|
|
0 commit comments