Skip to content

Commit a201be8

Browse files
committed
8361255: CTW: Tolerate more NCDFE problems
Reviewed-by: kvn, thartmann
1 parent db4b4a5 commit a201be8

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/Compiler.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import jdk.internal.reflect.ConstantPool;
2929
import jdk.test.whitebox.WhiteBox;
3030

31+
import java.lang.reflect.Constructor;
3132
import java.lang.reflect.Executable;
33+
import java.lang.reflect.Method;
3234
import java.util.Arrays;
3335
import java.util.Objects;
3436
import java.util.concurrent.Executor;
@@ -79,26 +81,53 @@ public static void compileClass(Class<?> aClass, long id, Executor executor) {
7981
preloadClasses(aClass.getName(), id, constantPool);
8082
}
8183

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+
}
8492
compileClinit(aClass, id);
8593

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+
86115
// Populate profile for all methods to expand the scope of
87116
// compiler optimizations. Do this before compilations start.
88-
for (Executable e : aClass.getDeclaredConstructors()) {
117+
for (Executable e : constructors) {
89118
WHITE_BOX.markMethodProfiled(e);
90119
}
91-
for (Executable e : aClass.getDeclaredMethods()) {
120+
for (Executable e : methods) {
92121
WHITE_BOX.markMethodProfiled(e);
93122
}
94123

95124
// Now schedule the compilations.
96125
long methodCount = 0;
97-
for (Executable e : aClass.getDeclaredConstructors()) {
126+
for (Executable e : constructors) {
98127
++methodCount;
99128
executor.execute(new CompileMethodCommand(id, e));
100129
}
101-
for (Executable e : aClass.getDeclaredMethods()) {
130+
for (Executable e : methods) {
102131
++methodCount;
103132
executor.execute(new CompileMethodCommand(id, e));
104133
}
@@ -127,9 +156,12 @@ private static void preloadClasses(String className, long id,
127156
if (constantPool.getTagAt(i) == ConstantPool.Tag.CLASS) {
128157
constantPool.getClassAt(i);
129158
}
159+
} catch (NoClassDefFoundError e) {
160+
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to preload : %s%n",
161+
id, className, e);
130162
} 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);
133165
t.printStackTrace(CompileTheWorld.ERR);
134166
}
135167
}

test/hotspot/jtreg/testlibrary/ctw/src/sun/hotspot/tools/ctw/PathHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,12 @@ protected final void processClass(String name, Executor executor) {
245245
CompileTheWorld.OUT.println(String.format("[%d]\t%s", id, name));
246246
aClass = entry.loader().loadClass(name);
247247
Compiler.compileClass(aClass, id, executor);
248+
} catch (NoClassDefFoundError e) {
249+
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to load/compile, skipped: %s%n",
250+
id, name, e);
248251
} catch (Throwable e) {
249-
CompileTheWorld.OUT.println(String.format("[%d]\t%s\tWARNING skipped: %s",
250-
id, name, e));
252+
CompileTheWorld.OUT.printf("[%d]\t%s\tWARNING skipped: %s%n",
253+
id, name, e);
251254
e.printStackTrace(CompileTheWorld.ERR);
252255
}
253256
}

0 commit comments

Comments
 (0)