diff --git a/src/engine/CodeValidator.v3 b/src/engine/CodeValidator.v3 index c5133cce..d7d15595 100644 --- a/src/engine/CodeValidator.v3 +++ b/src/engine/CodeValidator.v3 @@ -1616,14 +1616,13 @@ class SidetableBuilder { // Emit a sidetable entry for a resume handler. def refH(target: ControlEntry, tag: TagDecl, val_stack_top: int) { var stp = sidetable.length; - var valcount = labelArgs(target).length; - var popcount = val_stack_top - valcount - target.val_stack_top; if (Trace.validation) { - OUT.put2(" refH(@+pc tag=%d vsp=%d", if(tag != null, tag.tag_index, -1), target.val_stack_top); + OUT.put2(" refH(@+pc tag=%d vsp=%d)", if(tag != null, tag.tag_index, -1), target.val_stack_top); OUT.ln(); } - var ti = if(tag != null, tag.tag_index, -1); - Sidetables.putSuspendHandlerEntry(sidetable, valcount, popcount, target.first_ref, ti); + var valcount = labelArgs(target).length; + var popcount = val_stack_top - valcount - target.val_stack_top; + Sidetables.putSuspendHandlerEntry(sidetable, valcount, popcount, target.first_ref); target.first_ref = stp; } // Emit a sidetable entry for a catch entry. diff --git a/src/engine/Sidetable.v3 b/src/engine/Sidetable.v3 index 54ed9b46..6a04ccac 100644 --- a/src/engine/Sidetable.v3 +++ b/src/engine/Sidetable.v3 @@ -64,13 +64,12 @@ component Sidetables { .put(0) // reserved .put(0); // reserved } - def putSuspendHandlerEntry(v: Vector, valcount: int, popcount: int, sidetable_pos: int, tag_index: int) { + def putSuspendHandlerEntry(v: Vector, valcount: int, popcount: int, sidetable_pos: int) { var handler_pc = 0; v.put(handler_pc) // handler pc .put(valcount) .put(popcount) - .put(sidetable_pos) - .put(tag_index); // tag index + .put(sidetable_pos); } } @@ -171,11 +170,10 @@ layout Sidetable_ResumeEntry { // Entries for suspension handlers to store the pc, the tag and the stp. layout Sidetable_SuspendHandlerEntry { +0 handler_pc: u32; - +4 valcount: u32; - +8 popcount: u32; + +4 valcount: u32; + +8 popcount: u32; +12 stp: u32; - +16 tag: u32; - =20; + =16; } // Entries for memory accesses store the access kind, which classifies how complex it is to decode diff --git a/src/engine/x86-64/V3Offsets.v3 b/src/engine/x86-64/V3Offsets.v3 index 1a0f9076..e5fbdf9c 100644 --- a/src/engine/x86-64/V3Offsets.v3 +++ b/src/engine/x86-64/V3Offsets.v3 @@ -57,7 +57,7 @@ class V3Offsets { def X86_64Stack_func = int.view(Pointer.atField(vs.func) - Pointer.atObject(vs)); def X86_64Stack_parent_rsp_ptr = int.view(Pointer.atField(vs.parent_rsp_ptr) - Pointer.atObject(vs)); def X86_64Stack_parent = int.view(Pointer.atField(vs.parent) - Pointer.atObject(vs)); - def X86_64Stack_curr_resume_handler = int.view(Pointer.atField(vs.curr_resume_handler) - Pointer.atObject(vs)); + // def X86_64Stack_curr_resume_handler = int.view(Pointer.atField(vs.curr_resume_handler) - Pointer.atObject(vs)); def X86_64Stack_state = int.view(Pointer.atField(vs.state_) - Pointer.atObject(vs)); def X86_64Stack_return_results = int.view(Pointer.atField(vs.return_results) - Pointer.atObject(vs)); diff --git a/src/engine/x86-64/X86_64Interpreter.v3 b/src/engine/x86-64/X86_64Interpreter.v3 index 9575bbfd..10be49a5 100644 --- a/src/engine/x86-64/X86_64Interpreter.v3 +++ b/src/engine/x86-64/X86_64Interpreter.v3 @@ -2208,9 +2208,9 @@ class X86_64InterpreterGen(ic: X86_64InterpreterCode, w: DataWriter) { asm.movd_r_m(n_args, r_stp.plus(Sidetable_ResumeEntry.n_binds.offset)); // set curr_resume_handler - var r_currStack = r_tmp4; - asm.movq_r_m(r_currStack, m_curStack); - asm.q.movq_m_r(r_currStack.plus(offsets.X86_64Stack_curr_resume_handler), r_stp); + // var r_currStack = r_tmp4; + // asm.movq_r_m(r_currStack, m_curStack); + // asm.q.movq_m_r(r_currStack.plus(offsets.X86_64Stack_curr_resume_handler), r_stp); // extract top stack from continuation var stack_ref = r_tmp4; @@ -2238,7 +2238,7 @@ class X86_64InterpreterGen(ic: X86_64InterpreterCode, w: DataWriter) { asm.q.sub_r_r(r_vsp, vsp_offset); var r_cont_ref = r_tmp0; - r_currStack = r_tmp1; + var r_currStack = r_tmp1; // mov %stack, [cur_stack] ; reload stack object from (thread-local) curStack asm.movq_r_m(r_currStack, m_curStack); @@ -2307,7 +2307,7 @@ class X86_64InterpreterGen(ic: X86_64InterpreterCode, w: DataWriter) { // label: start asm.bind(lookup_start); // mov %handlers, [%parent.curr_resume_handler] - asm.movq_r_m(handlers, parent.plus(offsets.X86_64Stack_curr_resume_handler)); + // asm.movq_r_m(handlers, parent.plus(offsets.X86_64Stack_curr_resume_handler)); saveCallerIVars(); callRuntime(refRuntimeCall(RT.runtime_handle_suspend), [r_instance, tag_index], true); diff --git a/src/engine/x86-64/X86_64Runtime.v3 b/src/engine/x86-64/X86_64Runtime.v3 index 16262e01..f380d70f 100644 --- a/src/engine/x86-64/X86_64Runtime.v3 +++ b/src/engine/x86-64/X86_64Runtime.v3 @@ -157,18 +157,20 @@ component X86_64Runtime { var stack = curStack.setRsp(CiRuntime.callerSp()); var tag = instance.tags[tag_index]; - var top = stack; - var prev = top; + var prev = stack; while (prev.parent != null) { var parent = X86_64Stack.!(prev.parent); var accessor = TargetFrame(parent.rsp).getFrameAccessor(); var lookup_pc = accessor.pc(); var func = accessor.func().decl; var handler = func.findResumeHandler(instance, tag, lookup_pc); - // if (handler.handler_pc >= 0) { - - // return null; - // } + if (handler.handler_pc >= 0) { + var cont = Continuation.new(stack, prev); + prev.parent = null; + prev.parent_rsp_ptr = Pointer.NULL; + Trace.OUT.puts("FOUND").ln(); + return null; + } prev = parent; } diff --git a/src/engine/x86-64/X86_64Stack.v3 b/src/engine/x86-64/X86_64Stack.v3 index 2620cb1f..f319c86a 100644 --- a/src/engine/x86-64/X86_64Stack.v3 +++ b/src/engine/x86-64/X86_64Stack.v3 @@ -17,7 +17,6 @@ class X86_64Stack extends WasmStack { // other, assert that this is {null} on the child stack and manually set it). var parent_rsp_ptr: Pointer; - var curr_resume_handler: Pointer; // pointer to sidetable entry for resume private var params_arity = -1; var return_results: Array; var state_: StackState;