Skip to content

Commit e08e94f

Browse files
committed
8310266: JFR: Refactor after 'view' command
Reviewed-by: mgronlun
1 parent f8f8bfb commit e08e94f

Some content is hidden

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

56 files changed

+974
-1098
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737
import java.util.Set;
3838
import java.util.StringJoiner;
3939

40+
import jdk.jfr.internal.SecuritySupport;
4041
import jdk.jfr.internal.Type;
4142
import jdk.jfr.internal.TypeLibrary;
42-
import jdk.jfr.internal.Utils;
43+
import jdk.jfr.internal.util.Utils;
4344

4445
/**
4546
* Describes event metadata, such as labels, descriptions and units.
@@ -114,7 +115,7 @@ public final class AnnotationElement {
114115
public AnnotationElement(Class<? extends Annotation> annotationType, Map<String, Object> values) {
115116
Objects.requireNonNull(annotationType, "annotationType");
116117
Objects.requireNonNull(values, "values");
117-
Utils.checkRegisterPermission();
118+
SecuritySupport.checkRegisterPermission();
118119
// copy values to avoid modification after validation
119120
HashMap<String, Object> map = new HashMap<>(values);
120121
for (Map.Entry<String, Object> entry : map.entrySet()) {

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -37,8 +37,9 @@
3737
import jdk.jfr.internal.EventClassBuilder;
3838
import jdk.jfr.internal.JVMSupport;
3939
import jdk.jfr.internal.MetadataRepository;
40+
import jdk.jfr.internal.SecuritySupport;
4041
import jdk.jfr.internal.Type;
41-
import jdk.jfr.internal.Utils;
42+
import jdk.jfr.internal.util.Utils;
4243

4344
/**
4445
* Class for defining an event at runtime.
@@ -101,7 +102,7 @@ public static EventFactory create(List<AnnotationElement> annotationElements, Li
101102
Objects.requireNonNull(fields, "fields");
102103
JVMSupport.ensureWithInternalError();
103104

104-
Utils.checkRegisterPermission();
105+
SecuritySupport.checkRegisterPermission();
105106

106107
List<AnnotationElement> sanitizedAnnotation = Utils.sanitizeNullFreeList(annotationElements, AnnotationElement.class);
107108
List<ValueDescriptor> sanitizedFields = Utils.sanitizeNullFreeList(fields, ValueDescriptor.class);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import jdk.jfr.internal.MetadataRepository;
3737
import jdk.jfr.internal.PlatformEventType;
3838
import jdk.jfr.internal.Type;
39-
import jdk.jfr.internal.Utils;
39+
import jdk.jfr.internal.util.Utils;
4040

4141
/**
4242
* Describes an event, its fields, settings and annotations.

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -44,7 +44,8 @@
4444
import jdk.jfr.internal.PlatformRecorder;
4545
import jdk.jfr.internal.PlatformRecording;
4646
import jdk.jfr.internal.Repository;
47-
import jdk.jfr.internal.Utils;
47+
import jdk.jfr.internal.SecuritySupport;
48+
import jdk.jfr.internal.util.Utils;
4849
import jdk.jfr.internal.periodic.PeriodicEvents;
4950

5051
/**
@@ -164,7 +165,7 @@ public static void unregister(Class<? extends Event> eventClass) {
164165
*/
165166
public static FlightRecorder getFlightRecorder() throws IllegalStateException, SecurityException {
166167
synchronized (PlatformRecorder.class) {
167-
Utils.checkAccessFlightRecorder();
168+
SecuritySupport.checkAccessFlightRecorder();
168169
JVMSupport.ensureWithIllegalStateException();
169170
if (platformRecorder == null) {
170171
try {
@@ -222,7 +223,7 @@ public static void addPeriodicEvent(Class<? extends Event> eventClass, Runnable
222223
}
223224

224225
Utils.ensureValidEventSubclass(eventClass);
225-
Utils.checkRegisterPermission();
226+
SecuritySupport.checkRegisterPermission();
226227
@SuppressWarnings("removal")
227228
AccessControlContext acc = AccessController.getContext();
228229
PeriodicEvents.addUserEvent(acc, eventClass, hook);
@@ -238,7 +239,7 @@ public static void addPeriodicEvent(Class<? extends Event> eventClass, Runnable
238239
*/
239240
public static boolean removePeriodicEvent(Runnable hook) throws SecurityException {
240241
Objects.requireNonNull(hook, "hook");
241-
Utils.checkRegisterPermission();
242+
SecuritySupport.checkRegisterPermission();
242243
if (JVMSupport.isNotAvailable()) {
243244
return false;
244245
}
@@ -275,7 +276,7 @@ public List<EventType> getEventTypes() {
275276
*/
276277
public static void addListener(FlightRecorderListener changeListener) {
277278
Objects.requireNonNull(changeListener, "changeListener");
278-
Utils.checkAccessFlightRecorder();
279+
SecuritySupport.checkAccessFlightRecorder();
279280
if (JVMSupport.isNotAvailable()) {
280281
return;
281282
}
@@ -299,7 +300,7 @@ public static void addListener(FlightRecorderListener changeListener) {
299300
*/
300301
public static boolean removeListener(FlightRecorderListener changeListener) {
301302
Objects.requireNonNull(changeListener, "changeListener");
302-
Utils.checkAccessFlightRecorder();
303+
SecuritySupport.checkAccessFlightRecorder();
303304
if (JVMSupport.isNotAvailable()) {
304305
return false;
305306
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,8 +34,8 @@
3434
import jdk.jfr.internal.PlatformRecorder;
3535
import jdk.jfr.internal.PlatformRecording;
3636
import jdk.jfr.internal.PrivateAccess;
37+
import jdk.jfr.internal.SecuritySupport;
3738
import jdk.jfr.internal.Type;
38-
import jdk.jfr.internal.Utils;
3939
import jdk.jfr.internal.management.EventSettingsModifier;
4040

4141
/**
@@ -221,7 +221,7 @@ public boolean isVisible(EventType t) {
221221
*/
222222
public FlightRecorderPermission(String name) {
223223
super(Objects.requireNonNull(name, "name"));
224-
if (!name.equals(Utils.ACCESS_FLIGHT_RECORDER) && !name.equals(Utils.REGISTER_EVENT)) {
224+
if (!name.equals(SecuritySupport.ACCESS_FLIGHT_RECORDER) && !name.equals(SecuritySupport.REGISTER_EVENT)) {
225225
throw new IllegalArgumentException("name: " + name);
226226
}
227227
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import jdk.jfr.internal.PlatformRecorder;
3939
import jdk.jfr.internal.PlatformRecording;
4040
import jdk.jfr.internal.Type;
41-
import jdk.jfr.internal.Utils;
41+
import jdk.jfr.internal.util.Utils;
4242
import jdk.jfr.internal.WriteableUserPath;
4343

4444
/**

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
import java.util.Objects;
3232

3333
import jdk.jfr.internal.AnnotationConstruct;
34+
import jdk.jfr.internal.SecuritySupport;
3435
import jdk.jfr.internal.Type;
35-
import jdk.jfr.internal.Utils;
36+
import jdk.jfr.internal.util.Utils;
3637

3738
/**
3839
* Describes the event fields and annotation elements.
@@ -149,7 +150,7 @@ public ValueDescriptor(Class<?> type, String name, List<AnnotationElement> annot
149150
Objects.requireNonNull(type, "type");
150151
Objects.requireNonNull(name, "name");
151152
Objects.requireNonNull(annotations, "annotations");
152-
Utils.checkRegisterPermission();
153+
SecuritySupport.checkRegisterPermission();
153154
if (!allowArray) {
154155
if (type.isArray()) {
155156
throw new IllegalArgumentException("Array types are not allowed");

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -36,7 +36,6 @@
3636
import java.util.function.Consumer;
3737

3838
import jdk.jfr.internal.SecuritySupport;
39-
import jdk.jfr.internal.Utils;
4039
import jdk.jfr.internal.consumer.EventDirectoryStream;
4140
import jdk.jfr.internal.consumer.EventFileStream;
4241
import jdk.jfr.internal.consumer.FileAccess;
@@ -120,7 +119,7 @@ public interface EventStream extends AutoCloseable {
120119
*/
121120
@SuppressWarnings("removal")
122121
public static EventStream openRepository() throws IOException {
123-
Utils.checkAccessFlightRecorder();
122+
SecuritySupport.checkAccessFlightRecorder();
124123
return new EventDirectoryStream(
125124
AccessController.getContext(),
126125
null,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import jdk.jfr.internal.PlatformRecording;
4747
import jdk.jfr.internal.PrivateAccess;
4848
import jdk.jfr.internal.SecuritySupport;
49-
import jdk.jfr.internal.Utils;
49+
import jdk.jfr.internal.util.Utils;
5050
import jdk.jfr.internal.consumer.EventDirectoryStream;
5151
import jdk.jfr.internal.management.StreamBarrier;
5252

@@ -102,7 +102,7 @@ public RecordingStream() {
102102
}
103103

104104
private RecordingStream(Map<String, String> settings) {
105-
Utils.checkAccessFlightRecorder();
105+
SecuritySupport.checkAccessFlightRecorder();
106106
@SuppressWarnings("removal")
107107
AccessControlContext acc = AccessController.getContext();
108108
this.recording = new Recording();

src/jdk.jfr/share/classes/jdk/jfr/events/EventConfigurations.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,15 +24,15 @@
2424
*/
2525

2626
package jdk.jfr.events;
27-
import jdk.jfr.internal.Utils;
27+
import jdk.jfr.internal.JVMSupport;
2828
import jdk.jfr.internal.event.EventConfiguration;
2929

3030
public final class EventConfigurations {
31-
public static final EventConfiguration SOCKET_READ = Utils.getConfiguration(SocketReadEvent.class);
32-
public static final EventConfiguration SOCKET_WRITE = Utils.getConfiguration(SocketWriteEvent.class);
33-
public static final EventConfiguration FILE_READ = Utils.getConfiguration(FileReadEvent.class);
34-
public static final EventConfiguration FILE_WRITE = Utils.getConfiguration(FileWriteEvent.class);
35-
public static final EventConfiguration FILE_FORCE = Utils.getConfiguration(FileForceEvent.class);
36-
public static final EventConfiguration ERROR_THROWN = Utils.getConfiguration(ErrorThrownEvent.class);
37-
public static final EventConfiguration EXCEPTION_THROWN = Utils.getConfiguration(ExceptionThrownEvent.class);
31+
public static final EventConfiguration SOCKET_READ = JVMSupport.getConfiguration(SocketReadEvent.class);
32+
public static final EventConfiguration SOCKET_WRITE = JVMSupport.getConfiguration(SocketWriteEvent.class);
33+
public static final EventConfiguration FILE_READ = JVMSupport.getConfiguration(FileReadEvent.class);
34+
public static final EventConfiguration FILE_WRITE = JVMSupport.getConfiguration(FileWriteEvent.class);
35+
public static final EventConfiguration FILE_FORCE = JVMSupport.getConfiguration(FileForceEvent.class);
36+
public static final EventConfiguration ERROR_THROWN = JVMSupport.getConfiguration(ErrorThrownEvent.class);
37+
public static final EventConfiguration EXCEPTION_THROWN = JVMSupport.getConfiguration(ExceptionThrownEvent.class);
3838
}

src/jdk.jfr/share/classes/jdk/jfr/internal/Control.java

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,6 +35,9 @@
3535

3636
import jdk.jfr.SettingControl;
3737
import jdk.jfr.internal.settings.JDKSettingControl;
38+
import jdk.jfr.internal.settings.PeriodSetting;
39+
import jdk.jfr.internal.settings.StackTraceSetting;
40+
import jdk.jfr.internal.settings.ThresholdSetting;
3841

3942
final class Control {
4043
@SuppressWarnings("removal")
@@ -176,4 +179,17 @@ final String getLastValue() {
176179
final SettingControl getSettingControl() {
177180
return delegate;
178181
}
182+
183+
boolean isVisible(boolean hasEventHook) {
184+
if (isType(ThresholdSetting.class)) {
185+
return !hasEventHook;
186+
}
187+
if (isType(PeriodSetting.class)) {
188+
return hasEventHook;
189+
}
190+
if (isType(StackTraceSetting.class)) {
191+
return !hasEventHook;
192+
}
193+
return true;
194+
}
179195
}

src/jdk.jfr/share/classes/jdk/jfr/internal/EventControl.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -50,6 +50,7 @@
5050
import jdk.jfr.internal.settings.StackTraceSetting;
5151
import jdk.jfr.internal.settings.ThresholdSetting;
5252
import jdk.jfr.internal.settings.ThrottleSetting;
53+
import jdk.jfr.internal.util.Utils;
5354

5455
// This class can't have a hard reference from PlatformEventType, since it
5556
// holds SettingControl instances that need to be released
@@ -282,7 +283,7 @@ void writeActiveSettingEvent(long timestamp) {
282283
return;
283284
}
284285
for (NamedControl nc : namedControls) {
285-
if (Utils.isSettingVisible(nc.control, type.hasEventHook()) && type.isVisible()) {
286+
if (nc.control.isVisible(type.hasEventHook()) && type.isVisible()) {
286287
String value = nc.control.getLastValue();
287288
if (value == null) {
288289
value = nc.control.getDefaultValue();

src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,6 +53,7 @@
5353
import jdk.jfr.SettingDefinition;
5454
import jdk.jfr.internal.event.EventConfiguration;
5555
import jdk.jfr.internal.event.EventWriter;
56+
import jdk.jfr.internal.util.Utils;
5657

5758
/**
5859
* Class responsible for adding instrumentation to a subclass of {@link Event}.

0 commit comments

Comments
 (0)