replace Frame::StackType with ir::Type

This commit is contained in:
Joshua Warner 2014-05-05 10:49:50 -06:00
parent 37d104871c
commit 7abbace8fb

View File

@ -1350,13 +1350,7 @@ int methodReferenceReturnCode(Thread* t, object reference)
class Frame { class Frame {
public: public:
enum StackType { Frame(Context* context, ir::Type* stackMap)
Integer,
Long,
Object
};
Frame(Context* context, uint8_t* stackMap)
: context(context), : context(context),
t(context->thread), t(context->thread),
c(context->compiler), c(context->compiler),
@ -1367,10 +1361,12 @@ class Frame {
level(0), level(0),
types(TargetBytesPerWord) types(TargetBytesPerWord)
{ {
memset(stackMap, 0, codeMaxStack(t, methodCode(t, context->method))); memset(stackMap,
0,
codeMaxStack(t, methodCode(t, context->method)) * sizeof(ir::Type));
} }
Frame(Frame* f, uint8_t* stackMap) Frame(Frame* f, ir::Type* stackMap)
: context(f->context), : context(f->context),
t(context->thread), t(context->thread),
c(context->compiler), c(context->compiler),
@ -1381,8 +1377,9 @@ class Frame {
level(f->level + 1), level(f->level + 1),
types(TargetBytesPerWord) types(TargetBytesPerWord)
{ {
memcpy(stackMap, f->stackMap, codeMaxStack memcpy(stackMap,
(t, methodCode(t, context->method))); f->stackMap,
codeMaxStack(t, methodCode(t, context->method)) * sizeof(ir::Type));
if (level > 1) { if (level > 1) {
context->eventLog.append(PushContextEvent); context->eventLog.append(PushContextEvent);
@ -1442,10 +1439,11 @@ class Frame {
return localSize() + stackSize(); return localSize() + stackSize();
} }
void set(unsigned index, uint8_t type) { void set(unsigned index, ir::Type type)
{
assert(t, index < frameSize()); assert(t, index < frameSize());
if (type == Object) { if (type == types.object) {
context->eventLog.append(MarkEvent); context->eventLog.append(MarkEvent);
context->eventLog.append2(index); context->eventLog.append2(index);
} else { } else {
@ -1459,7 +1457,8 @@ class Frame {
} }
} }
uint8_t get(unsigned index) { ir::Type get(unsigned index)
{
assert(t, index < frameSize()); assert(t, index < frameSize());
int si = index - localSize(); int si = index - localSize();
assert(t, si >= 0); assert(t, si >= 0);
@ -1468,25 +1467,25 @@ class Frame {
void pushedInt() { void pushedInt() {
assert(t, sp + 1 <= frameSize()); assert(t, sp + 1 <= frameSize());
set(sp++, Integer); set(sp++, types.i4);
} }
void pushedLong() { void pushedLong() {
assert(t, sp + 2 <= frameSize()); assert(t, sp + 2 <= frameSize());
set(sp++, Long); set(sp++, types.i8);
set(sp++, Long); set(sp++, types.i8);
} }
void pushedObject() { void pushedObject() {
assert(t, sp + 1 <= frameSize()); assert(t, sp + 1 <= frameSize());
set(sp++, Object); set(sp++, types.object);
} }
void popped(unsigned count) { void popped(unsigned count) {
assert(t, sp >= count); assert(t, sp >= count);
assert(t, sp - count >= localSize()); assert(t, sp - count >= localSize());
while (count) { while (count) {
set(--sp, Integer); set(--sp, types.i4);
-- count; -- count;
} }
} }
@ -1494,39 +1493,39 @@ class Frame {
void poppedInt() { void poppedInt() {
assert(t, sp >= 1); assert(t, sp >= 1);
assert(t, sp - 1 >= localSize()); assert(t, sp - 1 >= localSize());
assert(t, get(sp - 1) == Integer); assert(t, get(sp - 1) == types.i4);
-- sp; -- sp;
} }
void poppedLong() { void poppedLong() {
assert(t, sp >= 1); assert(t, sp >= 1);
assert(t, sp - 2 >= localSize()); assert(t, sp - 2 >= localSize());
assert(t, get(sp - 1) == Long); assert(t, get(sp - 1) == types.i8);
assert(t, get(sp - 2) == Long); assert(t, get(sp - 2) == types.i8);
sp -= 2; sp -= 2;
} }
void poppedObject() { void poppedObject() {
assert(t, sp >= 1); assert(t, sp >= 1);
assert(t, sp - 1 >= localSize()); assert(t, sp - 1 >= localSize());
assert(t, get(sp - 1) == Object); assert(t, get(sp - 1) == types.object);
set(--sp, Integer); set(--sp, types.i4);
} }
void storedInt(unsigned index) { void storedInt(unsigned index) {
assert(t, index < localSize()); assert(t, index < localSize());
set(index, Integer); set(index, types.i4);
} }
void storedLong(unsigned index) { void storedLong(unsigned index) {
assert(t, index + 1 < localSize()); assert(t, index + 1 < localSize());
set(index, Long); set(index, types.i8);
set(index + 1, Long); set(index + 1, types.i8);
} }
void storedObject(unsigned index) { void storedObject(unsigned index) {
assert(t, index < localSize()); assert(t, index < localSize());
set(index, Object); set(index, types.object);
} }
void dupped() { void dupped() {
@ -1540,8 +1539,8 @@ class Frame {
assert(t, sp + 1 <= frameSize()); assert(t, sp + 1 <= frameSize());
assert(t, sp - 2 >= localSize()); assert(t, sp - 2 >= localSize());
uint8_t b2 = get(sp - 2); ir::Type b2 = get(sp - 2);
uint8_t b1 = get(sp - 1); ir::Type b1 = get(sp - 1);
set(sp - 1, b2); set(sp - 1, b2);
set(sp - 2, b1); set(sp - 2, b1);
@ -1554,9 +1553,9 @@ class Frame {
assert(t, sp + 1 <= frameSize()); assert(t, sp + 1 <= frameSize());
assert(t, sp - 3 >= localSize()); assert(t, sp - 3 >= localSize());
uint8_t b3 = get(sp - 3); ir::Type b3 = get(sp - 3);
uint8_t b2 = get(sp - 2); ir::Type b2 = get(sp - 2);
uint8_t b1 = get(sp - 1); ir::Type b1 = get(sp - 1);
set(sp - 2, b3); set(sp - 2, b3);
set(sp - 1, b2); set(sp - 1, b2);
@ -1570,8 +1569,8 @@ class Frame {
assert(t, sp + 2 <= frameSize()); assert(t, sp + 2 <= frameSize());
assert(t, sp - 2 >= localSize()); assert(t, sp - 2 >= localSize());
uint8_t b2 = get(sp - 2); ir::Type b2 = get(sp - 2);
uint8_t b1 = get(sp - 1); ir::Type b1 = get(sp - 1);
set(sp, b2); set(sp, b2);
set(sp + 1, b1); set(sp + 1, b1);
@ -1583,9 +1582,9 @@ class Frame {
assert(t, sp + 2 <= frameSize()); assert(t, sp + 2 <= frameSize());
assert(t, sp - 3 >= localSize()); assert(t, sp - 3 >= localSize());
uint8_t b3 = get(sp - 3); ir::Type b3 = get(sp - 3);
uint8_t b2 = get(sp - 2); ir::Type b2 = get(sp - 2);
uint8_t b1 = get(sp - 1); ir::Type b1 = get(sp - 1);
set(sp - 1, b3); set(sp - 1, b3);
set(sp - 3, b2); set(sp - 3, b2);
@ -1600,10 +1599,10 @@ class Frame {
assert(t, sp + 2 <= frameSize()); assert(t, sp + 2 <= frameSize());
assert(t, sp - 4 >= localSize()); assert(t, sp - 4 >= localSize());
uint8_t b4 = get(sp - 4); ir::Type b4 = get(sp - 4);
uint8_t b3 = get(sp - 3); ir::Type b3 = get(sp - 3);
uint8_t b2 = get(sp - 2); ir::Type b2 = get(sp - 2);
uint8_t b1 = get(sp - 1); ir::Type b1 = get(sp - 1);
set(sp - 2, b4); set(sp - 2, b4);
set(sp - 1, b3); set(sp - 1, b3);
@ -1618,7 +1617,7 @@ class Frame {
void swapped() { void swapped() {
assert(t, sp - 2 >= localSize()); assert(t, sp - 2 >= localSize());
uint8_t saved = get(sp - 1); ir::Type saved = get(sp - 1);
set(sp - 1, get(sp - 2)); set(sp - 1, get(sp - 2));
set(sp - 2, saved); set(sp - 2, saved);
@ -1854,7 +1853,7 @@ class Frame {
assert(t, sp >= 1); assert(t, sp >= 1);
assert(t, sp - 1 >= localSize()); assert(t, sp - 1 >= localSize());
if (get(sp - 1) == Object) { if (get(sp - 1) == types.object) {
storedObject(translateLocalIndex(context, 1, index)); storedObject(translateLocalIndex(context, 1, index));
} else { } else {
storedInt(translateLocalIndex(context, 1, index)); storedInt(translateLocalIndex(context, 1, index));
@ -1883,7 +1882,7 @@ class Frame {
void dupX2() { void dupX2() {
ir::Value* s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
if (get(sp - 2) == Long) { if (get(sp - 2) == types.i8) {
ir::Value* s1 = popLongQuiet(); ir::Value* s1 = popLongQuiet();
pushQuiet(types.i4, s0); pushQuiet(types.i4, s0);
@ -1903,7 +1902,7 @@ class Frame {
} }
void dup2() { void dup2() {
if (get(sp - 1) == Long) { if (get(sp - 1) == types.i8) {
pushLongQuiet(c->peek(2, 0)); pushLongQuiet(c->peek(2, 0));
} else { } else {
ir::Value* s0 = popQuiet(types.i4); ir::Value* s0 = popQuiet(types.i4);
@ -1919,7 +1918,7 @@ class Frame {
} }
void dup2X1() { void dup2X1() {
if (get(sp - 1) == Long) { if (get(sp - 1) == types.i8) {
ir::Value* s0 = popLongQuiet(); ir::Value* s0 = popLongQuiet();
ir::Value* s1 = popQuiet(types.i4); ir::Value* s1 = popQuiet(types.i4);
@ -1942,10 +1941,10 @@ class Frame {
} }
void dup2X2() { void dup2X2() {
if (get(sp - 1) == Long) { if (get(sp - 1) == types.i8) {
ir::Value* s0 = popLongQuiet(); ir::Value* s0 = popLongQuiet();
if (get(sp - 3) == Long) { if (get(sp - 3) == types.i8) {
ir::Value* s1 = popLongQuiet(); ir::Value* s1 = popLongQuiet();
pushLongQuiet(s0); pushLongQuiet(s0);
@ -2131,7 +2130,7 @@ class Frame {
// Innermost subroutine we're compiling code for // Innermost subroutine we're compiling code for
Subroutine* subroutine; Subroutine* subroutine;
uint8_t* stackMap; ir::Type* stackMap;
unsigned ip; unsigned ip;
unsigned sp; unsigned sp;
unsigned level; unsigned level;
@ -3446,6 +3445,7 @@ handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function)
void void
handleEntrance(MyThread* t, Frame* frame) handleEntrance(MyThread* t, Frame* frame)
{ {
ir::Types types(TargetBytesPerWord);
object method = frame->context->method; object method = frame->context->method;
if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC)) if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC))
@ -3458,7 +3458,7 @@ handleEntrance(MyThread* t, Frame* frame)
frame->types.object, frame->types.object,
loadLocal(frame->context, 1, frame->types.object, 0), loadLocal(frame->context, 1, frame->types.object, 0),
index); index);
frame->set(index, Frame::Object); frame->set(index, types.object);
} }
handleMonitorEvent handleMonitorEvent
@ -4042,7 +4042,8 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
ir::Types types(TargetBytesPerWord); ir::Types types(TargetBytesPerWord);
start: start:
uint8_t* stackMap = static_cast<uint8_t*>(stack.push(stackSize)); ir::Type* stackMap
= static_cast<ir::Type*>(stack.push(stackSize * sizeof(ir::Type)));
frame = new (stack.push(sizeof(Frame))) Frame(frame, stackMap); frame = new (stack.push(sizeof(Frame))) Frame(frame, stackMap);
loop: loop:
@ -4077,22 +4078,21 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
if (DebugInstructions) { if (DebugInstructions) {
unsigned startingIp = ip; unsigned startingIp = ip;
// TODO: fix stack printing
fprintf(stderr, " stack: ["); fprintf(stderr, " stack: [");
for (size_t i = frame->localSize(); i < frame->sp; i++) { for (size_t i = frame->localSize(); i < frame->sp; i++) {
switch (frame->get(i)) { ir::Type ty = frame->get(i);
case Frame::Integer: if (ty == types.i4) {
fprintf(stderr, "I"); fprintf(stderr, "I");
break; } else if (ty == types.i8) {
case Frame::Long:
fprintf(stderr, "L"); fprintf(stderr, "L");
break; } else if (ty == types.f4) {
case Frame::Object: fprintf(stderr, "F");
} else if (ty == types.f8) {
fprintf(stderr, "D");
} else if (ty == types.object) {
fprintf(stderr, "O"); fprintf(stderr, "O");
break; } else {
default:
fprintf(stderr, "?"); fprintf(stderr, "?");
break;
} }
} }
fprintf(stderr, "]\n"); fprintf(stderr, "]\n");
@ -6117,7 +6117,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned initialIp,
frame->dispose(); frame->dispose();
frame = 0; frame = 0;
stack.pop(sizeof(Frame)); stack.pop(sizeof(Frame));
stack.pop(stackSize); stack.pop(stackSize * sizeof(ir::Type));
switch (stack.popValue()) { switch (stack.popValue()) {
case Return: case Return:
return; return;
@ -7022,13 +7022,13 @@ compile(MyThread* t, Context* context)
c->init(codeLength(t, methodCode(t, context->method)), footprint, locals, c->init(codeLength(t, methodCode(t, context->method)), footprint, locals,
alignedFrameSize(t, context->method)); alignedFrameSize(t, context->method));
THREAD_RUNTIME_ARRAY(t, uint8_t, stackMap, ir::Type* stackMap = (ir::Type*)malloc(
codeMaxStack(t, methodCode(t, context->method))); sizeof(ir::Type) * codeMaxStack(t, methodCode(t, context->method)));
Frame frame(context, RUNTIME_ARRAY_BODY(stackMap)); Frame frame(context, stackMap);
unsigned index = methodParameterFootprint(t, context->method); unsigned index = methodParameterFootprint(t, context->method);
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) { if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
frame.set(--index, Frame::Object); frame.set(--index, frame.types.object);
c->initLocal(index, frame.types.object); c->initLocal(index, frame.types.object);
} }
@ -7040,29 +7040,29 @@ compile(MyThread* t, Context* context)
switch (*it.next()) { switch (*it.next()) {
case 'L': case 'L':
case '[': case '[':
frame.set(--index, Frame::Object); frame.set(--index, frame.types.object);
c->initLocal(index, frame.types.object); c->initLocal(index, frame.types.object);
break; break;
case 'J': case 'J':
frame.set(--index, Frame::Long); frame.set(--index, frame.types.i8);
frame.set(--index, Frame::Long); frame.set(--index, frame.types.i8);
c->initLocal(index, frame.types.i8); c->initLocal(index, frame.types.i8);
break; break;
case 'D': case 'D':
frame.set(--index, Frame::Long); frame.set(--index, frame.types.f8);
frame.set(--index, Frame::Long); frame.set(--index, frame.types.f8);
c->initLocal(index, frame.types.f8); c->initLocal(index, frame.types.f8);
break; break;
case 'F': case 'F':
frame.set(--index, Frame::Integer); frame.set(--index, frame.types.i4);
c->initLocal(index, frame.types.f4); c->initLocal(index, frame.types.f4);
break; break;
default: default:
frame.set(--index, Frame::Integer); frame.set(--index, frame.types.i4);
c->initLocal(index, frame.types.i4); c->initLocal(index, frame.types.i4);
break; break;
} }
@ -7108,12 +7108,10 @@ compile(MyThread* t, Context* context)
c->restoreState(state); c->restoreState(state);
THREAD_RUNTIME_ARRAY( ir::Type* stackMap = (ir::Type*)malloc(
t, sizeof(ir::Type)
uint8_t, * codeMaxStack(t, methodCode(t, context->method)));
stackMap, Frame frame2(&frame, stackMap);
codeMaxStack(t, methodCode(t, context->method)));
Frame frame2(&frame, RUNTIME_ARRAY_BODY(stackMap));
unsigned end = duplicatedBaseIp + exceptionHandlerEnd(eh); unsigned end = duplicatedBaseIp + exceptionHandlerEnd(eh);
if (exceptionHandlerIp(eh) >= static_cast<unsigned>(start) if (exceptionHandlerIp(eh) >= static_cast<unsigned>(start)
@ -7128,7 +7126,7 @@ compile(MyThread* t, Context* context)
for (unsigned i = 1; for (unsigned i = 1;
i < codeMaxStack(t, methodCode(t, context->method)); i < codeMaxStack(t, methodCode(t, context->method));
++i) { ++i) {
frame2.set(localSize(t, context->method) + i, Frame::Integer); frame2.set(localSize(t, context->method) + i, frame2.types.i4);
} }
compile(t, &frame2, exceptionHandlerIp(eh), start); compile(t, &frame2, exceptionHandlerIp(eh), start);
@ -7146,6 +7144,7 @@ compile(MyThread* t, Context* context)
context->dirtyRoots = false; context->dirtyRoots = false;
calculateFrameMaps(t, context, 0, 0, 0); calculateFrameMaps(t, context, 0, 0, 0);
} }
free(stackMap);
} }
void void