diff --git a/src/builtin.cpp b/src/builtin.cpp index 9bcae9a79d..ae9df41c16 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -537,12 +537,9 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName) } } - System::Library* lib; - if (LIKELY(t->m->system->success - (t->m->system->load(&lib, n, mapName, t->m->libraries)))) + if (UNLIKELY(not t->m->system->success + (t->m->system->load(&(t->m->libraries), n, mapName)))) { - t->m->libraries = 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 753e06bd33..db200823ef 100644 --- a/src/finder.cpp +++ b/src/finder.cpp @@ -400,8 +400,8 @@ class BuiltinElement: public JarElement { virtual void init() { if (index == 0) { - System::Library* library; - if (s->success(s->load(&library, 0, false, 0))) { + System::Library* library = 0; + if (s->success(s->load(&library, 0, false))) { void* p = library->resolve(name); if (p) { uint8_t* (*function)(unsigned*); diff --git a/src/machine.cpp b/src/machine.cpp index 57fced2806..96e9cbadfe 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -1812,7 +1812,7 @@ 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, 0))) + not system->success(system->load(&libraries, 0, false))) { system->abort(); } diff --git a/src/posix.cpp b/src/posix.cpp index 0738a769e3..cefdc5cb88 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -447,13 +447,13 @@ class MySystem: public System { class Library: public System::Library { public: Library(System* s, void* p, const char* name, unsigned nameLength, - bool mapName, System::Library* next): + bool mapName): s(s), p(p), name_(name), nameLength(nameLength), mapName_(mapName), - next_(next) + next_(0) { } virtual void* resolve(const char* function) { @@ -639,8 +639,7 @@ class MySystem: public System { virtual Status load(System::Library** lib, const char* name, - bool mapName, - System::Library* next) + bool mapName) { void* p; unsigned nameLength = (name ? strlen(name) : 0); @@ -666,8 +665,14 @@ class MySystem: public System { n = 0; } - *lib = new (allocate(this, sizeof(Library))) - Library(this, p, n, nameLength, mapName, next); + Library* newLib = 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/system.h b/src/system.h index 9d19ae57a9..ad1a7d9e28 100644 --- a/src/system.h +++ b/src/system.h @@ -104,8 +104,7 @@ class System { unsigned returnType) = 0; virtual Status map(Region**, const char* name) = 0; virtual FileType identify(const char* name) = 0; - virtual Status load(Library**, const char* name, bool mapName, Library* next) - = 0; + virtual Status load(Library**, const char* name, bool mapName) = 0; virtual char pathSeparator() = 0; virtual int64_t now() = 0; virtual void exit(int code) = 0; diff --git a/src/windows.cpp b/src/windows.cpp index b545a809dd..c713634689 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -606,8 +606,7 @@ class MySystem: public System { virtual Status load(System::Library** lib, const char* name, - bool mapName, - System::Library* next) + bool mapName) { HMODULE handle; unsigned nameLength = (name ? strlen(name) : 0); @@ -635,8 +634,14 @@ class MySystem: public System { n = 0; } - *lib = new (allocate(this, sizeof(Library))) - Library(this, handle, n, mapName, nameLength, next); + Library* newLib = 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;