From f88ec09898b463796c6dbec58cca88024480e99a Mon Sep 17 00:00:00 2001 From: David Kozak Date: Wed, 17 Mar 2021 09:09:00 +0100 Subject: [PATCH] Localization: move each substitution into its own file --- .../CharsetSubstitutionsFeature.java | 39 ++++ .../jdk/localization/LocalizationFeature.java | 4 +- .../substitutions/DefaultLocaleComputer.java | 38 ++++ .../substitutions/LocaleSubstitutions.java | 189 ------------------ .../OptimizedModeOnlySubstitutions.java | 146 -------------- ...a => Target_java_nio_charset_Charset.java} | 35 +--- .../Target_java_text_BreakIterator.java | 66 ++++++ .../Target_java_text_DateFormatSymbols.java | 39 ++++ ...stResourceBundle_SubstituteLoadLookup.java | 49 +++++ .../Target_java_util_Locale.java | 54 +++++ ...a => Target_java_util_ResourceBundle.java} | 133 ++---------- ...rget_java_util_ResourceBundle_Control.java | 48 +++++ ...leProviderAdapter_OptimizedLocaleMode.java | 34 ++++ ...ale_provider_JRELocaleProviderAdapter.java | 78 ++++++++ ...leProviderAdapter_OptimizedLocaleMode.java | 67 +++++++ ..._util_locale_provider_LocaleResources.java | 46 +++++ ...caleServiceProviderPool_JvmLocaleMode.java | 47 +++++ ...rviceProviderPool_OptimizedLocaleMode.java | 109 ++++++++++ ...l_locale_provider_TimeZoneNameUtility.java | 44 ++++ ...stResourceBundle_SubstituteLoadLookup.java | 60 ++++++ ...stResourceBundle_SubstituteLoadLookup.java | 69 +++++++ 21 files changed, 911 insertions(+), 483 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/CharsetSubstitutionsFeature.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/DefaultLocaleComputer.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/LocaleSubstitutions.java delete mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/OptimizedModeOnlySubstitutions.java rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/{CharsetSubstitutions.java => Target_java_nio_charset_Charset.java} (81%) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_BreakIterator.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_DateFormatSymbols.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ListResourceBundle_SubstituteLoadLookup.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java rename substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/{ResourceBundleSubstitutions.java => Target_java_util_ResourceBundle.java} (53%) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle_Control.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_AuxLocaleProviderAdapter_OptimizedLocaleMode.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_JRELocaleProviderAdapter.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleProviderAdapter_OptimizedLocaleMode.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleResources.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_JvmLocaleMode.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_TimeZoneNameUtility.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_OpenListResourceBundle_SubstituteLoadLookup.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_ParallelListResourceBundle_SubstituteLoadLookup.java diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/CharsetSubstitutionsFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/CharsetSubstitutionsFeature.java new file mode 100644 index 000000000000..0588c0864ad1 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/CharsetSubstitutionsFeature.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization; + +import com.oracle.svm.core.annotate.AutomaticFeature; +import com.oracle.svm.core.configure.ResourcesRegistry; +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.hosted.Feature; + +@AutomaticFeature +class CharsetSubstitutionsFeature implements Feature { + @Override + public void beforeAnalysis(BeforeAnalysisAccess access) { + Class clazz = access.findClassByName("java.lang.CharacterName"); + access.registerReachabilityHandler(a -> ImageSingletons.lookup(ResourcesRegistry.class).addResources("java/lang/uniName.dat"), clazz); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationFeature.java index 8cda220ae285..6dc2c6cbce99 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/LocalizationFeature.java @@ -53,7 +53,7 @@ import java.util.spi.TimeZoneNameProvider; import com.oracle.svm.core.jdk.localization.compression.GzipBundleCompression; -import com.oracle.svm.core.jdk.localization.substitutions.OptimizedModeOnlySubstitutions; +import com.oracle.svm.core.jdk.localization.substitutions.Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode; import org.graalvm.collections.Pair; import org.graalvm.compiler.nodes.ValueNode; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; @@ -361,7 +361,7 @@ private void addProviders() { for (Class providerClass : getSpiClasses()) { LocaleProviderAdapter adapter = Objects.requireNonNull(LocaleProviderAdapter.getAdapter(providerClass, defaultLocale)); LocaleServiceProvider provider = Objects.requireNonNull(adapter.getLocaleServiceProvider(providerClass)); - optimizedLocalizationSupport.providerPools.put(providerClass, new OptimizedModeOnlySubstitutions.Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode(provider)); + optimizedLocalizationSupport.providerPools.put(providerClass, new Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode(provider)); } for (Locale locale : allLocales) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/DefaultLocaleComputer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/DefaultLocaleComputer.java new file mode 100644 index 000000000000..82f1c1ccf252 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/DefaultLocaleComputer.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import jdk.vm.ci.meta.MetaAccessProvider; +import jdk.vm.ci.meta.ResolvedJavaField; +import org.graalvm.nativeimage.ImageSingletons; + +final class DefaultLocaleComputer implements RecomputeFieldValue.CustomFieldValueComputer { + @Override + public Object compute(MetaAccessProvider metaAccess, ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) { + return ImageSingletons.lookup(LocalizationSupport.class).defaultLocale; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/LocaleSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/LocaleSubstitutions.java deleted file mode 100644 index dcaf5f0b7d96..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/LocaleSubstitutions.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2013, 2017, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk.localization.substitutions; - -import java.lang.ref.ReferenceQueue; -import java.lang.ref.SoftReference; -import java.text.BreakIterator; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import org.graalvm.nativeimage.ImageSingletons; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK8OrEarlier; -import com.oracle.svm.core.jdk.localization.LocalizationSupport; -import com.oracle.svm.core.jdk.localization.substitutions.modes.JvmLocaleMode; -import com.oracle.svm.core.util.VMError; - -//Checkstyle: allow reflection - -import jdk.vm.ci.meta.MetaAccessProvider; -import jdk.vm.ci.meta.ResolvedJavaField; -import sun.util.locale.provider.JRELocaleProviderAdapter; -import sun.util.locale.provider.LocaleResources; - -@TargetClass(java.util.Locale.class) -final class Target_java_util_Locale { - - @Alias @RecomputeFieldValue(kind = Kind.Custom, declClass = DefaultLocaleComputer.class) // - private static Locale defaultLocale; - @Alias @RecomputeFieldValue(kind = Kind.Custom, declClass = DefaultLocaleComputer.class) // - private static Locale defaultDisplayLocale; - @Alias @RecomputeFieldValue(kind = Kind.Custom, declClass = DefaultLocaleComputer.class) // - private static Locale defaultFormatLocale; - - @Substitute - private static Object initDefault() { - throw VMError.unsupportedFeature("The default Locale must be initialized during image generation"); - } - - @Substitute - private static Object initDefault(Locale.Category category) { - throw VMError.unsupportedFeature("The default Locale must be initialized during image generation: " + category); - } -} - -final class DefaultLocaleComputer implements RecomputeFieldValue.CustomFieldValueComputer { - @Override - public Object compute(MetaAccessProvider metaAccess, ResolvedJavaField original, ResolvedJavaField annotated, Object receiver) { - return ImageSingletons.lookup(LocalizationSupport.class).defaultLocale; - } -} - -@TargetClass(sun.util.locale.provider.TimeZoneNameUtility.class) -final class Target_sun_util_locale_provider_TimeZoneNameUtility { - - @Alias @RecomputeFieldValue(kind = Kind.FromAlias)// - static ConcurrentHashMap> cachedZoneData = new ConcurrentHashMap<>(); - - @Alias @RecomputeFieldValue(kind = Kind.FromAlias)// - static Map>> cachedDisplayNames = new ConcurrentHashMap<>(); -} - -@TargetClass(java.text.BreakIterator.class) -final class Target_java_text_BreakIterator { - - @Substitute - private static BreakIterator getWordInstance(Locale locale) { - assert locale == Locale.getDefault(); - return (BreakIterator) Util_java_text_BreakIterator.WORD_INSTANCE.clone(); - } - - @Substitute - private static BreakIterator getLineInstance(Locale locale) { - assert locale == Locale.getDefault(); - return (BreakIterator) Util_java_text_BreakIterator.LINE_INSTANCE.clone(); - } - - @Substitute - private static BreakIterator getCharacterInstance(Locale locale) { - assert locale == Locale.getDefault(); - return (BreakIterator) Util_java_text_BreakIterator.CHARACTER_INSTANCE.clone(); - } - - @Substitute - private static BreakIterator getSentenceInstance(Locale locale) { - assert locale == Locale.getDefault(); - return (BreakIterator) Util_java_text_BreakIterator.SENTENCE_INSTANCE.clone(); - } -} - -@TargetClass(LocaleResources.class) -final class Target_sun_util_locale_provider_LocaleResources { - @RecomputeFieldValue(kind = Kind.NewInstance, declClass = ConcurrentHashMap.class)// - @Alias// - private ConcurrentMap cache; - @RecomputeFieldValue(kind = Kind.NewInstance, declClass = ReferenceQueue.class)// - @Alias// - private ReferenceQueue referenceQueue; -} - -@TargetClass(JRELocaleProviderAdapter.class) -final class Target_sun_util_locale_provider_JRELocaleProviderAdapter { - @RecomputeFieldValue(kind = Kind.NewInstance, declClass = ConcurrentHashMap.class)// - @Alias// - private ConcurrentMap> langtagSets; - - @RecomputeFieldValue(kind = Kind.NewInstance, declClass = ConcurrentHashMap.class)// - @Alias// - private ConcurrentMap localeResourcesMap; - - @Alias // - @TargetElement(onlyWith = JDK8OrEarlier.class) // - static Boolean isNonENSupported; - - @Substitute // - @TargetElement(onlyWith = JDK8OrEarlier.class) // - private static boolean isNonENLangSupported() { - /* - * The original implementation performs lazily initialization that looks at the file system - * (a certain .jar file being present). That cannot work in a native image, and even worse - * it makes file access methods reachable in very basic images. - */ - VMError.guarantee(isNonENSupported != null, "isNonENSupported must be initialized during image generation"); - return isNonENSupported; - } - - @Substitute - @SuppressWarnings({"unused", "static-method"}) - protected Set createLanguageTagSet(String category) { - return ImageSingletons.lookup(LocalizationSupport.class).supportedLanguageTags; - } -} - -final class Util_java_text_BreakIterator { - static final BreakIterator WORD_INSTANCE = BreakIterator.getWordInstance(); - static final BreakIterator LINE_INSTANCE = BreakIterator.getLineInstance(); - static final BreakIterator CHARACTER_INSTANCE = BreakIterator.getCharacterInstance(); - static final BreakIterator SENTENCE_INSTANCE = BreakIterator.getSentenceInstance(); -} - -@SuppressWarnings({"static-method"}) -@TargetClass(value = sun.util.locale.provider.LocaleServiceProviderPool.class, onlyWith = JvmLocaleMode.class) -final class Target_sun_util_locale_provider_LocaleServiceProviderPool_JvmLocaleMode { - @Substitute - private static Locale[] getAllAvailableLocales() { - return ImageSingletons.lookup(LocalizationSupport.class).allLocales; - } - - @Substitute - private Locale[] getAvailableLocales() { - return ImageSingletons.lookup(LocalizationSupport.class).allLocales; - } -} - -/** Dummy class to have a class with the file's name. */ -public final class LocaleSubstitutions { - -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/OptimizedModeOnlySubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/OptimizedModeOnlySubstitutions.java deleted file mode 100644 index ba059fa2ee46..000000000000 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/OptimizedModeOnlySubstitutions.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2021, 2021, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.svm.core.jdk.localization.substitutions; - -import com.oracle.svm.core.annotate.Delete; -import com.oracle.svm.core.annotate.KeepOriginal; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.jdk.JDK11OrLater; -import com.oracle.svm.core.jdk.JDK11To14; -import com.oracle.svm.core.jdk.JDK8OrEarlier; -import com.oracle.svm.core.jdk.localization.LocalizationSupport; -import com.oracle.svm.core.jdk.localization.OptimizedLocalizationSupport; -import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; -import com.oracle.svm.core.util.VMError; -import org.graalvm.collections.Pair; -import org.graalvm.nativeimage.ImageSingletons; - -// Checkstyle: stop -import sun.util.locale.provider.LocaleProviderAdapter; -import sun.util.locale.provider.LocaleServiceProviderPool; -// Checkstyle: resume - -import java.util.Locale; -import java.util.spi.LocaleServiceProvider; - -public class OptimizedModeOnlySubstitutions { - @TargetClass(value = sun.util.locale.provider.LocaleProviderAdapter.class, onlyWith = OptimizedLocaleMode.class) - static final class Target_sun_util_locale_provider_LocaleProviderAdapter_OptimizedLocaleMode { - - @Substitute - @SuppressWarnings({"unused"}) - public static LocaleProviderAdapter getAdapter(Class providerClass, Locale locale) { - OptimizedLocalizationSupport support = ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport(); - for (Locale candidateLocale : support.control.getCandidateLocales("", locale)) { - LocaleProviderAdapter result = support.adaptersByClass.get(Pair.create(providerClass, candidateLocale)); - if (result != null) { - return result; - } - } - throw VMError.unsupportedFeature("LocaleProviderAdapter.getAdapter: providerClass: " + providerClass.getName() + ", locale: " + locale); - } - - @Substitute - public static LocaleProviderAdapter forType(LocaleProviderAdapter.Type type) { - final LocaleProviderAdapter result = ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().adaptersByType.get(type); - if (result != null) { - return result; - } - throw VMError.unsupportedFeature("LocaleProviderAdapter.forType: type: " + type.toString()); - } - } - - @Substitute - @TargetClass(value = sun.util.locale.provider.LocaleServiceProviderPool.class, onlyWith = OptimizedLocaleMode.class) - @SuppressWarnings({"static-method"}) - public static final class Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode { - - private final LocaleServiceProvider cachedProvider; - - public Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode(LocaleServiceProvider cachedProvider) { - this.cachedProvider = cachedProvider; - } - - @Substitute - private static LocaleServiceProviderPool getPool(Class providerClass) { - LocaleServiceProviderPool result = (LocaleServiceProviderPool) ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().providerPools.get(providerClass); - if (result == null) { - throw VMError.unsupportedFeature("LocaleServiceProviderPool.getPool " + providerClass.getName()); - } - return result; - } - - @Substitute - @TargetElement(onlyWith = JDK8OrEarlier.class) - private boolean hasProviders() { - return false; - } - - @KeepOriginal - private native

S getLocalizedObject(LocaleServiceProviderPool.LocalizedObjectGetter getter, Locale locale, Object... params); - - @KeepOriginal - private native

S getLocalizedObject(LocaleServiceProviderPool.LocalizedObjectGetter getter, Locale locale, String key, Object... params); - - @SuppressWarnings({"unused", "unchecked"}) - @Substitute - private

S getLocalizedObjectImpl(LocaleServiceProviderPool.LocalizedObjectGetter getter, Locale locale, boolean isObjectProvider, String key, - Object... params) { - if (locale == null) { - throw new NullPointerException(); - } - return getter.getObject((P) cachedProvider, locale, key, params); - } - - @KeepOriginal // - @TargetElement(onlyWith = JDK11OrLater.class) // - public native

S getLocalizedObject(LocaleServiceProviderPool.LocalizedObjectGetter getter, - Locale locale, - Boolean isObjectProvider, - String key, - Object... params); - - @KeepOriginal // - @TargetElement(onlyWith = JDK11To14.class) // - static native void config(Class caller, String message); - - @Substitute - private static Locale[] getAllAvailableLocales() { - return ImageSingletons.lookup(LocalizationSupport.class).allLocales; - } - - @Substitute - private Locale[] getAvailableLocales() { - return ImageSingletons.lookup(LocalizationSupport.class).allLocales; - } - } - - @Delete - @TargetClass(value = sun.util.locale.provider.AuxLocaleProviderAdapter.class, onlyWith = OptimizedLocaleMode.class) - static final class Target_sun_util_locale_provider_AuxLocaleProviderAdapter_OptimizedLocaleMode { - } -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/CharsetSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java similarity index 81% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/CharsetSubstitutions.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java index c18d5fb68af7..1f3b52c8ddbd 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/CharsetSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_nio_charset_Charset.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2021, 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 @@ -24,7 +24,13 @@ */ package com.oracle.svm.core.jdk.localization.substitutions; -// Checkstyle: allow reflection +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK8OrEarlier; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import org.graalvm.nativeimage.ImageSingletons; import java.nio.charset.Charset; import java.util.Collections; @@ -32,18 +38,6 @@ import java.util.SortedMap; import java.util.TreeMap; -import com.oracle.svm.core.jdk.JDK8OrEarlier; -import com.oracle.svm.core.jdk.localization.LocalizationSupport; -import org.graalvm.nativeimage.ImageSingletons; -import org.graalvm.nativeimage.hosted.Feature; - -import com.oracle.svm.core.annotate.Alias; -import com.oracle.svm.core.annotate.AutomaticFeature; -import com.oracle.svm.core.annotate.Substitute; -import com.oracle.svm.core.annotate.TargetClass; -import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.configure.ResourcesRegistry; - @TargetClass(java.nio.charset.Charset.class) @SuppressWarnings({"unused"}) final class Target_java_nio_charset_Charset { @@ -94,16 +88,3 @@ private static boolean atBugLevel(String bl) { return false; } } - -@AutomaticFeature -class CharsetSubstitutionsFeature implements Feature { - @Override - public void beforeAnalysis(BeforeAnalysisAccess access) { - Class clazz = access.findClassByName("java.lang.CharacterName"); - access.registerReachabilityHandler(a -> ImageSingletons.lookup(ResourcesRegistry.class).addResources("java/lang/uniName.dat"), clazz); - } -} - -/** Dummy class to have a class with the file's name. */ -public final class CharsetSubstitutions { -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_BreakIterator.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_BreakIterator.java new file mode 100644 index 000000000000..ad03b611ecf6 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_BreakIterator.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +import java.text.BreakIterator; +import java.util.Locale; + +@TargetClass(java.text.BreakIterator.class) +final class Target_java_text_BreakIterator { + + @Substitute + private static BreakIterator getWordInstance(Locale locale) { + assert locale == Locale.getDefault(); + return (BreakIterator) Util_java_text_BreakIterator.WORD_INSTANCE.clone(); + } + + @Substitute + private static BreakIterator getLineInstance(Locale locale) { + assert locale == Locale.getDefault(); + return (BreakIterator) Util_java_text_BreakIterator.LINE_INSTANCE.clone(); + } + + @Substitute + private static BreakIterator getCharacterInstance(Locale locale) { + assert locale == Locale.getDefault(); + return (BreakIterator) Util_java_text_BreakIterator.CHARACTER_INSTANCE.clone(); + } + + @Substitute + private static BreakIterator getSentenceInstance(Locale locale) { + assert locale == Locale.getDefault(); + return (BreakIterator) Util_java_text_BreakIterator.SENTENCE_INSTANCE.clone(); + } +} + +final class Util_java_text_BreakIterator { + static final BreakIterator WORD_INSTANCE = BreakIterator.getWordInstance(); + static final BreakIterator LINE_INSTANCE = BreakIterator.getLineInstance(); + static final BreakIterator CHARACTER_INSTANCE = BreakIterator.getCharacterInstance(); + static final BreakIterator SENTENCE_INSTANCE = BreakIterator.getSentenceInstance(); +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_DateFormatSymbols.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_DateFormatSymbols.java new file mode 100644 index 000000000000..8c9dc7845641 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_text_DateFormatSymbols.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +@TargetClass(java.text.DateFormatSymbols.class) +final class Target_java_text_DateFormatSymbols { + + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias) // + private static ConcurrentMap cachedInstances = new ConcurrentHashMap<>(3); +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ListResourceBundle_SubstituteLoadLookup.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ListResourceBundle_SubstituteLoadLookup.java new file mode 100644 index 000000000000..dae672175d86 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ListResourceBundle_SubstituteLoadLookup.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.SubstituteLoadLookup; +import org.graalvm.nativeimage.ImageSingletons; + +import java.util.Map; + +@TargetClass(value = java.util.ListResourceBundle.class, onlyWith = SubstituteLoadLookup.class) +@SuppressWarnings({"static-method"}) +final class Target_java_util_ListResourceBundle_SubstituteLoadLookup { + + @Alias private volatile Map lookup; + + @Substitute + private void loadLookup() { + if (lookup != null) { + return; + } + lookup = ImageSingletons.lookup(LocalizationSupport.class).getBundleContentOf(getClass()); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java new file mode 100644 index 000000000000..dbce4ce5bd7b --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.util.VMError; + +import java.util.Locale; + +@TargetClass(java.util.Locale.class) +final class Target_java_util_Locale { + + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = DefaultLocaleComputer.class) // + private static Locale defaultLocale; + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = DefaultLocaleComputer.class) // + private static Locale defaultDisplayLocale; + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Custom, declClass = DefaultLocaleComputer.class) // + private static Locale defaultFormatLocale; + + @Substitute + private static Object initDefault() { + throw VMError.unsupportedFeature("The default Locale must be initialized during image generation"); + } + + @Substitute + private static Object initDefault(Locale.Category category) { + throw VMError.unsupportedFeature("The default Locale must be initialized during image generation: " + category); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/ResourceBundleSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java similarity index 53% rename from substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/ResourceBundleSubstitutions.java rename to substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java index 408725588d22..e1119e6e7f90 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/ResourceBundleSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2021, 2021, 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 @@ -24,38 +24,27 @@ */ package com.oracle.svm.core.jdk.localization.substitutions; -//Checkstyle: allow reflection -//Checkstyle: allow synchronization - -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; -import java.util.ResourceBundle.Control; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -import com.oracle.svm.core.jdk.JDK11OrLater; -import com.oracle.svm.core.jdk.Target_java_lang_Module; -import com.oracle.svm.core.jdk.localization.LocalizationSupport; -import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; -import com.oracle.svm.core.jdk.localization.substitutions.modes.SubstituteLoadLookup; -import org.graalvm.nativeimage.ImageSingletons; - import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.RecomputeFieldValue; -import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; import com.oracle.svm.core.annotate.TargetElement; -import com.oracle.svm.core.util.VMError; +import com.oracle.svm.core.jdk.JDK11OrLater; +import com.oracle.svm.core.jdk.Target_java_lang_Module; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; +import org.graalvm.nativeimage.ImageSingletons; -import sun.util.resources.OpenListResourceBundle; +import java.util.Locale; +import java.util.ResourceBundle; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; @TargetClass(java.util.ResourceBundle.class) @SuppressWarnings({"unused"}) final class Target_java_util_ResourceBundle { - @Alias @RecomputeFieldValue(kind = Kind.FromAlias)// + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)// private static ConcurrentMap cacheList = new ConcurrentHashMap<>(); @TargetElement(onlyWith = OptimizedLocaleMode.class) @@ -66,7 +55,7 @@ private static ResourceBundle getBundle(String baseName) { @TargetElement(onlyWith = OptimizedLocaleMode.class) @Substitute - private static ResourceBundle getBundle(String baseName, Control control) { + private static ResourceBundle getBundle(String baseName, ResourceBundle.Control control) { return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, Locale.getDefault()); } @@ -78,7 +67,7 @@ private static ResourceBundle getBundle(String baseName, Locale locale) { @TargetElement(onlyWith = OptimizedLocaleMode.class) @Substitute - private static ResourceBundle getBundle(String baseName, Locale targetLocale, Control control) { + private static ResourceBundle getBundle(String baseName, Locale targetLocale, ResourceBundle.Control control) { return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, targetLocale); } @@ -90,7 +79,7 @@ private static ResourceBundle getBundle(String baseName, Locale locale, ClassLoa @TargetElement(onlyWith = OptimizedLocaleMode.class) @Substitute - private static ResourceBundle getBundle(String baseName, Locale targetLocale, ClassLoader loader, Control control) { + private static ResourceBundle getBundle(String baseName, Locale targetLocale, ClassLoader loader, ResourceBundle.Control control) { return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, targetLocale); } @@ -111,97 +100,3 @@ private static ResourceBundle getBundle(String baseName, Locale targetLocale, Ta return ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().getCached(baseName, targetLocale); } } - -@TargetClass(value = java.util.ListResourceBundle.class, onlyWith = SubstituteLoadLookup.class) -@SuppressWarnings({"static-method"}) -final class Target_java_util_ListResourceBundle_SubstituteLoadLookup { - - @Alias private volatile Map lookup; - - @Substitute - private void loadLookup() { - if (lookup != null) { - return; - } - lookup = ImageSingletons.lookup(LocalizationSupport.class).getBundleContentOf(getClass()); - } -} - -@TargetClass(value = sun.util.resources.OpenListResourceBundle.class, onlyWith = SubstituteLoadLookup.class) -@SuppressWarnings({"static-method"}) -final class Target_sun_util_resources_OpenListResourceBundle_SubstituteLoadLookup { - - @Alias private volatile Map lookup; - - @Substitute - private void loadLookup() { - LocalizationSupport support = ImageSingletons.lookup(LocalizationSupport.class); - Map content = support.getBundleContentOf(getClass()); - // use the supplied map implementation specified by the factory method - Map tmp = createMap(content.size()); - tmp.putAll(content); - synchronized (this) { - if (lookup == null) { - lookup = content; - } - } - } - - @Alias - protected native Map createMap(int size); -} - -@TargetClass(value = sun.util.resources.ParallelListResourceBundle.class, onlyWith = SubstituteLoadLookup.class) -@SuppressWarnings({"unused", "static-method"}) -final class Target_sun_util_resources_ParallelListResourceBundle_SubstituteLoadLookup { - - @Alias private ConcurrentMap lookup; - - @Substitute - private void setParallelContents(OpenListResourceBundle rb) { - throw VMError.unsupportedFeature("Resource bundle lookup must be loaded during native image generation: " + getClass().getTypeName()); - } - - @Substitute - private boolean areParallelContentsComplete() { - return true; - } - - @Substitute - private void loadLookupTablesIfNecessary() { - LocalizationSupport support = ImageSingletons.lookup(LocalizationSupport.class); - synchronized (this) { - if (lookup == null) { - lookup = new ConcurrentHashMap<>(support.getBundleContentOf(getClass())); - } - } - } -} - -@TargetClass(value = java.util.ResourceBundle.class, innerClass = "Control") -@SuppressWarnings({"unused", "static-method"}) -final class Target_java_util_ResourceBundle_Control { - - /** - * Bundles are baked into the image, therefore their source can't really be modified at runtime. - * Since their source can't be modified, there is no need to reload them. - */ - @Substitute - public boolean needsReload(String baseName, Locale locale, - String format, ClassLoader loader, - ResourceBundle bundle, long loadTime) { - - return false; - } -} - -@TargetClass(java.text.DateFormatSymbols.class) -final class Target_java_text_DateFormatSymbols { - - @Alias @RecomputeFieldValue(kind = Kind.FromAlias) // - private static ConcurrentMap cachedInstances = new ConcurrentHashMap<>(3); -} - -/** Dummy class to have a class with the file's name. */ -public final class ResourceBundleSubstitutions { -} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle_Control.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle_Control.java new file mode 100644 index 000000000000..ee389373436b --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_ResourceBundle_Control.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; + +import java.util.Locale; +import java.util.ResourceBundle; + +@TargetClass(value = java.util.ResourceBundle.class, innerClass = "Control") +@SuppressWarnings({"unused", "static-method"}) +final class Target_java_util_ResourceBundle_Control { + + /** + * Bundles are baked into the image, therefore their source can't really be modified at runtime. + * Since their source can't be modified, there is no need to reload them. + */ + @Substitute + public boolean needsReload(String baseName, Locale locale, + String format, ClassLoader loader, + ResourceBundle bundle, long loadTime) { + + return false; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_AuxLocaleProviderAdapter_OptimizedLocaleMode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_AuxLocaleProviderAdapter_OptimizedLocaleMode.java new file mode 100644 index 000000000000..963ecaf4cfec --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_AuxLocaleProviderAdapter_OptimizedLocaleMode.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Delete; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; + +@Delete +@TargetClass(value = sun.util.locale.provider.AuxLocaleProviderAdapter.class, onlyWith = OptimizedLocaleMode.class) +final class Target_sun_util_locale_provider_AuxLocaleProviderAdapter_OptimizedLocaleMode { +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_JRELocaleProviderAdapter.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_JRELocaleProviderAdapter.java new file mode 100644 index 000000000000..8f7f5f0bcc06 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_JRELocaleProviderAdapter.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK8OrEarlier; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.util.VMError; +import org.graalvm.nativeimage.ImageSingletons; + +// Checkstyle: stop +import sun.util.locale.provider.JRELocaleProviderAdapter; +import sun.util.locale.provider.LocaleResources; +// Checkstyle: resume + +import java.util.Locale; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +@TargetClass(JRELocaleProviderAdapter.class) +final class Target_sun_util_locale_provider_JRELocaleProviderAdapter { + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// + @Alias// + private ConcurrentMap> langtagSets; + + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// + @Alias// + private ConcurrentMap localeResourcesMap; + + @Alias // + @TargetElement(onlyWith = JDK8OrEarlier.class) // + static Boolean isNonENSupported; + + @Substitute // + @TargetElement(onlyWith = JDK8OrEarlier.class) // + private static boolean isNonENLangSupported() { + /* + * The original implementation performs lazily initialization that looks at the file system + * (a certain .jar file being present). That cannot work in a native image, and even worse + * it makes file access methods reachable in very basic images. + */ + VMError.guarantee(isNonENSupported != null, "isNonENSupported must be initialized during image generation"); + return isNonENSupported; + } + + @Substitute + @SuppressWarnings({"unused", "static-method"}) + protected Set createLanguageTagSet(String category) { + return ImageSingletons.lookup(LocalizationSupport.class).supportedLanguageTags; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleProviderAdapter_OptimizedLocaleMode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleProviderAdapter_OptimizedLocaleMode.java new file mode 100644 index 000000000000..76854d4bf550 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleProviderAdapter_OptimizedLocaleMode.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.OptimizedLocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; +import com.oracle.svm.core.util.VMError; +import org.graalvm.collections.Pair; +import org.graalvm.nativeimage.ImageSingletons; + +// Checkstyle: stop +import sun.util.locale.provider.LocaleProviderAdapter; +// Checkstyle: resume + +import java.util.Locale; +import java.util.spi.LocaleServiceProvider; + +@TargetClass(value = sun.util.locale.provider.LocaleProviderAdapter.class, onlyWith = OptimizedLocaleMode.class) +final class Target_sun_util_locale_provider_LocaleProviderAdapter_OptimizedLocaleMode { + + @Substitute + @SuppressWarnings({"unused"}) + public static LocaleProviderAdapter getAdapter(Class providerClass, Locale locale) { + OptimizedLocalizationSupport support = ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport(); + for (Locale candidateLocale : support.control.getCandidateLocales("", locale)) { + LocaleProviderAdapter result = support.adaptersByClass.get(Pair.create(providerClass, candidateLocale)); + if (result != null) { + return result; + } + } + throw VMError.unsupportedFeature("LocaleProviderAdapter.getAdapter: providerClass: " + providerClass.getName() + ", locale: " + locale); + } + + @Substitute + public static LocaleProviderAdapter forType(LocaleProviderAdapter.Type type) { + final LocaleProviderAdapter result = ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().adaptersByType.get(type); + if (result != null) { + return result; + } + throw VMError.unsupportedFeature("LocaleProviderAdapter.forType: type: " + type.toString()); + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleResources.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleResources.java new file mode 100644 index 000000000000..316f0b2c913a --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleResources.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; +// Checkstyle: stop +import sun.util.locale.provider.LocaleResources; +// Checkstyle: resume + +import java.lang.ref.ReferenceQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +@TargetClass(LocaleResources.class) +final class Target_sun_util_locale_provider_LocaleResources { + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// + @Alias// + private ConcurrentMap cache; + @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ReferenceQueue.class)// + @Alias// + private ReferenceQueue referenceQueue; +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_JvmLocaleMode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_JvmLocaleMode.java new file mode 100644 index 000000000000..4803ebcbe6d1 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_JvmLocaleMode.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.JvmLocaleMode; +import org.graalvm.nativeimage.ImageSingletons; + +import java.util.Locale; + +@SuppressWarnings({"static-method"}) +@TargetClass(value = sun.util.locale.provider.LocaleServiceProviderPool.class, onlyWith = JvmLocaleMode.class) +final class Target_sun_util_locale_provider_LocaleServiceProviderPool_JvmLocaleMode { + @Substitute + private static Locale[] getAllAvailableLocales() { + return ImageSingletons.lookup(LocalizationSupport.class).allLocales; + } + + @Substitute + private Locale[] getAvailableLocales() { + return ImageSingletons.lookup(LocalizationSupport.class).allLocales; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java new file mode 100644 index 000000000000..6798bf245fd9 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.KeepOriginal; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.annotate.TargetElement; +import com.oracle.svm.core.jdk.JDK11OrLater; +import com.oracle.svm.core.jdk.JDK11To14; +import com.oracle.svm.core.jdk.JDK8OrEarlier; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.OptimizedLocaleMode; +import com.oracle.svm.core.util.VMError; +import org.graalvm.nativeimage.ImageSingletons; + +// Checkstyle: stop +import sun.util.locale.provider.LocaleServiceProviderPool; +// Checkstyle: resume + +import java.util.Locale; +import java.util.spi.LocaleServiceProvider; + +@Substitute +@TargetClass(value = sun.util.locale.provider.LocaleServiceProviderPool.class, onlyWith = OptimizedLocaleMode.class) +@SuppressWarnings({"static-method"}) +public final class Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode { + + private final LocaleServiceProvider cachedProvider; + + public Target_sun_util_locale_provider_LocaleServiceProviderPool_OptimizedLocaleMode(LocaleServiceProvider cachedProvider) { + this.cachedProvider = cachedProvider; + } + + @Substitute + private static LocaleServiceProviderPool getPool(Class providerClass) { + LocaleServiceProviderPool result = (LocaleServiceProviderPool) ImageSingletons.lookup(LocalizationSupport.class).asOptimizedSupport().providerPools.get(providerClass); + if (result == null) { + throw VMError.unsupportedFeature("LocaleServiceProviderPool.getPool " + providerClass.getName()); + } + return result; + } + + @Substitute + @TargetElement(onlyWith = JDK8OrEarlier.class) + private boolean hasProviders() { + return false; + } + + @KeepOriginal + private native

S getLocalizedObject(LocaleServiceProviderPool.LocalizedObjectGetter getter, Locale locale, Object... params); + + @KeepOriginal + private native

S getLocalizedObject(LocaleServiceProviderPool.LocalizedObjectGetter getter, Locale locale, String key, Object... params); + + @SuppressWarnings({"unused", "unchecked"}) + @Substitute + private

S getLocalizedObjectImpl(LocaleServiceProviderPool.LocalizedObjectGetter getter, Locale locale, boolean isObjectProvider, String key, + Object... params) { + if (locale == null) { + throw new NullPointerException(); + } + return getter.getObject((P) cachedProvider, locale, key, params); + } + + @KeepOriginal // + @TargetElement(onlyWith = JDK11OrLater.class) // + public native

S getLocalizedObject(LocaleServiceProviderPool.LocalizedObjectGetter getter, + Locale locale, + Boolean isObjectProvider, + String key, + Object... params); + + @KeepOriginal // + @TargetElement(onlyWith = JDK11To14.class) // + static native void config(Class caller, String message); + + @Substitute + private static Locale[] getAllAvailableLocales() { + return ImageSingletons.lookup(LocalizationSupport.class).allLocales; + } + + @Substitute + private Locale[] getAvailableLocales() { + return ImageSingletons.lookup(LocalizationSupport.class).allLocales; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_TimeZoneNameUtility.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_TimeZoneNameUtility.java new file mode 100644 index 000000000000..bad1b49c78bf --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_locale_provider_TimeZoneNameUtility.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.RecomputeFieldValue; +import com.oracle.svm.core.annotate.TargetClass; + +import java.lang.ref.SoftReference; +import java.util.Locale; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +@TargetClass(sun.util.locale.provider.TimeZoneNameUtility.class) +final class Target_sun_util_locale_provider_TimeZoneNameUtility { + + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)// + static ConcurrentHashMap> cachedZoneData = new ConcurrentHashMap<>(); + + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.FromAlias)// + static Map>> cachedDisplayNames = new ConcurrentHashMap<>(); +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_OpenListResourceBundle_SubstituteLoadLookup.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_OpenListResourceBundle_SubstituteLoadLookup.java new file mode 100644 index 000000000000..d13540c134b2 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_OpenListResourceBundle_SubstituteLoadLookup.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.SubstituteLoadLookup; +import org.graalvm.nativeimage.ImageSingletons; + +import java.util.Map; + +//Checkstyle: allow synchronization + +@TargetClass(value = sun.util.resources.OpenListResourceBundle.class, onlyWith = SubstituteLoadLookup.class) +@SuppressWarnings({"static-method"}) +final class Target_sun_util_resources_OpenListResourceBundle_SubstituteLoadLookup { + + @Alias private volatile Map lookup; + + @Substitute + private void loadLookup() { + LocalizationSupport support = ImageSingletons.lookup(LocalizationSupport.class); + Map content = support.getBundleContentOf(getClass()); + // use the supplied map implementation specified by the factory method + Map tmp = createMap(content.size()); + tmp.putAll(content); + synchronized (this) { + if (lookup == null) { + lookup = content; + } + } + } + + @Alias + protected native Map createMap(int size); +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_ParallelListResourceBundle_SubstituteLoadLookup.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_ParallelListResourceBundle_SubstituteLoadLookup.java new file mode 100644 index 000000000000..1041242ca371 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_sun_util_resources_ParallelListResourceBundle_SubstituteLoadLookup.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2021, 2021, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.core.jdk.localization.substitutions; + +import com.oracle.svm.core.annotate.Alias; +import com.oracle.svm.core.annotate.Substitute; +import com.oracle.svm.core.annotate.TargetClass; +import com.oracle.svm.core.jdk.localization.LocalizationSupport; +import com.oracle.svm.core.jdk.localization.substitutions.modes.SubstituteLoadLookup; +import com.oracle.svm.core.util.VMError; +import org.graalvm.nativeimage.ImageSingletons; + +//Checkstyle: stop +import sun.util.resources.OpenListResourceBundle; +//Checkstyle: resume + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +//Checkstyle: allow synchronization + +@TargetClass(value = sun.util.resources.ParallelListResourceBundle.class, onlyWith = SubstituteLoadLookup.class) +@SuppressWarnings({"unused", "static-method"}) +final class Target_sun_util_resources_ParallelListResourceBundle_SubstituteLoadLookup { + + @Alias private ConcurrentMap lookup; + + @Substitute + private void setParallelContents(OpenListResourceBundle rb) { + throw VMError.unsupportedFeature("Resource bundle lookup must be loaded during native image generation: " + getClass().getTypeName()); + } + + @Substitute + private boolean areParallelContentsComplete() { + return true; + } + + @Substitute + private void loadLookupTablesIfNecessary() { + LocalizationSupport support = ImageSingletons.lookup(LocalizationSupport.class); + synchronized (this) { + if (lookup == null) { + lookup = new ConcurrentHashMap<>(support.getBundleContentOf(getClass())); + } + } + } +}