[vmkit-commits] [vmkit] r144857 - /vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp

Will Dietz wdietz2 at illinois.edu
Wed Nov 16 14:54:03 PST 2011


Author: wdietz2
Date: Wed Nov 16 16:54:03 2011
New Revision: 144857

URL: http://llvm.org/viewvc/llvm-project?rev=144857&view=rev
Log:
Fix detection of whether or not symbols are from j3 or not.

Unfortunately, native code that's part of OpenJDK likes to dlopen things with
RTLD_GLOBAL, resulting in the existing mechanism for determining where a symbol
came from inaccurate.

Instead, search both our process (and any global libraries), but also search our
loaded libraries.

Using this, we can determine which symbols are in vmkit: they must be in in the self
search AND be a different symbol from what was found in the library search.

Modified:
    vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp

Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=144857&r1=144856&r2=144857&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Wed Nov 16 16:54:03 2011
@@ -977,22 +977,39 @@
 }
 
 word_t JnjvmClassLoader::loadInLib(const char* buf, bool& j3) {
-  word_t res = (word_t)TheCompiler->loadMethod(mvm::System::GetSelfHandle(), buf);
-  
-  if (!res) {
-    for (std::vector<void*>::iterator i = nativeLibs.begin(),
-              e = nativeLibs.end(); i!= e; ++i) {
-      res = (word_t)TheCompiler->loadMethod((*i), buf);
-      if (res) break;
-    }
-  } else {
-    j3 = true;
+  // Check 'self'.  Should only check our process, however it's possible native
+  // code dlopen'd something itself (with RTLD_GLOBAL; OpenJDK does this).
+  // To handle this, we search both ourselves and the libraries we loaded.
+  word_t sym =
+    (word_t)TheCompiler->loadMethod(mvm::System::GetSelfHandle(), buf);
+
+  // Search loaded libraries as well, both as fallback and to determine
+  // whether or not the symbol in question is defined by vmkit.
+  word_t symFromLib = 0;
+  for (std::vector<void*>::iterator i = nativeLibs.begin(),
+      e = nativeLibs.end(); i!= e; ++i) {
+    symFromLib = (word_t)TheCompiler->loadMethod((*i), buf);
+    if (symFromLib) break;
+  }
+
+  if (sym) {
+    // Always use the definition from 'self', if it exists.
+    // Furthermore, claim it's defined in j3 iff it wasn't found in one of our
+    // libraries.  This might be wrong if we do a lookup on a symbol that's
+    // neither in vmkit nor a VM-loaded library (but /is/ in a different library
+    // that has been dlopen'd by native code), but that should never
+    // be called from java code anyway.
+    j3 = (sym != symFromLib);
+    return sym;
   }
-  
-  if (!res && this != bootstrapLoader)
-    res = bootstrapLoader->loadInLib(buf, j3);
 
-  return (word_t)res;
+  // Otherwise return what we found in the libraries, if anything
+  if (symFromLib) return symFromLib;
+
+  if (this != bootstrapLoader)
+    return bootstrapLoader->loadInLib(buf, j3);
+
+  return 0;
 }
 
 void* JnjvmClassLoader::loadLib(const char* buf) {





More information about the vmkit-commits mailing list