Skip to content

Commit 5709f79

Browse files
committed
8352648: JFR: 'jfr query' should not be available in product builds
Reviewed-by: mgronlun, shade
1 parent 02a4ce2 commit 5709f79

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

src/hotspot/share/jfr/jni/jfrJniMethod.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,11 @@ JVM_END
429429
NO_TRANSITION(jlong, jfr_nanos_now(JNIEnv* env, jclass jvm))
430430
return JfrChunk::nanos_now();
431431
NO_TRANSITION_END
432+
433+
NO_TRANSITION(jboolean, jfr_is_product(JNIEnv* env, jclass jvm))
434+
#ifdef PRODUCT
435+
return true;
436+
#else
437+
return false;
438+
#endif
439+
NO_TRANSITION_END

src/hotspot/share/jfr/jni/jfrJniMethod.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ void JNICALL jfr_unregister_stack_filter(JNIEnv* env, jclass jvm, jlong id);
167167

168168
jlong JNICALL jfr_nanos_now(JNIEnv* env, jclass jvm);
169169

170+
jboolean JNICALL jfr_is_product(JNIEnv* env, jclass jvm);
171+
170172
#ifdef __cplusplus
171173
}
172174
#endif

src/hotspot/share/jfr/jni/jfrJniMethodRegistration.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
100100
(char*)"emitDataLoss", (char*)"(J)V", (void*)jfr_emit_data_loss,
101101
(char*)"registerStackFilter", (char*)"([Ljava/lang/String;[Ljava/lang/String;)J", (void*)jfr_register_stack_filter,
102102
(char*)"unregisterStackFilter", (char*)"(J)V", (void*)jfr_unregister_stack_filter,
103-
(char*)"nanosNow", (char*)"()J", (void*)jfr_nanos_now
103+
(char*)"nanosNow", (char*)"()J", (void*)jfr_nanos_now,
104+
(char*)"isProduct", (char*)"()Z", (void*)jfr_is_product
104105
};
105106

106107
const size_t method_array_length = sizeof(method) / sizeof(JNINativeMethod);

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

+7
Original file line numberDiff line numberDiff line change
@@ -675,4 +675,11 @@ public final class JVM {
675675
* @param value
676676
*/
677677
public static native void setMiscellaneous(long eventTypeId, long value);
678+
679+
/**
680+
* Returns whether the current build is a product build.
681+
*
682+
* @return {@code true} if this is a product build, {@code false} otherwise.
683+
*/
684+
public static native boolean isProduct();
678685
}

src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Command.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import jdk.jfr.internal.util.UserDataException;
4444
import jdk.jfr.internal.util.UserSyntaxException;
45+
import jdk.jfr.internal.JVM;
4546

4647
abstract class Command {
4748
public static final String title = "Tool for working with Flight Recorder files";
@@ -51,8 +52,9 @@ abstract class Command {
5152
private static List<Command> createCommands() {
5253
List<Command> commands = new ArrayList<>();
5354
commands.add(new Print());
54-
// Uncomment when developing new queries for the view command
55-
commands.add(new Query());
55+
if (!JVM.isProduct()) {
56+
commands.add(new Query());
57+
}
5658
commands.add(new View());
5759
commands.add(new Configure());
5860
commands.add(new Metadata());

src/jdk.jfr/share/classes/jdk/jfr/internal/tool/Query.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,18 @@ public void displayOptionUsage(PrintStream p) {
9494
p.println(" WHERE B.when = 'Before GC' AND A.when = 'After GC'");
9595
p.println(" GROUP BY gcId");
9696
p.println(" ORDER BY G.startTime\" recording.jfr");
97+
p.println();
98+
p.println("************************************ WARNING ******************************************");
99+
p.println("The query command is only available in debug builds and is targeted towards OpenJDK");
100+
p.println("developers. The tool may be removed or its syntax changed at any time.");
101+
p.println("***************************************************************************************");
102+
p.println();
97103
}
98104

99105
@Override
100106
public List<String> getOptionSyntax() {
101107
List<String> list = new ArrayList<>();
102-
list.add("[--verbose] [--width <integer>] <query> <file>");
108+
list.add("[--verbose] [--width <integer>] <query> <file> (in debug builds)");
103109
return list;
104110
}
105111

0 commit comments

Comments
 (0)