OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [vm/] [reference/] [java/] [lang/] [VMClassLoader.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* VMClassLoader.java -- Reference implementation of native interface
2
   required by ClassLoader
3
   Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation
4
 
5
This file is part of GNU Classpath.
6
 
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.
11
 
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.
16
 
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.
21
 
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.
26
 
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. */
38
 
39
 
40
package java.lang;
41
 
42
import gnu.classpath.SystemProperties;
43
import gnu.classpath.Configuration;
44
 
45
import java.io.File;
46
import java.io.IOException;
47
import java.net.MalformedURLException;
48
import java.net.URL;
49
import java.security.ProtectionDomain;
50
import java.util.Enumeration;
51
import java.util.HashMap;
52
import java.util.Map;
53
import java.util.StringTokenizer;
54
import java.util.Vector;
55
import java.util.zip.ZipFile;
56
 
57
/**
58
 * java.lang.VMClassLoader is a package-private helper for VMs to implement
59
 * on behalf of java.lang.ClassLoader.
60
 *
61
 * @author John Keiser
62
 * @author Mark Wielaard (mark@klomp.org)
63
 * @author Eric Blake (ebb9@email.byu.edu)
64
 */
65
final class VMClassLoader
66
{
67
 
68
 
69
  /** packages loaded by the bootstrap class loader */
70
  static final HashMap definedPackages = new HashMap();
71
 
72
  /**
73
   * Converts the array string of native package names to
74
   * Packages. The packages are then put into the
75
   * definedPackages hashMap
76
   */
77
  static
78
  {
79
    String[] packages = getBootPackages();
80
 
81
    if( packages != null)
82
      {
83
        String specName =
84
              SystemProperties.getProperty("java.specification.name");
85
        String vendor =
86
              SystemProperties.getProperty("java.specification.vendor");
87
        String version =
88
              SystemProperties.getProperty("java.specification.version");
89
 
90
        Package p;
91
 
92
        for(int i = 0; i < packages.length; i++)
93
          {
94
            p = new Package(packages[i],
95
                  specName,
96
                  vendor,
97
                  version,
98
                  "GNU Classpath",
99
                  "GNU",
100
                  Configuration.CLASSPATH_VERSION,
101
                  null);
102
 
103
            definedPackages.put(packages[i], p);
104
          }
105
      }
106
  }
107
 
108
 
109
  /**
110
   * Helper to define a class using a string of bytes. This assumes that
111
   * the security checks have already been performed, if necessary.
112
   *
113
   * Implementations of this method are advised to consider the
114
   * situation where user code modifies the byte array after it has
115
   * been passed to defineClass.  This can be handled by making a
116
   * private copy of the array, or arranging to only read any given
117
   * byte a single time.
118
   *
119
   * @param name the name to give the class, or null if unknown
120
   * @param data the data representing the classfile, in classfile format
121
   * @param offset the offset into the data where the classfile starts
122
   * @param len the length of the classfile data in the array
123
   * @param pd the protection domain
124
   * @return the class that was defined
125
   * @throws ClassFormatError if data is not in proper classfile format
126
   */
127
  static final native Class defineClass(ClassLoader cl, String name,
128
                                 byte[] data, int offset, int len,
129
                                 ProtectionDomain pd)
130
    throws ClassFormatError;
131
 
132
  /**
133
   * Helper to resolve all references to other classes from this class.
134
   *
135
   * @param c the class to resolve
136
   */
137
  static final native void resolveClass(Class c);
138
 
139
  /**
140
   * Helper to load a class from the bootstrap class loader.
141
   *
142
   * @param name the class name to load
143
   * @param resolve whether to resolve it
144
   * @return the class, loaded by the bootstrap classloader or null
145
   * if the class wasn't found. Returning null is equivalent to throwing
146
   * a ClassNotFoundException (but a possible performance optimization).
147
   */
148
  static final native Class loadClass(String name, boolean resolve)
149
    throws ClassNotFoundException;
150
 
151
  /**
152
   * Helper to load a resource from the bootstrap class loader.
153
   *
154
   * @param name the resource to find
155
   * @return the URL to the resource
156
   */
157
  static URL getResource(String name)
158
  {
159
    Enumeration e = getResources(name);
160
    if (e.hasMoreElements())
161
      return (URL)e.nextElement();
162
    return null;
163
  }
164
 
165
  /** jars from property java.boot.class.path */
166
  static final HashMap bootjars = new HashMap();
167
 
168
  /**
169
   * Helper to get a list of resources from the bootstrap class loader.
170
   *
171
   * @param name the resource to find
172
   * @return an enumeration of resources
173
   * @throws IOException if one occurs
174
   */
175
  static Enumeration getResources(String name)
176
  {
177
    StringTokenizer st = new StringTokenizer(
178
      SystemProperties.getProperty("java.boot.class.path", "."),
179
      File.pathSeparator);
180
    Vector v = new Vector();
181
    while (st.hasMoreTokens())
182
      {
183
        File file = new File(st.nextToken());
184
        if (file.isDirectory())
185
          {
186
            try
187
              {
188
                File f = new File(file, name);
189
                if (!f.exists()) continue;
190
                v.add(new URL("file://" + f.getAbsolutePath()));
191
              }
192
            catch (MalformedURLException e)
193
              {
194
                throw new Error(e);
195
              }
196
          }
197
        else if (file.isFile())
198
          {
199
            ZipFile zip;
200
            synchronized(bootjars)
201
              {
202
                zip = (ZipFile) bootjars.get(file.getName());
203
              }
204
            if(zip == null)
205
              {
206
                try
207
                  {
208
                    zip = new ZipFile(file);
209
                    synchronized(bootjars)
210
                      {
211
                        bootjars.put(file.getName(), zip);
212
                      }
213
                  }
214
                catch (IOException e)
215
                  {
216
                    continue;
217
                  }
218
              }
219
            String zname = name.startsWith("/") ? name.substring(1) : name;
220
            if (zip.getEntry(zname) == null)
221
              continue;
222
            try
223
              {
224
                v.add(new URL("jar:file://"
225
                  + file.getAbsolutePath() + "!/" + zname));
226
              }
227
            catch (MalformedURLException e)
228
              {
229
                throw new Error(e);
230
              }
231
          }
232
      }
233
    return v.elements();
234
  }
235
 
236
 
237
  /**
238
   * Returns a String[] of native package names. The default
239
   * implementation returns an empty array, or you may decide
240
   * this needs native help.
241
   */
242
  private static String[] getBootPackages()
243
  {
244
    return new String[0];
245
  }
246
 
247
 
248
  /**
249
   * Helper to get a package from the bootstrap class loader.
250
   *
251
   * @param name the name to find
252
   * @return the named package, if it exists
253
   */
254
  static Package getPackage(String name)
255
  {
256
    return (Package)definedPackages.get(name);
257
  }
258
 
259
 
260
 
261
  /**
262
   * Helper to get all packages from the bootstrap class loader.
263
   *
264
   * @return all named packages, if any exist
265
   */
266
  static Package[] getPackages()
267
  {
268
    Package[] packages = new Package[definedPackages.size()];
269
    definedPackages.values().toArray(packages);
270
    return packages;
271
  }
272
 
273
  /**
274
   * Helper for java.lang.Integer, Byte, etc to get the TYPE class
275
   * at initialization time. The type code is one of the chars that
276
   * represents the primitive type as in JNI.
277
   *
278
   * <ul>
279
   * <li>'Z' - boolean</li>
280
   * <li>'B' - byte</li>
281
   * <li>'C' - char</li>
282
   * <li>'D' - double</li>
283
   * <li>'F' - float</li>
284
   * <li>'I' - int</li>
285
   * <li>'J' - long</li>
286
   * <li>'S' - short</li>
287
   * <li>'V' - void</li>
288
   * </ul>
289
   *
290
   * @param type the primitive type
291
   * @return a "bogus" class representing the primitive type
292
   */
293
  static final native Class getPrimitiveClass(char type);
294
 
295
  /**
296
   * The system default for assertion status. This is used for all system
297
   * classes (those with a null ClassLoader), as well as the initial value for
298
   * every ClassLoader's default assertion status.
299
   *
300
   * XXX - Not implemented yet; this requires native help.
301
   *
302
   * @return the system-wide default assertion status
303
   */
304
  static final boolean defaultAssertionStatus()
305
  {
306
    return true;
307
  }
308
 
309
  /**
310
   * The system default for package assertion status. This is used for all
311
   * ClassLoader's packageAssertionStatus defaults. It must be a map of
312
   * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
313
   * represented as a null key.
314
   *
315
   * XXX - Not implemented yet; this requires native help.
316
   *
317
   * @return a (read-only) map for the default packageAssertionStatus
318
   */
319
  static final Map packageAssertionStatus()
320
  {
321
    return new HashMap();
322
  }
323
 
324
  /**
325
   * The system default for class assertion status. This is used for all
326
   * ClassLoader's classAssertionStatus defaults. It must be a map of
327
   * class names to Boolean.TRUE or Boolean.FALSE
328
   *
329
   * XXX - Not implemented yet; this requires native help.
330
   *
331
   * @return a (read-only) map for the default classAssertionStatus
332
   */
333
  static final Map classAssertionStatus()
334
  {
335
    return new HashMap();
336
  }
337
 
338
  static ClassLoader getSystemClassLoader()
339
  {
340
    return ClassLoader.defaultGetSystemClassLoader();
341
  }
342
 
343
  /**
344
   * Find the class if this class loader previously defined this class
345
   * or if this class loader has been recorded as the initiating class loader
346
   * for this class.
347
   */
348
  static native Class findLoadedClass(ClassLoader cl, String name);
349
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.