diff --git a/src/builtin.cpp b/src/builtin.cpp index ae9df41c16..98c6d9b06f 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -527,7 +527,7 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName) } } - for (System::Library* lib = t->m->libraries; lib; lib = lib->next()) { + for (System::Library* lib = t->m->firstLibrary; lib; lib = lib->next()) { if (lib->name() and strcmp(lib->name(), n) == 0 and lib->mapName() == mapName) @@ -537,9 +537,11 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName) } } - if (UNLIKELY(not t->m->system->success - (t->m->system->load(&(t->m->libraries), n, mapName)))) - { + System::Library* lib; + if (LIKELY(t->m->system->success(t->m->system->load(&lib, n, mapName)))) { + t->m->lastLibrary->setNext(lib); + t->m->lastLibrary = lib; + } else { object message = makeString(t, "library not found: %s", n); t->exception = makeUnsatisfiedLinkError(t, message); } diff --git a/src/finder.cpp b/src/finder.cpp index db200823ef..dc0144a895 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -400,7 +400,7 @@ class BuiltinElement: public JarElement { virtual void init() { if (index == 0) { - System::Library* library = 0; + System::Library* library; if (s->success(s->load(&library, 0, false))) { void* p = library->resolve(name); if (p) { @@ -415,7 +415,7 @@ class BuiltinElement: public JarElement { index = JarIndex::open(s, region); } } - library->dispose(); + library->disposeAll(); } } } diff --git a/src/machine.cpp b/src/machine.cpp index 96e9cbadfe..509af2d023 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1788,7 +1788,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder, heapLock(0), classLock(0), referenceLock(0), - libraries(0), + firstLibrary(0), loader(0), bootstrapClassMap(0), monitorMap(0), @@ -1812,10 +1812,12 @@ Machine::Machine(System* system, Heap* heap, Finder* finder, not system->success(system->make(&heapLock)) or not system->success(system->make(&classLock)) or not system->success(system->make(&referenceLock)) or - not system->success(system->load(&libraries, 0, false))) + not system->success(system->load(&firstLibrary, 0, false))) { system->abort(); } + + lastLibrary = firstLibrary; } void @@ -1827,8 +1829,8 @@ Machine::dispose() classLock->dispose(); referenceLock->dispose(); - if (libraries) { - libraries->dispose(); + if (firstLibrary) { + firstLibrary->disposeAll(); } for (Reference* r = jniReferences; r;) { diff --git a/src/machine.h b/src/machine.h index 4ea31165e7..7862cd6fbd 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1141,7 +1141,8 @@ class Machine { System::Monitor* heapLock; System::Monitor* classLock; System::Monitor* referenceLock; - System::Library* libraries; + System::Library* firstLibrary; + System::Library* lastLibrary; object loader; object bootstrapClassMap; object monitorMap; diff --git a/src/posix.cpp b/src/posix.cpp index cefdc5cb88..4f3b46857a 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -472,7 +472,11 @@ class MySystem: public System { return next_; } - virtual void dispose() { + virtual void setNext(System::Library* lib) { + next_ = lib; + } + + virtual void disposeAll() { if (Verbose) { fprintf(stderr, "close %p\n", p); } @@ -480,7 +484,7 @@ class MySystem: public System { dlclose(p); if (next_) { - next_->dispose(); + next_->disposeAll(); } if (name_) { @@ -665,14 +669,9 @@ class MySystem: public System { n = 0; } - Library* newLib = new (allocate(this, sizeof(Library))) + *lib = new (allocate(this, sizeof(Library))) Library(this, p, n, nameLength, mapName); - if (*lib) { - static_cast(*lib)->next_ = newLib; - } - - *lib = newLib; return 0; } else { // fprintf(stderr, "dlerror: %s\n", dlerror()); diff --git a/src/process.h b/src/process.h index bc45f9bdc3..80bb26b658 100644 --- a/src/process.h +++ b/src/process.h @@ -127,7 +127,7 @@ findMethod(Thread* t, object method, object class_) inline void* resolveNativeMethod(Thread* t, object method) { - for (System::Library* lib = t->m->libraries; lib; lib = lib->next()) { + for (System::Library* lib = t->m->firstLibrary; lib; lib = lib->next()) { void* p = lib->resolve(reinterpret_cast (&byteArrayBody(t, methodCode(t, method), 0))); if (p) { diff --git a/src/system.h b/src/system.h index ad1a7d9e28..2f06357cbf 100644 --- a/src/system.h +++ b/src/system.h @@ -77,7 +77,8 @@ class System { virtual const char* name() = 0; virtual bool mapName() = 0; virtual Library* next() = 0; - virtual void dispose() = 0; + virtual void setNext(Library* lib) = 0; + virtual void disposeAll() = 0; }; class SignalHandler { diff --git a/src/windows.cpp b/src/windows.cpp index c713634689..60e22e0df2 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -457,7 +457,11 @@ class MySystem: public System { return next_; } - virtual void dispose() { + virtual void setNext(System::Library* lib) { + next_ = lib; + } + + virtual void disposeAll() { if (Verbose) { fprintf(stderr, "close %p\n", handle); } @@ -634,14 +638,9 @@ class MySystem: public System { n = 0; } - Library* newLib = new (allocate(this, sizeof(Library))) + *lib = new (allocate(this, sizeof(Library))) Library(this, p, n, nameLength, mapName); - if (*lib) { - static_cast(*lib)->next = newLib; - } - - *lib = newLib; return 0; } else { return 1;