8264001: JFR: Modernize implementation

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2021-03-24 09:54:29 +00:00
parent fad8484058
commit ae9af57bf6
57 changed files with 239 additions and 322 deletions

View file

@ -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 final class AnnotationElement {
}
v.add(object);
}
this.annotationValues = Utils.smallUnmodifiable(v);
this.annotationValues = List.copyOf(v);
this.inBootClassLoader = annotationType.getClassLoader() == null;
}

View file

@ -30,8 +30,6 @@ import java.io.Reader;
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 final class Configuration {
*/
public static List<Configuration> getConfigurations() {
if (JVMSupport.isNotAvailable()) {
return new ArrayList<>();
return List.of();
}
return Collections.unmodifiableList(JFC.getConfigurations());
return List.copyOf(JFC.getConfigurations());
}
}

View file

@ -97,6 +97,7 @@ abstract public class Event extends jdk.internal.event.Event {
/**
* Starts the timing of this event.
*/
@Override
final public void begin() {
}
@ -105,6 +106,7 @@ abstract public class Event extends jdk.internal.event.Event {
*
* The {@code end} method must be invoked after the {@code begin} method.
*/
@Override
final public void end() {
}
@ -116,6 +118,7 @@ abstract public class Event extends jdk.internal.event.Event {
* 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 @@ abstract public class Event extends jdk.internal.event.Event {
*
* @return {@code true} if event is enabled, {@code false} otherwise
*/
@Override
final public boolean isEnabled() {
return false;
}
@ -139,6 +143,7 @@ abstract public class Event extends jdk.internal.event.Event {
* @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 @@ abstract public class Event extends jdk.internal.event.Event {
* @see EventType#getFields()
* @see EventFactory
*/
@Override
final public void set(int index, Object value) {
}
}

View file

@ -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 @@ import jdk.jfr.internal.Utils;
* @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 final class EventType {
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 final class EventType {
if (c == null) {
return UNCATEGORIZED;
}
return Collections.unmodifiableList(Arrays.asList(c.value()));
return List.of(c.value());
}
// package private

View file

@ -38,7 +38,6 @@ import java.util.Objects;
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;

View file

@ -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 @@ public final class FlightRecorderPermission extends java.security.BasicPermissio
@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 final class FlightRecorderPermission extends java.security.BasicPermissio
@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

View file

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

View file

@ -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 final class SettingDescriptor {
* @return a list of annotations, not {@code null}
*/
public List<AnnotationElement> getAnnotationElements() {
return Collections.unmodifiableList(annotationConstruct.getUnmodifiableAnnotationElements());
return annotationConstruct.getUnmodifiableAnnotationElements();
}
/**

View file

@ -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 final class ValueDescriptor {
* 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 final class ValueDescriptor {
*/
public List<ValueDescriptor> getFields() {
if (type.isSimpleType()) {
return Collections.emptyList();
return List.of();
}
return type.getFields();
}

View file

@ -263,6 +263,7 @@ public interface EventStream extends AutoCloseable {
* <p>
* Closing a previously closed stream has no effect.
*/
@Override
void close();
/**

View file

@ -112,7 +112,7 @@ public final class MetadataEvent {
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);
}
}

View file

@ -120,6 +120,7 @@ public final class RecordedEvent extends RecordedObject {
return objectContext.fields;
}
@Override
final Object objectAt(int index) {
if (index == 0) {
return startTimeTicks;

View file

@ -34,7 +34,6 @@ import java.time.OffsetDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
import jdk.jfr.Configuration;
import jdk.jfr.EventType;
@ -43,7 +42,6 @@ import jdk.jfr.Timestamp;
import jdk.jfr.ValueDescriptor;
import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.Type;
import jdk.jfr.internal.consumer.EventDirectoryStream;
import jdk.jfr.internal.consumer.JdkJfrConsumer;
import jdk.jfr.internal.consumer.ObjectContext;
import jdk.jfr.internal.consumer.ObjectFactory;
@ -63,10 +61,12 @@ public class RecordedObject {
static{
JdkJfrConsumer access = new JdkJfrConsumer() {
@Override
public List<Type> readTypes(RecordingFile file) throws IOException {
return file.readTypes();
}
@Override
public boolean isLastEventInChunk(RecordingFile file) {
return file.isLastEventInChunk();
}
@ -430,8 +430,8 @@ public class RecordedObject {
*/
public final boolean getBoolean(String name) {
Object o = getValue(name);
if (o instanceof Boolean) {
return ((Boolean) o).booleanValue();
if (o instanceof Boolean b) {
return b;
}
throw newIllegalArgumentException(name, "boolean");
}
@ -457,8 +457,8 @@ public class RecordedObject {
*/
public final byte getByte(String name) {
Object o = getValue(name);
if (o instanceof Byte) {
return ((Byte) o).byteValue();
if (o instanceof Byte b) {
return b;
}
throw newIllegalArgumentException(name, "byte");
}
@ -484,8 +484,8 @@ public class RecordedObject {
*/
public final char getChar(String name) {
Object o = getValue(name);
if (o instanceof Character) {
return ((Character) o).charValue();
if (o instanceof Character c) {
return c;
}
throw newIllegalArgumentException(name, "char");
@ -519,19 +519,19 @@ public class RecordedObject {
*/
public final short getShort(String name) {
Object o = getValue(name, true);
if (o instanceof Short) {
return ((Short) o).shortValue();
if (o instanceof Short s) {
return s;
}
if (o instanceof Byte) {
return ((Byte) o).byteValue();
if (o instanceof Byte b) {
return b;
}
if (o instanceof UnsignedValue) {
Object u = ((UnsignedValue) o).value();
if (u instanceof Short) {
return ((Short) u).shortValue();
if (o instanceof UnsignedValue unsigned) {
Object u = unsigned.value();
if (u instanceof Short s) {
return s;
}
if (u instanceof Byte) {
return (short) Byte.toUnsignedInt(((Byte) u));
if (u instanceof Byte b) {
return (short) Byte.toUnsignedInt(b);
}
}
throw newIllegalArgumentException(name, "short");
@ -566,28 +566,28 @@ public class RecordedObject {
*/
public final int getInt(String name) {
Object o = getValue(name, true);
if (o instanceof Integer) {
return ((Integer) o).intValue();
if (o instanceof Integer i) {
return i;
}
if (o instanceof Short) {
return ((Short) o).intValue();
if (o instanceof Short s) {
return s;
}
if (o instanceof Character) {
return ((Character) o).charValue();
if (o instanceof Character c) {
return c;
}
if (o instanceof Byte) {
return ((Byte) o).intValue();
if (o instanceof Byte b) {
return b;
}
if (o instanceof UnsignedValue) {
Object u = ((UnsignedValue) o).value();
if (u instanceof Integer) {
return ((Integer) u).intValue();
if (o instanceof UnsignedValue unsigned) {
Object u = unsigned.value();
if (u instanceof Integer i) {
return i;
}
if (u instanceof Short) {
return Short.toUnsignedInt(((Short) u));
if (u instanceof Short s) {
return Short.toUnsignedInt(s);
}
if (u instanceof Byte) {
return Byte.toUnsignedInt(((Byte) u));
if (u instanceof Byte b) {
return Byte.toUnsignedInt(b);
}
}
throw newIllegalArgumentException(name, "int");
@ -619,23 +619,23 @@ public class RecordedObject {
*/
public final float getFloat(String name) {
Object o = getValue(name);
if (o instanceof Float) {
return ((Float) o).floatValue();
if (o instanceof Float f) {
return f;
}
if (o instanceof Long) {
return ((Long) o).floatValue();
if (o instanceof Long l) {
return l;
}
if (o instanceof Integer) {
return ((Integer) o).floatValue();
if (o instanceof Integer i) {
return i;
}
if (o instanceof Short) {
return ((Short) o).floatValue();
if (o instanceof Short s) {
return s;
}
if (o instanceof Byte) {
return ((Byte) o).byteValue();
if (o instanceof Byte b) {
return b;
}
if (o instanceof Character) {
return ((Character) o).charValue();
if (o instanceof Character c) {
return c;
}
throw newIllegalArgumentException(name, "float");
}
@ -669,31 +669,31 @@ public class RecordedObject {
*/
public final long getLong(String name) {
Object o = getValue(name, true);
if (o instanceof Long) {
return ((Long) o).longValue();
if (o instanceof Long l) {
return l;
}
if (o instanceof Integer) {
return ((Integer) o).longValue();
if (o instanceof Integer i) {
return i;
}
if (o instanceof Short) {
return ((Short) o).longValue();
if (o instanceof Short s) {
return s;
}
if (o instanceof Character) {
return ((Character) o).charValue();
if (o instanceof Character c) {
return c;
}
if (o instanceof Byte) {
return ((Byte) o).longValue();
if (o instanceof Byte b) {
return b.longValue();
}
if (o instanceof UnsignedValue) {
Object u = ((UnsignedValue) o).value();
if (u instanceof Integer) {
return Integer.toUnsignedLong(((Integer) u));
if (o instanceof UnsignedValue unsigned) {
Object u = unsigned.value();
if (u instanceof Integer i) {
return Integer.toUnsignedLong(i);
}
if (u instanceof Short) {
return Short.toUnsignedLong(((Short) u));
if (u instanceof Short s) {
return Short.toUnsignedLong(s);
}
if (u instanceof Byte) {
return Byte.toUnsignedLong(((Byte) u));
if (u instanceof Byte b) {
return Byte.toUnsignedLong(b);
}
}
throw newIllegalArgumentException(name, "long");
@ -725,26 +725,26 @@ public class RecordedObject {
*/
public final double getDouble(String name) {
Object o = getValue(name);
if (o instanceof Double) {
return ((Double) o).doubleValue();
if (o instanceof Double d) {
return d.doubleValue();
}
if (o instanceof Float) {
return ((Float) o).doubleValue();
if (o instanceof Float f) {
return f.doubleValue();
}
if (o instanceof Long) {
return ((Long) o).doubleValue();
if (o instanceof Long l) {
return l.doubleValue();
}
if (o instanceof Integer) {
return ((Integer) o).doubleValue();
if (o instanceof Integer i) {
return i.doubleValue();
}
if (o instanceof Short) {
return ((Short) o).doubleValue();
if (o instanceof Short s) {
return s.doubleValue();
}
if (o instanceof Byte) {
return ((Byte) o).byteValue();
if (o instanceof Byte b) {
return b.doubleValue();
}
if (o instanceof Character) {
return ((Character) o).charValue();
if (o instanceof Character c) {
return c;
}
throw newIllegalArgumentException(name, "double");
}
@ -797,31 +797,31 @@ public class RecordedObject {
*/
public final Duration getDuration(String name) {
Object o = getValue(name);
if (o instanceof Long) {
return getDuration(((Long) o).longValue(), name);
if (o instanceof Long l) {
return getDuration(l, name);
}
if (o instanceof Integer) {
return getDuration(((Integer) o).longValue(), name);
if (o instanceof Integer i) {
return getDuration(i, name);
}
if (o instanceof Short) {
return getDuration(((Short) o).longValue(), name);
if (o instanceof Short s) {
return getDuration(s, name);
}
if (o instanceof Character) {
return getDuration(((Character) o).charValue(), name);
if (o instanceof Character c) {
return getDuration(c, name);
}
if (o instanceof Byte) {
return getDuration(((Byte) o).longValue(), name);
if (o instanceof Byte b) {
return getDuration(b, name);
}
if (o instanceof UnsignedValue) {
Object u = ((UnsignedValue) o).value();
if (u instanceof Integer) {
return getDuration(Integer.toUnsignedLong((Integer) u), name);
if (o instanceof UnsignedValue unsigned) {
Object u = unsigned.value();
if (u instanceof Integer i) {
return getDuration(Integer.toUnsignedLong(i), name);
}
if (u instanceof Short) {
return getDuration(Short.toUnsignedLong((Short) u), name);
if (u instanceof Short s) {
return getDuration(Short.toUnsignedLong(s), name);
}
if (u instanceof Byte) {
return getDuration(Short.toUnsignedLong((Byte) u), name);
if (u instanceof Byte b) {
return getDuration(Short.toUnsignedLong(b), name);
}
}
throw newIllegalArgumentException(name, "java.time.Duration");
@ -876,31 +876,31 @@ public class RecordedObject {
*/
public final Instant getInstant(String name) {
Object o = getValue(name, true);
if (o instanceof Long) {
return getInstant(((Long) o).longValue(), name);
if (o instanceof Long l) {
return getInstant(l, name);
}
if (o instanceof Integer) {
return getInstant(((Integer) o).longValue(), name);
if (o instanceof Integer i) {
return getInstant(i, name);
}
if (o instanceof Short) {
return getInstant(((Short) o).longValue(), name);
if (o instanceof Short s) {
return getInstant(s, name);
}
if (o instanceof Character) {
return getInstant(((Character) o).charValue(), name);
if (o instanceof Character c) {
return getInstant(c, name);
}
if (o instanceof Byte) {
return getInstant(((Byte) o).longValue(), name);
if (o instanceof Byte b) {
return getInstant(b, name);
}
if (o instanceof UnsignedValue) {
Object u = ((UnsignedValue) o).value();
if (u instanceof Integer) {
return getInstant(Integer.toUnsignedLong((Integer) u), name);
if (o instanceof UnsignedValue unsigned) {
Object u = unsigned.value();
if (u instanceof Integer i) {
return getInstant(Integer.toUnsignedLong(i), name);
}
if (u instanceof Short) {
return getInstant(Short.toUnsignedLong((Short) u), name);
if (u instanceof Short s) {
return getInstant(Short.toUnsignedLong(s), name);
}
if (u instanceof Byte) {
return getInstant(Short.toUnsignedLong((Byte) u), name);
if (u instanceof Byte b) {
return getInstant(Short.toUnsignedLong(b), name);
}
}
throw newIllegalArgumentException(name, "java.time.Instant");
@ -982,8 +982,8 @@ public class RecordedObject {
StringWriter s = new StringWriter();
PrettyWriter p = new PrettyWriter(new PrintWriter(s));
p.setStackDepth(5);
if (this instanceof RecordedEvent) {
p.print((RecordedEvent) this);
if (this instanceof RecordedEvent event) {
p.print(event);
} else {
p.print(this, "");
}

View file

@ -25,8 +25,8 @@
package jdk.jfr.consumer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import jdk.jfr.internal.consumer.ObjectContext;
@ -51,7 +51,7 @@ public final class RecordedStackTrace extends RecordedObject {
public List<RecordedFrame> getFrames() {
Object[] array = getTyped("frames", Object[].class, null);
if (array == null) {
return Collections.EMPTY_LIST;
return new ArrayList<>(0);
}
List<?> list = Arrays.asList(array);
return (List<RecordedFrame>) list;

View file

@ -193,6 +193,7 @@ public final class RecordingFile implements Closeable {
*
* @throws IOException if an I/O error occurred
*/
@Override
public void close() throws IOException {
if (input != null) {
eof = true;

View file

@ -48,7 +48,7 @@
* .stream()
* .sorted((a, b) -> b.getValue().compareTo(a.getValue()))
* .forEach(e -> System.out.printf("%8d %s\n", e.getValue(), e.getKey()));
* }
* }
* }</pre>
* <p>
* <b>Null-handling</b>

View file

@ -28,7 +28,6 @@ package jdk.jfr.events;
import jdk.internal.misc.VM.BufferPool;
import jdk.internal.misc.VM;
import jdk.jfr.*;
import jdk.jfr.internal.Type;
@Category({ "Java Application", "Statistics" })
public abstract class AbstractBufferStatisticsEvent extends AbstractJDKEvent {

View file

@ -40,12 +40,8 @@ import jdk.jfr.internal.Type;
@StackTrace(false)
public final class ActiveRecordingEvent extends AbstractJDKEvent {
public static final ThreadLocal<ActiveRecordingEvent> EVENT = new ThreadLocal<ActiveRecordingEvent>() {
@Override
protected ActiveRecordingEvent initialValue() {
return new ActiveRecordingEvent();
}
};
// To be accessed when holding recorder lock
public static final ActiveRecordingEvent EVENT = new ActiveRecordingEvent();
@Label("Id")
public long id;

View file

@ -29,7 +29,6 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.List;
import jdk.jfr.AnnotationElement;
@ -58,17 +57,18 @@ public final class AnnotationConstruct {
}
}
private List<AnnotationElement> annotationElements = Collections.emptyList();
private List<AnnotationElement> annotationElements;
private byte unsignedFlag = -1;
public AnnotationConstruct(List<AnnotationElement> ann) {
this.annotationElements = ann;
public AnnotationConstruct(List<AnnotationElement> elements) {
this.annotationElements = List.copyOf(elements);
}
public AnnotationConstruct() {
this(List.of());
}
public void setAnnotationElements(List<AnnotationElement> elements) {
annotationElements = Utils.smallUnmodifiable(elements);
annotationElements = List.copyOf(elements);
}
public String getLabel() {
@ -100,11 +100,6 @@ public final class AnnotationConstruct {
return annotationElements;
}
// package private
boolean remove(AnnotationElement annotation) {
return annotationElements.remove(annotation);
}
private AnnotationElement getAnnotationElement(Class<? extends Annotation> clazz) {
// if multiple annotation elements with the same name exists, prioritize
// the one with the same id. Note, id alone is not a guarantee, since it

View file

@ -95,14 +95,13 @@ public final class EventControl {
}
addControl(Enabled.NAME, defineEnabled(eventType));
ArrayList<AnnotationElement> aes = new ArrayList<>(eventType.getAnnotationElements());
List<AnnotationElement> aes = new ArrayList<>(eventType.getAnnotationElements());
remove(eventType, aes, Threshold.class);
remove(eventType, aes, Period.class);
remove(eventType, aes, Enabled.class);
remove(eventType, aes, StackTrace.class);
remove(eventType, aes, Cutoff.class);
remove(eventType, aes, Throttle.class);
aes.trimToSize();
eventType.setAnnotations(aes);
this.type = eventType;
this.idName = String.valueOf(eventType.getId());

View file

@ -195,9 +195,8 @@ public final class EventInstrumentation {
if (values != null && values.size() == 2) {
Object key = values.get(0);
Object value = values.get(1);
if (key instanceof String && value != null) {
if (key instanceof String keyName && value != null) {
if (type == value.getClass()) {
String keyName = (String) key;
if ("value".equals(keyName)) {
return (T) value;
}

View file

@ -25,8 +25,6 @@
package jdk.jfr.internal;
import java.util.function.Supplier;
/**
* JFR logger
*

View file

@ -252,6 +252,7 @@ public final class LongMap<T> {
return count;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < objects.length; i++) {

View file

@ -25,13 +25,10 @@
package jdk.jfr.internal;
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

View file

@ -124,8 +124,8 @@ final class MetadataReader {
type.setAnnotations(aes);
int index = 0;
if (type instanceof PlatformEventType) {
List<SettingDescriptor> settings = ((PlatformEventType) type).getAllSettings();
if (type instanceof PlatformEventType pType) {
List<SettingDescriptor> settings = pType.getAllSettings();
for (Element settingElement : typeElement.elements(ELEMENT_SETTING)) {
ArrayList<AnnotationElement> annotations = new ArrayList<>();
for (Element annotationElement : settingElement.elements(ELEMENT_ANNOTATION)) {
@ -221,8 +221,8 @@ final class MetadataReader {
private void buildEvenTypes() {
for (Type type : descriptor.types) {
if (type instanceof PlatformEventType) {
descriptor.eventTypes.add(PrivateAccess.getInstance().newEventType((PlatformEventType) type));
if (type instanceof PlatformEventType pType) {
descriptor.eventTypes.add(PrivateAccess.getInstance().newEventType(pType));
}
}
}

View file

@ -70,8 +70,7 @@ public final class MetadataRepository {
private void initializeJVMEventTypes() {
List<RequestHook> requestHooks = new ArrayList<>();
for (Type type : typeLibrary.getTypes()) {
if (type instanceof PlatformEventType) {
PlatformEventType pEventType = (PlatformEventType) type;
if (type instanceof PlatformEventType pEventType) {
EventType eventType = PrivateAccess.getInstance().newEventType(pEventType);
pEventType.setHasDuration(eventType.getAnnotation(Threshold.class) != null);
pEventType.setHasStackTrace(eventType.getAnnotation(StackTrace.class) != null);
@ -291,9 +290,8 @@ public final class MetadataRepository {
knownIds.add(Type.getTypeId(ec));
}
for (Type type : typeLibrary.getTypes()) {
if (type instanceof PlatformEventType) {
if (!knownIds.contains(type.getId())) {
PlatformEventType pe = (PlatformEventType) type;
if (type instanceof PlatformEventType pe) {
if (!knownIds.contains(pe.getId())) {
if (!pe.isJVM()) {
pe.setRegistered(false);
}

View file

@ -169,8 +169,8 @@ final class MetadataWriter {
element.addAttribute(ATTRIBUTE_SIMPLE_TYPE, true);
}
element.addAttribute(ATTRIBUTE_ID, type.getId());
if (type instanceof PlatformEventType) {
for (SettingDescriptor v : ((PlatformEventType)type).getSettings()) {
if (type instanceof PlatformEventType pType) {
for (SettingDescriptor v : pType.getSettings()) {
makeSettingElement(element, v);
}
}

View file

@ -439,7 +439,7 @@ public final class PlatformRecorder {
private void writeMetaEvents() {
if (activeRecordingEvent.isEnabled()) {
ActiveRecordingEvent event = ActiveRecordingEvent.EVENT.get();
ActiveRecordingEvent event = ActiveRecordingEvent.EVENT;
for (PlatformRecording r : getRecordings()) {
if (r.getState() == RecordingState.RUNNING && r.shouldWriteMetadataEvent()) {
event.id = r.getId();

View file

@ -28,17 +28,12 @@ package jdk.jfr.internal;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Path;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.util.Comparator;
import jdk.jfr.internal.SecuritySupport.SafePath;
final class RepositoryChunk {
private static final int MAX_CHUNK_NAMES = 100;
private static final String FILE_EXTENSION = ".jfr";
static final Comparator<RepositoryChunk> END_TIME_COMPARATOR = new Comparator<RepositoryChunk>() {
@Override

View file

@ -172,6 +172,7 @@ public final class SecuritySupport {
return path.toFile();
}
@Override
public String toString() {
return text;
}
@ -183,8 +184,8 @@ public final class SecuritySupport {
@Override
public boolean equals(Object other) {
if(other != null && other instanceof SafePath){
return this.toPath().equals(((SafePath) other).toPath());
if(other != null && other instanceof SafePath s){
return this.toPath().equals(s.toPath());
}
return false;
}

View file

@ -100,6 +100,7 @@ final class ShutdownHook implements Runnable {
}
static final class ExceptionHandler implements Thread.UncaughtExceptionHandler {
@Override
public void uncaughtException(Thread t, Throwable e) {
JVM.getJVM().uncaughtException(t, e);
}

View file

@ -28,7 +28,6 @@ package jdk.jfr.internal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -212,8 +211,8 @@ public class Type implements Comparable<Type> {
}
public List<ValueDescriptor> getFields() {
if (fields instanceof ArrayList) {
((ArrayList<ValueDescriptor>) fields).trimToSize();
if (fields instanceof ArrayList<?> list) {
list.trimToSize();
fields = Collections.unmodifiableList(fields);
}
return fields;
@ -291,8 +290,7 @@ public class Type implements Comparable<Type> {
@Override
public boolean equals(Object object) {
if (object instanceof Type) {
Type that = (Type) object;
if (object instanceof Type that) {
return that.id == this.id;
}
return false;

View file

@ -26,7 +26,6 @@
package jdk.jfr.internal;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.Field;
@ -58,7 +57,6 @@ import jdk.jfr.SettingDescriptor;
import jdk.jfr.Timespan;
import jdk.jfr.Timestamp;
import jdk.jfr.ValueDescriptor;
import jdk.jfr.internal.tool.PrettyWriter;
public final class TypeLibrary {
@ -79,7 +77,7 @@ public final class TypeLibrary {
}
private static ValueDescriptor createStartTimeField() {
List<AnnotationElement> annos = createStandardAnnotations("Start Time", null);
var annos = createStandardAnnotations("Start Time", null);
annos.add(new jdk.jfr.AnnotationElement(Timestamp.class, Timestamp.TICKS));
return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_START_TIME, Type.LONG, annos, 0, false,
EventInstrumentation.FIELD_START_TIME);
@ -87,22 +85,19 @@ public final class TypeLibrary {
}
private static ValueDescriptor createStackTraceField() {
List<AnnotationElement> annos = new ArrayList<>();
annos = createStandardAnnotations("Stack Trace", "Stack Trace starting from the method the event was committed in");
var annos = createStandardAnnotations("Stack Trace", "Stack Trace starting from the method the event was committed in");
return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_STACK_TRACE, Type.STACK_TRACE, annos, 0, true,
EventInstrumentation.FIELD_STACK_TRACE);
}
private static ValueDescriptor createThreadField() {
List<AnnotationElement> annos = new ArrayList<>();
annos = createStandardAnnotations("Event Thread", "Thread in which event was committed in");
var annos = createStandardAnnotations("Event Thread", "Thread in which event was committed in");
return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_EVENT_THREAD, Type.THREAD, annos, 0, true,
EventInstrumentation.FIELD_EVENT_THREAD);
}
private static ValueDescriptor createDurationField() {
List<AnnotationElement> annos = new ArrayList<>();
annos = createStandardAnnotations("Duration", null);
var annos = createStandardAnnotations("Duration", null);
annos.add(new jdk.jfr.AnnotationElement(Timespan.class, Timespan.TICKS));
return PrivateAccess.getInstance().newValueDescriptor(EventInstrumentation.FIELD_DURATION, Type.LONG, annos, 0, false, EventInstrumentation.FIELD_DURATION);
}
@ -142,7 +137,6 @@ public final class TypeLibrary {
aes.add(ae);
}
}
aes.trimToSize();
type.setAnnotations(aes);
}
return getType(a);
@ -419,8 +413,8 @@ public final class TypeLibrary {
Logger.log(LogTag.JFR_METADATA, LogLevel.TRACE, "Cleaning out obsolete metadata");
List<Type> registered = new ArrayList<>();
for (Type type : types.values()) {
if (type instanceof PlatformEventType) {
if (((PlatformEventType) type).isRegistered()) {
if (type instanceof PlatformEventType pType) {
if (pType.isRegistered()) {
registered.add(type);
}
}
@ -472,8 +466,7 @@ public final class TypeLibrary {
typeQ.add(PrivateAccess.getInstance().getType(v));
visitAnnotations(typeQ, v.getAnnotationElements());
}
if (type instanceof PlatformEventType) {
PlatformEventType pe = (PlatformEventType) type;
if (type instanceof PlatformEventType pe) {
for (SettingDescriptor s : pe.getAllSettings()) {
typeQ.add(PrivateAccess.getInstance().getType(s));
visitAnnotations(typeQ, s.getAnnotationElements());

View file

@ -48,7 +48,6 @@ import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import java.util.HashMap;
import java.util.List;
@ -207,22 +206,20 @@ public final class Utils {
}
enum ThrottleUnit {
NANOSECONDS("ns", TimeUnit.NANOSECONDS, TimeUnit.SECONDS.toNanos(1), TimeUnit.SECONDS.toMillis(1)),
MICROSECONDS("us", TimeUnit.MICROSECONDS, TimeUnit.SECONDS.toNanos(1) / 1000, TimeUnit.SECONDS.toMillis(1)),
MILLISECONDS("ms", TimeUnit.MILLISECONDS, TimeUnit.SECONDS.toMillis(1), TimeUnit.SECONDS.toMillis(1)),
SECONDS("s", TimeUnit.SECONDS, 1, TimeUnit.SECONDS.toMillis(1)),
MINUTES("m", TimeUnit.MINUTES, 1, TimeUnit.MINUTES.toMillis(1)),
HOUR("h", TimeUnit.HOURS, 1, TimeUnit.HOURS.toMillis(1)),
DAY("d", TimeUnit.DAYS, 1, TimeUnit.DAYS.toMillis(1));
NANOSECONDS("ns", TimeUnit.SECONDS.toNanos(1), TimeUnit.SECONDS.toMillis(1)),
MICROSECONDS("us", TimeUnit.SECONDS.toNanos(1) / 1000, TimeUnit.SECONDS.toMillis(1)),
MILLISECONDS("ms", TimeUnit.SECONDS.toMillis(1), TimeUnit.SECONDS.toMillis(1)),
SECONDS("s", 1, TimeUnit.SECONDS.toMillis(1)),
MINUTES("m", 1, TimeUnit.MINUTES.toMillis(1)),
HOUR("h", 1, TimeUnit.HOURS.toMillis(1)),
DAY("d", 1, TimeUnit.DAYS.toMillis(1));
private final String text;
private final TimeUnit timeUnit;
private final long factor;
private final long millis;
ThrottleUnit(String t, TimeUnit u, long factor, long millis) {
ThrottleUnit(String t, long factor, long millis) {
this.text = t;
this.timeUnit = u;
this.factor = factor;
this.millis = millis;
}
@ -365,9 +362,7 @@ public final class Utils {
}
}
}
List<Annotation> annos = new ArrayList<>();
annos.add(a);
return annos;
return List.of(a);
}
static boolean isAfter(RecordingState stateToTest, RecordingState b) {
@ -649,16 +644,6 @@ public final class Utils {
return knownType;
}
public static <T> List<T> smallUnmodifiable(List<T> list) {
if (list.isEmpty()) {
return Collections.emptyList();
}
if (list.size() == 1) {
return Collections.singletonList(list.get(0));
}
return Collections.unmodifiableList(list);
}
public static String upgradeLegacyJDKEvent(String eventName) {
if (eventName.length() <= LEGACY_EVENT_NAME_PREFIX.length()) {
return eventName;

View file

@ -31,7 +31,6 @@ import java.security.AccessController;
import java.security.PrivilegedAction;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;

View file

@ -165,8 +165,7 @@ public final class ChunkParser {
void updateConfiguration(ParserConfiguration configuration, boolean resetEventCache) {
this.configuration = configuration;
parsers.forEach(p -> {
if (p instanceof EventParser) {
EventParser ep = (EventParser) p;
if (p instanceof EventParser ep) {
if (resetEventCache) {
ep.resetCache();
}
@ -244,9 +243,8 @@ public final class ChunkParser {
}
long typeId = input.readLong();
Parser p = parsers.get(typeId);
if (p instanceof EventParser) {
if (p instanceof EventParser ep) {
// Fast path
EventParser ep = (EventParser) p;
RecordedEvent event = ep.parse(input);
if (event != null) {
input.position(pos + size);
@ -398,8 +396,8 @@ public final class ChunkParser {
if (o == null) { // should not happen
return "null";
}
if (o instanceof String) {
return "\"" + String.valueOf(o) + "\"";
if (o instanceof String s) {
return "\"" + s + "\"";
}
if (o instanceof RecordedObject) {
return o.getClass().getName();
@ -484,8 +482,7 @@ public final class ChunkParser {
LongMap<Parser> ps = this.parsers;
if (ps != null) {
ps.forEach(p -> {
if (p instanceof EventParser) {
EventParser ep = (EventParser) p;
if (p instanceof EventParser ep) {
ep.resetCache();
}
});

View file

@ -60,6 +60,7 @@ final class ConstantMap {
return pool.get(key);
}
@Override
public String toString() {
return "ref: " + pool.name + "[" + key + "]";
}
@ -137,8 +138,8 @@ final class ConstantMap {
}
private static Object resolve(Object o) {
if (o instanceof Reference) {
return resolve(((Reference) o).resolve());
if (o instanceof Reference r) {
return resolve(r.resolve());
}
if (o != null && o.getClass().isArray()) {
final Object[] array = (Object[]) o;

View file

@ -28,7 +28,6 @@ package jdk.jfr.internal.consumer;
import java.io.IOException;
import java.nio.file.Path;
import java.security.AccessControlContext;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

View file

@ -33,8 +33,6 @@ import java.util.List;
import jdk.jfr.EventType;
import jdk.jfr.ValueDescriptor;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.internal.consumer.Parser;
import jdk.jfr.internal.consumer.RecordingInput;
/**
* Parses an event and returns a {@link RecordedEvent}.
@ -110,6 +108,7 @@ final class EventParser extends Parser {
return enabled;
}
@Override
public RecordedEvent parse(RecordingInput input) throws IOException {
if (!enabled) {
return null;

View file

@ -40,6 +40,7 @@ public final class FinishedStream extends EventByteStream {
this.buffer = new byte[blockSize];
}
@Override
public synchronized byte[] read() throws IOException {
// OK to reuse buffer since this
// is only used for serialization

View file

@ -28,11 +28,9 @@ package jdk.jfr.internal.consumer;
import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import jdk.jfr.Configuration;
import jdk.jfr.EventType;
import jdk.jfr.consumer.EventStream;
import jdk.jfr.consumer.MetadataEvent;
import jdk.jfr.consumer.RecordedClass;
import jdk.jfr.consumer.RecordedClassLoader;

View file

@ -143,8 +143,8 @@ public abstract class ObjectFactory<T> {
if (value == null) {
return null;
}
if (value instanceof Object[]) {
return createTyped(objectContext, id, (Object[]) value);
if (value instanceof Object[] array) {
return createTyped(objectContext, id, array);
}
throw new InternalError("Object factory must have struct type. Type was " + value.getClass().getName());
}

View file

@ -27,11 +27,9 @@ package jdk.jfr.internal.consumer;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.time.Instant;
import jdk.jfr.Recording;
import jdk.jfr.RecordingState;
import jdk.jfr.internal.Utils;
import jdk.jfr.internal.SecuritySupport;
import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.jfr.internal.management.EventByteStream;
@ -66,6 +64,7 @@ public final class OngoingStream extends EventByteStream {
this.repositoryFiles = new RepositoryFiles(SecuritySupport.PRIVILEGED, null);
}
@Override
public synchronized byte[] read() throws IOException {
try {
return readBytes();

View file

@ -35,8 +35,6 @@ import jdk.jfr.internal.LongMap;
import jdk.jfr.internal.MetadataDescriptor;
import jdk.jfr.internal.PrivateAccess;
import jdk.jfr.internal.Type;
import jdk.jfr.internal.consumer.Parser;
import jdk.jfr.internal.consumer.RecordingInput;
/**
* Class that create parsers suitable for reading events and constant pools

View file

@ -65,6 +65,7 @@ final class ParserFilter {
return -1;
}
@Override
public String toString() {
if (acceptAll) {
return "ACCEPT ALL";

View file

@ -58,8 +58,7 @@ final class SocketChannelImplInstrumentor {
long duration = EventHandler.timestamp() - start;
if (handler.shouldCommit(duration)) {
SocketAddress remoteAddress = getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
InetSocketAddress isa = (InetSocketAddress) remoteAddress;
if (remoteAddress instanceof InetSocketAddress isa) {
String hostString = isa.getAddress().toString();
int delimiterIndex = hostString.lastIndexOf('/');
@ -101,8 +100,7 @@ final class SocketChannelImplInstrumentor {
long duration = EventHandler.timestamp() - start;
if (handler.shouldCommit(duration)) {
SocketAddress remoteAddress = getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
InetSocketAddress isa = (InetSocketAddress) remoteAddress;
if (remoteAddress instanceof InetSocketAddress isa) {
String hostString = isa.getAddress().toString();
int delimiterIndex = hostString.lastIndexOf('/');
@ -145,8 +143,7 @@ final class SocketChannelImplInstrumentor {
if (handler.shouldCommit(duration)) {
long bytes = bytesWritten < 0 ? 0 : bytesWritten;
SocketAddress remoteAddress = getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
InetSocketAddress isa = (InetSocketAddress) remoteAddress;
if (remoteAddress instanceof InetSocketAddress isa) {
String hostString = isa.getAddress().toString();
int delimiterIndex = hostString.lastIndexOf('/');
@ -186,8 +183,7 @@ final class SocketChannelImplInstrumentor {
if (handler.shouldCommit(duration)) {
long bytes = bytesWritten < 0 ? 0 : bytesWritten;
SocketAddress remoteAddress = getRemoteAddress();
if (remoteAddress instanceof InetSocketAddress) {
InetSocketAddress isa = (InetSocketAddress) remoteAddress;
if (remoteAddress instanceof InetSocketAddress isa) {
String hostString = isa.getAddress().toString();
int delimiterIndex = hostString.lastIndexOf('/');

View file

@ -27,13 +27,9 @@ package jdk.jfr.internal.management;
import java.nio.file.Paths;
import java.nio.file.Path;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import jdk.jfr.internal.SecuritySupport;
import jdk.jfr.internal.SecuritySupport.SafePath;
import jdk.jfr.internal.Utils;
import jdk.jfr.internal.consumer.FileAccess;

View file

@ -30,7 +30,6 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -54,7 +53,6 @@ import jdk.jfr.internal.Utils;
import jdk.jfr.internal.WriteableUserPath;
import jdk.jfr.internal.consumer.EventDirectoryStream;
import jdk.jfr.internal.consumer.FileAccess;
import jdk.jfr.internal.consumer.JdkJfrConsumer;
import jdk.jfr.internal.instrument.JDKEvents;
/**
@ -84,7 +82,7 @@ public final class ManagementSupport {
// would normally be checked when a Flight Recorder instance is created
Utils.checkAccessFlightRecorder();
if (JVMSupport.isNotAvailable()) {
return new ArrayList<>();
return List.of();
}
JDKEvents.initialize(); // make sure JDK events are available
return Collections.unmodifiableList(MetadataRepository.getInstance().getRegisteredEventTypes());

View file

@ -35,8 +35,6 @@ import java.util.Timer;
import java.util.concurrent.TimeUnit;
import jdk.jfr.Recording;
import jdk.jfr.internal.consumer.FinishedStream;
import jdk.jfr.internal.consumer.OngoingStream;
// Exposes EventByteStreams to the FlightRecorderMXBean
public final class StreamManager {

View file

@ -26,22 +26,13 @@
package jdk.jfr.internal.settings;
import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.concurrent.TimeUnit;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import jdk.jfr.Description;
import jdk.jfr.Label;
import jdk.jfr.MetadataDefinition;
import jdk.jfr.Name;
import jdk.jfr.Timespan;
import jdk.jfr.internal.PlatformEventType;
import jdk.jfr.internal.Type;
import jdk.jfr.internal.Utils;

View file

@ -31,7 +31,6 @@ import java.io.IOError;
import java.io.IOException;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;

View file

@ -26,7 +26,6 @@
package jdk.jfr.internal.tool;
import java.io.PrintStream;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
@ -39,9 +38,10 @@ final class Help extends Command {
@Override
public List<String> getOptionSyntax() {
return Collections.singletonList("[<command>]");
return List.of("[<command>]");
}
@Override
protected List<String> getAliases() {
return List.of("--help", "-h", "-?");
}

View file

@ -90,8 +90,7 @@ final class JSONWriter extends EventPrintWriter {
printAsString(value);
return;
}
if (value instanceof Double) {
Double dValue = (Double) value;
if (value instanceof Double dValue) {
if (Double.isNaN(dValue) || Double.isInfinite(dValue)) {
printNull();
return;
@ -99,8 +98,7 @@ final class JSONWriter extends EventPrintWriter {
printAsString(value);
return;
}
if (value instanceof Float) {
Float fValue = (Float) value;
if (value instanceof Float fValue) {
if (Float.isNaN(fValue) || Float.isInfinite(fValue)) {
printNull();
return;

View file

@ -293,27 +293,26 @@ public final class PrettyWriter extends EventPrintWriter {
return;
}
if (value instanceof RecordedObject) {
if (value instanceof RecordedThread) {
printThread((RecordedThread) value, postFix);
if (value instanceof RecordedThread rt) {
printThread(rt, postFix);
return;
}
if (value instanceof RecordedClass) {
printClass((RecordedClass) value, postFix);
if (value instanceof RecordedClass rc) {
printClass(rc, postFix);
return;
}
if (value instanceof RecordedClassLoader) {
printClassLoader((RecordedClassLoader) value, postFix);
if (value instanceof RecordedClassLoader rcl) {
printClassLoader(rcl, postFix);
return;
}
if (value instanceof RecordedFrame) {
RecordedFrame frame = (RecordedFrame) value;
if (value instanceof RecordedFrame frame) {
if (frame.isJavaFrame()) {
printJavaFrame((RecordedFrame) value, postFix);
return;
}
}
if (value instanceof RecordedMethod) {
println(formatMethod((RecordedMethod) value));
if (value instanceof RecordedMethod rm) {
println(formatMethod(rm));
return;
}
if (field.getTypeName().equals(TYPE_OLD_OBJECT)) {
@ -328,29 +327,25 @@ public final class PrettyWriter extends EventPrintWriter {
return;
}
if (value instanceof Double) {
Double d = (Double) value;
if (value instanceof Double d) {
if (Double.isNaN(d) || d == Double.NEGATIVE_INFINITY) {
println("N/A");
return;
}
}
if (value instanceof Float) {
Float f = (Float) value;
if (value instanceof Float f) {
if (Float.isNaN(f) || f == Float.NEGATIVE_INFINITY) {
println("N/A");
return;
}
}
if (value instanceof Long) {
Long l = (Long) value;
if (value instanceof Long l) {
if (l == Long.MIN_VALUE) {
println("N/A");
return;
}
}
if (value instanceof Integer) {
Integer i = (Integer) value;
if (value instanceof Integer i) {
if (i == Integer.MIN_VALUE) {
println("N/A");
return;
@ -552,8 +547,7 @@ public final class PrettyWriter extends EventPrintWriter {
}
private boolean printFormatted(ValueDescriptor field, Object value) {
if (value instanceof Duration) {
Duration d = (Duration) value;
if (value instanceof Duration d) {
if (d.getSeconds() == Long.MIN_VALUE && d.getNano() == 0) {
println("N/A");
return true;
@ -561,8 +555,7 @@ public final class PrettyWriter extends EventPrintWriter {
println(Utils.formatDuration(d));
return true;
}
if (value instanceof OffsetDateTime) {
OffsetDateTime odt = (OffsetDateTime) value;
if (value instanceof OffsetDateTime odt) {
if (odt.equals(OffsetDateTime.MIN)) {
println("N/A");
return true;
@ -572,16 +565,15 @@ public final class PrettyWriter extends EventPrintWriter {
}
Percentage percentage = field.getAnnotation(Percentage.class);
if (percentage != null) {
if (value instanceof Number) {
double d = ((Number) value).doubleValue();
if (value instanceof Number n) {
double d = n.doubleValue();
println(String.format("%.2f", d * 100) + "%");
return true;
}
}
DataAmount dataAmount = field.getAnnotation(DataAmount.class);
if (dataAmount != null) {
if (value instanceof Number) {
Number n = (Number) value;
if (value instanceof Number n) {
long amount = n.longValue();
if (field.getAnnotation(Frequency.class) != null) {
if (dataAmount.value().equals(DataAmount.BYTES)) {
@ -606,8 +598,8 @@ public final class PrettyWriter extends EventPrintWriter {
}
MemoryAddress memoryAddress = field.getAnnotation(MemoryAddress.class);
if (memoryAddress != null) {
if (value instanceof Number) {
long d = ((Number) value).longValue();
if (value instanceof Number n) {
long d = n.longValue();
println(String.format("0x%08X", d));
return true;
}

View file

@ -25,7 +25,6 @@
package jdk.jfr.internal.tool;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;

View file

@ -64,7 +64,7 @@ final class Summary extends Command {
@Override
public List<String> getOptionSyntax() {
return Collections.singletonList("<file>");
return List.of("<file>");
}
@Override

View file

@ -44,6 +44,7 @@ final class Version extends Command {
System.out.println("1.0");
}
@Override
protected List<String> getAliases() {
return List.of("--version");
}