~ubuntu-branches/ubuntu/precise/classpath/precise

« back to all changes in this revision

Viewing changes to vm/reference/java/lang/VMClassLoader.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2006-05-27 16:11:15 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060527161115-h6e39eposdt5snb6
Tags: 2:0.91-3
* Install header files to /usr/include/classpath.
* debian/control: classpath: Conflict with jamvm < 1.4.3 and
  cacao < 0.96 (Closes: #368172).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* VMClassLoader.java -- Reference implementation of native interface
2
2
   required by ClassLoader
3
 
   Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation
 
3
   Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 Free Software Foundation
4
4
 
5
5
This file is part of GNU Classpath.
6
6
 
39
39
 
40
40
package java.lang;
41
41
 
 
42
import gnu.classpath.Configuration;
42
43
import gnu.classpath.SystemProperties;
43
 
import gnu.classpath.Configuration;
 
44
import gnu.java.lang.InstrumentationImpl;
44
45
 
 
46
import java.io.BufferedReader;
45
47
import java.io.File;
46
48
import java.io.IOException;
 
49
import java.io.InputStreamReader;
 
50
import java.lang.instrument.Instrumentation;
47
51
import java.net.MalformedURLException;
48
52
import java.net.URL;
49
53
import java.security.ProtectionDomain;
50
54
import java.util.Enumeration;
51
55
import java.util.HashMap;
 
56
import java.util.HashSet;
52
57
import java.util.Map;
 
58
import java.util.Set;
53
59
import java.util.StringTokenizer;
54
60
import java.util.Vector;
55
61
import java.util.zip.ZipFile;
98
104
                  "GNU Classpath",
99
105
                  "GNU",
100
106
                  Configuration.CLASSPATH_VERSION,
 
107
                  null,
101
108
                  null);
102
109
 
103
110
            definedPackages.put(packages[i], p);
170
177
   *
171
178
   * @param name the resource to find
172
179
   * @return an enumeration of resources
173
 
   * @throws IOException if one occurs
174
180
   */
175
181
  static Enumeration getResources(String name)
176
182
  {
236
242
 
237
243
  /**
238
244
   * Returns a String[] of native package names. The default
239
 
   * implementation returns an empty array, or you may decide
240
 
   * this needs native help.
 
245
   * implementation tries to load a list of package from
 
246
   * the META-INF/INDEX.LIST file in the boot jar file.
 
247
   * If not found or if any exception is raised, it returns
 
248
   * an empty array. You may decide this needs native help.
241
249
   */
242
250
  private static String[] getBootPackages()
243
251
  {
244
 
    return new String[0];
 
252
    URL indexList = getResource("META-INF/INDEX.LIST");
 
253
    if (indexList != null)
 
254
      {
 
255
        try
 
256
          {
 
257
            Set packageSet = new HashSet();
 
258
            String line;
 
259
            int lineToSkip = 3;
 
260
            BufferedReader reader = new BufferedReader(
 
261
                                                       new InputStreamReader(
 
262
                                                                             indexList.openStream()));
 
263
            while ((line = reader.readLine()) != null)
 
264
              {
 
265
                if (lineToSkip == 0)
 
266
                  {
 
267
                    if (line.length() == 0)
 
268
                      lineToSkip = 1;
 
269
                    else
 
270
                      packageSet.add(line.replace('/', '.'));
 
271
                  }
 
272
                else
 
273
                  lineToSkip--;
 
274
              }
 
275
            reader.close();
 
276
            return (String[]) packageSet.toArray(new String[packageSet.size()]);
 
277
          }
 
278
        catch (IOException e)
 
279
          {
 
280
            return new String[0];
 
281
          }
 
282
      }
 
283
    else
 
284
      return new String[0];
245
285
  }
246
286
 
247
287
 
346
386
   * for this class.
347
387
   */
348
388
  static native Class findLoadedClass(ClassLoader cl, String name);
 
389
 
 
390
  /**
 
391
   * The Instrumentation object created by the vm when agents are defined.
 
392
   */
 
393
  static final Instrumentation instrumenter = null;
 
394
 
 
395
  /**
 
396
   * Call the transformers of the possible Instrumentation object. This
 
397
   * implementation assumes the instrumenter is a
 
398
   * <code>InstrumentationImpl</code> object. VM implementors would
 
399
   * have to redefine this method if they provide their own implementation
 
400
   * of the <code>Instrumentation</code> interface.
 
401
   *
 
402
   * @param loader the initiating loader
 
403
   * @param name the name of the class
 
404
   * @param data the data representing the classfile, in classfile format
 
405
   * @param offset the offset into the data where the classfile starts
 
406
   * @param len the length of the classfile data in the array
 
407
   * @param pd the protection domain
 
408
   * @return the new data representing the classfile
 
409
   */
 
410
  static final Class defineClassWithTransformers(ClassLoader loader,
 
411
      String name, byte[] data, int offset, int len, ProtectionDomain pd)
 
412
  {
 
413
    
 
414
    if (instrumenter != null)
 
415
      {
 
416
        byte[] modifiedData = new byte[len];
 
417
        System.arraycopy(data, offset, modifiedData, 0, len);
 
418
        modifiedData =
 
419
          ((InstrumentationImpl)instrumenter).callTransformers(loader, name,
 
420
            null, pd, modifiedData);
 
421
        
 
422
        return defineClass(loader, name, modifiedData, 0, modifiedData.length,
 
423
            pd);
 
424
      }
 
425
    else
 
426
      {
 
427
        return defineClass(loader, name, data, offset, len, pd);
 
428
      }
 
429
  }
349
430
}