|
28 | 28 | import jdk.internal.reflect.ConstantPool;
|
29 | 29 | import jdk.test.whitebox.WhiteBox;
|
30 | 30 |
|
| 31 | +import java.lang.reflect.Constructor; |
31 | 32 | import java.lang.reflect.Executable;
|
| 33 | +import java.lang.reflect.Method; |
32 | 34 | import java.util.Arrays;
|
33 | 35 | import java.util.Objects;
|
34 | 36 | import java.util.concurrent.Executor;
|
@@ -79,26 +81,53 @@ public static void compileClass(Class<?> aClass, long id, Executor executor) {
|
79 | 81 | preloadClasses(aClass.getName(), id, constantPool);
|
80 | 82 | }
|
81 | 83 |
|
82 |
| - // Make sure the class is initialized. |
83 |
| - UNSAFE.ensureClassInitialized(aClass); |
| 84 | + // Attempt to initialize the class. If initialization is not possible |
| 85 | + // due to NCDFE, accept this, and try compile anyway. |
| 86 | + try { |
| 87 | + UNSAFE.ensureClassInitialized(aClass); |
| 88 | + } catch (NoClassDefFoundError e) { |
| 89 | + CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to init class : %s%n", |
| 90 | + id, aClass.getName(), e); |
| 91 | + } |
84 | 92 | compileClinit(aClass, id);
|
85 | 93 |
|
| 94 | + // Getting constructor/methods with unresolvable signatures would fail with NCDFE. |
| 95 | + // Try to get as much as possible, and compile everything else. |
| 96 | + // TODO: Would be good to have a Whitebox method that returns the subset of resolvable |
| 97 | + // constructors/methods without throwing NCDFE. This would extend the testing scope. |
| 98 | + Constructor[] constructors = new Constructor[0]; |
| 99 | + Method[] methods = new Method[0]; |
| 100 | + |
| 101 | + try { |
| 102 | + constructors = aClass.getDeclaredConstructors(); |
| 103 | + } catch (NoClassDefFoundError e) { |
| 104 | + CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to get constructors : %s%n", |
| 105 | + id, aClass.getName(), e); |
| 106 | + } |
| 107 | + |
| 108 | + try { |
| 109 | + methods = aClass.getDeclaredMethods(); |
| 110 | + } catch (NoClassDefFoundError e) { |
| 111 | + CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to get methods : %s%n", |
| 112 | + id, aClass.getName(), e); |
| 113 | + } |
| 114 | + |
86 | 115 | // Populate profile for all methods to expand the scope of
|
87 | 116 | // compiler optimizations. Do this before compilations start.
|
88 |
| - for (Executable e : aClass.getDeclaredConstructors()) { |
| 117 | + for (Executable e : constructors) { |
89 | 118 | WHITE_BOX.markMethodProfiled(e);
|
90 | 119 | }
|
91 |
| - for (Executable e : aClass.getDeclaredMethods()) { |
| 120 | + for (Executable e : methods) { |
92 | 121 | WHITE_BOX.markMethodProfiled(e);
|
93 | 122 | }
|
94 | 123 |
|
95 | 124 | // Now schedule the compilations.
|
96 | 125 | long methodCount = 0;
|
97 |
| - for (Executable e : aClass.getDeclaredConstructors()) { |
| 126 | + for (Executable e : constructors) { |
98 | 127 | ++methodCount;
|
99 | 128 | executor.execute(new CompileMethodCommand(id, e));
|
100 | 129 | }
|
101 |
| - for (Executable e : aClass.getDeclaredMethods()) { |
| 130 | + for (Executable e : methods) { |
102 | 131 | ++methodCount;
|
103 | 132 | executor.execute(new CompileMethodCommand(id, e));
|
104 | 133 | }
|
@@ -127,9 +156,12 @@ private static void preloadClasses(String className, long id,
|
127 | 156 | if (constantPool.getTagAt(i) == ConstantPool.Tag.CLASS) {
|
128 | 157 | constantPool.getClassAt(i);
|
129 | 158 | }
|
| 159 | + } catch (NoClassDefFoundError e) { |
| 160 | + CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to preload : %s%n", |
| 161 | + id, className, e); |
130 | 162 | } catch (Throwable t) {
|
131 |
| - CompileTheWorld.OUT.println(String.format("[%d]\t%s\tWARNING preloading failed : %s", |
132 |
| - id, className, t)); |
| 163 | + CompileTheWorld.OUT.printf("[%d]\t%s\tWARNING preloading failed : %s%n", |
| 164 | + id, className, t); |
133 | 165 | t.printStackTrace(CompileTheWorld.ERR);
|
134 | 166 | }
|
135 | 167 | }
|
|
0 commit comments