1 | /* Copyright (C) 2001, 2003 Free Software Foundation
|
---|
2 |
|
---|
3 | This file is part of libgcj.
|
---|
4 |
|
---|
5 | This software is copyrighted work licensed under the terms of the
|
---|
6 | Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
---|
7 | details. */
|
---|
8 |
|
---|
9 | package gnu.gcj.runtime;
|
---|
10 | import java.util.Hashtable;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * A ClassLoader backed by a gcj-compiled shared library.
|
---|
14 | * @author Per Bothner <per@bothner.com>, Brainfood Inc.
|
---|
15 | */
|
---|
16 |
|
---|
17 | public class SharedLibLoader extends ClassLoader
|
---|
18 | {
|
---|
19 | public native void finalize ();
|
---|
20 |
|
---|
21 | /** Called during dlopen's processing of the init section. */
|
---|
22 | void registerClass(String name, Class cls)
|
---|
23 | {
|
---|
24 | classMap.put(name, cls);
|
---|
25 | }
|
---|
26 |
|
---|
27 | /** Load a shared library, and associate a ClassLoader with it.
|
---|
28 | * @param libname named of shared library (passed to dlopen)
|
---|
29 | * @param parent the parent ClassLoader
|
---|
30 | * @param flags passed to dlopen
|
---|
31 | */
|
---|
32 | public SharedLibLoader(String libname, ClassLoader parent, int flags)
|
---|
33 | {
|
---|
34 | super(parent);
|
---|
35 | init(libname, flags);
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | /** Load a shared library, and asociate a ClassLoader with it.
|
---|
40 | * @param libname named of shared library (passed to dlopen)
|
---|
41 | */
|
---|
42 | public SharedLibLoader(String libname)
|
---|
43 | {
|
---|
44 | super(getSystemClassLoader());
|
---|
45 | init(libname, 0);
|
---|
46 | }
|
---|
47 |
|
---|
48 | void init(String libname, int flags)
|
---|
49 | {
|
---|
50 | init(libname.getBytes(), flags);
|
---|
51 | }
|
---|
52 |
|
---|
53 | native void init(byte[] libname, int flags);
|
---|
54 |
|
---|
55 | public Class loadClass(String name)
|
---|
56 | throws ClassNotFoundException
|
---|
57 | {
|
---|
58 | return super.loadClass(name);
|
---|
59 | }
|
---|
60 |
|
---|
61 | public Class findClass(String name)
|
---|
62 | throws ClassNotFoundException
|
---|
63 | {
|
---|
64 | Object cls = classMap.get(name);
|
---|
65 | if (cls == null)
|
---|
66 | throw new ClassNotFoundException(name);
|
---|
67 | return (Class) cls;
|
---|
68 | }
|
---|
69 |
|
---|
70 | /** The handle returned by dlopen. */
|
---|
71 | gnu.gcj.RawData handler;
|
---|
72 |
|
---|
73 | /** Map classnames to Classes. */
|
---|
74 | Hashtable classMap = new Hashtable(20);
|
---|
75 | }
|
---|