|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2025, 2025, Red Hat Inc. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. Oracle designates this |
| 9 | + * particular file as subject to the "Classpath" exception as provided |
| 10 | + * by Oracle in the LICENSE file that accompanied this code. |
| 11 | + * |
| 12 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 16 | + * accompanied this code). |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License version |
| 19 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | + * |
| 22 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | + * or visit www.oracle.com if you need additional information or have any |
| 24 | + * questions. |
| 25 | + */ |
| 26 | + |
| 27 | +package com.oracle.svm.test.jfr; |
| 28 | + |
| 29 | +import static org.junit.Assert.assertFalse; |
| 30 | +import static org.junit.Assert.assertNotNull; |
| 31 | +import static org.junit.Assert.assertTrue; |
| 32 | + |
| 33 | +import java.util.HashSet; |
| 34 | +import java.util.List; |
| 35 | +import java.util.Set; |
| 36 | + |
| 37 | +import org.junit.Test; |
| 38 | + |
| 39 | +import com.oracle.svm.core.jfr.JfrEvent; |
| 40 | + |
| 41 | +import jdk.jfr.Recording; |
| 42 | +import jdk.jfr.consumer.RecordedEvent; |
| 43 | + |
| 44 | +public class TestGarbageCollectionEvents extends JfrRecordingTest { |
| 45 | + @Test |
| 46 | + public void test() throws Throwable { |
| 47 | + String[] events = new String[]{JfrEvent.GarbageCollection.getName()}; |
| 48 | + Recording recording = startRecording(events); |
| 49 | + System.gc(); |
| 50 | + System.gc(); |
| 51 | + System.gc(); |
| 52 | + stopRecording(recording, TestGarbageCollectionEvents::validateEvents); |
| 53 | + } |
| 54 | + |
| 55 | + private static void validateEvents(List<RecordedEvent> events) { |
| 56 | + assertFalse(events.isEmpty()); |
| 57 | + int foundSystemGc = 0; |
| 58 | + Set<Integer> ids = new HashSet<>(); |
| 59 | + for (RecordedEvent event : events) { |
| 60 | + assertTrue(ids.add(event.getInt("gcId"))); |
| 61 | + assertNotNull(event.getThread("eventThread").getJavaName()); |
| 62 | + assertFalse(event.getDuration().isZero()); |
| 63 | + assertNotNull(event.getString("name")); |
| 64 | + assertTrue(event.getLong("longestPause") > 0); |
| 65 | + assertTrue(event.getLong("sumOfPauses") > 0); |
| 66 | + if (event.getString("cause").equals("java.lang.System.gc()")) { |
| 67 | + foundSystemGc++; |
| 68 | + } |
| 69 | + } |
| 70 | + assertTrue(foundSystemGc >= 3); |
| 71 | + } |
| 72 | +} |
0 commit comments