63
63
/**
64
64
* Implements reachability metadata tracing during native image execution. Enabling
65
65
* {@link Options#MetadataTracingSupport} at build time will generate code to trace all accesses of
66
- * reachability metadata, and then the run-time option {@link Options#RecordMetadata } enables
66
+ * reachability metadata, and then the run-time option {@link Options#TraceMetadata } enables
67
67
* tracing.
68
68
*/
69
69
public final class MetadataTracer {
70
70
71
71
public static class Options {
72
72
@ Option (help = "Generate an image that supports reachability metadata access tracing. " +
73
- "When tracing is supported, use the -XX:RecordMetadata option to enable tracing at run time." )//
73
+ "When tracing is supported, use the -XX:TraceMetadata option to enable tracing at run time." )//
74
74
public static final HostedOptionKey <Boolean > MetadataTracingSupport = new HostedOptionKey <>(false );
75
75
76
- static final String RECORD_METADATA_HELP = """
76
+ static final String TRACE_METADATA_HELP = """
77
77
Enables metadata tracing at run time. This option is only supported if -H:+MetadataTracingSupport is set when building the image.
78
78
The value of this option is a comma-separated list of arguments specified as key-value pairs. The following arguments are supported:
79
79
80
80
- path=<trace-output-directory> (required): Specifies the directory to write traced metadata to.
81
81
- merge=<boolean> (optional): Specifies whether to merge or overwrite metadata with existing files at the output path (default: true).
82
82
83
83
Example usage:
84
- -H:RecordMetadata =path=trace_output_directory
85
- -H:RecordMetadata =path=trace_output_directory,merge=false
84
+ -H:TraceMetadata =path=trace_output_directory
85
+ -H:TraceMetadata =path=trace_output_directory,merge=false
86
86
""" ;
87
87
88
- @ Option (help = RECORD_METADATA_HELP , stability = OptionStability .EXPERIMENTAL )//
89
- public static final RuntimeOptionKey <String > RecordMetadata = new RuntimeOptionKey <>(null );
88
+ @ Option (help = TRACE_METADATA_HELP , stability = OptionStability .EXPERIMENTAL )//
89
+ public static final RuntimeOptionKey <String > TraceMetadata = new RuntimeOptionKey <>(null );
90
90
}
91
91
92
- private RecordOptions options ;
92
+ private TraceOptions options ;
93
93
94
94
/**
95
95
* The configuration set to trace with. Do not read this field directly when tracing; instead
@@ -120,7 +120,7 @@ public static boolean enabled() {
120
120
}
121
121
122
122
/**
123
- * Returns whether tracing is enabled at run time (using {@code -XX:RecordMetadata }).
123
+ * Returns whether tracing is enabled at run time (using {@code -XX:TraceMetadata }).
124
124
*/
125
125
private boolean enabledAtRunTime () {
126
126
VMError .guarantee (Options .MetadataTracingSupport .getValue ());
@@ -214,10 +214,10 @@ public void traceSerializationType(String className) {
214
214
}
215
215
}
216
216
217
- private static void initialize (String recordMetadataValue ) {
217
+ private static void initialize (String traceMetadataValue ) {
218
218
assert Options .MetadataTracingSupport .getValue ();
219
219
220
- RecordOptions parsedOptions = RecordOptions .parse (recordMetadataValue );
220
+ TraceOptions parsedOptions = TraceOptions .parse (traceMetadataValue );
221
221
try {
222
222
Files .createDirectories (parsedOptions .path ());
223
223
} catch (IOException ex ) {
@@ -229,7 +229,7 @@ private static void initialize(String recordMetadataValue) {
229
229
singleton .config = initializeConfigurationSet (parsedOptions );
230
230
}
231
231
232
- private static ConfigurationSet initializeConfigurationSet (RecordOptions options ) {
232
+ private static ConfigurationSet initializeConfigurationSet (TraceOptions options ) {
233
233
if (options .merge () && Files .exists (options .path ())) {
234
234
ConfigurationFileCollection mergeConfigs = new ConfigurationFileCollection ();
235
235
mergeConfigs .addDirectory (options .path ());
@@ -268,8 +268,8 @@ static RuntimeSupport.Hook initializeMetadataTracingHook() {
268
268
return ;
269
269
}
270
270
VMError .guarantee (Options .MetadataTracingSupport .getValue ());
271
- if (Options .RecordMetadata .hasBeenSet ()) {
272
- initialize (Options .RecordMetadata .getValue ());
271
+ if (Options .TraceMetadata .hasBeenSet ()) {
272
+ initialize (Options .TraceMetadata .getValue ());
273
273
}
274
274
};
275
275
}
@@ -280,7 +280,7 @@ static RuntimeSupport.Hook shutDownMetadataTracingHook() {
280
280
return ;
281
281
}
282
282
VMError .guarantee (Options .MetadataTracingSupport .getValue ());
283
- if (Options .RecordMetadata .hasBeenSet ()) {
283
+ if (Options .TraceMetadata .hasBeenSet ()) {
284
284
shutdown ();
285
285
}
286
286
};
@@ -295,29 +295,29 @@ static RuntimeSupport.Hook checkImproperOptionUsageHook() {
295
295
return ;
296
296
}
297
297
VMError .guarantee (!Options .MetadataTracingSupport .getValue ());
298
- if (Options .RecordMetadata .hasBeenSet ()) {
298
+ if (Options .TraceMetadata .hasBeenSet ()) {
299
299
throw new IllegalArgumentException (
300
- "The option " + Options .RecordMetadata .getName () + " can only be used if metadata tracing is enabled at build time (using " +
300
+ "The option " + Options .TraceMetadata .getName () + " can only be used if metadata tracing is enabled at build time (using " +
301
301
hostedOptionCommandArgument + ")." );
302
302
}
303
303
};
304
304
}
305
305
}
306
306
307
- record RecordOptions (Path path , boolean merge ) {
307
+ record TraceOptions (Path path , boolean merge ) {
308
308
309
309
private static final int ARGUMENT_PARTS = 2 ;
310
310
311
- static RecordOptions parse (String recordMetadataValue ) {
312
- if (recordMetadataValue .isEmpty ()) {
313
- throw printHelp ("Option " + MetadataTracer .Options .RecordMetadata .getName () + " cannot be empty." );
314
- } else if (recordMetadataValue .equals ("help" )) {
315
- throw printHelp ("Option " + MetadataTracer .Options .RecordMetadata .getName () + " value is 'help'. Printing a description and aborting." );
311
+ static TraceOptions parse (String traceMetadataValue ) {
312
+ if (traceMetadataValue .isEmpty ()) {
313
+ throw printHelp ("Option " + MetadataTracer .Options .TraceMetadata .getName () + " cannot be empty." );
314
+ } else if (traceMetadataValue .equals ("help" )) {
315
+ throw printHelp ("Option " + MetadataTracer .Options .TraceMetadata .getName () + " value is 'help'. Printing a description and aborting." );
316
316
}
317
317
318
318
Map <String , String > parsedArguments = new HashMap <>();
319
319
Set <String > allArguments = new LinkedHashSet <>(List .of ("path" , "merge" ));
320
- for (String argument : recordMetadataValue .split ("," )) {
320
+ for (String argument : traceMetadataValue .split ("," )) {
321
321
String [] parts = SubstrateUtil .split (argument , "=" , ARGUMENT_PARTS );
322
322
if (parts .length != ARGUMENT_PARTS ) {
323
323
throw badArgumentError (argument , "Argument should be a key-value pair separated by '='" );
@@ -333,7 +333,7 @@ static RecordOptions parse(String recordMetadataValue) {
333
333
334
334
String path = requiredArgument (parsedArguments , "path" , IDENTITY_PARSER );
335
335
boolean merge = optionalArgument (parsedArguments , "merge" , true , BOOLEAN_PARSER );
336
- return new RecordOptions (Paths .get (path ), merge );
336
+ return new TraceOptions (Paths .get (path ), merge );
337
337
}
338
338
339
339
private static IllegalArgumentException printHelp (String errorMessage ) {
@@ -343,15 +343,15 @@ private static IllegalArgumentException printHelp(String errorMessage) {
343
343
%s description:
344
344
345
345
%s
346
- """ .formatted (errorMessage , MetadataTracer .Options .RecordMetadata .getName (), MetadataTracer .Options .RECORD_METADATA_HELP ));
346
+ """ .formatted (errorMessage , MetadataTracer .Options .TraceMetadata .getName (), MetadataTracer .Options .TRACE_METADATA_HELP ));
347
347
}
348
348
349
349
private static IllegalArgumentException parseError (String message ) {
350
- return new IllegalArgumentException (message + ". For more information (including usage examples), pass 'help' as an argument to " + MetadataTracer .Options .RecordMetadata .getName () + "." );
350
+ return new IllegalArgumentException (message + ". For more information (including usage examples), pass 'help' as an argument to " + MetadataTracer .Options .TraceMetadata .getName () + "." );
351
351
}
352
352
353
353
private static IllegalArgumentException badArgumentError (String argument , String message ) {
354
- throw parseError ("Bad argument provided for " + MetadataTracer .Options .RecordMetadata .getName () + ": '" + argument + "'. " + message );
354
+ throw parseError ("Bad argument provided for " + MetadataTracer .Options .TraceMetadata .getName () + ": '" + argument + "'. " + message );
355
355
}
356
356
357
357
private static IllegalArgumentException badArgumentValueError (String argumentKey , String argumentValue , String message ) {
@@ -373,7 +373,7 @@ private static <T> T requiredArgument(Map<String, String> arguments, String key,
373
373
if (arguments .containsKey (key )) {
374
374
return parser .parse (key , arguments .get (key ));
375
375
}
376
- throw parseError (MetadataTracer .Options .RecordMetadata .getName () + " missing required argument '" + key + "'" );
376
+ throw parseError (MetadataTracer .Options .TraceMetadata .getName () + " missing required argument '" + key + "'" );
377
377
}
378
378
379
379
private static <T > T optionalArgument (Map <String , String > options , String key , T defaultValue , ArgumentParser <T > parser ) {
0 commit comments