|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | +package com.oracle.svm.core.jdk; |
| 26 | + |
| 27 | +import java.nio.file.Path; |
| 28 | +import java.time.chrono.HijrahChronology; |
| 29 | +import java.util.Properties; |
| 30 | + |
| 31 | +import com.oracle.svm.core.annotate.Delete; |
| 32 | +import com.oracle.svm.core.annotate.Substitute; |
| 33 | +import com.oracle.svm.core.annotate.TargetClass; |
| 34 | +import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; |
| 35 | +import com.oracle.svm.core.feature.InternalFeature; |
| 36 | + |
| 37 | +/** |
| 38 | + * Feature to configure {@link HijrahChronology} at build time. All {@link HijrahChronology} object |
| 39 | + * that end up in the image heap are fully initialized. This has the advantage that the resources |
| 40 | + * and files for configuring the {@link HijrahChronology} variants are not needed at run time. On |
| 41 | + * the other hand, the configuration can no longer be changed after building. See |
| 42 | + * {@link HijrahChronology} for configuration option. |
| 43 | + */ |
| 44 | +@AutomaticallyRegisteredFeature |
| 45 | +public class HijrahChronologyFeature implements InternalFeature { |
| 46 | + @Override |
| 47 | + public void duringSetup(DuringSetupAccess access) { |
| 48 | + // implicitly initialize HijrahChronology objects via transitive call to checkCalendarInit() |
| 49 | + access.registerObjectReachabilityHandler(o -> o.isLeapYear(0), HijrahChronology.class); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +@TargetClass(HijrahChronology.class) |
| 54 | +final class Target_java_time_chrono_HijrahChronology { |
| 55 | + // Checkstyle: stop |
| 56 | + /** |
| 57 | + * Config path with includes JAVA_HOME. We force full initialization at build time |
| 58 | + * {@link HijrahChronologyFeature#duringSetup}, so no need to keep this. |
| 59 | + */ |
| 60 | + @Delete // |
| 61 | + private static Path CONF_PATH; |
| 62 | + // Checkstyle: resume |
| 63 | + |
| 64 | + /** |
| 65 | + * @see #CONF_PATH |
| 66 | + */ |
| 67 | + @Delete |
| 68 | + private static native void registerCustomChrono(); |
| 69 | + |
| 70 | + /** |
| 71 | + * @see #CONF_PATH |
| 72 | + */ |
| 73 | + @Delete |
| 74 | + private native void loadCalendarData(); |
| 75 | + |
| 76 | + /** |
| 77 | + * @see #CONF_PATH |
| 78 | + */ |
| 79 | + @Delete |
| 80 | + private static native Properties readConfigProperties(String chronologyId, String calendarType); |
| 81 | + |
| 82 | + /** |
| 83 | + * @see #CONF_PATH |
| 84 | + */ |
| 85 | + @Delete // |
| 86 | + private boolean initComplete; |
| 87 | + |
| 88 | + /** |
| 89 | + * No more initialization needed. |
| 90 | + * |
| 91 | + * @see #CONF_PATH |
| 92 | + */ |
| 93 | + @Substitute |
| 94 | + private void checkCalendarInit() { |
| 95 | + // initialized at build time |
| 96 | + } |
| 97 | +} |
0 commit comments