-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8352414: JFR: JavaMonitorDeflateEvent crashes when deflated monitor object is dead #24121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
shipilev
wants to merge
3
commits into
openjdk:master
from
shipilev:JDK-8352414-jfr-deflation-regression
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
test/jdk/jdk/jfr/event/runtime/StressJavaMonitorEvents.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| /* | ||
| * Copyright Amazon.com Inc. 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 | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| package jdk.jfr.event.runtime; | ||
|
|
||
| import static jdk.test.lib.Asserts.assertTrue; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.atomic.AtomicLong; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.ThreadLocalRandom; | ||
|
|
||
| import jdk.jfr.consumer.RecordingStream; | ||
| import jdk.jfr.consumer.RecordedClass; | ||
| import jdk.jfr.consumer.RecordedEvent; | ||
| import jdk.test.lib.jfr.EventNames; | ||
| import jdk.test.lib.jfr.Events; | ||
| import jdk.test.lib.thread.TestThread; | ||
| import jdk.test.lib.thread.XRun; | ||
|
|
||
| /** | ||
| * @test StressJavaMonitorEvents | ||
| * @summary Tests that VM does not crash when monitor-related JFR events are enabled | ||
| * @requires vm.flagless | ||
| * @requires vm.hasJFR | ||
| * @library /test/lib | ||
| * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:GuaranteedAsyncDeflationInterval=100 jdk.jfr.event.runtime.StressJavaMonitorEvents | ||
| */ | ||
| public class StressJavaMonitorEvents { | ||
|
|
||
| static final int RUN_TIME_MS = 10000; | ||
| static final int GC_EVERY_MS = 500; | ||
| static final int THREADS = 4; | ||
| static final int NUM_LOCKS = 1024; | ||
|
|
||
| static final List<String> CAPTURE_EVENTS = List.of( | ||
| EventNames.JavaMonitorEnter, | ||
| EventNames.JavaMonitorWait, | ||
| EventNames.JavaMonitorNotify, | ||
| EventNames.JavaMonitorInflate, | ||
| EventNames.JavaMonitorDeflate, | ||
| EventNames.JavaMonitorStatistics | ||
| ); | ||
|
|
||
| static final Set<String> CAN_BE_ZERO_EVENTS = Set.of( | ||
| // Only when lock actually gets contended, not guaranteed. | ||
| EventNames.JavaMonitorEnter, | ||
| // Only when there are waiters on the lock, not guaranteed. | ||
| EventNames.JavaMonitorNotify | ||
| ); | ||
|
|
||
| static final Object[] LOCKS = new Object[NUM_LOCKS]; | ||
|
|
||
| public static TestThread startThread(final long deadline) { | ||
| TestThread t = new TestThread(new XRun() { | ||
| @Override | ||
| public void xrun() throws Throwable { | ||
| ThreadLocalRandom r = ThreadLocalRandom.current(); | ||
| while (System.nanoTime() < deadline) { | ||
| // Overwrite random lock, making the old one dead | ||
| LOCKS[r.nextInt(NUM_LOCKS)] = new Object(); | ||
|
|
||
| // Wait on random lock, inflating it | ||
| Object waitLock = LOCKS[r.nextInt(NUM_LOCKS)]; | ||
| if (waitLock != null) { | ||
| synchronized (waitLock) { | ||
| waitLock.wait(1); | ||
| } | ||
| } | ||
|
|
||
| // Notify a random lock | ||
| Object notifyLock = LOCKS[r.nextInt(NUM_LOCKS)]; | ||
| if (notifyLock != null) { | ||
| synchronized (notifyLock) { | ||
| notifyLock.notify(); | ||
| } | ||
| } | ||
|
|
||
| // Notify all on a random lock | ||
| Object notifyAllLock = LOCKS[r.nextInt(NUM_LOCKS)]; | ||
| if (notifyAllLock != null) { | ||
| synchronized (notifyAllLock) { | ||
| notifyAllLock.notifyAll(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| t.start(); | ||
| return t; | ||
| } | ||
|
|
||
| public static void main(String[] args) throws Exception { | ||
| Map<String, AtomicLong> counters = new HashMap<>(); | ||
|
|
||
| try (RecordingStream rs = new RecordingStream()) { | ||
| // Setup all interesting events, and start recording. | ||
| for (String ev : CAPTURE_EVENTS) { | ||
| rs.enable(ev).withoutThreshold(); | ||
| AtomicLong counter = new AtomicLong(); | ||
| rs.onEvent(ev, e -> counter.incrementAndGet()); | ||
| counters.put(ev, counter); | ||
| } | ||
| rs.startAsync(); | ||
|
|
||
| long deadline = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(RUN_TIME_MS); | ||
| List<TestThread> threads = new ArrayList<>(); | ||
| for (int t = 0; t < THREADS; t++) { | ||
| threads.add(startThread(deadline)); | ||
| } | ||
|
|
||
| // Trigger GCs periodically to yield dead objects with inflated monitors. | ||
| while (System.nanoTime() < deadline) { | ||
| Thread.sleep(GC_EVERY_MS); | ||
| System.gc(); | ||
| } | ||
|
|
||
| // Wait for all threads to exit and close the recording. | ||
| for (TestThread t : threads) { | ||
| t.join(); | ||
| } | ||
| rs.close(); | ||
|
|
||
| // Print stats and check event counts. | ||
| for (String ev : CAPTURE_EVENTS) { | ||
| long count = counters.get(ev).get(); | ||
| System.out.println(ev + ": " + count); | ||
| assertTrue(CAN_BE_ZERO_EVENTS.contains(ev) || (count > 0)); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.