summaryrefslogtreecommitdiffstats
path: root/libjava/gnu/gcj/runtime/SharedLibHelper.java
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-28 22:17:37 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-28 22:17:37 +0000
commitcadef59253f55d4564de9e11df34be2222521be3 (patch)
treea5d84d77e14c8eed9bc348be5e03ab4e6490a077 /libjava/gnu/gcj/runtime/SharedLibHelper.java
parent8a9af253b42bf90afe7238f6667163a92c92fe96 (diff)
downloadppe42-gcc-cadef59253f55d4564de9e11df34be2222521be3.tar.gz
ppe42-gcc-cadef59253f55d4564de9e11df34be2222521be3.zip
* Makefile.in: Rebuilt.
* Makefile.am (ordinary_java_source_files): Added new files. * java/lang/Class.h (_Jv_sharedlib_register_hook): Declare as friend. * java/net/URLClassLoader.java (findClass): Don't use findURLResource. Use loader's getClass method. (URLLoader.getClass): New method. (addURL): Handle `gcjlib' URLs. (SoURLLoader): New class. (SoResource): Likewise. * gnu/gcj/protocol/gcjlib/Connection.java: New file. * gnu/gcj/protocol/gcjlib/Handler.java: New file. * include/jvm.h (struct _Jv_core_chain): Moved from natCore.cc. (_Jv_RegisterCoreHook): Declare. (_Jv_FindCore): Declare. * gnu/gcj/runtime/SharedLibHelper.java: New file. * gnu/gcj/runtime/natSharedLibLoader.cc (CoreHookFunc): New typedef. (core_hook): New function. (struct SharedLibDummy) [saved_core]: New field. (init): Set _Jv_RegisterCoreHook. Throw exception on failure. (register_hook): Set protection domain and class loader on new class. (finalize): Free core chain. * gnu/gcj/Core.java (Core): New constructor. * gnu/gcj/runtime/SharedLibLoader.java: Rewrote to use SharedLibHelper. * gnu/gcj/natCore.cc (_Jv_RegisterResource): Indentation fixlet. (_Jv_create_core): New function. (create): Use it. (default_register_resource): New function. (_Jv_RegisterCoreHook): New global. (_Jv_RegisterResource): Use it. (core_chain_struct): Removed. (_Jv_FindCore): New function. (_Jv_FreeCoreChain): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70892 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu/gcj/runtime/SharedLibHelper.java')
-rw-r--r--libjava/gnu/gcj/runtime/SharedLibHelper.java144
1 files changed, 144 insertions, 0 deletions
diff --git a/libjava/gnu/gcj/runtime/SharedLibHelper.java b/libjava/gnu/gcj/runtime/SharedLibHelper.java
new file mode 100644
index 00000000000..9e170a120be
--- /dev/null
+++ b/libjava/gnu/gcj/runtime/SharedLibHelper.java
@@ -0,0 +1,144 @@
+/* Copyright (C) 2001, 2003 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+package gnu.gcj.runtime;
+import java.lang.ref.WeakReference;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.HashMap;
+import java.security.*;
+import gnu.gcj.Core;
+
+public class SharedLibHelper
+{
+ /** Load a shared library, and associate a ClassLoader with it.
+ * @param libname named of shared library (passed to dlopen)
+ * @param parent the parent ClassLoader
+ * @parem flags passed to dlopen
+ */
+ SharedLibHelper(String libname, ClassLoader parent, CodeSource source,
+ int flags)
+ {
+ // FIXME: ask security manager first.
+ loader = parent;
+ baseName = libname;
+ domain = new ProtectionDomain(source,
+ Policy.getPolicy().getPermissions(source));
+ this.flags = flags;
+ }
+
+ public static SharedLibHelper findHelper (String libname)
+ {
+ synchronized (map)
+ {
+ WeakReference ref = (WeakReference) map.get(libname);
+ if (ref != null)
+ return (SharedLibHelper) ref.get();
+ return null;
+ }
+ }
+
+ public static SharedLibHelper findHelper (ClassLoader loader, String libname,
+ CodeSource source)
+ {
+ synchronized (map)
+ {
+ SharedLibHelper result;
+ WeakReference ref = (WeakReference) map.get(libname);
+ if (ref != null)
+ {
+ result = (SharedLibHelper) ref.get();
+ if (result != null)
+ {
+ if (result.loader != loader)
+ // FIXME
+ throw new UnknownError();
+ return result;
+ }
+ }
+
+ result = new SharedLibHelper(libname, loader, source, 0);
+ map.put(libname, new WeakReference(result));
+ return result;
+ }
+ }
+
+ public native void finalize ();
+
+ public Class findClass(String name)
+ {
+ ensureInit();
+ return (Class) classMap.get(name);
+ }
+
+ public URL findResource (String name)
+ {
+ ensureInit();
+ if (! hasResource(name))
+ return null;
+ try
+ {
+ return new URL("gcjlib", "", -1, baseName + "!/" + name);
+ }
+ catch (MalformedURLException _)
+ {
+ }
+ return null;
+ }
+
+ public native Core findCore (String name);
+
+ void ensureInit()
+ {
+ synchronized (classMap)
+ {
+ if (initialized)
+ return;
+ init();
+ initialized = true;
+ }
+ }
+
+ native boolean hasResource(String name);
+ native void init();
+
+ /** Called during dlopen's processing of the init section. */
+ void registerClass(String name, Class cls)
+ {
+ classMap.put(name, cls);
+ }
+
+ /** The handle returned by dlopen. */
+ gnu.gcj.RawData handler;
+
+ /** Holds a _Jv_core_chain for the loader. */
+ gnu.gcj.RawData core_chain;
+
+ /** Map classnames to Classes. */
+ HashMap classMap = new HashMap(20);
+
+ /** Class loader we're helping. */
+ ClassLoader loader;
+
+ /** Name of base file. */
+ String baseName;
+
+ /** Protection domain for loaded classes. */
+ ProtectionDomain domain;
+
+ /** Flags to pass to dlopen. FIXME: platform dependent.
+ 0 is always "sensible" (defined by us). */
+ int flags;
+
+ /** True if we've been initialized. */
+ boolean initialized = false;
+
+ /** Map shared library names to a helper object. This uses weak
+ references in the values so we don't prevent collection. */
+ static HashMap map = new HashMap ();
+}
OpenPOWER on IntegriCloud