Skip to content

Why the argument Continuation object not supported in constructor? And not set it as a field in the class #96

Description

@forchid

The version info

coroutines java-agent-1.5.3-shaded.jar, java 11, Ubuntu 20.04.1 LTS

The test case

import com.offbynull.coroutines.user.*; 

// 7,500,000 ops/s
public class Test implements Coroutine {

    final int times;

    public Test(int times) {
    	this.times = times;
    }
    
    @Override
    public void run(Continuation c) {
        System.out.println("started");
        for (int i = 0; i < this.times; i++) {
            echo(c, i);
            new CoObject(c, i % 10).execute(c);
	    //new CoObject(i % 10).execute(c);
        }
    }

    private void echo(Continuation c, int x) {
        if (x % 1000000 == 0 || x + 1 == this.times) {
            System.out.println(x);
        }
        c.suspend();
    }

    public static void main(String[] args) {
        int times = 10000000;
        if (args.length > 0) times = Integer.decode(args[0]);
    
        CoroutineRunner r = new CoroutineRunner(new Test(times));
        long ts = System.currentTimeMillis();
        for (int i = 0; i < times << 1; ++i) {
            r.execute();
        }
        long te = System.currentTimeMillis();
        
        System.out.println(String.format("time %sms, %d times", te - ts, times));
    }

    static class CoObject {
        final int n;

        public CoObject(Continuation co, int n) {
	    this.n = n;
	    init(co);
	}
	
	public CoObject(int n) {
	    this.n = n;
	}
       
        public void execute(Continuation co) {
            init(co);
	    for (int i = 0; i < n; ++i);
	}
 
        private void init(Continuation co) {
	    co.suspend();
	}
    }

}

The stack trace

Exception Details:
  Location:
    Test.run(Lcom/offbynull/coroutines/user/Continuation;)V @234: JBinvokespecial
  Reason:
    Type 'Test$CoObject' (current frame, stack[0]) is not assignable to 'uninitializedThis'
  Current Frame:
    bci: @234
    flags: { }
    locals: { 'Test', 'com/offbynull/coroutines/user/Continuation', top, 'com/offbynull/coroutines/user/MethodState', top, top, '[I', '[Ljava/lang/Object;', '[Ljava/lang/Object;' }
    stack: { 'Test$CoObject' }
  Stackmap Table:
    same_frame(@32)
    same_frame(@35)
    same_frame(@45)
    full_frame(@88,{Object[#18],Object[#23],top,Object[#28],top,top,top,top,Object[#32]},{})
    full_frame(@142,{Object[#18],Object[#23],top,Object[#28],top,top,Object[#0],Object[#32],Object[#32]},{})
    full_frame(@193,{Object[#18],Object[#23],top,Object[#28],top,top,top,top,Object[#32]},{})
    full_frame(@247,{Object[#18],Object[#23],top,Object[#28],top,top,Object[#0],Object[#32],Object[#32]},{})
    full_frame(@306,{Object[#18],Object[#23],top,Object[#28],top,top,top,top,Object[#32]},{})
    full_frame(@345,{Object[#18],Object[#23],top,Object[#28],top,top,top,Object[#32],Object[#32]},{})
    full_frame(@396,{Object[#18],Object[#23],top,Object[#28],top,top,top,top,Object[#32]},{})
    full_frame(@406,{Object[#18],Object[#23]},{})
    same_frame(@416)
    append_frame(@426,integer)
    full_frame(@646,{Object[#18],Object[#23],integer,top,top,top,Object[#0],Object[#32]},{})
    same_locals_1_stack_item_frame_extended(@871,top)
    full_frame(@1038,{Object[#18],Object[#23],integer,top,top,top,top,Object[#32]},{})
    full_frame(@1044,{Object[#18],Object[#23],integer},{})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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