Skip to content

Commit c5a5be6

Browse files
committed
fixed logic in CompilerConfigurationFactory.checkUnique
1 parent 2c7c747 commit c5a5be6

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/CompilerConfigurationFactory.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
*/
2525
package jdk.graal.compiler.hotspot;
2626

27-
import static jdk.vm.ci.common.InitTimer.timer;
2827
import static jdk.graal.compiler.core.common.LibGraalSupport.LIBGRAAL_SETTING_PROPERTY_PREFIX;
28+
import static jdk.vm.ci.common.InitTimer.timer;
2929

3030
import java.util.ArrayList;
3131
import java.util.Collections;
3232
import java.util.List;
3333
import java.util.function.Supplier;
3434
import java.util.stream.Collectors;
3535

36-
import jdk.graal.compiler.core.common.LibGraalSupport;
37-
import jdk.graal.compiler.serviceprovider.LibGraalService;
3836
import org.graalvm.collections.EconomicMap;
37+
3938
import jdk.graal.compiler.core.Instrumentation;
39+
import jdk.graal.compiler.core.common.LibGraalSupport;
4040
import jdk.graal.compiler.core.common.SuppressFBWarnings;
4141
import jdk.graal.compiler.core.common.util.PhasePlan;
4242
import jdk.graal.compiler.debug.GraalError;
@@ -50,7 +50,7 @@
5050
import jdk.graal.compiler.phases.tiers.CompilerConfiguration;
5151
import jdk.graal.compiler.serviceprovider.GlobalAtomicLong;
5252
import jdk.graal.compiler.serviceprovider.GraalServices;
53-
53+
import jdk.graal.compiler.serviceprovider.LibGraalService;
5454
import jdk.vm.ci.code.Architecture;
5555
import jdk.vm.ci.common.InitTimer;
5656
import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime;
@@ -93,7 +93,7 @@ public static class Options {
9393

9494
/**
9595
* The priority of this factory. This must be unique across all factory instances and is used
96-
* when selecting a factory when {@link Options#CompilerConfiguration} is omitted
96+
* when selecting a factory.
9797
*/
9898
private final int autoSelectionPriority;
9999

@@ -104,7 +104,8 @@ public static class Options {
104104
* {@link Options#CompilerConfiguration} option
105105
* @param info a higher level description of the configuration used for
106106
* {@link ShowConfigurationLevel#info}
107-
* @param autoSelectionPriority
107+
* @param autoSelectionPriority a priority which must be unique across all factory instances and
108+
* is used to select a factory
108109
*/
109110
protected CompilerConfigurationFactory(String name, String info, int autoSelectionPriority) {
110111
this.name = name;
@@ -174,23 +175,23 @@ public int compareTo(CompilerConfigurationFactory o) {
174175
}
175176

176177
/**
177-
* Asserts uniqueness of {@link #name} and {@link #autoSelectionPriority} for {@code factory} in
178-
* {@code factories}.
178+
* Checks uniqueness of {@link #autoSelectionPriority} for {@code factory} in {@code factories}.
179179
*/
180180
private static boolean checkUnique(CompilerConfigurationFactory factory, List<CompilerConfigurationFactory> factories) {
181181
for (CompilerConfigurationFactory other : factories) {
182-
if (other != factory && factory.autoSelectionPriority == other.autoSelectionPriority) {
183-
assert !other.name.equals(factory.name) : factory.getClass().getName() + " cannot have the same selector as " + other.getClass().getName() + ": " + factory.name;
184-
assert other.autoSelectionPriority != factory.autoSelectionPriority : factory.getClass().getName() + " cannot have the same auto-selection priority as " +
185-
other.getClass().getName() +
186-
": " + factory.autoSelectionPriority;
182+
if (other != factory) {
183+
GraalError.guarantee(other.autoSelectionPriority != factory.autoSelectionPriority, "%s cannot have the same auto-selection priority as %s: %s",
184+
factory.getClass().getName(),
185+
other.getClass().getName(),
186+
factory.autoSelectionPriority);
187187
}
188188
}
189189
return true;
190190
}
191191

192192
/**
193-
* @return sorted list of {@link CompilerConfigurationFactory}s
193+
* @return list of {@link CompilerConfigurationFactory}s sorted by {@linkplain #compareTo
194+
* decreasing auto-priority order}
194195
*/
195196
@SuppressFBWarnings(value = "DLS_DEAD_LOCAL_STORE", justification = "false positive on dead store to `candidates`")
196197
private static List<CompilerConfigurationFactory> getAllCandidates() {
@@ -229,6 +230,7 @@ public static CompilerConfigurationFactory selectFactory(String name, OptionValu
229230
} else if (value != null) {
230231
for (CompilerConfigurationFactory candidate : getAllCandidates()) {
231232
if (candidate.name.equals(value)) {
233+
// Selects highest priority candidate with specified name
232234
factory = candidate;
233235
break;
234236
}
@@ -242,7 +244,7 @@ public static CompilerConfigurationFactory selectFactory(String name, OptionValu
242244
if (candidates.isEmpty()) {
243245
throw new GraalError("No %s providers found", CompilerConfigurationFactory.class.getName());
244246
}
245-
factory = candidates.get(0);
247+
factory = candidates.getFirst();
246248
}
247249
}
248250
assert factory != null;

0 commit comments

Comments
 (0)