Skip to content

Commit

Permalink
make OptionsParser#libgraalOptions final
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Jan 13, 2025
1 parent bbe9880 commit 46bf4bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,11 @@ public void duringSetup(DuringSetupAccess access) {
* Collects all instances of the LibGraalLoader loaded {@link OptionKey} class reached by the
* static analysis.
*/
private class OptionCollector implements Consumer<OptionKey<?>> {
private final class OptionCollector implements Consumer<OptionKey<?>> {
private final Set<OptionKey<?>> options = Collections.newSetFromMap(new ConcurrentHashMap<>());

/**
* Libgraal compiler options info.
*/
private final OptionsParser.LibGraalOptionsInfo compilerOptionsInfo;

private boolean sealed;

OptionCollector() {
compilerOptionsInfo = OptionsParser.setLibgraalOptions(OptionsParser.LibGraalOptionsInfo.create());
}

@Override
public void accept(OptionKey<?> option) {
if (sealed) {
Expand All @@ -221,11 +212,11 @@ void afterAnalysis(AfterAnalysisAccess access) {
GraalError.guarantee(access.isReachable(descriptor.getClass()), "%s", descriptor.getClass());

String name = option.getName();
compilerOptionsInfo.descriptors().put(name, descriptor);
OptionsParser.libgraalOptions.descriptors().put(name, descriptor);

String module = modules.get(descriptor.getDeclaringClass().getName());
if (module.contains("enterprise")) {
compilerOptionsInfo.enterpriseOptions().add(name);
OptionsParser.libgraalOptions.enterpriseOptions().add(name);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.Set;
import java.util.regex.Pattern;

import jdk.graal.compiler.debug.GraalError;
import jdk.graal.nativeimage.LibGraalLoader;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.MapCursor;
Expand Down Expand Up @@ -68,7 +68,7 @@ public static LibGraalOptionsInfo create() {
* Compiler options info available in libgraal. This field is only non-null when
* {@link OptionsParser} is loaded by a {@link jdk.graal.nativeimage.LibGraalLoader}.
*/
private static LibGraalOptionsInfo libgraalOptions;
public static final LibGraalOptionsInfo libgraalOptions = OptionsParser.class.getClassLoader() instanceof LibGraalLoader ? LibGraalOptionsInfo.create() : null;

/**
* Gets an iterable of available {@link OptionDescriptors}.
Expand Down Expand Up @@ -97,14 +97,6 @@ public static Iterable<OptionDescriptors> getOptionsLoader() {
}
}

@ExcludeFromJacocoGeneratedReport("only called when building libgraal")
public static LibGraalOptionsInfo setLibgraalOptions(LibGraalOptionsInfo info) {
GraalError.guarantee(inImageBuildtimeCode(), "Can only set libgraal compiler options when building libgraal");
GraalError.guarantee(libgraalOptions == null, "Libgraal compiler options must be set exactly once");
OptionsParser.libgraalOptions = info;
return info;
}

/**
* Parses a map representing assignments of values to options.
*
Expand Down

0 comments on commit 46bf4bb

Please sign in to comment.