1 /* 2 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jdk.jfr.event.gc.detailed; 24 25 import java.nio.file.Paths; 26 import java.util.List; 27 28 import jdk.jfr.EventType; 29 import jdk.jfr.FlightRecorder; 30 import jdk.jfr.Recording; 31 import jdk.jfr.consumer.RecordedEvent; 32 import jdk.test.lib.Asserts; 33 import jdk.test.lib.jfr.EventNames; 34 import jdk.test.lib.jfr.Events; 35 import jdk.test.lib.jfr.GCHelper; 36 37 public class TestG1HeapRegionInformationEvent { 38 private final static String EVENT_NAME = EventNames.G1HeapRegionInformation; main(String[] args)39 public static void main(String[] args) throws Exception { 40 Recording recording = null; 41 try { 42 recording = new Recording(); 43 // activate the event we are interested in and start recording 44 for (EventType t : FlightRecorder.getFlightRecorder().getEventTypes()) { 45 System.out.println(t.getName()); 46 } 47 recording.enable(EVENT_NAME); 48 recording.start(); 49 recording.stop(); 50 51 // Verify recording 52 List<RecordedEvent> events = Events.fromRecording(recording); 53 Events.hasEvents(events); 54 55 for (RecordedEvent event : events) { 56 Events.assertField(event, "index").notEqual(-1); 57 Asserts.assertTrue(GCHelper.isValidG1HeapRegionType(Events.assertField(event, "type").getValue())); 58 Events.assertField(event, "used").atMost(1L*1024*1024); 59 } 60 61 } catch (Throwable t) { 62 if (recording != null) { 63 recording.dump(Paths.get("TestG1HeapRegionInformationEvent.jfr")); 64 } 65 throw t; 66 } finally { 67 if (recording != null) { 68 recording.close(); 69 } 70 } 71 } 72 } 73