mirror of
https://github.com/corda/corda.git
synced 2025-01-22 12:28:11 +00:00
43cbfd3f3a
Previously, we unwound the stack by following the chain of frame pointers for normal returns, stack trace creation, and exception unwinding. On x86, this required reserving EBP/RBP for frame pointer duties, making it unavailable for general computation and requiring that it be explicitly saved and restored on entry and exit, respectively. On PowerPC, we use an ABI that makes the stack pointer double as a frame pointer, so it doesn't cost us anything. We've been using the same convention on ARM, but it doesn't match the native calling convention, which makes it unusable when we want to call native code from Java and pass arguments on the stack. So far, the ARM calling convention mismatch hasn't been an issue because we've never passed more arguments from Java to native code than would fit in registers. However, we must now pass an extra argument (the thread pointer) to e.g. divideLong so it can throw an exception on divide by zero, which means the last argument must be passed on the stack. This will clobber the linkage area we've been using to hold the frame pointer, so we need to stop using it. One solution would be to use the same convention on ARM as we do on x86, but this would introduce the same overhead of making a register unavailable for general use and extra code at method entry and exit. Instead, this commit removes the need for a frame pointer. Unwinding involves consulting a map of instruction offsets to frame sizes which is generated at compile time. This is necessary because stack trace creation can happen at any time due to Thread.getStackTrace being called by another thread, and the frame size varies during the execution of a method. So far, only x86(_64) is working, and continuations and tail call optimization are probably broken. More to come.
53 lines
1.1 KiB
C++
53 lines
1.1 KiB
C++
/* Copyright (c) 2008-2010, Avian Contributors
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
for any purpose with or without fee is hereby granted, provided
|
|
that the above copyright notice and this permission notice appear
|
|
in all copies.
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
details. */
|
|
|
|
#ifndef ARCH_H
|
|
#define ARCH_H
|
|
|
|
#ifdef _MSC_VER
|
|
# include "windows.h"
|
|
# pragma push_macro("assert")
|
|
# include "intrin.h"
|
|
# pragma pop_macro("assert")
|
|
# undef interface
|
|
#endif
|
|
|
|
#include "common.h"
|
|
|
|
extern "C" void NO_RETURN
|
|
vmJump(void* address, void* stack, void* thread, uintptr_t returnLow,
|
|
uintptr_t returnHigh);
|
|
|
|
namespace vm {
|
|
|
|
inline void
|
|
compileTimeMemoryBarrier()
|
|
{
|
|
#ifdef _MSC_VER
|
|
_ReadWriteBarrier();
|
|
#else
|
|
__asm__ __volatile__("": : :"memory");
|
|
#endif
|
|
}
|
|
|
|
} // namespace vm
|
|
|
|
#if (defined ARCH_x86_32) || (defined ARCH_x86_64)
|
|
# include "x86.h"
|
|
#elif defined ARCH_powerpc
|
|
# include "powerpc.h"
|
|
#elif defined ARCH_arm
|
|
# include "arm.h"
|
|
#else
|
|
# error unsupported architecture
|
|
#endif
|
|
|
|
#endif//ARCH_H
|