Skip to content
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

Add opt-in link-at-build-time option to fail fast on NoClassDefFound #9856

Open
wants to merge 3 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 @@ -121,11 +121,13 @@ public void report(BigBang bb) {
printStream.close();

String unsupportedFeaturesMessage;
String output = outputStream.toString();
String detailedMessage = output.isEmpty() ? "" : "\nDetailed message:\n" + output;
if (singleEntry) {
unsupportedFeaturesMessage = entries.get(0).message + "\nDetailed message:\n" + outputStream.toString();
unsupportedFeaturesMessage = entries.get(0).message + detailedMessage;
throw new UnsupportedFeatureException(unsupportedFeaturesMessage, entries.get(0).originalException);
} else {
unsupportedFeaturesMessage = "Unsupported features in " + entries.size() + " methods" + "\nDetailed message:\n" + outputStream.toString();
unsupportedFeaturesMessage = "Unsupported features in " + entries.size() + " methods" + detailedMessage;
throw new UnsupportedFeatureException(unsupportedFeaturesMessage);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -51,6 +51,11 @@ static final class Options {
@APIOption(name = "link-at-build-time-paths")//
@Option(help = "file:doc-files/LinkAtBuildTimePathsHelp.txt")//
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> LinkAtBuildTimePaths = new HostedOptionKey<>(AccumulatingLocatableMultiOptionValue.Strings.build());

// FIXME: Remove once we have a proper way to handle missing classes through JVMCI (see
// https://github.com/oracle/graal/issues/6253)
@Option(help = "Fail fast in case of missing classes when linking at build time.") //
public static final HostedOptionKey<Boolean> LinkAtBuildTimeFailFast = new HostedOptionKey<>(false);
}

private final ClassLoaderSupport classLoaderSupport;
Expand Down Expand Up @@ -118,4 +123,8 @@ private String linkAtBuildTimeReason(Class<?> clazz) {
Set<OptionOrigin> origins = (Set<OptionOrigin>) reason;
return origins.stream().map(OptionOrigin::toString).collect(Collectors.joining(" and "));
}

public static boolean failFast() {
return Options.LinkAtBuildTimeFailFast.getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,10 @@ private static void reportUserException(Throwable e, OptionValues parsedHostedOp
} else {
reportUserError(e.getMessage());
}
Throwable current = e.getCause();
while (current != null) {
Throwable cause = e.getCause();
if (cause != null) {
System.out.print("Caused by: ");
current.printStackTrace(System.out);
current = current.getCause();
cause.printStackTrace(System.out);
}
if (parsedHostedOptions != null && NativeImageOptions.ReportExceptionStackTraces.getValue(parsedHostedOptions)) {
System.out.print("Internal exception: ");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -288,7 +288,12 @@ protected void maybeEagerlyResolve(int cpi, int bytecode) {
try {
super.maybeEagerlyResolve(cpi, bytecode);
} catch (UnresolvedElementException e) {
if (e.getCause() instanceof LambdaConversionException || e.getCause() instanceof LinkageError || e.getCause() instanceof IllegalAccessError) {
Throwable cause = e.getCause();
if (cause instanceof NoClassDefFoundError && linkAtBuildTime && LinkAtBuildTimeSupport.failFast()) {
String message = "Error during parsing of method " + method.format("%H.%n(%P)") + ". " +
LinkAtBuildTimeSupport.singleton().errorMessageFor(method.getDeclaringClass());
throw new UnresolvedElementException(message, cause);
} else if (cause instanceof LambdaConversionException || cause instanceof LinkageError) {
/*
* Ignore LinkageError, LambdaConversionException or IllegalAccessError if
* thrown from eager resolution attempt. This is usually followed by a call to
Expand Down Expand Up @@ -1084,7 +1089,7 @@ private Object loadConstantDynamic(int cpi, int opcode) {
* Therefore, we cannot just treat it as "safe at build time". The class
* initialization is also completely useless because the invoking class must be
* already initialized by the time the boostrap method is executed.
*
*
* We replicate the implementation of the bootstrap method here without doing
* the class initialization.
*/
Expand Down
Loading