diff --git a/src/compile.cpp b/src/compile.cpp index 61112a5fc0..f7ad3591f4 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -2133,14 +2133,14 @@ makeCurrentContinuation(MyThread* t, void** targetIp, void** targetStack) object c = makeContinuation (t, 0, context, method, ip, - ((frameSize - + t->arch->frameFooterSize() - + t->arch->returnAddressOffset() - - t->arch->frameReturnAddressSize()) * BytesPerWord), - ((frameSize - + t->arch->frameFooterSize() - + t->arch->framePointerOffset() - - t->arch->frameReturnAddressSize()) * BytesPerWord), + (frameSize + + t->arch->frameFooterSize() + + t->arch->returnAddressOffset() + - t->arch->frameReturnAddressSize()) * BytesPerWord, + (frameSize + + t->arch->frameFooterSize() + + t->arch->framePointerOffset() + - t->arch->frameReturnAddressSize()) * BytesPerWord, totalSize); memcpy(&continuationBody(t, c, 0), top, totalSize * BytesPerWord); @@ -6780,6 +6780,8 @@ callContinuation(MyThread* t, object continuation, object result, t->trace->nativeMethod = 0; t->trace->targetMethod = 0; + popResources(t); + transition(t, ip, stack, continuation, t->trace); vmJump(ip, stack, t, reinterpret_cast(result), 0); @@ -6857,6 +6859,10 @@ jumpAndInvoke(MyThread* t, object method, void* stack, ...) RUNTIME_ARRAY_BODY(arguments)[i] = va_arg(a, uintptr_t); } va_end(a); + + assert(t, t->exception == 0); + + popResources(t); vmJumpAndInvoke (t, reinterpret_cast(methodAddress(t, method)), diff --git a/src/continuations-x86.S b/src/continuations-x86.S index de30be72ac..af2b399ea0 100644 --- a/src/continuations-x86.S +++ b/src/continuations-x86.S @@ -59,11 +59,13 @@ LOCAL(vmInvoke_continuationTest): #endif movq %r10,(%rsp,%rdi,1) +#ifdef AVIAN_USE_FRAME_POINTER // save the current base pointer in the frame and update it movq CONTINUATION_FRAME_POINTER_OFFSET(%rcx),%rdi movq %rbp,(%rsp,%rdi,1) addq %rsp,%rdi movq %rdi,%rbp +#endif // consume the continuation movq CONTINUATION_NEXT(%rcx),%rdi @@ -151,11 +153,13 @@ LOCAL(vmInvoke_offset): #endif movl %esi,(%esp,%edi,1) +#ifdef AVIAN_USE_FRAME_POINTER // save the current base pointer in the frame and update it movl CONTINUATION_FRAME_POINTER_OFFSET(%ecx),%edi movl %ebp,(%esp,%edi,1) addl %esp,%edi movl %edi,%ebp +#endif // consume the continuation movl CONTINUATION_NEXT(%ecx),%edi diff --git a/src/machine.cpp b/src/machine.cpp index cd7c40cf51..b7975d0abb 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -2843,28 +2843,19 @@ makeNewGeneral(Thread* t, object class_) return instance; } -void NO_RETURN -throw_(Thread* t, object e) +void +popResources(Thread* t) { - assert(t, t->exception == 0); - - Thread::Checkpoint* checkpoint = t->checkpoint; - - expect(t, not checkpoint->noThrow); - - t->exception = e; - - while (t->resource != checkpoint->resource) { + while (t->resource != t->checkpoint->resource) { Thread::Resource* r = t->resource; t->resource = r->next; + fprintf(stderr, "unwind resource %p %p %p\n", r, + reinterpret_cast(r)[0], + reinterpret_cast(r)[0][0]); r->release(); } - t->protector = checkpoint->protector; - - checkpoint->unwind(); - - abort(t); + t->protector = t->checkpoint->protector; } object diff --git a/src/machine.h b/src/machine.h index f721277b44..745ada691e 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2572,8 +2572,24 @@ makeThrowable(Thread* t, Machine::Type type, const char* format, ...) return r; } -void NO_RETURN -throw_(Thread* t, object e); +void +popResources(Thread* t); + +inline void NO_RETURN +throw_(Thread* t, object e) +{ + assert(t, t->exception == 0); + + expect(t, not t->checkpoint->noThrow); + + t->exception = e; + + popResources(t); + + t->checkpoint->unwind(); + + abort(t); +} inline void NO_RETURN throwNew(Thread* t, Machine::Type type) diff --git a/src/x86.cpp b/src/x86.cpp index eb61e405ad..c5227cca26 100644 --- a/src/x86.cpp +++ b/src/x86.cpp @@ -3029,7 +3029,7 @@ class MyArchitecture: public Assembler::Architecture { } virtual int framePointerOffset() { - return -1; + return UseFramePointer ? -1 : 0; } virtual void plan