From 78141024c23efab479b9e3cac851198299166155 Mon Sep 17 00:00:00 2001 From: Pushkar Kulkarni Date: Mon, 20 Nov 2023 14:50:23 +0000 Subject: [PATCH] 8244508: JFR: FlightRecorderOptions reset date format Reviewed-by: clanger Backport-of: f3519016c7766934d0aa3014b1a0593d91a0556c --- src/hotspot/share/jfr/dcmd/jfrDcmds.cpp | 6 ++- src/hotspot/share/jfr/dcmd/jfrDcmds.hpp | 4 ++ .../jfr/recorder/service/jfrOptionSet.cpp | 1 + .../jdk/jfr/internal/dcmd/DCmdConfigure.java | 41 ++++++++++++++----- .../startupargs/TestOptionsWithLocale.java | 40 ++++++++++++++++++ 5 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 test/jdk/jdk/jfr/startupargs/TestOptionsWithLocale.java diff --git a/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp b/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp index 4aa5c56f3bb..024b5b57063 100644 --- a/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp +++ b/src/hotspot/share/jfr/dcmd/jfrDcmds.cpp @@ -556,7 +556,8 @@ JfrConfigureFlightRecorderDCmd::JfrConfigureFlightRecorderDCmd(outputStream* out _thread_buffer_size("thread_buffer_size", "Size of a thread buffer", "MEMORY SIZE", false, "8k"), _memory_size("memorysize", "Overall memory size, ", "MEMORY SIZE", false, "10m"), _max_chunk_size("maxchunksize", "Size of an individual disk chunk", "MEMORY SIZE", false, "12m"), - _sample_threads("samplethreads", "Activate Thread sampling", "BOOLEAN", false, "true") { + _sample_threads("samplethreads", "Activate Thread sampling", "BOOLEAN", false, "true"), + _verbose(true) { _dcmdparser.add_dcmd_option(&_repository_path); _dcmdparser.add_dcmd_option(&_dump_path); _dcmdparser.add_dcmd_option(&_stack_depth); @@ -643,7 +644,7 @@ void JfrConfigureFlightRecorderDCmd::execute(DCmdSource source, TRAPS) { static const char klass[] = "jdk/jfr/internal/dcmd/DCmdConfigure"; static const char method[] = "execute"; - static const char signature[] = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Integer;" + static const char signature[] = "(ZLjava/lang/String;Ljava/lang/String;Ljava/lang/Integer;" "Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;Ljava/lang/Long;" "Ljava/lang/Long;Ljava/lang/Boolean;)Ljava/lang/String;"; @@ -651,6 +652,7 @@ void JfrConfigureFlightRecorderDCmd::execute(DCmdSource source, TRAPS) { execute_args.set_receiver(h_dcmd_instance); // params + execute_args.push_int(_verbose ? 1 : 0); execute_args.push_jobject(repository_path); execute_args.push_jobject(dump_path); execute_args.push_jobject(stack_depth); diff --git a/src/hotspot/share/jfr/dcmd/jfrDcmds.hpp b/src/hotspot/share/jfr/dcmd/jfrDcmds.hpp index 15d8091a792..7468f7c5180 100644 --- a/src/hotspot/share/jfr/dcmd/jfrDcmds.hpp +++ b/src/hotspot/share/jfr/dcmd/jfrDcmds.hpp @@ -150,9 +150,13 @@ class JfrConfigureFlightRecorderDCmd : public DCmdWithParser { DCmdArgument _memory_size; DCmdArgument _max_chunk_size; DCmdArgument _sample_threads; + bool _verbose; public: JfrConfigureFlightRecorderDCmd(outputStream* output, bool heap); + void set_verbose(bool verbose) { + _verbose = verbose; + } static const char* name() { return "JFR.configure"; } diff --git a/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp b/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp index 74d1be1aad9..364718f9e63 100644 --- a/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp +++ b/src/hotspot/share/jfr/recorder/service/jfrOptionSet.cpp @@ -366,6 +366,7 @@ bool JfrOptionSet::configure(TRAPS) { configure._sample_threads.set_is_set(_dcmd_sample_threads.is_set()); configure._sample_threads.set_value(_dcmd_sample_threads.value()); + configure.set_verbose(false); configure.execute(DCmd_Source_Internal, THREAD); if (HAS_PENDING_EXCEPTION) { diff --git a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java index f15053a7caa..f2625aa6c5b 100644 --- a/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java +++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/dcmd/DCmdConfigure.java @@ -59,6 +59,7 @@ final class DCmdConfigure extends AbstractDCmd { */ public String execute ( + boolean verbose, String repositoryPath, String dumpPath, Integer stackDepth, @@ -92,66 +93,86 @@ final class DCmdConfigure extends AbstractDCmd { } catch (Exception e) { throw new DCmdException("Could not use " + repositoryPath + " as repository. " + e.getMessage(), e); } - printRepositoryPath(); + if (verbose) { + printRepositoryPath(); + } updated = true; } if (dumpPath != null) { Options.setDumpPath(new SafePath(dumpPath)); Logger.log(LogTag.JFR, LogLevel.INFO, "Emergency dump path set to " + dumpPath); - printDumpPath(); + if (verbose) { + printDumpPath(); + } updated = true; } if (stackDepth != null) { Options.setStackDepth(stackDepth); Logger.log(LogTag.JFR, LogLevel.INFO, "Stack depth set to " + stackDepth); - printStackDepth(); + if (verbose) { + printStackDepth(); + } updated = true; } if (globalBufferCount != null) { Options.setGlobalBufferCount(globalBufferCount); Logger.log(LogTag.JFR, LogLevel.INFO, "Global buffer count set to " + globalBufferCount); - printGlobalBufferCount(); + if (verbose) { + printGlobalBufferCount(); + } updated = true; } if (globalBufferSize != null) { Options.setGlobalBufferSize(globalBufferSize); Logger.log(LogTag.JFR, LogLevel.INFO, "Global buffer size set to " + globalBufferSize); - printGlobalBufferSize(); + if (verbose) { + printGlobalBufferSize(); + } updated = true; } if (threadBufferSize != null) { Options.setThreadBufferSize(threadBufferSize); Logger.log(LogTag.JFR, LogLevel.INFO, "Thread buffer size set to " + threadBufferSize); - printThreadBufferSize(); + if (verbose) { + printThreadBufferSize(); + } updated = true; } if (memorySize != null) { Options.setMemorySize(memorySize); Logger.log(LogTag.JFR, LogLevel.INFO, "Memory size set to " + memorySize); - printMemorySize(); + if (verbose) { + printMemorySize(); + } updated = true; } if (maxChunkSize != null) { Options.setMaxChunkSize(maxChunkSize); Logger.log(LogTag.JFR, LogLevel.INFO, "Max chunk size set to " + maxChunkSize); - printMaxChunkSize(); + if (verbose) { + printMaxChunkSize(); + } updated = true; } if (sampleThreads != null) { Options.setSampleThreads(sampleThreads); Logger.log(LogTag.JFR, LogLevel.INFO, "Sample threads set to " + sampleThreads); - printSampleThreads(); + if (verbose) { + printSampleThreads(); + } updated = true; } - + if (!verbose) { + return ""; + } if (!updated) { println("Current configuration:"); println(); diff --git a/test/jdk/jdk/jfr/startupargs/TestOptionsWithLocale.java b/test/jdk/jdk/jfr/startupargs/TestOptionsWithLocale.java new file mode 100644 index 00000000000..1d1a79040f3 --- /dev/null +++ b/test/jdk/jdk/jfr/startupargs/TestOptionsWithLocale.java @@ -0,0 +1,40 @@ +package jdk.jfr.startupargs; + +import java.io.IOException; +import java.text.DateFormat; +import java.util.Calendar; +import java.util.GregorianCalendar; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +/** + * @test + * @summary Checks that locale is respected when using -XX:FlightRecorderOptions + * See JDK-8244508 + * @key jfr + * @requires vm.hasJFR + * @modules jdk.jfr + * @library /test/lib + * @run main jdk.jfr.startupargs.TestOptionsWithLocale + */ +public class TestOptionsWithLocale { + + public static class PrintDate { + public static void main(String... args) { + GregorianCalendar date = new GregorianCalendar(2020, Calendar.JANUARY, 1); + DateFormat formatter = DateFormat.getDateTimeInstance(); + System.out.println(formatter.format(date.getTime())); + } + } + + public static void main(String... args) throws IOException { + ProcessBuilder pb = ProcessTools.createTestJvm( + "-Duser.country=DE", + "-Duser.language=de", + "-XX:FlightRecorderOptions:stackdepth=128", + PrintDate.class.getName()); + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("01.01.2020, 00:00:00"); + } +}