Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions test/jdk/jdk/jfr/event/gc/collection/GCEventAll.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2026, 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
Expand Down Expand Up @@ -166,9 +166,11 @@ private void verify(List<RecordedEvent> events, GCHelper.CollectionSummary beanC
List<GCHelper.GcBatch> gcBatches = null;
GCHelper.CollectionSummary eventCounts = null;

// For some GC configurations, the JFR recording may have stopped before we received the last gc event.
// The first/last GC batch can be incomplete if recording starts before all
// event settings are applied or stops before all events are received.
try {
gcBatches = GCHelper.GcBatch.createFromEvents(events);
List<RecordedEvent> completeEvents = GCHelper.removeFirstAndLastGC(events);
gcBatches = GCHelper.GcBatch.createFromEvents(completeEvents);
eventCounts = GCHelper.CollectionSummary.createFromEvents(gcBatches);

verifyUniqueIds(gcBatches);
Expand Down Expand Up @@ -244,9 +246,10 @@ private void verifyCollectionCount(String collector, long eventCounts, long bean
}
// JFR events and GarbageCollectorMXBean events are not updated at the same time.
// This means that number of collections may diff.
// We allow a diff of +- 1 collection count.
long minCount = Math.max(0, beanCounts - 1);
long maxCount = beanCounts + 1;
// We allow a diff of +- 2 collection counts, since the first and last
// GC batches are removed to avoid recording-boundary races.
long minCount = Math.max(0, beanCounts - 2);
long maxCount = beanCounts + 2;
Asserts.assertGreaterThanOrEqual(eventCounts, minCount, "Too few event counts for collector " + collector);
Asserts.assertLessThanOrEqual(eventCounts, maxCount, "Too many event counts for collector " + collector);
}
Expand Down