summaryrefslogtreecommitdiffstats
path: root/libjava/java
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-01 19:19:13 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2005-04-01 19:19:13 +0000
commit2e81f6a9549b2a6b185a16a036ce4988eb6c9782 (patch)
tree3d09f5cb569908269df7399fc0b8e4ca62d64f71 /libjava/java
parenta74502ce2de055943b18430267381b2f28927591 (diff)
downloadppe42-gcc-2e81f6a9549b2a6b185a16a036ce4988eb6c9782.tar.gz
ppe42-gcc-2e81f6a9549b2a6b185a16a036ce4988eb6c9782.zip
* java/lang/natVMClassLoader.cc (getSystemClassLoaderInternal):
Updated for name change. (nativeFindClass): New method. (loadClass): Use nativeFindClass. * java/lang/natClassLoader.cc (_Jv_FindClass): Use single-argument form of loadClass. * java/lang/VMClassLoader.java (tried_libraries, lib_control, LIB_FULL, LIB_CACHE, LIB_NEVER): New fields from old VMClassLoader. (initialize): New method. (nativeFindClass): Declare. * gnu/gcj/runtime/natVMClassLoader.cc: Removed. * gnu/gcj/runtime/VMClassLoader.java: Removed. * gnu/gcj/runtime/ExtensionClassLoader.java: Renamed from VMClassLoader.java. (definePackageForNative): Removed. (tried_libraries, LIB_CACHE, LIB_FULL, LIB_NEVER, lib_control): Moved to VMClassLoader.java. * prims.cc (_Jv_CreateJavaVM): Updated for renaming. * Makefile.am (gnu/gcj/runtime/ExtensionClassLoader.h): Renamed. (ordinary_java_source_files): Added ExtensionClassLoader.java, removed VMClassLoader.java. (nat_source_files): Removed natVMClassLoader.cc. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@97414 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/lang/VMClassLoader.java36
-rw-r--r--libjava/java/lang/natClassLoader.cc6
-rw-r--r--libjava/java/lang/natVMClassLoader.cc73
3 files changed, 109 insertions, 6 deletions
diff --git a/libjava/java/lang/VMClassLoader.java b/libjava/java/lang/VMClassLoader.java
index dfbfba4ceb3..c48fc709991 100644
--- a/libjava/java/lang/VMClassLoader.java
+++ b/libjava/java/lang/VMClassLoader.java
@@ -51,6 +51,7 @@ import java.security.ProtectionDomain;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.StringTokenizer;
import gnu.gcj.runtime.BootClassLoader;
@@ -87,6 +88,17 @@ final class VMClassLoader
// until we've initialized the system, at which point it is created.
static BootClassLoader bootLoader;
+ // This keeps track of shared libraries we've already tried to load.
+ private static HashSet tried_libraries;
+
+ // Holds one of the LIB_* constants; used to determine how shared
+ // library loads are done.
+ private static int lib_control;
+
+ private static final int LIB_FULL = 0;
+ private static final int LIB_CACHE = 1;
+ private static final int LIB_NEVER = 2;
+
/**
* Helper to define a class using a string of bytes. This assumes that
* the security checks have already been performed, if necessary.
@@ -298,6 +310,30 @@ final class VMClassLoader
static native void initBootLoader(String libdir);
+ static void initialize(String libdir)
+ {
+ initBootLoader(libdir);
+
+ String p
+ = System.getProperty ("gnu.gcj.runtime.VMClassLoader.library_control",
+ "");
+ if ("never".equals(p))
+ lib_control = LIB_NEVER;
+ else if ("cache".equals(p))
+ lib_control = LIB_CACHE;
+ else if ("full".equals(p))
+ lib_control = LIB_FULL;
+ else
+ lib_control = LIB_CACHE;
+
+ tried_libraries = new HashSet();
+ }
+
+ /**
+ * Possibly load a .so and search it for classes.
+ */
+ static native Class nativeFindClass(String name);
+
static ClassLoader getSystemClassLoader()
{
// This method is called as the initialization of systemClassLoader,
diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc
index c3b1f7e998f..00292f93dad 100644
--- a/libjava/java/lang/natClassLoader.cc
+++ b/libjava/java/lang/natClassLoader.cc
@@ -26,7 +26,6 @@ details. */
#include <java/lang/Character.h>
#include <java/lang/Thread.h>
#include <java/lang/ClassLoader.h>
-#include <gnu/gcj/runtime/VMClassLoader.h>
#include <java/lang/InternalError.h>
#include <java/lang/IllegalAccessError.h>
#include <java/lang/LinkageError.h>
@@ -226,8 +225,9 @@ _Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader)
{
if (loader)
{
- // Load using a user-defined loader, jvmspec 5.3.2
- klass = loader->loadClass(sname, false);
+ // Load using a user-defined loader, jvmspec 5.3.2.
+ // Note that we explicitly must call the single-argument form.
+ klass = loader->loadClass(sname);
// If "loader" delegated the loadClass operation to another
// loader, explicitly register that it is also an initiating
diff --git a/libjava/java/lang/natVMClassLoader.cc b/libjava/java/lang/natVMClassLoader.cc
index c59e1d67f04..e6c3b947d24 100644
--- a/libjava/java/lang/natVMClassLoader.cc
+++ b/libjava/java/lang/natVMClassLoader.cc
@@ -23,7 +23,7 @@ details. */
#include <java/lang/VMClassLoader.h>
#include <java/lang/VMCompiler.h>
-#include <gnu/gcj/runtime/VMClassLoader.h>
+#include <gnu/gcj/runtime/ExtensionClassLoader.h>
#include <gnu/gcj/runtime/SystemClassLoader.h>
#include <gnu/gcj/runtime/BootClassLoader.h>
#include <java/lang/ClassLoader.h>
@@ -31,6 +31,9 @@ details. */
#include <java/lang/Throwable.h>
#include <java/security/ProtectionDomain.h>
#include <java/lang/ClassFormatError.h>
+#include <java/lang/StringBuffer.h>
+#include <java/lang/Runtime.h>
+#include <java/util/HashSet.h>
void
java::lang::VMClassLoader::resolveClass (jclass klass)
@@ -110,8 +113,8 @@ java::lang::VMClassLoader::defineClass (java::lang::ClassLoader *loader,
java::lang::ClassLoader *
java::lang::VMClassLoader::getSystemClassLoaderInternal()
{
- _Jv_InitClass (&gnu::gcj::runtime::VMClassLoader::class$);
- return gnu::gcj::runtime::VMClassLoader::system_instance;
+ _Jv_InitClass (&gnu::gcj::runtime::ExtensionClassLoader::class$);
+ return gnu::gcj::runtime::ExtensionClassLoader::system_instance;
}
jclass
@@ -130,6 +133,68 @@ java::lang::VMClassLoader::initBootLoader(jstring libdir)
}
jclass
+java::lang::VMClassLoader::nativeFindClass (jstring name)
+{
+ jclass klass = NULL;
+
+ if (lib_control != LIB_NEVER)
+ {
+ // Turn `gnu.pkg.quux' into `lib-gnu-pkg-quux'. Then search for
+ // a module named (eg, on Linux) `lib-gnu-pkg-quux.so', followed
+ // by `lib-gnu-pkg.so' and `lib-gnu.so'. If loading one of
+ // these causes the class to appear in the cache, then use it.
+ java::lang::StringBuffer *sb
+ = new java::lang::StringBuffer (JvNewStringLatin1("lib-"));
+ // Skip inner classes
+ jstring cn;
+ jint ci = name->indexOf('$');
+ if (ci == -1)
+ cn = name;
+ else
+ cn = name->substring (0, ci);
+ jstring so_base_name
+ = (sb->append (cn)->toString ())->replace ('.', '-');
+
+ using namespace ::java::lang;
+ Runtime *rt = Runtime::getRuntime();
+
+ _Jv_Utf8Const *name_u = NULL;
+
+ // Compare against `3' because that is the length of "lib".
+ while (! klass && so_base_name && so_base_name->length() > 3)
+ {
+ if (lib_control == LIB_CACHE)
+ {
+ // If we've already tried this name, we're done.
+ if (tried_libraries->contains(so_base_name))
+ break;
+ tried_libraries->add(so_base_name);
+ }
+
+ jboolean loaded = rt->loadLibraryInternal (so_base_name);
+
+ jint nd = so_base_name->lastIndexOf ('-');
+ if (nd == -1)
+ so_base_name = NULL;
+ else
+ so_base_name = so_base_name->substring (0, nd);
+
+ if (loaded)
+ {
+ if (name_u == NULL)
+ name_u = _Jv_makeUtf8Const (name);
+ klass = _Jv_FindClassInCache (name_u);
+ }
+ }
+ }
+
+ if (klass)
+ definePackageForNative(name);
+
+ return klass;
+}
+
+jclass
java::lang::VMClassLoader::loadClass(jstring name, jboolean resolve)
{
// We try the boot loader first, so that the endorsed directory
@@ -142,6 +207,8 @@ java::lang::VMClassLoader::loadClass(jstring name, jboolean resolve)
_Jv_Utf8Const *utf = _Jv_makeUtf8Const (name);
klass = _Jv_FindClassInCache (utf);
}
+ if (! klass)
+ klass = nativeFindClass(name);
if (klass)
{
// We never want to return a class without its supers linked.
OpenPOWER on IntegriCloud