Skip to content

Commit ae9af57

Browse files
committed
8264001: JFR: Modernize implementation
Reviewed-by: mgronlun
1 parent fad8484 commit ae9af57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+239
-322
lines changed

src/jdk.jfr/share/classes/jdk/jfr/AnnotationElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public final class AnnotationElement {
100100
}
101101
checkType(Utils.unboxType(valueType));
102102
}
103-
this.annotationValues = Utils.smallUnmodifiable(objects);
103+
this.annotationValues = List.copyOf(objects);
104104
this.inBootClassLoader = boot;
105105
}
106106

@@ -203,7 +203,7 @@ public AnnotationElement(Class<? extends Annotation> annotationType, Map<String,
203203
}
204204
v.add(object);
205205
}
206-
this.annotationValues = Utils.smallUnmodifiable(v);
206+
this.annotationValues = List.copyOf(v);
207207
this.inBootClassLoader = annotationType.getClassLoader() == null;
208208
}
209209

src/jdk.jfr/share/classes/jdk/jfr/Configuration.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
import java.nio.file.Files;
3131
import java.nio.file.Path;
3232
import java.text.ParseException;
33-
import java.util.ArrayList;
34-
import java.util.Collections;
3533
import java.util.LinkedHashMap;
3634
import java.util.List;
3735
import java.util.Map;
@@ -190,8 +188,8 @@ public static Configuration getConfiguration(String name) throws IOException, Pa
190188
*/
191189
public static List<Configuration> getConfigurations() {
192190
if (JVMSupport.isNotAvailable()) {
193-
return new ArrayList<>();
191+
return List.of();
194192
}
195-
return Collections.unmodifiableList(JFC.getConfigurations());
193+
return List.copyOf(JFC.getConfigurations());
196194
}
197195
}

src/jdk.jfr/share/classes/jdk/jfr/Event.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ protected Event() {
9797
/**
9898
* Starts the timing of this event.
9999
*/
100+
@Override
100101
final public void begin() {
101102
}
102103

@@ -105,6 +106,7 @@ final public void begin() {
105106
*
106107
* The {@code end} method must be invoked after the {@code begin} method.
107108
*/
109+
@Override
108110
final public void end() {
109111
}
110112

@@ -116,6 +118,7 @@ final public void end() {
116118
* not end with an explicit invocation of the {@code end} method, then the event
117119
* ends when the {@code commit} method is invoked.
118120
*/
121+
@Override
119122
final public void commit() {
120123
}
121124

@@ -126,6 +129,7 @@ final public void commit() {
126129
*
127130
* @return {@code true} if event is enabled, {@code false} otherwise
128131
*/
132+
@Override
129133
final public boolean isEnabled() {
130134
return false;
131135
}
@@ -139,6 +143,7 @@ final public boolean isEnabled() {
139143
* @return {@code true} if the event can be written to the Flight Recorder
140144
* system, {@code false} otherwise
141145
*/
146+
@Override
142147
final public boolean shouldCommit() {
143148
return false;
144149
}
@@ -164,6 +169,7 @@ final public boolean shouldCommit() {
164169
* @see EventType#getFields()
165170
* @see EventFactory
166171
*/
172+
@Override
167173
final public void set(int index, Object value) {
168174
}
169175
}

src/jdk.jfr/share/classes/jdk/jfr/EventType.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package jdk.jfr;
2727

2828
import java.lang.annotation.Annotation;
29-
import java.util.Arrays;
3029
import java.util.Collections;
3130
import java.util.LinkedHashMap;
3231
import java.util.List;
@@ -45,8 +44,8 @@
4544
* @since 9
4645
*/
4746
public final class EventType {
47+
private static final List<String> UNCATEGORIZED = List.of("Uncategorized");
4848
private final PlatformEventType platformEventType;
49-
private final List<String> UNCATEGORIZED = Collections.singletonList("Uncategorized");
5049
private Map<String, ValueDescriptor> cache; // create lazy to avoid memory overhead
5150
// helper constructor
5251
EventType(PlatformEventType platformEventType) {
@@ -79,11 +78,11 @@ public ValueDescriptor getField(String name) {
7978
Objects.requireNonNull(name);
8079
if (cache == null) {
8180
List<ValueDescriptor> fields = getFields();
82-
Map<String, ValueDescriptor> newCache = new LinkedHashMap<String, ValueDescriptor>(fields.size());
81+
Map<String, ValueDescriptor> newCache = new LinkedHashMap<>(fields.size());
8382
for (ValueDescriptor v :fields) {
8483
newCache.put(v.getName(), v);
8584
}
86-
cache = newCache;
85+
cache = Map.copyOf(newCache);
8786
}
8887
ValueDescriptor result = cache.get(name);
8988
if (result == null) {
@@ -230,7 +229,7 @@ public List<String> getCategoryNames() {
230229
if (c == null) {
231230
return UNCATEGORIZED;
232231
}
233-
return Collections.unmodifiableList(Arrays.asList(c.value()));
232+
return List.of(c.value());
234233
}
235234

236235
// package private

src/jdk.jfr/share/classes/jdk/jfr/FlightRecorder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838

3939
import jdk.jfr.internal.JVM;
4040
import jdk.jfr.internal.JVMSupport;
41-
import jdk.jfr.internal.LogLevel;
4241
import jdk.jfr.internal.Logger;
4342
import jdk.jfr.internal.MetadataRepository;
4443
import jdk.jfr.internal.Options;

src/jdk.jfr/share/classes/jdk/jfr/FlightRecorderPermission.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package jdk.jfr;
2727

2828
import java.security.AccessControlContext;
29-
import java.util.Collections;
3029
import java.util.List;
3130
import java.util.Map;
3231
import java.util.Objects;
@@ -109,17 +108,17 @@ private final static class InternalAccess extends PrivateAccess {
109108

110109
@Override
111110
public Type getType(Object o) {
112-
if (o instanceof AnnotationElement) {
113-
return ((AnnotationElement) o).getType();
111+
if (o instanceof AnnotationElement ae) {
112+
return ae.getType();
114113
}
115-
if (o instanceof EventType) {
116-
return ((EventType) o).getType();
114+
if (o instanceof EventType et) {
115+
return et.getType();
117116
}
118-
if (o instanceof ValueDescriptor) {
119-
return ((ValueDescriptor) o).getType();
117+
if (o instanceof ValueDescriptor vd) {
118+
return vd.getType();
120119
}
121-
if (o instanceof SettingDescriptor) {
122-
return ((SettingDescriptor) o).getType();
120+
if (o instanceof SettingDescriptor sd) {
121+
return sd.getType();
123122
}
124123
throw new Error("Unknown type " + o.getClass());
125124
}
@@ -176,7 +175,7 @@ public String getFieldName(ValueDescriptor v) {
176175

177176
@Override
178177
public ValueDescriptor newValueDescriptor(Class<?> type, String name) {
179-
return new ValueDescriptor(type, name, Collections.emptyList(), true);
178+
return new ValueDescriptor(type, name, List.of(), true);
180179
}
181180

182181
@Override

src/jdk.jfr/share/classes/jdk/jfr/Recording.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public Recording(Map<String, String> settings) {
135135
* FlightRecorderPermission "accessFlightRecorder" is not set.
136136
*/
137137
public Recording() {
138-
this(new HashMap<String, String>());
138+
this(Map.of());
139139
}
140140

141141
/**

src/jdk.jfr/share/classes/jdk/jfr/SettingDescriptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package jdk.jfr;
2727

2828
import java.lang.annotation.Annotation;
29-
import java.util.Collections;
3029
import java.util.List;
3130
import java.util.Objects;
3231

@@ -196,7 +195,7 @@ public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
196195
* @return a list of annotations, not {@code null}
197196
*/
198197
public List<AnnotationElement> getAnnotationElements() {
199-
return Collections.unmodifiableList(annotationConstruct.getUnmodifiableAnnotationElements());
198+
return annotationConstruct.getUnmodifiableAnnotationElements();
200199
}
201200

202201
/**

src/jdk.jfr/share/classes/jdk/jfr/ValueDescriptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
package jdk.jfr;
2727

2828
import java.lang.annotation.Annotation;
29-
import java.util.ArrayList;
3029
import java.util.Collections;
3130
import java.util.List;
3231
import java.util.Objects;
@@ -131,7 +130,7 @@ public ValueDescriptor(Class<?> type, String name) {
131130
* doesn't have {@code FlightRecorderPermission("registerEvent")}
132131
*/
133132
public ValueDescriptor(Class<?> type, String name, List<AnnotationElement> annotations) {
134-
this(type, name, new ArrayList<>(annotations), false);
133+
this(type, name, List.copyOf(annotations), false);
135134
}
136135

137136

@@ -289,7 +288,7 @@ public List<AnnotationElement> getAnnotationElements() {
289288
*/
290289
public List<ValueDescriptor> getFields() {
291290
if (type.isSimpleType()) {
292-
return Collections.emptyList();
291+
return List.of();
293292
}
294293
return type.getFields();
295294
}

src/jdk.jfr/share/classes/jdk/jfr/consumer/EventStream.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ default void onMetadata(Consumer<MetadataEvent> action) {
263263
* <p>
264264
* Closing a previously closed stream has no effect.
265265
*/
266+
@Override
266267
void close();
267268

268269
/**

0 commit comments

Comments
 (0)