diff --git a/src/machine.cpp b/src/machine.cpp index 3d2afc4355..a5ed75a822 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -177,16 +177,22 @@ postVisit(Thread* t, Heap::Visitor* v) if (m->heap->status(*p) == Heap::Unreachable) { // reference is unreachable - remove it from the list + fprintf(stderr, "unreachable wr: %p\n", *p); + *p = jreferenceNext(t, *p); } else if (m->heap->status(jreferenceTarget(t, *p)) == Heap::Unreachable) { // target is unreachable - clear the reference and remove it // from the list + fprintf(stderr, "target unreachable for wr: %p\n", *p); + jreferenceTarget(t, *p) = 0; *p = jreferenceNext(t, *p); } else { // both reference and target are reachable + fprintf(stderr, "viable wr: %p\n", *p); + v->visit(&jreferenceTarget(t, *p)); v->visit(p); @@ -341,14 +347,6 @@ collect(Thread* t, Heap::CollectionType type) cast(dst, 0) |= ExtendedMark; extendedWord(t, dst, base) = takeHash(t, o); } - - if (classVmFlags(t, class_) & WeakReferenceFlag) { - fprintf(stderr, "weak reference to %p at %p\n", - jreferenceTarget(t, dst), - &jreferenceTarget(t, dst)); - jreferenceNext(t, dst) = m->weakReferences; - m->weakReferences = dst; - } } virtual void walk(void* p, Heap::Walker* w) { @@ -482,6 +480,7 @@ Machine::Machine(System* system, Heap* heap, ClassFinder* classFinder): finalizers(0), tenuredFinalizers(0), finalizeQueue(0), + weakReferences(0), tenuredWeakReferences(0), unsafe(false) { @@ -998,6 +997,10 @@ objectMonitor(Thread* t, object o) object p = hashMapFind(t, t->vm->monitorMap, o, objectHash, referenceEqual); if (p) { + fprintf(stderr, "found monitor %p for object 0x%x\n", + static_cast(pointerValue(t, p)), + objectHash(t, o)); + return static_cast(pointerValue(t, p)); } else { PROTECT(t, o); @@ -1011,7 +1014,13 @@ objectMonitor(Thread* t, object o) p = makePointer(t, m); PROTECT(t, p); - object wr = makeWeakReference(t, o, 0); + object wr = makeWeakReference(t, o, t->vm->weakReferences); + t->vm->weakReferences = wr; + + fprintf(stderr, "made monitor %p for object 0x%x\n", + m, + objectHash(t, o)); + fprintf(stderr, "new wr: %p\n", wr); hashMapInsert(t, t->vm->monitorMap, wr, p, referenceHash); diff --git a/src/machine.h b/src/machine.h index b4866ad459..ad680c71ad 100644 --- a/src/machine.h +++ b/src/machine.h @@ -23,8 +23,8 @@ namespace vm { const bool Verbose = false; const bool Debug = false; -const bool DebugRun = true; -const bool DebugStack = true; +const bool DebugRun = false; +const bool DebugStack = false; const uintptr_t HashTakenMark = 1; const uintptr_t ExtendedMark = 2; @@ -1644,13 +1644,6 @@ hash(const int8_t* s, unsigned length) inline unsigned baseSize(Thread* t, object o, object class_) { - if (classArrayElementSize(t, class_)) { - noop(); - if (cast(o, classFixedSize(t, class_) - BytesPerWord)) { - noop(); - } - } - return divide(classFixedSize(t, class_), BytesPerWord) + divide(classArrayElementSize(t, class_) * cast(o, classFixedSize(t, class_) - BytesPerWord),