Skip to content

Commit dd93fd1

Browse files
fangerertimfel
authored andcommitted
Add hint to methods used when handling StackOverflowError
1 parent e9a3619 commit dd93fd1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,6 +2151,12 @@ public PythonNativeWrapper getSingletonNativeWrapper(PythonAbstractObject obj) {
21512151
return null;
21522152
}
21532153

2154+
/**
2155+
* This method is intended to be called to re-acquire the GIL after a {@link StackOverflowError}
2156+
* was catched. To reduce the probability that re-acquiring the GIL causes again a
2157+
* {@link StackOverflowError}, it is important to keep this method as simple as possible. In
2158+
* particular, do not add calls if there is a way to avoid it.
2159+
*/
21542160
public void reacquireGilAfterStackOverflow() {
21552161
while (!ownsGil()) {
21562162
try {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ private static RuntimeException createStacktraceCarrier() {
122122
return new RuntimeException();
123123
}
124124

125+
/*
126+
* Note: we use this method to convert a Java StackOverflowError into a Python RecursionError.
127+
* At the time when this is done, some Java stack frames were already unwinded but there is no
128+
* guarantee on how many. Therefore, it is important that this method is simple. In particular,
129+
* do not add calls if that can be avoided.
130+
*/
125131
public static PException fromObject(PBaseException actual, Node node, Throwable wrapped) {
126132
PException pException = new PException(actual, node, wrapped);
127133
actual.setException(pException);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/object/PythonObjectFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,12 @@ public final PBaseException createBaseException(Object cls, Object[] data, PTupl
933933
return trace(new PBaseException(cls, getShape(cls), data, args));
934934
}
935935

936+
/*
937+
* Note: we use this method to convert a Java StackOverflowError into a Python RecursionError.
938+
* At the time when this is done, some Java stack frames were already unwinded but there is no
939+
* guarantee on how many. Therefore, it is important that this method is simple. In particular,
940+
* do not add calls if that can be avoided.
941+
*/
936942
public final PBaseException createBaseException(Object cls, TruffleString format, Object[] args) {
937943
return createBaseException(cls, null, format, args);
938944
}

0 commit comments

Comments
 (0)