2008-02-19 18:06:52 +00:00
|
|
|
/* Copyright (c) 2008, Avian Contributors
|
|
|
|
|
|
|
|
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. */
|
|
|
|
|
2007-09-24 01:39:03 +00:00
|
|
|
#include "machine.h"
|
2007-12-09 22:45:43 +00:00
|
|
|
#include "util.h"
|
|
|
|
#include "vector.h"
|
2007-09-26 23:23:03 +00:00
|
|
|
#include "process.h"
|
2007-12-09 22:45:43 +00:00
|
|
|
#include "compiler.h"
|
2008-01-01 17:08:47 +00:00
|
|
|
#include "x86.h"
|
2007-09-24 01:39:03 +00:00
|
|
|
|
|
|
|
using namespace vm;
|
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
extern "C" uint64_t
|
2007-12-09 22:45:43 +00:00
|
|
|
vmInvoke(void* thread, void* function, void* stack, unsigned stackSize,
|
2007-09-26 23:23:03 +00:00
|
|
|
unsigned returnType);
|
|
|
|
|
2007-10-04 03:19:39 +00:00
|
|
|
extern "C" void
|
|
|
|
vmCall();
|
|
|
|
|
2007-09-24 01:39:03 +00:00
|
|
|
namespace {
|
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
const bool Verbose = false;
|
2007-12-26 23:59:55 +00:00
|
|
|
const bool DebugNatives = false;
|
2008-04-07 23:47:41 +00:00
|
|
|
const bool DebugCallTable = false;
|
2008-04-11 19:03:40 +00:00
|
|
|
const bool DebugMethodTree = false;
|
2008-01-07 16:01:35 +00:00
|
|
|
const bool DebugFrameMaps = false;
|
2007-12-11 23:52:28 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
const bool CheckArrayBounds = true;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
class MyThread: public Thread {
|
|
|
|
public:
|
|
|
|
class CallTrace {
|
|
|
|
public:
|
|
|
|
CallTrace(MyThread* t):
|
|
|
|
t(t),
|
2007-12-30 22:24:48 +00:00
|
|
|
ip(t->ip),
|
2007-12-09 22:45:43 +00:00
|
|
|
base(t->base),
|
|
|
|
stack(t->stack),
|
2008-04-07 23:47:41 +00:00
|
|
|
nativeMethod(0),
|
2007-12-09 22:45:43 +00:00
|
|
|
next(t->trace)
|
|
|
|
{
|
|
|
|
t->trace = this;
|
2007-12-30 22:24:48 +00:00
|
|
|
t->ip = 0;
|
2007-12-09 22:45:43 +00:00
|
|
|
t->base = 0;
|
|
|
|
t->stack = 0;
|
|
|
|
}
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
~CallTrace() {
|
|
|
|
t->stack = stack;
|
|
|
|
t->base = base;
|
2007-12-30 22:24:48 +00:00
|
|
|
t->ip = ip;
|
2007-12-09 22:45:43 +00:00
|
|
|
t->trace = next;
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyThread* t;
|
2007-12-30 22:24:48 +00:00
|
|
|
void* ip;
|
2007-12-09 22:45:43 +00:00
|
|
|
void* base;
|
|
|
|
void* stack;
|
2008-04-07 23:47:41 +00:00
|
|
|
object nativeMethod;
|
2007-12-09 22:45:43 +00:00
|
|
|
CallTrace* next;
|
|
|
|
};
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyThread(Machine* m, object javaThread, Thread* parent):
|
|
|
|
Thread(m, javaThread, parent),
|
2007-12-30 22:24:48 +00:00
|
|
|
ip(0),
|
2007-12-09 22:45:43 +00:00
|
|
|
base(0),
|
|
|
|
stack(0),
|
|
|
|
trace(0),
|
2008-04-07 23:47:41 +00:00
|
|
|
reference(0)
|
2007-10-03 00:22:48 +00:00
|
|
|
{ }
|
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
void* ip;
|
2007-12-09 22:45:43 +00:00
|
|
|
void* base;
|
|
|
|
void* stack;
|
|
|
|
CallTrace* trace;
|
|
|
|
Reference* reference;
|
|
|
|
};
|
|
|
|
|
|
|
|
object
|
2008-04-07 23:47:41 +00:00
|
|
|
resolveThisPointer(MyThread* t, void* stack, object method)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
return reinterpret_cast<object*>(stack)[methodParameterFootprint(t, method)];
|
|
|
|
}
|
2007-12-23 19:26:35 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
object
|
|
|
|
resolveTarget(MyThread* t, void* stack, object method)
|
|
|
|
{
|
|
|
|
object class_ = objectClass(t, resolveThisPointer(t, stack, method));
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (classVmFlags(t, class_) & BootstrapFlag) {
|
|
|
|
PROTECT(t, method);
|
|
|
|
PROTECT(t, class_);
|
2007-12-31 22:40:56 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
resolveClass(t, className(t, class_));
|
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (classFlags(t, methodClass(t, method)) & ACC_INTERFACE) {
|
|
|
|
return findInterfaceMethod(t, method, class_);
|
|
|
|
} else {
|
|
|
|
return findMethod(t, method, class_);
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
object&
|
|
|
|
methodTree(MyThread* t);
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object
|
2008-04-07 23:47:41 +00:00
|
|
|
methodTreeSentinal(MyThread* t);
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
intptr_t
|
|
|
|
compareIpToMethodBounds(Thread* t, intptr_t ip, object method)
|
|
|
|
{
|
|
|
|
intptr_t start = reinterpret_cast<intptr_t>
|
|
|
|
(&singletonValue(t, methodCompiled(t, method), 0));
|
2008-04-10 23:48:28 +00:00
|
|
|
|
|
|
|
if (DebugMethodTree) {
|
|
|
|
fprintf(stderr, "find 0x%lx in (0x%lx,0x%lx)\n", ip, start,
|
|
|
|
start + (singletonCount(t, methodCompiled(t, method))
|
|
|
|
* BytesPerWord));
|
|
|
|
}
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (ip < start) {
|
|
|
|
return -1;
|
2008-04-10 23:48:28 +00:00
|
|
|
} else if (ip < start + (singletonCount(t, methodCompiled(t, method))
|
|
|
|
* BytesPerWord))
|
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
methodForIp(MyThread* t, void* ip)
|
|
|
|
{
|
2008-04-10 23:48:28 +00:00
|
|
|
if (DebugMethodTree) {
|
|
|
|
fprintf(stderr, "query for method containing %p\n", ip);
|
|
|
|
}
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
return treeQuery(t, methodTree(t), reinterpret_cast<intptr_t>(ip),
|
|
|
|
methodTreeSentinal(t), compareIpToMethodBounds);
|
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
class MyStackWalker: public Processor::StackWalker {
|
|
|
|
public:
|
|
|
|
class MyProtector: public Thread::Protector {
|
|
|
|
public:
|
|
|
|
MyProtector(MyStackWalker* walker):
|
|
|
|
Protector(walker->t), walker(walker)
|
|
|
|
{ }
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual void visit(Heap::Visitor* v) {
|
2008-04-07 23:47:41 +00:00
|
|
|
v->visit(&(walker->method_));
|
2007-12-09 22:45:43 +00:00
|
|
|
v->visit(&(walker->nativeMethod));
|
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyStackWalker* walker;
|
|
|
|
};
|
|
|
|
|
|
|
|
MyStackWalker(MyThread* t):
|
|
|
|
t(t),
|
2008-04-10 23:48:28 +00:00
|
|
|
ip_(t->ip ? t->ip : (t->stack ? *static_cast<void**>(t->stack) : 0)),
|
2007-12-09 22:45:43 +00:00
|
|
|
base(t->base),
|
|
|
|
stack(t->stack),
|
|
|
|
trace(t->trace),
|
2008-04-07 23:47:41 +00:00
|
|
|
nativeMethod(trace->nativeMethod),
|
|
|
|
method_(ip_ ? methodForIp(t, ip_) : 0),
|
2007-12-09 22:45:43 +00:00
|
|
|
protector(this)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
MyStackWalker(MyStackWalker* w):
|
|
|
|
t(w->t),
|
2008-04-10 23:48:28 +00:00
|
|
|
ip_(w->ip_),
|
2007-12-09 22:45:43 +00:00
|
|
|
base(w->base),
|
|
|
|
stack(w->stack),
|
|
|
|
trace(w->trace),
|
|
|
|
nativeMethod(w->nativeMethod),
|
2008-04-07 23:47:41 +00:00
|
|
|
method_(w->method_),
|
2007-12-09 22:45:43 +00:00
|
|
|
protector(this)
|
|
|
|
{ }
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual void walk(Processor::StackVisitor* v) {
|
2007-12-14 18:27:56 +00:00
|
|
|
if (stack == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (not v->visit(this)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (MyStackWalker it(this); it.next();) {
|
|
|
|
MyStackWalker walker(it);
|
|
|
|
if (not v->visit(&walker)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool next() {
|
|
|
|
if (nativeMethod) {
|
|
|
|
nativeMethod = 0;
|
|
|
|
} else {
|
|
|
|
stack = static_cast<void**>(base) + 1;
|
|
|
|
base = *static_cast<void**>(base);
|
2008-04-11 19:03:40 +00:00
|
|
|
ip_ = *static_cast<void**>(stack);
|
2008-04-07 23:47:41 +00:00
|
|
|
method_ = methodForIp(t, *static_cast<void**>(stack));
|
|
|
|
if (method_ == 0) {
|
2007-12-14 18:27:56 +00:00
|
|
|
if (trace and trace->stack) {
|
2007-12-09 22:45:43 +00:00
|
|
|
base = trace->base;
|
|
|
|
stack = static_cast<void**>(trace->stack);
|
2008-04-07 23:47:41 +00:00
|
|
|
nativeMethod = trace->nativeMethod;
|
2007-12-09 22:45:43 +00:00
|
|
|
trace = trace->next;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2007-10-12 17:56:43 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual object method() {
|
|
|
|
if (nativeMethod) {
|
|
|
|
return nativeMethod;
|
|
|
|
} else {
|
2008-04-07 23:47:41 +00:00
|
|
|
return method_;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual int ip() {
|
|
|
|
if (nativeMethod) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
2008-04-07 23:47:41 +00:00
|
|
|
return reinterpret_cast<intptr_t>(ip_) - reinterpret_cast<intptr_t>
|
|
|
|
(&singletonValue(t, methodCompiled(t, method_), 0));
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual unsigned count() {
|
|
|
|
class Visitor: public Processor::StackVisitor {
|
|
|
|
public:
|
|
|
|
Visitor(): count(0) { }
|
|
|
|
|
|
|
|
virtual bool visit(Processor::StackWalker*) {
|
|
|
|
++ count;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned count;
|
|
|
|
} v;
|
|
|
|
|
|
|
|
MyStackWalker walker(this);
|
|
|
|
walker.walk(&v);
|
|
|
|
|
|
|
|
return v.count;
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyThread* t;
|
2008-04-07 23:47:41 +00:00
|
|
|
void* ip_;
|
2007-12-09 22:45:43 +00:00
|
|
|
void* base;
|
|
|
|
void* stack;
|
|
|
|
MyThread::CallTrace* trace;
|
|
|
|
object nativeMethod;
|
2008-04-07 23:47:41 +00:00
|
|
|
object method_;
|
2007-12-09 22:45:43 +00:00
|
|
|
MyProtector protector;
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
localOffset(MyThread* t, int v, object method)
|
|
|
|
{
|
|
|
|
int parameterFootprint = methodParameterFootprint(t, method) * BytesPerWord;
|
|
|
|
|
|
|
|
v *= BytesPerWord;
|
|
|
|
if (v < parameterFootprint) {
|
|
|
|
return (parameterFootprint - v - BytesPerWord) + (BytesPerWord * 2);
|
|
|
|
} else {
|
|
|
|
return -(v + BytesPerWord - parameterFootprint);
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-28 00:02:05 +00:00
|
|
|
inline object*
|
|
|
|
localObject(MyThread* t, void* base, object method, unsigned index)
|
|
|
|
{
|
|
|
|
return reinterpret_cast<object*>
|
|
|
|
(static_cast<uint8_t*>(base) + localOffset(t, index, method));
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
class PoolElement {
|
|
|
|
public:
|
2007-12-31 22:40:56 +00:00
|
|
|
PoolElement(object value, Promise* address, PoolElement* next):
|
|
|
|
value(value), address(address), next(next)
|
2007-12-16 00:24:15 +00:00
|
|
|
{ }
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
object value;
|
2007-12-16 00:24:15 +00:00
|
|
|
Promise* address;
|
2007-12-31 22:40:56 +00:00
|
|
|
PoolElement* next;
|
2007-12-09 22:45:43 +00:00
|
|
|
};
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
class Context;
|
|
|
|
|
|
|
|
class TraceElement: public Compiler::TraceHandler {
|
2007-12-09 22:45:43 +00:00
|
|
|
public:
|
2007-12-31 22:40:56 +00:00
|
|
|
TraceElement(Context* context, object target,
|
|
|
|
bool virtualCall, TraceElement* next):
|
|
|
|
context(context),
|
|
|
|
address(0),
|
|
|
|
target(target),
|
|
|
|
virtualCall(virtualCall),
|
|
|
|
next(next)
|
|
|
|
{ }
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
virtual void handleTrace(Promise* address) {
|
|
|
|
if (this->address == 0) {
|
|
|
|
this->address = address;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Context* context;
|
|
|
|
Promise* address;
|
2008-04-07 23:47:41 +00:00
|
|
|
intptr_t addressValue;
|
2007-12-09 22:45:43 +00:00
|
|
|
object target;
|
|
|
|
bool virtualCall;
|
2007-12-31 22:40:56 +00:00
|
|
|
TraceElement* next;
|
|
|
|
uintptr_t map[0];
|
2007-10-03 00:22:48 +00:00
|
|
|
};
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
inline Stack*
|
|
|
|
push(Compiler* c, Stack* s, Operand* v)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
return c->push8(s, v);
|
|
|
|
} else {
|
|
|
|
return c->push4(s, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Stack*
|
|
|
|
pop(Compiler* c, Stack* s, Operand* v)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
return c->pop8(s, v);
|
|
|
|
} else {
|
|
|
|
return c->pop4(s, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
mov(Compiler* c, Operand* src, Operand* dst)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
c->mov8(src, dst);
|
|
|
|
} else {
|
|
|
|
c->mov4(src, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Operand*
|
|
|
|
result(Compiler* c)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
return c->result8();
|
|
|
|
} else {
|
|
|
|
return c->result4();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
returnW(Compiler* c, Operand* v)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
c->return8(v);
|
|
|
|
} else {
|
|
|
|
c->return4(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
cmp(Compiler* c, Operand* src, Operand* dst)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
c->cmp8(src, dst);
|
|
|
|
} else {
|
|
|
|
c->cmp4(src, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
and_(Compiler* c, Operand* src, Operand* dst)
|
|
|
|
{
|
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
c->and8(src, dst);
|
|
|
|
} else {
|
|
|
|
c->and4(src, dst);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
enum Event {
|
|
|
|
PushEvent,
|
|
|
|
PopEvent,
|
|
|
|
IpEvent,
|
|
|
|
MarkEvent,
|
|
|
|
ClearEvent,
|
|
|
|
TraceEvent
|
|
|
|
};
|
|
|
|
|
2008-01-20 18:55:08 +00:00
|
|
|
unsigned
|
|
|
|
localSize(MyThread* t, object method)
|
|
|
|
{
|
|
|
|
unsigned size = codeMaxLocals(t, methodCode(t, method));
|
2008-01-20 22:05:59 +00:00
|
|
|
if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC))
|
|
|
|
== ACC_SYNCHRONIZED)
|
|
|
|
{
|
2008-01-20 18:55:08 +00:00
|
|
|
++ size;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned
|
|
|
|
frameSize(MyThread* t, object method)
|
|
|
|
{
|
2008-01-20 18:55:08 +00:00
|
|
|
return localSize(t, method) + codeMaxStack(t, methodCode(t, method));
|
2008-01-07 14:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
stackMapSizeInWords(MyThread* t, object method)
|
|
|
|
{
|
|
|
|
return ceiling(codeMaxStack(t, methodCode(t, method)), BitsPerWord)
|
|
|
|
* BytesPerWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
frameMapSizeInWords(MyThread* t, object method)
|
|
|
|
{
|
|
|
|
return ceiling(frameSize(t, method), BitsPerWord) * BytesPerWord;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t*
|
|
|
|
makeVisitTable(MyThread* t, Zone* zone, object method)
|
|
|
|
{
|
|
|
|
unsigned size = codeLength(t, methodCode(t, method)) * 2;
|
|
|
|
uint16_t* table = static_cast<uint16_t*>(zone->allocate(size));
|
|
|
|
memset(table, 0, size);
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t*
|
2008-01-08 15:24:57 +00:00
|
|
|
makeRootTable(MyThread* t, Zone* zone, object method)
|
2008-01-07 14:51:07 +00:00
|
|
|
{
|
|
|
|
unsigned size = frameMapSizeInWords(t, method)
|
|
|
|
* codeLength(t, methodCode(t, method))
|
|
|
|
* BytesPerWord;
|
|
|
|
uintptr_t* table = static_cast<uintptr_t*>(zone->allocate(size));
|
2008-01-08 15:24:57 +00:00
|
|
|
memset(table, 0xFF, size);
|
2008-01-07 14:51:07 +00:00
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
class Context {
|
2007-10-10 22:39:40 +00:00
|
|
|
public:
|
2007-12-09 22:45:43 +00:00
|
|
|
class MyProtector: public Thread::Protector {
|
|
|
|
public:
|
2007-12-31 22:40:56 +00:00
|
|
|
MyProtector(Context* c): Protector(c->t), c(c) { }
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
virtual void visit(Heap::Visitor* v) {
|
2007-12-31 22:40:56 +00:00
|
|
|
v->visit(&(c->method));
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
for (PoolElement* p = c->objectPool; p; p = p->next) {
|
|
|
|
v->visit(&(p->value));
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
for (TraceElement* p = c->traceLog; p; p = p->next) {
|
|
|
|
v->visit(&(p->target));
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
Context* c;
|
2007-10-10 22:39:40 +00:00
|
|
|
};
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
Context(MyThread* t, object method, uint8_t* indirectCaller):
|
2007-10-10 22:39:40 +00:00
|
|
|
t(t),
|
2008-01-14 23:37:24 +00:00
|
|
|
zone(t->m->system, t->m->heap, false, 16 * 1024),
|
|
|
|
c(makeCompiler(t->m->system, t->m->heap, &zone, indirectCaller)),
|
2007-10-10 22:39:40 +00:00
|
|
|
method(method),
|
2007-12-31 22:40:56 +00:00
|
|
|
objectPool(0),
|
|
|
|
traceLog(0),
|
2008-04-07 23:47:41 +00:00
|
|
|
traceLogCount(0),
|
2008-01-07 14:51:07 +00:00
|
|
|
visitTable(makeVisitTable(t, &zone, method)),
|
2008-01-08 15:24:57 +00:00
|
|
|
rootTable(makeRootTable(t, &zone, method)),
|
2008-01-14 23:37:24 +00:00
|
|
|
eventLog(t->m->system, t->m->heap, 1024),
|
2007-12-31 22:40:56 +00:00
|
|
|
protector(this)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Context(MyThread* t):
|
|
|
|
t(t),
|
2008-01-14 23:37:24 +00:00
|
|
|
zone(t->m->system, t->m->heap, false, LikelyPageSizeInBytes),
|
|
|
|
c(makeCompiler(t->m->system, t->m->heap, &zone, 0)),
|
2007-12-31 22:40:56 +00:00
|
|
|
method(0),
|
|
|
|
objectPool(0),
|
|
|
|
traceLog(0),
|
2008-04-07 23:47:41 +00:00
|
|
|
traceLogCount(0),
|
2008-01-07 14:51:07 +00:00
|
|
|
visitTable(0),
|
|
|
|
rootTable(0),
|
2008-01-14 23:37:24 +00:00
|
|
|
eventLog(t->m->system, t->m->heap, 0),
|
2007-12-31 22:40:56 +00:00
|
|
|
protector(this)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~Context() {
|
|
|
|
c->dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
MyThread* t;
|
|
|
|
Zone zone;
|
|
|
|
Compiler* c;
|
|
|
|
object method;
|
|
|
|
PoolElement* objectPool;
|
|
|
|
TraceElement* traceLog;
|
2008-04-07 23:47:41 +00:00
|
|
|
unsigned traceLogCount;
|
2008-01-07 14:51:07 +00:00
|
|
|
uint16_t* visitTable;
|
|
|
|
uintptr_t* rootTable;
|
2008-03-05 21:44:17 +00:00
|
|
|
bool dirtyRoots;
|
2008-01-07 14:51:07 +00:00
|
|
|
Vector eventLog;
|
2007-12-31 22:40:56 +00:00
|
|
|
MyProtector protector;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Frame {
|
|
|
|
public:
|
2008-01-07 14:51:07 +00:00
|
|
|
Frame(Context* context, uintptr_t* stackMap):
|
2007-12-31 22:40:56 +00:00
|
|
|
context(context),
|
|
|
|
t(context->t),
|
|
|
|
c(context->c),
|
|
|
|
stack(0),
|
2008-01-07 14:51:07 +00:00
|
|
|
stackMap(stackMap),
|
2007-12-09 22:45:43 +00:00
|
|
|
ip(0),
|
2008-01-07 16:01:35 +00:00
|
|
|
sp(localSize()),
|
2008-01-07 14:51:07 +00:00
|
|
|
level(0)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-01-07 14:51:07 +00:00
|
|
|
memset(stackMap, 0,
|
|
|
|
stackMapSizeInWords(t, context->method) * BytesPerWord);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 16:01:35 +00:00
|
|
|
Frame(Frame* f, uintptr_t* stackMap):
|
2007-12-31 22:40:56 +00:00
|
|
|
context(f->context),
|
|
|
|
t(context->t),
|
|
|
|
c(context->c),
|
2007-12-16 00:24:15 +00:00
|
|
|
stack(f->stack),
|
2008-01-07 14:51:07 +00:00
|
|
|
stackMap(stackMap),
|
2007-12-09 22:45:43 +00:00
|
|
|
ip(f->ip),
|
2008-01-07 14:51:07 +00:00
|
|
|
sp(f->sp),
|
|
|
|
level(f->level + 1)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-01-07 14:51:07 +00:00
|
|
|
memcpy(stackMap, f->stackMap,
|
|
|
|
stackMapSizeInWords(t, context->method) * BytesPerWord);
|
|
|
|
|
|
|
|
if (level > 1) {
|
|
|
|
context->eventLog.append(PushEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Frame() {
|
|
|
|
if (level > 1 and t->exception == 0) {
|
|
|
|
context->eventLog.append(PopEvent);
|
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* append(object o) {
|
2007-12-16 00:24:15 +00:00
|
|
|
Promise* p = c->poolAppend(0);
|
2007-12-31 22:40:56 +00:00
|
|
|
context->objectPool = new
|
|
|
|
(context->zone.allocate(sizeof(PoolElement)))
|
|
|
|
PoolElement(o, p, context->objectPool);
|
2007-12-16 00:24:15 +00:00
|
|
|
return c->absolute(p);
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned localSize() {
|
2008-01-20 18:55:08 +00:00
|
|
|
return ::localSize(t, context->method);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned stackSize() {
|
|
|
|
return codeMaxStack(t, methodCode(t, context->method));
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned frameSize() {
|
|
|
|
return localSize() + stackSize();
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2008-01-07 16:01:35 +00:00
|
|
|
void mark(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < frameSize());
|
2007-10-10 22:39:40 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
context->eventLog.append(MarkEvent);
|
|
|
|
context->eventLog.append2(index);
|
|
|
|
|
|
|
|
int si = index - localSize();
|
|
|
|
if (si >= 0) {
|
|
|
|
markBit(stackMap, si);
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 16:01:35 +00:00
|
|
|
void clear(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < frameSize());
|
|
|
|
|
|
|
|
context->eventLog.append(ClearEvent);
|
|
|
|
context->eventLog.append2(index);
|
|
|
|
|
|
|
|
int si = index - localSize();
|
|
|
|
if (si >= 0) {
|
|
|
|
clearBit(stackMap, si);
|
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 16:01:35 +00:00
|
|
|
unsigned get(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < frameSize());
|
|
|
|
int si = index - localSize();
|
|
|
|
assert(t, si >= 0);
|
|
|
|
return getBit(stackMap, si);
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pushedInt() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 1 <= frameSize());
|
|
|
|
assert(t, get(sp) == 0);
|
2007-12-09 22:45:43 +00:00
|
|
|
++ sp;
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pushedObject() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 1 <= frameSize());
|
|
|
|
mark(sp++);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-12-12 22:19:13 +00:00
|
|
|
|
|
|
|
void popped(unsigned count) {
|
|
|
|
assert(t, sp >= count);
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp - count >= localSize());
|
2007-12-12 22:19:13 +00:00
|
|
|
while (count) {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(-- sp);
|
2007-12-12 22:19:13 +00:00
|
|
|
-- count;
|
|
|
|
}
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
void poppedInt() {
|
|
|
|
assert(t, sp >= 1);
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp - 1 >= localSize());
|
|
|
|
assert(t, get(sp - 1) == 0);
|
2007-12-09 22:45:43 +00:00
|
|
|
-- sp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void poppedObject() {
|
|
|
|
assert(t, sp >= 1);
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp - 1 >= localSize());
|
|
|
|
assert(t, get(sp - 1) != 0);
|
|
|
|
clear(-- sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void storedInt(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < localSize());
|
|
|
|
clear(index);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void storedObject(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < localSize());
|
|
|
|
mark(index);
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dupped() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 1 <= frameSize());
|
|
|
|
assert(t, sp - 1 >= localSize());
|
|
|
|
if (get(sp - 1)) {
|
|
|
|
mark(sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
++ sp;
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 17:21:26 +00:00
|
|
|
void duppedX1() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 1 <= frameSize());
|
|
|
|
assert(t, sp - 2 >= localSize());
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned b2 = get(sp - 2);
|
|
|
|
unsigned b1 = get(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
if (b2) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b1) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 2);
|
|
|
|
mark(sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++ sp;
|
2007-10-16 17:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void duppedX2() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 1 <= frameSize());
|
|
|
|
assert(t, sp - 3 >= localSize());
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned b3 = get(sp - 3);
|
|
|
|
unsigned b2 = get(sp - 2);
|
|
|
|
unsigned b1 = get(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
if (b3) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b2) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b1) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 3);
|
|
|
|
mark(sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 3);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++ sp;
|
2007-10-16 17:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dupped2() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 2 <= frameSize());
|
|
|
|
assert(t, sp - 2 >= localSize());
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned b2 = get(sp - 2);
|
|
|
|
unsigned b1 = get(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
if (b2) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b1) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp + 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp += 2;
|
2007-10-16 17:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dupped2X1() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 2 <= frameSize());
|
|
|
|
assert(t, sp - 3 >= localSize());
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned b3 = get(sp - 3);
|
|
|
|
unsigned b2 = get(sp - 2);
|
|
|
|
unsigned b1 = get(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
if (b3) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b2) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 3);
|
|
|
|
mark(sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 3);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b1) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 2);
|
|
|
|
mark(sp + 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sp += 2;
|
2007-10-16 17:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dupped2X2() {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp + 2 <= frameSize());
|
|
|
|
assert(t, sp - 4 >= localSize());
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned b4 = get(sp - 4);
|
|
|
|
unsigned b3 = get(sp - 3);
|
|
|
|
unsigned b2 = get(sp - 2);
|
|
|
|
unsigned b1 = get(sp - 1);
|
2007-10-12 00:30:46 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (b4) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (b3) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (b2) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 4);
|
|
|
|
mark(sp);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 4);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (b1) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 3);
|
|
|
|
mark(sp + 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 3);
|
2007-10-13 21:48:40 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
sp += 2;
|
2007-10-13 21:48:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void swapped() {
|
2008-01-07 16:01:35 +00:00
|
|
|
assert(t, sp - 2 >= localSize());
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
bool savedBit = get(sp - 1);
|
|
|
|
if (get(sp - 2)) {
|
|
|
|
mark(sp - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 1);
|
2007-10-13 21:48:40 +00:00
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (savedBit) {
|
2008-01-07 14:51:07 +00:00
|
|
|
mark(sp - 2);
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-01-07 14:51:07 +00:00
|
|
|
clear(sp - 2);
|
2007-10-13 21:48:40 +00:00
|
|
|
}
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* machineIp(unsigned logicalIp) {
|
|
|
|
return c->promiseConstant(c->machineIp(logicalIp));
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
void visitLogicalIp(unsigned ip) {
|
|
|
|
context->eventLog.append(IpEvent);
|
2008-01-07 16:01:35 +00:00
|
|
|
context->eventLog.append2(ip);
|
2008-01-07 14:51:07 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void startLogicalIp(unsigned ip) {
|
|
|
|
c->startLogicalIp(ip);
|
|
|
|
this->ip = ip;
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
void topIntToLong() {
|
|
|
|
dup();
|
|
|
|
if (BytesPerWord == 4) {
|
|
|
|
c->mov4To8(c->stack(stack, 0), c->stack(stack, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void topLongToInt() {
|
|
|
|
mov(c, c->stack(stack, 0), c->stack(stack, 1));
|
|
|
|
stack = c->pop(stack, 1);
|
|
|
|
poppedInt();
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void pushInt(Operand* o) {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, o);
|
|
|
|
pushedInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushInt1(Operand* o) {
|
|
|
|
stack = c->push1(stack, o);
|
|
|
|
pushedInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushInt2(Operand* o) {
|
|
|
|
stack = c->push2(stack, o);
|
|
|
|
pushedInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushInt2z(Operand* o) {
|
|
|
|
stack = c->push2z(stack, o);
|
|
|
|
pushedInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void pushInt4(Operand* o) {
|
|
|
|
stack = c->push4(stack, o);
|
2007-12-09 22:45:43 +00:00
|
|
|
pushedInt();
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
void pushAddress(Operand* o) {
|
|
|
|
stack = push(c, stack, o);
|
|
|
|
pushedInt();
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void pushObject(Operand* o) {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, o);
|
2007-12-09 22:45:43 +00:00
|
|
|
pushedObject();
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
void pushObject() {
|
2007-12-17 20:55:31 +00:00
|
|
|
stack = c->pushed(stack, 1);
|
2007-12-12 22:19:13 +00:00
|
|
|
pushedObject();
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void pushLong(Operand* o) {
|
2007-12-16 21:30:19 +00:00
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
stack = c->push(stack, 1);
|
|
|
|
}
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = c->push8(stack, o);
|
2007-12-16 21:30:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
pushedInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
pushedInt();
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void pop(unsigned count) {
|
2007-12-12 22:19:13 +00:00
|
|
|
popped(count);
|
2007-12-16 00:24:15 +00:00
|
|
|
stack = c->pop(stack, count);
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* topInt() {
|
|
|
|
assert(t, sp >= 1);
|
2008-01-07 16:01:35 +00:00
|
|
|
assert(t, sp - 1 >= localSize());
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, get(sp - 1) == 0);
|
2007-12-16 00:24:15 +00:00
|
|
|
return c->stack(stack, 0);
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* topLong() {
|
|
|
|
assert(t, sp >= 2);
|
2008-01-07 16:01:35 +00:00
|
|
|
assert(t, sp - 2 >= localSize());
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, get(sp - 1) == 0);
|
|
|
|
assert(t, get(sp - 2) == 0);
|
2007-12-23 00:00:35 +00:00
|
|
|
return c->stack(stack, 0);
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* topObject() {
|
|
|
|
assert(t, sp >= 1);
|
2008-01-07 16:01:35 +00:00
|
|
|
assert(t, sp - 1 >= localSize());
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, get(sp - 1) != 0);
|
2007-12-16 00:24:15 +00:00
|
|
|
return c->stack(stack, 0);
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* popInt() {
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* tmp = c->temporary();
|
2007-12-16 00:24:15 +00:00
|
|
|
popInt(tmp);
|
|
|
|
return tmp;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* popInt4() {
|
|
|
|
Operand* tmp = c->temporary();
|
|
|
|
popInt4(tmp);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* popLong() {
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* tmp = c->temporary();
|
2007-12-16 00:24:15 +00:00
|
|
|
popLong(tmp);
|
|
|
|
return tmp;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* popObject() {
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* tmp = c->temporary();
|
|
|
|
popObject(tmp);
|
|
|
|
return tmp;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void popInt(Operand* o) {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = ::pop(c, stack, o);
|
2007-12-09 22:45:43 +00:00
|
|
|
poppedInt();
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
void popInt4(Operand* o) {
|
|
|
|
stack = c->pop4(stack, o);
|
|
|
|
poppedInt();
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void popLong(Operand* o) {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = c->pop8(stack, o);
|
2007-12-16 21:30:19 +00:00
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
stack = c->pop(stack, 1);
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
poppedInt();
|
|
|
|
poppedInt();
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void popObject(Operand* o) {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = ::pop(c, stack, o);
|
2007-12-09 22:45:43 +00:00
|
|
|
poppedObject();
|
2007-10-11 22:43:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void loadInt(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < localSize());
|
2007-12-31 22:40:56 +00:00
|
|
|
pushInt(c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void loadLong(unsigned index) {
|
2007-12-11 23:52:28 +00:00
|
|
|
assert(t, index < static_cast<unsigned>
|
2008-01-07 14:51:07 +00:00
|
|
|
(localSize() - 1));
|
2007-12-31 22:40:56 +00:00
|
|
|
pushLong(c->memory(c->base(), localOffset(t, index + 1, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void loadObject(unsigned index) {
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, index < localSize());
|
2007-12-31 22:40:56 +00:00
|
|
|
pushObject(c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void storeInt(unsigned index) {
|
2007-12-31 22:40:56 +00:00
|
|
|
popInt(c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
storedInt(index);
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void storeLong(unsigned index) {
|
2007-12-31 22:40:56 +00:00
|
|
|
popLong(c->memory(c->base(), localOffset(t, index + 1, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
storedInt(index);
|
|
|
|
storedInt(index + 1);
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void storeObject(unsigned index) {
|
2007-12-31 22:40:56 +00:00
|
|
|
popObject(c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
storedObject(index);
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
void storeObjectOrAddress(unsigned index) {
|
|
|
|
stack = ::pop
|
2007-12-31 22:40:56 +00:00
|
|
|
(c, stack, c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-12-26 23:59:55 +00:00
|
|
|
|
|
|
|
assert(t, sp >= 1);
|
2008-01-07 14:51:07 +00:00
|
|
|
assert(t, sp - 1 >= localSize());
|
|
|
|
if (get(sp - 1)) {
|
2007-12-26 23:59:55 +00:00
|
|
|
storedObject(index);
|
|
|
|
} else {
|
|
|
|
storedInt(index);
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
popped(1);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void dup() {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 0));
|
2007-12-09 22:45:43 +00:00
|
|
|
dupped();
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void dupX1() {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 0));
|
|
|
|
mov(c, c->stack(stack, 2), c->stack(stack, 1));
|
|
|
|
mov(c, c->stack(stack, 0), c->stack(stack, 2));
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
duppedX1();
|
|
|
|
}
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void dupX2() {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 0));
|
|
|
|
mov(c, c->stack(stack, 2), c->stack(stack, 1));
|
|
|
|
mov(c, c->stack(stack, 3), c->stack(stack, 2));
|
|
|
|
mov(c, c->stack(stack, 0), c->stack(stack, 3));
|
2007-10-11 22:43:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
duppedX2();
|
2007-10-10 22:39:40 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void dup2() {
|
2007-12-26 23:59:55 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 1));
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 1));
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
dupped2();
|
|
|
|
}
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void dup2X1() {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 1));
|
|
|
|
stack = push(c, stack, c->stack(stack, 1));
|
|
|
|
mov(c, c->stack(stack, 4), c->stack(stack, 2));
|
|
|
|
mov(c, c->stack(stack, 1), c->stack(stack, 4));
|
|
|
|
mov(c, c->stack(stack, 0), c->stack(stack, 3));
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
dupped2X1();
|
2007-10-18 00:41:49 +00:00
|
|
|
}
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void dup2X2() {
|
2007-12-26 16:56:14 +00:00
|
|
|
stack = push(c, stack, c->stack(stack, 1));
|
|
|
|
stack = push(c, stack, c->stack(stack, 1));
|
|
|
|
mov(c, c->stack(stack, 5), c->stack(stack, 3));
|
|
|
|
mov(c, c->stack(stack, 4), c->stack(stack, 2));
|
|
|
|
mov(c, c->stack(stack, 1), c->stack(stack, 5));
|
|
|
|
mov(c, c->stack(stack, 0), c->stack(stack, 4));
|
2007-10-02 00:08:17 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
dupped2X2();
|
|
|
|
}
|
2007-10-02 00:08:17 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void swap() {
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* s0 = c->stack(stack, 0);
|
|
|
|
Operand* s1 = c->stack(stack, 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* tmp = c->temporary();
|
2007-10-02 00:08:17 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
mov(c, s0, tmp);
|
|
|
|
mov(c, s1, s0);
|
|
|
|
mov(c, tmp, s1);
|
2007-10-02 00:08:17 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->release(tmp);
|
2007-10-02 00:08:17 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
swapped();
|
2007-10-02 00:08:17 +00:00
|
|
|
}
|
2007-12-31 22:40:56 +00:00
|
|
|
|
|
|
|
TraceElement* trace(object target, bool virtualCall) {
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned mapSize = frameMapSizeInWords(t, context->method);
|
2007-12-31 22:40:56 +00:00
|
|
|
|
|
|
|
TraceElement* e = context->traceLog = new
|
|
|
|
(context->zone.allocate(sizeof(TraceElement) + (mapSize * BytesPerWord)))
|
|
|
|
TraceElement(context, target, virtualCall, context->traceLog);
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
++ context->traceLogCount;
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
context->eventLog.append(TraceEvent);
|
|
|
|
context->eventLog.appendAddress(e);
|
2007-12-31 22:40:56 +00:00
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
Context* context;
|
2007-12-09 22:45:43 +00:00
|
|
|
MyThread* t;
|
|
|
|
Compiler* c;
|
2007-12-16 00:24:15 +00:00
|
|
|
Stack* stack;
|
2008-01-07 14:51:07 +00:00
|
|
|
uintptr_t* stackMap;
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned ip;
|
|
|
|
unsigned sp;
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned level;
|
2007-12-30 22:24:48 +00:00
|
|
|
};
|
|
|
|
|
2008-01-20 18:55:08 +00:00
|
|
|
unsigned
|
|
|
|
savedTargetIndex(MyThread* t, object method)
|
|
|
|
{
|
|
|
|
return codeMaxLocals(t, methodCode(t, method));
|
|
|
|
}
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
object
|
|
|
|
findCallNode(MyThread* t, void* address);
|
|
|
|
|
|
|
|
void
|
|
|
|
insertCallNode(MyThread* t, object node);
|
|
|
|
|
|
|
|
void
|
|
|
|
removeCallNode(MyThread* t, object node);
|
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
void*
|
|
|
|
findExceptionHandler(Thread* t, object method, void* ip)
|
|
|
|
{
|
|
|
|
PROTECT(t, method);
|
|
|
|
|
|
|
|
object table = codeExceptionHandlerTable(t, methodCode(t, method));
|
|
|
|
if (table) {
|
|
|
|
object index = arrayBody(t, table, 0);
|
|
|
|
|
|
|
|
uint8_t* compiled = reinterpret_cast<uint8_t*>
|
|
|
|
(&singletonValue(t, methodCompiled(t, method), 0));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < arrayLength(t, table) - 1; ++i) {
|
|
|
|
unsigned start = intArrayBody(t, index, i * 3);
|
|
|
|
unsigned end = intArrayBody(t, index, (i * 3) + 1);
|
|
|
|
unsigned key = difference(ip, compiled) - 1;
|
|
|
|
|
|
|
|
if (key >= start and key < end) {
|
|
|
|
object catchType = 0;
|
|
|
|
if (arrayBody(t, table, i + 1)) {
|
|
|
|
object e = t->exception;
|
|
|
|
t->exception = 0;
|
|
|
|
PROTECT(t, e);
|
|
|
|
|
|
|
|
PROTECT(t, table);
|
|
|
|
PROTECT(t, index);
|
|
|
|
|
|
|
|
catchType = resolveClassInObject
|
|
|
|
(t, table, ArrayBody + ((i + 1) * BytesPerWord));
|
|
|
|
|
|
|
|
if (catchType) {
|
|
|
|
t->exception = e;
|
|
|
|
} else {
|
|
|
|
// can't find what we're supposed to catch - move on.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (catchType == 0 or instanceOf(t, catchType, t->exception)) {
|
|
|
|
return compiled + intArrayBody(t, index, (i * 3) + 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-01 17:08:47 +00:00
|
|
|
void
|
|
|
|
findUnwindTarget(MyThread* t, void** targetIp, void** targetBase,
|
|
|
|
void** targetStack)
|
2007-09-29 21:08:29 +00:00
|
|
|
{
|
2007-12-30 22:24:48 +00:00
|
|
|
void* ip = t->ip;
|
2007-12-09 22:45:43 +00:00
|
|
|
void* base = t->base;
|
|
|
|
void** stack = static_cast<void**>(t->stack);
|
2007-12-31 22:40:56 +00:00
|
|
|
if (ip) {
|
|
|
|
t->ip = 0;
|
|
|
|
} else {
|
2007-12-30 22:24:48 +00:00
|
|
|
ip = *stack;
|
|
|
|
}
|
|
|
|
|
2008-01-01 17:08:47 +00:00
|
|
|
*targetIp = 0;
|
|
|
|
while (*targetIp == 0) {
|
2008-04-07 23:47:41 +00:00
|
|
|
object method = methodForIp(t, ip);
|
|
|
|
if (method) {
|
2008-01-14 16:33:26 +00:00
|
|
|
PROTECT(t, method);
|
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
void* handler = findExceptionHandler(t, method, ip);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
if (handler) {
|
2007-10-04 22:41:19 +00:00
|
|
|
unsigned parameterFootprint = methodParameterFootprint(t, method);
|
2008-01-20 18:55:08 +00:00
|
|
|
unsigned localFootprint = localSize(t, method);
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-16 01:00:25 +00:00
|
|
|
stack = static_cast<void**>(base)
|
|
|
|
- (localFootprint - parameterFootprint);
|
2007-10-04 22:41:19 +00:00
|
|
|
|
|
|
|
*(--stack) = t->exception;
|
|
|
|
t->exception = 0;
|
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
*targetIp = handler;
|
2008-01-01 17:08:47 +00:00
|
|
|
*targetBase = base;
|
|
|
|
*targetStack = stack;
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2007-12-28 00:02:05 +00:00
|
|
|
if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
|
|
|
|
object lock;
|
|
|
|
if (methodFlags(t, method) & ACC_STATIC) {
|
|
|
|
lock = methodClass(t, method);
|
|
|
|
} else {
|
2008-01-20 18:55:08 +00:00
|
|
|
lock = *localObject(t, base, method, savedTargetIndex(t, method));
|
2007-12-28 00:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
release(t, lock);
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
stack = static_cast<void**>(base) + 1;
|
2007-12-30 22:24:48 +00:00
|
|
|
ip = *stack;
|
2007-12-09 22:45:43 +00:00
|
|
|
base = *static_cast<void**>(base);
|
2007-10-12 17:56:43 +00:00
|
|
|
}
|
2007-10-12 22:06:33 +00:00
|
|
|
} else {
|
2008-01-01 17:08:47 +00:00
|
|
|
*targetIp = ip;
|
|
|
|
*targetBase = base;
|
|
|
|
*targetStack = stack + 1;
|
2007-10-12 17:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-01 17:08:47 +00:00
|
|
|
void NO_RETURN
|
|
|
|
unwind(MyThread* t)
|
|
|
|
{
|
|
|
|
void* ip;
|
|
|
|
void* base;
|
|
|
|
void* stack;
|
|
|
|
findUnwindTarget(t, &ip, &base, &stack);
|
|
|
|
vmJump(ip, base, stack, t);
|
|
|
|
}
|
|
|
|
|
2008-01-08 19:36:34 +00:00
|
|
|
void FORCE_ALIGN
|
|
|
|
tryInitClass(MyThread* t, object class_)
|
|
|
|
{
|
|
|
|
initClass(t, class_);
|
|
|
|
if (UNLIKELY(t->exception)) unwind(t);
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void* FORCE_ALIGN
|
2007-12-30 22:24:48 +00:00
|
|
|
findInterfaceMethodFromInstance(MyThread* t, object method, object instance)
|
2007-10-16 17:21:26 +00:00
|
|
|
{
|
2007-12-30 22:24:48 +00:00
|
|
|
if (instance) {
|
|
|
|
return &singletonValue
|
|
|
|
(t, methodCompiled
|
|
|
|
(t, findInterfaceMethod(t, method, objectClass(t, instance))), 0);
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
unwind(t);
|
|
|
|
}
|
2007-10-16 17:21:26 +00:00
|
|
|
}
|
|
|
|
|
2007-10-15 19:12:38 +00:00
|
|
|
intptr_t
|
|
|
|
compareDoublesG(uint64_t bi, uint64_t ai)
|
|
|
|
{
|
|
|
|
double a = bitsToDouble(ai);
|
|
|
|
double b = bitsToDouble(bi);
|
|
|
|
|
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
} else if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else if (a == b) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t
|
|
|
|
compareDoublesL(uint64_t bi, uint64_t ai)
|
|
|
|
{
|
|
|
|
double a = bitsToDouble(ai);
|
|
|
|
double b = bitsToDouble(bi);
|
|
|
|
|
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
} else if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else if (a == b) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t
|
|
|
|
compareFloatsG(uint32_t bi, uint32_t ai)
|
|
|
|
{
|
|
|
|
float a = bitsToFloat(ai);
|
|
|
|
float b = bitsToFloat(bi);
|
|
|
|
|
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
} else if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else if (a == b) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t
|
|
|
|
compareFloatsL(uint32_t bi, uint32_t ai)
|
|
|
|
{
|
|
|
|
float a = bitsToFloat(ai);
|
|
|
|
float b = bitsToFloat(bi);
|
|
|
|
|
|
|
|
if (a < b) {
|
|
|
|
return -1;
|
|
|
|
} else if (a > b) {
|
|
|
|
return 1;
|
|
|
|
} else if (a == b) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
addDouble(uint64_t b, uint64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(bitsToDouble(a) + bitsToDouble(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
subtractDouble(uint64_t b, uint64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(bitsToDouble(a) - bitsToDouble(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
multiplyDouble(uint64_t b, uint64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(bitsToDouble(a) * bitsToDouble(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
divideDouble(uint64_t b, uint64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(bitsToDouble(a) / bitsToDouble(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
moduloDouble(uint64_t b, uint64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(fmod(bitsToDouble(a), bitsToDouble(b)));
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint64_t
|
|
|
|
negateDouble(uint64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(- bitsToDouble(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
doubleToFloat(int64_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(static_cast<float>(bitsToDouble(a)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
doubleToInt(int64_t a)
|
|
|
|
{
|
|
|
|
return static_cast<int32_t>(bitsToDouble(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
doubleToLong(int64_t a)
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(bitsToDouble(a));
|
|
|
|
}
|
|
|
|
|
2007-10-15 19:12:38 +00:00
|
|
|
uint32_t
|
|
|
|
addFloat(uint32_t b, uint32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(bitsToFloat(a) + bitsToFloat(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
subtractFloat(uint32_t b, uint32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(bitsToFloat(a) - bitsToFloat(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
multiplyFloat(uint32_t b, uint32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(bitsToFloat(a) * bitsToFloat(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
divideFloat(uint32_t b, uint32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(bitsToFloat(a) / bitsToFloat(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
moduloFloat(uint32_t b, uint32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(fmod(bitsToFloat(a), bitsToFloat(b)));
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint32_t
|
|
|
|
negateFloat(uint32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(- bitsToFloat(a));
|
|
|
|
}
|
|
|
|
|
2007-10-08 21:41:41 +00:00
|
|
|
int64_t
|
2007-10-15 19:12:38 +00:00
|
|
|
divideLong(int64_t b, int64_t a)
|
2007-10-08 21:41:41 +00:00
|
|
|
{
|
|
|
|
return a / b;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
2007-10-15 19:12:38 +00:00
|
|
|
moduloLong(int64_t b, int64_t a)
|
2007-10-08 21:41:41 +00:00
|
|
|
{
|
|
|
|
return a % b;
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint64_t
|
|
|
|
floatToDouble(int32_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(static_cast<double>(bitsToFloat(a)));
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
floatToInt(int32_t a)
|
|
|
|
{
|
|
|
|
return static_cast<int32_t>(bitsToFloat(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
floatToLong(int32_t a)
|
|
|
|
{
|
|
|
|
return static_cast<int64_t>(bitsToFloat(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
intToDouble(int32_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(static_cast<double>(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
intToFloat(int32_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(static_cast<float>(a));
|
|
|
|
}
|
|
|
|
|
2008-03-21 00:37:58 +00:00
|
|
|
uint64_t
|
|
|
|
longToDouble(int64_t a)
|
|
|
|
{
|
|
|
|
return doubleToBits(static_cast<double>(a));
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
longToFloat(int64_t a)
|
|
|
|
{
|
|
|
|
return floatToBits(static_cast<float>(a));
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
object FORCE_ALIGN
|
2007-09-30 02:48:27 +00:00
|
|
|
makeBlankObjectArray(Thread* t, object class_, int32_t length)
|
|
|
|
{
|
|
|
|
return makeObjectArray(t, class_, length, true);
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
object FORCE_ALIGN
|
2007-09-30 02:48:27 +00:00
|
|
|
makeBlankArray(Thread* t, object (*constructor)(Thread*, uintptr_t, bool),
|
|
|
|
int32_t length)
|
|
|
|
{
|
|
|
|
return constructor(t, length, true);
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uintptr_t
|
|
|
|
lookUpAddress(int32_t key, uintptr_t* start, int32_t count,
|
2007-12-17 20:55:31 +00:00
|
|
|
uintptr_t default_)
|
2007-10-01 15:19:15 +00:00
|
|
|
{
|
2007-12-09 22:45:43 +00:00
|
|
|
int32_t bottom = 0;
|
|
|
|
int32_t top = count;
|
|
|
|
for (int32_t span = top - bottom; span; span = top - bottom) {
|
|
|
|
int32_t middle = bottom + (span / 2);
|
|
|
|
uintptr_t* p = start + (middle * 2);
|
|
|
|
int32_t k = *p;
|
|
|
|
|
|
|
|
if (key < k) {
|
|
|
|
top = middle;
|
|
|
|
} else if (key > k) {
|
|
|
|
bottom = middle + 1;
|
|
|
|
} else {
|
|
|
|
return p[1];
|
2007-10-01 15:19:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-17 20:55:31 +00:00
|
|
|
return default_;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void FORCE_ALIGN
|
2007-12-30 22:24:48 +00:00
|
|
|
setMaybeNull(MyThread* t, object o, unsigned offset, object value)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
if (LIKELY(o)) {
|
2007-12-30 22:24:48 +00:00
|
|
|
set(t, o, offset, value);
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
unwind(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void FORCE_ALIGN
|
2007-12-30 22:24:48 +00:00
|
|
|
acquireMonitorForObject(MyThread* t, object o)
|
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
if (LIKELY(o)) {
|
2007-12-30 22:24:48 +00:00
|
|
|
acquire(t, o);
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
unwind(t);
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void FORCE_ALIGN
|
2007-12-30 22:24:48 +00:00
|
|
|
releaseMonitorForObject(MyThread* t, object o)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
if (LIKELY(o)) {
|
2007-12-30 22:24:48 +00:00
|
|
|
release(t, o);
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
unwind(t);
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object
|
|
|
|
makeMultidimensionalArray2(MyThread* t, object class_, uintptr_t* stack,
|
|
|
|
int32_t dimensions)
|
|
|
|
{
|
|
|
|
PROTECT(t, class_);
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
int32_t counts[dimensions];
|
|
|
|
for (int i = dimensions - 1; i >= 0; --i) {
|
|
|
|
counts[i] = stack[dimensions - i - 1];
|
|
|
|
if (UNLIKELY(counts[i] < 0)) {
|
|
|
|
object message = makeString(t, "%d", counts[i]);
|
|
|
|
t->exception = makeNegativeArraySizeException(t, message);
|
|
|
|
return 0;
|
2007-10-01 15:19:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object array = makeArray(t, counts[0], true);
|
|
|
|
setObjectClass(t, array, class_);
|
|
|
|
PROTECT(t, array);
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
populateMultiArray(t, array, counts, 0, dimensions);
|
2007-10-01 15:19:15 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
return array;
|
2007-10-01 15:19:15 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
object FORCE_ALIGN
|
2007-12-09 22:45:43 +00:00
|
|
|
makeMultidimensionalArray(MyThread* t, object class_, uintptr_t* stack,
|
|
|
|
int32_t dimensions)
|
2007-10-01 15:19:15 +00:00
|
|
|
{
|
2007-12-09 22:45:43 +00:00
|
|
|
object r = makeMultidimensionalArray2(t, class_, stack, dimensions);
|
2007-10-01 15:19:15 +00:00
|
|
|
if (UNLIKELY(t->exception)) {
|
|
|
|
unwind(t);
|
|
|
|
} else {
|
2007-12-09 22:45:43 +00:00
|
|
|
return r;
|
2007-10-01 15:19:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void NO_RETURN FORCE_ALIGN
|
2008-01-03 18:37:00 +00:00
|
|
|
throwArrayIndexOutOfBounds(MyThread* t, object array, int32_t index)
|
2007-09-27 00:01:38 +00:00
|
|
|
{
|
2008-01-03 18:37:00 +00:00
|
|
|
object message = makeString
|
|
|
|
(t, "array of length %d indexed at %d", arrayLength(t, array), index);
|
|
|
|
t->exception = makeArrayIndexOutOfBoundsException(t, message);
|
|
|
|
unwind(t);
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void NO_RETURN FORCE_ALIGN
|
2008-01-03 18:37:00 +00:00
|
|
|
throwNegativeArraySize(MyThread* t, int32_t length)
|
|
|
|
{
|
|
|
|
object message = makeString(t, "%d", length);
|
|
|
|
t->exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-12-09 22:45:43 +00:00
|
|
|
unwind(t);
|
2007-09-27 00:01:38 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void NO_RETURN FORCE_ALIGN
|
2007-12-09 22:45:43 +00:00
|
|
|
throw_(MyThread* t, object o)
|
2007-10-09 17:15:40 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
if (LIKELY(o)) {
|
2007-12-09 22:45:43 +00:00
|
|
|
t->exception = o;
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
2007-10-08 21:41:41 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
unwind(t);
|
|
|
|
}
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void FORCE_ALIGN
|
2007-12-23 00:00:35 +00:00
|
|
|
checkCast(MyThread* t, object class_, object o)
|
|
|
|
{
|
|
|
|
if (UNLIKELY(o and not isAssignableFrom(t, class_, objectClass(t, o)))) {
|
2008-01-15 23:33:20 +00:00
|
|
|
object message = makeString
|
|
|
|
(t, "%s as %s",
|
|
|
|
&byteArrayBody(t, className(t, objectClass(t, o)), 0),
|
|
|
|
&byteArrayBody(t, className(t, class_), 0));
|
2008-01-03 18:37:00 +00:00
|
|
|
t->exception = makeClassCastException(t, message);
|
|
|
|
unwind(t);
|
2007-12-23 00:00:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
void FORCE_ALIGN
|
|
|
|
gcIfNecessary(MyThread* t)
|
|
|
|
{
|
|
|
|
if (UNLIKELY(t->backupHeap)) {
|
|
|
|
collect(t, Heap::MinorCollection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void
|
2007-12-22 00:26:55 +00:00
|
|
|
pushReturnValue(MyThread* t, Frame* frame, unsigned code)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2007-12-26 16:56:14 +00:00
|
|
|
Compiler* c = frame->c;
|
2007-12-22 00:26:55 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (code) {
|
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
|
|
|
case CharField:
|
|
|
|
case ShortField:
|
|
|
|
case FloatField:
|
2007-12-26 16:56:14 +00:00
|
|
|
case IntField: {
|
|
|
|
Operand* result = c->result4();
|
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case ObjectField: {
|
|
|
|
Operand* result = ::result(c);
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pushObject(result);
|
2007-12-26 16:56:14 +00:00
|
|
|
c->release(result);
|
|
|
|
} break;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case LongField:
|
2007-12-26 16:56:14 +00:00
|
|
|
case DoubleField: {
|
|
|
|
Operand* result = c->result8();
|
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
|
|
|
} break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case VoidField:
|
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default:
|
|
|
|
abort(t);
|
2007-10-17 01:21:35 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
object
|
|
|
|
defaultCompiled(MyThread* t);
|
|
|
|
|
|
|
|
object
|
|
|
|
nativeCompiled(MyThread* t);
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void
|
|
|
|
compileDirectInvoke(MyThread* t, Frame* frame, object target)
|
|
|
|
{
|
2007-12-23 18:01:41 +00:00
|
|
|
Compiler* c = frame->c;
|
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
if (methodFlags(t, target) & ACC_NATIVE) {
|
|
|
|
c->call
|
|
|
|
(c->constant
|
|
|
|
(reinterpret_cast<intptr_t>
|
|
|
|
(&singletonBody(t, nativeCompiled(t), 0))),
|
|
|
|
frame->trace(target, false));
|
|
|
|
} else if (methodCompiled(t, target) == defaultCompiled(t)) {
|
|
|
|
c->alignedCall
|
|
|
|
(c->constant
|
|
|
|
(reinterpret_cast<intptr_t>
|
|
|
|
(&singletonBody(t, defaultCompiled(t), 0))),
|
|
|
|
frame->trace(target, false));
|
|
|
|
} else {
|
|
|
|
c->call
|
|
|
|
(c->constant
|
|
|
|
(reinterpret_cast<intptr_t>
|
|
|
|
(&singletonBody(t, methodCompiled(t, target), 0))),
|
|
|
|
frame->trace(0, false));
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pop(methodParameterFootprint(t, target));
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
pushReturnValue(t, frame, methodReturnCode(t, target));
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2007-12-28 00:02:05 +00:00
|
|
|
void
|
|
|
|
handleMonitorEvent(MyThread* t, Frame* frame, intptr_t function)
|
|
|
|
{
|
|
|
|
Compiler* c = frame->c;
|
2007-12-31 22:40:56 +00:00
|
|
|
object method = frame->context->method;
|
2007-12-28 00:02:05 +00:00
|
|
|
|
|
|
|
if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
|
|
|
|
Operand* lock;
|
|
|
|
if (methodFlags(t, method) & ACC_STATIC) {
|
|
|
|
lock = frame->append(methodClass(t, method));
|
|
|
|
} else {
|
2008-01-20 18:55:08 +00:00
|
|
|
lock = c->memory
|
|
|
|
(c->base(), localOffset(t, savedTargetIndex(t, method), method));
|
2007-12-28 00:02:05 +00:00
|
|
|
}
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
|
|
|
(c->constant(function),
|
|
|
|
frame->trace(0, false),
|
|
|
|
2, c->thread(), lock);
|
2008-01-11 22:16:24 +00:00
|
|
|
}
|
2007-12-28 00:02:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handleEntrance(MyThread* t, Frame* frame)
|
|
|
|
{
|
2008-01-20 18:55:08 +00:00
|
|
|
object method = frame->context->method;
|
|
|
|
|
2008-01-20 22:05:59 +00:00
|
|
|
if ((methodFlags(t, method) & (ACC_SYNCHRONIZED | ACC_STATIC))
|
|
|
|
== ACC_SYNCHRONIZED)
|
2008-01-20 18:55:08 +00:00
|
|
|
{
|
|
|
|
Compiler* c = frame->c;
|
|
|
|
|
|
|
|
// save 'this' pointer in case it is overwritten.
|
|
|
|
unsigned index = savedTargetIndex(t, method);
|
|
|
|
mov(c, c->memory(c->base(), localOffset(t, 0, method)),
|
|
|
|
c->memory(c->base(), localOffset(t, index, method)));
|
|
|
|
frame->mark(index);
|
|
|
|
}
|
|
|
|
|
2007-12-28 00:02:05 +00:00
|
|
|
handleMonitorEvent
|
|
|
|
(t, frame, reinterpret_cast<intptr_t>(acquireMonitorForObject));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
handleExit(MyThread* t, Frame* frame)
|
|
|
|
{
|
|
|
|
handleMonitorEvent
|
|
|
|
(t, frame, reinterpret_cast<intptr_t>(releaseMonitorForObject));
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void
|
2008-04-09 19:08:13 +00:00
|
|
|
compile(MyThread* t, Frame* initialFrame, unsigned ip,
|
|
|
|
bool exceptionHandler = false)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-01-07 14:51:07 +00:00
|
|
|
uintptr_t stackMap[stackMapSizeInWords(t, initialFrame->context->method)];
|
2008-01-07 16:01:35 +00:00
|
|
|
Frame myFrame(initialFrame, stackMap);
|
2007-12-09 22:45:43 +00:00
|
|
|
Frame* frame = &myFrame;
|
|
|
|
Compiler* c = frame->c;
|
2007-12-31 22:40:56 +00:00
|
|
|
Context* context = frame->context;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
object code = methodCode(t, context->method);
|
2007-12-09 22:45:43 +00:00
|
|
|
PROTECT(t, code);
|
|
|
|
|
|
|
|
while (ip < codeLength(t, code)) {
|
2008-01-07 14:51:07 +00:00
|
|
|
frame->visitLogicalIp(ip);
|
|
|
|
|
|
|
|
if (context->visitTable[ip] ++) {
|
2007-12-09 22:45:43 +00:00
|
|
|
// we've already visited this part of the code
|
|
|
|
return;
|
2007-09-30 04:07:22 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->startLogicalIp(ip);
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
if (exceptionHandler) {
|
|
|
|
exceptionHandler = false;
|
|
|
|
|
|
|
|
c->indirectCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(gcIfNecessary)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
1, c->thread());
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
// fprintf(stderr, "ip: %d map: %ld\n", ip, *(frame->map));
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned instruction = codeBody(t, code, ip++);
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (instruction) {
|
|
|
|
case aaload:
|
|
|
|
case baload:
|
|
|
|
case caload:
|
|
|
|
case daload:
|
|
|
|
case faload:
|
|
|
|
case iaload:
|
|
|
|
case laload:
|
|
|
|
case saload: {
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* index = frame->popInt4();
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* array = frame->popObject();
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
if (CheckArrayBounds) {
|
|
|
|
Operand* load = c->label();
|
|
|
|
Operand* throw_ = c->label();
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
c->cmp4(c->constant(0), index);
|
|
|
|
c->jl(throw_);
|
2008-01-03 18:37:00 +00:00
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
c->cmp4(c->memory(array, ArrayLength, 0, 1), index);
|
2008-01-08 17:10:24 +00:00
|
|
|
c->jl(load);
|
2008-01-03 18:37:00 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
c->mark(throw_);
|
2008-01-03 18:37:00 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
c->indirectCallNoReturn
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(throwArrayIndexOutOfBounds)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
3, c->thread(), array, index);
|
|
|
|
|
|
|
|
c->mark(load);
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (instruction) {
|
|
|
|
case aaload:
|
2007-12-30 22:24:48 +00:00
|
|
|
frame->pushObject
|
2007-12-31 22:40:56 +00:00
|
|
|
(c->memory(array, ArrayBody, index, BytesPerWord));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case faload:
|
|
|
|
case iaload:
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->pushInt4(c->memory(array, ArrayBody, index, 4));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case baload:
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->pushInt1(c->memory(array, ArrayBody, index, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case caload:
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->pushInt2z(c->memory(array, ArrayBody, index, 2));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case daload:
|
|
|
|
case laload:
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->pushLong(c->memory(array, ArrayBody, index, 8));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case saload:
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->pushInt2(c->memory(array, ArrayBody, index, 2));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(index);
|
|
|
|
c->release(array);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aastore:
|
|
|
|
case bastore:
|
|
|
|
case castore:
|
|
|
|
case dastore:
|
|
|
|
case fastore:
|
|
|
|
case iastore:
|
|
|
|
case lastore:
|
|
|
|
case sastore: {
|
|
|
|
Operand* value;
|
|
|
|
if (instruction == dastore or instruction == lastore) {
|
|
|
|
value = frame->popLong();
|
|
|
|
} else if (instruction == aastore) {
|
|
|
|
value = frame->popObject();
|
|
|
|
} else {
|
|
|
|
value = frame->popInt();
|
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* index = frame->popInt4();
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* array = frame->popObject();
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
if (CheckArrayBounds) {
|
|
|
|
Operand* store = c->label();
|
|
|
|
Operand* throw_ = c->label();
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
c->cmp4(c->constant(0), index);
|
|
|
|
c->jl(throw_);
|
2008-01-03 18:37:00 +00:00
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
c->cmp4(c->memory(array, ArrayLength, 0, 1), index);
|
2008-01-08 17:10:24 +00:00
|
|
|
c->jl(store);
|
2008-01-03 18:37:00 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
c->mark(throw_);
|
2008-01-03 18:37:00 +00:00
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
c->indirectCallNoReturn
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(throwArrayIndexOutOfBounds)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
3, c->thread(), array, index);
|
|
|
|
|
|
|
|
c->mark(store);
|
|
|
|
}
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (instruction) {
|
2007-12-23 18:01:41 +00:00
|
|
|
case aastore: {
|
2007-12-26 16:56:14 +00:00
|
|
|
c->shl4(c->constant(log(BytesPerWord)), index);
|
|
|
|
c->add4(c->constant(ArrayBody), index);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-30 22:24:48 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(setMaybeNull)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-09 22:45:43 +00:00
|
|
|
4, c->thread(), array, index, value);
|
2007-12-23 18:01:41 +00:00
|
|
|
} break;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fastore:
|
|
|
|
case iastore:
|
2007-12-31 22:40:56 +00:00
|
|
|
c->mov4(value, c->memory(array, ArrayBody, index, 4));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case bastore:
|
2007-12-31 22:40:56 +00:00
|
|
|
c->mov1(value, c->memory(array, ArrayBody, index, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case castore:
|
|
|
|
case sastore:
|
2007-12-31 22:40:56 +00:00
|
|
|
c->mov2(value, c->memory(array, ArrayBody, index, 2));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dastore:
|
|
|
|
case lastore:
|
2007-12-31 22:40:56 +00:00
|
|
|
c->mov8(value, c->memory(array, ArrayBody, index, 8));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(value);
|
|
|
|
c->release(index);
|
|
|
|
c->release(array);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aconst_null:
|
|
|
|
frame->pushObject(c->constant(0));
|
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aload:
|
|
|
|
frame->loadObject(codeBody(t, code, ip++));
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aload_0:
|
|
|
|
frame->loadObject(0);
|
|
|
|
break;
|
2007-10-08 23:13:55 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aload_1:
|
|
|
|
frame->loadObject(1);
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aload_2:
|
|
|
|
frame->loadObject(2);
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case aload_3:
|
|
|
|
frame->loadObject(3);
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case anewarray: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
|
|
|
|
object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* nonnegative = c->label();
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* length = frame->popInt4();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->cmp4(c->constant(0), length);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jge(nonnegative);
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
c->indirectCallNoReturn
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(throwNegativeArraySize)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
2, c->thread(), length);
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->mark(nonnegative);
|
2007-10-08 23:13:55 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(makeBlankObjectArray)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
3, c->thread(), frame->append(class_), length);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(length);
|
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushObject(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
case areturn: {
|
2007-12-28 00:02:05 +00:00
|
|
|
handleExit(t, frame);
|
2007-12-12 22:19:13 +00:00
|
|
|
Operand* result = frame->popObject();
|
2007-12-26 16:56:14 +00:00
|
|
|
returnW(c, result);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(result);
|
|
|
|
} return;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
case arraylength: {
|
|
|
|
Operand* array = frame->popObject();
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushInt4(c->memory(array, ArrayLength, 0, 1));
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(array);
|
|
|
|
} break;
|
2007-10-04 03:19:39 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case astore:
|
2007-12-26 23:59:55 +00:00
|
|
|
frame->storeObjectOrAddress(codeBody(t, code, ip++));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case astore_0:
|
2007-12-27 16:02:03 +00:00
|
|
|
frame->storeObjectOrAddress(0);
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-17 17:22:09 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case astore_1:
|
2007-12-27 16:02:03 +00:00
|
|
|
frame->storeObjectOrAddress(1);
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case astore_2:
|
2007-12-27 16:02:03 +00:00
|
|
|
frame->storeObjectOrAddress(2);
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case astore_3:
|
2007-12-27 16:02:03 +00:00
|
|
|
frame->storeObjectOrAddress(3);
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
case athrow: {
|
|
|
|
Operand* e = frame->popObject();
|
2007-12-09 22:45:43 +00:00
|
|
|
c->indirectCallNoReturn
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(throw_)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-12 22:19:13 +00:00
|
|
|
2, c->thread(), e);
|
|
|
|
c->release(e);
|
|
|
|
} return;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case bipush:
|
|
|
|
frame->pushInt
|
|
|
|
(c->constant(static_cast<int8_t>(codeBody(t, code, ip++))));
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case checkcast: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* instance = frame->topObject();
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* classOperand = frame->append(class_);
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(checkCast)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
3, c->thread(), classOperand, instance);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case d2f: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(doubleToFloat)), 2, 0, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case d2i: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(doubleToInt)), 2, 0, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case d2l: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(doubleToLong)), 2, 0, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dadd: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(addDouble)), 4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dcmpg: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(compareDoublesG)),
|
|
|
|
4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 21:34:04 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dcmpl: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(compareDoublesL)),
|
|
|
|
4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dconst_0:
|
2007-12-26 16:56:14 +00:00
|
|
|
frame->pushLong(c->constant(doubleToBits(0.0)));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case dconst_1:
|
2007-12-26 16:56:14 +00:00
|
|
|
frame->pushLong(c->constant(doubleToBits(1.0)));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ddiv: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(divideDouble)),
|
|
|
|
4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dmul: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(multiplyDouble)),
|
|
|
|
4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dneg: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(negateDouble)), 2, 0, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case vm::drem: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(moduloDouble)), 4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dsub: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
2007-12-26 16:56:14 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(subtractDouble)),
|
|
|
|
4, 0, a, 0, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dup:
|
|
|
|
frame->dup();
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dup_x1:
|
|
|
|
frame->dupX1();
|
|
|
|
break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dup_x2:
|
|
|
|
frame->dupX2();
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dup2:
|
|
|
|
frame->dup2();
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dup2_x1:
|
|
|
|
frame->dup2X1();
|
|
|
|
break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case dup2_x2:
|
|
|
|
frame->dup2X2();
|
|
|
|
break;
|
2007-10-09 17:15:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case f2d: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(floatToDouble)), 1, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case f2i: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(floatToInt)), 1, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case f2l: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(floatToLong)), 1, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fadd: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(addFloat)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fcmpg: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(compareFloatsG)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fcmpl: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(compareFloatsL)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fconst_0:
|
|
|
|
frame->pushInt(c->constant(floatToBits(0.0)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fconst_1:
|
|
|
|
frame->pushInt(c->constant(floatToBits(1.0)));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case fconst_2:
|
|
|
|
frame->pushInt(c->constant(floatToBits(2.0)));
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fdiv: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(divideFloat)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fmul: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(multiplyFloat)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fneg: {
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* a = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(negateFloat)), 1, a);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
|
|
|
frame->pushInt(result);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case vm::frem: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(moduloFloat)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case fsub: {
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(subtractFloat)), 2, a, b);
|
2007-12-23 00:15:46 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case getfield:
|
|
|
|
case getstatic: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
|
|
|
|
object field = resolveField(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* table;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (instruction == getstatic) {
|
2008-01-08 19:36:34 +00:00
|
|
|
c->indirectCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(tryInitClass)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
2, c->thread(), frame->append(fieldClass(t, field)));
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
table = frame->append(classStaticTable(t, fieldClass(t, field)));
|
|
|
|
} else {
|
|
|
|
table = frame->popObject();
|
|
|
|
}
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (fieldCode(t, field)) {
|
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushInt1(c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case CharField:
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushInt2z(c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ShortField:
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushInt2(c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case FloatField:
|
|
|
|
case IntField:
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushInt4(c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case DoubleField:
|
|
|
|
case LongField:
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushLong(c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ObjectField:
|
2008-04-09 19:08:13 +00:00
|
|
|
frame->pushObject(c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default:
|
|
|
|
abort(t);
|
|
|
|
}
|
2007-12-12 22:19:13 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
if (instruction == getfield) {
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(table);
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case goto_: {
|
|
|
|
uint32_t newIp = (ip - 3) + codeReadInt16(t, code, ip);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
c->jmp(frame->machineIp(newIp));
|
2007-12-09 22:45:43 +00:00
|
|
|
ip = newIp;
|
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case goto_w: {
|
|
|
|
uint32_t newIp = (ip - 5) + codeReadInt32(t, code, ip);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
c->jmp(frame->machineIp(newIp));
|
2007-12-09 22:45:43 +00:00
|
|
|
ip = newIp;
|
|
|
|
} break;
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case i2b: {
|
2007-12-16 21:30:19 +00:00
|
|
|
Operand* top = frame->topInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mov1ToW(top, top);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case i2c: {
|
2007-12-16 21:30:19 +00:00
|
|
|
Operand* top = frame->topInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mov2zToW(top, top);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case i2d: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(intToDouble)), 1, a);
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result8();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case i2f: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-23 00:00:35 +00:00
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(intToFloat)), 1, a);
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-23 00:00:35 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
case i2l:
|
2007-12-26 16:56:14 +00:00
|
|
|
frame->topIntToLong();
|
2007-12-26 23:59:55 +00:00
|
|
|
break;
|
2007-10-04 03:19:39 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case i2s: {
|
2007-12-16 21:30:19 +00:00
|
|
|
Operand* top = frame->topInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mov2ToW(top, top);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case iadd: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->add4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case iand: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->and4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_m1:
|
|
|
|
frame->pushInt(c->constant(-1));
|
|
|
|
break;
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_0:
|
|
|
|
frame->pushInt(c->constant(0));
|
|
|
|
break;
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_1:
|
|
|
|
frame->pushInt(c->constant(1));
|
|
|
|
break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_2:
|
|
|
|
frame->pushInt(c->constant(2));
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_3:
|
|
|
|
frame->pushInt(c->constant(3));
|
|
|
|
break;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_4:
|
|
|
|
frame->pushInt(c->constant(4));
|
|
|
|
break;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iconst_5:
|
|
|
|
frame->pushInt(c->constant(5));
|
|
|
|
break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case idiv: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->div4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case if_acmpeq:
|
|
|
|
case if_acmpne: {
|
|
|
|
uint32_t newIp = (ip - 3) + codeReadInt16(t, code, ip);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
|
|
|
|
|
|
|
Operand* a = frame->popObject();
|
|
|
|
Operand* b = frame->popObject();
|
2007-12-26 16:56:14 +00:00
|
|
|
cmp(c, a, b);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* target = frame->machineIp(newIp);
|
2007-12-09 22:45:43 +00:00
|
|
|
if (instruction == if_acmpeq) {
|
|
|
|
c->je(target);
|
|
|
|
} else {
|
|
|
|
c->jne(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
compile(t, frame, newIp);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
} break;
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case if_icmpeq:
|
|
|
|
case if_icmpne:
|
|
|
|
case if_icmpgt:
|
|
|
|
case if_icmpge:
|
|
|
|
case if_icmplt:
|
|
|
|
case if_icmple: {
|
|
|
|
uint32_t newIp = (ip - 3) + codeReadInt16(t, code, ip);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
|
|
|
|
|
|
|
Operand* a = frame->popInt();
|
|
|
|
Operand* b = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->cmp4(a, b);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* target = frame->machineIp(newIp);
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (instruction) {
|
|
|
|
case if_icmpeq:
|
|
|
|
c->je(target);
|
|
|
|
break;
|
|
|
|
case if_icmpne:
|
|
|
|
c->jne(target);
|
|
|
|
break;
|
|
|
|
case if_icmpgt:
|
|
|
|
c->jg(target);
|
|
|
|
break;
|
|
|
|
case if_icmpge:
|
|
|
|
c->jge(target);
|
|
|
|
break;
|
|
|
|
case if_icmplt:
|
|
|
|
c->jl(target);
|
|
|
|
break;
|
|
|
|
case if_icmple:
|
|
|
|
c->jle(target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
compile(t, frame, newIp);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
} break;
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ifeq:
|
|
|
|
case ifne:
|
|
|
|
case ifgt:
|
|
|
|
case ifge:
|
|
|
|
case iflt:
|
|
|
|
case ifle: {
|
|
|
|
uint32_t newIp = (ip - 3) + codeReadInt16(t, code, ip);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->cmp4(c->constant(0), a);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* target = frame->machineIp(newIp);
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (instruction) {
|
|
|
|
case ifeq:
|
|
|
|
c->je(target);
|
|
|
|
break;
|
|
|
|
case ifne:
|
|
|
|
c->jne(target);
|
|
|
|
break;
|
|
|
|
case ifgt:
|
|
|
|
c->jg(target);
|
|
|
|
break;
|
|
|
|
case ifge:
|
|
|
|
c->jge(target);
|
|
|
|
break;
|
|
|
|
case iflt:
|
|
|
|
c->jl(target);
|
|
|
|
break;
|
|
|
|
case ifle:
|
|
|
|
c->jle(target);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
compile(t, frame, newIp);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
} break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ifnull:
|
|
|
|
case ifnonnull: {
|
|
|
|
uint32_t newIp = (ip - 3) + codeReadInt16(t, code, ip);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* a = frame->popObject();
|
2007-12-26 16:56:14 +00:00
|
|
|
cmp(c, c->constant(0), a);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* target = frame->machineIp(newIp);
|
2007-12-09 22:45:43 +00:00
|
|
|
if (instruction == ifnull) {
|
|
|
|
c->je(target);
|
|
|
|
} else {
|
|
|
|
c->jne(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
compile(t, frame, newIp);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
} break;
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iinc: {
|
|
|
|
uint8_t index = codeBody(t, code, ip++);
|
|
|
|
int8_t count = codeBody(t, code, ip++);
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
c->add4(c->constant(count),
|
|
|
|
c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iload:
|
|
|
|
case fload:
|
|
|
|
frame->loadInt(codeBody(t, code, ip++));
|
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iload_0:
|
|
|
|
case fload_0:
|
|
|
|
frame->loadInt(0);
|
|
|
|
break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iload_1:
|
|
|
|
case fload_1:
|
|
|
|
frame->loadInt(1);
|
|
|
|
break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iload_2:
|
|
|
|
case fload_2:
|
|
|
|
frame->loadInt(2);
|
|
|
|
break;
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iload_3:
|
|
|
|
case fload_3:
|
|
|
|
frame->loadInt(3);
|
|
|
|
break;
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case imul: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mul4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-26 19:19:45 +00:00
|
|
|
case ineg: {
|
|
|
|
c->neg4(frame->topInt());
|
|
|
|
} break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case instanceof: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
2007-09-30 04:07:22 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-30 04:07:22 +00:00
|
|
|
|
2007-12-14 18:27:56 +00:00
|
|
|
Operand* instance = frame->popObject();
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* classOperand = frame->append(class_);
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(instanceOf)),
|
|
|
|
3, c->thread(), classOperand, instance);
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = c->result4();
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->release(instance);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case invokeinterface: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
ip += 2;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object target = resolveMethod(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned parameterFootprint = methodParameterFootprint(t, target);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned instance = parameterFootprint - 1;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
c->indirectCall
|
2007-12-16 23:52:38 +00:00
|
|
|
(c->constant
|
|
|
|
(reinterpret_cast<intptr_t>(findInterfaceMethodFromInstance)),
|
2007-12-31 23:21:57 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-16 23:52:38 +00:00
|
|
|
3, c->thread(), frame->append(target),
|
2007-12-23 00:00:35 +00:00
|
|
|
c->stack(frame->stack, instance));
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-31 22:40:56 +00:00
|
|
|
c->call(result, frame->trace(target, true));
|
2007-12-23 00:00:35 +00:00
|
|
|
c->release(result);
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pop(parameterFootprint);
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
pushReturnValue(t, frame, methodReturnCode(t, target));
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case invokespecial: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object target = resolveMethod(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2008-01-11 22:16:24 +00:00
|
|
|
object class_ = methodClass(t, context->method);
|
2007-12-09 22:45:43 +00:00
|
|
|
if (isSpecialMethod(t, target, class_)) {
|
|
|
|
target = findMethod(t, target, classSuper(t, class_));
|
|
|
|
}
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
compileDirectInvoke(t, frame, target);
|
|
|
|
} break;
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case invokestatic: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object target = resolveMethod(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
compileDirectInvoke(t, frame, target);
|
|
|
|
} break;
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case invokevirtual: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object target = resolveMethod(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned parameterFootprint = methodParameterFootprint(t, target);
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned offset = ClassVtable + (methodOffset(t, target) * BytesPerWord);
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* instance = c->stack(frame->stack, parameterFootprint - 1);
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* class_ = c->temporary();
|
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
mov(c, c->memory(instance, 0, 0, 1), class_);
|
2007-12-26 16:56:14 +00:00
|
|
|
and_(c, c->constant(PointerMask), class_);
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->call(c->memory(class_, offset, 0, 1), frame->trace(target, true));
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->release(class_);
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pop(parameterFootprint);
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
pushReturnValue(t, frame, methodReturnCode(t, target));
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ior: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->or4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case irem: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->rem4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ireturn:
|
2007-12-14 18:27:56 +00:00
|
|
|
case freturn: {
|
2007-12-28 00:02:05 +00:00
|
|
|
handleExit(t, frame);
|
2007-12-14 18:27:56 +00:00
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->return4(a);
|
2007-12-14 18:27:56 +00:00
|
|
|
c->release(a);
|
|
|
|
} return;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ishl: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->shl4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ishr: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->shr4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case istore:
|
|
|
|
case fstore:
|
|
|
|
frame->storeInt(codeBody(t, code, ip++));
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case istore_0:
|
|
|
|
case fstore_0:
|
|
|
|
frame->storeInt(0);
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case istore_1:
|
|
|
|
case fstore_1:
|
|
|
|
frame->storeInt(1);
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case istore_2:
|
|
|
|
case fstore_2:
|
|
|
|
frame->storeInt(2);
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case istore_3:
|
|
|
|
case fstore_3:
|
|
|
|
frame->storeInt(3);
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case isub: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->sub4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iushr: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->ushr4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ixor: {
|
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->xor4(a, frame->topInt());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case jsr:
|
2007-12-26 23:59:55 +00:00
|
|
|
case jsr_w: {
|
|
|
|
uint32_t newIp;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
if (instruction == jsr) {
|
|
|
|
newIp = (ip - 3) + codeReadInt16(t, code, ip);
|
|
|
|
} else {
|
|
|
|
newIp = (ip - 5) + codeReadInt32(t, code, ip);
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
|
|
|
|
|
|
|
frame->pushAddress(frame->machineIp(ip));
|
|
|
|
c->jmp(frame->machineIp(newIp));
|
|
|
|
|
|
|
|
// NB: we assume that the stack will look the same on return
|
|
|
|
// from the subroutine as at call time.
|
|
|
|
compile(t, frame, newIp);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-12-27 20:32:34 +00:00
|
|
|
|
|
|
|
frame->pop(1);
|
2007-12-16 21:30:19 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2008-03-21 00:37:58 +00:00
|
|
|
case l2d: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(longToDouble)), 2, 0, a);
|
|
|
|
|
|
|
|
Operand* result = c->result8();
|
|
|
|
frame->pushLong(result);
|
|
|
|
c->release(result);
|
|
|
|
c->release(a);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case l2f: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(longToDouble)), 2, 0, a);
|
|
|
|
|
|
|
|
Operand* result = c->result4();
|
|
|
|
frame->pushInt(result);
|
|
|
|
c->release(result);
|
|
|
|
c->release(a);
|
|
|
|
} break;
|
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
case l2i:
|
|
|
|
frame->topLongToInt();
|
|
|
|
break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ladd: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->add8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-26 19:19:45 +00:00
|
|
|
case land: {
|
|
|
|
Operand* a = frame->popLong();
|
|
|
|
c->and8(a, frame->topLong());
|
|
|
|
c->release(a);
|
|
|
|
} break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lcmp: {
|
|
|
|
Operand* next = c->label();
|
|
|
|
Operand* less = c->label();
|
|
|
|
Operand* greater = c->label();
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* a = frame->popLong();
|
|
|
|
Operand* b = frame->popLong();
|
|
|
|
Operand* result = c->temporary();
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
c->cmp8(a, b);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
|
|
|
c->release(b);
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jl(less);
|
|
|
|
c->jg(greater);
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mov4(c->constant(0), result);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jmp(next);
|
|
|
|
|
|
|
|
c->mark(less);
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mov4(c->constant(-1), result);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jmp(next);
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->mark(greater);
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mov4(c->constant(1), result);
|
2007-10-15 19:12:38 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->mark(next);
|
|
|
|
frame->pushInt(result);
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->release(result);
|
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lconst_0:
|
2007-12-26 16:56:14 +00:00
|
|
|
frame->pushLong(c->constant(0));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lconst_1:
|
2007-12-26 16:56:14 +00:00
|
|
|
frame->pushLong(c->constant(1));
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ldc:
|
|
|
|
case ldc_w: {
|
|
|
|
uint16_t index;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (instruction == ldc) {
|
|
|
|
index = codeBody(t, code, ip++);
|
|
|
|
} else {
|
|
|
|
index = codeReadInt16(t, code, ip);
|
|
|
|
}
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object pool = codePool(t, code);
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (singletonIsObject(t, pool, index - 1)) {
|
|
|
|
object v = singletonObject(t, pool, index - 1);
|
|
|
|
if (objectClass(t, v)
|
|
|
|
== arrayBody(t, t->m->types, Machine::ByteArrayType))
|
|
|
|
{
|
|
|
|
object class_ = resolveClassInPool(t, pool, index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-30 15:52:21 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pushObject(frame->append(class_));
|
2007-10-08 21:41:41 +00:00
|
|
|
} else {
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pushObject(frame->append(v));
|
2007-10-08 21:41:41 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
|
|
|
frame->pushInt(c->constant(singletonValue(t, pool, index - 1)));
|
|
|
|
}
|
|
|
|
} break;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ldc2_w: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object pool = codePool(t, code);
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint64_t v;
|
|
|
|
memcpy(&v, &singletonValue(t, pool, index - 1), 8);
|
2007-12-26 16:56:14 +00:00
|
|
|
frame->pushLong(c->constant(v));
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ldiv_: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->div8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lload:
|
|
|
|
case dload:
|
|
|
|
frame->loadLong(codeBody(t, code, ip++));
|
|
|
|
break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lload_0:
|
|
|
|
case dload_0:
|
|
|
|
frame->loadLong(0);
|
|
|
|
break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lload_1:
|
|
|
|
case dload_1:
|
|
|
|
frame->loadLong(1);
|
|
|
|
break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lload_2:
|
|
|
|
case dload_2:
|
|
|
|
frame->loadLong(2);
|
|
|
|
break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lload_3:
|
|
|
|
case dload_3:
|
|
|
|
frame->loadLong(3);
|
|
|
|
break;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lmul: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->mul8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lneg:
|
2007-12-26 16:56:14 +00:00
|
|
|
c->neg8(frame->topLong());
|
2007-12-09 22:45:43 +00:00
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lookupswitch: {
|
|
|
|
int32_t base = ip - 1;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
ip = (ip + 3) & ~3; // pad to four byte boundary
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* key = frame->popInt4();
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
uint32_t defaultIp = base + codeReadInt32(t, code, ip);
|
|
|
|
assert(t, defaultIp < codeLength(t, code));
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* default_ = c->absolute
|
|
|
|
(c->poolAppendPromise(c->machineIp(defaultIp)));
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
int32_t pairCount = codeReadInt32(t, code, ip);
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* start = 0;
|
|
|
|
uint32_t ipTable[pairCount];
|
2007-12-09 22:45:43 +00:00
|
|
|
for (int32_t i = 0; i < pairCount; ++i) {
|
|
|
|
unsigned index = ip + (i * 8);
|
|
|
|
int32_t key = codeReadInt32(t, code, index);
|
|
|
|
uint32_t newIp = base + codeReadInt32(t, code, index);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
ipTable[i] = newIp;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Promise* p = c->poolAppend(key);
|
2007-12-09 22:45:43 +00:00
|
|
|
if (i == 0) {
|
2007-12-16 00:24:15 +00:00
|
|
|
start = c->promiseConstant(p);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-12-16 00:24:15 +00:00
|
|
|
c->poolAppendPromise(c->machineIp(newIp));
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-12-16 00:24:15 +00:00
|
|
|
assert(t, start);
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(lookUpAddress)),
|
|
|
|
4, key, start, c->constant(pairCount), default_);
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->jmp(result);
|
|
|
|
c->release(result);
|
2007-12-12 22:19:13 +00:00
|
|
|
|
|
|
|
c->release(key);
|
2007-12-16 00:24:15 +00:00
|
|
|
|
|
|
|
for (int32_t i = 0; i < pairCount; ++i) {
|
|
|
|
compile(t, frame, ipTable[i]);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
ip = defaultIp;
|
|
|
|
} break;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lor: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->or8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lrem: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->rem8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lreturn:
|
2007-12-12 22:19:13 +00:00
|
|
|
case dreturn: {
|
2007-12-28 00:02:05 +00:00
|
|
|
handleExit(t, frame);
|
2007-12-12 22:19:13 +00:00
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->return8(a);
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
|
|
|
} return;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lshl: {
|
2007-12-26 19:19:45 +00:00
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->shl8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lshr: {
|
2007-12-26 19:19:45 +00:00
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->shr8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lstore:
|
|
|
|
case dstore:
|
|
|
|
frame->storeLong(codeBody(t, code, ip++));
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lstore_0:
|
|
|
|
case dstore_0:
|
|
|
|
frame->storeLong(0);
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lstore_1:
|
|
|
|
case dstore_1:
|
|
|
|
frame->storeLong(1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lstore_2:
|
|
|
|
case dstore_2:
|
|
|
|
frame->storeLong(2);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case lstore_3:
|
|
|
|
case dstore_3:
|
|
|
|
frame->storeLong(3);
|
|
|
|
break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lsub: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->sub8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lushr: {
|
2007-12-26 19:19:45 +00:00
|
|
|
Operand* a = frame->popInt();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->ushr8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lxor: {
|
|
|
|
Operand* a = frame->popLong();
|
2007-12-26 16:56:14 +00:00
|
|
|
c->xor8(a, frame->topLong());
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case monitorenter: {
|
2007-12-12 22:19:13 +00:00
|
|
|
Operand* a = frame->popObject();
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(acquireMonitorForObject)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-12 22:19:13 +00:00
|
|
|
2, c->thread(), a);
|
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case monitorexit: {
|
2007-12-12 22:19:13 +00:00
|
|
|
Operand* a = frame->popObject();
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(releaseMonitorForObject)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-12 22:19:13 +00:00
|
|
|
2, c->thread(), a);
|
|
|
|
c->release(a);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case multianewarray: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
uint8_t dimensions = codeBody(t, code, ip++);
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
PROTECT(t, class_);
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2008-01-03 23:53:37 +00:00
|
|
|
Operand* stack = c->temporary();
|
|
|
|
mov(c, c->stack(), stack);
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(makeMultidimensionalArray)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2008-01-03 23:53:37 +00:00
|
|
|
4, c->thread(), frame->append(class_), stack,
|
2007-12-09 22:45:43 +00:00
|
|
|
c->constant(dimensions));
|
2008-01-03 23:53:37 +00:00
|
|
|
|
|
|
|
c->release(stack);
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pop(dimensions);
|
|
|
|
frame->pushObject(result);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-12 00:30:46 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case new_: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
|
|
|
|
object class_ = resolveClassInPool(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
|
|
|
|
if (classVmFlags(t, class_) & WeakReferenceFlag) {
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(makeNewWeakReference)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-09 22:45:43 +00:00
|
|
|
2, c->thread(), frame->append(class_));
|
|
|
|
} else {
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(makeNew)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-09 22:45:43 +00:00
|
|
|
2, c->thread(), frame->append(class_));
|
|
|
|
}
|
2007-09-29 21:08:29 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pushObject(result);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case newarray: {
|
|
|
|
uint8_t type = codeBody(t, code, ip++);
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* nonnegative = c->label();
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* length = frame->popInt4();
|
|
|
|
c->cmp4(c->constant(0), length);
|
2007-12-12 22:19:13 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jge(nonnegative);
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
c->indirectCallNoReturn
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(throwNegativeArraySize)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
2, c->thread(), length);
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->mark(nonnegative);
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object (*constructor)(Thread*, uintptr_t, bool);
|
|
|
|
switch (type) {
|
|
|
|
case T_BOOLEAN:
|
|
|
|
constructor = makeBooleanArray;
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_CHAR:
|
|
|
|
constructor = makeCharArray;
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_FLOAT:
|
|
|
|
constructor = makeFloatArray;
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_DOUBLE:
|
|
|
|
constructor = makeDoubleArray;
|
|
|
|
break;
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_BYTE:
|
|
|
|
constructor = makeByteArray;
|
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_SHORT:
|
|
|
|
constructor = makeShortArray;
|
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_INT:
|
|
|
|
constructor = makeIntArray;
|
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case T_LONG:
|
|
|
|
constructor = makeLongArray;
|
|
|
|
break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default: abort(t);
|
|
|
|
}
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
c->indirectCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(makeBlankArray)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-16 00:24:15 +00:00
|
|
|
3, c->thread(), c->constant(reinterpret_cast<intptr_t>(constructor)),
|
2008-01-03 18:37:00 +00:00
|
|
|
length);
|
2007-12-23 00:00:35 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-16 00:24:15 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
c->release(length);
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
frame->pushObject(result);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->release(result);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case nop: break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case pop_:
|
|
|
|
frame->pop(1);
|
|
|
|
break;
|
2007-09-27 22:20:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case pop2:
|
|
|
|
frame->pop(2);
|
|
|
|
break;
|
2007-09-27 22:20:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case putfield:
|
|
|
|
case putstatic: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
|
|
|
|
object field = resolveField(t, codePool(t, code), index - 1);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-17 22:38:59 +00:00
|
|
|
object staticTable = 0;
|
2007-09-27 22:20:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (instruction == putstatic) {
|
2008-01-08 19:36:34 +00:00
|
|
|
c->indirectCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(tryInitClass)),
|
|
|
|
frame->trace(0, false),
|
|
|
|
2, c->thread(), frame->append(fieldClass(t, field)));
|
2007-09-27 22:20:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
staticTable = classStaticTable(t, fieldClass(t, field));
|
|
|
|
}
|
2007-10-12 22:06:33 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* value;
|
|
|
|
switch (fieldCode(t, field)) {
|
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
|
|
|
case CharField:
|
|
|
|
case ShortField:
|
|
|
|
case FloatField:
|
|
|
|
case IntField: {
|
|
|
|
value = frame->popInt();
|
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case DoubleField:
|
|
|
|
case LongField: {
|
|
|
|
value = frame->popLong();
|
|
|
|
} break;
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ObjectField: {
|
2007-12-12 22:19:13 +00:00
|
|
|
value = frame->popObject();
|
2007-09-26 23:23:03 +00:00
|
|
|
} break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default: abort(t);
|
|
|
|
}
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* table;
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (instruction == putstatic) {
|
|
|
|
table = frame->append(staticTable);
|
|
|
|
} else {
|
|
|
|
table = frame->popObject();
|
|
|
|
}
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (fieldCode(t, field)) {
|
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
2008-04-09 19:08:13 +00:00
|
|
|
c->mov1(value, c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-10-17 01:21:35 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case CharField:
|
|
|
|
case ShortField:
|
2008-04-09 19:08:13 +00:00
|
|
|
c->mov2(value, c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-10-17 01:21:35 +00:00
|
|
|
break;
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
case FloatField:
|
|
|
|
case IntField:
|
2008-04-09 19:08:13 +00:00
|
|
|
c->mov4(value, c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-10-10 17:26:28 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case DoubleField:
|
|
|
|
case LongField:
|
2008-04-09 19:08:13 +00:00
|
|
|
c->mov8(value, c->memory(table, fieldOffset(t, field), 0, 1));
|
2007-10-10 17:26:28 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ObjectField:
|
2007-12-31 22:40:56 +00:00
|
|
|
if (instruction == putfield) {
|
2007-12-30 22:24:48 +00:00
|
|
|
c->indirectCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(setMaybeNull)),
|
2007-12-31 22:40:56 +00:00
|
|
|
frame->trace(0, false),
|
2007-12-30 22:24:48 +00:00
|
|
|
4, c->thread(), table, c->constant(fieldOffset(t, field)), value);
|
|
|
|
} else {
|
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(set)),
|
|
|
|
4, c->thread(), table, c->constant(fieldOffset(t, field)), value);
|
|
|
|
}
|
2007-10-10 17:26:28 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default: abort(t);
|
|
|
|
}
|
2007-12-12 22:19:13 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
if (instruction == putfield) {
|
2007-12-12 22:19:13 +00:00
|
|
|
c->release(table);
|
|
|
|
}
|
|
|
|
c->release(value);
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
case ret:
|
|
|
|
c->jmp
|
|
|
|
(c->memory
|
2007-12-31 22:40:56 +00:00
|
|
|
(c->base(), localOffset
|
|
|
|
(t, codeBody(t, code, ip), context->method)));
|
2007-12-26 23:59:55 +00:00
|
|
|
return;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case return_:
|
2007-12-28 00:02:05 +00:00
|
|
|
handleExit(t, frame);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->epilogue();
|
|
|
|
c->ret();
|
|
|
|
return;
|
2007-10-10 17:26:28 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case sipush:
|
|
|
|
frame->pushInt
|
|
|
|
(c->constant(static_cast<int16_t>(codeReadInt16(t, code, ip))));
|
|
|
|
break;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case swap:
|
|
|
|
frame->swap();
|
|
|
|
break;
|
2007-10-17 01:21:35 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case tableswitch: {
|
|
|
|
int32_t base = ip - 1;
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
ip = (ip + 3) & ~3; // pad to four byte boundary
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-03 18:37:00 +00:00
|
|
|
Operand* key = frame->popInt4();
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint32_t defaultIp = base + codeReadInt32(t, code, ip);
|
|
|
|
assert(t, defaultIp < codeLength(t, code));
|
|
|
|
|
|
|
|
int32_t bottom = codeReadInt32(t, code, ip);
|
|
|
|
int32_t top = codeReadInt32(t, code, ip);
|
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
Operand* start = 0;
|
|
|
|
uint32_t ipTable[top - bottom + 1];
|
|
|
|
for (int32_t i = 0; i < top - bottom + 1; ++i) {
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned index = ip + (i * 4);
|
|
|
|
uint32_t newIp = base + codeReadInt32(t, code, index);
|
|
|
|
assert(t, newIp < codeLength(t, code));
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-16 00:24:15 +00:00
|
|
|
ipTable[i] = newIp;
|
|
|
|
|
|
|
|
Promise* p = c->poolAppendPromise(c->machineIp(newIp));
|
2007-12-09 22:45:43 +00:00
|
|
|
if (i == 0) {
|
2007-12-16 00:24:15 +00:00
|
|
|
start = c->promiseConstant(p);
|
2007-09-26 23:23:03 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-12-16 00:24:15 +00:00
|
|
|
assert(t, start);
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
Operand* defaultCase = c->label();
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
c->cmp4(c->constant(bottom), key);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jl(defaultCase);
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
c->cmp4(c->constant(top), key);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jg(defaultCase);
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
c->sub4(c->constant(bottom), key);
|
2007-12-09 22:45:43 +00:00
|
|
|
c->jmp(c->memory(start, 0, key, BytesPerWord));
|
|
|
|
|
|
|
|
c->mark(defaultCase);
|
2007-12-16 00:24:15 +00:00
|
|
|
c->jmp(frame->machineIp(defaultIp));
|
2007-12-12 22:19:13 +00:00
|
|
|
|
|
|
|
c->release(key);
|
2007-12-16 00:24:15 +00:00
|
|
|
|
|
|
|
for (int32_t i = 0; i < top - bottom + 1; ++i) {
|
|
|
|
compile(t, frame, ipTable[i]);
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
ip = defaultIp;
|
|
|
|
} break;
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
case wide: {
|
|
|
|
switch (codeBody(t, code, ip++)) {
|
|
|
|
case aload: {
|
|
|
|
frame->loadObject(codeReadInt16(t, code, ip));
|
2007-10-04 22:41:19 +00:00
|
|
|
} break;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case astore: {
|
|
|
|
frame->storeObject(codeReadInt16(t, code, ip));
|
|
|
|
} break;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iinc: {
|
|
|
|
uint16_t index = codeReadInt16(t, code, ip);
|
|
|
|
uint16_t count = codeReadInt16(t, code, ip);
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
c->add4(c->constant(count),
|
|
|
|
c->memory(c->base(), localOffset(t, index, context->method)));
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case iload: {
|
|
|
|
frame->loadInt(codeReadInt16(t, code, ip));
|
|
|
|
} break;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case istore: {
|
|
|
|
frame->storeInt(codeReadInt16(t, code, ip));
|
|
|
|
} break;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lload: {
|
|
|
|
frame->loadLong(codeReadInt16(t, code, ip));
|
|
|
|
} break;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case lstore: {
|
|
|
|
frame->storeLong(codeReadInt16(t, code, ip));
|
|
|
|
} break;
|
2007-10-12 14:26:36 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case ret:
|
2007-12-26 23:59:55 +00:00
|
|
|
c->jmp
|
|
|
|
(c->memory
|
|
|
|
(c->base(), localOffset
|
2007-12-31 22:40:56 +00:00
|
|
|
(t, codeReadInt16(t, code, ip), context->method)));
|
2007-12-26 23:59:55 +00:00
|
|
|
return;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
} break;
|
2007-12-26 19:19:45 +00:00
|
|
|
|
|
|
|
default: abort(t);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
void
|
|
|
|
logCompile(const void* code, unsigned size, const char* class_,
|
2008-01-07 22:04:53 +00:00
|
|
|
const char* name, const char* spec)
|
2007-12-26 16:56:14 +00:00
|
|
|
{
|
2008-01-08 21:23:49 +00:00
|
|
|
fprintf(stderr, "%s.%s%s from %p to %p\n",
|
|
|
|
class_, name, spec, code,
|
|
|
|
static_cast<const uint8_t*>(code) + size);
|
2007-12-26 16:56:14 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
void
|
2008-04-11 19:03:40 +00:00
|
|
|
translateExceptionHandlerTable(MyThread* t, Compiler* c, object code,
|
|
|
|
intptr_t start)
|
2008-01-07 14:51:07 +00:00
|
|
|
{
|
|
|
|
object oldTable = codeExceptionHandlerTable(t, code);
|
|
|
|
if (oldTable) {
|
|
|
|
PROTECT(t, code);
|
|
|
|
PROTECT(t, oldTable);
|
|
|
|
|
|
|
|
unsigned length = exceptionHandlerTableLength(t, oldTable);
|
2008-04-11 19:03:40 +00:00
|
|
|
|
|
|
|
object newIndex = makeIntArray(t, length * 3, false);
|
|
|
|
PROTECT(t, newIndex);
|
|
|
|
|
|
|
|
object newTable = makeArray(t, length + 1, false);
|
|
|
|
set(t, newTable, ArrayBody, newIndex);
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
for (unsigned i = 0; i < length; ++i) {
|
|
|
|
ExceptionHandler* oldHandler = exceptionHandlerTableBody
|
|
|
|
(t, oldTable, i);
|
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
intArrayBody(t, newIndex, i * 3)
|
2008-01-07 16:01:35 +00:00
|
|
|
= c->machineIp(exceptionHandlerStart(oldHandler))->value(c) - start;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
intArrayBody(t, newIndex, (i * 3) + 1)
|
2008-01-07 16:01:35 +00:00
|
|
|
= c->machineIp(exceptionHandlerEnd(oldHandler))->value(c) - start;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
intArrayBody(t, newIndex, (i * 3) + 2)
|
2008-01-07 16:01:35 +00:00
|
|
|
= c->machineIp(exceptionHandlerIp(oldHandler))->value(c) - start;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
object type =
|
|
|
|
(exceptionHandlerCatchType(oldHandler) ?
|
|
|
|
singletonObject(t, codePool(t, code),
|
|
|
|
exceptionHandlerCatchType(oldHandler) - 1) : 0);
|
|
|
|
|
|
|
|
set(t, newTable, ArrayBody + ((i + 1) * BytesPerWord), type);
|
2008-01-07 14:51:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set(t, code, CodeExceptionHandlerTable, newTable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-04-11 19:03:40 +00:00
|
|
|
translateLineNumberTable(MyThread* t, Compiler* c, object code, intptr_t start)
|
2008-01-07 14:51:07 +00:00
|
|
|
{
|
|
|
|
object oldTable = codeLineNumberTable(t, code);
|
|
|
|
if (oldTable) {
|
|
|
|
PROTECT(t, code);
|
|
|
|
PROTECT(t, oldTable);
|
|
|
|
|
|
|
|
unsigned length = lineNumberTableLength(t, oldTable);
|
|
|
|
object newTable = makeLineNumberTable(t, length, false);
|
|
|
|
for (unsigned i = 0; i < length; ++i) {
|
|
|
|
LineNumber* oldLine = lineNumberTableBody(t, oldTable, i);
|
|
|
|
LineNumber* newLine = lineNumberTableBody(t, newTable, i);
|
|
|
|
|
|
|
|
lineNumberIp(newLine)
|
2008-01-07 16:01:35 +00:00
|
|
|
= c->machineIp(lineNumberIp(oldLine))->value(c) - start;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
|
|
|
lineNumberLine(newLine) = lineNumberLine(oldLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
set(t, code, CodeLineNumberTable, newTable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-01-07 16:01:35 +00:00
|
|
|
printSet(uintptr_t m)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 16; ++i) {
|
|
|
|
if ((m >> i) & 1) {
|
|
|
|
fprintf(stderr, "1");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "_");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
2008-01-20 23:03:28 +00:00
|
|
|
calculateFrameMaps(MyThread* t, Context* context, uintptr_t* originalRoots,
|
|
|
|
unsigned eventIndex)
|
2008-01-07 14:51:07 +00:00
|
|
|
{
|
2008-01-20 23:03:28 +00:00
|
|
|
// for each instruction with more than one predecessor, and for each
|
|
|
|
// stack position, determine if there exists a path to that
|
|
|
|
// instruction such that there is not an object pointer left at that
|
|
|
|
// stack position (i.e. it is uninitialized or contains primitive
|
|
|
|
// data).
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned mapSize = frameMapSizeInWords(t, context->method);
|
|
|
|
|
|
|
|
uintptr_t roots[mapSize];
|
2008-01-20 23:03:28 +00:00
|
|
|
if (originalRoots) {
|
|
|
|
memcpy(roots, originalRoots, mapSize * BytesPerWord);
|
|
|
|
} else {
|
|
|
|
memset(roots, 0, mapSize * BytesPerWord);
|
|
|
|
}
|
2008-01-07 14:51:07 +00:00
|
|
|
|
|
|
|
int32_t ip = -1;
|
|
|
|
|
2008-01-08 17:10:24 +00:00
|
|
|
// invariant: for each stack position, roots contains a zero at that
|
|
|
|
// position if there exists some path to the current instruction
|
|
|
|
// such that there is definitely not an object pointer at that
|
|
|
|
// position. Otherwise, roots contains a one at that position,
|
|
|
|
// meaning either all known paths result in an object pointer at
|
|
|
|
// that position, or the contents of that position are as yet
|
|
|
|
// unknown.
|
|
|
|
|
2008-03-05 21:44:17 +00:00
|
|
|
unsigned length = context->eventLog.length();
|
|
|
|
while (eventIndex < length) {
|
2008-01-20 23:03:28 +00:00
|
|
|
Event e = static_cast<Event>(context->eventLog.get(eventIndex++));
|
2008-01-07 14:51:07 +00:00
|
|
|
switch (e) {
|
|
|
|
case PushEvent: {
|
2008-01-20 23:03:28 +00:00
|
|
|
eventIndex = calculateFrameMaps(t, context, roots, eventIndex);
|
2008-01-07 14:51:07 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case PopEvent:
|
2008-01-20 23:03:28 +00:00
|
|
|
return eventIndex;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
|
|
|
case IpEvent: {
|
2008-01-20 23:03:28 +00:00
|
|
|
ip = context->eventLog.get2(eventIndex);
|
2008-03-05 21:44:17 +00:00
|
|
|
eventIndex += 2;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2008-01-07 21:32:41 +00:00
|
|
|
if (DebugFrameMaps) {
|
|
|
|
fprintf(stderr, " roots at ip %3d: ", ip);
|
|
|
|
printSet(*roots);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
2008-01-20 23:03:28 +00:00
|
|
|
uintptr_t* tableRoots = context->rootTable + (ip * mapSize);
|
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
if (context->visitTable[ip] > 1) {
|
|
|
|
for (unsigned wi = 0; wi < mapSize; ++wi) {
|
2008-03-05 21:44:17 +00:00
|
|
|
uintptr_t newRoots = tableRoots[wi] & roots[wi];
|
|
|
|
|
|
|
|
if ((eventIndex == length
|
|
|
|
or context->eventLog.get(eventIndex) == PopEvent)
|
|
|
|
and newRoots != tableRoots[wi])
|
|
|
|
{
|
|
|
|
if (DebugFrameMaps) {
|
|
|
|
fprintf(stderr, "dirty roots!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
context->dirtyRoots = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
tableRoots[wi] = newRoots;
|
2008-01-08 15:24:57 +00:00
|
|
|
roots[wi] &= tableRoots[wi];
|
2008-01-07 14:51:07 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 16:01:35 +00:00
|
|
|
if (DebugFrameMaps) {
|
|
|
|
fprintf(stderr, "table roots at ip %3d: ", ip);
|
|
|
|
printSet(*tableRoots);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
2008-01-20 23:03:28 +00:00
|
|
|
} else {
|
|
|
|
memcpy(tableRoots, roots, mapSize * BytesPerWord);
|
2008-01-07 14:51:07 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case MarkEvent: {
|
2008-01-20 23:03:28 +00:00
|
|
|
unsigned i = context->eventLog.get2(eventIndex);
|
|
|
|
eventIndex += 2;
|
2008-01-07 14:51:07 +00:00
|
|
|
|
|
|
|
markBit(roots, i);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case ClearEvent: {
|
2008-01-20 23:03:28 +00:00
|
|
|
unsigned i = context->eventLog.get2(eventIndex);
|
|
|
|
eventIndex += 2;
|
2008-03-05 21:44:17 +00:00
|
|
|
|
|
|
|
clearBit(roots, i);
|
2008-01-07 14:51:07 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case TraceEvent: {
|
2008-01-20 23:03:28 +00:00
|
|
|
TraceElement* te; context->eventLog.get(eventIndex, &te, BytesPerWord);
|
2008-01-07 16:01:35 +00:00
|
|
|
memcpy(te->map, roots, mapSize * BytesPerWord);
|
|
|
|
|
2008-01-20 23:03:28 +00:00
|
|
|
eventIndex += BytesPerWord;
|
2008-01-07 14:51:07 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
}
|
2008-01-07 16:01:35 +00:00
|
|
|
|
2008-01-20 23:03:28 +00:00
|
|
|
return eventIndex;
|
2008-01-07 14:51:07 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 01:20:36 +00:00
|
|
|
Allocator*
|
|
|
|
codeAllocator(MyThread* t);
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
int
|
|
|
|
compareTraceElementPointers(const void* va, const void* vb)
|
|
|
|
{
|
|
|
|
TraceElement* a = *static_cast<TraceElement* const*>(va);
|
|
|
|
TraceElement* b = *static_cast<TraceElement* const*>(vb);
|
|
|
|
if (a->addressValue > b->addressValue) {
|
|
|
|
return 1;
|
|
|
|
} else if (a->addressValue < b->addressValue) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t
|
|
|
|
compareMethodBounds(Thread* t, object a, object b)
|
|
|
|
{
|
2008-04-10 23:48:28 +00:00
|
|
|
if (DebugMethodTree) {
|
|
|
|
fprintf(stderr, "compare %p to %p\n",
|
|
|
|
&singletonValue(t, methodCompiled(t, a), 0),
|
|
|
|
&singletonValue(t, methodCompiled(t, b), 0));
|
|
|
|
}
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
return reinterpret_cast<intptr_t>
|
|
|
|
(&singletonValue(t, methodCompiled(t, a), 0))
|
|
|
|
- reinterpret_cast<intptr_t>
|
|
|
|
(&singletonValue(t, methodCompiled(t, b), 0));
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object
|
2007-12-31 22:40:56 +00:00
|
|
|
finish(MyThread* t, Context* context, const char* name)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
Compiler* c = context->c;
|
2007-12-18 02:09:32 +00:00
|
|
|
|
2007-12-11 23:52:28 +00:00
|
|
|
unsigned count = ceiling(c->codeSize() + c->poolSize(), BytesPerWord);
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned size = count + singletonMaskSize(count);
|
2008-01-10 01:20:36 +00:00
|
|
|
object result = allocate3
|
|
|
|
(t, codeAllocator(t), Machine::ImmortalAllocation,
|
2008-01-13 22:05:08 +00:00
|
|
|
SingletonBody + (size * BytesPerWord), true, true);
|
2008-01-10 01:20:36 +00:00
|
|
|
initSingleton(t, result, size, true);
|
|
|
|
mark(t, result, 0);
|
2007-12-09 22:45:43 +00:00
|
|
|
singletonMask(t, result)[0] = 1;
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint8_t* start = reinterpret_cast<uint8_t*>(&singletonValue(t, result, 0));
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->writeTo(start);
|
2007-10-04 22:41:19 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
if (context->method) {
|
2007-12-16 22:41:07 +00:00
|
|
|
PROTECT(t, result);
|
2007-10-12 14:26:36 +00:00
|
|
|
|
2008-04-11 19:03:40 +00:00
|
|
|
translateExceptionHandlerTable(t, c, methodCode(t, context->method),
|
|
|
|
reinterpret_cast<intptr_t>(start));
|
|
|
|
|
|
|
|
translateLineNumberTable(t, c, methodCode(t, context->method),
|
|
|
|
reinterpret_cast<intptr_t>(start));
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
{ object code = methodCode(t, context->method);
|
|
|
|
|
|
|
|
code = makeCode(t, 0,
|
|
|
|
codeExceptionHandlerTable(t, code),
|
|
|
|
codeLineNumberTable(t, code),
|
|
|
|
codeMaxStack(t, code),
|
|
|
|
codeMaxLocals(t, code),
|
|
|
|
0, false);
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
set(t, context->method, MethodCode, code);
|
|
|
|
}
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (context->traceLogCount) {
|
|
|
|
TraceElement* elements[context->traceLogCount];
|
|
|
|
unsigned index = 0;
|
|
|
|
for (TraceElement* p = context->traceLog; p; p = p->next) {
|
|
|
|
elements[index++] = p;
|
|
|
|
p->addressValue = p->address->value(c);
|
|
|
|
|
|
|
|
if (p->target) {
|
|
|
|
insertCallNode
|
|
|
|
(t, makeCallNode
|
|
|
|
(t, p->address->value(c), p->target, p->virtualCall, 0));
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
qsort(elements, context->traceLogCount, sizeof(TraceElement*),
|
|
|
|
compareTraceElementPointers);
|
|
|
|
|
|
|
|
unsigned size = frameSize(t, context->method);
|
|
|
|
object map = makeIntArray
|
|
|
|
(t, context->traceLogCount
|
|
|
|
+ ceiling(context->traceLogCount * size, 32),
|
|
|
|
false);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < context->traceLogCount; ++i) {
|
|
|
|
TraceElement* p = elements[i];
|
|
|
|
|
|
|
|
intArrayBody(t, map, i) = static_cast<intptr_t>(p->addressValue)
|
|
|
|
- reinterpret_cast<intptr_t>(start);
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < size; ++j) {
|
|
|
|
unsigned index = ((i * size) + j);
|
|
|
|
int32_t* v = &intArrayBody
|
|
|
|
(t, map, context->traceLogCount + (index / 32));
|
|
|
|
|
|
|
|
if (getBit(p->map, j)) {
|
|
|
|
*v |= static_cast<int32_t>(1) << (index % 32);
|
|
|
|
} else {
|
|
|
|
*v &= ~(static_cast<int32_t>(1) << (index % 32));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set(t, methodCode(t, context->method), CodePool, map);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-08 21:41:41 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
for (PoolElement* p = context->objectPool; p; p = p->next) {
|
|
|
|
intptr_t offset = p->address->value(c)
|
|
|
|
- reinterpret_cast<intptr_t>(start);
|
|
|
|
|
|
|
|
singletonMarkObject(t, result, offset / BytesPerWord);
|
|
|
|
|
|
|
|
set(t, result, SingletonBody + offset, p->value);
|
|
|
|
}
|
|
|
|
|
2007-12-11 23:52:28 +00:00
|
|
|
if (Verbose) {
|
2007-12-31 22:40:56 +00:00
|
|
|
logCompile
|
|
|
|
(start, c->codeSize(),
|
|
|
|
reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
|
|
|
|
reinterpret_cast<const char*>
|
2008-01-07 22:04:53 +00:00
|
|
|
(&byteArrayBody(t, methodName(t, context->method), 0)),
|
|
|
|
reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, methodSpec(t, context->method), 0)));
|
2007-12-11 23:52:28 +00:00
|
|
|
}
|
2007-12-13 00:18:31 +00:00
|
|
|
|
|
|
|
// for debugging:
|
2007-12-23 00:00:35 +00:00
|
|
|
if (false and
|
2007-12-31 22:40:56 +00:00
|
|
|
strcmp
|
|
|
|
(reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, className(t, methodClass(t, context->method)), 0)),
|
2008-04-10 23:48:28 +00:00
|
|
|
"java/lang/System") == 0 and
|
2007-12-31 22:40:56 +00:00
|
|
|
strcmp
|
|
|
|
(reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, methodName(t, context->method), 0)),
|
2008-04-10 23:48:28 +00:00
|
|
|
"getProperty") == 0)
|
2007-12-13 00:18:31 +00:00
|
|
|
{
|
|
|
|
asm("int3");
|
|
|
|
}
|
2007-12-26 16:56:14 +00:00
|
|
|
} else {
|
|
|
|
if (Verbose) {
|
2008-01-07 22:04:53 +00:00
|
|
|
logCompile(start, c->codeSize(), 0, name, 0);
|
2007-12-26 16:56:14 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-09-27 22:20:54 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object
|
2007-12-31 22:40:56 +00:00
|
|
|
compile(MyThread* t, Context* context)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
Compiler* c = context->c;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-08 21:23:49 +00:00
|
|
|
// fprintf(stderr, "compiling %s.%s%s\n",
|
|
|
|
// &byteArrayBody(t, className(t, methodClass(t, context->method)), 0),
|
|
|
|
// &byteArrayBody(t, methodName(t, context->method), 0),
|
|
|
|
// &byteArrayBody(t, methodSpec(t, context->method), 0));
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
c->prologue();
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
unsigned footprint = methodParameterFootprint(t, context->method);
|
2008-01-20 18:55:08 +00:00
|
|
|
unsigned locals = localSize(t, context->method);
|
2007-12-12 18:59:45 +00:00
|
|
|
c->reserve(locals - footprint);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
uintptr_t stackMap[stackMapSizeInWords(t, context->method)];
|
|
|
|
Frame frame(context, stackMap);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned index = 0;
|
2008-01-07 16:01:35 +00:00
|
|
|
if ((methodFlags(t, context->method) & ACC_STATIC) == 0) {
|
2008-01-07 14:51:07 +00:00
|
|
|
frame.mark(index++);
|
|
|
|
}
|
|
|
|
|
2008-01-07 16:01:35 +00:00
|
|
|
for (MethodSpecIterator it
|
|
|
|
(t, reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, methodSpec(t, context->method), 0)));
|
|
|
|
it.hasNext();)
|
|
|
|
{
|
2008-01-07 14:51:07 +00:00
|
|
|
switch (*it.next()) {
|
|
|
|
case 'L':
|
|
|
|
case '[':
|
|
|
|
frame.mark(index++);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'J':
|
|
|
|
case 'D':
|
|
|
|
index += 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
++ index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-07 22:04:53 +00:00
|
|
|
handleEntrance(t, &frame);
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
compile(t, &frame, 0);
|
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-03-05 21:44:17 +00:00
|
|
|
context->dirtyRoots = false;
|
2008-01-20 23:03:28 +00:00
|
|
|
unsigned eventIndex = calculateFrameMaps(t, context, 0, 0);
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
object eht = codeExceptionHandlerTable(t, methodCode(t, context->method));
|
2007-12-09 22:45:43 +00:00
|
|
|
if (eht) {
|
|
|
|
PROTECT(t, eht);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-26 00:17:27 +00:00
|
|
|
unsigned visitCount = exceptionHandlerTableLength(t, eht);
|
|
|
|
bool visited[visitCount];
|
|
|
|
memset(visited, 0, visitCount);
|
|
|
|
|
|
|
|
while (visitCount) {
|
|
|
|
bool progress = false;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < exceptionHandlerTableLength(t, eht); ++i) {
|
|
|
|
ExceptionHandler* eh = exceptionHandlerTableBody(t, eht, i);
|
|
|
|
unsigned start = exceptionHandlerStart(eh);
|
|
|
|
|
|
|
|
if (not visited[i] and context->visitTable[start]) {
|
|
|
|
-- visitCount;
|
|
|
|
visited[i] = true;
|
|
|
|
progress = true;
|
|
|
|
|
|
|
|
uintptr_t stackMap[stackMapSizeInWords(t, context->method)];
|
|
|
|
Frame frame2(&frame, stackMap);
|
|
|
|
|
|
|
|
uintptr_t* roots = context->rootTable
|
|
|
|
+ (start * frameMapSizeInWords(t, context->method));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < localSize(t, context->method); ++ i) {
|
|
|
|
if (getBit(roots, i)) {
|
|
|
|
frame2.mark(i);
|
|
|
|
} else {
|
|
|
|
frame2.clear(i);
|
|
|
|
}
|
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-26 00:17:27 +00:00
|
|
|
frame2.pushObject();
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2008-01-26 00:17:27 +00:00
|
|
|
for (unsigned i = 1;
|
|
|
|
i < codeMaxStack(t, methodCode(t, context->method));
|
|
|
|
++i)
|
|
|
|
{
|
|
|
|
frame2.clear(localSize(t, context->method) + i);
|
|
|
|
}
|
2008-01-07 14:51:07 +00:00
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
compile(t, &frame2, exceptionHandlerIp(eh), true);
|
2008-01-26 00:17:27 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2008-01-20 23:03:28 +00:00
|
|
|
|
2008-01-26 00:17:27 +00:00
|
|
|
eventIndex = calculateFrameMaps(t, context, 0, eventIndex);
|
|
|
|
}
|
2008-01-20 23:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-01-26 00:17:27 +00:00
|
|
|
assert(t, progress);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-03-05 21:44:17 +00:00
|
|
|
while (context->dirtyRoots) {
|
|
|
|
context->dirtyRoots = false;
|
|
|
|
calculateFrameMaps(t, context, 0, 0);
|
|
|
|
}
|
2008-01-20 23:03:28 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
return finish(t, context, 0);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void
|
|
|
|
compile(MyThread* t, object method);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void*
|
2007-12-16 22:41:07 +00:00
|
|
|
compileMethod2(MyThread* t)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
object node = findCallNode(t, *static_cast<void**>(t->stack));
|
2007-12-16 22:41:07 +00:00
|
|
|
PROTECT(t, node);
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
object target = callNodeTarget(t, node);
|
2007-12-16 22:41:07 +00:00
|
|
|
PROTECT(t, target);
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (callNodeVirtualCall(t, node)) {
|
2008-01-11 22:16:24 +00:00
|
|
|
target = resolveTarget(t, t->stack, target);
|
2007-12-18 00:22:37 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
compile(t, target);
|
|
|
|
}
|
2007-10-13 21:48:40 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (UNLIKELY(t->exception)) {
|
2007-12-16 22:41:07 +00:00
|
|
|
return 0;
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-04-07 23:47:41 +00:00
|
|
|
if (callNodeVirtualCall(t, node)) {
|
|
|
|
classVtable
|
|
|
|
(t, objectClass
|
|
|
|
(t, resolveThisPointer(t, t->stack, target)), methodOffset(t, target))
|
|
|
|
= &singletonValue(t, methodCompiled(t, target), 0);
|
|
|
|
} else {
|
2008-04-08 00:03:58 +00:00
|
|
|
{ ACQUIRE(t, t->m->classLock);
|
|
|
|
removeCallNode(t, node);
|
|
|
|
}
|
2008-04-07 23:47:41 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
Context context(t);
|
|
|
|
context.c->updateCall
|
2008-04-07 23:47:41 +00:00
|
|
|
(reinterpret_cast<void*>(callNodeAddress(t, node)),
|
2007-12-31 22:40:56 +00:00
|
|
|
&singletonValue(t, methodCompiled(t, target), 0));
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
return &singletonValue(t, methodCompiled(t, target), 0);
|
|
|
|
}
|
|
|
|
}
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
void* FORCE_ALIGN
|
2007-12-16 22:41:07 +00:00
|
|
|
compileMethod(MyThread* t)
|
|
|
|
{
|
|
|
|
void* r = compileMethod2(t);
|
|
|
|
|
|
|
|
if (UNLIKELY(t->exception)) {
|
|
|
|
unwind(t);
|
|
|
|
} else {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uint64_t
|
|
|
|
invokeNative2(MyThread* t, object method)
|
|
|
|
{
|
|
|
|
PROTECT(t, method);
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-01-11 22:16:24 +00:00
|
|
|
assert(t, methodFlags(t, method) & ACC_NATIVE);
|
|
|
|
|
2008-01-08 19:36:34 +00:00
|
|
|
initClass(t, methodClass(t, method));
|
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2008-01-28 17:27:02 +00:00
|
|
|
if (methodCode(t, method) == 0) {
|
2007-12-09 22:45:43 +00:00
|
|
|
void* function = resolveNativeMethod(t, method);
|
|
|
|
if (UNLIKELY(function == 0)) {
|
|
|
|
object message = makeString
|
2008-01-31 00:08:47 +00:00
|
|
|
(t, "%s.%s%s",
|
|
|
|
&byteArrayBody(t, className(t, methodClass(t, method)), 0),
|
|
|
|
&byteArrayBody(t, methodName(t, method), 0),
|
|
|
|
&byteArrayBody(t, methodSpec(t, method), 0));
|
2007-12-09 22:45:43 +00:00
|
|
|
t->exception = makeUnsatisfiedLinkError(t, message);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object p = makePointer(t, function);
|
|
|
|
set(t, method, MethodCode, p);
|
|
|
|
}
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object class_ = methodClass(t, method);
|
|
|
|
PROTECT(t, class_);
|
2007-09-28 14:45:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned footprint = methodParameterFootprint(t, method) + 1;
|
|
|
|
if (methodFlags(t, method) & ACC_STATIC) {
|
|
|
|
++ footprint;
|
|
|
|
}
|
2008-01-03 19:49:07 +00:00
|
|
|
unsigned count = methodParameterCount(t, method) + 2;
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uintptr_t args[footprint];
|
|
|
|
unsigned argOffset = 0;
|
|
|
|
uint8_t types[count];
|
|
|
|
unsigned typeOffset = 0;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
args[argOffset++] = reinterpret_cast<uintptr_t>(t);
|
|
|
|
types[typeOffset++] = POINTER_TYPE;
|
2007-10-22 14:14:05 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
uintptr_t* sp = static_cast<uintptr_t*>(t->stack)
|
2007-12-15 01:11:01 +00:00
|
|
|
+ methodParameterFootprint(t, method);
|
2007-10-22 14:14:05 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (methodFlags(t, method) & ACC_STATIC) {
|
|
|
|
args[argOffset++] = reinterpret_cast<uintptr_t>(&class_);
|
|
|
|
} else {
|
|
|
|
args[argOffset++] = reinterpret_cast<uintptr_t>(sp--);
|
|
|
|
}
|
|
|
|
types[typeOffset++] = POINTER_TYPE;
|
2007-10-22 14:14:05 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MethodSpecIterator it
|
|
|
|
(t, reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, methodSpec(t, method), 0)));
|
|
|
|
|
|
|
|
while (it.hasNext()) {
|
|
|
|
unsigned type = types[typeOffset++]
|
|
|
|
= fieldType(t, fieldCode(t, *it.next()));
|
2007-10-22 14:14:05 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
switch (type) {
|
|
|
|
case INT8_TYPE:
|
|
|
|
case INT16_TYPE:
|
|
|
|
case INT32_TYPE:
|
|
|
|
case FLOAT_TYPE:
|
|
|
|
args[argOffset++] = *(sp--);
|
|
|
|
break;
|
2007-10-22 14:14:05 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case INT64_TYPE:
|
|
|
|
case DOUBLE_TYPE: {
|
2007-12-23 19:18:34 +00:00
|
|
|
memcpy(args + argOffset, sp - 1, 8);
|
2007-12-18 02:09:32 +00:00
|
|
|
argOffset += (8 / BytesPerWord);
|
2007-12-18 00:22:37 +00:00
|
|
|
sp -= 2;
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
case POINTER_TYPE: {
|
2007-12-20 00:02:32 +00:00
|
|
|
if (*sp) {
|
|
|
|
args[argOffset++] = reinterpret_cast<uintptr_t>(sp);
|
|
|
|
} else {
|
|
|
|
args[argOffset++] = 0;
|
|
|
|
}
|
|
|
|
-- sp;
|
2007-12-09 22:45:43 +00:00
|
|
|
} break;
|
2007-09-28 23:41:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
default: abort(t);
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void* function = pointerValue(t, methodCode(t, method));
|
2007-12-23 18:09:41 +00:00
|
|
|
unsigned returnCode = methodReturnCode(t, method);
|
|
|
|
unsigned returnType = fieldType(t, returnCode);
|
2007-12-09 22:45:43 +00:00
|
|
|
uint64_t result;
|
2008-01-20 22:05:59 +00:00
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
if (DebugNatives) {
|
2007-12-09 22:45:43 +00:00
|
|
|
fprintf(stderr, "invoke native method %s.%s\n",
|
|
|
|
&byteArrayBody(t, className(t, methodClass(t, method)), 0),
|
|
|
|
&byteArrayBody(t, methodName(t, method), 0));
|
|
|
|
}
|
2007-10-04 00:41:54 +00:00
|
|
|
|
2008-01-11 17:49:11 +00:00
|
|
|
if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
|
|
|
|
if (methodFlags(t, method) & ACC_STATIC) {
|
|
|
|
acquire(t, methodClass(t, method));
|
|
|
|
} else {
|
|
|
|
acquire(t, *reinterpret_cast<object*>(args[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-01 21:17:54 +00:00
|
|
|
Reference* reference = t->reference;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
{ ENTER(t, Thread::IdleState);
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
result = t->m->system->call
|
|
|
|
(function,
|
|
|
|
args,
|
|
|
|
types,
|
2008-01-03 19:49:07 +00:00
|
|
|
count,
|
2007-12-09 22:45:43 +00:00
|
|
|
footprint * BytesPerWord,
|
|
|
|
returnType);
|
2007-09-24 01:39:03 +00:00
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2008-01-11 17:49:11 +00:00
|
|
|
if (methodFlags(t, method) & ACC_SYNCHRONIZED) {
|
|
|
|
if (methodFlags(t, method) & ACC_STATIC) {
|
|
|
|
release(t, methodClass(t, method));
|
|
|
|
} else {
|
|
|
|
release(t, *reinterpret_cast<object*>(args[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-26 23:59:55 +00:00
|
|
|
if (DebugNatives) {
|
2007-12-09 22:45:43 +00:00
|
|
|
fprintf(stderr, "return from native method %s.%s\n",
|
|
|
|
&byteArrayBody(t, className(t, methodClass(t, method)), 0),
|
|
|
|
&byteArrayBody(t, methodName(t, method), 0));
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2007-12-23 18:09:41 +00:00
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
switch (returnCode) {
|
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = static_cast<int8_t>(result);
|
|
|
|
break;
|
2007-12-23 18:09:41 +00:00
|
|
|
|
|
|
|
case CharField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = static_cast<uint16_t>(result);
|
|
|
|
break;
|
2007-12-23 18:09:41 +00:00
|
|
|
|
|
|
|
case ShortField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = static_cast<int16_t>(result);
|
|
|
|
break;
|
2007-12-23 18:09:41 +00:00
|
|
|
|
|
|
|
case FloatField:
|
|
|
|
case IntField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = static_cast<int32_t>(result);
|
|
|
|
break;
|
2007-12-18 02:09:32 +00:00
|
|
|
|
2007-12-23 18:09:41 +00:00
|
|
|
case LongField:
|
|
|
|
case DoubleField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = result;
|
|
|
|
break;
|
2007-12-23 18:09:41 +00:00
|
|
|
|
|
|
|
case ObjectField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = static_cast<uintptr_t>(result) ? *reinterpret_cast<uintptr_t*>
|
2007-12-23 18:09:41 +00:00
|
|
|
(static_cast<uintptr_t>(result)) : 0;
|
2008-02-01 21:17:54 +00:00
|
|
|
break;
|
2007-12-23 18:09:41 +00:00
|
|
|
|
|
|
|
case VoidField:
|
2008-02-01 21:17:54 +00:00
|
|
|
result = 0;
|
|
|
|
break;
|
2007-12-23 18:09:41 +00:00
|
|
|
|
|
|
|
default: abort(t);
|
2007-12-18 02:09:32 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
} else {
|
2008-02-01 21:17:54 +00:00
|
|
|
result = 0;
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
2008-02-01 21:17:54 +00:00
|
|
|
|
|
|
|
while (t->reference != reference) {
|
|
|
|
dispose(t, t->reference);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
2008-01-07 22:49:34 +00:00
|
|
|
uint64_t FORCE_ALIGN
|
2007-12-09 22:45:43 +00:00
|
|
|
invokeNative(MyThread* t)
|
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
if (t->trace->nativeMethod == 0) {
|
|
|
|
object node = findCallNode(t, *static_cast<void**>(t->stack));
|
|
|
|
t->trace->nativeMethod = callNodeTarget(t, node);
|
|
|
|
if (callNodeVirtualCall(t, node)) {
|
|
|
|
t->trace->nativeMethod = resolveTarget
|
|
|
|
(t, t->stack, t->trace->nativeMethod);
|
2008-04-01 17:37:59 +00:00
|
|
|
}
|
2008-01-11 22:16:24 +00:00
|
|
|
}
|
2008-04-01 17:37:59 +00:00
|
|
|
|
2007-12-17 22:38:59 +00:00
|
|
|
uint64_t result = 0;
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (LIKELY(t->exception == 0)) {
|
2008-04-07 23:47:41 +00:00
|
|
|
result = invokeNative2(t, t->trace->nativeMethod);
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2008-04-10 23:48:28 +00:00
|
|
|
t->trace->nativeMethod = 0;
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (UNLIKELY(t->exception)) {
|
|
|
|
unwind(t);
|
|
|
|
} else {
|
|
|
|
return result;
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2008-04-10 23:48:28 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
unsigned
|
|
|
|
frameMapIndex(MyThread* t, object method, int32_t offset)
|
|
|
|
{
|
|
|
|
object map = codePool(t, methodCode(t, method));
|
|
|
|
unsigned mapSize = ceiling
|
|
|
|
(intArrayLength(t, map), (32 / frameSize(t, method)) + 1);
|
|
|
|
unsigned indexSize = intArrayLength(t, map) - mapSize;
|
|
|
|
|
|
|
|
unsigned bottom = 0;
|
|
|
|
unsigned top = indexSize;
|
|
|
|
for (unsigned span = top - bottom; span; span = top - bottom) {
|
|
|
|
unsigned middle = bottom + (span / 2);
|
|
|
|
int32_t v = intArrayBody(t, map, middle);
|
|
|
|
|
|
|
|
if (offset == v) {
|
|
|
|
return (indexSize * 32) + (frameSize(t, method) * middle);
|
|
|
|
} else if (offset < v) {
|
|
|
|
top = middle;
|
|
|
|
} else {
|
|
|
|
bottom = middle + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
abort(t);
|
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void
|
2008-04-07 23:47:41 +00:00
|
|
|
visitStackAndLocals(MyThread* t, Heap::Visitor* v, void* base, object method,
|
|
|
|
void* ip, void* calleeBase, unsigned argumentFootprint)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-01-07 14:51:07 +00:00
|
|
|
unsigned count;
|
|
|
|
if (calleeBase) {
|
|
|
|
unsigned parameterFootprint = methodParameterFootprint(t, method);
|
|
|
|
unsigned height = static_cast<uintptr_t*>(base)
|
2008-01-07 16:01:35 +00:00
|
|
|
- static_cast<uintptr_t*>(calleeBase) - 2;
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-07 14:51:07 +00:00
|
|
|
count = parameterFootprint + height - argumentFootprint;
|
|
|
|
} else {
|
2008-01-20 18:55:08 +00:00
|
|
|
count = frameSize(t, method);
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count) {
|
2008-04-07 23:47:41 +00:00
|
|
|
object map = codePool(t, methodCode(t, method));
|
|
|
|
int index = frameMapIndex
|
|
|
|
(t, method, difference
|
|
|
|
(ip, &singletonValue(t, methodCompiled(t, method), 0)));
|
2007-09-29 20:24:14 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
for (unsigned i = 0; i < count; ++i) {
|
2008-04-07 23:47:41 +00:00
|
|
|
int j = index + i;
|
|
|
|
if ((intArrayBody(t, map, j / 32)
|
|
|
|
& (static_cast<int32_t>(1) << (j % 32))))
|
|
|
|
{
|
|
|
|
v->visit(localObject(t, base, method, i));
|
2007-10-17 01:21:35 +00:00
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
void
|
2007-12-09 22:45:43 +00:00
|
|
|
visitStack(MyThread* t, Heap::Visitor* v)
|
2007-09-26 23:23:03 +00:00
|
|
|
{
|
2007-12-30 22:24:48 +00:00
|
|
|
void* ip = t->ip;
|
2007-12-09 22:45:43 +00:00
|
|
|
void* base = t->base;
|
|
|
|
void** stack = static_cast<void**>(t->stack);
|
2008-01-02 01:07:12 +00:00
|
|
|
if (ip == 0 and stack) {
|
2007-12-30 22:24:48 +00:00
|
|
|
ip = *stack;
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyThread::CallTrace* trace = t->trace;
|
2008-01-07 14:51:07 +00:00
|
|
|
void* calleeBase = 0;
|
|
|
|
unsigned argumentFootprint = 0;
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-16 22:41:07 +00:00
|
|
|
while (stack) {
|
2008-04-07 23:47:41 +00:00
|
|
|
object method = methodForIp(t, ip);
|
|
|
|
if (method) {
|
|
|
|
PROTECT(t, method);
|
2008-01-07 16:01:35 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
visitStackAndLocals
|
|
|
|
(t, v, base, method, ip, calleeBase, argumentFootprint);
|
2008-01-07 14:51:07 +00:00
|
|
|
|
|
|
|
calleeBase = base;
|
2008-04-07 23:47:41 +00:00
|
|
|
argumentFootprint = methodParameterFootprint(t, method);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
stack = static_cast<void**>(base) + 1;
|
2008-01-02 01:07:12 +00:00
|
|
|
if (stack) {
|
|
|
|
ip = *stack;
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
base = *static_cast<void**>(base);
|
|
|
|
} else if (trace) {
|
2008-01-07 14:51:07 +00:00
|
|
|
calleeBase = 0;
|
|
|
|
argumentFootprint = 0;
|
2007-12-09 22:45:43 +00:00
|
|
|
base = trace->base;
|
|
|
|
stack = static_cast<void**>(trace->stack);
|
2008-01-02 01:07:12 +00:00
|
|
|
if (stack) {
|
|
|
|
ip = *stack;
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
trace = trace->next;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object
|
2007-12-31 22:40:56 +00:00
|
|
|
compileDefault(MyThread* t, Context* context)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
Compiler* c = context->c;
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
mov(c, c->base(), c->memory(c->thread(), difference(&(t->base), t)));
|
|
|
|
mov(c, c->stack(), c->memory(c->thread(), difference(&(t->stack), t)));
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-23 00:00:35 +00:00
|
|
|
c->directCall
|
2007-12-09 22:45:43 +00:00
|
|
|
(c->constant(reinterpret_cast<intptr_t>(compileMethod)),
|
2007-12-23 00:00:35 +00:00
|
|
|
1, c->thread());
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
Operand* result = ::result(c);
|
2007-12-23 00:00:35 +00:00
|
|
|
c->jmp(result);
|
|
|
|
c->release(result);
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
return finish(t, context, "default");
|
2007-09-26 23:23:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object
|
2007-12-31 22:40:56 +00:00
|
|
|
compileNative(MyThread* t, Context* context)
|
2007-09-26 23:23:03 +00:00
|
|
|
{
|
2007-12-31 22:40:56 +00:00
|
|
|
Compiler* c = context->c;
|
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
mov(c, c->base(), c->memory(c->thread(), difference(&(t->base), t)));
|
|
|
|
mov(c, c->stack(), c->memory(c->thread(), difference(&(t->stack), t)));
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-12 22:19:13 +00:00
|
|
|
c->directCall
|
|
|
|
(c->constant(reinterpret_cast<intptr_t>(invokeNative)), 1, c->thread());
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
c->ret();
|
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
return finish(t, context, "native");
|
2007-09-26 23:23:03 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
class ArgumentList {
|
|
|
|
public:
|
|
|
|
ArgumentList(Thread* t, uintptr_t* array, bool* objectMask, object this_,
|
|
|
|
const char* spec, bool indirectObjects, va_list arguments):
|
|
|
|
t(static_cast<MyThread*>(t)),
|
|
|
|
array(array),
|
|
|
|
objectMask(objectMask),
|
2007-10-12 17:56:43 +00:00
|
|
|
position(0),
|
|
|
|
protector(this)
|
2007-09-25 23:53:11 +00:00
|
|
|
{
|
|
|
|
if (this_) {
|
|
|
|
addObject(this_);
|
|
|
|
}
|
|
|
|
|
2007-10-12 17:56:43 +00:00
|
|
|
for (MethodSpecIterator it(t, spec); it.hasNext();) {
|
|
|
|
switch (*it.next()) {
|
2007-09-25 23:53:11 +00:00
|
|
|
case 'L':
|
|
|
|
case '[':
|
|
|
|
if (indirectObjects) {
|
|
|
|
object* v = va_arg(arguments, object*);
|
|
|
|
addObject(v ? *v : 0);
|
|
|
|
} else {
|
|
|
|
addObject(va_arg(arguments, object));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'J':
|
|
|
|
case 'D':
|
|
|
|
addLong(va_arg(arguments, uint64_t));
|
|
|
|
break;
|
2007-10-12 17:56:43 +00:00
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
default:
|
|
|
|
addInt(va_arg(arguments, uint32_t));
|
2007-10-12 17:56:43 +00:00
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
2007-10-12 17:56:43 +00:00
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ArgumentList(Thread* t, uintptr_t* array, bool* objectMask, object this_,
|
|
|
|
const char* spec, object arguments):
|
|
|
|
t(static_cast<MyThread*>(t)),
|
|
|
|
array(array),
|
|
|
|
objectMask(objectMask),
|
2007-10-12 17:56:43 +00:00
|
|
|
position(0),
|
|
|
|
protector(this)
|
2007-09-25 23:53:11 +00:00
|
|
|
{
|
|
|
|
if (this_) {
|
|
|
|
addObject(this_);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned index = 0;
|
2007-10-12 17:56:43 +00:00
|
|
|
for (MethodSpecIterator it(t, spec); it.hasNext();) {
|
|
|
|
switch (*it.next()) {
|
2007-09-25 23:53:11 +00:00
|
|
|
case 'L':
|
|
|
|
case '[':
|
|
|
|
addObject(objectArrayBody(t, arguments, index++));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'J':
|
|
|
|
case 'D':
|
|
|
|
addLong(cast<int64_t>(objectArrayBody(t, arguments, index++),
|
|
|
|
BytesPerWord));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
addInt(cast<int32_t>(objectArrayBody(t, arguments, index++),
|
|
|
|
BytesPerWord));
|
2007-10-12 17:56:43 +00:00
|
|
|
break;
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void addObject(object v) {
|
|
|
|
array[position] = reinterpret_cast<uintptr_t>(v);
|
|
|
|
objectMask[position] = true;
|
|
|
|
++ position;
|
|
|
|
}
|
|
|
|
|
2007-10-12 22:06:33 +00:00
|
|
|
void addInt(uintptr_t v) {
|
2007-09-25 23:53:11 +00:00
|
|
|
array[position] = v;
|
|
|
|
objectMask[position] = false;
|
|
|
|
++ position;
|
|
|
|
}
|
|
|
|
|
|
|
|
void addLong(uint64_t v) {
|
2007-12-23 20:06:24 +00:00
|
|
|
if (BytesPerWord == 8) {
|
|
|
|
memcpy(array + position + 1, &v, 8);
|
|
|
|
} else {
|
2008-01-16 01:01:11 +00:00
|
|
|
// push words in reverse order, since they will be switched back
|
|
|
|
// when pushed on the stack:
|
|
|
|
array[position] = v >> 32;
|
|
|
|
array[position + 1] = v;
|
2007-12-23 20:06:24 +00:00
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
objectMask[position] = false;
|
2007-12-23 20:06:24 +00:00
|
|
|
objectMask[position + 1] = false;
|
2007-09-25 23:53:11 +00:00
|
|
|
position += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyThread* t;
|
|
|
|
uintptr_t* array;
|
|
|
|
bool* objectMask;
|
|
|
|
unsigned position;
|
2007-10-12 17:56:43 +00:00
|
|
|
|
|
|
|
class MyProtector: public Thread::Protector {
|
|
|
|
public:
|
|
|
|
MyProtector(ArgumentList* list): Protector(list->t), list(list) { }
|
|
|
|
|
|
|
|
virtual void visit(Heap::Visitor* v) {
|
|
|
|
for (unsigned i = 0; i < list->position; ++i) {
|
|
|
|
if (list->objectMask[i]) {
|
2007-10-28 19:14:53 +00:00
|
|
|
v->visit(reinterpret_cast<object*>(list->array + i));
|
2007-10-12 17:56:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ArgumentList* list;
|
|
|
|
} protector;
|
2007-09-25 23:53:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
object
|
|
|
|
invoke(Thread* thread, object method, ArgumentList* arguments)
|
|
|
|
{
|
|
|
|
MyThread* t = static_cast<MyThread*>(thread);
|
|
|
|
|
2007-09-26 23:23:03 +00:00
|
|
|
unsigned returnCode = methodReturnCode(t, method);
|
2007-09-25 23:53:11 +00:00
|
|
|
unsigned returnType = fieldType(t, returnCode);
|
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
uint64_t result;
|
2007-09-30 02:48:27 +00:00
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
{ MyThread::CallTrace trace(t);
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (methodFlags(t, method) & ACC_NATIVE) {
|
|
|
|
trace.nativeMethod = method;
|
|
|
|
}
|
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
result = vmInvoke
|
|
|
|
(t, &singletonValue(t, methodCompiled(t, method), 0), arguments->array,
|
|
|
|
arguments->position, returnType);
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
|
|
|
object r;
|
|
|
|
switch (returnCode) {
|
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
|
|
|
case CharField:
|
|
|
|
case ShortField:
|
|
|
|
case FloatField:
|
|
|
|
case IntField:
|
|
|
|
r = makeInt(t, result);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LongField:
|
|
|
|
case DoubleField:
|
|
|
|
r = makeLong(t, result);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ObjectField:
|
2007-12-16 00:24:15 +00:00
|
|
|
r = reinterpret_cast<object>(result);
|
2007-09-25 23:53:11 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VoidField:
|
|
|
|
r = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
abort(t);
|
|
|
|
};
|
2007-09-24 01:39:03 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
unsigned
|
|
|
|
traceSize(Thread* t)
|
|
|
|
{
|
|
|
|
class Counter: public Processor::StackVisitor {
|
|
|
|
public:
|
|
|
|
Counter(Thread* t): t(t), count(0) { }
|
|
|
|
|
|
|
|
virtual bool visit(Processor::StackWalker*) {
|
|
|
|
++ count;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread* t;
|
|
|
|
unsigned count;
|
|
|
|
} counter(t);
|
|
|
|
|
|
|
|
t->m->processor->walkStack(t, &counter);
|
|
|
|
|
|
|
|
return FixedSizeOfArray + (counter.count * ArrayElementSizeOfArray)
|
|
|
|
+ (counter.count * FixedSizeOfTraceElement);
|
|
|
|
}
|
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
class SegFaultHandler: public System::SignalHandler {
|
|
|
|
public:
|
|
|
|
SegFaultHandler(): m(0) { }
|
|
|
|
|
2008-01-01 17:08:47 +00:00
|
|
|
virtual bool handleSignal(void** ip, void** base, void** stack,
|
|
|
|
void** thread)
|
|
|
|
{
|
2007-12-30 22:24:48 +00:00
|
|
|
MyThread* t = static_cast<MyThread*>(m->localThread->get());
|
2008-01-02 01:07:12 +00:00
|
|
|
if (t->state == Thread::ActiveState) {
|
2008-04-07 23:51:32 +00:00
|
|
|
object node = methodForIp(t, *ip);
|
2008-01-02 01:07:12 +00:00
|
|
|
if (node) {
|
|
|
|
t->ip = *ip;
|
|
|
|
t->base = *base;
|
|
|
|
t->stack = *stack;
|
2008-04-09 19:08:13 +00:00
|
|
|
|
|
|
|
ensure(t, FixedSizeOfNullPointerException + traceSize(t));
|
|
|
|
|
2008-01-02 01:07:12 +00:00
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
|
|
|
|
findUnwindTarget(t, ip, base, stack);
|
|
|
|
*thread = t;
|
|
|
|
return true;
|
|
|
|
}
|
2007-12-30 22:24:48 +00:00
|
|
|
}
|
2008-01-02 01:07:12 +00:00
|
|
|
return false;
|
2007-12-30 22:24:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Machine* m;
|
|
|
|
};
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
class MyProcessor: public Processor {
|
2007-09-24 01:39:03 +00:00
|
|
|
public:
|
2008-01-13 22:05:08 +00:00
|
|
|
MyProcessor(System* s, Allocator* allocator):
|
2007-09-25 23:53:11 +00:00
|
|
|
s(s),
|
2008-01-13 22:05:08 +00:00
|
|
|
allocator(allocator),
|
2007-12-09 22:45:43 +00:00
|
|
|
defaultCompiled(0),
|
|
|
|
nativeCompiled(0),
|
2008-04-07 23:47:41 +00:00
|
|
|
callTable(0),
|
|
|
|
callTableSize(0),
|
|
|
|
methodTree(0),
|
|
|
|
methodTreeSentinal(0),
|
2008-01-10 01:20:36 +00:00
|
|
|
indirectCaller(0),
|
|
|
|
indirectCallerSize(0),
|
2008-01-14 23:37:24 +00:00
|
|
|
codeAllocator(s, allocator, true, 64 * 1024)
|
2007-09-24 01:39:03 +00:00
|
|
|
{ }
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
virtual Thread*
|
|
|
|
makeThread(Machine* m, object javaThread, Thread* parent)
|
|
|
|
{
|
2008-01-14 23:37:24 +00:00
|
|
|
MyThread* t = new (m->heap->allocate(sizeof(MyThread), false))
|
2007-10-25 22:06:05 +00:00
|
|
|
MyThread(m, javaThread, parent);
|
|
|
|
t->init();
|
|
|
|
return t;
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object getDefaultCompiled(MyThread* t) {
|
|
|
|
if (defaultCompiled == 0) {
|
2007-12-31 22:40:56 +00:00
|
|
|
Context context(t);
|
|
|
|
defaultCompiled = compileDefault(t, &context);
|
2007-10-01 15:19:15 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
return defaultCompiled;
|
2007-10-01 15:19:15 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
object getNativeCompiled(MyThread* t) {
|
|
|
|
if (nativeCompiled == 0) {
|
2007-12-31 22:40:56 +00:00
|
|
|
Context context(t);
|
|
|
|
nativeCompiled = compileNative(t, &context);
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
return nativeCompiled;
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual object
|
|
|
|
makeMethod(vm::Thread* t,
|
|
|
|
uint8_t vmFlags,
|
|
|
|
uint8_t returnCode,
|
|
|
|
uint8_t parameterCount,
|
|
|
|
uint8_t parameterFootprint,
|
|
|
|
uint16_t flags,
|
|
|
|
uint16_t offset,
|
|
|
|
object name,
|
|
|
|
object spec,
|
|
|
|
object class_,
|
|
|
|
object code)
|
2007-10-04 03:19:39 +00:00
|
|
|
{
|
2007-12-09 22:45:43 +00:00
|
|
|
return vm::makeMethod
|
|
|
|
(t, vmFlags, returnCode, parameterCount, parameterFootprint, flags,
|
2008-01-20 22:05:59 +00:00
|
|
|
offset, name, spec, class_, code,
|
|
|
|
getDefaultCompiled(static_cast<MyThread*>(t)));
|
2007-10-04 03:19:39 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual object
|
|
|
|
makeClass(vm::Thread* t,
|
|
|
|
uint16_t flags,
|
|
|
|
uint8_t vmFlags,
|
|
|
|
uint8_t arrayDimensions,
|
|
|
|
uint16_t fixedSize,
|
|
|
|
uint16_t arrayElementSize,
|
|
|
|
object objectMask,
|
|
|
|
object name,
|
|
|
|
object super,
|
|
|
|
object interfaceTable,
|
|
|
|
object virtualTable,
|
|
|
|
object fieldTable,
|
|
|
|
object methodTable,
|
|
|
|
object staticTable,
|
|
|
|
object loader,
|
|
|
|
unsigned vtableLength)
|
2007-09-26 23:23:03 +00:00
|
|
|
{
|
2007-12-11 21:26:59 +00:00
|
|
|
return vm::makeClass
|
2007-12-09 22:45:43 +00:00
|
|
|
(t, flags, vmFlags, arrayDimensions, fixedSize, arrayElementSize,
|
|
|
|
objectMask, name, super, interfaceTable, virtualTable, fieldTable,
|
|
|
|
methodTable, staticTable, loader, vtableLength, false);
|
2007-12-11 21:26:59 +00:00
|
|
|
}
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2007-12-11 21:26:59 +00:00
|
|
|
virtual void
|
|
|
|
initVtable(Thread* t, object c)
|
|
|
|
{
|
2008-01-20 22:05:59 +00:00
|
|
|
void* compiled = &singletonBody
|
|
|
|
(t, getDefaultCompiled(static_cast<MyThread*>(t)), 0);
|
2007-09-26 23:23:03 +00:00
|
|
|
|
2008-01-20 22:05:59 +00:00
|
|
|
for (unsigned i = 0; i < classLength(t, c); ++i) {
|
|
|
|
classVtable(t, c, i) = compiled;
|
2007-09-26 23:23:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
initClass(Thread* t, object c)
|
|
|
|
{
|
|
|
|
PROTECT(t, c);
|
|
|
|
|
|
|
|
ACQUIRE(t, t->m->classLock);
|
|
|
|
if (classVmFlags(t, c) & NeedInitFlag
|
|
|
|
and (classVmFlags(t, c) & InitFlag) == 0)
|
|
|
|
{
|
2007-09-28 23:41:03 +00:00
|
|
|
classVmFlags(t, c) |= InitFlag;
|
2007-09-26 23:23:03 +00:00
|
|
|
invoke(t, classInitializer(t, c), 0);
|
|
|
|
if (t->exception) {
|
|
|
|
t->exception = makeExceptionInInitializerError(t, t->exception);
|
|
|
|
}
|
|
|
|
classVmFlags(t, c) &= ~(NeedInitFlag | InitFlag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
virtual void
|
2007-10-12 17:56:43 +00:00
|
|
|
visitObjects(Thread* vmt, Heap::Visitor* v)
|
2007-09-25 23:53:11 +00:00
|
|
|
{
|
2007-10-12 17:56:43 +00:00
|
|
|
MyThread* t = static_cast<MyThread*>(vmt);
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (t == t->m->rootThread) {
|
|
|
|
v->visit(&defaultCompiled);
|
|
|
|
v->visit(&nativeCompiled);
|
2008-04-07 23:47:41 +00:00
|
|
|
v->visit(&callTable);
|
|
|
|
v->visit(&methodTree);
|
|
|
|
v->visit(&methodTreeSentinal);
|
2007-10-14 01:18:25 +00:00
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
for (MyThread::CallTrace* trace = t->trace; trace; trace = trace->next) {
|
|
|
|
v->visit(&(trace->nativeMethod));
|
|
|
|
}
|
2008-04-01 17:37:59 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
for (Reference* r = t->reference; r; r = r->next) {
|
|
|
|
v->visit(&(r->target));
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
visitStack(t, v);
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual void
|
|
|
|
walkStack(Thread* vmt, StackVisitor* v)
|
2007-09-25 23:53:11 +00:00
|
|
|
{
|
2007-12-09 22:45:43 +00:00
|
|
|
MyThread* t = static_cast<MyThread*>(vmt);
|
2007-09-25 23:53:11 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyStackWalker walker(t);
|
|
|
|
walker.walk(v);
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
2007-10-04 22:41:19 +00:00
|
|
|
virtual int
|
2007-12-09 22:45:43 +00:00
|
|
|
lineNumber(Thread* vmt, object method, int ip)
|
2007-10-04 22:41:19 +00:00
|
|
|
{
|
2007-12-09 22:45:43 +00:00
|
|
|
return findLineNumber(static_cast<MyThread*>(vmt), method, ip);
|
2007-10-04 22:41:19 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
virtual object*
|
2007-09-30 03:33:38 +00:00
|
|
|
makeLocalReference(Thread* vmt, object o)
|
2007-09-25 23:53:11 +00:00
|
|
|
{
|
2007-09-30 03:33:38 +00:00
|
|
|
if (o) {
|
|
|
|
MyThread* t = static_cast<MyThread*>(vmt);
|
2008-01-13 22:05:08 +00:00
|
|
|
PROTECT(t, o);
|
2007-09-30 03:33:38 +00:00
|
|
|
|
2008-01-14 23:37:24 +00:00
|
|
|
Reference* r = new (t->m->heap->allocate(sizeof(Reference), false))
|
2007-09-30 03:33:38 +00:00
|
|
|
Reference(o, &(t->reference));
|
|
|
|
|
|
|
|
return &(r->target);
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
2007-09-30 03:33:38 +00:00
|
|
|
disposeLocalReference(Thread* t, object* r)
|
2007-09-25 23:53:11 +00:00
|
|
|
{
|
2007-09-30 03:33:38 +00:00
|
|
|
if (r) {
|
|
|
|
vm::dispose(t, reinterpret_cast<Reference*>(r));
|
|
|
|
}
|
2007-09-25 23:53:11 +00:00
|
|
|
}
|
|
|
|
|
2007-09-24 01:39:03 +00:00
|
|
|
virtual object
|
|
|
|
invokeArray(Thread* t, object method, object this_, object arguments)
|
|
|
|
{
|
2008-04-01 17:37:59 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2007-09-24 01:39:03 +00:00
|
|
|
assert(t, t->state == Thread::ActiveState
|
|
|
|
or t->state == Thread::ExclusiveState);
|
|
|
|
|
|
|
|
assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0));
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
const char* spec = reinterpret_cast<char*>
|
|
|
|
(&byteArrayBody(t, methodSpec(t, method), 0));
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned size = methodParameterFootprint(t, method);
|
2007-09-25 23:53:11 +00:00
|
|
|
uintptr_t array[size];
|
|
|
|
bool objectMask[size];
|
|
|
|
ArgumentList list(t, array, objectMask, this_, spec, arguments);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
PROTECT(t, method);
|
|
|
|
|
|
|
|
compile(static_cast<MyThread*>(t), method);
|
|
|
|
|
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
return ::invoke(t, method, &list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-24 01:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual object
|
|
|
|
invokeList(Thread* t, object method, object this_, bool indirectObjects,
|
|
|
|
va_list arguments)
|
|
|
|
{
|
2008-04-01 17:37:59 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2007-09-24 01:39:03 +00:00
|
|
|
assert(t, t->state == Thread::ActiveState
|
|
|
|
or t->state == Thread::ExclusiveState);
|
|
|
|
|
|
|
|
assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0));
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
const char* spec = reinterpret_cast<char*>
|
|
|
|
(&byteArrayBody(t, methodSpec(t, method), 0));
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned size = methodParameterFootprint(t, method);
|
2007-09-25 23:53:11 +00:00
|
|
|
uintptr_t array[size];
|
|
|
|
bool objectMask[size];
|
|
|
|
ArgumentList list
|
|
|
|
(t, array, objectMask, this_, spec, indirectObjects, arguments);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
PROTECT(t, method);
|
|
|
|
|
|
|
|
compile(static_cast<MyThread*>(t), method);
|
|
|
|
|
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
return ::invoke(t, method, &list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2007-09-24 01:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual object
|
|
|
|
invokeList(Thread* t, const char* className, const char* methodName,
|
|
|
|
const char* methodSpec, object this_, va_list arguments)
|
|
|
|
{
|
2008-04-01 17:37:59 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2007-09-24 01:39:03 +00:00
|
|
|
assert(t, t->state == Thread::ActiveState
|
|
|
|
or t->state == Thread::ExclusiveState);
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
unsigned size = parameterFootprint(t, methodSpec, false);
|
2007-09-25 23:53:11 +00:00
|
|
|
uintptr_t array[size];
|
|
|
|
bool objectMask[size];
|
|
|
|
ArgumentList list
|
|
|
|
(t, array, objectMask, this_, methodSpec, false, arguments);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
|
|
|
object method = resolveMethod(t, className, methodName, methodSpec);
|
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
assert(t, ((methodFlags(t, method) & ACC_STATIC) == 0) xor (this_ == 0));
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
PROTECT(t, method);
|
|
|
|
|
|
|
|
compile(static_cast<MyThread*>(t), method);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
return ::invoke(t, method, &list);
|
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-10-03 00:22:48 +00:00
|
|
|
|
2007-12-30 22:24:48 +00:00
|
|
|
virtual void dispose(Thread* vmt) {
|
|
|
|
MyThread* t = static_cast<MyThread*>(vmt);
|
|
|
|
|
2007-12-11 21:26:59 +00:00
|
|
|
while (t->reference) {
|
|
|
|
vm::dispose(t, t->reference);
|
|
|
|
}
|
2008-01-10 01:20:36 +00:00
|
|
|
|
2008-01-13 22:05:08 +00:00
|
|
|
t->m->heap->free(t, sizeof(*t), false);
|
2007-12-11 21:26:59 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
virtual void dispose() {
|
2008-01-10 01:20:36 +00:00
|
|
|
codeAllocator.dispose();
|
|
|
|
|
|
|
|
s->handleSegFault(0);
|
|
|
|
|
2008-01-13 22:05:08 +00:00
|
|
|
allocator->free(this, sizeof(*this), false);
|
2007-09-24 01:39:03 +00:00
|
|
|
}
|
2008-04-09 19:08:13 +00:00
|
|
|
|
|
|
|
virtual object getStackTrace(Thread* vmt, Thread* vmTarget) {
|
|
|
|
MyThread* t = static_cast<MyThread*>(vmt);
|
|
|
|
MyThread* target = static_cast<MyThread*>(vmTarget);
|
|
|
|
|
|
|
|
class Visitor: public System::ThreadVisitor {
|
|
|
|
public:
|
|
|
|
Visitor(MyThread* t, MyThread* target): t(t), target(target) { }
|
|
|
|
|
|
|
|
virtual void visit(void* ip, void* base, void* stack) {
|
|
|
|
ensure(t, traceSize(t));
|
|
|
|
|
|
|
|
void* oldIp = target->ip;
|
|
|
|
void* oldBase = target->ip;
|
|
|
|
void* oldStack = target->stack;
|
|
|
|
|
|
|
|
target->ip = ip;
|
|
|
|
target->base = base;
|
|
|
|
target->stack = stack;
|
|
|
|
|
|
|
|
trace = makeTrace(t, target);
|
|
|
|
|
|
|
|
target->ip = oldIp;
|
|
|
|
target->base = oldBase;
|
|
|
|
target->stack = oldStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
MyThread* t;
|
|
|
|
MyThread* target;
|
|
|
|
object trace;
|
|
|
|
} visitor(t, target);
|
|
|
|
|
|
|
|
if (t->backupHeap) {
|
|
|
|
PROTECT(t, visitor.trace);
|
|
|
|
|
|
|
|
collect(t, Heap::MinorCollection);
|
|
|
|
}
|
|
|
|
|
|
|
|
return visitor.trace;
|
|
|
|
}
|
2007-09-24 01:39:03 +00:00
|
|
|
|
|
|
|
System* s;
|
2008-01-13 22:05:08 +00:00
|
|
|
Allocator* allocator;
|
2007-12-09 22:45:43 +00:00
|
|
|
object defaultCompiled;
|
|
|
|
object nativeCompiled;
|
2008-04-07 23:47:41 +00:00
|
|
|
object callTable;
|
|
|
|
unsigned callTableSize;
|
|
|
|
object methodTree;
|
|
|
|
object methodTreeSentinal;
|
2007-12-11 21:26:59 +00:00
|
|
|
uint8_t* indirectCaller;
|
2008-01-10 01:20:36 +00:00
|
|
|
unsigned indirectCallerSize;
|
2007-12-30 22:24:48 +00:00
|
|
|
SegFaultHandler segFaultHandler;
|
2008-01-10 01:20:36 +00:00
|
|
|
Zone codeAllocator;
|
2007-09-24 01:39:03 +00:00
|
|
|
};
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyProcessor*
|
|
|
|
processor(MyThread* t)
|
2007-10-04 03:19:39 +00:00
|
|
|
{
|
2007-12-09 22:45:43 +00:00
|
|
|
MyProcessor* p = static_cast<MyProcessor*>(t->m->processor);
|
2008-04-07 23:47:41 +00:00
|
|
|
if (p->callTable == 0) {
|
2007-12-09 22:45:43 +00:00
|
|
|
ACQUIRE(t, t->m->classLock);
|
2007-10-04 03:19:39 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (p->callTable == 0) {
|
|
|
|
p->callTable = makeArray(t, 128, true);
|
|
|
|
|
|
|
|
p->methodTree = p->methodTreeSentinal = makeTreeNode(t, 0, 0, 0);
|
|
|
|
set(t, p->methodTree, TreeNodeLeft, p->methodTreeSentinal);
|
|
|
|
set(t, p->methodTree, TreeNodeRight, p->methodTreeSentinal);
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2007-12-31 22:40:56 +00:00
|
|
|
Context context(t);
|
|
|
|
Compiler* c = context.c;
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
mov(c, c->base(), c->memory(c->thread(), difference(&(t->base), t)));
|
|
|
|
mov(c, c->stack(), c->memory(c->thread(), difference(&(t->stack), t)));
|
2007-12-09 22:45:43 +00:00
|
|
|
|
|
|
|
c->jmp(c->indirectTarget());
|
|
|
|
|
2008-01-10 01:20:36 +00:00
|
|
|
p->indirectCallerSize = c->codeSize();
|
2007-12-11 21:26:59 +00:00
|
|
|
p->indirectCaller = static_cast<uint8_t*>
|
2008-01-10 01:51:58 +00:00
|
|
|
(p->codeAllocator.allocate(p->indirectCallerSize));
|
2007-12-09 22:45:43 +00:00
|
|
|
c->writeTo(p->indirectCaller);
|
2007-12-11 21:26:59 +00:00
|
|
|
|
2007-12-26 16:56:14 +00:00
|
|
|
if (Verbose) {
|
2008-01-07 22:04:53 +00:00
|
|
|
logCompile(p->indirectCaller, c->codeSize(), 0, "indirect caller", 0);
|
2007-12-26 16:56:14 +00:00
|
|
|
}
|
2007-12-30 22:24:48 +00:00
|
|
|
|
2008-01-13 22:05:08 +00:00
|
|
|
p->segFaultHandler.m = t->m;
|
|
|
|
expect(t, t->m->system->success
|
|
|
|
(t->m->system->handleSegFault(&(p->segFaultHandler))));
|
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
2007-09-24 01:39:03 +00:00
|
|
|
|
2008-04-09 19:08:13 +00:00
|
|
|
object
|
|
|
|
defaultCompiled(MyThread* t)
|
|
|
|
{
|
|
|
|
return processor(t)->getDefaultCompiled(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
nativeCompiled(MyThread* t)
|
|
|
|
{
|
|
|
|
return processor(t)->getNativeCompiled(t);
|
|
|
|
}
|
|
|
|
|
2007-10-16 17:21:26 +00:00
|
|
|
void
|
2007-12-09 22:45:43 +00:00
|
|
|
compile(MyThread* t, object method)
|
|
|
|
{
|
|
|
|
MyProcessor* p = processor(t);
|
|
|
|
|
2007-12-11 21:26:59 +00:00
|
|
|
if (methodCompiled(t, method) == p->getDefaultCompiled(t)) {
|
2007-12-09 22:45:43 +00:00
|
|
|
PROTECT(t, method);
|
|
|
|
|
|
|
|
ACQUIRE(t, t->m->classLock);
|
|
|
|
|
2007-12-11 21:26:59 +00:00
|
|
|
if (methodCompiled(t, method) == p->getDefaultCompiled(t)) {
|
2008-01-08 19:36:34 +00:00
|
|
|
initClass(t, methodClass(t, method));
|
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
|
2008-01-08 21:23:49 +00:00
|
|
|
if (methodCompiled(t, method) == p->getDefaultCompiled(t)) {
|
2008-01-20 22:05:59 +00:00
|
|
|
object compiled;
|
|
|
|
if (methodFlags(t, method) & ACC_NATIVE) {
|
|
|
|
compiled = p->getNativeCompiled(t);
|
|
|
|
} else {
|
|
|
|
Context context(t, method, p->indirectCaller);
|
|
|
|
compiled = compile(t, &context);
|
2008-04-10 23:48:28 +00:00
|
|
|
if (UNLIKELY(t->exception)) return;
|
2008-01-20 22:05:59 +00:00
|
|
|
}
|
|
|
|
|
2008-01-08 21:23:49 +00:00
|
|
|
set(t, method, MethodCompiled, compiled);
|
2007-12-09 22:45:43 +00:00
|
|
|
|
2008-01-08 21:23:49 +00:00
|
|
|
if (methodVirtual(t, method)) {
|
|
|
|
classVtable(t, methodClass(t, method), methodOffset(t, method))
|
|
|
|
= &singletonValue(t, compiled, 0);
|
|
|
|
}
|
2008-04-10 23:48:28 +00:00
|
|
|
|
|
|
|
if ((methodFlags(t, method) & ACC_NATIVE) == 0) {
|
|
|
|
if (DebugMethodTree) {
|
|
|
|
fprintf(stderr, "insert method at %p\n",
|
|
|
|
&singletonValue(t, methodCompiled(t, method), 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
methodTree(t) = treeInsert
|
|
|
|
(t, methodTree(t), method, methodTreeSentinal(t),
|
|
|
|
compareMethodBounds);
|
|
|
|
}
|
2007-12-11 23:52:28 +00:00
|
|
|
}
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
2008-04-07 23:47:41 +00:00
|
|
|
findCallNode(MyThread* t, void* address)
|
2007-10-16 17:21:26 +00:00
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
if (DebugCallTable) {
|
2007-12-12 01:19:03 +00:00
|
|
|
fprintf(stderr, "find trace node %p\n", address);
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyProcessor* p = processor(t);
|
2008-04-07 23:47:41 +00:00
|
|
|
object table = p->callTable;
|
2007-12-11 00:48:09 +00:00
|
|
|
|
|
|
|
intptr_t key = reinterpret_cast<intptr_t>(address);
|
|
|
|
unsigned index = static_cast<uintptr_t>(key)
|
2007-12-28 16:50:26 +00:00
|
|
|
& (arrayLength(t, table) - 1);
|
2007-12-11 00:48:09 +00:00
|
|
|
|
2007-12-28 16:50:26 +00:00
|
|
|
for (object n = arrayBody(t, table, index);
|
2008-04-07 23:47:41 +00:00
|
|
|
n; n = callNodeNext(t, n))
|
2007-12-11 00:48:09 +00:00
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
intptr_t k = callNodeAddress(t, n);
|
2007-12-11 00:48:09 +00:00
|
|
|
|
|
|
|
if (k == key) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
}
|
2007-12-14 18:27:56 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-12-11 00:48:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
resizeTable(MyThread* t, object oldTable, unsigned newLength)
|
|
|
|
{
|
|
|
|
PROTECT(t, oldTable);
|
|
|
|
|
2007-12-28 16:50:26 +00:00
|
|
|
object oldNode = 0;
|
|
|
|
PROTECT(t, oldNode);
|
|
|
|
|
2007-12-11 00:48:09 +00:00
|
|
|
object newTable = makeArray(t, newLength, true);
|
2008-01-02 01:07:12 +00:00
|
|
|
PROTECT(t, newTable);
|
2007-12-11 00:48:09 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < arrayLength(t, oldTable); ++i) {
|
2007-12-28 16:50:26 +00:00
|
|
|
for (oldNode = arrayBody(t, oldTable, i);
|
|
|
|
oldNode;
|
2008-04-07 23:47:41 +00:00
|
|
|
oldNode = callNodeNext(t, oldNode))
|
2007-12-28 16:50:26 +00:00
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
intptr_t k = callNodeAddress(t, oldNode);
|
2007-12-11 00:48:09 +00:00
|
|
|
|
|
|
|
unsigned index = k & (newLength - 1);
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
object newNode = makeCallNode
|
|
|
|
(t, callNodeAddress(t, oldNode),
|
|
|
|
callNodeTarget(t, oldNode),
|
|
|
|
callNodeVirtualCall(t, oldNode),
|
|
|
|
arrayBody(t, newTable, index));
|
2007-12-28 16:50:26 +00:00
|
|
|
|
|
|
|
set(t, newTable, ArrayBody + (index * BytesPerWord), newNode);
|
2007-12-11 00:48:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newTable;
|
2007-12-09 22:45:43 +00:00
|
|
|
}
|
2007-10-16 17:21:26 +00:00
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
void
|
2008-04-07 23:47:41 +00:00
|
|
|
insertCallNode(MyThread* t, object node)
|
2007-12-09 22:45:43 +00:00
|
|
|
{
|
2008-04-07 23:47:41 +00:00
|
|
|
if (DebugCallTable) {
|
2007-12-12 01:19:03 +00:00
|
|
|
fprintf(stderr, "insert trace node %p\n",
|
2008-04-07 23:47:41 +00:00
|
|
|
reinterpret_cast<void*>(callNodeAddress(t, node)));
|
2007-12-12 01:19:03 +00:00
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
MyProcessor* p = processor(t);
|
2007-12-11 21:26:59 +00:00
|
|
|
PROTECT(t, node);
|
2007-12-11 00:48:09 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
++ p->callTableSize;
|
|
|
|
|
|
|
|
if (p->callTableSize >= arrayLength(t, p->callTable) * 2) {
|
|
|
|
p->callTable = resizeTable
|
|
|
|
(t, p->callTable, arrayLength(t, p->callTable) * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t key = callNodeAddress(t, node);
|
|
|
|
unsigned index = static_cast<uintptr_t>(key)
|
|
|
|
& (arrayLength(t, p->callTable) - 1);
|
|
|
|
|
|
|
|
set(t, node, CallNodeNext, arrayBody(t, p->callTable, index));
|
|
|
|
set(t, p->callTable, ArrayBody + (index * BytesPerWord), node);
|
|
|
|
}
|
2007-12-11 00:48:09 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
void
|
|
|
|
removeCallNode(MyThread* t, object node)
|
|
|
|
{
|
|
|
|
if (DebugCallTable) {
|
|
|
|
fprintf(stderr, "remove call node %p\n",
|
|
|
|
reinterpret_cast<void*>(callNodeAddress(t, node)));
|
2007-12-11 00:48:09 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
MyProcessor* p = processor(t);
|
|
|
|
PROTECT(t, node);
|
|
|
|
|
|
|
|
object oldNode = 0;
|
|
|
|
PROTECT(t, oldNode);
|
|
|
|
|
|
|
|
object newNode = 0;
|
|
|
|
PROTECT(t, newNode);
|
|
|
|
|
|
|
|
intptr_t key = callNodeAddress(t, node);
|
2007-12-11 00:48:09 +00:00
|
|
|
unsigned index = static_cast<uintptr_t>(key)
|
2008-04-07 23:47:41 +00:00
|
|
|
& (arrayLength(t, p->callTable) - 1);
|
|
|
|
|
|
|
|
for (oldNode = arrayBody(t, p->callTable, index);
|
|
|
|
oldNode;
|
|
|
|
oldNode = callNodeNext(t, oldNode))
|
|
|
|
{
|
|
|
|
if (oldNode != node) {
|
|
|
|
newNode = makeCallNode
|
|
|
|
(t, callNodeAddress(t, oldNode),
|
|
|
|
callNodeTarget(t, oldNode),
|
|
|
|
callNodeVirtualCall(t, oldNode),
|
|
|
|
newNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set(t, p->callTable, ArrayBody + (index * BytesPerWord), newNode);
|
|
|
|
|
|
|
|
-- p->callTableSize;
|
2007-12-11 00:48:09 +00:00
|
|
|
|
2008-04-07 23:47:41 +00:00
|
|
|
if (p->callTableSize <= arrayLength(t, p->callTable) / 3) {
|
|
|
|
p->callTable = resizeTable
|
|
|
|
(t, p->callTable, arrayLength(t, p->callTable) / 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object&
|
|
|
|
methodTree(MyThread* t)
|
|
|
|
{
|
|
|
|
return processor(t)->methodTree;
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
methodTreeSentinal(MyThread* t)
|
|
|
|
{
|
|
|
|
return processor(t)->methodTreeSentinal;
|
2007-10-16 17:21:26 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 01:20:36 +00:00
|
|
|
Allocator*
|
|
|
|
codeAllocator(MyThread* t) {
|
|
|
|
return &(processor(t)->codeAllocator);
|
|
|
|
}
|
|
|
|
|
2007-12-09 22:45:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
|
2007-09-25 23:53:11 +00:00
|
|
|
Processor*
|
2008-01-13 22:05:08 +00:00
|
|
|
makeProcessor(System* system, Allocator* allocator)
|
2007-09-24 01:39:03 +00:00
|
|
|
{
|
2008-01-14 23:37:24 +00:00
|
|
|
return new (allocator->allocate(sizeof(MyProcessor), false))
|
2008-01-13 22:05:08 +00:00
|
|
|
MyProcessor(system, allocator);
|
2007-09-24 01:39:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace vm
|