From d5a00c45567ac2b0530860b759d006b2040fbd5a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sun, 29 Jul 2007 12:52:08 -0600 Subject: [PATCH] break native hashMap type into hashMap and weakHashMap; start investgating GC stress failures related to or uncovered by new string interning support --- src/heap.cpp | 2 +- src/machine.cpp | 35 +++++++++++++++++++++-------------- src/machine.h | 5 ----- src/types.def | 4 +++- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/heap.cpp b/src/heap.cpp index 708b53a73a..c9f3d8dd2e 100644 --- a/src/heap.cpp +++ b/src/heap.cpp @@ -18,7 +18,7 @@ const unsigned MinimumGen2SizeInBytes = 128 * 1024; const unsigned Top = ~static_cast(0); const bool Verbose = true; -const bool Debug = false; +const bool Debug = true; class Context; diff --git a/src/machine.cpp b/src/machine.cpp index 9a6bd5d069..6d57a8885b 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -637,7 +637,7 @@ parseInterfaceTable(Thread* t, Stream& s, object class_, object pool) PROTECT(t, class_); PROTECT(t, pool); - object map = makeHashMap(t, NormalMap, 0, 0); + object map = makeHashMap(t, 0, 0); PROTECT(t, map); if (classSuper(t, class_)) { @@ -844,10 +844,10 @@ parseMethodTable(Thread* t, Stream& s, object class_, object pool) PROTECT(t, class_); PROTECT(t, pool); - object virtualMap = makeHashMap(t, NormalMap, 0, 0); + object virtualMap = makeHashMap(t, 0, 0); PROTECT(t, virtualMap); - object nativeMap = makeHashMap(t, NormalMap, 0, 0); + object nativeMap = makeHashMap(t, 0, 0); PROTECT(t, nativeMap); unsigned virtualCount = 0; @@ -1374,14 +1374,14 @@ Thread::Thread(Machine* m, object javaThread, Thread* parent): classVmFlags(t, arrayBody(t, m->types, Machine::PhantomReferenceType)) |= ReferenceFlag | WeakReferenceFlag; - m->bootstrapClassMap = makeHashMap(this, NormalMap, 0, 0); + m->bootstrapClassMap = makeHashMap(this, 0, 0); #include "type-java-initializations.cpp" - m->classMap = makeHashMap(this, NormalMap, 0, 0); - m->builtinMap = makeHashMap(this, NormalMap, 0, 0); - m->monitorMap = makeHashMap(this, WeakMap, 0, 0); - m->stringMap = makeHashMap(this, WeakMap, 0, 0); + m->classMap = makeHashMap(this, 0, 0); + m->builtinMap = makeHashMap(this, 0, 0); + m->monitorMap = makeWeakHashMap(this, 0, 0); + m->stringMap = makeWeakHashMap(this, 0, 0); populateBuiltinMap(t, m->builtinMap); @@ -1789,7 +1789,9 @@ hashMapFindNode(Thread* t, object map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { - bool weak = hashMapType(t, map) == WeakMap; + bool weak = objectClass(t, map) + == arrayBody(t, t->vm->types, Machine::WeakHashMapType); + object array = hashMapArray(t, map); if (array) { unsigned index = hash(t, key) & (arrayLength(t, array) - 1); @@ -1827,7 +1829,8 @@ hashMapResize(Thread* t, object map, uint32_t (*hash)(Thread*, object), newArray = makeArray(t, newLength, true); if (oldArray) { - bool weak = hashMapType(t, map) == WeakMap; + bool weak = objectClass(t, map) + == arrayBody(t, t->vm->types, Machine::WeakHashMapType); for (unsigned i = 0; i < arrayLength(t, oldArray); ++i) { object next; @@ -1855,7 +1858,9 @@ void hashMapInsert(Thread* t, object map, object key, object value, uint32_t (*hash)(Thread*, object)) { - bool weak = hashMapType(t, map) == WeakMap; + bool weak = objectClass(t, map) + == arrayBody(t, t->vm->types, Machine::WeakHashMapType); + object array = hashMapArray(t, map); PROTECT(t, array); @@ -1892,7 +1897,9 @@ hashMapRemove(Thread* t, object map, object key, uint32_t (*hash)(Thread*, object), bool (*equal)(Thread*, object, object)) { - bool weak = hashMapType(t, map) == WeakMap; + bool weak = objectClass(t, map) + == arrayBody(t, t->vm->types, Machine::WeakHashMapType); + object array = hashMapArray(t, map); object o = 0; if (array) { @@ -2246,14 +2253,14 @@ objectMonitor(Thread* t, object o) object intern(Thread* t, object s) { + PROTECT(t, s); + ACQUIRE(t, t->vm->referenceLock); object n = hashMapFindNode(t, t->vm->stringMap, s, stringHash, stringEqual); if (n) { return jreferenceTarget(t, tripleFirst(t, n)); } else { - PROTECT(t, s); - hashMapInsert(t, t->vm->stringMap, s, 0, stringHash); addFinalizer(t, s, removeString); return s; diff --git a/src/machine.h b/src/machine.h index 85d87bf5d5..aace9da0c0 100644 --- a/src/machine.h +++ b/src/machine.h @@ -51,11 +51,6 @@ enum StackTag { ObjectTag }; -enum MapType { - NormalMap, - WeakMap -}; - const int NativeLine = -1; const int UnknownLine = -2; diff --git a/src/types.def b/src/types.def index 19a8501f47..cb38bbfa6e 100644 --- a/src/types.def +++ b/src/types.def @@ -95,10 +95,12 @@ (void* next)) (type hashMap - (uint32_t type) (uint32_t size) (object array)) +(type weakHashMap + (extends hashMap)) + (type hashMapIterator (object map) (object node)