2007-06-03 02:00:23 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "heap.h"
|
2007-06-25 02:02:24 +00:00
|
|
|
#include "class-finder.h"
|
2007-06-16 01:02:24 +00:00
|
|
|
#include "stream.h"
|
2007-06-18 19:23:44 +00:00
|
|
|
#include "constants.h"
|
2007-06-25 02:02:24 +00:00
|
|
|
#include "jni-vm.h"
|
2007-06-18 21:13:21 +00:00
|
|
|
#include "vm.h"
|
2007-06-03 02:00:23 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
#define PROTECT(thread, name) \
|
|
|
|
Thread::Protector MAKE_NAME(protector_) (thread, &name);
|
2007-06-07 00:30:16 +00:00
|
|
|
|
2007-06-15 00:50:55 +00:00
|
|
|
#define ACQUIRE(t, x) MonitorResource MAKE_NAME(monitorResource_) (t, x)
|
|
|
|
#define ACQUIRE_RAW(t, x) RawMonitorResource MAKE_NAME(monitorResource_) (t, x)
|
2007-06-14 23:55:06 +00:00
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
using namespace vm;
|
|
|
|
|
2007-05-21 15:47:44 +00:00
|
|
|
namespace {
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
static const bool Debug = true;
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
class Thread;
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
void (*Initializer)(Thread*, object);
|
|
|
|
|
2007-06-18 04:09:02 +00:00
|
|
|
void assert(Thread*, bool);
|
2007-06-24 19:57:00 +00:00
|
|
|
void expect(Thread*, bool);
|
2007-06-18 04:09:02 +00:00
|
|
|
object resolveClass(Thread*, object);
|
2007-06-18 21:13:21 +00:00
|
|
|
object allocate(Thread*, unsigned);
|
2007-06-21 18:35:24 +00:00
|
|
|
object& arrayBodyUnsafe(Thread*, object, unsigned);
|
2007-06-18 21:13:21 +00:00
|
|
|
void set(Thread*, object&, object);
|
2007-06-24 21:49:04 +00:00
|
|
|
object makeString(Thread*, const char*, ...);
|
2007-06-24 19:57:00 +00:00
|
|
|
object makeByteArray(Thread*, const char*, ...);
|
2007-06-18 19:23:44 +00:00
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
object&
|
|
|
|
objectClass(object o)
|
|
|
|
{
|
|
|
|
return cast<object>(o, 0);
|
|
|
|
}
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
enum FieldCode {
|
2007-06-24 21:49:04 +00:00
|
|
|
VoidField,
|
2007-06-24 01:39:49 +00:00
|
|
|
ByteField,
|
|
|
|
CharField,
|
|
|
|
DoubleField,
|
|
|
|
FloatField,
|
|
|
|
IntField,
|
|
|
|
LongField,
|
|
|
|
ShortField,
|
|
|
|
BooleanField,
|
|
|
|
ObjectField
|
|
|
|
};
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
class Machine {
|
|
|
|
public:
|
2007-06-18 21:13:21 +00:00
|
|
|
enum {
|
|
|
|
#include "type-enums.cpp"
|
|
|
|
} Type;
|
|
|
|
|
2007-06-20 16:58:35 +00:00
|
|
|
Machine(System* system, Heap* heap, ClassFinder* classFinder);
|
|
|
|
|
2007-06-20 17:42:13 +00:00
|
|
|
~Machine() {
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
2007-06-22 22:47:57 +00:00
|
|
|
void dispose();
|
2007-06-20 17:42:13 +00:00
|
|
|
|
|
|
|
System* system;
|
2007-06-03 02:00:23 +00:00
|
|
|
Heap* heap;
|
2007-06-14 23:55:06 +00:00
|
|
|
ClassFinder* classFinder;
|
2007-06-03 02:00:23 +00:00
|
|
|
Thread* rootThread;
|
|
|
|
Thread* exclusive;
|
|
|
|
unsigned activeCount;
|
|
|
|
unsigned liveCount;
|
|
|
|
System::Monitor* stateLock;
|
2007-06-08 14:23:04 +00:00
|
|
|
System::Monitor* heapLock;
|
2007-06-14 23:55:06 +00:00
|
|
|
System::Monitor* classLock;
|
2007-06-24 19:57:00 +00:00
|
|
|
System::Library* libraries;
|
2007-06-14 23:55:06 +00:00
|
|
|
object classMap;
|
2007-06-24 19:57:00 +00:00
|
|
|
object bootstrapClassMap;
|
2007-06-24 21:49:04 +00:00
|
|
|
object builtinMap;
|
2007-06-18 21:13:21 +00:00
|
|
|
object types;
|
2007-06-21 18:35:24 +00:00
|
|
|
bool unsafe;
|
2007-06-25 02:02:24 +00:00
|
|
|
JNIEnvVTable jniEnvVTable;
|
2007-06-03 02:00:23 +00:00
|
|
|
};
|
|
|
|
|
2007-06-22 22:47:57 +00:00
|
|
|
class Chain {
|
|
|
|
public:
|
|
|
|
Chain(Chain* next): next(next) { }
|
|
|
|
|
|
|
|
static unsigned footprint(unsigned sizeInBytes) {
|
|
|
|
return sizeof(Chain) + sizeInBytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t* data() {
|
|
|
|
return reinterpret_cast<uint8_t*>(this) + sizeof(Chain);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dispose(System* s, Chain* c) {
|
|
|
|
if (c) {
|
|
|
|
if (c->next) dispose(s, c->next);
|
|
|
|
s->free(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Chain* next;
|
|
|
|
};
|
|
|
|
|
2007-06-25 02:02:24 +00:00
|
|
|
class Thread : public JNIEnv {
|
2007-06-03 02:00:23 +00:00
|
|
|
public:
|
|
|
|
enum State {
|
|
|
|
NoState,
|
|
|
|
ActiveState,
|
|
|
|
IdleState,
|
|
|
|
ZombieState,
|
|
|
|
ExclusiveState,
|
|
|
|
ExitState
|
|
|
|
};
|
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
class Protector {
|
|
|
|
public:
|
|
|
|
Protector(Thread* t, object* p): t(t), p(p), next(t->protector) {
|
|
|
|
t->protector = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
~Protector() {
|
|
|
|
t->protector = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
Thread* t;
|
|
|
|
object* p;
|
|
|
|
Protector* next;
|
|
|
|
};
|
|
|
|
|
2007-06-22 20:55:11 +00:00
|
|
|
static const unsigned HeapSizeInBytes = 64 * 1024;
|
|
|
|
static const unsigned StackSizeInBytes = 64 * 1024;
|
2007-06-03 02:00:23 +00:00
|
|
|
|
2007-06-22 21:31:45 +00:00
|
|
|
static const unsigned HeapSizeInWords = HeapSizeInBytes / BytesPerWord;
|
|
|
|
static const unsigned StackSizeInWords = StackSizeInBytes / BytesPerWord;
|
|
|
|
|
2007-06-20 17:42:13 +00:00
|
|
|
Thread(Machine* m);
|
|
|
|
|
2007-06-22 22:47:57 +00:00
|
|
|
void dispose();
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
Machine* vm;
|
|
|
|
Thread* next;
|
|
|
|
Thread* child;
|
|
|
|
State state;
|
2007-06-13 14:03:08 +00:00
|
|
|
object thread;
|
2007-06-03 02:00:23 +00:00
|
|
|
object frame;
|
|
|
|
object code;
|
|
|
|
object exception;
|
2007-06-08 14:23:04 +00:00
|
|
|
unsigned ip;
|
2007-06-03 02:00:23 +00:00
|
|
|
unsigned sp;
|
|
|
|
unsigned heapIndex;
|
2007-06-08 00:23:12 +00:00
|
|
|
Protector* protector;
|
2007-06-22 22:47:57 +00:00
|
|
|
Chain* chain;
|
2007-06-25 01:34:07 +00:00
|
|
|
object stack[StackSizeInWords];
|
|
|
|
object heap[HeapSizeInWords];
|
2007-06-03 02:00:23 +00:00
|
|
|
};
|
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
#include "type-declarations.cpp"
|
|
|
|
#include "type-constructors.cpp"
|
2007-06-18 04:09:02 +00:00
|
|
|
|
2007-06-15 00:50:55 +00:00
|
|
|
void enter(Thread* t, Thread::State state);
|
|
|
|
|
2007-06-14 23:55:06 +00:00
|
|
|
class MonitorResource {
|
|
|
|
public:
|
2007-06-15 00:50:55 +00:00
|
|
|
MonitorResource(Thread* t, System::Monitor* m): t(t), m(m) {
|
|
|
|
if (not m->tryAcquire(t)) {
|
|
|
|
enter(t, Thread::IdleState);
|
|
|
|
m->acquire(t);
|
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~MonitorResource() { m->release(t); }
|
2007-06-14 23:55:06 +00:00
|
|
|
|
|
|
|
private:
|
2007-06-15 00:50:55 +00:00
|
|
|
Thread* t;
|
|
|
|
System::Monitor* m;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RawMonitorResource {
|
|
|
|
public:
|
|
|
|
RawMonitorResource(Thread* t, System::Monitor* m): t(t), m(m) {
|
|
|
|
m->acquire(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
~RawMonitorResource() { m->release(t); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Thread* t;
|
2007-06-14 23:55:06 +00:00
|
|
|
System::Monitor* m;
|
|
|
|
};
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
inline void NO_RETURN
|
|
|
|
abort(Thread* t)
|
|
|
|
{
|
2007-06-22 23:17:13 +00:00
|
|
|
abort(t->vm->system);
|
2007-06-03 02:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
assert(Thread* t, bool v)
|
|
|
|
{
|
2007-06-22 23:17:13 +00:00
|
|
|
assert(t->vm->system, v);
|
2007-06-03 02:00:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
inline void
|
|
|
|
expect(Thread* t, bool v)
|
|
|
|
{
|
|
|
|
expect(t->vm->system, v);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
hash(const int8_t* s, unsigned length)
|
|
|
|
{
|
|
|
|
uint32_t h = 0;
|
|
|
|
for (unsigned i = 0; i < length; ++i) h = (h * 31) + s[i];
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t
|
|
|
|
byteArrayHash(Thread* t, object array)
|
|
|
|
{
|
|
|
|
return hash(&byteArrayBody(t, array, 0), byteArrayLength(t, array));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
byteArrayEqual(Thread* t, object a, object b)
|
|
|
|
{
|
|
|
|
return a == b or
|
|
|
|
((byteArrayLength(t, a) == byteArrayLength(t, b)) and
|
|
|
|
memcmp(&byteArrayBody(t, a, 0), &byteArrayBody(t, b, 0),
|
|
|
|
byteArrayLength(t, a)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
intArrayEqual(Thread* t, object a, object b)
|
|
|
|
{
|
|
|
|
return a == b or
|
|
|
|
((intArrayLength(t, a) == intArrayLength(t, b)) and
|
|
|
|
memcmp(&intArrayBody(t, a, 0), &intArrayBody(t, b, 0),
|
|
|
|
intArrayLength(t, a) * 4) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t
|
|
|
|
methodHash(Thread* t, object method)
|
|
|
|
{
|
|
|
|
return byteArrayHash(t, methodName(t, method))
|
|
|
|
^ byteArrayHash(t, methodSpec(t, method));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
methodEqual(Thread* t, object a, object b)
|
|
|
|
{
|
|
|
|
return a == b or
|
|
|
|
(byteArrayEqual(t, methodName(t, a), methodName(t, b)) and
|
|
|
|
byteArrayEqual(t, methodSpec(t, a), methodSpec(t, b)));
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
hashMapFindNode(Thread* t, object map, object key,
|
|
|
|
uint32_t (*hash)(Thread*, object),
|
|
|
|
bool (*equal)(Thread*, object, object))
|
|
|
|
{
|
|
|
|
object array = hashMapArray(t, map);
|
|
|
|
if (array) {
|
|
|
|
unsigned index = hash(t, key) & (arrayLength(t, array) - 1);
|
|
|
|
object n = arrayBody(t, array, index);
|
|
|
|
while (n) {
|
|
|
|
if (equal(t, tripleFirst(t, n), key)) {
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = tripleThird(t, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
hashMapFind(Thread* t, object map, object key,
|
|
|
|
uint32_t (*hash)(Thread*, object),
|
|
|
|
bool (*equal)(Thread*, object, object))
|
|
|
|
{
|
|
|
|
object n = hashMapFindNode(t, map, key, hash, equal);
|
|
|
|
return (n ? tripleSecond(t, n) : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hashMapGrow(Thread* t, object map, uint32_t (*hash)(Thread*, object))
|
|
|
|
{
|
|
|
|
PROTECT(t, map);
|
|
|
|
|
|
|
|
object oldArray = hashMapArray(t, map);
|
|
|
|
unsigned oldLength = (oldArray ? arrayLength(t, oldArray) : 0);
|
|
|
|
PROTECT(t, oldArray);
|
|
|
|
|
|
|
|
unsigned newLength = (oldLength ? oldLength * 2 : 32);
|
|
|
|
object newArray = makeArray(t, newLength, true);
|
|
|
|
|
|
|
|
if (oldArray) {
|
|
|
|
for (unsigned i = 0; i < oldLength; ++i) {
|
|
|
|
object next;
|
|
|
|
for (object p = arrayBody(t, oldArray, i); p; p = next) {
|
|
|
|
next = tripleThird(t, p);
|
|
|
|
|
|
|
|
object key = tripleFirst(t, p);
|
|
|
|
unsigned index = hash(t, key) & (newLength - 1);
|
|
|
|
object n = arrayBody(t, newArray, index);
|
|
|
|
|
|
|
|
set(t, tripleThird(t, p), n);
|
|
|
|
set(t, arrayBody(t, newArray, index), p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set(t, hashMapArray(t, map), newArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
hashMapInsert(Thread* t, object map, object key, object value,
|
|
|
|
uint32_t (*hash)(Thread*, object))
|
|
|
|
{
|
|
|
|
object array = hashMapArray(t, map);
|
|
|
|
PROTECT(t, array);
|
|
|
|
|
|
|
|
++ hashMapSize(t, map);
|
|
|
|
|
|
|
|
if (array == 0 or hashMapSize(t, map) >= arrayLength(t, array) * 2) {
|
|
|
|
PROTECT(t, map);
|
|
|
|
PROTECT(t, key);
|
|
|
|
PROTECT(t, value);
|
|
|
|
|
|
|
|
hashMapGrow(t, map, hash);
|
|
|
|
array = hashMapArray(t, map);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned index = hash(t, key) & (arrayLength(t, array) - 1);
|
|
|
|
object n = arrayBody(t, array, index);
|
|
|
|
|
|
|
|
n = makeTriple(t, key, value, n);
|
|
|
|
|
|
|
|
set(t, arrayBody(t, array, index), n);
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
hashMapIterator(Thread* t, object map)
|
|
|
|
{
|
|
|
|
object array = hashMapArray(t, map);
|
|
|
|
if (array) {
|
|
|
|
for (unsigned i = 0; i < arrayLength(t, array); ++i) {
|
|
|
|
if (arrayBody(t, array, i)) {
|
|
|
|
return makeHashMapIterator(t, map, arrayBody(t, array, i), i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
hashMapIteratorNext(Thread* t, object it)
|
|
|
|
{
|
|
|
|
object map = hashMapIteratorMap(t, it);
|
|
|
|
object node = hashMapIteratorNode(t, it);
|
|
|
|
unsigned index = hashMapIteratorIndex(t, it);
|
|
|
|
|
|
|
|
if (tripleThird(t, node)) {
|
|
|
|
return makeHashMapIterator(t, map, tripleThird(t, node), index + 1);
|
|
|
|
} else {
|
|
|
|
object array = hashMapArray(t, map);
|
|
|
|
for (unsigned i = index; i < arrayLength(t, array); ++i) {
|
|
|
|
if (arrayBody(t, array, i)) {
|
|
|
|
return makeHashMapIterator(t, map, arrayBody(t, array, i), i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
listAppend(Thread* t, object list, object value)
|
|
|
|
{
|
|
|
|
PROTECT(t, list);
|
|
|
|
|
|
|
|
++ listSize(t, list);
|
|
|
|
|
|
|
|
object p = makePair(t, value, 0);
|
|
|
|
if (listFront(t, list)) {
|
|
|
|
set(t, pairSecond(t, listRear(t, list)), p);
|
|
|
|
} else {
|
|
|
|
set(t, listFront(t, list), p);
|
|
|
|
}
|
|
|
|
set(t, listRear(t, list), p);
|
|
|
|
}
|
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
inline void
|
|
|
|
push(Thread* t, object o)
|
|
|
|
{
|
|
|
|
t->stack[(t->sp)++] = o;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
pushSafe(Thread* t, object o)
|
|
|
|
{
|
|
|
|
expect(t, t->sp + 1 < Thread::StackSizeInWords);
|
|
|
|
push(t, o);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
pop(Thread* t)
|
|
|
|
{
|
|
|
|
return t->stack[--(t->sp)];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object&
|
|
|
|
top(Thread* t)
|
|
|
|
{
|
|
|
|
return t->stack[t->sp - 1];
|
|
|
|
}
|
|
|
|
|
2007-06-22 22:47:57 +00:00
|
|
|
void
|
|
|
|
Thread::dispose()
|
|
|
|
{
|
|
|
|
Chain::dispose(vm->system, chain);
|
|
|
|
|
|
|
|
for (Thread* c = child; c; c = c->next) {
|
|
|
|
c->dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:06:06 +00:00
|
|
|
void
|
2007-06-20 16:58:35 +00:00
|
|
|
visitRoots(Thread* t, Heap::Visitor* v)
|
2007-06-02 00:06:06 +00:00
|
|
|
{
|
2007-06-03 02:00:23 +00:00
|
|
|
t->heapIndex = 0;
|
|
|
|
|
2007-06-13 14:03:08 +00:00
|
|
|
v->visit(&(t->thread));
|
2007-06-02 00:06:06 +00:00
|
|
|
v->visit(&(t->frame));
|
|
|
|
v->visit(&(t->code));
|
|
|
|
v->visit(&(t->exception));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < t->sp; ++i) {
|
2007-06-21 23:23:43 +00:00
|
|
|
v->visit(t->stack + i);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
for (Thread::Protector* p = t->protector; p; p = p->next) {
|
|
|
|
v->visit(p->p);
|
|
|
|
}
|
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
for (Thread* c = t->child; c; c = c->next) {
|
|
|
|
visitRoots(c, v);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 22:47:57 +00:00
|
|
|
void
|
|
|
|
postCollect(Thread* t)
|
|
|
|
{
|
|
|
|
Chain::dispose(t->vm->system, t->chain);
|
|
|
|
t->chain = 0;
|
|
|
|
|
|
|
|
for (Thread* c = t->child; c; c = c->next) {
|
|
|
|
postCollect(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-02 00:06:06 +00:00
|
|
|
void
|
|
|
|
collect(Machine* m, Heap::CollectionType type)
|
|
|
|
{
|
2007-06-20 16:58:35 +00:00
|
|
|
class Client: public Heap::Client {
|
2007-06-02 00:06:06 +00:00
|
|
|
public:
|
2007-06-20 16:58:35 +00:00
|
|
|
Client(Machine* m): m(m) { }
|
2007-06-02 00:06:06 +00:00
|
|
|
|
2007-06-20 16:58:35 +00:00
|
|
|
virtual void visitRoots(Heap::Visitor* v) {
|
2007-06-14 23:55:06 +00:00
|
|
|
v->visit(&(m->classMap));
|
2007-06-24 19:57:00 +00:00
|
|
|
v->visit(&(m->bootstrapClassMap));
|
2007-06-24 21:49:04 +00:00
|
|
|
v->visit(&(m->builtinMap));
|
2007-06-18 21:13:21 +00:00
|
|
|
v->visit(&(m->types));
|
2007-06-14 23:55:06 +00:00
|
|
|
|
|
|
|
for (Thread* t = m->rootThread; t; t = t->next) {
|
2007-06-20 16:58:35 +00:00
|
|
|
::visitRoots(t, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned sizeInWords(void* p) {
|
2007-06-20 17:42:13 +00:00
|
|
|
Thread* t = m->rootThread;
|
|
|
|
|
2007-06-20 16:58:35 +00:00
|
|
|
p = m->heap->follow(p);
|
|
|
|
object class_ = m->heap->follow(objectClass(p));
|
|
|
|
|
2007-06-21 18:35:24 +00:00
|
|
|
unsigned n = divide(classFixedSize(t, class_), BytesPerWord);
|
|
|
|
|
2007-06-20 16:58:35 +00:00
|
|
|
if (classArrayElementSize(t, class_)) {
|
2007-06-21 18:35:24 +00:00
|
|
|
n += divide(classArrayElementSize(t, class_)
|
|
|
|
* cast<uint32_t>(p, classFixedSize(t, class_) - 4),
|
|
|
|
BytesPerWord);
|
2007-06-20 16:58:35 +00:00
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void walk(void* p, Heap::Walker* w) {
|
2007-06-20 17:42:13 +00:00
|
|
|
Thread* t = m->rootThread;
|
|
|
|
|
2007-06-20 16:58:35 +00:00
|
|
|
p = m->heap->follow(p);
|
|
|
|
object class_ = m->heap->follow(objectClass(p));
|
|
|
|
object objectMask = m->heap->follow(classObjectMask(t, class_));
|
|
|
|
|
2007-06-21 18:35:24 +00:00
|
|
|
if (objectMask) {
|
2007-06-21 22:50:52 +00:00
|
|
|
// fprintf(stderr, "p: %p; class: %p; mask: %p; mask length: %d\n",
|
|
|
|
// p, class_, objectMask, intArrayLength(t, objectMask));
|
2007-06-21 18:35:24 +00:00
|
|
|
|
|
|
|
unsigned fixedSize = classFixedSize(t, class_);
|
|
|
|
unsigned arrayElementSize = classArrayElementSize(t, class_);
|
|
|
|
unsigned arrayLength
|
|
|
|
= (arrayElementSize ? cast<uint32_t>(p, fixedSize - 4) : 0);
|
|
|
|
|
|
|
|
int mask[intArrayLength(t, objectMask)];
|
|
|
|
memcpy(mask, &intArrayBody(t, objectMask, 0),
|
|
|
|
intArrayLength(t, objectMask) * 4);
|
|
|
|
|
|
|
|
// fprintf
|
|
|
|
// (stderr,
|
|
|
|
// "fixed size: %d; array length: %d; element size: %d; mask: %x\n",
|
|
|
|
// fixedSize, arrayLength, arrayElementSize, mask[0]);
|
|
|
|
|
|
|
|
unsigned fixedSizeInWords = divide(fixedSize, BytesPerWord);
|
|
|
|
unsigned arrayElementSizeInWords
|
|
|
|
= divide(arrayElementSize, BytesPerWord);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < fixedSizeInWords; ++i) {
|
|
|
|
if (mask[wordOf(i)] & (static_cast<uintptr_t>(1) << bitOf(i))) {
|
|
|
|
if (not w->visit(i)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-06-20 16:58:35 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 18:35:24 +00:00
|
|
|
bool arrayObjectElements = false;
|
|
|
|
for (unsigned j = 0; j < arrayElementSizeInWords; ++j) {
|
|
|
|
unsigned k = fixedSizeInWords + j;
|
2007-06-20 16:58:35 +00:00
|
|
|
if (mask[wordOf(k)] & (static_cast<uintptr_t>(1) << bitOf(k))) {
|
2007-06-21 18:35:24 +00:00
|
|
|
arrayObjectElements = true;
|
|
|
|
break;
|
2007-06-20 16:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-21 18:35:24 +00:00
|
|
|
|
|
|
|
if (arrayObjectElements) {
|
|
|
|
for (unsigned i = 0; i < arrayLength; ++i) {
|
|
|
|
for (unsigned j = 0; j < arrayElementSizeInWords; ++j) {
|
|
|
|
unsigned k = fixedSizeInWords + j;
|
|
|
|
if (mask[wordOf(k)] & (static_cast<uintptr_t>(1) << bitOf(k))) {
|
|
|
|
if (not w->visit
|
|
|
|
(fixedSizeInWords + (i * arrayElementSizeInWords) + j))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
w->visit(0);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2007-06-14 23:55:06 +00:00
|
|
|
Machine* m;
|
2007-06-02 00:06:06 +00:00
|
|
|
} it(m);
|
|
|
|
|
2007-06-21 18:35:24 +00:00
|
|
|
m->unsafe = true;
|
2007-06-03 02:00:23 +00:00
|
|
|
m->heap->collect(type, &it);
|
2007-06-21 18:35:24 +00:00
|
|
|
m->unsafe = false;
|
2007-06-22 22:47:57 +00:00
|
|
|
|
|
|
|
postCollect(m->rootThread);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
void
|
|
|
|
enter(Thread* t, Thread::State s)
|
2007-06-02 00:06:06 +00:00
|
|
|
{
|
2007-06-05 00:28:52 +00:00
|
|
|
if (s == t->state) return;
|
2007-06-02 00:06:06 +00:00
|
|
|
|
2007-06-15 00:50:55 +00:00
|
|
|
ACQUIRE_RAW(t, t->vm->stateLock);
|
2007-06-02 00:06:06 +00:00
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
switch (s) {
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::ExclusiveState: {
|
|
|
|
assert(t, t->state == Thread::ActiveState);
|
2007-06-02 00:06:06 +00:00
|
|
|
|
|
|
|
while (t->vm->exclusive) {
|
2007-06-03 02:00:23 +00:00
|
|
|
// another thread got here first.
|
|
|
|
enter(t, Thread::IdleState);
|
|
|
|
enter(t, Thread::ActiveState);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
t->state = Thread::ExclusiveState;
|
2007-06-02 00:06:06 +00:00
|
|
|
t->vm->exclusive = t;
|
2007-06-03 02:00:23 +00:00
|
|
|
|
2007-06-02 00:06:06 +00:00
|
|
|
while (t->vm->activeCount > 1) {
|
2007-06-15 00:50:55 +00:00
|
|
|
t->vm->stateLock->wait(t);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
2007-06-03 02:00:23 +00:00
|
|
|
} break;
|
2007-06-02 00:06:06 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::IdleState:
|
|
|
|
case Thread::ZombieState: {
|
|
|
|
switch (t->state) {
|
|
|
|
case Thread::ExclusiveState: {
|
2007-06-03 02:00:23 +00:00
|
|
|
assert(t, t->vm->exclusive == t);
|
|
|
|
t->vm->exclusive = 0;
|
|
|
|
} break;
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::ActiveState: break;
|
2007-06-03 02:00:23 +00:00
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
-- t->vm->activeCount;
|
2007-06-05 00:28:52 +00:00
|
|
|
if (s == Thread::ZombieState) {
|
2007-06-03 02:00:23 +00:00
|
|
|
-- t->vm->liveCount;
|
|
|
|
}
|
|
|
|
t->state = s;
|
2007-06-02 00:06:06 +00:00
|
|
|
|
2007-06-15 00:50:55 +00:00
|
|
|
t->vm->stateLock->notifyAll(t);
|
2007-06-03 02:00:23 +00:00
|
|
|
} break;
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::ActiveState: {
|
|
|
|
switch (t->state) {
|
|
|
|
case Thread::ExclusiveState: {
|
2007-06-03 02:00:23 +00:00
|
|
|
assert(t, t->vm->exclusive == t);
|
|
|
|
|
|
|
|
t->state = s;
|
|
|
|
t->vm->exclusive = 0;
|
|
|
|
|
2007-06-15 00:50:55 +00:00
|
|
|
t->vm->stateLock->notifyAll(t);
|
2007-06-03 02:00:23 +00:00
|
|
|
} break;
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::NoState:
|
|
|
|
case Thread::IdleState: {
|
2007-06-03 02:00:23 +00:00
|
|
|
while (t->vm->exclusive) {
|
2007-06-15 00:50:55 +00:00
|
|
|
t->vm->stateLock->wait(t);
|
2007-06-03 02:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
++ t->vm->activeCount;
|
2007-06-05 00:28:52 +00:00
|
|
|
if (t->state == Thread::NoState) {
|
2007-06-03 02:00:23 +00:00
|
|
|
++ t->vm->liveCount;
|
|
|
|
}
|
|
|
|
t->state = s;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::ExitState: {
|
|
|
|
switch (t->state) {
|
|
|
|
case Thread::ExclusiveState: {
|
2007-06-03 02:00:23 +00:00
|
|
|
assert(t, t->vm->exclusive == t);
|
|
|
|
t->vm->exclusive = 0;
|
|
|
|
} break;
|
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
case Thread::ActiveState: break;
|
2007-06-03 02:00:23 +00:00
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
-- t->vm->activeCount;
|
|
|
|
t->state = s;
|
|
|
|
|
|
|
|
while (t->vm->liveCount > 1) {
|
2007-06-15 00:50:55 +00:00
|
|
|
t->vm->stateLock->wait(t);
|
2007-06-03 02:00:23 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(t);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
2007-06-03 02:00:23 +00:00
|
|
|
}
|
2007-06-02 00:06:06 +00:00
|
|
|
|
2007-06-22 22:47:57 +00:00
|
|
|
inline object
|
|
|
|
allocateLarge(Thread* t, unsigned sizeInBytes)
|
2007-06-03 02:00:23 +00:00
|
|
|
{
|
2007-06-22 22:47:57 +00:00
|
|
|
void* p = t->vm->system->allocate(Chain::footprint(sizeInBytes));
|
|
|
|
t->chain = new (p) Chain(t->chain);
|
|
|
|
return t->chain->data();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
allocateSmall(Thread* t, unsigned sizeInBytes)
|
|
|
|
{
|
|
|
|
object o = t->heap + t->heapIndex;
|
|
|
|
t->heapIndex += divide(sizeInBytes, BytesPerWord);
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
allocate2(Thread* t, unsigned sizeInBytes)
|
|
|
|
{
|
|
|
|
if (sizeInBytes > Thread::HeapSizeInBytes and t->chain == 0) {
|
|
|
|
return allocateLarge(t, sizeInBytes);
|
2007-06-03 02:00:23 +00:00
|
|
|
}
|
|
|
|
|
2007-06-15 00:50:55 +00:00
|
|
|
ACQUIRE_RAW(t, t->vm->stateLock);
|
2007-06-03 02:00:23 +00:00
|
|
|
|
|
|
|
while (t->vm->exclusive) {
|
|
|
|
// another thread wants to enter the exclusive state, either for a
|
|
|
|
// collection or some other reason. We give it a chance here.
|
|
|
|
enter(t, Thread::IdleState);
|
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
}
|
|
|
|
|
2007-06-22 20:55:11 +00:00
|
|
|
if (t->heapIndex + divide(sizeInBytes, BytesPerWord)
|
2007-06-22 21:31:45 +00:00
|
|
|
>= Thread::HeapSizeInWords)
|
2007-06-22 20:55:11 +00:00
|
|
|
{
|
2007-06-03 02:00:23 +00:00
|
|
|
enter(t, Thread::ExclusiveState);
|
|
|
|
collect(t->vm, Heap::MinorCollection);
|
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
}
|
2007-06-22 22:47:57 +00:00
|
|
|
|
|
|
|
if (sizeInBytes > Thread::HeapSizeInBytes) {
|
|
|
|
return allocateLarge(t, sizeInBytes);
|
|
|
|
} else {
|
|
|
|
return allocateSmall(t, sizeInBytes);
|
|
|
|
}
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
2007-06-22 20:55:11 +00:00
|
|
|
allocate(Thread* t, unsigned sizeInBytes)
|
2007-06-02 00:06:06 +00:00
|
|
|
{
|
2007-06-22 20:55:11 +00:00
|
|
|
if (UNLIKELY(t->heapIndex + divide(sizeInBytes, BytesPerWord)
|
2007-06-22 21:31:45 +00:00
|
|
|
>= Thread::HeapSizeInWords
|
2007-06-02 00:06:06 +00:00
|
|
|
or t->vm->exclusive))
|
|
|
|
{
|
2007-06-22 22:47:57 +00:00
|
|
|
return allocate2(t, sizeInBytes);
|
|
|
|
} else {
|
|
|
|
return allocateSmall(t, sizeInBytes);
|
2007-06-02 00:06:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 14:23:04 +00:00
|
|
|
inline void
|
|
|
|
set(Thread* t, object& target, object value)
|
|
|
|
{
|
|
|
|
target = value;
|
2007-06-15 16:00:08 +00:00
|
|
|
if (t->vm->heap->needsMark(&target)) {
|
|
|
|
ACQUIRE_RAW(t, t->vm->heapLock);
|
|
|
|
t->vm->heap->mark(&target);
|
2007-06-15 00:50:55 +00:00
|
|
|
}
|
2007-06-08 14:23:04 +00:00
|
|
|
}
|
|
|
|
|
2007-06-07 00:30:16 +00:00
|
|
|
inline object
|
|
|
|
make(Thread* t, object class_)
|
|
|
|
{
|
2007-06-08 14:23:04 +00:00
|
|
|
PROTECT(t, class_);
|
2007-06-25 02:20:35 +00:00
|
|
|
unsigned sizeInBytes = pad(classFixedSize(t, class_));
|
2007-06-22 20:55:11 +00:00
|
|
|
object instance = allocate(t, sizeInBytes);
|
2007-06-07 00:30:16 +00:00
|
|
|
*static_cast<object*>(instance) = class_;
|
|
|
|
memset(static_cast<object*>(instance) + sizeof(object), 0,
|
2007-06-22 20:55:11 +00:00
|
|
|
sizeInBytes - sizeof(object));
|
2007-06-07 00:30:16 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
unsigned
|
|
|
|
objectSize(Thread* t, object o)
|
|
|
|
{
|
|
|
|
object class_ = objectClass(o);
|
|
|
|
|
|
|
|
unsigned n = divide(classFixedSize(t, class_), BytesPerWord);
|
|
|
|
|
|
|
|
if (classArrayElementSize(t, class_)) {
|
|
|
|
n += divide(classArrayElementSize(t, class_)
|
|
|
|
* cast<uint32_t>(o, classFixedSize(t, class_) - 4),
|
|
|
|
BytesPerWord);
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-06-07 00:30:16 +00:00
|
|
|
object
|
2007-06-18 21:13:21 +00:00
|
|
|
makeByteArray(Thread* t, const char* format, va_list a)
|
2007-06-07 00:30:16 +00:00
|
|
|
{
|
|
|
|
static const unsigned Size = 256;
|
|
|
|
char buffer[Size];
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
vsnprintf(buffer, Size - 1, format, a);
|
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
object s = makeByteArray(t, strlen(buffer) + 1, false);
|
2007-06-18 21:13:21 +00:00
|
|
|
memcpy(&byteArrayBody(t, s, 0), buffer, byteArrayLength(t, s));
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeByteArray(Thread* t, const char* format, ...)
|
|
|
|
{
|
2007-06-07 00:30:16 +00:00
|
|
|
va_list a;
|
|
|
|
va_start(a, format);
|
2007-06-18 21:13:21 +00:00
|
|
|
object s = makeByteArray(t, format, a);
|
2007-06-07 00:30:16 +00:00
|
|
|
va_end(a);
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeString(Thread* t, const char* format, ...)
|
|
|
|
{
|
|
|
|
va_list a;
|
|
|
|
va_start(a, format);
|
|
|
|
object s = makeByteArray(t, format, a);
|
|
|
|
va_end(a);
|
2007-06-08 00:23:12 +00:00
|
|
|
|
|
|
|
return makeString(t, s, 0, byteArrayLength(t, s), 0);
|
|
|
|
}
|
2007-06-07 00:30:16 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
object
|
|
|
|
makeTrace(Thread* t)
|
|
|
|
{
|
|
|
|
object trace = 0;
|
2007-06-20 21:27:22 +00:00
|
|
|
if (t->frame) {
|
|
|
|
PROTECT(t, trace);
|
|
|
|
frameIp(t, t->frame) = t->ip;
|
|
|
|
for (; t->frame; t->frame = frameNext(t, t->frame)) {
|
|
|
|
trace = makeTrace
|
|
|
|
(t, frameMethod(t, t->frame), frameIp(t, t->frame), trace);
|
|
|
|
}
|
2007-06-08 00:23:12 +00:00
|
|
|
}
|
|
|
|
return trace;
|
|
|
|
}
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
object
|
|
|
|
makeRuntimeException(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
|
|
|
return makeClassCastException(t, message, trace, 0);
|
|
|
|
}
|
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
object
|
|
|
|
makeArrayIndexOutOfBoundsException(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeArrayIndexOutOfBoundsException(t, message, trace, 0);
|
2007-06-08 00:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeNegativeArrayStoreException(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeNegativeArrayStoreException(t, message, trace, 0);
|
2007-06-08 00:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeClassCastException(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeClassCastException(t, message, trace, 0);
|
2007-06-14 23:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeClassNotFoundException(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeClassNotFoundException(t, message, trace, 0);
|
2007-06-08 00:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeNullPointerException(Thread* t)
|
|
|
|
{
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeNullPointerException(t, 0, makeTrace(t), 0);
|
2007-06-08 00:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeStackOverflowError(Thread* t)
|
|
|
|
{
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeStackOverflowError(t, 0, makeTrace(t), 0);
|
2007-06-07 00:30:16 +00:00
|
|
|
}
|
|
|
|
|
2007-06-14 02:41:59 +00:00
|
|
|
object
|
|
|
|
makeNoSuchFieldError(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeNoSuchFieldError(t, message, trace, 0);
|
2007-06-14 02:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeNoSuchMethodError(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
2007-06-24 19:57:00 +00:00
|
|
|
return makeNoSuchMethodError(t, message, trace, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makeUnsatisfiedLinkError(Thread* t, object message)
|
|
|
|
{
|
|
|
|
PROTECT(t, message);
|
|
|
|
object trace = makeTrace(t);
|
|
|
|
return makeUnsatisfiedLinkError(t, message, trace, 0);
|
2007-06-14 02:41:59 +00:00
|
|
|
}
|
|
|
|
|
2007-06-09 02:29:56 +00:00
|
|
|
inline bool
|
2007-06-17 22:03:27 +00:00
|
|
|
isLongOrDouble(Thread* t, object o)
|
2007-06-09 02:29:56 +00:00
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
return objectClass(o) == arrayBody(t, t->vm->types, Machine::LongType)
|
|
|
|
or objectClass(o) == arrayBody(t, t->vm->types, Machine::DoubleType);
|
2007-06-09 02:29:56 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
unsigned
|
2007-06-24 19:57:00 +00:00
|
|
|
fieldCode(Thread* t, unsigned javaCode)
|
2007-06-11 23:40:24 +00:00
|
|
|
{
|
2007-06-24 01:39:49 +00:00
|
|
|
switch (javaCode) {
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'B':
|
2007-06-24 01:39:49 +00:00
|
|
|
return ByteField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'C':
|
2007-06-24 01:39:49 +00:00
|
|
|
return CharField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'D':
|
2007-06-24 01:39:49 +00:00
|
|
|
return DoubleField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'F':
|
2007-06-24 01:39:49 +00:00
|
|
|
return FloatField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'I':
|
2007-06-24 01:39:49 +00:00
|
|
|
return IntField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'J':
|
2007-06-24 01:39:49 +00:00
|
|
|
return LongField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'S':
|
2007-06-24 01:39:49 +00:00
|
|
|
return ShortField;
|
2007-06-25 02:20:35 +00:00
|
|
|
case 'V':
|
|
|
|
return VoidField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'Z':
|
2007-06-24 01:39:49 +00:00
|
|
|
return BooleanField;
|
2007-06-16 21:39:05 +00:00
|
|
|
case 'L':
|
|
|
|
case '[':
|
2007-06-24 01:39:49 +00:00
|
|
|
return ObjectField;
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
primitiveValue(Thread* t, unsigned code, object o)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case ByteField:
|
|
|
|
return byteValue(t, o);
|
|
|
|
case CharField:
|
|
|
|
return charValue(t, o);
|
|
|
|
case DoubleField:
|
|
|
|
return doubleValue(t, o);
|
|
|
|
case FloatField:
|
|
|
|
return floatValue(t, o);
|
|
|
|
case IntField:
|
|
|
|
return intValue(t, o);
|
|
|
|
case LongField:
|
|
|
|
return longValue(t, o);
|
|
|
|
case ShortField:
|
|
|
|
return shortValue(t, o);
|
|
|
|
case BooleanField:
|
|
|
|
return booleanValue(t, o);
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
makePrimitive(Thread* t, unsigned code, uint64_t value)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case ByteField:
|
|
|
|
return makeByte(t, value);
|
|
|
|
case CharField:
|
|
|
|
return makeChar(t, value);
|
|
|
|
case DoubleField:
|
|
|
|
return makeDouble(t, value);
|
|
|
|
case FloatField:
|
|
|
|
return makeFloat(t, value);
|
|
|
|
case IntField:
|
|
|
|
return makeInt(t, value);
|
|
|
|
case LongField:
|
|
|
|
return makeLong(t, value);
|
|
|
|
case ShortField:
|
|
|
|
return makeShort(t, value);
|
|
|
|
case BooleanField:
|
|
|
|
return makeBoolean(t, value);
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
2007-06-24 19:57:00 +00:00
|
|
|
primitiveSize(Thread* t, unsigned code)
|
2007-06-24 01:39:49 +00:00
|
|
|
{
|
|
|
|
switch (code) {
|
2007-06-25 02:20:35 +00:00
|
|
|
case VoidField:
|
|
|
|
return 0;
|
2007-06-24 01:39:49 +00:00
|
|
|
case ByteField:
|
|
|
|
case BooleanField:
|
|
|
|
return 1;
|
|
|
|
case CharField:
|
|
|
|
case ShortField:
|
|
|
|
return 2;
|
|
|
|
case FloatField:
|
|
|
|
case IntField:
|
|
|
|
return 4;
|
2007-06-25 02:20:35 +00:00
|
|
|
case DoubleField:
|
|
|
|
case LongField:
|
|
|
|
return 8;
|
2007-06-24 01:39:49 +00:00
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object
|
|
|
|
getField(Thread* t, object instance, object field)
|
|
|
|
{
|
|
|
|
switch (fieldCode(t, field)) {
|
|
|
|
case ByteField:
|
|
|
|
return makeByte(t, cast<int8_t>(instance, fieldOffset(t, field)));
|
|
|
|
case CharField:
|
|
|
|
return makeChar(t, cast<int16_t>(instance, fieldOffset(t, field)));
|
|
|
|
case DoubleField:
|
|
|
|
return makeDouble(t, cast<int64_t>(instance, fieldOffset(t, field)));
|
|
|
|
case FloatField:
|
|
|
|
return makeFloat(t, cast<int32_t>(instance, fieldOffset(t, field)));
|
|
|
|
case IntField:
|
|
|
|
return makeInt(t, cast<int32_t>(instance, fieldOffset(t, field)));
|
|
|
|
case LongField:
|
|
|
|
return makeLong(t, cast<int64_t>(instance, fieldOffset(t, field)));
|
|
|
|
case ShortField:
|
|
|
|
return makeShort(t, cast<int16_t>(instance, fieldOffset(t, field)));
|
|
|
|
case BooleanField:
|
|
|
|
return makeBoolean(t, cast<int8_t>(instance, fieldOffset(t, field)));
|
|
|
|
case ObjectField:
|
2007-06-16 21:39:05 +00:00
|
|
|
return cast<object>(instance, fieldOffset(t, field));
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
2007-06-11 23:40:24 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
void
|
2007-06-11 23:40:24 +00:00
|
|
|
setField(Thread* t, object o, object field, object value)
|
|
|
|
{
|
2007-06-24 01:39:49 +00:00
|
|
|
switch (fieldCode(t, field)) {
|
|
|
|
case ByteField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int8_t>(o, fieldOffset(t, field)) = byteValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case CharField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int16_t>(o, fieldOffset(t, field)) = charValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case DoubleField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int64_t>(o, fieldOffset(t, field)) = doubleValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case FloatField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int32_t>(o, fieldOffset(t, field)) = floatValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case IntField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int32_t>(o, fieldOffset(t, field)) = intValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case LongField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int64_t>(o, fieldOffset(t, field)) = longValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case ShortField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int16_t>(o, fieldOffset(t, field)) = shortValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case BooleanField:
|
2007-06-16 21:39:05 +00:00
|
|
|
cast<int8_t>(o, fieldOffset(t, field)) = booleanValue(t, value);
|
|
|
|
break;
|
2007-06-24 01:39:49 +00:00
|
|
|
case ObjectField:
|
2007-06-16 21:39:05 +00:00
|
|
|
set(t, cast<object>(o, fieldOffset(t, field)), value);
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
2007-06-11 23:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
getStatic(Thread* t, object field)
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
return arrayBody(t, classStaticTable(t, fieldClass(t, field)),
|
|
|
|
fieldOffset(t, field));
|
2007-06-11 23:40:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
setStatic(Thread* t, object field, object value)
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, arrayBody(t, classStaticTable(t, fieldClass(t, field)),
|
|
|
|
fieldOffset(t, field)), value);
|
2007-06-11 23:40:24 +00:00
|
|
|
}
|
|
|
|
|
2007-06-09 02:29:56 +00:00
|
|
|
bool
|
|
|
|
instanceOf(Thread* t, object class_, object o)
|
|
|
|
{
|
|
|
|
if (o == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
if (objectClass(class_)
|
|
|
|
== arrayBody(t, t->vm->types, Machine::InterfaceType))
|
|
|
|
{
|
2007-06-09 02:29:56 +00:00
|
|
|
for (object oc = objectClass(o); oc; oc = classSuper(t, oc)) {
|
|
|
|
object itable = classInterfaceTable(t, oc);
|
2007-06-17 22:03:27 +00:00
|
|
|
for (unsigned i = 0; i < arrayLength(t, itable); i += 2) {
|
2007-06-18 21:13:21 +00:00
|
|
|
if (arrayBody(t, itable, i) == class_) {
|
2007-06-09 02:29:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (object oc = objectClass(o); oc; oc = classSuper(t, oc)) {
|
2007-06-17 22:03:27 +00:00
|
|
|
if (oc == class_) {
|
2007-06-09 02:29:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-11 23:40:24 +00:00
|
|
|
object
|
|
|
|
findInterfaceMethod(Thread* t, object method, object o)
|
|
|
|
{
|
2007-06-17 22:03:27 +00:00
|
|
|
object interface = methodClass(t, method);
|
2007-06-11 23:40:24 +00:00
|
|
|
object itable = classInterfaceTable(t, objectClass(o));
|
2007-06-17 22:03:27 +00:00
|
|
|
for (unsigned i = 0; i < arrayLength(t, itable); i += 2) {
|
2007-06-18 21:13:21 +00:00
|
|
|
if (arrayBody(t, itable, i) == interface) {
|
|
|
|
return arrayBody(t, arrayBody(t, itable, i + 1),
|
|
|
|
methodOffset(t, method));
|
2007-06-11 23:40:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
2007-06-13 14:03:08 +00:00
|
|
|
findMethod(Thread* t, object method, object class_)
|
2007-06-11 23:40:24 +00:00
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
return arrayBody(t, classVirtualTable(t, class_),
|
|
|
|
methodOffset(t, method));
|
2007-06-11 23:40:24 +00:00
|
|
|
}
|
|
|
|
|
2007-06-13 14:03:08 +00:00
|
|
|
inline object
|
|
|
|
findVirtualMethod(Thread* t, object method, object o)
|
|
|
|
{
|
|
|
|
return findMethod(t, method, objectClass(o));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
isSuperclass(Thread* t, object class_, object base)
|
|
|
|
{
|
|
|
|
for (object oc = classSuper(t, base); oc; oc = classSuper(t, oc)) {
|
2007-06-17 22:03:27 +00:00
|
|
|
if (oc == class_) {
|
2007-06-13 14:03:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-14 02:41:59 +00:00
|
|
|
inline int
|
|
|
|
strcmp(const int8_t* a, const int8_t* b)
|
|
|
|
{
|
|
|
|
return ::strcmp(reinterpret_cast<const char*>(a),
|
|
|
|
reinterpret_cast<const char*>(b));
|
|
|
|
}
|
|
|
|
|
2007-06-13 14:03:08 +00:00
|
|
|
inline bool
|
|
|
|
isSpecialMethod(Thread* t, object method, object class_)
|
|
|
|
{
|
|
|
|
return (classFlags(t, class_) & ACC_SUPER)
|
2007-06-14 02:41:59 +00:00
|
|
|
and strcmp(reinterpret_cast<const int8_t*>("<init>"),
|
2007-06-18 21:13:21 +00:00
|
|
|
&byteArrayBody(t, methodName(t, method), 0)) != 0
|
2007-06-13 14:03:08 +00:00
|
|
|
and isSuperclass(t, methodClass(t, method), class_);
|
|
|
|
}
|
|
|
|
|
2007-06-14 02:12:28 +00:00
|
|
|
object
|
2007-06-14 23:55:06 +00:00
|
|
|
find(Thread* t, object class_, object table, object reference,
|
2007-06-14 02:41:59 +00:00
|
|
|
object& (*name)(Thread*, object),
|
|
|
|
object& (*spec)(Thread*, object),
|
|
|
|
object (*makeError)(Thread*, object))
|
|
|
|
{
|
|
|
|
object n = referenceName(t, reference);
|
|
|
|
object s = referenceSpec(t, reference);
|
2007-06-17 22:03:27 +00:00
|
|
|
for (unsigned i = 0; i < arrayLength(t, table); ++i) {
|
2007-06-21 01:38:02 +00:00
|
|
|
object o = arrayBody(t, table, i);
|
|
|
|
|
|
|
|
if (strcmp(&byteArrayBody(t, name(t, o), 0),
|
2007-06-18 21:13:21 +00:00
|
|
|
&byteArrayBody(t, n, 0)) == 0 and
|
2007-06-21 01:38:02 +00:00
|
|
|
strcmp(&byteArrayBody(t, spec(t, o), 0),
|
2007-06-18 21:13:21 +00:00
|
|
|
&byteArrayBody(t, s, 0)) == 0)
|
2007-06-14 02:12:28 +00:00
|
|
|
{
|
2007-06-21 01:38:02 +00:00
|
|
|
return o;
|
2007-06-14 02:12:28 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-14 02:41:59 +00:00
|
|
|
|
|
|
|
object message = makeString
|
2007-06-21 01:38:02 +00:00
|
|
|
(t, "%s:%s not found in %s",
|
2007-06-18 21:13:21 +00:00
|
|
|
&byteArrayBody(t, n, 0),
|
|
|
|
&byteArrayBody(t, s, 0),
|
|
|
|
&byteArrayBody(t, className(t, class_), 0));
|
2007-06-14 02:41:59 +00:00
|
|
|
t->exception = makeError(t, message);
|
2007-06-14 02:12:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-14 02:41:59 +00:00
|
|
|
inline object
|
|
|
|
findFieldInClass(Thread* t, object class_, object reference)
|
|
|
|
{
|
2007-06-14 23:55:06 +00:00
|
|
|
return find(t, class_, classFieldTable(t, class_), reference, fieldName,
|
|
|
|
fieldSpec, makeNoSuchFieldError);
|
2007-06-14 02:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
findMethodInClass(Thread* t, object class_, object reference)
|
|
|
|
{
|
2007-06-14 23:55:06 +00:00
|
|
|
return find(t, class_, classMethodTable(t, class_), reference, methodName,
|
|
|
|
methodSpec, makeNoSuchMethodError);
|
|
|
|
}
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object
|
|
|
|
parsePool(Thread* t, Stream& s)
|
|
|
|
{
|
|
|
|
unsigned poolCount = s.read2() - 1;
|
2007-06-21 19:43:33 +00:00
|
|
|
object pool = makeArray(t, poolCount, true);
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
PROTECT(t, pool);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < poolCount; ++i) {
|
|
|
|
unsigned c = s.read1();
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case CONSTANT_Integer: {
|
|
|
|
object value = makeInt(t, s.read4());
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_Float: {
|
|
|
|
object value = makeFloat(t, s.readFloat());
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_Long: {
|
|
|
|
object value = makeLong(t, s.read8());
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_Double: {
|
|
|
|
object value = makeLong(t, s.readDouble());
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_Utf8: {
|
|
|
|
unsigned length = s.read2();
|
2007-06-21 19:43:33 +00:00
|
|
|
object value = makeByteArray(t, length + 1, false);
|
2007-06-21 01:38:02 +00:00
|
|
|
s.read(reinterpret_cast<uint8_t*>(&byteArrayBody(t, value, 0)), length);
|
|
|
|
byteArrayBody(t, value, length) = 0;
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_Class: {
|
2007-06-21 19:43:33 +00:00
|
|
|
object value = makeIntArray(t, 2, false);
|
2007-06-21 01:38:02 +00:00
|
|
|
intArrayBody(t, value, 0) = c;
|
|
|
|
intArrayBody(t, value, 1) = s.read2();
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_String: {
|
2007-06-21 19:43:33 +00:00
|
|
|
object value = makeIntArray(t, 2, false);
|
2007-06-21 01:38:02 +00:00
|
|
|
intArrayBody(t, value, 0) = c;
|
|
|
|
intArrayBody(t, value, 1) = s.read2();
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_NameAndType: {
|
2007-06-21 19:43:33 +00:00
|
|
|
object value = makeIntArray(t, 3, false);
|
2007-06-21 01:38:02 +00:00
|
|
|
intArrayBody(t, value, 0) = c;
|
|
|
|
intArrayBody(t, value, 1) = s.read2();
|
|
|
|
intArrayBody(t, value, 2) = s.read2();
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_Fieldref:
|
|
|
|
case CONSTANT_Methodref:
|
|
|
|
case CONSTANT_InterfaceMethodref: {
|
2007-06-21 19:43:33 +00:00
|
|
|
object value = makeIntArray(t, 3, false);
|
2007-06-21 01:38:02 +00:00
|
|
|
intArrayBody(t, value, 0) = c;
|
|
|
|
intArrayBody(t, value, 1) = s.read2();
|
|
|
|
intArrayBody(t, value, 2) = s.read2();
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default: abort(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < poolCount; ++i) {
|
|
|
|
object o = arrayBody(t, pool, i);
|
|
|
|
if (objectClass(o) == arrayBody(t, t->vm->types, Machine::IntArrayType)) {
|
|
|
|
switch (intArrayBody(t, o, 0)) {
|
|
|
|
case CONSTANT_Class: {
|
|
|
|
set(t, arrayBody(t, pool, i),
|
|
|
|
arrayBody(t, pool, intArrayBody(t, o, 1) - 1));
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_String: {
|
|
|
|
object bytes = arrayBody(t, pool, intArrayBody(t, o, 1) - 1);
|
|
|
|
object value = makeString(t, bytes, 0, byteArrayLength(t, bytes), 0);
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case CONSTANT_NameAndType: {
|
|
|
|
object name = arrayBody(t, pool, intArrayBody(t, o, 1) - 1);
|
|
|
|
object type = arrayBody(t, pool, intArrayBody(t, o, 2) - 1);
|
|
|
|
object value = makePair(t, name, type);
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < poolCount; ++i) {
|
|
|
|
object o = arrayBody(t, pool, i);
|
|
|
|
if (objectClass(o) == arrayBody(t, t->vm->types, Machine::IntArrayType)) {
|
|
|
|
switch (intArrayBody(t, o, 0)) {
|
|
|
|
case CONSTANT_Fieldref:
|
|
|
|
case CONSTANT_Methodref:
|
|
|
|
case CONSTANT_InterfaceMethodref: {
|
|
|
|
object c = arrayBody(t, pool, intArrayBody(t, o, 1) - 1);
|
|
|
|
object nameAndType = arrayBody(t, pool, intArrayBody(t, o, 2) - 1);
|
|
|
|
object value = makeReference
|
|
|
|
(t, c, pairFirst(t, nameAndType), pairSecond(t, nameAndType));
|
|
|
|
set(t, arrayBody(t, pool, i), value);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
void
|
|
|
|
parseInterfaceTable(Thread* t, Stream& s, object class_, object pool)
|
|
|
|
{
|
|
|
|
PROTECT(t, class_);
|
|
|
|
PROTECT(t, pool);
|
|
|
|
|
|
|
|
object map = makeHashMap(t, 0, 0);
|
|
|
|
PROTECT(t, map);
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
if (classSuper(t, class_)) {
|
|
|
|
object superInterfaces = classInterfaceTable(t, classSuper(t, class_));
|
|
|
|
if (superInterfaces) {
|
|
|
|
PROTECT(t, superInterfaces);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
for (unsigned i = 0; i < arrayLength(t, superInterfaces); i += 2) {
|
|
|
|
object name = interfaceName(t, arrayBody(t, superInterfaces, i));
|
|
|
|
hashMapInsert(t, map, name, name, byteArrayHash);
|
|
|
|
}
|
|
|
|
}
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned count = s.read2();
|
|
|
|
for (unsigned i = 0; i < count; ++i) {
|
2007-06-21 01:38:02 +00:00
|
|
|
object name = arrayBody(t, pool, s.read2() - 1);
|
2007-06-17 22:03:27 +00:00
|
|
|
hashMapInsert(t, map, name, name, byteArrayHash);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object interfaceTable = 0;
|
|
|
|
if (hashMapSize(t, map)) {
|
2007-06-21 19:43:33 +00:00
|
|
|
interfaceTable = makeArray(t, hashMapSize(t, map), true);
|
2007-06-17 23:25:58 +00:00
|
|
|
PROTECT(t, interfaceTable);
|
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
unsigned i = 0;
|
2007-06-18 04:09:02 +00:00
|
|
|
object it = hashMapIterator(t, map);
|
2007-06-17 23:25:58 +00:00
|
|
|
PROTECT(t, it);
|
|
|
|
|
2007-06-18 04:09:02 +00:00
|
|
|
for (; it; it = hashMapIteratorNext(t, it)) {
|
|
|
|
object interface = resolveClass
|
|
|
|
(t, tripleFirst(t, hashMapIteratorNode(t, it)));
|
2007-06-17 23:25:58 +00:00
|
|
|
if (UNLIKELY(t->exception)) return;
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, arrayBody(t, interfaceTable, i++), interface);
|
2007-06-17 23:25:58 +00:00
|
|
|
|
|
|
|
// we'll fill in this table in parseMethodTable():
|
|
|
|
object vtable = makeArray
|
2007-06-21 19:43:33 +00:00
|
|
|
(t, arrayLength(t, interfaceMethodTable(t, interface)), true);
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, arrayBody(t, interfaceTable, i++), vtable);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set(t, classInterfaceTable(t, class_), interfaceTable);
|
|
|
|
}
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
inline unsigned
|
2007-06-18 04:09:02 +00:00
|
|
|
fieldSize(Thread* t, object field)
|
|
|
|
{
|
2007-06-24 01:39:49 +00:00
|
|
|
unsigned code = fieldCode(t, field);
|
|
|
|
if (code == ObjectField) {
|
2007-06-20 04:26:36 +00:00
|
|
|
return BytesPerWord;
|
2007-06-24 01:39:49 +00:00
|
|
|
} else {
|
2007-06-24 19:57:00 +00:00
|
|
|
return primitiveSize(t, code);
|
2007-06-18 04:09:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
void
|
|
|
|
parseFieldTable(Thread* t, Stream& s, object class_, object pool)
|
|
|
|
{
|
|
|
|
PROTECT(t, class_);
|
|
|
|
PROTECT(t, pool);
|
|
|
|
|
2007-06-21 18:35:24 +00:00
|
|
|
unsigned memberOffset = BytesPerWord;
|
|
|
|
if (classSuper(t, class_)) {
|
2007-06-22 20:55:11 +00:00
|
|
|
memberOffset = classFixedSize(t, classSuper(t, class_));
|
2007-06-21 18:35:24 +00:00
|
|
|
}
|
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
unsigned count = s.read2();
|
|
|
|
if (count) {
|
|
|
|
unsigned staticOffset = 0;
|
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
object fieldTable = makeArray(t, count, true);
|
2007-06-16 21:39:05 +00:00
|
|
|
PROTECT(t, fieldTable);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < count; ++i) {
|
|
|
|
unsigned flags = s.read2();
|
|
|
|
unsigned name = s.read2();
|
|
|
|
unsigned spec = s.read2();
|
|
|
|
|
|
|
|
unsigned attributeCount = s.read2();
|
|
|
|
for (unsigned j = 0; j < attributeCount; ++j) {
|
|
|
|
s.read2();
|
|
|
|
s.skip(s.read4());
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
object field = makeField
|
2007-06-24 01:39:49 +00:00
|
|
|
(t,
|
|
|
|
flags,
|
|
|
|
0, // offset
|
2007-06-24 19:57:00 +00:00
|
|
|
fieldCode(t, byteArrayBody(t, arrayBody(t, pool, spec - 1), 0)),
|
2007-06-24 01:39:49 +00:00
|
|
|
arrayBody(t, pool, name - 1),
|
|
|
|
arrayBody(t, pool, spec - 1),
|
|
|
|
class_);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
|
|
|
if (flags & ACC_STATIC) {
|
2007-06-24 19:57:00 +00:00
|
|
|
fieldOffset(t, field) = staticOffset++;
|
2007-06-16 21:39:05 +00:00
|
|
|
} else {
|
2007-06-20 04:26:36 +00:00
|
|
|
unsigned excess = memberOffset % BytesPerWord;
|
2007-06-24 19:57:00 +00:00
|
|
|
if (excess and fieldCode(t, field) == ObjectField) {
|
2007-06-20 04:26:36 +00:00
|
|
|
memberOffset += BytesPerWord - excess;
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
fieldOffset(t, field) = memberOffset;
|
|
|
|
memberOffset += fieldSize(t, field);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
set(t, arrayBody(t, fieldTable, i), field);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set(t, classFieldTable(t, class_), fieldTable);
|
|
|
|
|
|
|
|
if (staticOffset) {
|
2007-06-21 19:43:33 +00:00
|
|
|
object staticTable = makeArray(t, staticOffset, true);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
|
|
|
set(t, classStaticTable(t, class_), staticTable);
|
|
|
|
}
|
|
|
|
}
|
2007-06-21 18:35:24 +00:00
|
|
|
|
|
|
|
classFixedSize(t, class_) = divide(memberOffset, BytesPerWord);
|
|
|
|
|
|
|
|
object mask = makeIntArray
|
2007-06-21 19:43:33 +00:00
|
|
|
(t, divide(classFixedSize(t, class_), BitsPerWord), true);
|
2007-06-21 18:35:24 +00:00
|
|
|
|
|
|
|
bool sawReferenceField = false;
|
|
|
|
for (object c = class_; c; c = classSuper(t, c)) {
|
|
|
|
object fieldTable = classFieldTable(t, c);
|
|
|
|
if (fieldTable) {
|
|
|
|
for (int i = arrayLength(t, fieldTable) - 1; i >= 0; --i) {
|
|
|
|
object field = arrayBody(t, fieldTable, i);
|
2007-06-24 01:39:49 +00:00
|
|
|
if (fieldCode(t, field) == ObjectField) {
|
2007-06-21 18:35:24 +00:00
|
|
|
unsigned index = fieldOffset(t, field) / BytesPerWord;
|
|
|
|
intArrayBody(t, mask, (index / 32)) |= 1 << (index % 32);
|
|
|
|
sawReferenceField = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sawReferenceField) {
|
|
|
|
set(t, classObjectMask(t, class_), mask);
|
|
|
|
}
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
object
|
2007-06-17 23:25:58 +00:00
|
|
|
parseCode(Thread* t, Stream& s, object pool)
|
2007-06-16 21:39:05 +00:00
|
|
|
{
|
2007-06-17 23:25:58 +00:00
|
|
|
unsigned maxStack = s.read2();
|
|
|
|
unsigned maxLocals = s.read2();
|
|
|
|
unsigned length = s.read4();
|
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
object code = makeCode(t, pool, 0, maxStack, maxLocals, length, false);
|
2007-06-18 21:13:21 +00:00
|
|
|
s.read(&codeBody(t, code, 0), length);
|
2007-06-17 23:25:58 +00:00
|
|
|
|
|
|
|
unsigned ehtLength = s.read2();
|
|
|
|
if (ehtLength) {
|
|
|
|
PROTECT(t, code);
|
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
object eht = makeExceptionHandlerTable(t, ehtLength, false);
|
2007-06-17 23:25:58 +00:00
|
|
|
for (unsigned i = 0; i < ehtLength; ++i) {
|
2007-06-18 04:09:02 +00:00
|
|
|
ExceptionHandler* eh = exceptionHandlerTableBody(t, eht, i);
|
|
|
|
exceptionHandlerStart(eh) = s.read2();
|
|
|
|
exceptionHandlerEnd(eh) = s.read2();
|
|
|
|
exceptionHandlerIp(eh) = s.read2();
|
|
|
|
exceptionHandlerCatchType(eh) = s.read2();
|
2007-06-17 23:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set(t, codeExceptionHandlerTable(t, code), eht);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned attributeCount = s.read2();
|
|
|
|
for (unsigned j = 0; j < attributeCount; ++j) {
|
|
|
|
s.read2();
|
|
|
|
s.skip(s.read4());
|
|
|
|
}
|
2007-06-18 04:25:42 +00:00
|
|
|
|
|
|
|
return code;
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 04:09:02 +00:00
|
|
|
unsigned
|
|
|
|
parameterCount(Thread* t, object spec)
|
|
|
|
{
|
|
|
|
unsigned count = 0;
|
2007-06-18 21:13:21 +00:00
|
|
|
const char* s = reinterpret_cast<const char*>(&byteArrayBody(t, spec, 0));
|
2007-06-18 04:09:02 +00:00
|
|
|
++ s; // skip '('
|
|
|
|
while (*s and *s != ')') {
|
|
|
|
switch (*s) {
|
|
|
|
case 'L':
|
|
|
|
while (*s and *s != ';') ++ s;
|
|
|
|
++ s;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
|
|
|
while (*s == '[') ++ s;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
++ s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++ count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
object
|
2007-06-24 21:49:04 +00:00
|
|
|
makeJNIName(Thread* t, object method, bool /*decorate*/)
|
2007-06-24 19:57:00 +00:00
|
|
|
{
|
2007-06-24 21:49:04 +00:00
|
|
|
object name = makeByteArray
|
|
|
|
(t, "Java_%s_%s",
|
|
|
|
&byteArrayBody(t, className(t, methodClass(t, method)), 0),
|
|
|
|
&byteArrayBody(t, methodName(t, method), 0));
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < byteArrayLength(t, name) - 1; ++i) {
|
|
|
|
switch (byteArrayBody(t, name, i)) {
|
|
|
|
case '/':
|
|
|
|
byteArrayBody(t, name, i) = '_';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: decorate and translate as needed
|
|
|
|
return name;
|
2007-06-24 19:57:00 +00:00
|
|
|
}
|
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
void
|
2007-06-18 04:09:02 +00:00
|
|
|
parseMethodTable(Thread* t, Stream& s, object class_, object pool)
|
2007-06-16 21:39:05 +00:00
|
|
|
{
|
|
|
|
PROTECT(t, class_);
|
|
|
|
PROTECT(t, pool);
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
object virtualMap = makeHashMap(t, 0, 0);
|
|
|
|
PROTECT(t, virtualMap);
|
|
|
|
|
|
|
|
object nativeMap = makeHashMap(t, 0, 0);
|
|
|
|
PROTECT(t, nativeMap);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
|
|
|
unsigned virtualCount = 0;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object superVirtualTable = 0;
|
2007-06-17 22:03:27 +00:00
|
|
|
PROTECT(t, superVirtualTable);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
if (classSuper(t, class_)) {
|
|
|
|
superVirtualTable = classVirtualTable(t, classSuper(t, class_));
|
|
|
|
}
|
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
if (superVirtualTable) {
|
|
|
|
virtualCount = arrayLength(t, superVirtualTable);
|
2007-06-16 21:39:05 +00:00
|
|
|
for (unsigned i = 0; i < virtualCount; ++i) {
|
2007-06-18 21:13:21 +00:00
|
|
|
object method = arrayBody(t, superVirtualTable, i);
|
2007-06-24 19:57:00 +00:00
|
|
|
hashMapInsert(t, virtualMap, method, method, methodHash);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
object newVirtuals = makeList(t, 0, 0, 0);
|
|
|
|
PROTECT(t, newVirtuals);
|
|
|
|
|
|
|
|
unsigned count = s.read2();
|
|
|
|
if (count) {
|
2007-06-21 19:43:33 +00:00
|
|
|
object methodTable = makeArray(t, count, true);
|
2007-06-16 21:39:05 +00:00
|
|
|
PROTECT(t, methodTable);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < count; ++i) {
|
|
|
|
unsigned flags = s.read2();
|
|
|
|
unsigned name = s.read2();
|
|
|
|
unsigned spec = s.read2();
|
|
|
|
|
|
|
|
object code = 0;
|
|
|
|
unsigned attributeCount = s.read2();
|
|
|
|
for (unsigned j = 0; j < attributeCount; ++j) {
|
2007-06-21 01:38:02 +00:00
|
|
|
object name = arrayBody(t, pool, s.read2() - 1);
|
2007-06-17 23:25:58 +00:00
|
|
|
unsigned length = s.read4();
|
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
if (strcmp(reinterpret_cast<const int8_t*>("Code"),
|
2007-06-18 21:13:21 +00:00
|
|
|
&byteArrayBody(t, name, 0)) == 0)
|
2007-06-16 21:39:05 +00:00
|
|
|
{
|
2007-06-17 23:25:58 +00:00
|
|
|
code = parseCode(t, s, pool);
|
2007-06-16 21:39:05 +00:00
|
|
|
} else {
|
2007-06-17 23:25:58 +00:00
|
|
|
s.skip(length);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
unsigned parameterCount = ::parameterCount
|
|
|
|
(t, arrayBody(t, pool, spec - 1));
|
|
|
|
|
|
|
|
if ((flags & ACC_STATIC) == 0) {
|
|
|
|
++ parameterCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
object method = makeMethod(t,
|
|
|
|
flags,
|
|
|
|
0, // offset
|
|
|
|
parameterCount,
|
|
|
|
arrayBody(t, pool, name - 1),
|
|
|
|
arrayBody(t, pool, spec - 1),
|
|
|
|
class_,
|
|
|
|
code);
|
2007-06-24 19:57:00 +00:00
|
|
|
PROTECT(t, method);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-17 23:25:58 +00:00
|
|
|
if (flags & ACC_STATIC) {
|
|
|
|
if (strcmp(reinterpret_cast<const int8_t*>("<clinit>"),
|
2007-06-24 19:57:00 +00:00
|
|
|
&byteArrayBody(t, methodName(t, method), 0)) == 0)
|
2007-06-17 23:25:58 +00:00
|
|
|
{
|
2007-06-24 19:57:00 +00:00
|
|
|
set(t, classInitializer(t, class_), method);
|
2007-06-17 23:25:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-06-24 19:57:00 +00:00
|
|
|
object p = hashMapFindNode
|
|
|
|
(t, virtualMap, method, methodHash, methodEqual);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
|
|
|
if (p) {
|
2007-06-24 19:57:00 +00:00
|
|
|
methodOffset(t, method) = methodOffset(t, tripleFirst(t, p));
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
set(t, tripleSecond(t, p), method);
|
2007-06-16 21:39:05 +00:00
|
|
|
} else {
|
2007-06-24 19:57:00 +00:00
|
|
|
methodOffset(t, method) = virtualCount++;
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
listAppend(t, newVirtuals, method);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
if (flags & ACC_NATIVE) {
|
|
|
|
object p = hashMapFindNode
|
|
|
|
(t, nativeMap, method, methodHash, methodEqual);
|
|
|
|
|
|
|
|
if (p == 0) {
|
|
|
|
hashMapInsert(t, virtualMap, method, method, methodHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set(t, arrayBody(t, methodTable, i), method);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < count; ++i) {
|
|
|
|
object method = arrayBody(t, methodTable, i);
|
|
|
|
|
|
|
|
if (methodFlags(t, method) & ACC_NATIVE) {
|
|
|
|
object p = hashMapFindNode
|
|
|
|
(t, nativeMap, method, methodHash, methodEqual);
|
|
|
|
|
|
|
|
object jniName = makeJNIName(t, method, p != 0);
|
|
|
|
set(t, methodCode(t, method), jniName);
|
|
|
|
}
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set(t, classMethodTable(t, class_), methodTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (virtualCount) {
|
2007-06-17 23:25:58 +00:00
|
|
|
// generate class vtable
|
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
object vtable = makeArray(t, virtualCount, false);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
unsigned i = 0;
|
2007-06-17 22:03:27 +00:00
|
|
|
if (superVirtualTable) {
|
|
|
|
for (; i < arrayLength(t, superVirtualTable); ++i) {
|
2007-06-18 21:13:21 +00:00
|
|
|
object method = arrayBody(t, superVirtualTable, i);
|
2007-06-24 19:57:00 +00:00
|
|
|
method = hashMapFind(t, virtualMap, method, methodHash, methodEqual);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, arrayBody(t, vtable, i), method);
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
2007-06-21 01:38:02 +00:00
|
|
|
}
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
for (object p = listFront(t, newVirtuals); p; p = pairSecond(t, p)) {
|
|
|
|
set(t, arrayBody(t, vtable, i++), pairFirst(t, p));
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
set(t, classVirtualTable(t, class_), vtable);
|
2007-06-17 23:25:58 +00:00
|
|
|
|
|
|
|
// generate interface vtables
|
|
|
|
|
|
|
|
object itable = classInterfaceTable(t, class_);
|
2007-06-21 01:38:02 +00:00
|
|
|
if (itable) {
|
|
|
|
PROTECT(t, itable);
|
2007-06-17 23:25:58 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
for (unsigned i = 0; i < arrayLength(t, itable); i += 2) {
|
|
|
|
object methodTable = interfaceMethodTable(t, arrayBody(t, itable, i));
|
|
|
|
object vtable = arrayBody(t, itable, i + 1);
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < arrayLength(t, methodTable); ++j) {
|
|
|
|
object method = arrayBody(t, methodTable, j);
|
2007-06-24 19:57:00 +00:00
|
|
|
method = hashMapFind(t, virtualMap, method, methodHash, methodEqual);
|
2007-06-21 01:38:02 +00:00
|
|
|
|
|
|
|
set(t, arrayBody(t, vtable, j), method);
|
|
|
|
}
|
2007-06-17 23:25:58 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-16 21:39:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-16 01:02:24 +00:00
|
|
|
object
|
|
|
|
parseClass(Thread* t, const uint8_t* data, unsigned size)
|
|
|
|
{
|
|
|
|
class Client : public Stream::Client {
|
|
|
|
public:
|
|
|
|
Client(Thread* t): t(t) { }
|
|
|
|
|
|
|
|
virtual void NO_RETURN handleEOS() {
|
|
|
|
abort(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Thread* t;
|
|
|
|
} client(t);
|
|
|
|
|
|
|
|
Stream s(&client, data, size);
|
|
|
|
|
|
|
|
uint32_t magic = s.read4();
|
|
|
|
assert(t, magic == 0xCAFEBABE);
|
|
|
|
s.read2(); // minor version
|
|
|
|
s.read2(); // major version
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object pool = parsePool(t, s);
|
2007-06-16 01:02:24 +00:00
|
|
|
|
|
|
|
unsigned flags = s.read2();
|
|
|
|
unsigned name = s.read2();
|
|
|
|
|
|
|
|
object class_ = makeClass(t,
|
2007-06-18 04:09:02 +00:00
|
|
|
flags,
|
2007-06-16 01:02:24 +00:00
|
|
|
0, // fixed size
|
|
|
|
0, // array size
|
|
|
|
0, // object mask
|
2007-06-21 01:38:02 +00:00
|
|
|
arrayBody(t, pool, name - 1),
|
2007-06-16 21:39:05 +00:00
|
|
|
0, // super
|
|
|
|
0, // interfaces
|
2007-06-18 04:09:02 +00:00
|
|
|
0, // vtable
|
2007-06-16 01:02:24 +00:00
|
|
|
0, // fields
|
|
|
|
0, // methods
|
|
|
|
0, // static table
|
2007-06-18 04:09:02 +00:00
|
|
|
0); // initializer
|
2007-06-16 01:02:24 +00:00
|
|
|
PROTECT(t, class_);
|
2007-06-16 21:39:05 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
unsigned super = s.read2();
|
|
|
|
if (super) {
|
|
|
|
object sc = resolveClass(t, arrayBody(t, pool, super - 1));
|
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2007-06-16 01:02:24 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
set(t, classSuper(t, class_), sc);
|
|
|
|
}
|
2007-06-16 21:39:05 +00:00
|
|
|
|
|
|
|
parseInterfaceTable(t, s, class_, pool);
|
2007-06-17 23:25:58 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2007-06-16 01:02:24 +00:00
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
parseFieldTable(t, s, class_, pool);
|
2007-06-17 23:25:58 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2007-06-16 01:02:24 +00:00
|
|
|
|
2007-06-16 21:39:05 +00:00
|
|
|
parseMethodTable(t, s, class_, pool);
|
2007-06-17 23:25:58 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
2007-06-16 01:02:24 +00:00
|
|
|
|
|
|
|
return class_;
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
void
|
|
|
|
updateBootstrapClass(Thread* t, object bootstrapClass, object class_)
|
|
|
|
{
|
|
|
|
expect(t, bootstrapClass != class_);
|
|
|
|
|
|
|
|
// verify that the classes have the same layout
|
|
|
|
expect(t, classSuper(t, bootstrapClass) == classSuper(t, class_));
|
|
|
|
expect(t, classFixedSize(t, bootstrapClass) == classFixedSize(t, class_));
|
|
|
|
expect(t, (classObjectMask(t, bootstrapClass) == 0
|
|
|
|
and classObjectMask(t, class_) == 0)
|
|
|
|
or intArrayEqual(t, classObjectMask(t, bootstrapClass),
|
|
|
|
classObjectMask(t, class_)));
|
|
|
|
|
|
|
|
PROTECT(t, bootstrapClass);
|
|
|
|
PROTECT(t, class_);
|
|
|
|
|
|
|
|
enter(t, Thread::ExclusiveState);
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
memcpy(bootstrapClass, class_, objectSize(t, class_) * BytesPerWord);
|
2007-06-24 19:57:00 +00:00
|
|
|
|
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
}
|
|
|
|
|
2007-06-14 23:55:06 +00:00
|
|
|
object
|
|
|
|
resolveClass(Thread* t, object spec)
|
|
|
|
{
|
|
|
|
PROTECT(t, spec);
|
|
|
|
ACQUIRE(t, t->vm->classLock);
|
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
object class_ = hashMapFind
|
|
|
|
(t, t->vm->classMap, spec, byteArrayHash, byteArrayEqual);
|
2007-06-14 23:55:06 +00:00
|
|
|
if (class_ == 0) {
|
2007-06-20 19:20:25 +00:00
|
|
|
ClassFinder::Data* data = t->vm->classFinder->find
|
|
|
|
(reinterpret_cast<const char*>(&byteArrayBody(t, spec, 0)));
|
2007-06-14 23:55:06 +00:00
|
|
|
|
|
|
|
if (data) {
|
2007-06-21 01:38:02 +00:00
|
|
|
fprintf(stderr, "parsing %s\n", &byteArrayBody
|
|
|
|
(t, spec, 0));
|
|
|
|
|
2007-06-16 01:02:24 +00:00
|
|
|
// parse class file
|
2007-06-20 19:20:25 +00:00
|
|
|
class_ = parseClass(t, data->start(), data->length());
|
|
|
|
data->dispose();
|
2007-06-15 02:03:33 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
fprintf(stderr, "done parsing %s\n", &byteArrayBody
|
|
|
|
(t, className(t, class_), 0));
|
|
|
|
|
2007-06-14 23:55:06 +00:00
|
|
|
PROTECT(t, class_);
|
2007-06-16 01:02:24 +00:00
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
object bootstrapClass = hashMapFind
|
|
|
|
(t, t->vm->bootstrapClassMap, spec, byteArrayHash, byteArrayEqual);
|
|
|
|
if (bootstrapClass) {
|
|
|
|
PROTECT(t, bootstrapClass);
|
|
|
|
|
|
|
|
updateBootstrapClass(t, bootstrapClass, class_);
|
|
|
|
class_ = bootstrapClass;
|
2007-06-24 01:39:49 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
hashMapInsert(t, t->vm->classMap, spec, class_, byteArrayHash);
|
2007-06-14 23:55:06 +00:00
|
|
|
} else {
|
2007-06-18 21:13:21 +00:00
|
|
|
object message = makeString(t, "%s", &byteArrayBody(t, spec, 0));
|
2007-06-14 23:55:06 +00:00
|
|
|
t->exception = makeClassNotFoundException(t, message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return class_;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
resolveClass(Thread* t, object pool, unsigned index)
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
object o = arrayBody(t, pool, index);
|
|
|
|
if (objectClass(o) == arrayBody(t, t->vm->types, Machine::ByteArrayType)) {
|
2007-06-14 23:55:06 +00:00
|
|
|
PROTECT(t, pool);
|
|
|
|
|
|
|
|
o = resolveClass(t, o);
|
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, arrayBody(t, pool, index), o);
|
2007-06-14 23:55:06 +00:00
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
resolveClass(Thread* t, object container, object& (*class_)(Thread*, object))
|
|
|
|
{
|
|
|
|
object o = class_(t, container);
|
2007-06-18 21:13:21 +00:00
|
|
|
if (objectClass(o) == arrayBody(t, t->vm->types, Machine::ByteArrayType)) {
|
2007-06-14 23:55:06 +00:00
|
|
|
PROTECT(t, container);
|
|
|
|
|
|
|
|
o = resolveClass(t, o);
|
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
|
|
|
set(t, class_(t, container), o);
|
|
|
|
}
|
|
|
|
return o;
|
2007-06-14 02:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
resolve(Thread* t, object pool, unsigned index,
|
2007-06-14 02:41:59 +00:00
|
|
|
object (*find)(Thread*, object, object))
|
2007-06-14 02:12:28 +00:00
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
object o = arrayBody(t, pool, index);
|
2007-06-22 23:17:13 +00:00
|
|
|
if (objectClass(o) == arrayBody(t, t->vm->types, Machine::ReferenceType)) {
|
2007-06-14 02:41:59 +00:00
|
|
|
PROTECT(t, pool);
|
2007-06-14 02:12:28 +00:00
|
|
|
|
2007-06-14 23:55:06 +00:00
|
|
|
object class_ = resolveClass(t, o, referenceClass);
|
2007-06-14 02:12:28 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
o = find(t, class_, arrayBody(t, pool, index));
|
2007-06-14 02:12:28 +00:00
|
|
|
if (UNLIKELY(t->exception)) return 0;
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, arrayBody(t, pool, index), o);
|
2007-06-14 02:12:28 +00:00
|
|
|
}
|
2007-06-14 02:41:59 +00:00
|
|
|
return o;
|
2007-06-14 02:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
resolveField(Thread* t, object pool, unsigned index)
|
|
|
|
{
|
2007-06-14 02:41:59 +00:00
|
|
|
return resolve(t, pool, index, findFieldInClass);
|
2007-06-14 02:12:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
resolveMethod(Thread* t, object pool, unsigned index)
|
|
|
|
{
|
2007-06-14 02:41:59 +00:00
|
|
|
return resolve(t, pool, index, findMethodInClass);
|
2007-06-14 02:12:28 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
object
|
|
|
|
makeNativeMethodData(Thread* t, object method, void* function, bool builtin)
|
|
|
|
{
|
|
|
|
PROTECT(t, method);
|
|
|
|
|
|
|
|
object data = makeNativeMethodData(t,
|
|
|
|
function,
|
|
|
|
0, // argument table size
|
|
|
|
0, // return code,
|
|
|
|
builtin,
|
|
|
|
methodParameterCount(t, method),
|
|
|
|
false);
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
unsigned argumentTableSize = BytesPerWord / 4;
|
2007-06-24 21:49:04 +00:00
|
|
|
unsigned index = 0;
|
|
|
|
|
|
|
|
if ((methodFlags(t, method) & ACC_STATIC) == 0) {
|
|
|
|
nativeMethodDataParameterCodes(t, data, index++) = ObjectField;
|
2007-06-25 01:34:07 +00:00
|
|
|
argumentTableSize += BytesPerWord / 4;
|
2007-06-24 21:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* s = reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, methodSpec(t, method), 0));
|
|
|
|
++ s; // skip '('
|
|
|
|
while (*s and *s != ')') {
|
|
|
|
unsigned code = fieldCode(t, *s);
|
|
|
|
nativeMethodDataParameterCodes(t, data, index++) = code;
|
|
|
|
|
|
|
|
switch (*s) {
|
|
|
|
case 'L':
|
2007-06-25 01:34:07 +00:00
|
|
|
argumentTableSize += BytesPerWord / 4;
|
2007-06-24 21:49:04 +00:00
|
|
|
while (*s and *s != ';') ++ s;
|
|
|
|
++ s;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '[':
|
2007-06-25 01:34:07 +00:00
|
|
|
argumentTableSize += BytesPerWord / 4;
|
2007-06-24 21:49:04 +00:00
|
|
|
while (*s == '[') ++ s;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
argumentTableSize += divide(primitiveSize(t, code), 4);
|
|
|
|
++ s;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nativeMethodDataArgumentTableSize(t, data) = argumentTableSize;
|
|
|
|
nativeMethodDataReturnCode(t, data) = fieldCode(t, s[1]);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2007-06-24 01:39:49 +00:00
|
|
|
inline object
|
|
|
|
resolveNativeMethodData(Thread* t, object method)
|
|
|
|
{
|
|
|
|
if (objectClass(methodCode(t, method))
|
|
|
|
== arrayBody(t, t->vm->types, Machine::ByteArrayType))
|
|
|
|
{
|
2007-06-24 21:49:04 +00:00
|
|
|
object data = 0;
|
2007-06-24 19:57:00 +00:00
|
|
|
for (System::Library* lib = t->vm->libraries; lib; lib = lib->next()) {
|
2007-06-24 01:39:49 +00:00
|
|
|
void* p = lib->resolve(reinterpret_cast<const char*>
|
|
|
|
(&byteArrayBody(t, methodCode(t, method), 0)));
|
|
|
|
if (p) {
|
|
|
|
PROTECT(t, method);
|
2007-06-24 21:49:04 +00:00
|
|
|
data = makeNativeMethodData(t, method, p, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
if (data == 0) {
|
|
|
|
object p = hashMapFind(t, t->vm->builtinMap, methodCode(t, method),
|
|
|
|
byteArrayHash, byteArrayEqual);
|
|
|
|
if (p) {
|
|
|
|
PROTECT(t, method);
|
|
|
|
data = makeNativeMethodData(t, method, pointerValue(t, p), true);
|
|
|
|
}
|
|
|
|
}
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-25 02:20:35 +00:00
|
|
|
if (LIKELY(data)) {
|
2007-06-24 21:49:04 +00:00
|
|
|
set(t, methodCode(t, method), data);
|
2007-06-25 02:20:35 +00:00
|
|
|
} else {
|
|
|
|
object message = makeString
|
|
|
|
(t, "%s", &byteArrayBody(t, methodCode(t, method), 0));
|
|
|
|
t->exception = makeUnsatisfiedLinkError(t, message);
|
2007-06-24 21:49:04 +00:00
|
|
|
}
|
2007-06-25 02:20:35 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
return data;
|
|
|
|
} else {
|
|
|
|
return methodCode(t, method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline object
|
|
|
|
invokeNative(Thread* t, object method)
|
|
|
|
{
|
|
|
|
object data = resolveNativeMethodData(t, method);
|
2007-06-25 02:20:35 +00:00
|
|
|
if (UNLIKELY(t->exception)) {
|
2007-06-24 21:49:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned parameterCount = methodParameterCount(t, method);
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
uint32_t args[nativeMethodDataArgumentTableSize(t, data)];
|
|
|
|
uint8_t sizes[parameterCount + 1];
|
|
|
|
unsigned offset = 0;
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
sizes[0] = BytesPerWord;
|
2007-06-25 02:02:24 +00:00
|
|
|
memcpy(args + offset, &t, BytesPerWord);
|
2007-06-25 01:34:07 +00:00
|
|
|
offset += BytesPerWord / 4;
|
2007-06-24 21:49:04 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < parameterCount; ++i) {
|
|
|
|
unsigned code = nativeMethodDataParameterCodes(t, data, i);
|
|
|
|
|
|
|
|
if (code == ObjectField) {
|
2007-06-25 01:34:07 +00:00
|
|
|
sizes[i + 1] = BytesPerWord;
|
|
|
|
unsigned position = (t->sp - parameterCount) + i;
|
|
|
|
if (t->stack[position]) {
|
|
|
|
memcpy(args + offset, t->stack + position, BytesPerWord);
|
|
|
|
} else {
|
|
|
|
memset(args + offset, 0, BytesPerWord);
|
|
|
|
}
|
|
|
|
offset += BytesPerWord / 4;
|
2007-06-24 21:49:04 +00:00
|
|
|
} else {
|
|
|
|
sizes[i + 1] = primitiveSize(t, code);
|
|
|
|
uint64_t v = primitiveValue(t, code, t->stack[t->sp + i]);
|
|
|
|
if (sizes[i + 1] == 8) {
|
2007-06-25 01:34:07 +00:00
|
|
|
memcpy(args + offset, &v, 8);
|
|
|
|
offset += 2;
|
2007-06-24 21:49:04 +00:00
|
|
|
} else {
|
|
|
|
args[offset++] = v;
|
2007-06-24 01:39:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-24 21:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned returnCode = nativeMethodDataReturnCode(t, data);
|
|
|
|
unsigned returnSize
|
|
|
|
= (returnCode == ObjectField ? 4 : primitiveSize(t, returnCode));
|
|
|
|
|
|
|
|
void* function = nativeMethodDataFunction(t, data);
|
|
|
|
|
|
|
|
bool builtin = nativeMethodDataBuiltin(t, data);
|
|
|
|
if (not builtin) {
|
|
|
|
enter(t, Thread::IdleState);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t rv = t->vm->system->call(function,
|
|
|
|
parameterCount,
|
|
|
|
args,
|
|
|
|
sizes,
|
|
|
|
returnSize);
|
|
|
|
|
|
|
|
if (not builtin) {
|
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
}
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
if (UNLIKELY(t->exception) or returnCode == VoidField) {
|
2007-06-24 01:39:49 +00:00
|
|
|
return 0;
|
2007-06-24 21:49:04 +00:00
|
|
|
} else if (returnCode == ObjectField) {
|
2007-06-25 01:34:07 +00:00
|
|
|
return (rv == 0 ? 0 :
|
|
|
|
*reinterpret_cast<object*>(static_cast<uintptr_t>(rv)));
|
2007-06-24 01:39:49 +00:00
|
|
|
} else {
|
2007-06-24 21:49:04 +00:00
|
|
|
return makePrimitive(t, returnCode, rv);
|
|
|
|
}
|
2007-06-24 01:39:49 +00:00
|
|
|
}
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
void
|
|
|
|
builtinLoadLibrary(JNIEnv* e, jstring nameString)
|
|
|
|
{
|
2007-06-25 02:02:24 +00:00
|
|
|
Thread* t = static_cast<Thread*>(e);
|
2007-06-25 01:34:07 +00:00
|
|
|
|
|
|
|
if (LIKELY(nameString)) {
|
|
|
|
object n = *nameString;
|
|
|
|
char name[stringLength(t, n) + 1];
|
|
|
|
memcpy(name,
|
|
|
|
&byteArrayBody(t, stringBytes(t, n), stringOffset(t, n)),
|
|
|
|
stringLength(t, n));
|
|
|
|
name[stringLength(t, n)] = 0;
|
|
|
|
|
|
|
|
System::Library* lib;
|
|
|
|
if (LIKELY(t->vm->system->success
|
|
|
|
(t->vm->system->load(&lib, name, t->vm->libraries))))
|
|
|
|
{
|
|
|
|
t->vm->libraries = lib;
|
|
|
|
} else {
|
|
|
|
object message = makeString(t, "library not found: %s", name);
|
|
|
|
t->exception = makeRuntimeException(t, message);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring
|
|
|
|
builtinToString(JNIEnv* e, jobject this_)
|
|
|
|
{
|
2007-06-25 02:02:24 +00:00
|
|
|
Thread* t = static_cast<Thread*>(e);
|
2007-06-25 01:34:07 +00:00
|
|
|
|
|
|
|
object s = makeString
|
|
|
|
(t, "%s@%p",
|
|
|
|
&byteArrayBody(t, className(t, objectClass(*this_)), 0),
|
|
|
|
*this_);
|
|
|
|
|
|
|
|
pushSafe(t, s);
|
|
|
|
return t->stack + (t->sp - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsize
|
|
|
|
GetStringUTFLength(JNIEnv* e, jstring s)
|
|
|
|
{
|
2007-06-25 02:02:24 +00:00
|
|
|
Thread* t = static_cast<Thread*>(e);
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
|
|
|
|
jsize length = 0;
|
|
|
|
if (LIKELY(s)) {
|
|
|
|
length = stringLength(t, *s);
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
enter(t, Thread::IdleState);
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char*
|
|
|
|
GetStringUTFChars(JNIEnv* e, jstring s, jboolean* isCopy)
|
|
|
|
{
|
2007-06-25 02:02:24 +00:00
|
|
|
Thread* t = static_cast<Thread*>(e);
|
|
|
|
|
2007-06-25 01:34:07 +00:00
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
|
|
|
|
char* chars = 0;
|
|
|
|
if (LIKELY(s)) {
|
|
|
|
chars = static_cast<char*>(t->vm->system->allocate(stringLength(t, *s)));
|
|
|
|
|
|
|
|
memcpy(chars,
|
|
|
|
&byteArrayBody(t, stringBytes(t, *s), stringOffset(t, *s)),
|
|
|
|
stringLength(t, *s));
|
|
|
|
|
|
|
|
chars[stringLength(t, *s)] = 0;
|
|
|
|
} else {
|
|
|
|
t->exception = makeNullPointerException(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
enter(t, Thread::IdleState);
|
|
|
|
|
|
|
|
*isCopy = true;
|
|
|
|
return chars;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ReleaseStringUTFChars(JNIEnv* e, jstring, const char* chars)
|
|
|
|
{
|
2007-06-25 02:02:24 +00:00
|
|
|
static_cast<Thread*>(e)->vm->system->free(chars);
|
|
|
|
}
|
|
|
|
|
|
|
|
Machine::Machine(System* system, Heap* heap, ClassFinder* classFinder):
|
|
|
|
system(system),
|
|
|
|
heap(heap),
|
|
|
|
classFinder(classFinder),
|
|
|
|
rootThread(0),
|
|
|
|
exclusive(0),
|
|
|
|
activeCount(0),
|
|
|
|
liveCount(0),
|
|
|
|
stateLock(0),
|
|
|
|
heapLock(0),
|
|
|
|
classLock(0),
|
|
|
|
libraries(0),
|
|
|
|
classMap(0),
|
|
|
|
bootstrapClassMap(0),
|
|
|
|
builtinMap(0),
|
|
|
|
types(0),
|
|
|
|
unsafe(false)
|
|
|
|
{
|
|
|
|
memset(&jniEnvVTable, 0, sizeof(JNIEnvVTable));
|
|
|
|
|
|
|
|
jniEnvVTable.GetStringUTFLength = GetStringUTFLength;
|
|
|
|
jniEnvVTable.GetStringUTFChars = GetStringUTFChars;
|
|
|
|
jniEnvVTable.ReleaseStringUTFChars = ReleaseStringUTFChars;
|
|
|
|
|
|
|
|
if (not system->success(system->make(&stateLock)) or
|
|
|
|
not system->success(system->make(&heapLock)) or
|
|
|
|
not system->success(system->make(&classLock)))
|
|
|
|
{
|
|
|
|
system->abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Machine::dispose()
|
|
|
|
{
|
|
|
|
stateLock->dispose();
|
|
|
|
heapLock->dispose();
|
|
|
|
classLock->dispose();
|
2007-06-25 02:20:35 +00:00
|
|
|
if (libraries) {
|
|
|
|
libraries->dispose();
|
|
|
|
}
|
2007-06-25 02:02:24 +00:00
|
|
|
|
|
|
|
if (rootThread) {
|
|
|
|
rootThread->dispose();
|
|
|
|
}
|
2007-06-25 01:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Thread::Thread(Machine* m):
|
2007-06-25 02:02:24 +00:00
|
|
|
JNIEnv(&(m->jniEnvVTable)),
|
2007-06-25 01:34:07 +00:00
|
|
|
vm(m),
|
|
|
|
next(0),
|
|
|
|
child(0),
|
|
|
|
state(NoState),
|
|
|
|
thread(0),
|
|
|
|
frame(0),
|
|
|
|
code(0),
|
|
|
|
exception(0),
|
|
|
|
ip(0),
|
|
|
|
sp(0),
|
|
|
|
heapIndex(0),
|
|
|
|
protector(0),
|
|
|
|
chain(0)
|
|
|
|
{
|
|
|
|
if (m->rootThread == 0) {
|
|
|
|
m->rootThread = this;
|
|
|
|
m->unsafe = true;
|
|
|
|
|
|
|
|
Thread* t = this;
|
|
|
|
|
|
|
|
#include "type-initializations.cpp"
|
|
|
|
|
|
|
|
object arrayClass = arrayBody(t, t->vm->types, Machine::ArrayType);
|
|
|
|
set(t, objectClass(t->vm->types), arrayClass);
|
|
|
|
|
|
|
|
object classClass = arrayBody(t, m->types, Machine::ClassType);
|
|
|
|
set(t, objectClass(classClass), classClass);
|
|
|
|
|
|
|
|
object intArrayClass = arrayBody(t, m->types, Machine::IntArrayType);
|
|
|
|
set(t, objectClass(intArrayClass), classClass);
|
|
|
|
|
|
|
|
m->unsafe = false;
|
|
|
|
|
|
|
|
m->bootstrapClassMap = makeHashMap(this, 0, 0);
|
|
|
|
|
|
|
|
#include "type-java-initializations.cpp"
|
|
|
|
|
|
|
|
m->classMap = makeHashMap(this, 0, 0);
|
|
|
|
m->builtinMap = makeHashMap(this, 0, 0);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
const char* key;
|
|
|
|
void* value;
|
|
|
|
} builtins[] = {
|
|
|
|
{ "Java_java_lang_Object_toString",
|
|
|
|
reinterpret_cast<void*>(builtinToString) },
|
2007-06-25 02:20:35 +00:00
|
|
|
{ "Java_java_lang_System_loadLibrary",
|
2007-06-25 01:34:07 +00:00
|
|
|
reinterpret_cast<void*>(builtinLoadLibrary) },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned i = 0; builtins[i].key; ++i) {
|
|
|
|
object key = makeByteArray(t, builtins[i].key);
|
|
|
|
PROTECT(t, key);
|
|
|
|
object value = makePointer(t, builtins[i].value);
|
|
|
|
|
|
|
|
hashMapInsert(t, m->builtinMap, key, value, byteArrayHash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-21 15:47:44 +00:00
|
|
|
object
|
|
|
|
run(Thread* t)
|
|
|
|
{
|
2007-06-08 14:23:04 +00:00
|
|
|
unsigned& ip = t->ip;
|
|
|
|
unsigned& sp = t->sp;
|
|
|
|
object& code = t->code;
|
|
|
|
object& frame = t->frame;
|
|
|
|
object& exception = t->exception;
|
|
|
|
object* stack = t->stack;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
|
|
|
|
2007-05-21 15:47:44 +00:00
|
|
|
loop:
|
2007-06-22 02:13:17 +00:00
|
|
|
//fprintf(stderr, "ip: %d; instruction: 0x%x\n", ip, codeBody(t, code, ip));
|
2007-06-21 18:35:24 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
switch (codeBody(t, code, ip++)) {
|
2007-05-21 15:47:44 +00:00
|
|
|
case aaload: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < objectArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, objectArrayBody(t, array, i));
|
2007-05-21 15:47:44 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
objectArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
|
|
|
case aastore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < objectArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, objectArrayBody(t, array, i), value);
|
2007-05-21 15:47:44 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
objectArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
|
|
|
case aconst_null: {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, 0);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-31 00:29:07 +00:00
|
|
|
case aload:
|
|
|
|
case iload:
|
|
|
|
case lload: {
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, frameLocals(t, frame, codeBody(t, code, ip++)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-31 00:29:07 +00:00
|
|
|
case aload_0:
|
|
|
|
case iload_0:
|
|
|
|
case lload_0: {
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, frameLocals(t, frame, 0));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-31 00:29:07 +00:00
|
|
|
case aload_1:
|
|
|
|
case iload_1:
|
|
|
|
case lload_1: {
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, frameLocals(t, frame, 1));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-31 00:29:07 +00:00
|
|
|
case aload_2:
|
|
|
|
case iload_2:
|
|
|
|
case lload_2: {
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, frameLocals(t, frame, 2));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-31 00:29:07 +00:00
|
|
|
case aload_3:
|
|
|
|
case iload_3:
|
|
|
|
case lload_3: {
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, frameLocals(t, frame, 3));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
|
|
|
case anewarray: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object count = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t c = intValue(t, count);
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(c >= 0)) {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-21 15:47:44 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object class_ = resolveClass(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-06-21 19:43:33 +00:00
|
|
|
object array = makeObjectArray(t, class_, c, true);
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, array);
|
2007-05-21 15:47:44 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d", c);
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNegativeArrayStoreException(t, message);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case areturn:
|
|
|
|
case ireturn:
|
|
|
|
case lreturn: {
|
2007-06-08 14:23:04 +00:00
|
|
|
frame = frameNext(t, frame);
|
|
|
|
if (frame) {
|
|
|
|
code = methodCode(t, frameMethod(t, frame));
|
|
|
|
ip = frameIp(t, frame);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto loop;
|
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-08 14:23:04 +00:00
|
|
|
code = 0;
|
2007-05-21 15:47:44 +00:00
|
|
|
return value;
|
|
|
|
}
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
|
|
|
case arraylength: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object array = pop(t);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-18 21:13:21 +00:00
|
|
|
if (objectClass(array)
|
|
|
|
== arrayBody(t, t->vm->types, Machine::ObjectArrayType))
|
|
|
|
{
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, objectArrayLength(t, array)));
|
|
|
|
} else {
|
|
|
|
// for all other array types, the length follow the class pointer.
|
2007-06-20 04:26:36 +00:00
|
|
|
push(t, makeInt(t, cast<uint32_t>(array, BytesPerWord)));
|
2007-06-06 00:41:04 +00:00
|
|
|
}
|
2007-05-21 15:47:44 +00:00
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
2007-06-03 02:00:23 +00:00
|
|
|
} abort(t);
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case astore:
|
|
|
|
case istore:
|
|
|
|
case lstore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, frameLocals(t, frame, codeBody(t, code, ip++)), value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case astore_0:
|
|
|
|
case istore_0:
|
|
|
|
case lstore_0: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, frameLocals(t, frame, 0), value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case astore_1:
|
|
|
|
case istore_1:
|
|
|
|
case lstore_1: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, frameLocals(t, frame, 1), value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case astore_2:
|
|
|
|
case istore_2:
|
|
|
|
case lstore_2: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, frameLocals(t, frame, 2), value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case astore_3:
|
|
|
|
case istore_3:
|
|
|
|
case lstore_3: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, frameLocals(t, frame, 3), value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
|
|
|
case athrow: {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = pop(t);
|
|
|
|
if (UNLIKELY(exception == 0)) {
|
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
2007-05-21 15:47:44 +00:00
|
|
|
goto throw_;
|
2007-06-03 02:00:23 +00:00
|
|
|
} abort(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
|
|
|
case baload: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < byteArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, makeByte(t, byteArrayBody(t, array, i)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
byteArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case bastore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < byteArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
byteArrayBody(t, array, i) = intValue(t, value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
byteArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case bipush: {
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, makeInt(t, codeBody(t, code, ip++)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case caload: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < charArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, makeInt(t, charArrayBody(t, array, i)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
charArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case castore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < charArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
charArrayBody(t, array, i) = intValue(t, value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
charArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case checkcast: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 14:23:04 +00:00
|
|
|
if (stack[sp - 1]) {
|
2007-05-22 00:05:29 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object class_ = resolveClass(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 14:23:04 +00:00
|
|
|
if (not instanceOf(t, class_, stack[sp - 1])) {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString
|
2007-06-08 14:23:04 +00:00
|
|
|
(t, "%s as %s",
|
2007-06-18 21:13:21 +00:00
|
|
|
&byteArrayBody(t, className(t, objectClass(stack[sp - 1])), 0),
|
|
|
|
&byteArrayBody(t, className(t, class_), 0));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeClassCastException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case dup: {
|
2007-06-08 14:23:04 +00:00
|
|
|
object value = stack[sp - 1];
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case dup_x1: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object first = pop(t);
|
|
|
|
object second = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, first);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case dup_x2: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object first = pop(t);
|
|
|
|
object second = pop(t);
|
|
|
|
object third = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, first);
|
|
|
|
push(t, third);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case dup2: {
|
2007-06-08 14:23:04 +00:00
|
|
|
object first = stack[sp - 1];
|
2007-06-17 22:03:27 +00:00
|
|
|
if (isLongOrDouble(t, first)) {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
object second = stack[sp - 2];
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case dup2_x1: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object first = pop(t);
|
|
|
|
object second = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
if (isLongOrDouble(t, first)) {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, first);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
object third = pop(t);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
|
|
|
push(t, third);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case dup2_x2: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object first = pop(t);
|
|
|
|
object second = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-17 22:03:27 +00:00
|
|
|
if (isLongOrDouble(t, first)) {
|
|
|
|
if (isLongOrDouble(t, second)) {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, first);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
object third = pop(t);
|
|
|
|
push(t, first);
|
|
|
|
push(t, third);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
object third = pop(t);
|
2007-06-17 22:03:27 +00:00
|
|
|
if (isLongOrDouble(t, third)) {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
|
|
|
push(t, third);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
object fourth = pop(t);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
|
|
|
push(t, fourth);
|
|
|
|
push(t, third);
|
|
|
|
push(t, second);
|
|
|
|
push(t, first);
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case getfield: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object instance = pop(t);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(instance)) {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object field = resolveField(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-11 23:40:24 +00:00
|
|
|
push(t, getField(t, instance, field));
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case getstatic: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
2007-05-25 14:48:07 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object field = resolveField(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-25 14:48:07 +00:00
|
|
|
|
2007-06-17 23:25:58 +00:00
|
|
|
object clinit = classInitializer(t, fieldClass(t, field));
|
|
|
|
if (clinit) {
|
|
|
|
set(t, classInitializer(t, fieldClass(t, field)), 0);
|
|
|
|
code = clinit;
|
2007-05-31 00:29:07 +00:00
|
|
|
ip -= 3;
|
|
|
|
goto invoke;
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-11 23:40:24 +00:00
|
|
|
push(t, getStatic(t, field));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case goto_: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-21 18:35:24 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case goto_w: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset3 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset4 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 5) + static_cast<int32_t>
|
2007-06-21 18:35:24 +00:00
|
|
|
(((offset1 << 24) | (offset2 << 16) | (offset3 << 8) | offset4));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case i2b: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, static_cast<int8_t>(intValue(t, v))));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case i2c: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, static_cast<uint16_t>(intValue(t, v))));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case i2l: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeLong(t, intValue(t, v)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case i2s: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, static_cast<int16_t>(intValue(t, v))));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iadd: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) + intValue(t, b)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iaload: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < intArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, makeInt(t, intArrayBody(t, array, i)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
intArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iand: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) & intValue(t, b)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iastore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < intArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
intArrayBody(t, array, i) = intValue(t, value);
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
intArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iconst_0: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, 0));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iconst_1: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, 1));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iconst_2: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, 2));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iconst_3: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, 3));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iconst_4: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, 4));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iconst_5: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, 5));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case idiv: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) / intValue(t, b)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_acmpeq: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
|
|
|
if (a == b) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_acmpne: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
|
|
|
if (a != b) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_icmpeq: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, a) == intValue(t, b)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_icmpne: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, a) != intValue(t, b)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_icmpgt: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, a) > intValue(t, b)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_icmpge: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, a) >= intValue(t, b)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_icmplt: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, a) < intValue(t, b)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case if_icmple: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, a) < intValue(t, b)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifeq: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, v) == 0) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifne: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, v)) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifgt: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, v) > 0) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifge: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, v) >= 0) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iflt: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, v) < 0) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifle: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
if (intValue(t, v) <= 0) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifnonnull: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
|
|
|
if (v) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ifnull: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
|
|
|
if (v == 0) {
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iinc: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index = codeBody(t, code, ip++);
|
|
|
|
int8_t c = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
int32_t v = intValue(t, frameLocals(t, frame, index));
|
2007-06-22 21:31:45 +00:00
|
|
|
set(t, frameLocals(t, frame, index), makeInt(t, v + c));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case imul: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) * intValue(t, b)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ineg: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, - intValue(t, v)));
|
2007-05-22 00:05:29 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case instanceof: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 14:23:04 +00:00
|
|
|
if (stack[sp - 1]) {
|
2007-05-22 00:05:29 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object class_ = resolveClass(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-22 00:05:29 +00:00
|
|
|
|
2007-06-08 14:23:04 +00:00
|
|
|
if (instanceOf(t, class_, stack[sp - 1])) {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, makeInt(t, 1));
|
2007-05-22 00:05:29 +00:00
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, makeInt(t, 0));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, makeInt(t, 0));
|
2007-05-22 00:05:29 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
2007-05-25 14:48:07 +00:00
|
|
|
case invokeinterface: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
|
|
|
ip += 2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object method = resolveMethod(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
unsigned parameterCount = methodParameterCount(t, method);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (LIKELY(stack[sp - parameterCount])) {
|
|
|
|
code = findInterfaceMethod(t, method, stack[sp - parameterCount]);
|
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
|
|
|
|
goto invoke;
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case invokespecial: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object method = resolveMethod(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
unsigned parameterCount = methodParameterCount(t, method);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (LIKELY(stack[sp - parameterCount])) {
|
2007-06-13 14:03:08 +00:00
|
|
|
object class_ = methodClass(t, frameMethod(t, t->frame));
|
|
|
|
if (isSpecialMethod(t, method, class_)) {
|
|
|
|
code = findMethod(t, method, classSuper(t, class_));
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
code = method;
|
2007-05-30 00:08:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
goto invoke;
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case invokestatic: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object method = resolveMethod(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-18 04:09:02 +00:00
|
|
|
object clinit = classInitializer(t, methodClass(t, method));
|
2007-06-17 23:25:58 +00:00
|
|
|
if (clinit) {
|
2007-06-18 04:09:02 +00:00
|
|
|
set(t, classInitializer(t, methodClass(t, method)), 0);
|
2007-06-17 23:25:58 +00:00
|
|
|
code = clinit;
|
2007-06-11 23:40:24 +00:00
|
|
|
ip -= 3;
|
2007-05-30 00:08:10 +00:00
|
|
|
goto invoke;
|
|
|
|
}
|
|
|
|
|
2007-06-08 14:23:04 +00:00
|
|
|
code = method;
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto invoke;
|
|
|
|
|
|
|
|
case invokevirtual: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object method = resolveMethod(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
unsigned parameterCount = methodParameterCount(t, method);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (LIKELY(stack[sp - parameterCount])) {
|
|
|
|
code = findVirtualMethod(t, method, stack[sp - parameterCount]);
|
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-30 00:08:10 +00:00
|
|
|
|
|
|
|
goto invoke;
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ior: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) | intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case irem: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) % intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ishl: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) << intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ishr: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) >> intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case isub: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) - intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iushr: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, static_cast<uint32_t>(intValue(t, a)) >> intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ixor: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-05 00:28:52 +00:00
|
|
|
push(t, makeInt(t, intValue(t, a) ^ intValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case jsr: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, ip));
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int16_t>(((offset1 << 8) | offset2));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case jsr_w: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t offset1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset2 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset3 = codeBody(t, code, ip++);
|
|
|
|
uint8_t offset4 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, ip));
|
2007-06-21 22:50:52 +00:00
|
|
|
ip = (ip - 3) + static_cast<int32_t>
|
|
|
|
((offset1 << 24) | (offset2 << 16) | (offset3 << 8) | offset4);
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case l2i: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, static_cast<int32_t>(longValue(t, v))));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ladd: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) + longValue(t, b)));
|
2007-05-25 14:48:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
2007-05-30 00:08:10 +00:00
|
|
|
case laload: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < longArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, makeLong(t, longArrayBody(t, array, i)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
longArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case land: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) & longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lastore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < longArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
longArrayBody(t, array, i) = longValue(t, value);
|
2007-05-30 00:08:10 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
longArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lcmp: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeInt(t, longValue(t, a) > longValue(t, b) ? 1
|
|
|
|
: longValue(t, a) == longValue(t, b) ? 0 : -1));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lconst_0: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, 0));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lconst_1: {
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, 1));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ldc: {
|
2007-06-21 01:38:02 +00:00
|
|
|
push(t, arrayBody(t, codePool(t, code), codeBody(t, code, ip++) - 1));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ldc_w:
|
|
|
|
case ldc2_w: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
push(t, arrayBody(t, codePool(t, code), ((index1 << 8) | index2) - 1));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
2007-06-18 19:23:44 +00:00
|
|
|
case vm::ldiv: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) / longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lmul: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) * longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lneg: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object v = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, - longValue(t, v)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lor: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) | longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lrem: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) % longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lshl: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) << longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lshr: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) >> longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lsub: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) - longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lushr: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, static_cast<uint64_t>(longValue(t, a))
|
|
|
|
<< longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case lxor: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object b = pop(t);
|
|
|
|
object a = pop(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
|
2007-06-06 00:41:04 +00:00
|
|
|
push(t, makeLong(t, longValue(t, a) ^ longValue(t, b)));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
2007-05-31 00:29:07 +00:00
|
|
|
case new_: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object class_ = resolveClass(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-06-11 23:40:24 +00:00
|
|
|
|
2007-06-18 04:09:02 +00:00
|
|
|
object clinit = classInitializer(t, class_);
|
2007-06-17 23:25:58 +00:00
|
|
|
if (clinit) {
|
2007-06-18 04:09:02 +00:00
|
|
|
set(t, classInitializer(t, class_), 0);
|
2007-06-17 23:25:58 +00:00
|
|
|
code = clinit;
|
2007-05-31 00:29:07 +00:00
|
|
|
ip -= 3;
|
|
|
|
goto invoke;
|
|
|
|
}
|
|
|
|
|
2007-06-07 00:30:16 +00:00
|
|
|
push(t, make(t, class_));
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case newarray: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object count = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t c = intValue(t, count);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(c >= 0)) {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t type = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
|
|
|
object array;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case T_BOOLEAN:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeBooleanArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_CHAR:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeCharArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_FLOAT:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeFloatArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DOUBLE:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeDoubleArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_BYTE:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeByteArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_SHORT:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeShortArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_INT:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeIntArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_LONG:
|
2007-06-21 19:43:33 +00:00
|
|
|
array = makeLongArray(t, c, true);
|
2007-05-31 00:29:07 +00:00
|
|
|
break;
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
default: abort(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
}
|
2007-06-21 19:43:33 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, array);
|
2007-05-31 00:29:07 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d", c);
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNegativeArrayStoreException(t, message);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case nop: goto loop;
|
|
|
|
|
2007-06-25 02:02:24 +00:00
|
|
|
case pop_: {
|
2007-06-08 14:23:04 +00:00
|
|
|
-- sp;
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case pop2: {
|
2007-06-08 14:23:04 +00:00
|
|
|
object top = stack[sp - 1];
|
2007-06-17 22:03:27 +00:00
|
|
|
if (isLongOrDouble(t, top)) {
|
2007-06-08 14:23:04 +00:00
|
|
|
-- sp;
|
2007-05-31 00:29:07 +00:00
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
sp -= 2;
|
2007-05-31 00:29:07 +00:00
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case putfield: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object instance = pop(t);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(instance)) {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object field = resolveField(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
setField(t, instance, field, value);
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case putstatic: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-21 01:38:02 +00:00
|
|
|
object field = resolveField(t, codePool(t, code), index - 1);
|
2007-06-08 14:23:04 +00:00
|
|
|
if (UNLIKELY(exception)) goto throw_;
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-17 23:25:58 +00:00
|
|
|
object clinit = classInitializer(t, fieldClass(t, field));
|
|
|
|
if (clinit) {
|
|
|
|
set(t, classInitializer(t, fieldClass(t, field)), 0);
|
|
|
|
code = clinit;
|
2007-05-31 00:29:07 +00:00
|
|
|
ip -= 3;
|
|
|
|
goto invoke;
|
|
|
|
}
|
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
setStatic(t, field, value);
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ret: {
|
2007-06-18 21:13:21 +00:00
|
|
|
ip = intValue(t, frameLocals(t, frame, codeBody(t, code, ip)));
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case return_: {
|
2007-06-08 14:23:04 +00:00
|
|
|
frame = frameNext(t, frame);
|
|
|
|
if (frame) {
|
|
|
|
code = methodCode(t, frameMethod(t, frame));
|
|
|
|
ip = frameIp(t, frame);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto loop;
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
code = 0;
|
2007-05-31 00:29:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case saload: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < shortArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, makeShort(t, shortArrayBody(t, array, i)));
|
2007-05-31 00:29:07 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
shortArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case sastore: {
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
|
|
|
object index = pop(t);
|
|
|
|
object array = pop(t);
|
2007-06-05 00:28:52 +00:00
|
|
|
int32_t i = intValue(t, index);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-08 00:23:12 +00:00
|
|
|
if (LIKELY(array)) {
|
|
|
|
if (LIKELY(i >= 0 and
|
|
|
|
static_cast<uint32_t>(i) < shortArrayLength(t, array)))
|
|
|
|
{
|
2007-06-18 21:13:21 +00:00
|
|
|
shortArrayBody(t, array, i) = intValue(t, value);
|
2007-05-31 00:29:07 +00:00
|
|
|
} else {
|
2007-06-08 00:23:12 +00:00
|
|
|
object message = makeString(t, "%d not in [0,%d]", i,
|
|
|
|
shortArrayLength(t, array));
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeArrayIndexOutOfBoundsException(t, message);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-08 14:23:04 +00:00
|
|
|
exception = makeNullPointerException(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case sipush: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t byte1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t byte2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
push(t, makeInt(t, (byte1 << 8) | byte2));
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case swap: {
|
2007-06-08 14:23:04 +00:00
|
|
|
object tmp = stack[sp - 1];
|
|
|
|
stack[sp - 1] = stack[sp - 2];
|
|
|
|
stack[sp - 2] = tmp;
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case wide: goto wide;
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
default: abort(t);
|
2007-05-31 00:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wide:
|
2007-06-18 21:13:21 +00:00
|
|
|
switch (codeBody(t, code, ip++)) {
|
2007-05-31 00:29:07 +00:00
|
|
|
case aload:
|
|
|
|
case iload:
|
|
|
|
case lload: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
push(t, frameLocals(t, frame, (index1 << 8) | index2));
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case astore:
|
|
|
|
case istore:
|
|
|
|
case lstore: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-04 13:12:22 +00:00
|
|
|
object value = pop(t);
|
2007-06-18 21:13:21 +00:00
|
|
|
set(t, frameLocals(t, frame, (index1 << 8) | index2), value);
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case iinc: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
uint16_t index = (index1 << 8) | index2;
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t count1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t count2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
uint16_t count = (count1 << 8) | count2;
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
int32_t v = intValue(t, frameLocals(t, frame, index));
|
2007-06-22 21:31:45 +00:00
|
|
|
set(t, frameLocals(t, frame, index), makeInt(t, v + count));
|
2007-05-31 00:29:07 +00:00
|
|
|
} goto loop;
|
|
|
|
|
|
|
|
case ret: {
|
2007-06-18 21:13:21 +00:00
|
|
|
uint8_t index1 = codeBody(t, code, ip++);
|
|
|
|
uint8_t index2 = codeBody(t, code, ip++);
|
2007-05-31 00:29:07 +00:00
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
ip = intValue(t, frameLocals(t, frame, (index1 << 8) | index2));
|
2007-05-30 00:08:10 +00:00
|
|
|
} goto loop;
|
|
|
|
|
2007-06-03 02:00:23 +00:00
|
|
|
default: abort(t);
|
2007-05-30 00:08:10 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
invoke: {
|
|
|
|
unsigned parameterCount = methodParameterCount(t, code);
|
|
|
|
unsigned base = sp - parameterCount;
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
if (methodFlags(t, code) & ACC_NATIVE) {
|
2007-06-24 21:49:04 +00:00
|
|
|
object r = invokeNative(t, code);
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-24 21:49:04 +00:00
|
|
|
if (UNLIKELY(exception)) {
|
|
|
|
goto throw_;
|
2007-06-24 01:39:49 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
sp = base;
|
2007-06-24 21:49:04 +00:00
|
|
|
if (nativeMethodDataReturnCode(t, methodCode(t, code)) != VoidField) {
|
|
|
|
push(t, r);
|
2007-06-24 19:57:00 +00:00
|
|
|
}
|
2007-06-24 01:39:49 +00:00
|
|
|
} else {
|
2007-06-25 02:20:35 +00:00
|
|
|
if (UNLIKELY(codeMaxStack(t, methodCode(t, code)) + base
|
|
|
|
> Thread::StackSizeInWords))
|
|
|
|
{
|
|
|
|
exception = makeStackOverflowError(t);
|
|
|
|
goto throw_;
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
frameIp(t, frame) = ip;
|
|
|
|
ip = 0;
|
2007-06-21 19:43:33 +00:00
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
frame = makeFrame(t, code, frame, 0, base,
|
|
|
|
codeMaxLocals(t, methodCode(t, code)), false);
|
|
|
|
code = methodCode(t, code);
|
2007-06-21 19:43:33 +00:00
|
|
|
|
2007-06-25 02:20:35 +00:00
|
|
|
if (parameterCount) {
|
|
|
|
memcpy(&frameLocals(t, frame, 0), stack + base,
|
|
|
|
parameterCount * BytesPerWord);
|
|
|
|
}
|
2007-06-21 19:43:33 +00:00
|
|
|
|
2007-06-25 02:20:35 +00:00
|
|
|
if (frameLength(t, frame) - parameterCount) {
|
|
|
|
memset(&frameLocals(t, frame, 0) + parameterCount, 0,
|
|
|
|
(frameLength(t, frame) - parameterCount) * BytesPerWord);
|
|
|
|
}
|
2007-06-24 01:39:49 +00:00
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
sp = base;
|
|
|
|
}
|
|
|
|
} goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
|
|
|
|
throw_:
|
2007-06-08 14:23:04 +00:00
|
|
|
for (; frame; frame = frameNext(t, frame)) {
|
|
|
|
code = methodCode(t, frameMethod(t, frame));
|
|
|
|
object eht = codeExceptionHandlerTable(t, code);
|
2007-05-25 14:48:07 +00:00
|
|
|
if (eht) {
|
2007-06-06 02:24:09 +00:00
|
|
|
for (unsigned i = 0; i < exceptionHandlerTableLength(t, eht); ++i) {
|
|
|
|
ExceptionHandler* eh = exceptionHandlerTableBody(t, eht, i);
|
2007-06-21 01:38:02 +00:00
|
|
|
object catchType =
|
|
|
|
arrayBody(t, codePool(t, code), exceptionHandlerCatchType(eh) - 1);
|
|
|
|
|
2007-05-25 14:48:07 +00:00
|
|
|
if (catchType == 0 or
|
2007-06-21 01:38:02 +00:00
|
|
|
(objectClass(catchType)
|
|
|
|
== arrayBody(t, t->vm->types, Machine::ClassType) and
|
|
|
|
instanceOf(t, catchType, exception)))
|
2007-05-25 14:48:07 +00:00
|
|
|
{
|
2007-06-08 14:23:04 +00:00
|
|
|
sp = frameStackBase(t, frame);
|
2007-05-25 14:48:07 +00:00
|
|
|
ip = exceptionHandlerIp(eh);
|
2007-06-08 14:23:04 +00:00
|
|
|
push(t, exception);
|
|
|
|
exception = 0;
|
2007-05-25 14:48:07 +00:00
|
|
|
goto loop;
|
2007-05-21 15:47:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
object p = 0;
|
|
|
|
object n = 0;
|
|
|
|
for (object trace = throwableTrace(t, exception); trace; trace = n) {
|
|
|
|
n = traceNext(t, trace);
|
|
|
|
set(t, traceNext(t, trace), p);
|
|
|
|
p = trace;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (object e = exception; e; e = throwableCause(t, e)) {
|
|
|
|
if (e == exception) {
|
|
|
|
fprintf(stderr, "uncaught exception: ");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "caused by: ");
|
2007-06-21 01:38:02 +00:00
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
fprintf(stderr, "%s", &byteArrayBody
|
|
|
|
(t, className(t, objectClass(exception)), 0));
|
|
|
|
|
|
|
|
if (throwableMessage(t, exception)) {
|
|
|
|
fprintf(stderr, ": %s\n", &byteArrayBody
|
|
|
|
(t, stringBytes(t, throwableMessage(t, exception)), 0));
|
|
|
|
}
|
2007-06-21 01:38:02 +00:00
|
|
|
|
|
|
|
for (; p; p = traceNext(t, p)) {
|
2007-06-25 02:20:35 +00:00
|
|
|
fprintf(stderr, " at %s:%s\n",
|
|
|
|
&byteArrayBody
|
|
|
|
(t, className(t, methodClass(t, traceMethod(t, p))), 0),
|
|
|
|
&byteArrayBody
|
2007-06-21 01:38:02 +00:00
|
|
|
(t, methodName(t, traceMethod(t, p)), 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-24 19:57:00 +00:00
|
|
|
return 0;
|
2007-05-21 15:47:44 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
void
|
|
|
|
run(Thread* t, const char* className, int argc, const char** argv)
|
|
|
|
{
|
2007-06-21 18:35:24 +00:00
|
|
|
enter(t, Thread::ActiveState);
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
object class_ = resolveClass(t, makeByteArray(t, "%s", className));
|
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
PROTECT(t, class_);
|
|
|
|
|
|
|
|
object name = makeByteArray(t, "main");
|
|
|
|
PROTECT(t, name);
|
|
|
|
|
|
|
|
object spec = makeByteArray(t, "([Ljava/lang/String;)V");
|
|
|
|
object reference = makeReference(t, class_, name, spec);
|
|
|
|
|
|
|
|
object method = findMethodInClass(t, class_, reference);
|
|
|
|
if (LIKELY(t->exception == 0)) {
|
|
|
|
t->code = methodCode(t, method);
|
2007-06-21 19:43:33 +00:00
|
|
|
t->frame = makeFrame
|
|
|
|
(t, method, 0, 0, 0, codeMaxLocals(t, t->code), true);
|
2007-06-18 21:13:21 +00:00
|
|
|
|
|
|
|
object args = makeObjectArray
|
2007-06-21 19:43:33 +00:00
|
|
|
(t, arrayBody(t, t->vm->types, Machine::StringType), argc, true);
|
|
|
|
|
2007-06-18 21:13:21 +00:00
|
|
|
PROTECT(t, args);
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
object arg = makeString(t, "%s", argv);
|
|
|
|
set(t, objectArrayBody(t, args, i), arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
push(t, args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
run(t);
|
|
|
|
}
|
|
|
|
|
2007-05-21 15:47:44 +00:00
|
|
|
} // namespace
|
2007-06-18 21:13:21 +00:00
|
|
|
|
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
void
|
2007-06-20 16:58:35 +00:00
|
|
|
run(System* system, Heap* heap, ClassFinder* classFinder,
|
2007-06-18 21:13:21 +00:00
|
|
|
const char* className, int argc, const char** argv)
|
|
|
|
{
|
2007-06-20 16:58:35 +00:00
|
|
|
Machine m(system, heap, classFinder);
|
|
|
|
Thread t(&m);
|
2007-06-18 21:13:21 +00:00
|
|
|
|
|
|
|
run(&t, className, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|