Skip to content

Commit df624d2

Browse files
committed
[GR-64030] Added support for compressing option help text in libgraal image.
PullRequest: graal/20486
2 parents 4fda18a + 9470778 commit df624d2

File tree

19 files changed

+261
-102
lines changed

19 files changed

+261
-102
lines changed

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalFeature.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void afterAnalysis(AfterAnalysisAccess access) {
232232
Map<String, String> modules = libgraalLoader.getClassModuleMap();
233233
for (OptionKey<?> option : options) {
234234
OptionDescriptor descriptor = option.getDescriptor();
235-
if (descriptor != null && descriptor.getContainer().optionsAreServiceLoadable()) {
235+
if (descriptor != null && descriptor.getContainer().optionsAreDiscoverable()) {
236236
GraalError.guarantee(access.isReachable(option.getClass()), "%s", option.getClass());
237237
GraalError.guarantee(access.isReachable(descriptor.getClass()), "%s", descriptor.getClass());
238238

@@ -252,6 +252,7 @@ void afterAnalysis(AfterAnalysisAccess access) {
252252
}
253253
}
254254
}
255+
OptionDescriptor.sealHelpStrings();
255256
}
256257
}
257258

compiler/src/jdk.graal.compiler.libgraal/src/jdk/graal/compiler/libgraal/LibGraalSupportImpl.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ public void printOptions(PrintStream out, String namePrefix) {
218218
d.valueType(),
219219
assign,
220220
"[community edition]",
221-
d.help(),
222-
List.of());
221+
List.of(d.help()));
223222
});
224223
}
225224

compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/options/processor/OptionProcessor.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,11 @@ private void processElement(Element element, OptionsDeclarer optionsDeclarer) {
213213
}
214214

215215
String briefHelp = helpLines.getFirst();
216-
List<String> extraHelp;
217216
if (briefHelp.isEmpty()) {
218217
if (helpLines.size() > 1) {
219218
processingEnv.getMessager().printMessage(Kind.ERROR, "First line of multi-line help text cannot be empty", element);
220219
return;
221220
}
222-
extraHelp = List.of();
223221
} else {
224222
if (helpLines.size() > 1) {
225223
if (briefHelp.charAt(briefHelp.length() - 1) != '.' && !helpLines.get(1).isBlank()) {
@@ -233,7 +231,6 @@ private void processElement(Element element, OptionsDeclarer optionsDeclarer) {
233231
processingEnv.getMessager().printMessage(Kind.ERROR, "Option help text must start with an upper case letter", element);
234232
return;
235233
}
236-
extraHelp = helpLines.subList(1, helpLines.size());
237234
}
238235

239236
String stability = getAnnotationValue(annotation, "stability", VariableElement.class).getSimpleName().toString();
@@ -252,12 +249,16 @@ private void processElement(Element element, OptionsDeclarer optionsDeclarer) {
252249
}
253250
boolean deprecated = getAnnotationValue(annotation, "deprecated", Boolean.class);
254251
String deprecationMessage = getAnnotationValue(annotation, "deprecationMessage", String.class);
255-
OptionInfo info = new OptionInfo(optionName, optionTypeName, briefHelp, extraHelp, optionType, declaringClass, fieldName, stability, deprecated, deprecationMessage);
252+
OptionInfo info = new OptionInfo(optionName, optionTypeName, String.join("\n", helpLines), optionType, declaringClass, fieldName, stability, deprecated, deprecationMessage);
256253
optionsDeclarer.options.add(info);
257254
}
258255

259256
private static String literal(String help) {
260-
return "\"" + help.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
257+
String quoted = help.replace("\\", "\\\\").replace("\"", "\\\"");
258+
if (help.indexOf('\n') != -1) {
259+
return "\"\"\"\n" + quoted + "\"\"\"";
260+
}
261+
return "\"" + quoted + "\"";
261262
}
262263

263264
static void createOptionsDescriptorsFile(ProcessingEnvironment processingEnv, OptionsDeclarer optionsDeclarer) {
@@ -310,7 +311,6 @@ static void createOptionsDescriptorsFile(ProcessingEnvironment processingEnv, Op
310311
String optionType = option.optionType;
311312
String type = option.type;
312313
String help = option.help;
313-
List<String> extraHelp = option.extraHelp;
314314
String fieldName = option.field;
315315
String stability = option.stability;
316316
boolean deprecated = option.deprecated;
@@ -320,16 +320,9 @@ static void createOptionsDescriptorsFile(ProcessingEnvironment processingEnv, Op
320320
out.printf(" /*optionType*/ %s.%s,\n", getSimpleName(OPTION_TYPE_CLASS_NAME), optionType);
321321
out.printf(" /*optionValueType*/ %s.class,\n", type);
322322
out.printf(" /*help*/ %s,\n", literal(help));
323-
if (!extraHelp.isEmpty()) {
324-
out.printf(" /*extraHelp*/ new String[] {\n");
325-
for (String line : extraHelp) {
326-
out.printf(" %s,\n", literal(line));
327-
}
328-
out.printf(" },\n");
329-
}
330323
out.printf(" /*container*/ getContainer(),\n");
331-
out.printf(" /*fieldName*/ \"%s\",\n", fieldName);
332324
out.printf(" /*option*/ %s,\n", optionField);
325+
out.printf(" /*fieldName*/ \"%s\",\n", fieldName);
333326
out.printf(" /*stability*/ %s.%s,\n", getSimpleName(OPTION_STABILITY_CLASS_NAME), stability);
334327
out.printf(" /*deprecated*/ %b,\n", deprecated);
335328
out.printf(" /*deprecationMessage*/ \"%s\");\n", deprecationMessage);
@@ -368,7 +361,7 @@ static void createOptionsDescriptorsFile(ProcessingEnvironment processingEnv, Op
368361
/**
369362
* The details of a single option, derived from an {@code @Option} annotated field.
370363
*/
371-
record OptionInfo(String name, String optionType, String help, List<String> extraHelp, String type,
364+
record OptionInfo(String name, String optionType, String help, String type,
372365
String declaringClass, String field, String stability, boolean deprecated,
373366
String deprecationMessage) implements Comparable<OptionInfo> {
374367

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/ReflectionOptionDescriptors.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public ReflectionOptionDescriptors(Class<?> declaringClass, String... fieldsAndH
9595

9696
private void addOption(String fieldName, String help) {
9797
try {
98-
Field f = container.getDeclaringClass().getDeclaredField(fieldName);
98+
Field f = container.declaringClass().getDeclaredField(fieldName);
9999
if (!OptionKey.class.isAssignableFrom(f.getType())) {
100100
throw new IllegalArgumentException(String.format("Option field must be of type %s: %s", OptionKey.class.getName(), f));
101101
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/hotspot/test/CompileTheWorld.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public static EconomicMap<OptionKey<?>, Object> parseOptions(String options) {
146146
for (String optionSetting : options.split("\\s+|#")) {
147147
OptionsParser.parseOptionSettingTo(optionSetting, optionSettings);
148148
}
149-
Iterable<OptionDescriptors> loader = OptionsContainer.load(OptionDescriptors.class.getClassLoader());
149+
Iterable<OptionDescriptors> loader = OptionsContainer.getDiscoverableOptions(OptionDescriptors.class.getClassLoader());
150150
OptionsParser.parseOptions(optionSettings, values, loader);
151151
}
152152
if (!values.containsKey(HighTier.Options.Inline)) {

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/options/test/TestOptionKey.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,13 @@ public static class Options {
111111
/*name*/ "MyDeprecatedOption",
112112
/*optionType*/ OptionType.User,
113113
/*optionValueType*/ String.class,
114-
/*help*/ "Help for MyDeprecatedOption with",
115-
/*extraHelp*/ new String[] {
116-
"some extra text on",
117-
"following lines.",
118-
},
114+
/*help*/ """
115+
Help for MyDeprecatedOption with
116+
some extra text on
117+
following lines.""",
119118
/*declaringClass*/ Options.class,
120-
/*fieldName*/ "MyDeprecatedOption",
121119
/*option*/ MyDeprecatedOption,
120+
/*fieldName*/ "MyDeprecatedOption",
122121
/*stability*/ OptionStability.EXPERIMENTAL,
123122
/*deprecated*/ true,
124123
/*deprecationMessage*/ "Some deprecation message"));
@@ -401,8 +400,9 @@ public void testOptionDescriptors() {
401400
Assert.assertTrue(desc.isDeprecated());
402401
Assert.assertEquals(desc.getOptionType(), OptionType.User);
403402
Assert.assertEquals(desc.getDeprecationMessage(), "Some deprecation message");
404-
Assert.assertEquals(desc.getHelp(), "Help for MyDeprecatedOption with");
405-
Assert.assertEquals(desc.getExtraHelp(), List.of("some extra text on", "following lines."));
403+
List<String> help = desc.getHelp();
404+
Assert.assertEquals(help.getFirst(), "Help for MyDeprecatedOption with");
405+
Assert.assertEquals(help.subList(1, help.size()), List.of("some extra text on", "following lines."));
406406
Assert.assertEquals(desc.getLocation(), Options.class.getName() + ".MyDeprecatedOption");
407407

408408
EconomicMap<String, OptionDescriptor> map = EconomicMap.create();

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/debug/DebugOptions.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public enum OptimizationLogTarget {
245245
The accepted values are:
246246
File - Dump IGV graphs to the local file system (see DumpPath).
247247
Network - Dump IGV graphs to the network destination specified by PrintGraphHost and PrintGraphPort.
248-
If a network connection cannot be opened, dumping falls back to file dumping.\s
248+
If a network connection cannot be opened, dumping falls back to file dumping.
249249
Disable - Do not dump IGV graphs.""", type = OptionType.Debug)
250250
public static final EnumOptionKey<PrintGraphTarget> PrintGraph = new EnumOptionKey<>(PrintGraphTarget.File);
251251

0 commit comments

Comments
 (0)