Skip to content

Commit d78ac12

Browse files
committed
Avoid allocation of temporary objects in interpreter
1 parent d96dd68 commit d78ac12

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/ExecutionContext.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,19 @@ public static Object enter(PythonThreadState threadState, Object[] pArguments, R
476476
return enter(threadState, pArguments, calleeRootNode.needsExceptionState());
477477
}
478478

479-
private static IndirectCallState enter(PythonThreadState threadState, Object[] pArguments, boolean needsExceptionState) {
479+
private static Object enter(PythonThreadState threadState, Object[] pArguments, boolean needsExceptionState) {
480480
Reference popTopFrameInfo = threadState.popTopFrameInfo();
481481
PArguments.setCallerFrameInfo(pArguments, popTopFrameInfo);
482482

483-
PException curExc = null;
484483
if (needsExceptionState) {
485-
curExc = threadState.getCaughtException();
484+
PException curExc = threadState.getCaughtException();
486485
if (curExc != null) {
487486
threadState.setCaughtException(null);
488487
}
489488
PArguments.setException(pArguments, curExc);
489+
return new IndirectCallState(popTopFrameInfo, curExc);
490490
}
491-
return new IndirectCallState(popTopFrameInfo, curExc);
491+
return popTopFrameInfo;
492492
}
493493

494494
public static void exit(PythonLanguage language, PythonContext context, Object state) {
@@ -501,10 +501,12 @@ public static void exit(PythonThreadState threadState, Object state) {
501501
* CalleeContext in its RootNode. If this topframeref was marked as escaped, it'll be
502502
* materialized at the latest needed time
503503
*/
504-
IndirectCallState indirectCallState = (IndirectCallState) state;
505-
threadState.setTopFrameInfo(indirectCallState.info);
506-
if (indirectCallState.curExc != null) {
504+
if (state instanceof IndirectCallState) {
505+
IndirectCallState indirectCallState = (IndirectCallState) state;
506+
threadState.setTopFrameInfo(indirectCallState.info);
507507
threadState.setCaughtException(indirectCallState.curExc);
508+
} else {
509+
threadState.setTopFrameInfo((Reference) state);
508510
}
509511
}
510512
}

0 commit comments

Comments
 (0)