Skip to content

8361255: CTW: Tolerate more NCDFE problems #26090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import jdk.internal.reflect.ConstantPool;
import jdk.test.whitebox.WhiteBox;

import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Objects;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -79,26 +81,53 @@ public static void compileClass(Class<?> aClass, long id, Executor executor) {
preloadClasses(aClass.getName(), id, constantPool);
}

// Make sure the class is initialized.
UNSAFE.ensureClassInitialized(aClass);
// Attempt to initialize the class. If initialization is not possible
// due to NCDFE, accept this, and try compile anyway.
try {
UNSAFE.ensureClassInitialized(aClass);
} catch (NoClassDefFoundError e) {
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to init class : %s%n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean \n here and in all other outputs? %n needs local variable to store size of output.

Copy link
Member Author

@shipilev shipilev Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant %n :)

You are probably thinking about C printf? In Java formatters, %n is the "platform-specific line separator". It is more compatible than just \n, which runs into platform-specific CR vs LF vs CRLF line separator mess.

See:

jshell> System.out.printf("Hello\nthere,\nVladimir!\n")
Hello
there,
Vladimir!
$6 ==> java.io.PrintStream@34c45dca

jshell> System.out.printf("Hello%nthere,%nVladimir!%n")
Hello
there,
Vladimir!
$7 ==> java.io.PrintStream@34c45dca

id, aClass.getName(), e);
}
compileClinit(aClass, id);

// Getting constructor/methods with unresolvable signatures would fail with NCDFE.
// Try to get as much as possible, and compile everything else.
// TODO: Would be good to have a Whitebox method that returns the subset of resolvable
// constructors/methods without throwing NCDFE. This would extend the testing scope.
Constructor[] constructors = new Constructor[0];
Method[] methods = new Method[0];

try {
constructors = aClass.getDeclaredConstructors();
} catch (NoClassDefFoundError e) {
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to get constructors : %s%n",
id, aClass.getName(), e);
}

try {
methods = aClass.getDeclaredMethods();
} catch (NoClassDefFoundError e) {
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to get methods : %s%n",
id, aClass.getName(), e);
}

// Populate profile for all methods to expand the scope of
// compiler optimizations. Do this before compilations start.
for (Executable e : aClass.getDeclaredConstructors()) {
for (Executable e : constructors) {
WHITE_BOX.markMethodProfiled(e);
}
for (Executable e : aClass.getDeclaredMethods()) {
for (Executable e : methods) {
WHITE_BOX.markMethodProfiled(e);
}

// Now schedule the compilations.
long methodCount = 0;
for (Executable e : aClass.getDeclaredConstructors()) {
for (Executable e : constructors) {
++methodCount;
executor.execute(new CompileMethodCommand(id, e));
}
for (Executable e : aClass.getDeclaredMethods()) {
for (Executable e : methods) {
++methodCount;
executor.execute(new CompileMethodCommand(id, e));
}
Expand Down Expand Up @@ -127,9 +156,12 @@ private static void preloadClasses(String className, long id,
if (constantPool.getTagAt(i) == ConstantPool.Tag.CLASS) {
constantPool.getClassAt(i);
}
} catch (NoClassDefFoundError e) {
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to preload : %s%n",
id, className, e);
} catch (Throwable t) {
CompileTheWorld.OUT.println(String.format("[%d]\t%s\tWARNING preloading failed : %s",
id, className, t));
CompileTheWorld.OUT.printf("[%d]\t%s\tWARNING preloading failed : %s%n",
id, className, t);
t.printStackTrace(CompileTheWorld.ERR);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,12 @@ protected final void processClass(String name, Executor executor) {
CompileTheWorld.OUT.println(String.format("[%d]\t%s", id, name));
aClass = entry.loader().loadClass(name);
Compiler.compileClass(aClass, id, executor);
} catch (NoClassDefFoundError e) {
CompileTheWorld.OUT.printf("[%d]\t%s\tNOTE unable to load/compile, skipped: %s%n",
id, name, e);
} catch (Throwable e) {
CompileTheWorld.OUT.println(String.format("[%d]\t%s\tWARNING skipped: %s",
id, name, e));
CompileTheWorld.OUT.printf("[%d]\t%s\tWARNING skipped: %s%n",
id, name, e);
e.printStackTrace(CompileTheWorld.ERR);
}
}
Expand Down