From 32d1cb0c0a6966d0b84c8109adb1827c358f5623 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 28 Jan 2022 12:07:28 +0100 Subject: [PATCH 1/3] Re-introduce and deprecate JDK8OrEarlier and JDK11OrLater. --- substratevm/CHANGELOG.md | 1 + .../com/oracle/svm/core/jdk/JDK11OrLater.java | 35 +++++++++++++++++++ .../oracle/svm/core/jdk/JDK8OrEarlier.java | 35 +++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrLater.java create mode 100644 substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK8OrEarlier.java diff --git a/substratevm/CHANGELOG.md b/substratevm/CHANGELOG.md index cb4ae24f1abe..14982467ed82 100644 --- a/substratevm/CHANGELOG.md +++ b/substratevm/CHANGELOG.md @@ -4,6 +4,7 @@ This changelog summarizes major changes to GraalVM Native Image. ## Version 22.1.0 * (GR-35898) Improved handling of static synchronized methods: the lock is no longer stored in the secondary monitor map, but in the mutable DynamicHubCompanion object. +* Remove support for JDK8. As a result, `JDK8OrEarlier` and `JDK11OrLater` have been deprecated and will be removed in a future release. ## Version 22.0.0 * (GR-33930) Decouple HostedOptionParser setup from classpath/modulepath scanning (use ServiceLoader for collecting options). diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrLater.java new file mode 100644 index 000000000000..dfd84852a9bf --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK11OrLater.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 2022, 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; + +import java.util.function.BooleanSupplier; + +@Deprecated(since = "22.1.0", forRemoval = true) +public class JDK11OrLater implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return true; + } +} diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK8OrEarlier.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK8OrEarlier.java new file mode 100644 index 000000000000..cc707ee552b0 --- /dev/null +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JDK8OrEarlier.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018, 2022, 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; + +import java.util.function.BooleanSupplier; + +@Deprecated(since = "22.1.0", forRemoval = true) +public class JDK8OrEarlier implements BooleanSupplier { + @Override + public boolean getAsBoolean() { + return false; + } +} From d9926bea76c11f46ade6ebac86b703d59bf0e51b Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 28 Jan 2022 12:08:59 +0100 Subject: [PATCH 2/3] Fix build output when BigBang is unavailable/null. --- .../src/com/oracle/svm/hosted/ProgressReporter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java index 78483e0773b8..f66c1d2301d1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java @@ -515,7 +515,7 @@ public void printEpilog(String imageName, NativeImageGenerator generator, boolea l().a(" ").link(p).dim().a(" (").a(artifactType.name().toLowerCase()).a(")").reset().flushln(); } }); - if (ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(parsedHostedOptions)) { + if (generator.getBigbang() != null && ImageBuildStatistics.Options.CollectImageBuildStatistics.getValue(parsedHostedOptions)) { l().a(" ").link(reportImageBuildStatistics(imageName, generator.getBigbang())).flushln(); } l().a(" ").link(reportBuildArtifacts(imageName, generator.getBuildArtifacts())).flushln(); From a6065a9a773dac6049f37efa7d2fd8c371598499 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Fri, 28 Jan 2022 13:25:46 +0100 Subject: [PATCH 3/3] Show code metadata in heap breakdown. --- .../native-image/BuildOutput.md | 40 ++++++++++--------- .../oracle/svm/core/code/ImageCodeInfo.java | 4 ++ .../oracle/svm/hosted/ProgressReporter.java | 4 ++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/docs/reference-manual/native-image/BuildOutput.md b/docs/reference-manual/native-image/BuildOutput.md index 5fd01181dac5..682136100d8a 100644 --- a/docs/reference-manual/native-image/BuildOutput.md +++ b/docs/reference-manual/native-image/BuildOutput.md @@ -33,17 +33,17 @@ GraalVM Native Image: Generating 'helloworld'... 13.57MB in total -------------------------------------------------------------------------------- Top 10 packages in code area: Top 10 object types in image heap: - 606.23KB java.util 1.64MB byte[] for general heap data - 282.34KB java.lang 715.56KB java.lang.String - 222.47KB java.util.regex 549.46KB java.lang.Class - 219.55KB java.text 451.79KB byte[] for java.lang.String - 193.17KB com.oracle.svm.jni 363.23KB java.util.HashMap$Node - 149.80KB java.util.concurrent 192.00KB java.util.HashMap$Node[] - 118.07KB java.math 139.83KB java.lang.String[] - 103.60KB com.oracle.svm.core.reflect 139.04KB char[] - 97.83KB sun.text.normalizer 130.59KB j.u.c.ConcurrentHashMap$Node - 88.78KB c.oracle.svm.core.genscavenge 103.92KB s.u.l.LocaleObjec~e$CacheEntry - ... 111 additional packages ... 723 additional object types + 607.28KB java.util 862.66KB byte[] for general heap data + 288.63KB java.lang 834.02KB byte[] for code metadata + 223.34KB java.util.regex 723.00KB java.lang.String + 220.45KB java.text 534.05KB java.lang.Class + 194.21KB com.oracle.svm.jni 457.63KB byte[] for java.lang.String + 153.69KB java.util.concurrent 363.75KB java.util.HashMap$Node + 118.78KB java.math 192.70KB java.util.HashMap$Node[] + 99.00KB com.oracle.svm.core.reflect 140.03KB java.lang.String[] + 98.21KB sun.text.normalizer 139.04KB char[] + 89.95KB c.oracle.svm.core.genscavenge 132.78KB c.o.s.c.h.DynamicHubCompanion + ... 112 additional packages ... 734 additional object types (use GraalVM Dashboard to see all) -------------------------------------------------------------------------------- 0.9s (5.6% of total time) in 17 GCs | Peak RSS: 3.22GB | CPU load: 10.87 @@ -114,24 +114,28 @@ Debug info is also generated as part of this stage (if requested). #### Code Area The code area contains machine code produced by the Graal compiler for all reachable methods. -Therefore, reducing the number of reachable methods also reduces the size of the code area. +Therefore, reducing the number of [reachable methods](#glossary-reachability) also reduces the size of the code area. #### Image Heap The image heap contains reachable objects such as static data, classes initialized at run-time, and `byte[]` for different purposes. ##### General Heap Data Stored in `byte[]` -The total size of all `byte[]` objects that are neither used for `java.lang.String`, nor [graph encodings](#glossary-graph-encodings), nor [method metadata](#glossary-method-metadata). -This typically dominates +The total size of all `byte[]` objects that are neither used for `java.lang.String`, nor [code metadata](#glossary-code-metadata), nor [method metadata](#glossary-method-metadata), nor [graph encodings](#glossary-graph-encodings). +Therefore, this can also include `byte[]` objects from application code. -##### Graph Encodings Stored in `byte[]` -The total size of all `byte[]` objects used for graph encodings. -These encodings are a result of [runtime compiled methods](#glossary-runtime-methods). -Therefore, reducing the number of such methods also reduces the size of corresponding graph encodings. +##### Code Metadata Stored in `byte[]` +The total size of all `byte[]` objects used for metadata for the [code area](#glossary-code-area). +Therefore, reducing the number of [reachable methods](#glossary-reachability) also reduces the size of this metadata. ##### Method Metadata Stored in `byte[]` The total size of all `byte[]` objects used for method metadata, a type of reflection metadata. To reduce the amount of method metadata, reduce the number of [classes registered for reflection](#glossary-reflection-classes). +##### Graph Encodings Stored in `byte[]` +The total size of all `byte[]` objects used for graph encodings. +These encodings are a result of [runtime compiled methods](#glossary-runtime-methods). +Therefore, reducing the number of such methods also reduces the size of corresponding graph encodings. + #### Debug Info The total size of generated debug information (if enabled). diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java index cd7c4bfda8f6..c926a520ea08 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/ImageCodeInfo.java @@ -109,6 +109,10 @@ public HostedImageCodeInfo getHostedImageCodeInfo() { return hostedImageCodeInfo; } + public long getTotalByteArraySize() { + return codeInfoIndex.length + codeInfoEncodings.length + referenceMapEncoding.length + frameInfoEncodings.length; + } + /** * Pure-hosted {@link CodeInfo} to collect and persist image code metadata in * {@link ImageCodeInfo} and provide accesses during image generation. diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java index f66c1d2301d1..131c637c52d5 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ProgressReporter.java @@ -65,6 +65,7 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.VM; import com.oracle.svm.core.annotate.AutomaticFeature; +import com.oracle.svm.core.code.CodeInfoTable; import com.oracle.svm.core.option.HostedOptionValues; import com.oracle.svm.core.reflect.MethodMetadataDecoder; import com.oracle.svm.core.util.VMError; @@ -489,6 +490,9 @@ private Map calculateHeapBreakdown(Collection heapObje long remainingBytes = byteArraySize; classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + "java.lang.String", stringByteLength); remainingBytes -= stringByteLength; + long codeInfoSize = CodeInfoTable.getImageCodeCache().getTotalByteArraySize(); + classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linePrinter.asDocLink("code metadata", "#glossary-code-metadata"), codeInfoSize); + remainingBytes -= codeInfoSize; long metadataByteLength = ImageSingletons.lookup(MethodMetadataDecoder.class).getMetadataByteLength(); if (metadataByteLength > 0) { classNameToSize.put(BREAKDOWN_BYTE_ARRAY_PREFIX + linePrinter.asDocLink("method metadata", "#glossary-method-metadata"), metadataByteLength);