fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / java / lang / VMClassLoader.java
blob02010e7e9734148bd0fe8f1bb7efd3435165bda3
1 /* VMClassLoader.java -- Reference implementation of native interface
2 required by ClassLoader
3 Copyright (C) 1998, 2001, 2002, 2003 Free Software Foundation
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
39 package java.lang;
41 import java.security.ProtectionDomain;
42 import java.net.URL;
43 import java.io.IOException;
44 import java.util.Enumeration;
45 import java.util.Map;
46 import java.util.HashMap;
47 import java.lang.reflect.Constructor;
48 import java.security.AllPermission;
49 import java.security.Permission;
50 import java.security.Permissions;
51 import java.security.ProtectionDomain;
53 import gnu.java.util.EmptyEnumeration;
55 /**
56 * java.lang.VMClassLoader is a package-private helper for VMs to implement
57 * on behalf of java.lang.ClassLoader.
59 * @author John Keiser
60 * @author Mark Wielaard <mark@klomp.org>
61 * @author Eric Blake <ebb9@email.byu.edu>
63 final class VMClassLoader
65 // Protection Domain definitions
66 // FIXME: should there be a special protection domain used for native code?
68 // The permission required to check what a classes protection domain is.
69 static final Permission protectionDomainPermission
70 = new RuntimePermission("getProtectionDomain");
71 // The protection domain returned if we cannot determine it.
72 static ProtectionDomain unknownProtectionDomain;
74 static
76 Permissions permissions = new Permissions();
77 permissions.add(new AllPermission());
78 unknownProtectionDomain = new ProtectionDomain(null, permissions);
81 /**
82 * Helper to define a class using a string of bytes. This assumes that
83 * the security checks have already been performed, if necessary.
85 * <strong>For backward compatibility, this just ignores the protection
86 * domain; that is the wrong behavior, and you should directly implement
87 * this method natively if you can.</strong>
89 * @param name the name to give the class, or null if unknown
90 * @param data the data representing the classfile, in classfile format
91 * @param offset the offset into the data where the classfile starts
92 * @param len the length of the classfile data in the array
93 * @param pd the protection domain
94 * @return the class that was defined
95 * @throws ClassFormatError if data is not in proper classfile format
97 static final native Class defineClass(ClassLoader cl, String name,
98 byte[] data, int offset, int len,
99 ProtectionDomain pd)
100 throws ClassFormatError;
102 static final native void linkClass0 (Class klass);
103 static final native void markClassErrorState0 (Class klass);
106 * Helper to resolve all references to other classes from this class.
108 * @param c the class to resolve
110 static final void resolveClass(Class clazz)
112 synchronized (clazz)
116 linkClass0 (clazz);
118 catch (Throwable x)
120 markClassErrorState0 (clazz);
122 LinkageError e;
123 if (x instanceof LinkageError)
124 e = (LinkageError) x;
125 else if (x instanceof ClassNotFoundException)
127 e = new NoClassDefFoundError("while resolving class: "
128 + clazz.getName());
129 e.initCause (x);
131 else
133 e = new LinkageError ("unexpected exception during linking: "
134 + clazz.getName());
135 e.initCause (x);
137 throw e;
143 * Helper to load a class from the bootstrap class loader.
145 * @param name the class name to load
146 * @param resolve whether to resolve it
147 * @return the class, loaded by the bootstrap classloader or null
148 * if the class wasn't found. Returning null is equivalent to throwing
149 * a ClassNotFoundException (but a possible performance optimization).
151 static final native Class loadClass(String name, boolean resolve)
152 throws ClassNotFoundException;
155 * Helper to load a resource from the bootstrap class loader.
157 * In libgcj, this does nothing, as the default system loader knows
158 * how to find resources that have been linked in.
160 * @param name the resource to find
161 * @return the URL to the resource
163 static URL getResource(String name)
165 return null;
169 * Helper to get a list of resources from the bootstrap class loader.
171 * In libgcj, this does nothing, as the default system loader knows
172 * how to find resources that have been linked in.
174 * @param name the resource to find
175 * @return an enumeration of resources
176 * @throws IOException if one occurs
178 static Enumeration getResources(String name) throws IOException
180 return EmptyEnumeration.getInstance();
184 * Helper to get a package from the bootstrap class loader. The default
185 * implementation of returning null may be adequate, or you may decide
186 * that this needs some native help.
188 * @param name the name to find
189 * @return the named package, if it exists
191 static Package getPackage(String name)
193 return null;
197 * Helper to get all packages from the bootstrap class loader. The default
198 * implementation of returning an empty array may be adequate, or you may
199 * decide that this needs some native help.
201 * @return all named packages, if any exist
203 static Package[] getPackages()
205 return new Package[0];
209 * Helper for java.lang.Integer, Byte, etc to get the TYPE class
210 * at initialization time. The type code is one of the chars that
211 * represents the primitive type as in JNI.
213 * <ul>
214 * <li>'Z' - boolean</li>
215 * <li>'B' - byte</li>
216 * <li>'C' - char</li>
217 * <li>'D' - double</li>
218 * <li>'F' - float</li>
219 * <li>'I' - int</li>
220 * <li>'J' - long</li>
221 * <li>'S' - short</li>
222 * <li>'V' - void</li>
223 * </ul>
225 * @param type the primitive type
226 * @return a "bogus" class representing the primitive type
228 static final native Class getPrimitiveClass(char type);
231 * The system default for assertion status. This is used for all system
232 * classes (those with a null ClassLoader), as well as the initial value for
233 * every ClassLoader's default assertion status.
235 * XXX - Not implemented yet; this requires native help.
237 * @return the system-wide default assertion status
239 static final boolean defaultAssertionStatus()
241 return true;
245 * The system default for package assertion status. This is used for all
246 * ClassLoader's packageAssertionStatus defaults. It must be a map of
247 * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
248 * represented as a null key.
250 * XXX - Not implemented yet; this requires native help.
252 * @return a (read-only) map for the default packageAssertionStatus
254 static final Map packageAssertionStatus()
256 return new HashMap();
260 * The system default for class assertion status. This is used for all
261 * ClassLoader's classAssertionStatus defaults. It must be a map of
262 * class names to Boolean.TRUE or Boolean.FALSE
264 * XXX - Not implemented yet; this requires native help.
266 * @return a (read-only) map for the default classAssertionStatus
268 static final Map classAssertionStatus()
270 return new HashMap();
273 static native ClassLoader getSystemClassLoaderInternal();
275 static ClassLoader getSystemClassLoader()
277 // This method is called as the initialization of systemClassLoader,
278 // so if there is a null value, this is the first call and we must check
279 // for java.system.class.loader.
280 String loader = System.getProperty("java.system.class.loader");
281 ClassLoader default_sys = getSystemClassLoaderInternal();
282 if (loader != null)
286 Class load_class = Class.forName(loader, true, default_sys);
287 Constructor c
288 = load_class.getConstructor(new Class[] { ClassLoader.class });
289 default_sys
290 = (ClassLoader) c.newInstance(new Object[] { default_sys });
292 catch (Exception e)
294 System.err.println("Requested system classloader "
295 + loader + " failed, using "
296 + "gnu.gcj.runtime.VMClassLoader");
297 e.printStackTrace();
300 return default_sys;