hotspot/test/runtime/6626217/Loader2.java
author mgerdin
Mon, 11 Aug 2014 17:12:41 +0400
changeset 25958 8dc85547d6d6
parent 6257 43c2f12b4e90
child 46503 760f8f589de3
permissions -rw-r--r--
8011397: JTREG needs to copy additional WhiteBox class file to JTwork/scratch/sun/hotspot Reviewed-by: kvn, iignatyev, mgerdin Contributed-by: andrey.x.zakharov@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6257
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     1
import java.io.ByteArrayInputStream;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     2
import java.io.FileInputStream;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     3
public class Loader2 extends ClassLoader {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     4
  int _recur;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     5
  public void print( String msg ) {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     6
    for( int i=0; i<_recur; i++ )
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     7
      System.out.print("  ");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     8
    System.out.println(">>Loader2>> "+msg);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
     9
  }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    10
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    11
  protected Class findClass2(String name) throws ClassNotFoundException {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    12
    print("Fetching the implementation of "+name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    13
    int old = _recur;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    14
    try {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    15
      FileInputStream fi = new FileInputStream(name+".impl2");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    16
      byte result[] = new byte[fi.available()];
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    17
      fi.read(result);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    18
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    19
      print("DefineClass1 on "+name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    20
      _recur++;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    21
      Class clazz = defineClass(name, result, 0, result.length);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    22
      _recur = old;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    23
      print("Returning newly loaded class.");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    24
      return clazz;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    25
    } catch (Exception e) {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    26
      _recur = old;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    27
      print("Not found on disk.");
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    28
      // If we caught an exception, either the class was not found or
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    29
      // it was unreadable by our process.
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    30
      return null;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    31
      //throw new ClassNotFoundException(e.toString());
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    32
    }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    33
  }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    34
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    35
  protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException  {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    36
    // Attempt a disk load first
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    37
    Class c = findClass2(name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    38
    if( c == null ) {
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    39
      // check if the class has already been loaded
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    40
      print("Checking for prior loaded class "+name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    41
      c = findLoadedClass(name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    42
      print("Letting super-loader load "+name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    43
      int old = _recur;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    44
      _recur++;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    45
      c = super.loadClass(name, false);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    46
      _recur=old;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    47
    }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    48
    if (resolve) { print("Resolving class "+name); resolveClass(c); }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    49
    print("Returning clazz "+c.getClassLoader()+":"+name);
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    50
    return c;
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    51
  }
43c2f12b4e90 6977952: Test: Sync missing tests from hs16.3 to hs17.x
asaha
parents:
diff changeset
    52
}