Path: blob/master/test/jdk/jdk/jfr/event/gc/detailed/TestG1EvacMemoryStatsEvent.java
42283 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22package jdk.jfr.event.gc.detailed;2324import java.util.List;2526import jdk.jfr.Recording;27import jdk.jfr.consumer.RecordedEvent;28import jdk.test.lib.jfr.EventNames;29import jdk.test.lib.jfr.Events;3031/**32* @test33* @key jfr34* @requires vm.hasJFR35* @requires vm.gc == "G1" | vm.gc == null36* @library /test/lib /test/jdk37* @run main/othervm -XX:NewSize=2m -XX:MaxNewSize=2m -Xmx32m -XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:-UseFastUnorderedTimeStamps jdk.jfr.event.gc.detailed.TestG1EvacMemoryStatsEvent38*/39public class TestG1EvacMemoryStatsEvent {4041public static byte[] bytes;4243public static void runTest(String event_name) throws Exception {4445Recording recording = new Recording();4647// activate the event we are interested in and start recording48recording.enable(event_name);49recording.start();5051// Setting NewSize and MaxNewSize will limit eden, so52// allocating 1024 5k byte arrays should trigger at53// least one Young GC.54for (int i = 0; i < 1024; i++) {55bytes = new byte[5 * 1024];56}57recording.stop();5859// Verify recording60List<RecordedEvent> all = Events.fromRecording(recording);61for (RecordedEvent e : all) {62Events.assertField(e, "statistics.gcId").above(0);63}6465recording.close();66}6768public static void main(String[] args) throws Exception {69runTest(EventNames.G1EvacuationYoungStatistics);70runTest(EventNames.G1EvacuationOldStatistics);71}7273}747576