2014-04-21 02:14:48 +00:00
|
|
|
/* Copyright (c) 2008-2014, Avian Contributors
|
2008-02-19 18:06:52 +00:00
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2013-02-28 22:57:09 +00:00
|
|
|
#ifndef AVIAN_COMMON_H
|
|
|
|
#define AVIAN_COMMON_H
|
2007-06-03 01:56:57 +00:00
|
|
|
|
2011-09-17 02:53:08 +00:00
|
|
|
#ifndef __STDC_CONSTANT_MACROS
|
|
|
|
# define __STDC_CONSTANT_MACROS
|
|
|
|
#endif
|
|
|
|
|
2007-06-18 04:25:42 +00:00
|
|
|
#include "stdlib.h"
|
2007-06-07 00:30:16 +00:00
|
|
|
#include "stdarg.h"
|
2007-09-25 23:53:11 +00:00
|
|
|
#include "stddef.h"
|
2007-06-07 00:30:16 +00:00
|
|
|
#include "string.h"
|
|
|
|
#include "stdio.h"
|
2013-02-27 20:25:50 +00:00
|
|
|
#include "avian/types.h"
|
2007-08-13 14:06:31 +00:00
|
|
|
#include "math.h"
|
2007-06-05 00:28:52 +00:00
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
2012-08-15 23:27:27 +00:00
|
|
|
#include "float.h"
|
2013-03-04 18:09:59 +00:00
|
|
|
#include <stdint.h>
|
2012-08-15 23:27:27 +00:00
|
|
|
|
2013-02-28 23:41:44 +00:00
|
|
|
#ifdef powerpc
|
|
|
|
# undef powerpc
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef linux
|
|
|
|
# undef linux
|
|
|
|
#endif
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
// don't complain about using 'this' in member initializers:
|
|
|
|
# pragma warning(disable:4355)
|
|
|
|
|
2012-08-15 23:27:27 +00:00
|
|
|
#define strncasecmp _strnicmp
|
|
|
|
|
|
|
|
#define FP_NAN 0
|
|
|
|
#define FP_INFINITE 1
|
|
|
|
#define FP_UNDEF 2
|
|
|
|
|
|
|
|
inline int fpclassify(double d) {
|
|
|
|
|
|
|
|
switch(_fpclass(d)) {
|
|
|
|
case _FPCLASS_SNAN:
|
|
|
|
case _FPCLASS_QNAN:
|
|
|
|
return FP_NAN;
|
|
|
|
case _FPCLASS_PINF:
|
|
|
|
case _FPCLASS_NINF:
|
|
|
|
return FP_INFINITE;
|
|
|
|
}
|
|
|
|
return FP_UNDEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int signbit(double d) {
|
|
|
|
return _copysign(1.0, d) < 0;
|
|
|
|
}
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
# define not !
|
|
|
|
# define or ||
|
|
|
|
# define and &&
|
|
|
|
# define xor ^
|
|
|
|
|
|
|
|
# define LIKELY(v) v
|
|
|
|
# define UNLIKELY(v) v
|
|
|
|
|
|
|
|
# define UNUSED
|
|
|
|
|
|
|
|
# define NO_RETURN __declspec(noreturn)
|
|
|
|
|
2011-09-01 03:18:00 +00:00
|
|
|
# define PACKED
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
# define PLATFORM_WINDOWS
|
|
|
|
|
|
|
|
# ifdef _M_IX86
|
|
|
|
typedef int32_t intptr_t;
|
|
|
|
typedef uint32_t uintptr_t;
|
|
|
|
# define ARCH_x86_32
|
2012-07-02 22:23:00 +00:00
|
|
|
# define BYTES_PER_WORD 4
|
2009-08-27 00:26:44 +00:00
|
|
|
# elif defined _M_X64
|
|
|
|
typedef int64_t intptr_t;
|
|
|
|
typedef uint64_t uintptr_t;
|
|
|
|
# define ARCH_x86_64
|
2013-01-28 15:20:52 +00:00
|
|
|
# define BYTES_PER_WORD 8
|
|
|
|
# elif defined _M_ARM_FP
|
|
|
|
typedef int32_t intptr_t;
|
|
|
|
typedef uint32_t uintptr_t;
|
|
|
|
# define ARCH_arm
|
|
|
|
# define BYTES_PER_WORD 4
|
2009-08-27 00:26:44 +00:00
|
|
|
# else
|
|
|
|
# error "unsupported architecture"
|
|
|
|
# endif
|
|
|
|
|
2011-02-14 18:47:59 +00:00
|
|
|
namespace vm {
|
|
|
|
|
2011-04-10 18:55:12 +00:00
|
|
|
typedef intptr_t intptr_alias_t;
|
2011-02-14 18:47:59 +00:00
|
|
|
|
|
|
|
} // namespace vm
|
2011-02-12 04:57:27 +00:00
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#else // not _MSC_VER
|
|
|
|
|
2013-02-28 22:57:09 +00:00
|
|
|
# include <stdint.h>
|
2009-08-27 00:26:44 +00:00
|
|
|
|
2012-06-28 22:21:24 +00:00
|
|
|
# define BYTES_PER_WORD __SIZEOF_POINTER__
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
# define LIKELY(v) __builtin_expect((v) != 0, true)
|
|
|
|
# define UNLIKELY(v) __builtin_expect((v) != 0, false)
|
|
|
|
|
|
|
|
# define UNUSED __attribute__((unused))
|
|
|
|
|
|
|
|
# define NO_RETURN __attribute__((noreturn))
|
|
|
|
|
2011-09-01 03:18:00 +00:00
|
|
|
# define PACKED __attribute__((packed))
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
# ifdef __MINGW32__
|
|
|
|
# define PLATFORM_WINDOWS
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifdef __i386__
|
|
|
|
# define ARCH_x86_32
|
|
|
|
# elif defined __x86_64__
|
|
|
|
# define ARCH_x86_64
|
2011-02-26 19:45:22 +00:00
|
|
|
# elif (defined __POWERPC__) || (defined __powerpc__)
|
2009-08-27 00:26:44 +00:00
|
|
|
# define ARCH_powerpc
|
|
|
|
# elif defined __arm__
|
|
|
|
# define ARCH_arm
|
|
|
|
# else
|
|
|
|
# error "unsupported architecture"
|
|
|
|
# endif
|
|
|
|
|
2011-02-14 18:47:59 +00:00
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
typedef intptr_t __attribute__((__may_alias__)) intptr_alias_t;
|
|
|
|
|
|
|
|
} // namespace vm
|
2011-02-12 04:57:27 +00:00
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#endif // not _MSC_VER
|
|
|
|
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
2013-11-08 15:35:10 +00:00
|
|
|
# define AVIAN_EXPORT __declspec(dllexport)
|
2008-07-14 17:02:43 +00:00
|
|
|
# define PATH_SEPARATOR ';'
|
2009-10-27 15:34:46 +00:00
|
|
|
#else // not PLATFORM_WINDOWS
|
2013-11-08 15:35:10 +00:00
|
|
|
# define AVIAN_EXPORT __attribute__ ((visibility("default"))) \
|
2011-09-22 22:55:45 +00:00
|
|
|
__attribute__ ((used))
|
2008-07-14 17:02:43 +00:00
|
|
|
# define PATH_SEPARATOR ':'
|
2009-10-27 15:34:46 +00:00
|
|
|
#endif // not PLATFORM_WINDOWS
|
2007-11-01 20:00:22 +00:00
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#if (defined ARCH_x86_32) || (defined ARCH_powerpc) || (defined ARCH_arm)
|
2009-05-27 01:02:39 +00:00
|
|
|
# define LD "ld"
|
2009-08-27 00:26:44 +00:00
|
|
|
# if (defined _MSC_VER) || ((defined __MINGW32__) && __GNUC__ >= 4)
|
2009-08-07 22:28:47 +00:00
|
|
|
# define LLD "I64d"
|
|
|
|
# else
|
|
|
|
# define LLD "lld"
|
|
|
|
# endif
|
|
|
|
# ifdef __APPLE__
|
|
|
|
# define ULD "lu"
|
|
|
|
# define LX "lx"
|
|
|
|
# else
|
|
|
|
# define LX "x"
|
|
|
|
# define ULD "u"
|
|
|
|
# endif
|
2009-08-27 00:26:44 +00:00
|
|
|
#elif defined ARCH_x86_64
|
2009-08-11 15:31:00 +00:00
|
|
|
# define LD "ld"
|
|
|
|
# define LX "lx"
|
2009-08-27 00:26:44 +00:00
|
|
|
# if (defined _MSC_VER) || (defined __MINGW32__)
|
2009-07-26 02:48:36 +00:00
|
|
|
# define LLD "I64d"
|
|
|
|
# define ULD "I64x"
|
|
|
|
# else
|
2012-07-09 19:05:11 +00:00
|
|
|
# ifdef __APPLE__
|
|
|
|
# define LLD "lld"
|
|
|
|
# else
|
|
|
|
# define LLD "ld"
|
|
|
|
# endif
|
2009-07-26 02:48:36 +00:00
|
|
|
# define ULD "lu"
|
|
|
|
# endif
|
2007-09-19 16:22:19 +00:00
|
|
|
#else
|
2007-09-21 14:16:43 +00:00
|
|
|
# error "Unsupported architecture"
|
2007-07-06 01:06:06 +00:00
|
|
|
#endif
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2007-10-24 16:24:02 +00:00
|
|
|
# define SO_PREFIX ""
|
|
|
|
#else
|
|
|
|
# define SO_PREFIX "lib"
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 16:13:41 +00:00
|
|
|
#ifdef __APPLE__
|
2010-11-16 03:28:53 +00:00
|
|
|
# define SO_SUFFIX ".dylib"
|
2009-08-27 00:26:44 +00:00
|
|
|
#elif defined PLATFORM_WINDOWS
|
2007-10-23 01:00:57 +00:00
|
|
|
# define SO_SUFFIX ".dll"
|
2007-09-20 16:13:41 +00:00
|
|
|
#else
|
2007-09-21 14:16:43 +00:00
|
|
|
# define SO_SUFFIX ".so"
|
2007-09-20 16:13:41 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
#define MACRO_XY(X, Y) X##Y
|
|
|
|
#define MACRO_MakeNameXY(FX, LINE) MACRO_XY(FX, LINE)
|
|
|
|
#define MAKE_NAME(FX) MACRO_MakeNameXY(FX, __LINE__)
|
|
|
|
|
2010-11-07 19:24:40 +00:00
|
|
|
#define RESOURCE(type, name, release) \
|
|
|
|
class MAKE_NAME(Resource_) { \
|
|
|
|
public: \
|
|
|
|
MAKE_NAME(Resource_)(type name): name(name) { } \
|
|
|
|
~MAKE_NAME(Resource_)() { release; } \
|
|
|
|
\
|
|
|
|
private: \
|
|
|
|
type name; \
|
|
|
|
} MAKE_NAME(resource_)(name);
|
|
|
|
|
2013-02-10 07:31:41 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning( disable : 4291 )
|
|
|
|
#endif
|
2007-06-20 17:42:13 +00:00
|
|
|
inline void* operator new(size_t, void* p) throw() { return p; }
|
|
|
|
|
2007-06-20 04:26:36 +00:00
|
|
|
namespace vm {
|
|
|
|
|
2011-04-10 18:55:12 +00:00
|
|
|
inline intptr_alias_t&
|
|
|
|
alias(void* p, unsigned offset)
|
|
|
|
{
|
|
|
|
return *reinterpret_cast<intptr_alias_t*>(static_cast<uint8_t*>(p) + offset);
|
|
|
|
}
|
|
|
|
|
2009-08-27 00:26:44 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
|
|
|
|
inline int
|
|
|
|
vsnprintf(char* dst, size_t size, const char* format, va_list a)
|
|
|
|
{
|
|
|
|
return vsnprintf_s(dst, size, _TRUNCATE, format, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
snprintf(char* dst, size_t size, const char* format, ...)
|
|
|
|
{
|
|
|
|
va_list a;
|
|
|
|
va_start(a, format);
|
|
|
|
int r = vsnprintf(dst, size, format, a);
|
|
|
|
va_end(a);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline FILE*
|
|
|
|
fopen(const char* name, const char* mode)
|
|
|
|
{
|
|
|
|
FILE* file;
|
|
|
|
if (fopen_s(&file, name, mode) == 0) {
|
|
|
|
return file;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // not _MSC_VER
|
|
|
|
|
|
|
|
inline int
|
|
|
|
vsnprintf(char* dst, size_t size, const char* format, va_list a)
|
|
|
|
{
|
|
|
|
return ::vsnprintf(dst, size, format, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
snprintf(char* dst, size_t size, const char* format, ...)
|
|
|
|
{
|
|
|
|
va_list a;
|
|
|
|
va_start(a, format);
|
|
|
|
int r = vsnprintf(dst, size, format, a);
|
|
|
|
va_end(a);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline FILE*
|
|
|
|
fopen(const char* name, const char* mode)
|
|
|
|
{
|
|
|
|
return ::fopen(name, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // not _MSC_VER
|
|
|
|
|
2007-06-20 04:26:36 +00:00
|
|
|
const unsigned BytesPerWord = sizeof(uintptr_t);
|
|
|
|
const unsigned BitsPerWord = BytesPerWord * 8;
|
|
|
|
|
2007-07-01 21:34:22 +00:00
|
|
|
const uintptr_t PointerMask
|
|
|
|
= ((~static_cast<uintptr_t>(0)) / BytesPerWord) * BytesPerWord;
|
|
|
|
|
2007-06-22 20:55:11 +00:00
|
|
|
const unsigned LikelyPageSizeInBytes = 4 * 1024;
|
2007-06-20 04:26:36 +00:00
|
|
|
|
2009-04-19 22:36:11 +00:00
|
|
|
inline unsigned
|
|
|
|
pad(unsigned n, unsigned alignment)
|
|
|
|
{
|
|
|
|
return (n + (alignment - 1)) & ~(alignment - 1);
|
|
|
|
}
|
|
|
|
|
2007-06-20 17:42:13 +00:00
|
|
|
inline unsigned
|
|
|
|
pad(unsigned n)
|
|
|
|
{
|
2009-04-19 22:36:11 +00:00
|
|
|
return pad(n, BytesPerWord);
|
2007-06-20 17:42:13 +00:00
|
|
|
}
|
|
|
|
|
2009-10-18 00:35:19 +00:00
|
|
|
inline uintptr_t
|
|
|
|
padWord(uintptr_t n, uintptr_t alignment)
|
|
|
|
{
|
|
|
|
return (n + (alignment - 1)) & ~(alignment - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uintptr_t
|
|
|
|
padWord(uintptr_t n)
|
|
|
|
{
|
|
|
|
return padWord(n, BytesPerWord);
|
|
|
|
}
|
|
|
|
|
2013-02-17 02:50:34 +00:00
|
|
|
inline bool fitsInInt8(int64_t v) {
|
|
|
|
return v == static_cast<int8_t>(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool fitsInInt16(int64_t v) {
|
|
|
|
return v == static_cast<int16_t>(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool fitsInInt32(int64_t v) {
|
|
|
|
return v == static_cast<int32_t>(v);
|
|
|
|
}
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
template <class T>
|
2007-06-20 17:42:13 +00:00
|
|
|
inline unsigned
|
|
|
|
wordOf(unsigned i)
|
|
|
|
{
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
return i / (sizeof(T) * 8);
|
2007-06-20 17:42:13 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
inline unsigned
|
|
|
|
wordOf(unsigned i)
|
|
|
|
{
|
|
|
|
return wordOf<uintptr_t>(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2007-06-20 17:42:13 +00:00
|
|
|
inline unsigned
|
|
|
|
bitOf(unsigned i)
|
|
|
|
{
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
return i % (sizeof(T) * 8);
|
2007-06-20 17:42:13 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
inline unsigned
|
|
|
|
bitOf(unsigned i)
|
|
|
|
{
|
|
|
|
return bitOf<uintptr_t>(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2007-06-20 17:42:13 +00:00
|
|
|
inline unsigned
|
|
|
|
indexOf(unsigned word, unsigned bit)
|
|
|
|
{
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
return (word * (sizeof(T) * 8)) + bit;
|
2007-06-20 17:42:13 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
inline unsigned
|
|
|
|
indexOf(unsigned word, unsigned bit)
|
|
|
|
{
|
|
|
|
return indexOf<uintptr_t>(word, bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
2007-10-12 02:52:16 +00:00
|
|
|
inline void
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
markBit(T* map, unsigned i)
|
2007-10-12 02:52:16 +00:00
|
|
|
{
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
map[wordOf<T>(i)] |= static_cast<T>(1) << bitOf<T>(i);
|
2007-10-12 02:52:16 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
template <class T>
|
2007-10-12 02:52:16 +00:00
|
|
|
inline void
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
clearBit(T* map, unsigned i)
|
2007-10-12 02:52:16 +00:00
|
|
|
{
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
map[wordOf<T>(i)] &= ~(static_cast<T>(1) << bitOf<T>(i));
|
2007-10-12 02:52:16 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
template <class T>
|
2007-10-12 02:52:16 +00:00
|
|
|
inline unsigned
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
getBit(T* map, unsigned i)
|
2007-10-12 02:52:16 +00:00
|
|
|
{
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
return (map[wordOf<T>(i)] & (static_cast<T>(1) << bitOf<T>(i)))
|
|
|
|
>> bitOf<T>(i);
|
2007-10-12 02:52:16 +00:00
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
// todo: the following (clearBits, setBits, and getBits) could be made
|
|
|
|
// more efficient by operating on a word at a time instead of a bit at
|
|
|
|
// a time:
|
|
|
|
|
|
|
|
template <class T>
|
2008-01-06 19:21:38 +00:00
|
|
|
inline void
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
clearBits(T* map, unsigned bitsPerRecord, unsigned index)
|
2008-01-06 19:21:38 +00:00
|
|
|
{
|
|
|
|
for (unsigned i = index, limit = index + bitsPerRecord; i < limit; ++i) {
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
clearBit<T>(map, i);
|
2008-01-06 19:21:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
template <class T>
|
2008-01-06 19:21:38 +00:00
|
|
|
inline void
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
setBits(T* map, unsigned bitsPerRecord, int index, unsigned v)
|
2008-01-06 19:21:38 +00:00
|
|
|
{
|
|
|
|
for (int i = index + bitsPerRecord - 1; i >= index; --i) {
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
if (v & 1) markBit<T>(map, i); else clearBit<T>(map, i);
|
2008-01-06 19:21:38 +00:00
|
|
|
v >>= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
template <class T>
|
2008-01-06 19:21:38 +00:00
|
|
|
inline unsigned
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
getBits(T* map, unsigned bitsPerRecord, unsigned index)
|
2008-01-06 19:21:38 +00:00
|
|
|
{
|
|
|
|
unsigned v = 0;
|
|
|
|
for (unsigned i = index, limit = index + bitsPerRecord; i < limit; ++i) {
|
|
|
|
v <<= 1;
|
support stack unwinding without using a frame pointer
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.
2011-01-17 02:05:05 +00:00
|
|
|
v |= getBit<T>(map, i);
|
2008-01-06 19:21:38 +00:00
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2007-06-20 17:42:13 +00:00
|
|
|
template <class T>
|
|
|
|
inline T&
|
2013-02-11 00:38:51 +00:00
|
|
|
fieldAtOffset(void* p, unsigned offset)
|
2007-06-20 17:42:13 +00:00
|
|
|
{
|
|
|
|
return *reinterpret_cast<T*>(static_cast<uint8_t*>(p) + offset);
|
|
|
|
}
|
|
|
|
|
2007-07-01 21:34:22 +00:00
|
|
|
template <class T>
|
|
|
|
inline T*
|
2013-02-11 00:14:16 +00:00
|
|
|
maskAlignedPointer(T* p)
|
2007-07-01 21:34:22 +00:00
|
|
|
{
|
|
|
|
return reinterpret_cast<T*>(reinterpret_cast<uintptr_t>(p) & PointerMask);
|
|
|
|
}
|
|
|
|
|
2007-09-17 00:13:36 +00:00
|
|
|
inline uint32_t
|
|
|
|
hash(const char* s)
|
|
|
|
{
|
|
|
|
uint32_t h = 0;
|
|
|
|
for (unsigned i = 0; s[i]; ++i) {
|
|
|
|
h = (h * 31) + s[i];
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t
|
|
|
|
hash(const uint8_t* s, unsigned length)
|
|
|
|
{
|
|
|
|
uint32_t h = 0;
|
|
|
|
for (unsigned i = 0; i < length; ++i) {
|
|
|
|
h = (h * 31) + s[i];
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t
|
|
|
|
hash(const int8_t* s, unsigned length)
|
|
|
|
{
|
|
|
|
return hash(reinterpret_cast<const uint8_t*>(s), length);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t
|
|
|
|
hash(const uint16_t* s, unsigned length)
|
|
|
|
{
|
|
|
|
uint32_t h = 0;
|
|
|
|
for (unsigned i = 0; i < length; ++i) {
|
|
|
|
h = (h * 31) + s[i];
|
|
|
|
}
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
2013-02-23 04:19:53 +00:00
|
|
|
inline void
|
|
|
|
write4(uint8_t* dst, uint32_t v)
|
|
|
|
{
|
|
|
|
memcpy(dst, &v, 4);
|
|
|
|
}
|
|
|
|
|
2007-10-15 19:12:38 +00:00
|
|
|
inline uint32_t
|
|
|
|
floatToBits(float f)
|
|
|
|
{
|
2007-10-25 20:26:51 +00:00
|
|
|
uint32_t bits; memcpy(&bits, &f, 4);
|
2007-10-15 19:12:38 +00:00
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint64_t
|
|
|
|
doubleToBits(double d)
|
|
|
|
{
|
2007-10-25 20:26:51 +00:00
|
|
|
uint64_t bits; memcpy(&bits, &d, 8);
|
2007-10-15 19:12:38 +00:00
|
|
|
return bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline double
|
|
|
|
bitsToDouble(uint64_t bits)
|
|
|
|
{
|
|
|
|
double d; memcpy(&d, &bits, 8);
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline float
|
|
|
|
bitsToFloat(uint32_t bits)
|
|
|
|
{
|
|
|
|
float f; memcpy(&f, &bits, 4);
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:50:44 +00:00
|
|
|
inline int
|
2007-11-25 23:00:55 +00:00
|
|
|
difference(void* a, void* b)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<intptr_t>(a) - reinterpret_cast<intptr_t>(b);
|
|
|
|
}
|
|
|
|
|
2008-11-23 23:58:01 +00:00
|
|
|
template <class T>
|
|
|
|
inline void*
|
|
|
|
voidPointer(T function)
|
|
|
|
{
|
|
|
|
void* p;
|
|
|
|
memcpy(&p, &function, sizeof(void*));
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2009-08-10 13:56:16 +00:00
|
|
|
inline void
|
|
|
|
replace(char a, char b, char* c)
|
|
|
|
{
|
|
|
|
for (; *c; ++c) if (*c == a) *c = b;
|
|
|
|
}
|
|
|
|
|
2010-09-10 21:05:29 +00:00
|
|
|
inline void
|
|
|
|
replace(char a, char b, char* dst, const char* src)
|
|
|
|
{
|
|
|
|
unsigned i = 0;
|
|
|
|
for (; src[i]; ++ i) {
|
|
|
|
dst[i] = src[i] == a ? b : src[i];
|
|
|
|
}
|
|
|
|
dst[i] = 0;
|
|
|
|
}
|
|
|
|
|
2011-03-04 23:55:31 +00:00
|
|
|
inline bool
|
|
|
|
equal(const void* a, unsigned al, const void* b, unsigned bl)
|
|
|
|
{
|
|
|
|
if (al == bl) {
|
|
|
|
return memcmp(a, b, al) == 0;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-20 14:36:31 +00:00
|
|
|
} // namespace vm
|
2007-06-20 04:26:36 +00:00
|
|
|
|
2013-02-28 22:57:09 +00:00
|
|
|
#endif // AVIAN_COMMON_H
|