This commit is contained in:
Joshua Warner 2014-07-16 18:07:56 -06:00 committed by Joshua Warner
parent 1ad1fe9048
commit 31de9a48c9
5 changed files with 165 additions and 181 deletions

View File

@ -25,17 +25,19 @@ class TraceHandler {
virtual void handleTrace(Promise* address, unsigned argumentIndex) = 0; virtual void handleTrace(Promise* address, unsigned argumentIndex) = 0;
}; };
template<size_t N> template <size_t N>
class Args { class Args {
public: public:
ir::Value* values[N]; ir::Value* values[N];
template<class... Ts> template <class... Ts>
Args(Ts... ts) : values{ts...} Args(Ts... ts)
: values{ts...}
{ {
} }
operator util::Slice<ir::Value*> () { operator util::Slice<ir::Value*>()
{
return util::Slice<ir::Value*>(&values[0], N); return util::Slice<ir::Value*>(&values[0], N);
} }
}; };
@ -47,13 +49,14 @@ inline Args<0> args()
inline Args<1> args(ir::Value* first) inline Args<1> args(ir::Value* first)
{ {
return Args<1> { first}; return Args<1>{first};
} }
template<class... Ts> template <class... Ts>
inline Args<1 + util::ArgumentCount<Ts...>::Result> args(ir::Value* first, Ts... rest) inline Args<1 + util::ArgumentCount<Ts...>::Result> args(ir::Value* first,
Ts... rest)
{ {
return Args<1 + util::ArgumentCount<Ts...>::Result> { first, rest... }; return Args<1 + util::ArgumentCount<Ts...>::Result>{first, rest...};
} }
class Compiler { class Compiler {
@ -115,10 +118,10 @@ class Compiler {
virtual ir::Value* peek(unsigned footprint, unsigned index) = 0; virtual ir::Value* peek(unsigned footprint, unsigned index) = 0;
virtual ir::Value* nativeCall(ir::Value* address, virtual ir::Value* nativeCall(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
util::Slice<ir::Value*> arguments) = 0; util::Slice<ir::Value*> arguments) = 0;
virtual ir::Value* stackCall(ir::Value* address, virtual ir::Value* stackCall(ir::Value* address,
unsigned flags, unsigned flags,

View File

@ -31,21 +31,17 @@ struct NonConst {
typedef T Type; typedef T Type;
}; };
template<class... Ts> template <class... Ts>
struct ArgumentCount; struct ArgumentCount;
template<class T, class... Ts> template <class T, class... Ts>
struct ArgumentCount<T, Ts...> { struct ArgumentCount<T, Ts...> {
enum { enum { Result = 1 + ArgumentCount<Ts...>::Result };
Result = 1 + ArgumentCount<Ts...>::Result
};
}; };
template<> template <>
struct ArgumentCount<> { struct ArgumentCount<> {
enum { enum { Result = 0 };
Result = 0
};
}; };
} // namespace util } // namespace util

View File

@ -2535,10 +2535,10 @@ class MyCompiler : public Compiler {
} }
virtual ir::Value* nativeCall(ir::Value* address, virtual ir::Value* nativeCall(ir::Value* address,
unsigned flags, unsigned flags,
TraceHandler* traceHandler, TraceHandler* traceHandler,
ir::Type resultType, ir::Type resultType,
util::Slice<ir::Value*> arguments) util::Slice<ir::Value*> arguments)
{ {
bool bigEndian = c.arch->bigEndian(); bool bigEndian = c.arch->bigEndian();

View File

@ -3084,11 +3084,12 @@ bool useLongJump(MyThread* t, uintptr_t target)
void compileSafePoint(MyThread* t, Compiler* c, Frame* frame) void compileSafePoint(MyThread* t, Compiler* c, Frame* frame)
{ {
c->nativeCall(c->constant(getThunk(t, idleIfNecessaryThunk), ir::Type::iptr()), c->nativeCall(
0, c->constant(getThunk(t, idleIfNecessaryThunk), ir::Type::iptr()),
frame->trace(0, 0), 0,
ir::Type::void_(), frame->trace(0, 0),
args(c->threadRegister())); ir::Type::void_(),
args(c->threadRegister()));
} }
void compileDirectInvoke(MyThread* t, void compileDirectInvoke(MyThread* t,
@ -3258,10 +3259,10 @@ void compileDirectAbstractInvoke(MyThread* t,
compileAbstractInvoke( compileAbstractInvoke(
frame, frame,
c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()), c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::iptr(), ir::Type::iptr(),
args(c->threadRegister(), frame->append(target))), args(c->threadRegister(), frame->append(target))),
target, target,
tailCall); tailCall);
} }
@ -3283,10 +3284,10 @@ void handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function)
} }
c->nativeCall(c->constant(function, ir::Type::iptr()), c->nativeCall(c->constant(function, ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), lock)); args(c->threadRegister(), lock));
} }
} }
@ -3655,8 +3656,9 @@ bool intrinsic(MyThread* t UNUSED, Frame* frame, GcMethod* target)
frame->pop(ir::Type::object()); frame->pop(ir::Type::object());
ir::Type type = MATCH(target->name(), "getInt") ? ir::Type::i4() ir::Type type = MATCH(target->name(), "getInt") ? ir::Type::i4()
: ir::Type::f4(); : ir::Type::f4();
frame->push(type, frame->push(
c->load(ir::ExtendMode::Signed, c->memory(address, type), type)); type,
c->load(ir::ExtendMode::Signed, c->memory(address, type), type));
return true; return true;
} else if ((MATCH(target->name(), "putInt") } else if ((MATCH(target->name(), "putInt")
and MATCH(target->spec(), "(JI)V")) and MATCH(target->spec(), "(JI)V"))
@ -3677,8 +3679,9 @@ bool intrinsic(MyThread* t UNUSED, Frame* frame, GcMethod* target)
frame->pop(ir::Type::object()); frame->pop(ir::Type::object());
ir::Type type = MATCH(target->name(), "getLong") ? ir::Type::i8() ir::Type type = MATCH(target->name(), "getLong") ? ir::Type::i8()
: ir::Type::f8(); : ir::Type::f8();
frame->pushLarge(type, frame->pushLarge(
c->load(ir::ExtendMode::Signed, c->memory(address, type), type)); type,
c->load(ir::ExtendMode::Signed, c->memory(address, type), type));
return true; return true;
} else if ((MATCH(target->name(), "putLong") } else if ((MATCH(target->name(), "putLong")
and MATCH(target->spec(), "(JJ)V")) and MATCH(target->spec(), "(JJ)V"))
@ -3916,11 +3919,12 @@ loop:
frame->pushObject(); frame->pushObject();
c->nativeCall(c->constant(getThunk(t, gcIfNecessaryThunk), ir::Type::iptr()), c->nativeCall(
0, c->constant(getThunk(t, gcIfNecessaryThunk), ir::Type::iptr()),
frame->trace(0, 0), 0,
ir::Type::void_(), frame->trace(0, 0),
args(c->threadRegister())); ir::Type::void_(),
args(c->threadRegister()));
} }
if (DebugInstructions) { if (DebugInstructions) {
@ -4489,8 +4493,7 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), frame->append(field->class_())));
frame->append(field->class_())));
} }
table = frame->append(field->class_()->staticTable()); table = frame->append(field->class_()->staticTable());
@ -4587,12 +4590,11 @@ loop:
if (TargetBytesPerWord == 4 and (field->code() == DoubleField if (TargetBytesPerWord == 4 and (field->code() == DoubleField
or field->code() == LongField)) { or field->code() == LongField)) {
c->nativeCall(c->constant(getThunk(t, releaseMonitorForObjectThunk), c->nativeCall(c->constant(getThunk(t, releaseMonitorForObjectThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), frame->append(field)));
frame->append(field)));
} else { } else {
c->nullaryOp(lir::LoadBarrier); c->nullaryOp(lir::LoadBarrier);
} }
@ -4614,8 +4616,7 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
rType, rType,
args(c->threadRegister(), args(c->threadRegister(), frame->append(pair)));
frame->append(pair)));
} else { } else {
ir::Value* instance = frame->pop(ir::Type::object()); ir::Value* instance = frame->pop(ir::Type::object());
@ -4625,9 +4626,7 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
rType, rType,
args(c->threadRegister(), args(c->threadRegister(), frame->append(pair), instance));
frame->append(pair),
instance));
} }
frame->pushReturnValue(fieldCode, result); frame->pushReturnValue(fieldCode, result);
@ -4918,14 +4917,14 @@ loop:
thunk = instanceOfFromReferenceThunk; thunk = instanceOfFromReferenceThunk;
} }
frame->push(ir::Type::i4(), frame->push(
c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()), ir::Type::i4(),
0, c->nativeCall(
frame->trace(0, 0), c->constant(getThunk(t, thunk), ir::Type::iptr()),
ir::Type::i4(), 0,
args(c->threadRegister(), frame->trace(0, 0),
frame->append(argument), ir::Type::i4(),
instance))); args(c->threadRegister(), frame->append(argument), instance)));
} break; } break;
case invokeinterface: { case invokeinterface: {
@ -4968,12 +4967,12 @@ loop:
ir::Value* result = c->stackCall( ir::Value* result = c->stackCall(
c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()), c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::iptr(), ir::Type::iptr(),
args(c->threadRegister(), args(c->threadRegister(),
frame->append(argument), frame->append(argument),
c->peek(1, parameterFootprint - 1))), c->peek(1, parameterFootprint - 1))),
tailCall ? Compiler::TailJump : 0, tailCall ? Compiler::TailJump : 0,
frame->trace(0, 0), frame->trace(0, 0),
operandTypeForFieldCode(t, returnCode), operandTypeForFieldCode(t, returnCode),
@ -5120,9 +5119,10 @@ loop:
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::iptr(), ir::Type::iptr(),
args(c->threadRegister(), args(c->threadRegister(),
frame->append(pair), frame->append(pair),
c->peek(1, c->peek(1,
methodReferenceParameterFootprint(t, ref, false) - 1))), methodReferenceParameterFootprint(t, ref, false)
- 1))),
ref, ref,
false, false,
isReferenceTailCall(t, code, ip, context->method, ref)); isReferenceTailCall(t, code, ip, context->method, ref));
@ -5250,14 +5250,11 @@ loop:
} else { } else {
frame->push(ir::Type::i4(), frame->push(ir::Type::i4(),
c->nativeCall(c->constant(getThunk(t, compareLongsThunk), c->nativeCall(c->constant(getThunk(t, compareLongsThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
0, 0,
ir::Type::i4(), ir::Type::i4(),
args(nullptr, args(nullptr, a, nullptr, b)));
a,
nullptr,
b)));
} }
} break; } break;
@ -5302,20 +5299,21 @@ loop:
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::object(), ir::Type::object(),
args(c->threadRegister(), args(c->threadRegister(),
frame->append(makePair(t, context->method, reference))))); frame->append(
makePair(t, context->method, reference)))));
} }
} }
if (v) { if (v) {
if (objectClass(t, v) == type(t, GcClass::Type)) { if (objectClass(t, v) == type(t, GcClass::Type)) {
frame->push(ir::Type::object(), frame->push(
c->nativeCall(c->constant(getThunk(t, getJClass64Thunk), ir::Type::object(),
ir::Type::iptr()), c->nativeCall(c->constant(getThunk(t, getJClass64Thunk),
0, ir::Type::iptr()),
frame->trace(0, 0), 0,
ir::Type::object(), frame->trace(0, 0),
args(c->threadRegister(), ir::Type::object(),
frame->append(v)))); args(c->threadRegister(), frame->append(v))));
} else { } else {
frame->push(ir::Type::object(), frame->append(v)); frame->push(ir::Type::object(), frame->append(v));
} }
@ -5535,23 +5533,21 @@ loop:
case monitorenter: { case monitorenter: {
ir::Value* target = frame->pop(ir::Type::object()); ir::Value* target = frame->pop(ir::Type::object());
c->nativeCall(c->constant(getThunk(t, acquireMonitorForObjectThunk), c->nativeCall(c->constant(getThunk(t, acquireMonitorForObjectThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), target));
target));
} break; } break;
case monitorexit: { case monitorexit: {
ir::Value* target = frame->pop(ir::Type::object()); ir::Value* target = frame->pop(ir::Type::object());
c->nativeCall(c->constant(getThunk(t, releaseMonitorForObjectThunk), c->nativeCall(c->constant(getThunk(t, releaseMonitorForObjectThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), target));
target));
} break; } break;
case multianewarray: { case multianewarray: {
@ -5583,13 +5579,13 @@ loop:
ir::Value* result ir::Value* result
= c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()), = c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::object(), ir::Type::object(),
args(c->threadRegister(), args(c->threadRegister(),
frame->append(argument), frame->append(argument),
c->constant(dimensions, ir::Type::i4()), c->constant(dimensions, ir::Type::i4()),
c->constant(offset, ir::Type::i4()))); c->constant(offset, ir::Type::i4())));
frame->popFootprint(dimensions); frame->popFootprint(dimensions);
frame->push(ir::Type::object(), result); frame->push(ir::Type::object(), result);
@ -5620,13 +5616,13 @@ loop:
thunk = makeNewFromReferenceThunk; thunk = makeNewFromReferenceThunk;
} }
frame->push(ir::Type::object(), frame->push(
c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()), ir::Type::object(),
0, c->nativeCall(c->constant(getThunk(t, thunk), ir::Type::iptr()),
frame->trace(0, 0), 0,
ir::Type::object(), frame->trace(0, 0),
args(c->threadRegister(), ir::Type::object(),
frame->append(argument)))); args(c->threadRegister(), frame->append(argument))));
} break; } break;
case newarray: { case newarray: {
@ -5636,13 +5632,13 @@ loop:
frame->push(ir::Type::object(), frame->push(ir::Type::object(),
c->nativeCall(c->constant(getThunk(t, makeBlankArrayThunk), c->nativeCall(c->constant(getThunk(t, makeBlankArrayThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::object(), ir::Type::object(),
args(c->threadRegister(), args(c->threadRegister(),
c->constant(type, ir::Type::i4()), c->constant(type, ir::Type::i4()),
length))); length)));
} break; } break;
case nop: case nop:
@ -5683,8 +5679,7 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), frame->append(field->class_())));
frame->append(field->class_())));
} }
staticTable = field->class_()->staticTable(); staticTable = field->class_()->staticTable();
@ -5703,12 +5698,11 @@ loop:
PROTECT(t, field); PROTECT(t, field);
c->nativeCall(c->constant(getThunk(t, acquireMonitorForObjectThunk), c->nativeCall(c->constant(getThunk(t, acquireMonitorForObjectThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), frame->append(field)));
frame->append(field)));
} else { } else {
c->nullaryOp(lir::StoreStoreBarrier); c->nullaryOp(lir::StoreStoreBarrier);
} }
@ -5779,9 +5773,10 @@ loop:
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(),
table, table,
c->constant(targetFieldOffset(context, field), ir::Type::i4()), c->constant(targetFieldOffset(context, field),
value)); ir::Type::i4()),
value));
} else { } else {
c->nativeCall( c->nativeCall(
c->constant(getThunk(t, setObjectThunk), ir::Type::iptr()), c->constant(getThunk(t, setObjectThunk), ir::Type::iptr()),
@ -5789,9 +5784,10 @@ loop:
0, 0,
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(),
table, table,
c->constant(targetFieldOffset(context, field), ir::Type::i4()), c->constant(targetFieldOffset(context, field),
value)); ir::Type::i4()),
value));
} }
break; break;
@ -5803,12 +5799,11 @@ loop:
if (TargetBytesPerWord == 4 if (TargetBytesPerWord == 4
and (fieldCode == DoubleField or fieldCode == LongField)) { and (fieldCode == DoubleField or fieldCode == LongField)) {
c->nativeCall(c->constant(getThunk(t, releaseMonitorForObjectThunk), c->nativeCall(c->constant(getThunk(t, releaseMonitorForObjectThunk),
ir::Type::iptr()), ir::Type::iptr()),
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
ir::Type::void_(), ir::Type::void_(),
args(c->threadRegister(), args(c->threadRegister(), frame->append(field)));
frame->append(field)));
} else { } else {
c->nullaryOp(lir::StoreLoadBarrier); c->nullaryOp(lir::StoreLoadBarrier);
} }
@ -5837,37 +5832,32 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
rType, rType,
args(c->threadRegister(), args(c->threadRegister(), frame->append(pair), value));
frame->append(pair),
value));
} else { } else {
ir::Value* instance = frame->pop(ir::Type::object()); ir::Value* instance = frame->pop(ir::Type::object());
c->nativeCall(c->constant(getThunk(t, setFieldValueFromReferenceThunk), c->nativeCall(
ir::Type::iptr()), c->constant(getThunk(t, setFieldValueFromReferenceThunk),
0, ir::Type::iptr()),
frame->trace(0, 0), 0,
rType, frame->trace(0, 0),
args(c->threadRegister(), rType,
frame->append(pair), args(
instance, c->threadRegister(), frame->append(pair), instance, value));
value));
} }
} break; } break;
case DoubleField: case DoubleField:
case LongField: { case LongField: {
if (instruction == putstatic) { if (instruction == putstatic) {
c->nativeCall(c->constant( c->nativeCall(
getThunk(t, setStaticLongFieldValueFromReferenceThunk), c->constant(
ir::Type::iptr()), getThunk(t, setStaticLongFieldValueFromReferenceThunk),
0, ir::Type::iptr()),
frame->trace(0, 0), 0,
rType, frame->trace(0, 0),
args(c->threadRegister(), rType,
frame->append(pair), args(c->threadRegister(), frame->append(pair), nullptr, value));
nullptr,
value));
} else { } else {
ir::Value* instance = frame->pop(ir::Type::object()); ir::Value* instance = frame->pop(ir::Type::object());
@ -5878,10 +5868,10 @@ loop:
frame->trace(0, 0), frame->trace(0, 0),
rType, rType,
args(c->threadRegister(), args(c->threadRegister(),
frame->append(pair), frame->append(pair),
instance, instance,
nullptr, nullptr,
value)); value));
} }
} break; } break;
@ -5894,9 +5884,7 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
rType, rType,
args(c->threadRegister(), args(c->threadRegister(), frame->append(pair), value));
frame->append(pair),
value));
} else { } else {
ir::Value* instance = frame->pop(ir::Type::object()); ir::Value* instance = frame->pop(ir::Type::object());
@ -5906,10 +5894,8 @@ loop:
0, 0,
frame->trace(0, 0), frame->trace(0, 0),
rType, rType,
args(c->threadRegister(), args(
frame->append(pair), c->threadRegister(), frame->append(pair), instance, value));
instance,
value));
} }
} break; } break;

View File

@ -1473,7 +1473,6 @@ void writeMap(Output* out, Module& module, Class* cl)
{ {
std::ostringstream ss; std::ostringstream ss;
for (const auto f : cl->fields) { for (const auto f : cl->fields) {
ss << "Type_"; ss << "Type_";
ss << enumName(module, f); ss << enumName(module, f);
if (f->nogc) { if (f->nogc) {