1 /* Copyright (C) 1999, 2001, 2002, 2003 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 /* Author: Kresten Krab Thorup <krab@gnu.org> */
11 package gnu
.gcj
.runtime
;
14 import java
.util
.StringTokenizer
;
15 import java
.util
.HashSet
;
18 public final class VMClassLoader
extends java
.net
.URLClassLoader
20 private VMClassLoader ()
24 = System
.getProperty ("gnu.gcj.runtime.VMClassLoader.library_control",
26 if ("never".equals(p
))
27 lib_control
= LIB_NEVER
;
28 else if ("cache".equals(p
))
29 lib_control
= LIB_CACHE
;
30 else if ("full".equals(p
))
32 // In case we ever want to change the default.
33 lib_control
= LIB_FULL
;
36 lib_control
= LIB_FULL
;
39 private static URL
[] init()
42 = new StringTokenizer (System
.getProperty ("java.class.path", "."),
43 System
.getProperty ("path.separator", ":"));
45 java
.util
.Vector p
= new java
.util
.Vector();
46 while (st
.hasMoreElements ())
48 String e
= st
.nextToken ();
51 if (!e
.endsWith (File
.separator
) && new File (e
).isDirectory ())
52 p
.addElement (new URL("file", "", -1, e
+ File
.separator
));
54 p
.addElement (new URL("file", "", -1, e
));
56 catch (java
.net
.MalformedURLException x
)
58 /* Ignore this path element */
61 // Add core:/ to the end of the java.class.path so any resources
62 // compiled into this executable may be found.
65 p
.addElement (new URL("core", "", -1, "/"));
67 catch (java
.net
.MalformedURLException x
)
69 // This should never happen.
72 URL
[] urls
= new URL
[p
.size()];
77 /** This is overridden to search the internal hash table, which
78 * will only search existing linked-in classes. This will make
79 * the default implementation of loadClass (in ClassLoader) work right.
80 * The implementation of this method is in java/lang/natClassLoader.cc.
82 protected native Class
findClass(String name
)
83 throws java
.lang
.ClassNotFoundException
;
85 // This keeps track of shared libraries we've already tried to load.
86 private HashSet tried_libraries
= new HashSet();
88 // Holds one of the LIB_* constants; used to determine how shared
89 // library loads are done.
90 private int lib_control
;
92 // The only VMClassLoader that can exist.
93 static VMClassLoader instance
= new VMClassLoader();
95 private static final int LIB_FULL
= 0;
96 private static final int LIB_CACHE
= 1;
97 private static final int LIB_NEVER
= 2;