@@ -66,7 +66,7 @@ public static class Options {
66
66
public static final RuntimeOptionKey <String > RecordMetadata = new RuntimeOptionKey <>("" );
67
67
}
68
68
69
- private ConfigurationSet config ;
69
+ private volatile ConfigurationSet config ;
70
70
71
71
private Path recordMetadataPath ;
72
72
@@ -75,36 +75,75 @@ public static MetadataTracer singleton() {
75
75
return ImageSingletons .lookup (MetadataTracer .class );
76
76
}
77
77
78
+ /**
79
+ * Returns whether tracing is enabled at run time (using {@code -XX:RecordMetadata=path}).
80
+ */
78
81
public boolean enabled () {
79
82
VMError .guarantee (Options .MetadataTracingSupport .getValue ());
80
- return config != null ;
83
+ return recordMetadataPath != null ;
81
84
}
82
85
86
+ /**
87
+ * Marks the given type as reachable from reflection.
88
+ *
89
+ * @return the corresponding {@link ConfigurationType} or {@code null} if tracing is not active
90
+ * (e.g., during shutdown).
91
+ */
83
92
public ConfigurationType traceReflectionType (String className ) {
84
93
assert enabled ();
85
- return config .getReflectionConfiguration ().getOrCreateType (UnresolvedConfigurationCondition .alwaysTrue (), new NamedConfigurationTypeDescriptor (className ));
94
+ ConfigurationSet configurationSet = config ;
95
+ if (configurationSet != null ) {
96
+ return configurationSet .getReflectionConfiguration ().getOrCreateType (UnresolvedConfigurationCondition .alwaysTrue (), new NamedConfigurationTypeDescriptor (className ));
97
+ }
98
+ return null ;
86
99
}
87
100
101
+ /**
102
+ * Marks the given type as reachable from JNI.
103
+ *
104
+ * @return the corresponding {@link ConfigurationType} or {@code null} if tracing is not active
105
+ * (e.g., during shutdown).
106
+ */
88
107
public ConfigurationType traceJNIType (String className ) {
89
108
assert enabled ();
90
109
ConfigurationType result = traceReflectionType (className );
91
- result .setJniAccessible ();
110
+ if (result != null ) {
111
+ result .setJniAccessible ();
112
+ }
92
113
return result ;
93
114
}
94
115
116
+ /**
117
+ * Marks the given resource within the given (optional) module as reachable.
118
+ */
95
119
public void traceResource (String resourceName , String moduleName ) {
96
120
assert enabled ();
97
- config .getResourceConfiguration ().addGlobPattern (UnresolvedConfigurationCondition .alwaysTrue (), resourceName , moduleName );
121
+ ConfigurationSet configurationSet = config ;
122
+ if (configurationSet != null ) {
123
+ configurationSet .getResourceConfiguration ().addGlobPattern (UnresolvedConfigurationCondition .alwaysTrue (), resourceName , moduleName );
124
+ }
98
125
}
99
126
127
+ /**
128
+ * Marks the given resource bundle within the given locale as reachable.
129
+ */
100
130
public void traceResourceBundle (String baseName ) {
101
131
assert enabled ();
102
- config .getResourceConfiguration ().addBundle (UnresolvedConfigurationCondition .alwaysTrue (), baseName , List .of ());
132
+ ConfigurationSet configurationSet = config ;
133
+ if (configurationSet != null ) {
134
+ configurationSet .getResourceConfiguration ().addBundle (UnresolvedConfigurationCondition .alwaysTrue (), baseName , List .of ());
135
+ }
103
136
}
104
137
138
+ /**
139
+ * Marks the given type as serializable.
140
+ */
105
141
public void traceSerializationType (String className ) {
106
142
assert enabled ();
107
- config .getReflectionConfiguration ().getOrCreateType (UnresolvedConfigurationCondition .alwaysTrue (), new NamedConfigurationTypeDescriptor (className )).setSerializable ();
143
+ ConfigurationSet configurationSet = config ;
144
+ if (configurationSet != null ) {
145
+ configurationSet .getReflectionConfiguration ().getOrCreateType (UnresolvedConfigurationCondition .alwaysTrue (), new NamedConfigurationTypeDescriptor (className )).setSerializable ();
146
+ }
108
147
}
109
148
110
149
private static void initialize () {
@@ -128,6 +167,7 @@ private static void shutdown() {
128
167
assert Options .MetadataTracingSupport .getValue ();
129
168
MetadataTracer singleton = MetadataTracer .singleton ();
130
169
ConfigurationSet config = singleton .config ;
170
+ singleton .config = null ; // clear config so that shutdown events are not traced.
131
171
if (config != null ) {
132
172
try {
133
173
config .writeConfiguration (configFile -> singleton .recordMetadataPath .resolve (configFile .getFileName ()));
0 commit comments