Skip to content

Non-continuable method calling continuable method leads to OOM instead of not instrumented exception #12

Open
@forchid

Description

@forchid

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

import org.apache.commons.javaflow.api.*;

public class Test {
	
	static final int N = Integer.getInteger("N", 10000000);
	
	public static void main(String[] args) {
		long ts = System.currentTimeMillis();
		//Continuation co = Continuation.startWith(new Execution(), true);
		// Lambda example
		Continuation co = Continuation.startWith((CoRunnable)(() -> {
			int i = 1; 
			for (; i <= N; i++) {
                                iterate(i);
                        }
			System.out.println("i = " + i);
		}), true);
		int i = 1;
		
                for (; null != co; ) {
                        Object va = co.value();
	                //if (!va.equals(i)) throw new AssertionError(va + " != " +i);
	                //System.out.println(va + " <-> " +i);
                       co = co.resume(va);
	               ++i;
                }
		
		long te = System.currentTimeMillis();
		System.out.printf("items %d, time %dms%n", N, te - ts);
	}
	
	//@continuable
	static Object iterate(int i) {
		before();
		Object res = suspend(i);
		after();
		return res;
	}
	
	static void before() {}
	
	static void after() {}
	
	@continuable
	static Object suspend(int i) {
		return Continuation.suspend(i);
	}
	
	interface CoRunnable extends Runnable {
		@continuable void run();
	}
	
	static class Execution implements Runnable {

                @Override
                public @continuable void run() {
                       for (int i = 1; i <= N; i++) {
                               Continuation.suspend(i);
                       }
                }
        }
}
java -javaagent:D:\lib\java\javaflow.instrument-continuations.jar Test

The test result

[main] INFO org.apache.commons.javaflow.agent.core.ContinuableClassesInstrumentationAgent - Installing agent...
[main] INFO org.apache.commons.javaflow.agent.core.ContinuableClassesInstrumentationAgent - Agent was installed
i = 10000001
i = 10000001
i = 10000001
[main] ERROR org.apache.commons.javaflow.core.StackRecorder - Java heap space
java.lang.OutOfMemoryError: Java heap space
        at org.apache.commons.javaflow.core.Stack.ensurePrimitivesStackSize(Stack.java:323)
        at org.apache.commons.javaflow.core.Stack.pushInt(Stack.java:215)
        at Test.suspend(Test.java:48)
        at Test.iterate(Test.java:37)
        at Test.lambda$main$0(Test.java:16)
        at Test$$Lambda$1/1627800613.run(Unknown Source)
        at org.apache.commons.javaflow.core.StackRecorder.execute(StackRecorder.java:122)
        at org.apache.commons.javaflow.api.Continuation$SingleShotContinuation.resumeWith(Continuation.java:573)
        at org.apache.commons.javaflow.api.Continuation.resume(Continuation.java:314)
        at Test.main(Test.java:26)
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at org.apache.commons.javaflow.core.Stack.ensurePrimitivesStackSize(Stack.java:323)
        at org.apache.commons.javaflow.core.Stack.pushInt(Stack.java:215)
        at Test.suspend(Test.java:48)
        at Test.iterate(Test.java:37)
        at Test.lambda$main$0(Test.java:16)
        at Test$$Lambda$1/1627800613.run(Unknown Source)
        at org.apache.commons.javaflow.core.StackRecorder.execute(StackRecorder.java:122)
        at org.apache.commons.javaflow.api.Continuation$SingleShotContinuation.resumeWith(Continuation.java:573)
        at org.apache.commons.javaflow.api.Continuation.resume(Continuation.java:314)
        at Test.main(Test.java:26)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions