Skip to content
Permalink
Browse files
8264001: JFR: Modernize implementation
Reviewed-by: mgronlun
  • Loading branch information
egahlin committed Mar 24, 2021
1 parent fad8484 commit ae9af57bf694ff9dded1230e6dc675ead9aa4d10
Show file tree
Hide file tree
Showing 57 changed files with 239 additions and 322 deletions.
@@ -100,7 +100,7 @@ public final class AnnotationElement {
}
checkType(Utils.unboxType(valueType));
}
this.annotationValues = Utils.smallUnmodifiable(objects);
this.annotationValues = List.copyOf(objects);
this.inBootClassLoader = boot;
}

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

@@ -30,8 +30,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -190,8 +188,8 @@ public static Configuration getConfiguration(String name) throws IOException, Pa
*/
public static List<Configuration> getConfigurations() {
if (JVMSupport.isNotAvailable()) {
return new ArrayList<>();
return List.of();
}
return Collections.unmodifiableList(JFC.getConfigurations());
return List.copyOf(JFC.getConfigurations());
}
}
@@ -97,6 +97,7 @@ protected Event() {
/**
* Starts the timing of this event.
*/
@Override
final public void begin() {
}

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

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

@@ -126,6 +129,7 @@ final public void commit() {
*
* @return {@code true} if event is enabled, {@code false} otherwise
*/
@Override
final public boolean isEnabled() {
return false;
}
@@ -139,6 +143,7 @@ final public boolean isEnabled() {
* @return {@code true} if the event can be written to the Flight Recorder
* system, {@code false} otherwise
*/
@Override
final public boolean shouldCommit() {
return false;
}
@@ -164,6 +169,7 @@ final public boolean shouldCommit() {
* @see EventType#getFields()
* @see EventFactory
*/
@Override
final public void set(int index, Object value) {
}
}
@@ -26,7 +26,6 @@
package jdk.jfr;

import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
@@ -45,8 +44,8 @@
* @since 9
*/
public final class EventType {
private static final List<String> UNCATEGORIZED = List.of("Uncategorized");
private final PlatformEventType platformEventType;
private final List<String> UNCATEGORIZED = Collections.singletonList("Uncategorized");
private Map<String, ValueDescriptor> cache; // create lazy to avoid memory overhead
// helper constructor
EventType(PlatformEventType platformEventType) {
@@ -79,11 +78,11 @@ public ValueDescriptor getField(String name) {
Objects.requireNonNull(name);
if (cache == null) {
List<ValueDescriptor> fields = getFields();
Map<String, ValueDescriptor> newCache = new LinkedHashMap<String, ValueDescriptor>(fields.size());
Map<String, ValueDescriptor> newCache = new LinkedHashMap<>(fields.size());
for (ValueDescriptor v :fields) {
newCache.put(v.getName(), v);
}
cache = newCache;
cache = Map.copyOf(newCache);
}
ValueDescriptor result = cache.get(name);
if (result == null) {
@@ -230,7 +229,7 @@ public List<String> getCategoryNames() {
if (c == null) {
return UNCATEGORIZED;
}
return Collections.unmodifiableList(Arrays.asList(c.value()));
return List.of(c.value());
}

// package private
@@ -38,7 +38,6 @@

import jdk.jfr.internal.JVM;
import jdk.jfr.internal.JVMSupport;
import jdk.jfr.internal.LogLevel;
import jdk.jfr.internal.Logger;
import jdk.jfr.internal.MetadataRepository;
import jdk.jfr.internal.Options;
@@ -26,7 +26,6 @@
package jdk.jfr;

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

@Override
public Type getType(Object o) {
if (o instanceof AnnotationElement) {
return ((AnnotationElement) o).getType();
if (o instanceof AnnotationElement ae) {
return ae.getType();
}
if (o instanceof EventType) {
return ((EventType) o).getType();
if (o instanceof EventType et) {
return et.getType();
}
if (o instanceof ValueDescriptor) {
return ((ValueDescriptor) o).getType();
if (o instanceof ValueDescriptor vd) {
return vd.getType();
}
if (o instanceof SettingDescriptor) {
return ((SettingDescriptor) o).getType();
if (o instanceof SettingDescriptor sd) {
return sd.getType();
}
throw new Error("Unknown type " + o.getClass());
}
@@ -176,7 +175,7 @@ public String getFieldName(ValueDescriptor v) {

@Override
public ValueDescriptor newValueDescriptor(Class<?> type, String name) {
return new ValueDescriptor(type, name, Collections.emptyList(), true);
return new ValueDescriptor(type, name, List.of(), true);
}

@Override
@@ -135,7 +135,7 @@ public Recording(Map<String, String> settings) {
* FlightRecorderPermission "accessFlightRecorder" is not set.
*/
public Recording() {
this(new HashMap<String, String>());
this(Map.of());
}

/**
@@ -26,7 +26,6 @@
package jdk.jfr;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

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

/**
@@ -26,7 +26,6 @@
package jdk.jfr;

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


@@ -289,7 +288,7 @@ public List<AnnotationElement> getAnnotationElements() {
*/
public List<ValueDescriptor> getFields() {
if (type.isSimpleType()) {
return Collections.emptyList();
return List.of();
}
return type.getFields();
}
@@ -263,6 +263,7 @@ default void onMetadata(Consumer<MetadataEvent> action) {
* <p>
* Closing a previously closed stream has no effect.
*/
@Override
void close();

/**
@@ -112,7 +112,7 @@ private void calculateDelta() {
added.add(eventType);
}
}
this.removed = Collections.unmodifiableList(new ArrayList<>(previousSet.values()));
this.added = Collections.unmodifiableList(added);
this.removed = List.copyOf(previousSet.values());
this.added = List.copyOf(added);
}
}
@@ -120,6 +120,7 @@ public List<ValueDescriptor> getFields() {
return objectContext.fields;
}

@Override
final Object objectAt(int index) {
if (index == 0) {
return startTimeTicks;

0 comments on commit ae9af57

Please sign in to comment.