< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.options/src/org/graalvm/compiler/options/OptionsParser.java

Print this page

        

*** 22,31 **** --- 22,34 ---- */ package org.graalvm.compiler.options; + import static jdk.vm.ci.services.Services.IS_BUILDING_NATIVE_IMAGE; + import static jdk.vm.ci.services.Services.IS_IN_NATIVE_IMAGE; + import java.util.ArrayList; import java.util.Collection; import java.util.Formatter; import java.util.List; import java.util.ServiceLoader;
*** 37,51 **** * This class contains methods for parsing Graal options and matching them against a set of * {@link OptionDescriptors}. The {@link OptionDescriptors} are loaded via a {@link ServiceLoader}. */ public class OptionsParser { /** ! * Gets an iterable composed of the {@link ServiceLoader}s to be used when looking for ! * {@link OptionDescriptors} providers. */ public static Iterable<OptionDescriptors> getOptionsLoader() { boolean java8OrEarlier = System.getProperty("java.specification.version").compareTo("1.9") < 0; ClassLoader loader; if (java8OrEarlier) { // On JDK 8, Graal and its extensions are loaded by same class loader. loader = OptionDescriptors.class.getClassLoader(); --- 40,58 ---- * This class contains methods for parsing Graal options and matching them against a set of * {@link OptionDescriptors}. The {@link OptionDescriptors} are loaded via a {@link ServiceLoader}. */ public class OptionsParser { + private static volatile List<OptionDescriptors> cachedOptionDescriptors; + /** ! * Gets an iterable of available {@link OptionDescriptors}. */ public static Iterable<OptionDescriptors> getOptionsLoader() { + if (IS_IN_NATIVE_IMAGE || cachedOptionDescriptors != null) { + return cachedOptionDescriptors; + } boolean java8OrEarlier = System.getProperty("java.specification.version").compareTo("1.9") < 0; ClassLoader loader; if (java8OrEarlier) { // On JDK 8, Graal and its extensions are loaded by same class loader. loader = OptionDescriptors.class.getClassLoader();
*** 56,66 **** * class loader. As such, we need to start the provider search at the app class loader * instead of the platform class loader. */ loader = ClassLoader.getSystemClassLoader(); } ! return ServiceLoader.load(OptionDescriptors.class, loader); } /** * Parses a map representing assignments of values to options. * --- 63,81 ---- * class loader. As such, we need to start the provider search at the app class loader * instead of the platform class loader. */ loader = ClassLoader.getSystemClassLoader(); } ! Iterable<OptionDescriptors> result = ServiceLoader.load(OptionDescriptors.class, loader); ! if (IS_BUILDING_NATIVE_IMAGE) { ! ArrayList<OptionDescriptors> optionDescriptors = new ArrayList<>(); ! for (OptionDescriptors descriptors : result) { ! optionDescriptors.add(descriptors); ! } ! OptionsParser.cachedOptionDescriptors = optionDescriptors; ! } ! return result; } /** * Parses a map representing assignments of values to options. *
*** 176,186 **** throw new IllegalArgumentException("Value for option '" + name + "' has invalid number format: " + valueString); } } } ! desc.optionKey.update(values, value); } private static long parseLong(String v) { String valueString = v.toLowerCase(); long scale = 1; --- 191,201 ---- throw new IllegalArgumentException("Value for option '" + name + "' has invalid number format: " + valueString); } } } ! desc.getOptionKey().update(values, value); } private static long parseLong(String v) { String valueString = v.toLowerCase(); long scale = 1;
< prev index next >