Merge remote branch 'oss/master' into jdk7

This commit is contained in:
Joel Dice 2012-02-29 11:53:18 -07:00
commit 336a0d198b
4 changed files with 41 additions and 8 deletions

View File

@ -8532,7 +8532,7 @@ class MyProcessor: public Processor {
} }
Reference* r = new (t->m->heap->allocate(sizeof(Reference))) Reference* r = new (t->m->heap->allocate(sizeof(Reference)))
Reference(o, &(t->reference)); Reference(o, &(t->reference), false);
acquire(t, r); acquire(t, r);

View File

@ -2157,7 +2157,7 @@ SetStaticDoubleField(Thread* t, jobject c, jfieldID field, jdouble v)
} }
jobject JNICALL jobject JNICALL
NewGlobalRef(Thread* t, jobject o) newGlobalRef(Thread* t, jobject o, bool weak)
{ {
ENTER(t, Thread::ActiveState); ENTER(t, Thread::ActiveState);
@ -2165,7 +2165,7 @@ NewGlobalRef(Thread* t, jobject o)
if (o) { if (o) {
for (Reference* r = t->m->jniReferences; r; r = r->next) { for (Reference* r = t->m->jniReferences; r; r = r->next) {
if (r->target == *o) { if (r->target == *o and r->weak == weak) {
acquire(t, r); acquire(t, r);
return &(r->target); return &(r->target);
@ -2173,7 +2173,7 @@ NewGlobalRef(Thread* t, jobject o)
} }
Reference* r = new (t->m->heap->allocate(sizeof(Reference))) Reference* r = new (t->m->heap->allocate(sizeof(Reference)))
Reference(*o, &(t->m->jniReferences)); Reference(*o, &(t->m->jniReferences), weak);
acquire(t, r); acquire(t, r);
@ -2183,6 +2183,12 @@ NewGlobalRef(Thread* t, jobject o)
} }
} }
jobject JNICALL
NewGlobalRef(Thread* t, jobject o)
{
return newGlobalRef(t, o, false);
}
void JNICALL void JNICALL
DeleteGlobalRef(Thread* t, jobject r) DeleteGlobalRef(Thread* t, jobject r)
{ {
@ -2195,6 +2201,18 @@ DeleteGlobalRef(Thread* t, jobject r)
} }
} }
jobject JNICALL
NewWeakGlobalRef(Thread* t, jobject o)
{
return newGlobalRef(t, o, true);
}
void JNICALL
DeleteWeakGlobalRef(Thread* t, jobject r)
{
DeleteGlobalRef(t, r);
}
jint JNICALL jint JNICALL
EnsureLocalCapacity(Thread*, jint) EnsureLocalCapacity(Thread*, jint)
{ {
@ -3166,8 +3184,9 @@ populateJNITables(JavaVMVTable* vmTable, JNIEnvVTable* envTable)
envTable->SetStaticFloatField = local::SetStaticFloatField; envTable->SetStaticFloatField = local::SetStaticFloatField;
envTable->SetStaticDoubleField = local::SetStaticDoubleField; envTable->SetStaticDoubleField = local::SetStaticDoubleField;
envTable->NewGlobalRef = local::NewGlobalRef; envTable->NewGlobalRef = local::NewGlobalRef;
envTable->NewWeakGlobalRef = local::NewGlobalRef; envTable->NewWeakGlobalRef = local::NewWeakGlobalRef;
envTable->DeleteGlobalRef = local::DeleteGlobalRef; envTable->DeleteGlobalRef = local::DeleteGlobalRef;
envTable->DeleteWeakGlobalRef = local::DeleteWeakGlobalRef;
envTable->EnsureLocalCapacity = local::EnsureLocalCapacity; envTable->EnsureLocalCapacity = local::EnsureLocalCapacity;
envTable->ExceptionOccurred = local::ExceptionOccurred; envTable->ExceptionOccurred = local::ExceptionOccurred;
envTable->ExceptionDescribe = local::ExceptionDescribe; envTable->ExceptionDescribe = local::ExceptionDescribe;

View File

@ -584,6 +584,16 @@ postVisit(Thread* t, Heap::Visitor* v)
= m->tenuredWeakReferences; = m->tenuredWeakReferences;
m->tenuredWeakReferences = firstNewTenuredWeakReference; m->tenuredWeakReferences = firstNewTenuredWeakReference;
} }
for (Reference* r = m->jniReferences; r; r = r->next) {
if (r->weak) {
if (m->heap->status(r->target) == Heap::Unreachable) {
r->target = 0;
} else {
v->visit(&(r->target));
}
}
}
} }
void void
@ -4142,8 +4152,10 @@ visitRoots(Machine* m, Heap::Visitor* v)
} }
for (Reference* r = m->jniReferences; r; r = r->next) { for (Reference* r = m->jniReferences; r; r = r->next) {
if (not r->weak) {
v->visit(&(r->target)); v->visit(&(r->target));
} }
}
} }
void void

View File

@ -1215,11 +1215,12 @@ noop();
class Reference { class Reference {
public: public:
Reference(object target, Reference** handle): Reference(object target, Reference** handle, bool weak):
target(target), target(target),
next(*handle), next(*handle),
handle(handle), handle(handle),
count(0) count(0),
weak(weak)
{ {
if (next) { if (next) {
next->handle = &next; next->handle = &next;
@ -1231,6 +1232,7 @@ class Reference {
Reference* next; Reference* next;
Reference** handle; Reference** handle;
unsigned count; unsigned count;
bool weak;
}; };
class Classpath; class Classpath;