Open forchid opened 2 years ago
Is stack trace that short or is it truncated by you? Typically, in such scenario StackOverflowException
occurs earlier than OutOfMemoryException
...
Is stack trace that short or is it truncated by you? Typically, in such scenario
StackOverflowException
occurs earlier thanOutOfMemoryException
...
It's the whole stack trace.
Verified. Indeed, the code with non-continuable method calling continuable method creates an infinite loop here. You can check it if N=10 (any small number). Raising the number of iterations just reduces the time before OOM exception. I do not plan to fix this right now. Actually, I see no straightforward way to fix this for dynamic code execution, the only possible option is a static code analysis that checks for non-continuable -> continuable code calls. It implies analyzing bytecode of all methods - this what I tried to avoid when porting from JavaFlow due to inherent overhead of such approach. Anyway, I acknowledge that such analyzer is necessary and should be optionally available. However, I do not plan to add it in nearest time.
Actually, I see no straightforward way to fix this for dynamic code execution
Can we decide the non-continuable method in a continuable method in instrument module? If we can, add a thread-local boolean variable continuable representing whether the current method is continuable method or not. Before calling a non-continuable method except Continuation.suspend() in the continuable method, the variable continuable is set to false, and it's set true after it is called. If the variable continuable from thread-local is false in Continuation.suspend(), then throws the IllegalStateException("Continuation.suspend() is called in non-continuable method") for checking non-continuable -> continuable code calls.
Or Before calling a non-continuable method except Continuation.suspend() in the continuable method, calls the method degisterThread(), and calls registerThread() after it is called.
In this test case, the iterate() method call the continuable method suspend(), then OOM error happens! Java verison 1.8, and net.tascalate.javaflow.api-2.7.2.
The test case
The test result