Skip to content

Commit

Permalink
removed prev resume handler and uses accessor info
Browse files Browse the repository at this point in the history
  • Loading branch information
linxuanm committed Oct 25, 2024
1 parent e61d98b commit b0c977f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
9 changes: 4 additions & 5 deletions src/engine/CodeValidator.v3
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 5 additions & 7 deletions src/engine/Sidetable.v3
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ component Sidetables {
.put(0) // reserved
.put(0); // reserved
}
def putSuspendHandlerEntry(v: Vector<int>, valcount: int, popcount: int, sidetable_pos: int, tag_index: int) {
def putSuspendHandlerEntry(v: Vector<int>, 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);
}
}

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/engine/x86-64/V3Offsets.v3
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
10 changes: 5 additions & 5 deletions src/engine/x86-64/X86_64Interpreter.v3
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/engine/x86-64/X86_64Runtime.v3
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/engine/x86-64/X86_64Stack.v3
Original file line number Diff line number Diff line change
Expand Up @@ -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<ValueType>;
var state_: StackState;
Expand Down

0 comments on commit b0c977f

Please sign in to comment.