Skip to content
Browse files

fix Exceptions test for amd64

  • Loading branch information...
1 parent 04da77e commit 1ba497d90ad54c49a4b7c42737ef79e295eeb483 Joel Dice committed Nov 2, 2008
Showing with 312 additions and 271 deletions.
  1. +84 −99 src/compile.cpp
  2. +213 −164 src/compiler.cpp
  3. +8 −7 src/compiler.h
  4. +7 −1 test/Simple.java
View
183 src/compile.cpp
@@ -839,56 +839,42 @@ class Frame {
this->ip = ip;
}
- void pushQuiet(unsigned size, Compiler::Operand* o) {
- c->push(size, o);
+ void pushQuiet(unsigned footprint, Compiler::Operand* o) {
+ c->push(footprint, o);
context->eventLog.append(PushEvent);
context->eventLog.appendAddress(c->top());
}
void pushLongQuiet(Compiler::Operand* o) {
- if (BytesPerWord == 8) {
- c->push(8);
-
- context->eventLog.append(PushEvent);
- context->eventLog.appendAddress(c->top());
- }
-
- pushQuiet(8, o);
+ pushQuiet(2, o);
}
- Compiler::Operand* popQuiet(unsigned size) {
+ Compiler::Operand* popQuiet(unsigned footprint) {
context->eventLog.append(PopEvent);
context->eventLog.appendAddress(c->top());
- return c->pop(size);
+ return c->pop(footprint);
}
Compiler::Operand* popLongQuiet() {
- Compiler::Operand* r = popQuiet(8);
-
- if (BytesPerWord == 8) {
- context->eventLog.append(PopEvent);
- context->eventLog.appendAddress(c->top());
-
- c->pop(8);
- }
+ Compiler::Operand* r = popQuiet(2);
return r;
}
void pushInt(Compiler::Operand* o) {
- pushQuiet(4, o);
+ pushQuiet(1, o);
pushedInt();
}
void pushAddress(Compiler::Operand* o) {
- pushQuiet(BytesPerWord, o);
+ pushQuiet(1, o);
pushedInt();
}
void pushObject(Compiler::Operand* o) {
- pushQuiet(BytesPerWord, o);
+ pushQuiet(1, o);
pushedObject();
}
@@ -916,17 +902,17 @@ class Frame {
context->eventLog.appendAddress(s);
c->popped();
- i -= c->size(s);
+ i -= c->footprint(s);
}
}
Compiler::Operand* popInt() {
poppedInt();
- return popQuiet(4);
+ return popQuiet(1);
}
Compiler::Operand* peekLong(unsigned index) {
- return c->peek(8, index);
+ return c->peek(2, index);
}
Compiler::Operand* popLong() {
@@ -936,41 +922,41 @@ class Frame {
Compiler::Operand* popObject() {
poppedObject();
- return popQuiet(BytesPerWord);
+ return popQuiet(1);
}
void loadInt(unsigned index) {
assert(t, index < localSize());
- pushInt(c->loadLocal(BytesPerWord, index));
+ pushInt(c->loadLocal(1, index));
}
void loadLong(unsigned index) {
assert(t, index < static_cast<unsigned>(localSize() - 1));
- pushLong(c->loadLocal(8, index));
+ pushLong(c->loadLocal(2, index));
}
void loadObject(unsigned index) {
assert(t, index < localSize());
- pushObject(c->loadLocal(BytesPerWord, index));
+ pushObject(c->loadLocal(1, index));
}
void storeInt(unsigned index) {
- c->storeLocal(BytesPerWord, popInt(), index);
+ c->storeLocal(1, popInt(), index);
storedInt(index);
}
void storeLong(unsigned index) {
- c->storeLocal(8, popLong(), index);
+ c->storeLocal(2, popLong(), index);
storedLong(index);
}
void storeObject(unsigned index) {
- c->storeLocal(BytesPerWord, popObject(), index);
+ c->storeLocal(1, popObject(), index);
storedObject(index);
}
void storeObjectOrAddress(unsigned index) {
- c->storeLocal(BytesPerWord, popQuiet(BytesPerWord), index);
+ c->storeLocal(1, popQuiet(1), index);
assert(t, sp >= 1);
assert(t, sp - 1 >= localSize());
@@ -984,39 +970,39 @@ class Frame {
}
void dup() {
- pushQuiet(BytesPerWord, c->peek(BytesPerWord, 0));
+ pushQuiet(1, c->peek(1, 0));
dupped();
}
void dupX1() {
- Compiler::Operand* s0 = popQuiet(BytesPerWord);
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
+ Compiler::Operand* s0 = popQuiet(1);
+ Compiler::Operand* s1 = popQuiet(1);
- pushQuiet(BytesPerWord, s0);
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
+ pushQuiet(1, s0);
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
duppedX1();
}
void dupX2() {
- Compiler::Operand* s0 = popQuiet(BytesPerWord);
+ Compiler::Operand* s0 = popQuiet(1);
if (get(sp - 2) == Long) {
Compiler::Operand* s1 = popLongQuiet();
- pushQuiet(BytesPerWord, s0);
+ pushQuiet(1, s0);
pushLongQuiet(s1);
- pushQuiet(BytesPerWord, s0);
+ pushQuiet(1, s0);
} else {
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
- Compiler::Operand* s2 = popQuiet(BytesPerWord);
+ Compiler::Operand* s1 = popQuiet(1);
+ Compiler::Operand* s2 = popQuiet(1);
- pushQuiet(BytesPerWord, s0);
- pushQuiet(BytesPerWord, s2);
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
+ pushQuiet(1, s0);
+ pushQuiet(1, s2);
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
}
duppedX2();
@@ -1026,13 +1012,13 @@ class Frame {
if (get(sp - 1) == Long) {
pushLongQuiet(peekLong(0));
} else {
- Compiler::Operand* s0 = popQuiet(BytesPerWord);
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
+ Compiler::Operand* s0 = popQuiet(1);
+ Compiler::Operand* s1 = popQuiet(1);
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
}
dupped2();
@@ -1041,21 +1027,21 @@ class Frame {
void dup2X1() {
if (get(sp - 1) == Long) {
Compiler::Operand* s0 = popLongQuiet();
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
+ Compiler::Operand* s1 = popQuiet(1);
pushLongQuiet(s0);
- pushQuiet(BytesPerWord, s1);
+ pushQuiet(1, s1);
pushLongQuiet(s0);
} else {
- Compiler::Operand* s0 = popQuiet(BytesPerWord);
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
- Compiler::Operand* s2 = popQuiet(BytesPerWord);
-
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
- pushQuiet(BytesPerWord, s2);
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
+ Compiler::Operand* s0 = popQuiet(1);
+ Compiler::Operand* s1 = popQuiet(1);
+ Compiler::Operand* s2 = popQuiet(1);
+
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
+ pushQuiet(1, s2);
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
}
dupped2X1();
@@ -1072,37 +1058,37 @@ class Frame {
pushLongQuiet(s1);
pushLongQuiet(s0);
} else {
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
- Compiler::Operand* s2 = popQuiet(BytesPerWord);
+ Compiler::Operand* s1 = popQuiet(1);
+ Compiler::Operand* s2 = popQuiet(1);
pushLongQuiet(s0);
- pushQuiet(BytesPerWord, s2);
- pushQuiet(BytesPerWord, s1);
+ pushQuiet(1, s2);
+ pushQuiet(1, s1);
pushLongQuiet(s0);
}
} else {
- Compiler::Operand* s0 = popQuiet(BytesPerWord);
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
- Compiler::Operand* s2 = popQuiet(BytesPerWord);
- Compiler::Operand* s3 = popQuiet(BytesPerWord);
-
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
- pushQuiet(BytesPerWord, s3);
- pushQuiet(BytesPerWord, s2);
- pushQuiet(BytesPerWord, s1);
- pushQuiet(BytesPerWord, s0);
+ Compiler::Operand* s0 = popQuiet(1);
+ Compiler::Operand* s1 = popQuiet(1);
+ Compiler::Operand* s2 = popQuiet(1);
+ Compiler::Operand* s3 = popQuiet(1);
+
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
+ pushQuiet(1, s3);
+ pushQuiet(1, s2);
+ pushQuiet(1, s1);
+ pushQuiet(1, s0);
}
dupped2X2();
}
void swap() {
- Compiler::Operand* s0 = popQuiet(BytesPerWord);
- Compiler::Operand* s1 = popQuiet(BytesPerWord);
+ Compiler::Operand* s0 = popQuiet(1);
+ Compiler::Operand* s1 = popQuiet(1);
- pushQuiet(BytesPerWord, s0);
- pushQuiet(BytesPerWord, s1);
+ pushQuiet(1, s0);
+ pushQuiet(1, s1);
swapped();
}
@@ -1860,7 +1846,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
int index = 0;
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
- c->initLocal(BytesPerWord, index++);
+ c->initLocal(1, index++);
}
for (MethodSpecIterator it
@@ -1871,12 +1857,12 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
switch (*it.next()) {
case 'J':
case 'D':
- c->initLocal(8, index);
+ c->initLocal(2, index);
index += 2;
break;
default:
- c->initLocal(BytesPerWord, index++);
+ c->initLocal(1, index++);
break;
}
}
@@ -2098,7 +2084,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
if (UNLIKELY(t->exception)) return;
- Compiler::Operand* instance = c->peek(BytesPerWord, 0);
+ Compiler::Operand* instance = c->peek(1, 0);
c->call
(c->constant(getThunk(t, checkCastThunk)),
@@ -2645,7 +2631,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
int8_t count = codeBody(t, code, ip++);
c->storeLocal
- (4, c->add(4, c->constant(count), c->loadLocal(4, index)), index);
+ (1, c->add(4, c->constant(count), c->loadLocal(1, index)), index);
} break;
case iload:
@@ -2719,7 +2705,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
frame->trace(0, false),
BytesPerWord,
3, c->thread(), frame->append(target),
- c->peek(BytesPerWord, instance)),
+ c->peek(1, instance)),
0,
frame->trace(target, true),
rSize,
@@ -2771,8 +2757,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
unsigned offset = ClassVtable + (methodOffset(t, target) * BytesPerWord);
- Compiler::Operand* instance = c->peek
- (BytesPerWord, parameterFootprint - 1);
+ Compiler::Operand* instance = c->peek(1, parameterFootprint - 1);
unsigned rSize = resultSize(t, methodReturnCode(t, target));
@@ -3363,7 +3348,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
} break;
case ret:
- c->jmp(c->loadLocal(BytesPerWord, codeBody(t, code, ip)));
+ c->jmp(c->loadLocal(1, codeBody(t, code, ip)));
return;
case return_:
@@ -3449,7 +3434,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
uint16_t count = codeReadInt16(t, code, ip);
c->storeLocal
- (4, c->add(4, c->constant(count), c->loadLocal(4, index)), index);
+ (1, c->add(4, c->constant(count), c->loadLocal(1, index)), index);
} break;
case iload: {
@@ -3469,7 +3454,7 @@ compile(MyThread* t, Frame* initialFrame, unsigned ip,
} break;
case ret:
- c->jmp(c->loadLocal(BytesPerWord, codeReadInt16(t, code, ip)));
+ c->jmp(c->loadLocal(1, codeReadInt16(t, code, ip)));
return;
default: abort(t);
@@ -3873,15 +3858,15 @@ finish(MyThread* t, Context* context)
}
// for debugging:
- if (//false and
+ if (false and
strcmp
(reinterpret_cast<const char*>
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
- "java/lang/Long") == 0 and
+ "Simple") == 0 and
strcmp
(reinterpret_cast<const char*>
(&byteArrayBody(t, methodName(t, context->method), 0)),
- "toString") == 0)
+ "size") == 0)
{
asm("int3");
}
View
377 src/compiler.cpp
@@ -15,11 +15,13 @@ using namespace vm;
namespace {
-const bool DebugAppend = true;
-const bool DebugCompile = true;
+const bool DebugAppend = false;
+const bool DebugCompile = false;
const bool DebugStack = false;
-const bool DebugRegisters = true;
+const bool DebugRegisters = false;
const bool DebugFrameIndexes = false;
+const bool DebugFrame = false;
+const bool DebugControl = false;
const int AnyFrameIndex = -2;
const int NoFrameIndex = -1;
@@ -75,7 +77,7 @@ class Cell {
class Local {
public:
Value* value;
- unsigned sizeInBytes;
+ unsigned footprint;
};
class Site {
@@ -113,13 +115,13 @@ class Site {
class Stack: public Compiler::StackElement {
public:
- Stack(unsigned index, unsigned sizeInWords, Value* value, Stack* next):
- index(index), sizeInWords(sizeInWords), paddingInWords(0), value(value),
+ Stack(unsigned index, unsigned footprint, Value* value, Stack* next):
+ index(index), footprint(footprint), paddingInWords(0), value(value),
next(next)
{ }
unsigned index;
- unsigned sizeInWords;
+ unsigned footprint;
unsigned paddingInWords;
Value* value;
Stack* next;
@@ -568,9 +570,9 @@ class Event {
};
int
-frameIndex(Context* c, int index, unsigned sizeInWords)
+frameIndex(Context* c, int index, unsigned footprint)
{
- return c->alignedFrameSize + c->parameterFootprint - index - sizeInWords;
+ return c->alignedFrameSize + c->parameterFootprint - index - footprint;
}
unsigned
@@ -603,13 +605,13 @@ class FrameIterator {
public:
class Element {
public:
- Element(Value* value, unsigned localIndex, unsigned sizeInBytes):
- value(value), localIndex(localIndex), sizeInBytes(sizeInBytes)
+ Element(Value* value, unsigned localIndex, unsigned footprint):
+ value(value), localIndex(localIndex), footprint(footprint)
{ }
Value* const value;
const unsigned localIndex;
- const unsigned sizeInBytes;
+ const unsigned footprint;
};
FrameIterator(Context* c, Stack* stack, Local* locals):
@@ -625,21 +627,21 @@ class FrameIterator {
Element next(Context* c) {
Value* v;
unsigned li;
- unsigned sizeInBytes;
+ unsigned footprint;
if (stack) {
Stack* s = stack;
v = s->value;
li = s->index + c->localFootprint;
- sizeInBytes = s->sizeInWords * BytesPerWord;
+ footprint = s->footprint;
stack = stack->next;
} else {
Local* l = locals + localIndex;
v = l->value;
li = localIndex;
- sizeInBytes = l->sizeInBytes;
+ footprint = l->footprint;
-- localIndex;
}
- return Element(v, li, sizeInBytes);
+ return Element(v, li, footprint);
}
Stack* stack;
@@ -650,8 +652,7 @@ class FrameIterator {
int
frameIndex(Context* c, FrameIterator::Element* element)
{
- return frameIndex
- (c, element->localIndex, ceiling(element->sizeInBytes, BytesPerWord));;
+ return frameIndex(c, element->localIndex, element->footprint);
}
class SiteIterator {
@@ -1637,19 +1638,19 @@ move(Context* c, Stack* stack, Local* locals, unsigned size, Value* value,
Site* tmp = freeRegisterSite(c);
addSite(c, stack, locals, size, value, tmp);
- char srcb[256]; src->toString(c, srcb, 256);
- char tmpb[256]; tmp->toString(c, tmpb, 256);
- fprintf(stderr, "move %s to %s for %p\n", srcb, tmpb, value);
+// char srcb[256]; src->toString(c, srcb, 256);
+// char tmpb[256]; tmp->toString(c, tmpb, 256);
+// fprintf(stderr, "move %s to %s for %p\n", srcb, tmpb, value);
apply(c, Move, size, src, size, tmp);
src = tmp;
}
addSite(c, stack, locals, size, value, dst);
- char srcb[256]; src->toString(c, srcb, 256);
- char dstb[256]; dst->toString(c, dstb, 256);
- fprintf(stderr, "move %s to %s for %p\n", srcb, dstb, value);
+// char srcb[256]; src->toString(c, srcb, 256);
+// char dstb[256]; dst->toString(c, dstb, 256);
+// fprintf(stderr, "move %s to %s for %p\n", srcb, dstb, value);
apply(c, Move, size, src, size, dst);
}
@@ -1673,39 +1674,58 @@ toString(Context* c, Site* sites, char* buffer, unsigned size)
}
void
-releaseRegister(Context* c, Value* v, unsigned frameIndex, unsigned sizeInBytes, int r)
+releaseRegister(Context* c, Value* v, unsigned frameIndex,
+ unsigned sizeInBytes, int r)
{
Site* source = 0;
- for (Site** s = &(v->sites); *s;) {
- if ((*s)->usesRegister(c, r)) {
- char buffer[256]; (*s)->toString(c, buffer, 256);
- fprintf(stderr, "%p (%s) in %p at %d uses %d\n", *s, buffer, v, frameIndex, r);
-
- source = *s;
- *s = (*s)->next;
-
- source->release(c);
+ for (SiteIterator it(v); it.hasMore();) {
+ Site* s = it.next();
+ if (s->usesRegister(c, r)) {
+ if (DebugRegisters) {
+ char buffer[256]; s->toString(c, buffer, 256);
+ fprintf(stderr, "%p (%s) in %p at %d uses %d\n",
+ s, buffer, v, frameIndex, r);
+ }
+
+ source = s;
+ it.remove(c);
} else {
- char buffer[256]; (*s)->toString(c, buffer, 256);
- fprintf(stderr, "%p (%s) in %p at %d does not use %d\n", *s, buffer, v, frameIndex, r);
- s = &((*s)->next);
+ if (DebugRegisters) {
+ char buffer[256]; s->toString(c, buffer, 256);
+ fprintf(stderr, "%p (%s) in %p at %d does not use %d\n",
+ s, buffer, v, frameIndex, r);
+ }
}
}
if (not hasSite(v)) {
- move(c, c->stack, c->locals, sizeInBytes, v, source, frameSite(c, frameIndex));
+ move(c, c->stack, c->locals, sizeInBytes, v, source,
+ frameSite(c, frameIndex));
+ }
+
+ if (DebugRegisters) {
+ char buffer[256]; toString(c, v->sites, buffer, 256);
+ fprintf(stderr, "%p is left with %s\n", v, buffer);
}
+}
- char buffer[256]; toString(c, v->sites, buffer, 256);
- fprintf(stderr, "%p is left with %s\n", v, buffer);
+unsigned
+footprintSizeInBytes(unsigned footprint)
+{
+ if (BytesPerWord == 8) {
+ return 8;
+ } else {
+ return footprint * 4;
+ }
}
void
releaseRegister(Context* c, int r)
{
for (FrameIterator it(c, c->stack, c->locals); it.hasMore();) {
FrameIterator::Element e = it.next(c);
- releaseRegister(c, e.value, frameIndex(c, &e), e.sizeInBytes, r);
+ releaseRegister(c, e.value, frameIndex(c, &e),
+ footprintSizeInBytes(e.footprint), r);
}
}
@@ -1718,8 +1738,7 @@ trySteal(Context* c, Site* site, Value* v, unsigned size, Stack* stack,
for (unsigned li = 0; li < c->localFootprint; ++li) {
Local* local = locals + li;
if (local->value == v) {
- saveSite = frameSite
- (c, frameIndex(c, li, ceiling(local->sizeInBytes, BytesPerWord)));
+ saveSite = frameSite(c, frameIndex(c, li, local->footprint));
break;
}
}
@@ -1736,7 +1755,7 @@ trySteal(Context* c, Site* site, Value* v, unsigned size, Stack* stack,
saveSite = frameSite(c, frameIndex);
} else {
saveSite = frameSite
- (c, ::frameIndex(c, s->index + c->localFootprint, s->sizeInWords));
+ (c, ::frameIndex(c, s->index + c->localFootprint, s->footprint));
}
break;
}
@@ -2083,7 +2102,7 @@ apply(Context* c, TernaryOperation op,
void
addRead(Context* c, Event* e, Value* v, Read* r)
{
- fprintf(stderr, "add read %p to %p last %p event %p (%s)\n", r, v, v->lastRead, e, (e ? e->name() : 0));
+// fprintf(stderr, "add read %p to %p last %p event %p (%s)\n", r, v, v->lastRead, e, (e ? e->name() : 0));
r->value = v;
if (e) {
@@ -2112,10 +2131,10 @@ clean(Context* c, Value* v, unsigned popIndex)
(c, static_cast<MemorySite*>(s)->value.offset)
>= popIndex))
{
- char buffer[256]; s->toString(c, buffer, 256);
- fprintf(stderr, "remove %s from %p at %d pop index %d\n",
- buffer, v, offsetToFrameIndex
- (c, static_cast<MemorySite*>(s)->value.offset), popIndex);
+// char buffer[256]; s->toString(c, buffer, 256);
+// fprintf(stderr, "remove %s from %p at %d pop index %d\n",
+// buffer, v, offsetToFrameIndex
+// (c, static_cast<MemorySite*>(s)->value.offset), popIndex);
it.remove(c);
}
}
@@ -2173,56 +2192,56 @@ class CallEvent: public Event {
Read* target;
if (index < c->arch->argumentRegisterCount()) {
int r = c->arch->argumentRegister(index);
- fprintf(stderr, "reg %d arg read %p\n", r, s->value);
- target = fixedRegisterRead(c, s->sizeInWords * BytesPerWord, r);
+// fprintf(stderr, "reg %d arg read %p\n", r, s->value);
+ target = fixedRegisterRead(c, footprintSizeInBytes(s->footprint), r);
mask &= ~(1 << r);
} else {
- fprintf(stderr, "stack %d arg read %p\n", frameIndex, s->value);
- target = read(c, s->sizeInWords * BytesPerWord, 1 << MemoryOperand, 0,
- frameIndex);
- frameIndex += s->sizeInWords;
+// fprintf(stderr, "stack %d arg read %p\n", frameIndex, s->value);
+ target = read(c, footprintSizeInBytes(s->footprint),
+ 1 << MemoryOperand, 0, frameIndex);
+ frameIndex += s->footprint;
}
addRead(c, this, s->value, target);
- index += s->sizeInWords;
+ index += s->footprint;
s = s->next;
}
- fprintf(stderr, "address read %p\n", address);
+// fprintf(stderr, "address read %p\n", address);
addRead(c, this, address, read
(c, BytesPerWord, ~0, (static_cast<uint64_t>(mask) << 32) | mask,
AnyFrameIndex));
int footprint = stackArgumentFootprint;
for (Stack* s = stackBefore; s; s = s->next) {
if (footprint > 0) {
- fprintf(stderr, "stack arg read %p of size %d at %d of %d\n", s->value, s->sizeInWords, frameIndex, c->alignedFrameSize + c->parameterFootprint);
+// fprintf(stderr, "stack arg read %p of footprint %d at %d of %d\n", s->value, s->footprint, frameIndex, c->alignedFrameSize + c->parameterFootprint);
addRead(c, this, s->value, read
- (c, s->sizeInWords * BytesPerWord,
+ (c, footprintSizeInBytes(s->footprint),
1 << MemoryOperand, 0, frameIndex));
} else {
unsigned index = ::frameIndex
- (c, s->index + c->localFootprint, s->sizeInWords);
+ (c, s->index + c->localFootprint, s->footprint);
if (footprint == 0) {
assert(c, index >= frameIndex);
s->paddingInWords = index - frameIndex;
popIndex = index;
}
- fprintf(stderr, "stack save read %p of size %d at %d of %d\n", s->value, s->sizeInWords, index, c->alignedFrameSize + c->parameterFootprint);
+// fprintf(stderr, "stack save read %p of footprint %d at %d of %d\n", s->value, s->footprint, index, c->alignedFrameSize + c->parameterFootprint);
addRead(c, this, s->value, read
- (c, s->sizeInWords * BytesPerWord, 1 << MemoryOperand, 0, index));
+ (c, footprintSizeInBytes(s->footprint), 1 << MemoryOperand, 0,
+ index));
}
- frameIndex += s->sizeInWords;
- footprint -= s->sizeInWords;
+ frameIndex += s->footprint;
+ footprint -= s->footprint;
}
for (unsigned li = 0; li < c->localFootprint; ++li) {
Local* local = localsBefore + li;
if (local->value) {
- fprintf(stderr, "local save read %p of size %d at %d of %d\n", local->value, local->sizeInBytes, ::frameIndex(c, li, ceiling(local->sizeInBytes, BytesPerWord)), c->alignedFrameSize + c->parameterFootprint);
+// fprintf(stderr, "local save read %p of footprint %d at %d of %d\n", local->value, local->footprint, ::frameIndex(c, li, local->footprint), c->alignedFrameSize + c->parameterFootprint);
addRead(c, this, local->value, read
- (c, local->sizeInBytes, 1 << MemoryOperand, 0,
- ::frameIndex
- (c, li, ceiling(local->sizeInBytes, BytesPerWord))));
+ (c, footprintSizeInBytes(local->footprint), 1 << MemoryOperand,
+ 0, ::frameIndex(c, li, local->footprint)));
}
}
}
@@ -2345,8 +2364,8 @@ class MoveEvent: public Event {
if (cost == 0) {
target = src->source;
- char dstb[256]; target->toString(c, dstb, 256);
- fprintf(stderr, "null move in %s for %p to %p\n", dstb, src, dst);
+// char dstb[256]; target->toString(c, dstb, 256);
+// fprintf(stderr, "null move in %s for %p to %p\n", dstb, src, dst);
}
if (target == src->source) {
@@ -2370,9 +2389,9 @@ class MoveEvent: public Event {
if (target->match(c, typeMask, registerMask, frameIndex)
and not memoryToMemory)
{
- char srcb[256]; src->source->toString(c, srcb, 256);
- char dstb[256]; target->toString(c, dstb, 256);
- fprintf(stderr, "move %s to %s for %p to %p\n", srcb, dstb, src, dst);
+// char srcb[256]; src->source->toString(c, srcb, 256);
+// char dstb[256]; target->toString(c, dstb, 256);
+// fprintf(stderr, "move %s to %s for %p to %p\n", srcb, dstb, src, dst);
apply(c, type, srcSize, src->source, dstSize, target);
} else {
@@ -2382,9 +2401,9 @@ class MoveEvent: public Event {
addSite(c, stackBefore, localsBefore, dstSize, dst, tmpTarget);
- char srcb[256]; src->source->toString(c, srcb, 256);
- char dstb[256]; tmpTarget->toString(c, dstb, 256);
- fprintf(stderr, "move %s to %s for %p to %p\n", srcb, dstb, src, dst);
+// char srcb[256]; src->source->toString(c, srcb, 256);
+// char dstb[256]; tmpTarget->toString(c, dstb, 256);
+// fprintf(stderr, "move %s to %s for %p to %p\n", srcb, dstb, src, dst);
apply(c, type, srcSize, src->source, dstSize, tmpTarget);
@@ -2393,9 +2412,9 @@ class MoveEvent: public Event {
}
if (memoryToMemory or isStore) {
- char srcb[256]; tmpTarget->toString(c, srcb, 256);
- char dstb[256]; target->toString(c, dstb, 256);
- fprintf(stderr, "move %s to %s for %p to %p\n", srcb, dstb, src, dst);
+// char srcb[256]; tmpTarget->toString(c, srcb, 256);
+// char dstb[256]; target->toString(c, dstb, 256);
+// fprintf(stderr, "move %s to %s for %p to %p\n", srcb, dstb, src, dst);
apply(c, Move, dstSize, tmpTarget, dstSize, target);
} else {
@@ -2585,14 +2604,12 @@ void
removeBuddy(Context* c, Value* v)
{
if (v->buddy != v) {
- fprintf(stderr, "remove buddy %p from", v);
- for (Value* p = v->buddy; p != v; p = p->buddy) {
- fprintf(stderr, " %p", p);
- }
- fprintf(stderr, "\n");
- }
+// fprintf(stderr, "remove buddy %p from", v);
+// for (Value* p = v->buddy; p != v; p = p->buddy) {
+// fprintf(stderr, " %p", p);
+// }
+// fprintf(stderr, "\n");
- if (v->buddy != v) {
Value* next = v->buddy;
v->buddy = v;
Value* p = next;
@@ -2637,9 +2654,11 @@ class Snapshot {
Snapshot*
snapshot(Context* c, Value* value, Snapshot* next)
{
- char buffer[256]; toString(c, value->sites, buffer, 256);
- fprintf(stderr, "snapshot %p buddy %p sites %s\n",
- value, value->buddy, buffer);
+ if (DebugControl) {
+ char buffer[256]; toString(c, value->sites, buffer, 256);
+ fprintf(stderr, "snapshot %p buddy %p sites %s\n",
+ value, value->buddy, buffer);
+ }
return new (c->zone->allocate(sizeof(Snapshot))) Snapshot(c, value, next);
}
@@ -2655,33 +2674,37 @@ Stack*
stack(Context* c, Value* value, unsigned size, Stack* next)
{
return stack
- (c, value, size, (next ? next->index + next->sizeInWords : 0), next);
+ (c, value, size, (next ? next->index + next->footprint : 0), next);
}
Value*
maybeBuddy(Context* c, Value* v, unsigned sizeInBytes);
void
-push(Context* c, unsigned sizeInBytes, Value* v)
+push(Context* c, unsigned footprint, Value* v)
{
- assert(c, ceiling(sizeInBytes, BytesPerWord));
+ assert(c, footprint);
- v = maybeBuddy(c, v, sizeInBytes);
+ v = maybeBuddy(c, v, footprintSizeInBytes(footprint));
- fprintf(stderr, "push %p of size %d\n", v, sizeInBytes);
+ if (DebugFrame) {
+ fprintf(stderr, "push %p of footprint %d\n", v, footprint);
+ }
v->local = true;
- c->stack = stack(c, v, ceiling(sizeInBytes, BytesPerWord), c->stack);
+ c->stack = stack(c, v, footprint, c->stack);
}
Value*
-pop(Context* c, unsigned sizeInBytes UNUSED)
+pop(Context* c, unsigned footprint UNUSED)
{
Stack* s = c->stack;
- assert(c, ceiling(sizeInBytes, BytesPerWord) == s->sizeInWords);
+ assert(c, footprint == s->footprint);
assert(c, s->value->local);
- fprintf(stderr, "pop %p of size %d\n", s->value, sizeInBytes);
+ if (DebugFrame) {
+ fprintf(stderr, "pop %p of size %d\n", s->value, footprint);
+ }
c->stack = s->next;
s->value->local = false;
@@ -2710,8 +2733,8 @@ appendCombine(Context* c, TernaryOperation type,
if (thunk) {
Stack* oldStack = c->stack;
- ::push(c, secondSize, second);
- ::push(c, firstSize, first);
+ ::push(c, ceiling(secondSize, BytesPerWord), second);
+ ::push(c, ceiling(firstSize, BytesPerWord), first);
Stack* argumentStack = c->stack;
c->stack = oldStack;
@@ -3078,7 +3101,7 @@ appendFrameSite(Context* c, Value* value, unsigned size, int index)
unsigned
frameFootprint(Context* c, Stack* s)
{
- return c->localFootprint + (s ? (s->index + s->sizeInWords) : 0);
+ return c->localFootprint + (s ? (s->index + s->footprint) : 0);
}
void
@@ -3130,11 +3153,11 @@ class BuddyEvent: public Event {
while (p->buddy != original) p = p->buddy;
p->buddy = buddy;
- fprintf(stderr, "add buddy %p to ", buddy);
- for (Value* p = buddy->buddy; p != buddy; p = p->buddy) {
- fprintf(stderr, " %p", p);
- }
- fprintf(stderr, "\n");
+// fprintf(stderr, "add buddy %p to", buddy);
+// for (Value* p = buddy->buddy; p != buddy; p = p->buddy) {
+// fprintf(stderr, " %p", p);
+// }
+// fprintf(stderr, "\n");
nextRead(c, this, original);
}
@@ -3192,7 +3215,7 @@ append(Context* c, Event* e)
if (DebugAppend) {
fprintf(stderr, " -- append %s at %d with %d stack before\n",
e->name(), e->logicalInstruction->index, c->stack ?
- c->stack->index + c->stack->sizeInWords : 0);
+ c->stack->index + c->stack->footprint : 0);
}
if (c->lastEvent) {
@@ -3223,7 +3246,7 @@ readSource(Context* c, Stack* stack, Local* locals, Read* r)
{
if (not hasSite(r->value)) return 0;
- fprintf(stderr, "read source for %p\n", r->value);
+// fprintf(stderr, "read source for %p\n", r->value);
Site* site = r->pickSite(c, r->value, true);
@@ -3302,8 +3325,11 @@ resolveJunctionSite(Context* c, Event* e, Value* v,
e->junctionSites[siteIndex] = target->copy(c);
}
- char buffer[256]; target->toString(c, buffer, 256);
- fprintf(stderr, "resolved junction site %d %s %p\n", frameIndex, buffer, v);
+ if (DebugControl) {
+ char buffer[256]; target->toString(c, buffer, 256);
+ fprintf(stderr, "resolved junction site %d %s %p\n",
+ frameIndex, buffer, v);
+ }
}
return frozenSiteIndex;
@@ -3366,8 +3392,10 @@ populateSiteTables(Context* c, Event* e)
}
}
- fprintf(stderr, "resolved junction sites %p at %d\n",
- e->junctionSites, e->logicalInstruction->index);
+ if (DebugControl) {
+ fprintf(stderr, "resolved junction sites %p at %d\n",
+ e->junctionSites, e->logicalInstruction->index);
+ }
for (FrameIterator it(c, e->stackAfter, e->localsAfter); it.hasMore();) {
FrameIterator::Element el = it.next(c);
@@ -3389,8 +3417,10 @@ populateSiteTables(Context* c, Event* e)
}
}
- fprintf(stderr, "captured snapshots %p at %d\n",
- e->snapshots, e->logicalInstruction->index);
+ if (DebugControl) {
+ fprintf(stderr, "captured snapshots %p at %d\n",
+ e->snapshots, e->logicalInstruction->index);
+ }
}
}
@@ -3401,8 +3431,10 @@ setSites(Context* c, Event* e, Value* v, Site* s, unsigned size)
addSite(c, e->stackBefore, e->localsBefore, size, v, s->copy(c));
}
- char buffer[256]; toString(c, v->sites, buffer, 256);
- fprintf(stderr, "set sites %s for %p\n", buffer, v);
+ if (DebugControl) {
+ char buffer[256]; toString(c, v->sites, buffer, 256);
+ fprintf(stderr, "set sites %s for %p\n", buffer, v);
+ }
}
void
@@ -3434,9 +3466,9 @@ void
restore(Context* c, Event* e, Snapshot* snapshots)
{
for (Snapshot* s = snapshots; s; s = s->next) {
- char buffer[256]; toString(c, s->sites, buffer, 256);
- fprintf(stderr, "restore %p buddy %p sites %s\n",
- s->value, s->value->buddy, buffer);
+// char buffer[256]; toString(c, s->sites, buffer, 256);
+// fprintf(stderr, "restore %p buddy %p sites %s\n",
+// s->value, s->value->buddy, buffer);
s->value->buddy = s->buddy;
}
@@ -3479,7 +3511,7 @@ addStubRead(Context* c, Value* v, unsigned size, JunctionState* state,
{
if (v) {
StubRead* r = stubRead(c, size);
- fprintf(stderr, "add stub read %p to %p\n", r, v);
+// fprintf(stderr, "add stub read %p to %p\n", r, v);
addRead(c, 0, v, r);
StubReadPair* p = state->reads + ((*count)++);
@@ -3503,7 +3535,7 @@ populateJunctionReads(Context* c, Link* link)
for (FrameIterator it(c, c->stack, c->locals); it.hasMore();) {
FrameIterator::Element e = it.next(c);
- addStubRead(c, e.value, e.sizeInBytes, state, &count);
+ addStubRead(c, e.value, footprintSizeInBytes(e.footprint), state, &count);
}
state->readCount = count;
@@ -3571,9 +3603,9 @@ compile(Context* c)
countPredecessors(e->predecessors),
countSuccessors(e->successors),
e->stackBefore ?
- e->stackBefore->index + e->stackBefore->sizeInWords : 0,
+ e->stackBefore->index + e->stackBefore->footprint : 0,
e->stackAfter ?
- e->stackAfter->index + e->stackAfter->sizeInWords : 0);
+ e->stackAfter->index + e->stackAfter->footprint : 0);
}
e->block = block;
@@ -3596,12 +3628,19 @@ compile(Context* c)
{
updateJunctionReads(c, pl->junctionState);
}
- fprintf(stderr, "set sites to junction sites %p at %d\n",
- first->junctionSites, first->logicalInstruction->index);
+
+ if (DebugControl) {
+ fprintf(stderr, "set sites to junction sites %p at %d\n",
+ first->junctionSites, first->logicalInstruction->index);
+ }
+
setSites(c, e, first->junctionSites);
} else if (first->successors->nextSuccessor) {
- fprintf(stderr, "restore snapshots %p at %d\n",
- first->snapshots, first->logicalInstruction->index);
+ if (DebugControl) {
+ fprintf(stderr, "restore snapshots %p at %d\n",
+ first->snapshots, first->logicalInstruction->index);
+ }
+
restore(c, e, first->snapshots);
}
}
@@ -3683,7 +3722,7 @@ addMultiRead(Context* c, Value* v, unsigned size, ForkState* state,
unsigned* count)
{
MultiRead* r = multiRead(c, size);
- fprintf(stderr, "add multi read %p to %p\n", r, v);
+// fprintf(stderr, "add multi read %p to %p\n", r, v);
addRead(c, 0, v, r);
ForkElement* p = state->elements + ((*count)++);
@@ -3709,8 +3748,8 @@ saveState(Context* c)
for (FrameIterator it(c, c->stack, c->locals); it.hasMore();) {
FrameIterator::Element e = it.next(c);
- MultiRead* r = multiRead(c, e.sizeInBytes);
- fprintf(stderr, "add multi read %p to %p\n", r, e.value);
+ MultiRead* r = multiRead(c, footprintSizeInBytes(e.footprint));
+// fprintf(stderr, "add multi read %p to %p\n", r, e.value);
addRead(c, 0, e.value, r);
ForkElement* p = state->elements + (count++);
@@ -3848,8 +3887,8 @@ class MyCompiler: public Compiler {
p->successors = link;
c.lastEvent->visitLinks = cons(&c, link, c.lastEvent->visitLinks);
- fprintf(stderr, "populate junction reads for %d to %d\n",
- p->logicalInstruction->index, logicalIp);
+// fprintf(stderr, "populate junction reads for %d to %d\n",
+// p->logicalInstruction->index, logicalIp);
populateJunctionReads(&c, e->predecessors);
}
@@ -3942,28 +3981,28 @@ class MyCompiler: public Compiler {
virtual Operand* stackTop() {
Site* s = frameSite
(&c, frameIndex
- (&c, c.stack->index + c.localFootprint, c.stack->sizeInWords));
+ (&c, c.stack->index + c.localFootprint, c.stack->footprint));
return value(&c, s, s);
}
Promise* machineIp() {
return codePromise(&c, c.logicalCode[c.logicalIp]->lastEvent);
}
- virtual void push(unsigned sizeInBytes) {
- assert(&c, ceiling(sizeInBytes, BytesPerWord));
+ virtual void push(unsigned footprint) {
+ assert(&c, footprint);
Value* v = value(&c);
v->local = true;
- c.stack = ::stack(&c, v, ceiling(sizeInBytes, BytesPerWord), c.stack);
+ c.stack = ::stack(&c, v, footprint, c.stack);
}
- virtual void push(unsigned sizeInBytes, Operand* value) {
- ::push(&c, sizeInBytes, static_cast<Value*>(value));
+ virtual void push(unsigned footprint, Operand* value) {
+ ::push(&c, footprint, static_cast<Value*>(value));
}
- virtual Operand* pop(unsigned sizeInBytes) {
- return ::pop(&c, sizeInBytes);
+ virtual Operand* pop(unsigned footprint) {
+ return ::pop(&c, footprint);
}
virtual void pushed() {
@@ -3985,21 +4024,21 @@ class MyCompiler: public Compiler {
return c.stack;
}
- virtual unsigned size(StackElement* e) {
- return static_cast<Stack*>(e)->sizeInWords;
+ virtual unsigned footprint(StackElement* e) {
+ return static_cast<Stack*>(e)->footprint;
}
virtual unsigned padding(StackElement* e) {
return static_cast<Stack*>(e)->paddingInWords;
}
- virtual Operand* peek(unsigned sizeInBytes UNUSED, unsigned index) {
+ virtual Operand* peek(unsigned footprint UNUSED, unsigned index) {
Stack* s = c.stack;
for (unsigned i = index; i > 0;) {
- i -= s->sizeInWords;
+ i -= s->footprint;
s = s->next;
}
- assert(&c, s->sizeInWords == ceiling(sizeInBytes, BytesPerWord));
+ assert(&c, s->footprint == footprint);
return s->value;
}
@@ -4036,7 +4075,7 @@ class MyCompiler: public Compiler {
Stack* bottomArgument = 0;
for (int i = index - 1; i >= 0; --i) {
- ::push(&c, argumentSizes[i], arguments[i]);
+ ::push(&c, ceiling(argumentSizes[i], BytesPerWord), arguments[i]);
if (i == index - 1) {
bottomArgument = c.stack;
}
@@ -4067,19 +4106,24 @@ class MyCompiler: public Compiler {
appendReturn(&c, size, static_cast<Value*>(value));
}
- virtual void initLocal(unsigned size, unsigned index) {
+ virtual void initLocal(unsigned footprint, unsigned index) {
assert(&c, index < c.localFootprint);
Value* v = value(&c);
- fprintf(stderr, "init local %p of size %d at %d (%d)\n", v, size, index,
- frameIndex(&c, index, ceiling(size, BytesPerWord)));
+
+ if (DebugFrame) {
+ fprintf(stderr, "init local %p of footprint %d at %d (%d)\n",
+ v, footprint, index, frameIndex(&c, index, footprint));
+ }
+
appendFrameSite
- (&c, v, size, frameIndex(&c, index, ceiling(size, BytesPerWord)));
+ (&c, v, footprintSizeInBytes(footprint),
+ frameIndex(&c, index, footprint));
Local* local = c.locals + index;
local->value = v;
v->local = true;
- local->sizeInBytes = size;
+ local->footprint = footprint;
}
virtual void initLocalsFromLogicalIp(unsigned logicalIp) {
@@ -4094,40 +4138,45 @@ class MyCompiler: public Compiler {
for (unsigned i = 0; i < c.localFootprint; ++i) {
Local* local = e->localsBefore + i;
if (local->value) {
- initLocal(local->sizeInBytes, i);
+ initLocal(local->footprint, i);
}
}
}
- virtual void storeLocal(unsigned sizeInBytes, Operand* src, unsigned index) {
+ virtual void storeLocal(unsigned footprint, Operand* src, unsigned index) {
assert(&c, index < c.localFootprint);
Local* local = c.locals + index;
if (local->value) local->value->local = false;
- unsigned footprint = sizeof(Local) * c.localFootprint;
- Local* newLocals = static_cast<Local*>(c.zone->allocate(footprint));
- memcpy(newLocals, c.locals, footprint);
+ unsigned sizeInBytes = sizeof(Local) * c.localFootprint;
+ Local* newLocals = static_cast<Local*>(c.zone->allocate(sizeInBytes));
+ memcpy(newLocals, c.locals, sizeInBytes);
c.locals = newLocals;
local = c.locals + index;
- local->value = maybeBuddy(&c, static_cast<Value*>(src), sizeInBytes);
+ local->value = maybeBuddy
+ (&c, static_cast<Value*>(src), footprintSizeInBytes(footprint));
- fprintf(stderr, "store local %p of size %d at %d\n",
- local->value, sizeInBytes, index);
+ if (DebugFrame) {
+ fprintf(stderr, "store local %p of footprint %d at %d\n",
+ local->value, footprint, index);
+ }
local->value->local = true;
- local->sizeInBytes = sizeInBytes;
+ local->footprint = footprint;
}
- virtual Operand* loadLocal(unsigned sizeInBytes UNUSED, unsigned index) {
+ virtual Operand* loadLocal(unsigned footprint UNUSED, unsigned index) {
assert(&c, index < c.localFootprint);
assert(&c, c.locals[index].value);
assert(&c, c.locals[index].value->local);
- assert(&c, pad(c.locals[index].sizeInBytes) == pad(sizeInBytes));
+ assert(&c, c.locals[index].footprint == footprint);
- fprintf(stderr, "load local %p of size %d at %d\n",
- c.locals[index].value, sizeInBytes, index);
+ if (DebugFrame) {
+ fprintf(stderr, "load local %p of size %d at %d\n",
+ c.locals[index].value, footprint, index);
+ }
return c.locals[index].value;
}
View
15 src/compiler.h
@@ -63,15 +63,15 @@ class Compiler {
virtual Operand* stackTop() = 0;
- virtual void push(unsigned sizeInBytes) = 0;
- virtual void push(unsigned sizeInBytes, Operand* value) = 0;
- virtual Operand* pop(unsigned sizeInBytes) = 0;
+ virtual void push(unsigned footprint) = 0;
+ virtual void push(unsigned footprint, Operand* value) = 0;
+ virtual Operand* pop(unsigned footprint) = 0;
virtual void pushed() = 0;
virtual void popped() = 0;
virtual StackElement* top() = 0;
- virtual unsigned size(StackElement*) = 0;
+ virtual unsigned footprint(StackElement*) = 0;
virtual unsigned padding(StackElement*) = 0;
- virtual Operand* peek(unsigned sizeInBytes, unsigned index) = 0;
+ virtual Operand* peek(unsigned footprint, unsigned index) = 0;
virtual Operand* call(Operand* address,
unsigned flags,
@@ -90,8 +90,9 @@ class Compiler {
virtual void initLocal(unsigned size, unsigned index) = 0;
virtual void initLocalsFromLogicalIp(unsigned logicalIp) = 0;
- virtual void storeLocal(unsigned size, Operand* src, unsigned index) = 0;
- virtual Operand* loadLocal(unsigned size, unsigned index) = 0;
+ virtual void storeLocal(unsigned footprint, Operand* src,
+ unsigned index) = 0;
+ virtual Operand* loadLocal(unsigned footprint, unsigned index) = 0;
virtual void checkBounds(Operand* object, unsigned lengthOffset,
Operand* index, intptr_t handler) = 0;
View
8 test/Simple.java
@@ -1,5 +1,11 @@
public class Simple {
+ public static int size(long v, int radix) {
+ int size = 0;
+ for (long n = v; n != 0; n /= radix) ++size;
+ return size;
+ }
+
public static void main(String[] args) {
- System.out.println(Integer.toString(42));
+ size(42, 10);
}
}

0 comments on commit 1ba497d

Please sign in to comment.
Something went wrong with that request. Please try again.