Skip to content

Commit e97f9e9

Browse files
committed
provide flag ReportUsedMetadataFiles to print all parsed metadata files
1 parent 89aa75c commit e97f9e9

3 files changed

Lines changed: 89 additions & 0 deletions

File tree

substratevm/src/com.oracle.svm.configure/src/com/oracle/svm/configure/ConfigurationParser.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public static InputStream openStream(URI uri) throws IOException {
8383
public static final String BUNDLE_KEY = "bundle";
8484
private final EconomicMap<String, EconomicSet<String>> seenUnknownAttributesByType = EconomicMap.create();
8585
private final EnumSet<ConfigurationParserOption> parserOptions;
86+
private static EconomicSet<String> usedMetadataFiles = EconomicSet.create();
8687

8788
protected ConfigurationParser(EnumSet<ConfigurationParserOption> parserOptions) {
8889
this.parserOptions = parserOptions;
@@ -106,6 +107,7 @@ protected final boolean checkOption(ConfigurationParserOption option) {
106107
public void parseAndRegister(URI uri) throws IOException {
107108
try (Reader reader = openReader(uri)) {
108109
parseAndRegister(new JsonParser(reader).parse(), uri);
110+
reportUsedMetadataFile(uri); // report if successfully parsed
109111
} catch (FileNotFoundException e) {
110112
/*
111113
* Ignore: *-config.json files can be missing when reachability-metadata.json is
@@ -114,6 +116,23 @@ public void parseAndRegister(URI uri) throws IOException {
114116
}
115117
}
116118

119+
private static void reportUsedMetadataFile(URI uri) {
120+
// usedMetadataFiles should not be null in regular usecases, unless already read
121+
// OmitPreviousConfigTests is an example where this unfortunately happens.
122+
if (usedMetadataFiles != null) {
123+
usedMetadataFiles.add(uri.toString());
124+
}
125+
}
126+
127+
public static EconomicSet<String> getUsedMetadataFiles() {
128+
if (usedMetadataFiles == null) {
129+
return null;
130+
}
131+
EconomicSet<String> set = usedMetadataFiles;
132+
usedMetadataFiles = null; // avoid retaining memory here
133+
return set;
134+
}
135+
117136
protected static BufferedReader openReader(URI uri) throws IOException {
118137
return new BufferedReader(new InputStreamReader(openStream(uri)));
119138
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,9 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, String ol
13921392
@Option(help = "Enable runtime instantiation of reflection objects for non-invoked methods.", type = OptionType.Expert, deprecated = true)//
13931393
public static final HostedOptionKey<Boolean> ConfigureReflectionMetadata = new HostedOptionKey<>(true);
13941394

1395+
@Option(help = "Print a list of parsed metadata configuration files.", type = OptionType.Expert)//
1396+
public static final HostedOptionKey<Boolean> ReportUsedMetadataFiles = new HostedOptionKey<>(false);
1397+
13951398
@Option(help = "Include a list of methods included in the image for runtime inspection.", type = OptionType.Expert)//
13961399
public static final HostedOptionKey<Boolean> IncludeMethodData = new HostedOptionKey<>(false);
13971400

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2026, 2026, 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.hosted;
26+
27+
import com.oracle.graal.pointsto.reports.ReportUtils;
28+
import com.oracle.svm.configure.ConfigurationParser;
29+
import com.oracle.svm.core.SubstrateOptions;
30+
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
31+
import com.oracle.svm.core.feature.InternalFeature;
32+
import org.graalvm.collections.EconomicSet;
33+
34+
import java.io.File;
35+
import java.io.PrintWriter;
36+
import java.util.Collections;
37+
import java.util.List;
38+
39+
@AutomaticallyRegisteredFeature
40+
public class ReportUsedMetadataFilesFeature implements InternalFeature {
41+
42+
private EconomicSet<String> usedMetadataFiles;
43+
private boolean completed = false;
44+
45+
@Override
46+
public void duringAnalysis(DuringAnalysisAccess access) {
47+
// get the set in any case to clean up memory in the parser
48+
usedMetadataFiles = ConfigurationParser.getUsedMetadataFiles();
49+
if (SubstrateOptions.ReportUsedMetadataFiles.getValue() && !completed) {
50+
File file = ReportUtils.reportFile(SubstrateOptions.reportsPath(), "usedMetadataFiles", "txt");
51+
ReportUtils.report("usedMetadataFiles", file.toPath(), this::printMetadataFiles);
52+
}
53+
}
54+
55+
private void printMetadataFiles(PrintWriter out) {
56+
if (usedMetadataFiles != null) {
57+
List<String> files = usedMetadataFiles.toList();
58+
Collections.sort(files);
59+
for (String file : files) {
60+
out.println("used metadata: " + file);
61+
}
62+
} else {
63+
out.println("no metadata file used");
64+
}
65+
completed = true;
66+
}
67+
}

0 commit comments

Comments
 (0)