From 202fd421f7e8b0f4a9c7393d1045e879acd13e64 Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Tue, 17 Sep 2024 22:36:37 +0000 Subject: [PATCH] 8340213: jcmd VM.events ignores max argument Reviewed-by: szaldana, cjplummer, amenkov, mli --- .../share/services/diagnosticCommand.cpp | 1 - .../serviceability/dcmd/vm/EventsTest.java | 24 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/services/diagnosticCommand.cpp b/src/hotspot/share/services/diagnosticCommand.cpp index 7a2c0838146..4d4a5239b3b 100644 --- a/src/hotspot/share/services/diagnosticCommand.cpp +++ b/src/hotspot/share/services/diagnosticCommand.cpp @@ -899,7 +899,6 @@ void EventLogDCmd::execute(DCmdSource source, TRAPS) { int max = -1; if (max_value != nullptr) { char* endptr = nullptr; - int max; if (!parse_integer(max_value, &max)) { output()->print_cr("Invalid max option: \"%s\".", max_value); return; diff --git a/test/hotspot/jtreg/serviceability/dcmd/vm/EventsTest.java b/test/hotspot/jtreg/serviceability/dcmd/vm/EventsTest.java index b5fca58a5c5..9828a8990e0 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/vm/EventsTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/vm/EventsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,7 @@ import jdk.test.lib.dcmd.CommandExecutor; import jdk.test.lib.dcmd.JMXExecutor; import jdk.test.lib.process.OutputAnalyzer; import org.testng.annotations.Test; +import org.testng.Assert; /* * @test @@ -38,6 +39,9 @@ import org.testng.annotations.Test; */ public class EventsTest { + // MAX should be less than number of actually recorded events + private static int MAX = 9; + static String buildHeaderPattern(String logname) { return "^" + logname + ".*\\(\\d+ events\\):"; } @@ -64,9 +68,27 @@ public class EventsTest { output.stdoutShouldNotMatch(buildHeaderPattern("Classes unloaded")); } + public void run_max(CommandExecutor executor) { + OutputAnalyzer output = executor.execute("VM.events max=" + MAX); + long lines = output.asLines().stream().filter(x -> x.contains("Loading class")).count(); + Assert.assertTrue(lines == MAX, "There are should be " + MAX + " lines"); + } + + public void run_max_selected(CommandExecutor executor) { + OutputAnalyzer output = executor.execute("VM.events log=load max=" + MAX); + output.stdoutShouldMatch(buildHeaderPattern("Classes loaded")); + long lines = output.asLines().stream().filter(x -> x.contains("Loading class")).count(); + Assert.assertTrue(lines == MAX, "There are should be " + MAX + " lines"); + output.stdoutShouldNotMatch(buildHeaderPattern("Events")); + output.stdoutShouldNotMatch(buildHeaderPattern("Compilation")); + } + + @Test public void jmx() { run_all(new JMXExecutor()); run_selected(new JMXExecutor()); + run_max(new JMXExecutor()); + run_max_selected(new JMXExecutor()); } }