jamvm

view lib/java/lang/VMClassLoader.java @ 398:6476eceedae8

Comment out Java code that won't compile with OpenJDK's class library.

2008-08-04 Andrew John Hughes <gnu_andrew@member.fsf.org>

* lib/java/lang/VMClassLoader.java,
* lib/java/lang/VMRuntime.java,
* lib/java/lang/VMThread.java,
* lib/java/security/VMAccessController.java:
Remove GNU Classpath specific code through commenting.
author andrew
date Tue Aug 05 04:04:18 2008 +0100 (2008-08-05)
parents 768ab36fd30e
children
line source
1 /* VMClassLoader.java -- Reference implementation of native interface
2 required by ClassLoader
3 Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 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 /*
40 Robert Lougher 17/11/2003.
41 Major modifications have been made to this Classpath reference
42 implementation to work with JamVM.
43 */
45 package java.lang;
47 /*
48 import gnu.classpath.Configuration;
49 import gnu.classpath.SystemProperties;
50 import gnu.java.lang.InstrumentationImpl;
52 Removed to allow building against OpenJDK
53 Andrew John Hughes - July 2008
54 */
55 import java.io.BufferedReader;
56 import java.io.IOException;
57 import java.io.InputStreamReader;
58 import java.lang.instrument.Instrumentation;
59 import java.net.MalformedURLException;
60 import java.net.URL;
61 import java.security.ProtectionDomain;
62 import java.util.Enumeration;
63 import java.util.HashMap;
64 import java.util.HashSet;
65 import java.util.Set;
66 import java.util.Map;
67 import java.util.Vector;
69 /**
70 * java.lang.VMClassLoader is a package-private helper for VMs to implement
71 * on behalf of java.lang.ClassLoader.
72 *
73 * @author John Keiser
74 * @author Mark Wielaard (mark@klomp.org)
75 * @author Eric Blake (ebb9@email.byu.edu)
76 */
77 final class VMClassLoader
78 {
79 /** packages loaded by the bootstrap class loader */
80 static final HashMap definedPackages = new HashMap();
82 /**
83 * Converts the array string of native package names to
84 * Packages. The packages are then put into the
85 * definedPackages hashMap
86 */
87 static
88 {
89 String[] packages = getBootPackages();
91 if( packages != null)
92 {
93 /* Changed to work with OpenJDK
94 Not the same as these calls include security checks.
95 Andrew John Hughes - July 2008
96 */
97 String specName =
98 //SystemProperties.getProperty("java.specification.name");
99 System.getProperty("java.specification.name");
100 String vendor =
101 //SystemProperties.getProperty("java.specification.vendor");
102 System.getProperty("java.specification.vendor");
103 String version =
104 //SystemProperties.getProperty("java.specification.version");
105 System.getProperty("java.specification.version");
107 Package p;
109 for(int i = 0; i < packages.length; i++)
110 {
111 p = new Package(packages[i],
112 specName,
113 vendor,
114 version,
115 /* Changed to support OpenJDK
116 "GNU Classpath",
117 "GNU",
118 Configuration.CLASSPATH_VERSION,
119 */
120 "OpenJDK Common VM Interface",
121 "Andrew John Hughes",
122 "0.01",
123 null,
124 null);
126 definedPackages.put(packages[i], p);
127 }
128 }
129 }
131 /**
132 * Helper to define a class using a string of bytes. This assumes that
133 * the security checks have already been performed, if necessary.
134 *
135 * @param name the name to give the class, or null if unknown
136 * @param data the data representing the classfile, in classfile format
137 * @param offset the offset into the data where the classfile starts
138 * @param len the length of the classfile data in the array
139 * @param pd the protection domain
140 * @return the class that was defined
141 * @throws ClassFormatError if data is not in proper classfile format
142 */
143 static final native Class defineClass(ClassLoader cl, String name,
144 byte[] data, int offset, int len,
145 ProtectionDomain pd)
146 throws ClassFormatError;
148 /**
149 * Helper to resolve all references to other classes from this class.
150 *
151 * @param c the class to resolve
152 */
153 static final native void resolveClass(Class c);
155 /**
156 * Helper to load a class from the bootstrap class loader.
157 *
158 * @param name the class name to load
159 * @param resolve whether to resolve it
160 * @return the class, loaded by the bootstrap classloader or null
161 * if the class wasn't found. Returning null is equivalent to throwing
162 * a ClassNotFoundException (but a possible performance optimization).
163 */
164 static final native Class loadClass(String name, boolean resolve)
165 throws ClassNotFoundException;
167 /**
168 * Helper to load a resource from the bootstrap class loader.
169 *
170 * @param name the resource to find
171 * @return the URL to the resource
172 */
173 static URL getResource(String name) {
174 int entries = getBootClassPathSize();
176 for(int i = 0; i < entries; i++) {
177 String url = getBootClassPathResource(name, i);
178 if(url != null)
179 try {
180 return new URL(url);
181 } catch (MalformedURLException e) {}
182 }
184 return null;
185 }
187 /**
188 * Helper to get a list of resources from the bootstrap class loader.
189 *
190 * @param name the resource to find
191 * @return an enumeration of resources
192 */
193 static Enumeration getResources(String name) {
194 int entries = getBootClassPathSize();
195 Vector list = new Vector();
197 for(int i = 0; i < entries; i++) {
198 String url = getBootClassPathResource(name, i);
199 if(url != null)
200 try {
201 list.add(new URL(url));
202 } catch (MalformedURLException e) {}
203 }
205 return list.elements();
206 }
208 /**
209 * Returns a String[] of native package names. The default
210 * implementation tries to load a list of package from
211 * the META-INF/INDEX.LIST file in the boot jar file.
212 * If not found or if any exception is raised, it returns
213 * an empty array. You may decide this needs native help.
214 */
215 private static String[] getBootPackages()
216 {
217 URL indexList = getResource("META-INF/INDEX.LIST");
218 if (indexList != null)
219 {
220 try
221 {
222 Set packageSet = new HashSet();
223 String line;
224 int lineToSkip = 3;
225 BufferedReader reader = new BufferedReader(
226 new InputStreamReader(
227 indexList.openStream()));
228 while ((line = reader.readLine()) != null)
229 {
230 if (lineToSkip == 0)
231 {
232 if (line.length() == 0)
233 lineToSkip = 1;
234 else
235 packageSet.add(line.replace('/', '.'));
236 }
237 else
238 lineToSkip--;
239 }
240 reader.close();
241 return (String[]) packageSet.toArray(new String[packageSet.size()]);
242 }
243 catch (IOException e)
244 {
245 return new String[0];
246 }
247 }
248 else
249 return new String[0];
250 }
252 /**
253 * Helper to get a package from the bootstrap class loader.
254 *
255 * @param name the name to find
256 * @return the named package, if it exists
257 */
258 static Package getPackage(String name)
259 {
260 return (Package)definedPackages.get(name);
261 }
263 /**
264 * Helper to get all packages from the bootstrap class loader.
265 *
266 * @return all named packages, if any exist
267 */
268 static Package[] getPackages()
269 {
270 Package[] packages = new Package[definedPackages.size()];
271 definedPackages.values().toArray(packages);
272 return packages;
273 }
275 /**
276 * Helper for java.lang.Integer, Byte, etc to get the TYPE class
277 * at initialization time. The type code is one of the chars that
278 * represents the primitive type as in JNI.
279 *
280 * <ul>
281 * <li>'Z' - boolean</li>
282 * <li>'B' - byte</li>
283 * <li>'C' - char</li>
284 * <li>'D' - double</li>
285 * <li>'F' - float</li>
286 * <li>'I' - int</li>
287 * <li>'J' - long</li>
288 * <li>'S' - short</li>
289 * <li>'V' - void</li>
290 * </ul>
291 *
292 * @param type the primitive type
293 * @return a "bogus" class representing the primitive type
294 */
295 static final native Class getPrimitiveClass(char type);
297 /**
298 * The system default for assertion status. This is used for all system
299 * classes (those with a null ClassLoader), as well as the initial value for
300 * every ClassLoader's default assertion status.
301 *
302 * XXX - Not implemented yet; this requires native help.
303 *
304 * @return the system-wide default assertion status
305 */
306 static final boolean defaultAssertionStatus()
307 {
308 return true;
309 }
311 /**
312 * The system default for package assertion status. This is used for all
313 * ClassLoader's packageAssertionStatus defaults. It must be a map of
314 * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
315 * represented as a null key.
316 *
317 * XXX - Not implemented yet; this requires native help.
318 *
319 * @return a (read-only) map for the default packageAssertionStatus
320 */
321 static final Map packageAssertionStatus()
322 {
323 return new HashMap();
324 }
326 /**
327 * The system default for class assertion status. This is used for all
328 * ClassLoader's classAssertionStatus defaults. It must be a map of
329 * class names to Boolean.TRUE or Boolean.FALSE
330 *
331 * XXX - Not implemented yet; this requires native help.
332 *
333 * @return a (read-only) map for the default classAssertionStatus
334 */
335 static final Map classAssertionStatus()
336 {
337 return new HashMap();
338 }
340 /*
341 Removed to allow building against OpenJDK
342 Andrew John Hughes - July 2008
343 static ClassLoader getSystemClassLoader()
344 {
345 return ClassLoader.defaultGetSystemClassLoader();
346 }
347 */
349 /**
350 * Find the class if this class loader previously defined this class
351 * or if this class loader has been recorded as the initiating class loader
352 * for this class.
353 */
354 static native Class findLoadedClass(ClassLoader cl, String name);
356 /**
357 * The Instrumentation object created by the vm when agents are defined.
358 */
359 static final Instrumentation instrumenter = null;
361 /**
362 * Call the transformers of the possible Instrumentation object. This
363 * implementation assumes the instrumenter is a
364 * <code>InstrumentationImpl</code> object. VM implementors would
365 * have to redefine this method if they provide their own implementation
366 * of the <code>Instrumentation</code> interface.
367 *
368 * @param loader the initiating loader
369 * @param name the name of the class
370 * @param data the data representing the classfile, in classfile format
371 * @param offset the offset into the data where the classfile starts
372 * @param len the length of the classfile data in the array
373 * @param pd the protection domain
374 * @return the new data representing the classfile
375 */
376 static final Class defineClassWithTransformers(ClassLoader loader,
377 String name, byte[] data, int offset, int len, ProtectionDomain pd)
378 {
380 if (instrumenter != null)
381 {
382 byte[] modifiedData = new byte[len];
383 System.arraycopy(data, offset, modifiedData, 0, len);
384 /*
385 Removed to allow building against OpenJDK
386 Andrew John Hughes - July 2008
387 modifiedData =
388 ((InstrumentationImpl)instrumenter).callTransformers(loader, name,
389 null, pd, modifiedData);
390 return defineClass(loader, name, modifiedData, 0, modifiedData.length,
391 pd);
392 */
393 throw new InternalError("No transformers called.");
394 }
395 else
396 {
397 return defineClass(loader, name, data, offset, len, pd);
398 }
399 }
401 /* Native helper functions */
403 private static native int getBootClassPathSize();
404 private static native String getBootClassPathResource(String name, int index);
405 }