From 92aea95b36f42977b480076bd057c5b03d97b5ea Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 24 May 2009 22:27:50 -0600 Subject: [PATCH] continuation bugfixes --- src/compile-x86.S | 10 +++--- src/compile.cpp | 88 +++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/compile-x86.S b/src/compile-x86.S index d52d3ac68f..74381bf061 100644 --- a/src/compile-x86.S +++ b/src/compile-x86.S @@ -18,7 +18,7 @@ #define THREAD_CONTINUATION 168 #define THREAD_EXCEPTION 64 -#define THREAD_EXCEPTION_STACK 176 +#define THREAD_EXCEPTION_STACK_ADJUSTMENT 176 #define THREAD_EXCEPTION_OFFSET 184 #define THREAD_EXCEPTION_HANDLER 192 @@ -124,7 +124,8 @@ LOCAL(vmInvoke_continuationTest): LOCAL(vmInvoke_handleException): // we're handling an exception - call the exception handler instead movq $0,THREAD_EXCEPTION(%rbx) - movq THREAD_EXCEPTION_STACK(%rbx),%rsp + movq THREAD_EXCEPTION_STACK_ADJUSTMENT(%rbx),%rdi + subq %rdi,%rsp movq THREAD_EXCEPTION_OFFSET(%rbx),%rdi movq %rsi,(%rsp,%rdi,1) @@ -182,7 +183,7 @@ LOCAL(vmJumpAndInvoke_argumentTest): #define THREAD_CONTINUATION 96 #define THREAD_EXCEPTION 36 -#define THREAD_EXCEPTION_STACK 100 +#define THREAD_EXCEPTION_STACK_ADJUSTMENT 100 #define THREAD_EXCEPTION_OFFSET 104 #define THREAD_EXCEPTION_HANDLER 108 @@ -303,7 +304,8 @@ LOCAL(vmInvoke_continuationTest): LOCAL(vmInvoke_handleException): // we're handling an exception - call the exception handler instead movl $0,THREAD_EXCEPTION(%ebx) - movl THREAD_EXCEPTION_STACK(%ebx),%esp + movl THREAD_EXCEPTION_STACK_ADJUSTMENT(%ebx),%edi + subl %edi,%esp movl THREAD_EXCEPTION_OFFSET(%ebx),%edi movl %esi,(%esp,%edi,1) diff --git a/src/compile.cpp b/src/compile.cpp index 10623c53ac..f954b76143 100644 --- a/src/compile.cpp +++ b/src/compile.cpp @@ -88,7 +88,7 @@ class MyThread: public Thread { base(0), stack(0), continuation(0), - exceptionStack(0), + exceptionStackAdjustment(0), exceptionOffset(0), exceptionHandler(0), tailAddress(0), @@ -105,7 +105,7 @@ class MyThread: public Thread { void* base; void* stack; object continuation; - void* exceptionStack; + uintptr_t exceptionStackAdjustment; uintptr_t exceptionOffset; void* exceptionHandler; void* tailAddress; @@ -1426,43 +1426,43 @@ findUnwindTarget(MyThread* t, void** targetIp, void** targetBase, } while (t->continuation) { - object method = continuationMethod(t, t->continuation); + object c = t->continuation; + + object method = continuationMethod(t, c); void* handler = findExceptionHandler - (t, method, continuationAddress(t, t->continuation)); + (t, method, continuationAddress(t, c)); if (handler) { t->exceptionHandler = handler; - t->exceptionStack = static_cast(*targetStack) - + t->arch->argumentFootprint(methodParameterFootprint(t, target)) - - t->arch->argumentFootprint(methodParameterFootprint(t, method)) - - stackOffsetFromFrame(t, method); + t->exceptionStackAdjustment + = (stackOffsetFromFrame(t, method) + - ((continuationFramePointerOffset(t, c) / BytesPerWord) + - t->arch->framePointerOffset() + + t->arch->frameReturnAddressSize())) * BytesPerWord; t->exceptionOffset = localOffset(t, localSize(t, method), method) * BytesPerWord; break; } else if (t->exception) { releaseLock(t, method, - reinterpret_cast(t->continuation) + reinterpret_cast(c) + ContinuationBody - + continuationReturnAddressOffset(t, t->continuation) + + continuationReturnAddressOffset(t, c) - t->arch->returnAddressOffset()); } - t->continuation = continuationNext(t, t->continuation); + t->continuation = continuationNext(t, c); } } } } object -makeCurrentContinuation(MyThread* t, object context, void** targetIp, - void** targetBase, void** targetStack, - unsigned* oldArgumentFootprint) +makeCurrentContinuation(MyThread* t, void** targetIp, void** targetBase, + void** targetStack, unsigned* oldArgumentFootprint) { - PROTECT(t, context); - void* ip = t->ip; void* base = t->base; void* stack = t->stack; @@ -1470,6 +1470,11 @@ makeCurrentContinuation(MyThread* t, object context, void** targetIp, ip = t->arch->frameIp(stack); } + object context = t->continuation + ? continuationContext(t, t->continuation) + : makeContinuationContext(t, 0, 0, 0, 0, t->trace->originalMethod); + PROTECT(t, context); + object target = t->trace->targetMethod; PROTECT(t, target); @@ -5300,9 +5305,6 @@ callContinuation(MyThread* t, object continuation, object result, { assert(t, t->exception == 0); - t->trace->nativeMethod = 0; - t->trace->targetMethod = 0; - t->continuation = continuation; if (exception) { @@ -5313,8 +5315,13 @@ callContinuation(MyThread* t, object continuation, object result, t->stack = stack; findUnwindTarget(t, &ip, &base, &stack); + + t->ip = 0; } + t->trace->nativeMethod = 0; + t->trace->targetMethod = 0; + vmJump(ip, base, stack, t, reinterpret_cast(result), 0); } @@ -5371,8 +5378,7 @@ compatibleReturnType(MyThread* t, object oldMethod, object newMethod) void jumpAndInvoke(MyThread* t, object method, void* base, void* stack, - unsigned oldArgumentFootprint, unsigned argumentCount, - ...) + unsigned oldArgumentFootprint, ...) { t->trace->targetMethod = 0; @@ -5382,8 +5388,9 @@ jumpAndInvoke(MyThread* t, object method, void* base, void* stack, t->trace->nativeMethod = 0; } + unsigned argumentCount = methodParameterFootprint(t, method); uintptr_t arguments[argumentCount]; - va_list a; va_start(a, argumentCount); + va_list a; va_start(a, oldArgumentFootprint); for (unsigned i = 0; i < argumentCount; ++i) { arguments[i] = va_arg(a, uintptr_t); } @@ -5394,7 +5401,7 @@ jumpAndInvoke(MyThread* t, object method, void* base, void* stack, base, static_cast(stack) + oldArgumentFootprint - - t->arch->argumentFootprint(methodParameterFootprint(t, method)) + - t->arch->argumentFootprint(argumentCount) - t->arch->frameFooterSize() - t->arch->frameReturnAddressSize(), argumentCount * BytesPerWord, @@ -5517,9 +5524,9 @@ callContinuation(MyThread* t, object continuation, object result, case Rewind: { jumpAndInvoke - (t, rewindMethod(t), base, stack, oldArgumentFootprint, 3, - continuationContextBefore(t, nextContinuation), nextContinuation, - result, exception); + (t, rewindMethod(t), base, stack, oldArgumentFootprint, + continuationContextBefore(t, continuationContext(t, nextContinuation)), + nextContinuation, result, exception); } break; case Throw: { @@ -5803,7 +5810,7 @@ class MyProcessor: public Processor { if (false) { fprintf(stderr, "%d\n", difference(&(t->continuation), t)); fprintf(stderr, "%d\n", difference(&(t->exception), t)); - fprintf(stderr, "%d\n", difference(&(t->exceptionStack), t)); + fprintf(stderr, "%d\n", difference(&(t->exceptionStackAdjustment), t)); fprintf(stderr, "%d\n", difference(&(t->exceptionOffset), t)); fprintf(stderr, "%d\n", difference(&(t->exceptionHandler), t)); exit(0); @@ -6245,18 +6252,14 @@ class MyProcessor: public Processor { if (LIKELY(t->exception == 0)) { t->continuation = makeCurrentContinuation - (t, t->continuation - ? continuationContext(t, t->continuation) - : makeContinuationContext - (t, 0, 0, 0, 0, t->trace->originalMethod), - &ip, &base, &stack, &oldArgumentFootprint); + (t, &ip, &base, &stack, &oldArgumentFootprint); } } } if (LIKELY(t->exception == 0)) { jumpAndInvoke - (t, method, base, stack, oldArgumentFootprint, 2, receiver, + (t, method, base, stack, oldArgumentFootprint, receiver, t->continuation); } else { unwind(t); @@ -6296,25 +6299,20 @@ class MyProcessor: public Processor { } if (LIKELY(t->exception == 0)) { - object oldContext - = (t->continuation ? continuationContext(t, t->continuation) : 0); + t->continuation = makeCurrentContinuation + (t, &ip, &base, &stack, &oldArgumentFootprint); - object context = makeContinuationContext - (t, oldContext, before, after, 0, t->trace->originalMethod); + object newContext = makeContinuationContext + (t, continuationContext(t, t->continuation), before, after, + t->continuation, t->trace->originalMethod); - object continuation = makeCurrentContinuation - (t, context, &ip, &base, &stack, &oldArgumentFootprint); - - set(t, continuationContext(t, continuation), - ContinuationContextContinuation, continuation); - - t->continuation = continuation; + set(t, t->continuation, ContinuationContext, newContext); } } if (LIKELY(t->exception == 0)) { jumpAndInvoke - (t, windMethod, base, stack, oldArgumentFootprint, 3, before, thunk, + (t, windMethod, base, stack, oldArgumentFootprint, before, thunk, after); } else { unwind(t);