second try to fix library symbol lookup

This commit is contained in:
Joel Dice 2008-01-25 16:38:26 -07:00
parent 4ea8b0a1fe
commit e403a625d1
8 changed files with 32 additions and 28 deletions

View File

@ -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() if (lib->name()
and strcmp(lib->name(), n) == 0 and strcmp(lib->name(), n) == 0
and lib->mapName() == mapName) 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 System::Library* lib;
(t->m->system->load(&(t->m->libraries), n, mapName)))) 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); object message = makeString(t, "library not found: %s", n);
t->exception = makeUnsatisfiedLinkError(t, message); t->exception = makeUnsatisfiedLinkError(t, message);
} }

View File

@ -400,7 +400,7 @@ class BuiltinElement: public JarElement {
virtual void init() { virtual void init() {
if (index == 0) { if (index == 0) {
System::Library* library = 0; System::Library* library;
if (s->success(s->load(&library, 0, false))) { if (s->success(s->load(&library, 0, false))) {
void* p = library->resolve(name); void* p = library->resolve(name);
if (p) { if (p) {
@ -415,7 +415,7 @@ class BuiltinElement: public JarElement {
index = JarIndex::open(s, region); index = JarIndex::open(s, region);
} }
} }
library->dispose(); library->disposeAll();
} }
} }
} }

View File

@ -1788,7 +1788,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder,
heapLock(0), heapLock(0),
classLock(0), classLock(0),
referenceLock(0), referenceLock(0),
libraries(0), firstLibrary(0),
loader(0), loader(0),
bootstrapClassMap(0), bootstrapClassMap(0),
monitorMap(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(&heapLock)) or
not system->success(system->make(&classLock)) or not system->success(system->make(&classLock)) or
not system->success(system->make(&referenceLock)) 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(); system->abort();
} }
lastLibrary = firstLibrary;
} }
void void
@ -1827,8 +1829,8 @@ Machine::dispose()
classLock->dispose(); classLock->dispose();
referenceLock->dispose(); referenceLock->dispose();
if (libraries) { if (firstLibrary) {
libraries->dispose(); firstLibrary->disposeAll();
} }
for (Reference* r = jniReferences; r;) { for (Reference* r = jniReferences; r;) {

View File

@ -1141,7 +1141,8 @@ class Machine {
System::Monitor* heapLock; System::Monitor* heapLock;
System::Monitor* classLock; System::Monitor* classLock;
System::Monitor* referenceLock; System::Monitor* referenceLock;
System::Library* libraries; System::Library* firstLibrary;
System::Library* lastLibrary;
object loader; object loader;
object bootstrapClassMap; object bootstrapClassMap;
object monitorMap; object monitorMap;

View File

@ -472,7 +472,11 @@ class MySystem: public System {
return next_; return next_;
} }
virtual void dispose() { virtual void setNext(System::Library* lib) {
next_ = lib;
}
virtual void disposeAll() {
if (Verbose) { if (Verbose) {
fprintf(stderr, "close %p\n", p); fprintf(stderr, "close %p\n", p);
} }
@ -480,7 +484,7 @@ class MySystem: public System {
dlclose(p); dlclose(p);
if (next_) { if (next_) {
next_->dispose(); next_->disposeAll();
} }
if (name_) { if (name_) {
@ -665,14 +669,9 @@ class MySystem: public System {
n = 0; n = 0;
} }
Library* newLib = new (allocate(this, sizeof(Library))) *lib = new (allocate(this, sizeof(Library)))
Library(this, p, n, nameLength, mapName); Library(this, p, n, nameLength, mapName);
if (*lib) {
static_cast<Library*>(*lib)->next_ = newLib;
}
*lib = newLib;
return 0; return 0;
} else { } else {
// fprintf(stderr, "dlerror: %s\n", dlerror()); // fprintf(stderr, "dlerror: %s\n", dlerror());

View File

@ -127,7 +127,7 @@ findMethod(Thread* t, object method, object class_)
inline void* inline void*
resolveNativeMethod(Thread* t, object method) 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<const char*> void* p = lib->resolve(reinterpret_cast<const char*>
(&byteArrayBody(t, methodCode(t, method), 0))); (&byteArrayBody(t, methodCode(t, method), 0)));
if (p) { if (p) {

View File

@ -77,7 +77,8 @@ class System {
virtual const char* name() = 0; virtual const char* name() = 0;
virtual bool mapName() = 0; virtual bool mapName() = 0;
virtual Library* next() = 0; virtual Library* next() = 0;
virtual void dispose() = 0; virtual void setNext(Library* lib) = 0;
virtual void disposeAll() = 0;
}; };
class SignalHandler { class SignalHandler {

View File

@ -457,7 +457,11 @@ class MySystem: public System {
return next_; return next_;
} }
virtual void dispose() { virtual void setNext(System::Library* lib) {
next_ = lib;
}
virtual void disposeAll() {
if (Verbose) { if (Verbose) {
fprintf(stderr, "close %p\n", handle); fprintf(stderr, "close %p\n", handle);
} }
@ -634,14 +638,9 @@ class MySystem: public System {
n = 0; n = 0;
} }
Library* newLib = new (allocate(this, sizeof(Library))) *lib = new (allocate(this, sizeof(Library)))
Library(this, p, n, nameLength, mapName); Library(this, p, n, nameLength, mapName);
if (*lib) {
static_cast<Library*>(*lib)->next = newLib;
}
*lib = newLib;
return 0; return 0;
} else { } else {
return 1; return 1;