|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2021, 2021, Red Hat Inc. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. Oracle designates this |
| 9 | + * particular file as subject to the "Classpath" exception as provided |
| 10 | + * by Oracle in the LICENSE file that accompanied this code. |
| 11 | + * |
| 12 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 16 | + * accompanied this code). |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License version |
| 19 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | + * |
| 22 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | + * or visit www.oracle.com if you need additional information or have any |
| 24 | + * questions. |
| 25 | + */ |
| 26 | +package com.oracle.svm.core.jdk11; |
| 27 | + |
| 28 | +import com.oracle.svm.core.SubstrateUtil; |
| 29 | +import com.oracle.svm.core.annotate.Alias; |
| 30 | +import com.oracle.svm.core.annotate.Delete; |
| 31 | +import com.oracle.svm.core.annotate.RecomputeFieldValue; |
| 32 | +import com.oracle.svm.core.annotate.Substitute; |
| 33 | +import com.oracle.svm.core.annotate.TargetClass; |
| 34 | +import com.oracle.svm.core.hub.ClassForNameSupport; |
| 35 | +import com.oracle.svm.core.jdk.JDK11OrLater; |
| 36 | +import com.oracle.svm.core.jdk.Target_java_lang_Package; |
| 37 | + |
| 38 | +import java.util.concurrent.ConcurrentHashMap; |
| 39 | +import java.util.stream.Stream; |
| 40 | + |
| 41 | +@TargetClass(value = jdk.internal.loader.ClassLoaders.class, onlyWith = JDK11OrLater.class) |
| 42 | +final class Target_jdk_internal_loader_ClassLoaders_JDK11OrLater { |
| 43 | + @Alias |
| 44 | + static native Target_jdk_internal_loader_BuiltinClassLoader bootLoader(); |
| 45 | + |
| 46 | + @Alias |
| 47 | + public static native ClassLoader platformClassLoader(); |
| 48 | +} |
| 49 | + |
| 50 | +@TargetClass(value = jdk.internal.loader.BootLoader.class, onlyWith = JDK11OrLater.class) |
| 51 | +final class Target_jdk_internal_loader_BootLoader_JDK11OrLater { |
| 52 | + |
| 53 | + @Substitute |
| 54 | + static Package getDefinedPackage(String name) { |
| 55 | + if (name != null) { |
| 56 | + Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null, |
| 57 | + null, null, null, null, null); |
| 58 | + return SubstrateUtil.cast(pkg, Package.class); |
| 59 | + } else { |
| 60 | + return null; |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @Substitute |
| 65 | + public static Stream<Package> packages() { |
| 66 | + Target_jdk_internal_loader_BuiltinClassLoader bootClassLoader = Target_jdk_internal_loader_ClassLoaders_JDK11OrLater.bootLoader(); |
| 67 | + Target_java_lang_ClassLoader_JDK11OrLater systemClassLoader = SubstrateUtil.cast(bootClassLoader, Target_java_lang_ClassLoader_JDK11OrLater.class); |
| 68 | + return systemClassLoader.packages(); |
| 69 | + } |
| 70 | + |
| 71 | + @Delete("only used by #packages()") |
| 72 | + private static native String[] getSystemPackageNames(); |
| 73 | + |
| 74 | + @Substitute |
| 75 | + private static Class<?> loadClassOrNull(String name) { |
| 76 | + return ClassForNameSupport.forNameOrNull(name, null); |
| 77 | + } |
| 78 | + |
| 79 | + @SuppressWarnings("unused") |
| 80 | + @Substitute |
| 81 | + private static Class<?> loadClass(Target_java_lang_Module_JDK11OrLater module, String name) { |
| 82 | + /* The module system is not supported for now, therefore the module parameter is ignored. */ |
| 83 | + return ClassForNameSupport.forNameOrNull(name, null); |
| 84 | + } |
| 85 | + |
| 86 | + @Substitute |
| 87 | + private static boolean hasClassPath() { |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * All ClassLoaderValue are reset at run time for now. See also |
| 93 | + * {@link Target_java_lang_ClassLoader_JDK11OrLater#classLoaderValueMap} for resetting of individual class |
| 94 | + * loaders. |
| 95 | + */ |
| 96 | + // Checkstyle: stop |
| 97 | + @Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)// |
| 98 | + static ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP; |
| 99 | + // Checkstyle: resume |
| 100 | +} |
| 101 | + |
| 102 | +/** Dummy class to have a class with the file's name. */ |
| 103 | +public final class JavaLangSubstitutions_JDK11OrLater { |
| 104 | + |
| 105 | +} |
0 commit comments