|
31 | 31 | import static jdk.graal.compiler.replacements.StandardGraphBuilderPlugins.registerInvocationPlugins;
|
32 | 32 |
|
33 | 33 | import java.io.IOException;
|
34 |
| -import java.io.PrintWriter; |
35 | 34 | import java.lang.annotation.Annotation;
|
36 |
| -import java.lang.reflect.Executable; |
37 | 35 | import java.lang.reflect.Method;
|
38 | 36 | import java.lang.reflect.Modifier;
|
39 |
| -import java.lang.reflect.Type; |
40 | 37 | import java.nio.file.FileSystems;
|
41 | 38 | import java.nio.file.Files;
|
42 | 39 | import java.nio.file.Path;
|
43 | 40 | import java.util.ArrayList;
|
44 | 41 | import java.util.Arrays;
|
45 | 42 | import java.util.Collection;
|
46 | 43 | import java.util.Collections;
|
47 |
| -import java.util.Comparator; |
48 |
| -import java.util.EnumMap; |
49 | 44 | import java.util.EnumSet;
|
50 | 45 | import java.util.List;
|
51 | 46 | import java.util.ListIterator;
|
|
54 | 49 | import java.util.ServiceLoader;
|
55 | 50 | import java.util.Set;
|
56 | 51 | import java.util.concurrent.atomic.AtomicBoolean;
|
57 |
| -import java.util.function.BiConsumer; |
58 | 52 | import java.util.function.BooleanSupplier;
|
59 | 53 | import java.util.function.Function;
|
60 | 54 |
|
61 |
| -import org.graalvm.collections.EconomicMap; |
62 | 55 | import org.graalvm.collections.EconomicSet;
|
63 |
| -import org.graalvm.collections.MapCursor; |
64 | 56 | import org.graalvm.collections.Pair;
|
65 |
| -import org.graalvm.nativeimage.AnnotationAccess; |
66 | 57 | import org.graalvm.nativeimage.ImageInfo;
|
67 | 58 | import org.graalvm.nativeimage.ImageSingletons;
|
68 | 59 | import org.graalvm.nativeimage.Platform;
|
|
111 | 102 | import com.oracle.graal.pointsto.meta.HostedProviders;
|
112 | 103 | import com.oracle.graal.pointsto.meta.PointsToAnalysisFactory;
|
113 | 104 | import com.oracle.graal.pointsto.reports.AnalysisReporter;
|
114 |
| -import com.oracle.graal.pointsto.reports.ReportUtils; |
115 | 105 | import com.oracle.graal.pointsto.typestate.DefaultAnalysisPolicy;
|
116 | 106 | import com.oracle.graal.pointsto.util.AnalysisError;
|
117 | 107 | import com.oracle.graal.pointsto.util.GraalAccess;
|
|
171 | 161 | import com.oracle.svm.core.heap.Heap;
|
172 | 162 | import com.oracle.svm.core.heap.RestrictHeapAccessCallees;
|
173 | 163 | import com.oracle.svm.core.hub.DynamicHub;
|
174 |
| -import com.oracle.svm.core.hub.LayoutEncoding; |
175 | 164 | import com.oracle.svm.core.image.ImageHeapLayouter;
|
176 | 165 | import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
|
177 | 166 | import com.oracle.svm.core.jdk.ServiceCatalogSupport;
|
|
186 | 175 | import com.oracle.svm.core.util.ObservableImageHeapMapProvider;
|
187 | 176 | import com.oracle.svm.core.util.UserError;
|
188 | 177 | import com.oracle.svm.core.util.VMError;
|
| 178 | +import com.oracle.svm.hosted.BuildArtifactsExporter.BuildArtifactsImpl; |
189 | 179 | import com.oracle.svm.hosted.FeatureImpl.AfterAnalysisAccessImpl;
|
190 | 180 | import com.oracle.svm.hosted.FeatureImpl.AfterCompilationAccessImpl;
|
191 | 181 | import com.oracle.svm.hosted.FeatureImpl.AfterHeapLayoutAccessImpl;
|
|
244 | 234 | import com.oracle.svm.hosted.imagelayer.LoadImageSingletonFeature;
|
245 | 235 | import com.oracle.svm.hosted.jdk.localization.LocalizationFeature;
|
246 | 236 | import com.oracle.svm.hosted.meta.HostedConstantReflectionProvider;
|
247 |
| -import com.oracle.svm.hosted.meta.HostedField; |
248 |
| -import com.oracle.svm.hosted.meta.HostedInterface; |
249 | 237 | import com.oracle.svm.hosted.meta.HostedMetaAccess;
|
250 | 238 | import com.oracle.svm.hosted.meta.HostedMethod;
|
251 | 239 | import com.oracle.svm.hosted.meta.HostedSnippetReflectionProvider;
|
252 |
| -import com.oracle.svm.hosted.meta.HostedType; |
253 | 240 | import com.oracle.svm.hosted.meta.HostedUniverse;
|
254 | 241 | import com.oracle.svm.hosted.meta.UniverseBuilder;
|
255 | 242 | import com.oracle.svm.hosted.option.HostedOptionProvider;
|
|
265 | 252 | import com.oracle.svm.hosted.snippets.SubstrateGraphBuilderPlugins;
|
266 | 253 | import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor;
|
267 | 254 | import com.oracle.svm.hosted.substitute.DeletedFieldsPlugin;
|
| 255 | +import com.oracle.svm.hosted.substitute.SubstitutionInvocationPlugins; |
268 | 256 | import com.oracle.svm.hosted.util.CPUTypeAArch64;
|
269 | 257 | import com.oracle.svm.hosted.util.CPUTypeAMD64;
|
270 | 258 | import com.oracle.svm.hosted.util.CPUTypeRISCV64;
|
|
300 | 288 | import jdk.graal.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
|
301 | 289 | import jdk.graal.compiler.nodes.graphbuilderconf.GeneratedPluginFactory;
|
302 | 290 | import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
|
303 |
| -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugin; |
304 |
| -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; |
305 | 291 | import jdk.graal.compiler.nodes.spi.CoreProviders;
|
306 | 292 | import jdk.graal.compiler.nodes.spi.LoweringProvider;
|
307 | 293 | import jdk.graal.compiler.nodes.spi.StampProvider;
|
@@ -632,7 +618,7 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints, JavaMainSupport j
|
632 | 618 | ConfigurationValues.getTarget(), this.isStubBasedPluginsSupported());
|
633 | 619 |
|
634 | 620 | if (NativeImageOptions.PrintUniverse.getValue()) {
|
635 |
| - printTypes(); |
| 621 | + hUniverse.printTypes(); |
636 | 622 | }
|
637 | 623 |
|
638 | 624 | /* Find the entry point methods in the hosted world. */
|
@@ -1369,86 +1355,6 @@ protected boolean isStubBasedPluginsSupported() {
|
1369 | 1355 | return !SubstrateOptions.useLLVMBackend();
|
1370 | 1356 | }
|
1371 | 1357 |
|
1372 |
| - @Platforms(Platform.HOSTED_ONLY.class) |
1373 |
| - static class SubstitutionInvocationPlugins extends InvocationPlugins { |
1374 |
| - |
1375 |
| - private final AnnotationSubstitutionProcessor annotationSubstitutionProcessor; |
1376 |
| - private EconomicMap<String, Integer> missingIntrinsicMetrics; |
1377 |
| - |
1378 |
| - SubstitutionInvocationPlugins(AnnotationSubstitutionProcessor annotationSubstitutionProcessor) { |
1379 |
| - this.annotationSubstitutionProcessor = annotationSubstitutionProcessor; |
1380 |
| - this.missingIntrinsicMetrics = null; |
1381 |
| - } |
1382 |
| - |
1383 |
| - @Override |
1384 |
| - protected void register(Type declaringClass, InvocationPlugin plugin, boolean allowOverwrite) { |
1385 |
| - Type targetClass; |
1386 |
| - if (declaringClass instanceof Class<?> annotatedClass) { |
1387 |
| - targetClass = annotationSubstitutionProcessor.getTargetClass(annotatedClass); |
1388 |
| - if (targetClass != declaringClass) { |
1389 |
| - /* Found a target class. Check if it is included. */ |
1390 |
| - Executable annotatedMethod = plugin.name.equals("<init>") ? resolveConstructor(annotatedClass, plugin) : resolveMethod(annotatedClass, plugin); |
1391 |
| - String originalName = annotationSubstitutionProcessor.findOriginalElementName(annotatedMethod, (Class<?>) targetClass); |
1392 |
| - if (originalName == null) { |
1393 |
| - /* |
1394 |
| - * If the name is null, the element should not be substituted. Thus, we |
1395 |
| - * should also not register the invocation plugin. |
1396 |
| - */ |
1397 |
| - return; |
1398 |
| - } |
1399 |
| - if (!originalName.equals(plugin.name)) { |
1400 |
| - throw VMError.unimplemented(String.format(""" |
1401 |
| - InvocationPlugins cannot yet deal with substitution methods that set the target name via the @TargetElement(name = ...) property. |
1402 |
| - Annotated method "%s" vs target method "%s".""", plugin.name, originalName)); |
1403 |
| - } |
1404 |
| - } |
1405 |
| - } else { |
1406 |
| - targetClass = declaringClass; |
1407 |
| - } |
1408 |
| - super.register(targetClass, plugin, allowOverwrite); |
1409 |
| - } |
1410 |
| - |
1411 |
| - @Override |
1412 |
| - public void notifyNoPlugin(ResolvedJavaMethod targetMethod, OptionValues options) { |
1413 |
| - if (Options.WarnMissingIntrinsic.getValue(options)) { |
1414 |
| - for (Class<?> annotationType : AnnotationAccess.getAnnotationTypes(targetMethod)) { |
1415 |
| - if (ClassUtil.getUnqualifiedName(annotationType).contains("IntrinsicCandidate")) { |
1416 |
| - String method = String.format("%s.%s%s", targetMethod.getDeclaringClass().toJavaName().replace('.', '/'), targetMethod.getName(), |
1417 |
| - targetMethod.getSignature().toMethodDescriptor()); |
1418 |
| - synchronized (this) { |
1419 |
| - if (missingIntrinsicMetrics == null) { |
1420 |
| - missingIntrinsicMetrics = EconomicMap.create(); |
1421 |
| - try { |
1422 |
| - Runtime.getRuntime().addShutdownHook(new Thread(() -> { |
1423 |
| - if (missingIntrinsicMetrics.size() > 0) { |
1424 |
| - System.out.format("[Warning] Missing intrinsics found: %d%n", missingIntrinsicMetrics.size()); |
1425 |
| - List<Pair<String, Integer>> data = new ArrayList<>(); |
1426 |
| - final MapCursor<String, Integer> cursor = missingIntrinsicMetrics.getEntries(); |
1427 |
| - while (cursor.advance()) { |
1428 |
| - data.add(Pair.create(cursor.getKey(), cursor.getValue())); |
1429 |
| - } |
1430 |
| - data.stream().sorted(Comparator.comparing(Pair::getRight, Comparator.reverseOrder())).forEach( |
1431 |
| - pair -> System.out.format(" - %d occurrences during parsing: %s%n", pair.getRight(), pair.getLeft())); |
1432 |
| - } |
1433 |
| - })); |
1434 |
| - } catch (IllegalStateException e) { |
1435 |
| - // shutdown in progress, no need to register the hook |
1436 |
| - } |
1437 |
| - } |
1438 |
| - if (missingIntrinsicMetrics.containsKey(method)) { |
1439 |
| - missingIntrinsicMetrics.put(method, missingIntrinsicMetrics.get(method) + 1); |
1440 |
| - } else { |
1441 |
| - System.out.format("[Warning] Missing intrinsic %s found during parsing.%n", method); |
1442 |
| - missingIntrinsicMetrics.put(method, 1); |
1443 |
| - } |
1444 |
| - } |
1445 |
| - break; |
1446 |
| - } |
1447 |
| - } |
1448 |
| - } |
1449 |
| - } |
1450 |
| - } |
1451 |
| - |
1452 | 1358 | public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, HostedProviders providers, AnalysisMetaAccess aMetaAccess,
|
1453 | 1359 | AnalysisUniverse aUniverse, NativeLibraries nativeLibs, ImageClassLoader loader, ParsingReason reason,
|
1454 | 1360 | AnnotationSubstitutionProcessor annotationSubstitutionProcessor, ClassInitializationPlugin classInitializationPlugin,
|
@@ -1910,134 +1816,6 @@ public BigBang getBigbang() {
|
1910 | 1816 | return bb;
|
1911 | 1817 | }
|
1912 | 1818 |
|
1913 |
| - private void printTypes() { |
1914 |
| - String reportsPath = SubstrateOptions.reportsPath(); |
1915 |
| - ReportUtils.report("hosted universe", reportsPath, "universe_analysis", "txt", |
1916 |
| - writer -> printTypes(writer)); |
1917 |
| - } |
1918 |
| - |
1919 |
| - private void printTypes(PrintWriter writer) { |
1920 |
| - |
1921 |
| - for (HostedType type : hUniverse.getTypes()) { |
1922 |
| - writer.format("%8d %s ", type.getTypeID(), type.toJavaName(true)); |
1923 |
| - if (type.getSuperclass() != null) { |
1924 |
| - writer.format("extends %d %s ", type.getSuperclass().getTypeID(), type.getSuperclass().toJavaName(false)); |
1925 |
| - } |
1926 |
| - if (type.getInterfaces().length > 0) { |
1927 |
| - writer.print("implements "); |
1928 |
| - String sep = ""; |
1929 |
| - for (HostedInterface interf : type.getInterfaces()) { |
1930 |
| - writer.format("%s%d %s", sep, interf.getTypeID(), interf.toJavaName(false)); |
1931 |
| - sep = ", "; |
1932 |
| - } |
1933 |
| - writer.print(" "); |
1934 |
| - } |
1935 |
| - |
1936 |
| - if (type.getWrapped().isInstantiated()) { |
1937 |
| - writer.print("instantiated "); |
1938 |
| - } |
1939 |
| - if (type.getWrapped().isReachable()) { |
1940 |
| - writer.print("reachable "); |
1941 |
| - } |
1942 |
| - |
1943 |
| - if (SubstrateOptions.useClosedTypeWorldHubLayout()) { |
1944 |
| - writer.format("type check start %d range %d slot # %d ", type.getTypeCheckStart(), type.getTypeCheckRange(), type.getTypeCheckSlot()); |
1945 |
| - writer.format("type check slots %s ", slotsToString(type.getClosedTypeWorldTypeCheckSlots())); |
1946 |
| - } else { |
1947 |
| - writer.format("type id %s depth %s num class types %s num interface types %s ", type.getTypeID(), type.getTypeIDDepth(), type.getNumClassTypes(), type.getNumInterfaceTypes()); |
1948 |
| - writer.format("type check slots %s ", String.join(" ", Arrays.stream(type.getOpenTypeWorldTypeCheckSlots()).mapToObj(Integer::toString).toArray(String[]::new))); |
1949 |
| - } |
1950 |
| - // if (type.findLeafConcreteSubtype() != null) { |
1951 |
| - // writer.format("unique %d %s ", type.findLeafConcreteSubtype().getTypeID(), |
1952 |
| - // type.findLeafConcreteSubtype().toJavaName(false)); |
1953 |
| - // } |
1954 |
| - |
1955 |
| - int le = type.getHub().getLayoutEncoding(); |
1956 |
| - if (LayoutEncoding.isPrimitive(le)) { |
1957 |
| - writer.print("primitive "); |
1958 |
| - } else if (LayoutEncoding.isInterface(le)) { |
1959 |
| - writer.print("interface "); |
1960 |
| - } else if (LayoutEncoding.isAbstract(le)) { |
1961 |
| - writer.print("abstract "); |
1962 |
| - } else if (LayoutEncoding.isPureInstance(le)) { |
1963 |
| - writer.format("instance size %d ", LayoutEncoding.getPureInstanceAllocationSize(le).rawValue()); |
1964 |
| - } else if (LayoutEncoding.isArrayLike(le)) { |
1965 |
| - String arrayType = LayoutEncoding.isHybrid(le) ? "hybrid" : "array"; |
1966 |
| - String elements = LayoutEncoding.isArrayLikeWithPrimitiveElements(le) ? "primitives" : "objects"; |
1967 |
| - writer.format("%s containing %s, base %d shift %d scale %d ", arrayType, elements, LayoutEncoding.getArrayBaseOffset(le).rawValue(), LayoutEncoding.getArrayIndexShift(le), |
1968 |
| - LayoutEncoding.getArrayIndexScale(le)); |
1969 |
| - |
1970 |
| - } else { |
1971 |
| - throw VMError.shouldNotReachHereUnexpectedInput(le); // ExcludeFromJacocoGeneratedReport |
1972 |
| - } |
1973 |
| - |
1974 |
| - writer.println(); |
1975 |
| - |
1976 |
| - for (HostedType sub : type.getSubTypes()) { |
1977 |
| - writer.format(" s %d %s%n", sub.getTypeID(), sub.toJavaName(false)); |
1978 |
| - } |
1979 |
| - if (type.isInterface()) { |
1980 |
| - for (HostedMethod method : hUniverse.getMethods()) { |
1981 |
| - if (method.getDeclaringClass().equals(type)) { |
1982 |
| - printMethod(writer, method, -1); |
1983 |
| - } |
1984 |
| - } |
1985 |
| - |
1986 |
| - } else if (type.isInstanceClass()) { |
1987 |
| - |
1988 |
| - HostedField[] fields = type.getInstanceFields(false); |
1989 |
| - fields = Arrays.copyOf(fields, fields.length); |
1990 |
| - Arrays.sort(fields, Comparator.comparing(HostedField::toString)); |
1991 |
| - for (HostedField field : fields) { |
1992 |
| - writer.println(" f " + field.getLocation() + ": " + field.format("%T %n")); |
1993 |
| - } |
1994 |
| - HostedMethod[] vtable = type.getVTable(); |
1995 |
| - for (int i = 0; i < vtable.length; i++) { |
1996 |
| - if (vtable[i] != null) { |
1997 |
| - printMethod(writer, vtable[i], i); |
1998 |
| - } |
1999 |
| - } |
2000 |
| - for (HostedMethod method : hUniverse.getMethods()) { |
2001 |
| - if (method.getDeclaringClass().equals(type) && !method.hasVTableIndex()) { |
2002 |
| - printMethod(writer, method, -1); |
2003 |
| - } |
2004 |
| - } |
2005 |
| - } |
2006 |
| - } |
2007 |
| - |
2008 |
| - } |
2009 |
| - |
2010 |
| - private static void printMethod(PrintWriter writer, HostedMethod method, int vtableIndex) { |
2011 |
| - if (vtableIndex != -1) { |
2012 |
| - writer.print(" v " + vtableIndex + " "); |
2013 |
| - } else { |
2014 |
| - writer.print(" m "); |
2015 |
| - } |
2016 |
| - if (method.hasVTableIndex()) { |
2017 |
| - writer.print(method.getVTableIndex() + " "); |
2018 |
| - } |
2019 |
| - writer.print(method.format("%r %n(%p)") + ": " + method.getImplementations().length + " ["); |
2020 |
| - if (method.getImplementations().length <= 10) { |
2021 |
| - String sep = ""; |
2022 |
| - for (HostedMethod impl : method.getImplementations()) { |
2023 |
| - writer.print(sep + impl.getDeclaringClass().toJavaName(false)); |
2024 |
| - sep = ", "; |
2025 |
| - } |
2026 |
| - } |
2027 |
| - writer.println("]"); |
2028 |
| - } |
2029 |
| - |
2030 |
| - private static String slotsToString(short[] slots) { |
2031 |
| - if (slots == null) { |
2032 |
| - return "null"; |
2033 |
| - } |
2034 |
| - StringBuilder result = new StringBuilder(); |
2035 |
| - for (short slot : slots) { |
2036 |
| - result.append(Short.toUnsignedInt(slot)).append(" "); |
2037 |
| - } |
2038 |
| - return result.toString(); |
2039 |
| - } |
2040 |
| - |
2041 | 1819 | public static Path getOutputDirectory() {
|
2042 | 1820 | return NativeImageGenerator.generatedFiles(HostedOptionValues.singleton());
|
2043 | 1821 | }
|
@@ -2069,29 +1847,4 @@ private static <T extends Enum<T>> Set<T> parseCSVtoEnum(Class<T> enumType, List
|
2069 | 1847 | }
|
2070 | 1848 | return result;
|
2071 | 1849 | }
|
2072 |
| - |
2073 |
| - private static class BuildArtifactsImpl implements BuildArtifacts { |
2074 |
| - private final Map<ArtifactType, List<Path>> buildArtifacts = new EnumMap<>(ArtifactType.class); |
2075 |
| - |
2076 |
| - @Override |
2077 |
| - public void add(ArtifactType type, Path artifact) { |
2078 |
| - buildArtifacts.computeIfAbsent(type, t -> new ArrayList<>()).add(artifact); |
2079 |
| - } |
2080 |
| - |
2081 |
| - @Override |
2082 |
| - public List<Path> get(ArtifactType type) { |
2083 |
| - VMError.guarantee(buildArtifacts.containsKey(type), "Artifact type is missing: %s", type); |
2084 |
| - return buildArtifacts.get(type); |
2085 |
| - } |
2086 |
| - |
2087 |
| - @Override |
2088 |
| - public void forEach(BiConsumer<ArtifactType, List<Path>> action) { |
2089 |
| - buildArtifacts.forEach(action); |
2090 |
| - } |
2091 |
| - |
2092 |
| - @Override |
2093 |
| - public boolean isEmpty() { |
2094 |
| - return buildArtifacts.isEmpty(); |
2095 |
| - } |
2096 |
| - } |
2097 | 1850 | }
|
0 commit comments