2014-04-21 02:14:48 +00:00
|
|
|
/* Copyright (c) 2008-2014, Avian Contributors
|
2008-06-25 20:53:48 +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-11 15:07:46 +00:00
|
|
|
#ifndef AVIAN_CODEGEN_ASSEMBLER_H
|
|
|
|
#define AVIAN_CODEGEN_ASSEMBLER_H
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2014-02-07 21:24:56 +00:00
|
|
|
#include <avian/system/system.h>
|
2013-02-27 20:25:50 +00:00
|
|
|
#include "avian/zone.h"
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2014-02-07 21:24:56 +00:00
|
|
|
#include <avian/codegen/lir.h>
|
|
|
|
#include <avian/codegen/promise.h>
|
2013-02-11 15:07:46 +00:00
|
|
|
|
|
|
|
namespace avian {
|
|
|
|
namespace codegen {
|
|
|
|
|
2013-02-24 06:03:01 +00:00
|
|
|
class Architecture;
|
2013-02-12 04:31:19 +00:00
|
|
|
|
2013-02-11 15:07:46 +00:00
|
|
|
class OperandInfo {
|
|
|
|
public:
|
|
|
|
const unsigned size;
|
|
|
|
const lir::OperandType type;
|
|
|
|
lir::Operand* const operand;
|
|
|
|
|
|
|
|
inline OperandInfo(unsigned size, lir::OperandType type, lir::Operand* operand):
|
|
|
|
size(size),
|
|
|
|
type(type),
|
|
|
|
operand(operand)
|
|
|
|
{ }
|
|
|
|
};
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2009-05-26 05:27:10 +00:00
|
|
|
#ifdef AVIAN_TAILS
|
|
|
|
const bool TailCalls = true;
|
|
|
|
#else
|
|
|
|
const bool TailCalls = false;
|
|
|
|
#endif
|
|
|
|
|
2014-04-29 19:26:40 +00:00
|
|
|
#ifdef AVIAN_USE_FRAME_POINTER
|
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
|
|
|
const bool UseFramePointer = true;
|
|
|
|
#else
|
|
|
|
const bool UseFramePointer = false;
|
|
|
|
#endif
|
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
class Assembler {
|
|
|
|
public:
|
|
|
|
|
2008-03-13 23:43:11 +00:00
|
|
|
class Client {
|
|
|
|
public:
|
2008-05-06 21:13:02 +00:00
|
|
|
virtual int acquireTemporary
|
|
|
|
(uint32_t mask = ~static_cast<uint32_t>(0)) = 0;
|
2008-03-13 23:43:11 +00:00
|
|
|
virtual void releaseTemporary(int r) = 0;
|
2008-04-27 20:15:18 +00:00
|
|
|
|
|
|
|
virtual void save(int r) = 0;
|
2008-03-13 23:43:11 +00:00
|
|
|
};
|
|
|
|
|
2008-09-07 20:12:11 +00:00
|
|
|
class Block {
|
|
|
|
public:
|
|
|
|
virtual unsigned resolve(unsigned start, Block* next) = 0;
|
|
|
|
};
|
|
|
|
|
2008-08-17 19:32:40 +00:00
|
|
|
virtual void setClient(Client* client) = 0;
|
|
|
|
|
2008-08-23 18:04:36 +00:00
|
|
|
virtual Architecture* arch() = 0;
|
|
|
|
|
2011-01-30 21:14:57 +00:00
|
|
|
virtual void checkStackOverflow(uintptr_t handler,
|
|
|
|
unsigned stackLimitOffsetFromThread) = 0;
|
2011-02-20 03:33:26 +00:00
|
|
|
virtual void saveFrame(unsigned stackOffset, unsigned ipOffset) = 0;
|
2008-09-05 15:00:38 +00:00
|
|
|
virtual void pushFrame(unsigned argumentCount, ...) = 0;
|
|
|
|
virtual void allocateFrame(unsigned footprint) = 0;
|
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
|
|
|
virtual void adjustFrame(unsigned difference) = 0;
|
|
|
|
virtual void popFrame(unsigned footprint) = 0;
|
2009-04-19 22:36:11 +00:00
|
|
|
virtual void popFrameForTailCall(unsigned footprint, int offset,
|
|
|
|
int returnAddressSurrogate,
|
|
|
|
int framePointerSurrogate) = 0;
|
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
|
|
|
virtual void popFrameAndPopArgumentsAndReturn(unsigned frameFootprint,
|
|
|
|
unsigned argumentFootprint)
|
2009-04-19 22:36:11 +00:00
|
|
|
= 0;
|
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
|
|
|
virtual void popFrameAndUpdateStackAndReturn(unsigned frameFootprint,
|
|
|
|
unsigned stackOffsetFromThread)
|
2009-04-25 17:49:56 +00:00
|
|
|
= 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2013-02-11 15:07:46 +00:00
|
|
|
virtual void apply(lir::Operation op) = 0;
|
|
|
|
virtual void apply(lir::UnaryOperation op, OperandInfo a) = 0;
|
|
|
|
virtual void apply(lir::BinaryOperation op, OperandInfo a, OperandInfo b) = 0;
|
|
|
|
virtual void apply(lir::TernaryOperation op, OperandInfo a, OperandInfo b, OperandInfo c) = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2011-02-28 06:03:13 +00:00
|
|
|
virtual void setDestination(uint8_t* dst) = 0;
|
|
|
|
|
|
|
|
virtual void write() = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2010-12-07 22:57:11 +00:00
|
|
|
virtual Promise* offset(bool forTrace = false) = 0;
|
2008-08-30 20:12:27 +00:00
|
|
|
|
2008-09-09 00:31:19 +00:00
|
|
|
virtual Block* endBlock(bool startNew) = 0;
|
2008-08-30 20:12:27 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
virtual void endEvent() = 0;
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2010-11-14 02:28:05 +00:00
|
|
|
virtual unsigned length() = 0;
|
2009-10-20 14:20:49 +00:00
|
|
|
|
2011-01-30 21:14:57 +00:00
|
|
|
virtual unsigned footerSize() = 0;
|
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
|
|
|
|
2008-02-11 17:21:41 +00:00
|
|
|
virtual void dispose() = 0;
|
|
|
|
};
|
|
|
|
|
2013-02-11 15:07:46 +00:00
|
|
|
} // namespace codegen
|
|
|
|
} // namespace avian
|
2008-02-11 17:21:41 +00:00
|
|
|
|
2013-02-11 15:07:46 +00:00
|
|
|
#endif // AVIAN_CODEGEN_ASSEMBLER_H
|