Mercurial > hg > graal-jvmci-8
comparison test/runtime/6626217/Loader2.java @ 1715:495caa35b1b5
6977952: Test: Sync missing tests from hs16.3 to hs17.x
Reviewed-by: wrockett
author | asaha |
---|---|
date | Tue, 17 Aug 2010 22:52:50 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1714:f121b2772674 | 1715:495caa35b1b5 |
---|---|
1 import java.io.ByteArrayInputStream; | |
2 import java.io.FileInputStream; | |
3 public class Loader2 extends ClassLoader { | |
4 int _recur; | |
5 public void print( String msg ) { | |
6 for( int i=0; i<_recur; i++ ) | |
7 System.out.print(" "); | |
8 System.out.println(">>Loader2>> "+msg); | |
9 } | |
10 | |
11 protected Class findClass2(String name) throws ClassNotFoundException { | |
12 print("Fetching the implementation of "+name); | |
13 int old = _recur; | |
14 try { | |
15 FileInputStream fi = new FileInputStream(name+".impl2"); | |
16 byte result[] = new byte[fi.available()]; | |
17 fi.read(result); | |
18 | |
19 print("DefineClass1 on "+name); | |
20 _recur++; | |
21 Class clazz = defineClass(name, result, 0, result.length); | |
22 _recur = old; | |
23 print("Returning newly loaded class."); | |
24 return clazz; | |
25 } catch (Exception e) { | |
26 _recur = old; | |
27 print("Not found on disk."); | |
28 // If we caught an exception, either the class was not found or | |
29 // it was unreadable by our process. | |
30 return null; | |
31 //throw new ClassNotFoundException(e.toString()); | |
32 } | |
33 } | |
34 | |
35 protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { | |
36 // Attempt a disk load first | |
37 Class c = findClass2(name); | |
38 if( c == null ) { | |
39 // check if the class has already been loaded | |
40 print("Checking for prior loaded class "+name); | |
41 c = findLoadedClass(name); | |
42 print("Letting super-loader load "+name); | |
43 int old = _recur; | |
44 _recur++; | |
45 c = super.loadClass(name, false); | |
46 _recur=old; | |
47 } | |
48 if (resolve) { print("Resolving class "+name); resolveClass(c); } | |
49 print("Returning clazz "+c.getClassLoader()+":"+name); | |
50 return c; | |
51 } | |
52 } |