Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-34751] Remove code specific to JDK 8. #4151

Merged
merged 5 commits into from
Dec 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.lang.reflect.Method;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand All @@ -48,13 +47,13 @@

import com.oracle.svm.configure.config.ConfigurationSet;
import com.oracle.svm.configure.filters.FilterConfigurationParser;
import com.oracle.svm.configure.filters.ModuleFilterTools;
import com.oracle.svm.configure.filters.RuleNode;
import com.oracle.svm.configure.json.JsonWriter;
import com.oracle.svm.configure.trace.AccessAdvisor;
import com.oracle.svm.configure.trace.TraceProcessor;
import com.oracle.svm.core.configure.ConfigurationFile;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;

public class ConfigurationTool {

Expand Down Expand Up @@ -368,17 +367,7 @@ private static void generateFilterRules(Iterator<String> argsIter) throws IOExce
exportedInclusion = RuleNode.Inclusion.Include;
unexportedInclusion = RuleNode.Inclusion.Exclude;
}

try {
Class<?> moduleFilterToolsClass = Class.forName("com.oracle.svm.configure.jdk11.filters.ModuleFilterTools");
Method generateFromModulesMethod = ReflectionUtil.lookupMethod(moduleFilterToolsClass, "generateFromModules",
String[].class, RuleNode.Inclusion.class, RuleNode.Inclusion.class, RuleNode.Inclusion.class, boolean.class);
rootNode = (RuleNode) generateFromModulesMethod.invoke(null, moduleNames, rootInclusion, exportedInclusion, unexportedInclusion, reduce);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Module-based filter generation is not available in JDK 8 and below.");
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
rootNode = ModuleFilterTools.generateFromModules(moduleNames, rootInclusion, exportedInclusion, unexportedInclusion, reduce);
} else {
throw new UsageException(current + " is currently not supported in the native-image build of this tool.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.configure.jdk11.filters;
package com.oracle.svm.configure.filters;

import java.lang.module.ModuleDescriptor;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import com.oracle.svm.configure.filters.RuleNode;
import com.oracle.svm.configure.filters.RuleNode.Inclusion;

@SuppressWarnings("unused")
public class ModuleFilterTools {

public static RuleNode generateFromModules(String[] moduleNames, Inclusion rootInclusion, Inclusion exportedInclusion, Inclusion unexportedInclusion, boolean reduce) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.jdk.JDK17OrLater;
import com.oracle.svm.core.jdk11.ModuleUtil;
import com.oracle.svm.core.jdk.ModuleUtil;

@SuppressWarnings("unused")
@TargetClass(value = Module.class, onlyWith = JDK17OrLater.class)
@TargetClass(value = java.lang.Module.class, onlyWith = JDK17OrLater.class)
public final class Target_java_lang_Module_JDK17OrLater {

// Checkstyle: allow synchronization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@
import com.oracle.svm.core.classinitialization.EnsureClassInitializedNode;
import com.oracle.svm.core.jdk.JDK17OrLater;
import com.oracle.svm.core.jdk.Resources;
import com.oracle.svm.core.jdk.Target_java_lang_Module;
import com.oracle.svm.core.jdk.Target_jdk_internal_reflect_Reflection;
import com.oracle.svm.core.meta.SharedType;
import com.oracle.svm.core.util.LazyFinalReference;
import com.oracle.svm.core.util.VMError;
import com.oracle.svm.util.ReflectionUtil;
import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError;

import jdk.internal.reflect.ConstantPool;
import jdk.internal.reflect.Reflection;
import jdk.vm.ci.meta.JavaKind;

@Hybrid(canHybridFieldsBeDuplicated = false)
Expand Down Expand Up @@ -290,11 +290,9 @@ public final class DynamicHub implements JavaKind.FormatWithToString, AnnotatedE
private AnnotatedSuperInfo annotatedSuperInfo;

/**
* Field used for module information access at run-time The run time type of this field is
* java.lang.Module but can be casted to {@link Target_java_lang_Module} The module is of type
* Object to avoid ClassCastExceptions at image build time due to base module miss-match.
* Field used for module information access at run-time.
*/
private Object module;
private Module module;

/**
* JDK 11 and later: the class that serves as the host for the nest. All nestmates have the same
Expand All @@ -303,7 +301,7 @@ public final class DynamicHub implements JavaKind.FormatWithToString, AnnotatedE
private final Class<?> nestHost;

@Platforms(Platform.HOSTED_ONLY.class)
public void setModule(Object module) {
public void setModule(Module module) {
this.module = module;
}

Expand Down Expand Up @@ -682,7 +680,7 @@ public Enum<?>[] getEnumConstantsShared() {

@Substitute
public InputStream getResourceAsStream(String resourceName) {
String moduleName = module == null ? null : SubstrateUtil.cast(module, Target_java_lang_Module.class).name;
String moduleName = module == null ? null : module.getName();
String resolvedName = resolveName(resourceName);
return Resources.createInputStream(moduleName, resolvedName);
}
Expand Down Expand Up @@ -1253,17 +1251,17 @@ private Constructor<?> getEnclosingConstructor() {

@Substitute
public static Class<?> forName(String className) throws ClassNotFoundException {
Class<?> caller = Target_jdk_internal_reflect_Reflection.getCallerClass();
Class<?> caller = Reflection.getCallerClass();
return forName(className, true, caller.getClassLoader());
}

@Substitute //
public static Class<?> forName(@SuppressWarnings("unused") Target_java_lang_Module module, String className) {
public static Class<?> forName(@SuppressWarnings("unused") Module module, String className) {
/*
* The module system is not supported for now, therefore the module parameter is ignored and
* we use the class loader of the caller class instead of the module's loader.
*/
Class<?> caller = Target_jdk_internal_reflect_Reflection.getCallerClass();
Class<?> caller = Reflection.getCallerClass();
try {
return forName(className, false, caller.getClassLoader());
} catch (ClassNotFoundException e) {
Expand Down Expand Up @@ -1351,8 +1349,8 @@ public boolean desiredAssertionStatus() {
}

@Substitute //
public Target_java_lang_Module getModule() {
return (Target_java_lang_Module) module;
public Module getModule() {
return module;
}

@Substitute //
Expand Down Expand Up @@ -1504,7 +1502,7 @@ private void setSigners(@SuppressWarnings("unused") Object[] signers) {
native byte[] getRawTypeAnnotations();

@Delete
native Target_jdk_internal_reflect_ConstantPool getConstantPool();
native ConstantPool getConstantPool();

@Delete
private native Field[] getDeclaredFields0(boolean publicOnly);
Expand Down Expand Up @@ -1582,22 +1580,22 @@ final class Target_java_lang_Class_ReflectionData<T> {
// Checkstyle: resume
}

@TargetClass(className = "jdk.internal.reflect.ReflectionFactory")
@TargetClass(value = jdk.internal.reflect.ReflectionFactory.class)
final class Target_jdk_internal_reflect_ReflectionFactory {

@Alias //
private static Target_jdk_internal_reflect_ReflectionFactory soleInstance;

/**
* This substitution eliminates the SecurityManager check in the original method, which would
* make some build-time verifications fail.
*/
@Substitute
public static Target_jdk_internal_reflect_ReflectionFactory getReflectionFactory() {
return soleInstance;
}
}

@TargetClass(className = "jdk.internal.reflect.ConstantPool")
final class Target_jdk_internal_reflect_ConstantPool {
}

@TargetClass(className = "java.lang.reflect.RecordComponent", onlyWith = JDK17OrLater.class)
final class Target_java_lang_reflect_RecordComponent {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jdk11;
package com.oracle.svm.core.jdk;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* questions.
*/

package com.oracle.svm.core.jdk11;
package com.oracle.svm.core.jdk;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -34,7 +34,6 @@
import org.graalvm.nativeimage.hosted.Feature;

import com.oracle.svm.core.annotate.AutomaticFeature;
import com.oracle.svm.core.jdk.JDKVersionSpecificResourceBuilder;

public class JDKVersionSpecificResourceBuilderJDK11OrLater implements JDKVersionSpecificResourceBuilder {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.BooleanSupplier;
import java.util.stream.Stream;

import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode;
import org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode.BinaryOperation;
Expand Down Expand Up @@ -64,6 +65,7 @@
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.annotate.TargetElement;
import com.oracle.svm.core.annotate.Uninterruptible;
import com.oracle.svm.core.hub.ClassForNameSupport;
import com.oracle.svm.core.hub.DynamicHub;
import com.oracle.svm.core.jdk.JavaLangSubstitutions.ClassValueSupport;
import com.oracle.svm.core.monitor.MonitorSupport;
Expand Down Expand Up @@ -640,12 +642,67 @@ private String getExtendedNPEMessage() {
}
}

@TargetClass(className = "jdk.internal.loader.ClassLoaders")
@TargetClass(value = jdk.internal.loader.ClassLoaders.class)
final class Target_jdk_internal_loader_ClassLoaders {
@Alias
static native Target_jdk_internal_loader_BuiltinClassLoader bootLoader();

@Alias
public static native ClassLoader platformClassLoader();
}

@TargetClass(value = jdk.internal.loader.BootLoader.class)
final class Target_jdk_internal_loader_BootLoader {

@Substitute
static Package getDefinedPackage(String name) {
if (name != null) {
Target_java_lang_Package pkg = new Target_java_lang_Package(name, null, null, null,
null, null, null, null, null);
return SubstrateUtil.cast(pkg, Package.class);
} else {
return null;
}
}

@Substitute
public static Stream<Package> packages() {
Target_jdk_internal_loader_BuiltinClassLoader bootClassLoader = Target_jdk_internal_loader_ClassLoaders.bootLoader();
Target_java_lang_ClassLoader systemClassLoader = SubstrateUtil.cast(bootClassLoader, Target_java_lang_ClassLoader.class);
return systemClassLoader.packages();
}

@Delete("only used by #packages()")
private static native String[] getSystemPackageNames();

@Substitute
private static Class<?> loadClassOrNull(String name) {
return ClassForNameSupport.forNameOrNull(name, null);
}

@SuppressWarnings("unused")
@Substitute
private static Class<?> loadClass(Module module, String name) {
/* The module system is not supported for now, therefore the module parameter is ignored. */
return ClassForNameSupport.forNameOrNull(name, null);
}

@Substitute
private static boolean hasClassPath() {
return true;
}

/**
* All ClassLoaderValue are reset at run time for now. See also
* {@link Target_java_lang_ClassLoader#classLoaderValueMap} for resetting of individual class
* loaders.
*/
// Checkstyle: stop
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)//
static ConcurrentHashMap<?, ?> CLASS_LOADER_VALUE_MAP;
// Checkstyle: resume
}

/** Dummy class to have a class with the file's name. */
public final class JavaLangSubstitutions {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jdk11;
package com.oracle.svm.core.jdk;

import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

import com.oracle.svm.core.annotate.AutomaticFeature;
import com.oracle.svm.core.jdk.JNIRegistrationUtil;

@AutomaticFeature
public class JavaNetHttpFeature extends JNIRegistrationUtil implements Feature {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.core.jdk11;
package com.oracle.svm.core.jdk;

import com.oracle.svm.core.SubstrateUtil;

import javax.lang.model.SourceVersion;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -35,6 +32,10 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.lang.model.SourceVersion;

import com.oracle.svm.core.SubstrateUtil;

public final class ModuleUtil {
private ModuleUtil() {
}
Expand Down
Loading