implement Processor::makeLocalReference()/disposeLocalReference()

This commit is contained in:
Joel Dice 2007-09-29 21:33:38 -06:00
parent 8ae36c05b7
commit a73f474f34
3 changed files with 49 additions and 19 deletions

View File

@ -159,11 +159,13 @@ class MyThread: public Thread {
MyThread(Machine* m, object javaThread, vm::Thread* parent):
vm::Thread(m, javaThread, parent),
argumentList(0),
frame(0)
frame(0),
reference(0)
{ }
ArgumentList* argumentList;
void* frame;
Reference* reference;
};
inline bool
@ -2023,11 +2025,15 @@ invoke(Thread* thread, object method, ArgumentList* arguments)
unsigned returnType = fieldType(t, returnCode);
void* frame = t->frame;
Reference* reference = t->reference;
uint64_t result = vmInvoke
(&compiledBody(t, methodCompiled(t, method), 0), arguments->array,
arguments->position * BytesPerWord, returnType);
while (t->reference != reference) {
dispose(t, t->reference);
}
t->frame = frame;
object r;
@ -2187,15 +2193,26 @@ class MyProcessor: public Processor {
}
virtual object*
makeLocalReference(Thread* t, object)
makeLocalReference(Thread* vmt, object o)
{
abort(t);
if (o) {
MyThread* t = static_cast<MyThread*>(vmt);
Reference* r = new (t->m->system->allocate(sizeof(Reference)))
Reference(o, &(t->reference));
return &(r->target);
} else {
return 0;
}
}
virtual void
disposeLocalReference(Thread* t, object*)
disposeLocalReference(Thread* t, object* r)
{
abort(t);
if (r) {
vm::dispose(t, reinterpret_cast<Reference*>(r));
}
}
virtual object

View File

@ -1015,26 +1015,25 @@ NewGlobalRef(Thread* t, jobject o)
ACQUIRE(t, t->m->referenceLock);
t->m->jniReferences = new (t->m->system->allocate(sizeof(Reference)))
Reference(*o, t->m->jniReferences);
if (o) {
Reference* r = new (t->m->system->allocate(sizeof(Reference)))
Reference(*o, &(t->m->jniReferences));
return &(t->m->jniReferences->target);
return &(r->target);
} else {
return 0;
}
}
void JNICALL
DeleteGlobalRef(Thread* t, jobject o)
DeleteGlobalRef(Thread* t, jobject r)
{
ENTER(t, Thread::ActiveState);
ACQUIRE(t, t->m->referenceLock);
for (Reference** r = &(t->m->jniReferences); *r;) {
if (&((*r)->target) == o) {
*r = (*r)->next;
break;
} else {
r = &((*r)->next);
}
if (r) {
dispose(t, reinterpret_cast<Reference*>(r));
}
}

View File

@ -1076,13 +1076,20 @@ noop();
class Reference {
public:
Reference(object target, Reference* next):
Reference(object target, Reference** handle):
target(target),
next(next)
{ }
next(*handle),
handle(handle)
{
if (next) {
next->handle = &next;
}
*handle = this;
}
object target;
Reference* next;
Reference** handle;
};
class Machine {
@ -1255,6 +1262,13 @@ class StateResource {
Thread::State oldState;
};
inline void
dispose(Thread* t, Reference* r)
{
*(r->handle) = r->next;
t->m->system->free(r);
}
void
collect(Thread* t, Heap::CollectionType type);