GcCauseTest01.java revision 12343:1b7fd4c2f65e
133965Sjdp/* 233965Sjdp * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. 333965Sjdp * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 433965Sjdp * 533965Sjdp * This code is free software; you can redistribute it and/or modify it 633965Sjdp * under the terms of the GNU General Public License version 2 only, as 733965Sjdp * published by the Free Software Foundation. 833965Sjdp * 933965Sjdp * This code is distributed in the hope that it will be useful, but WITHOUT 1033965Sjdp * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1133965Sjdp * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1233965Sjdp * version 2 for more details (a copy is included in the LICENSE file that 1333965Sjdp * accompanied this code). 1433965Sjdp * 1533965Sjdp * You should have received a copy of the GNU General Public License version 1633965Sjdp * 2 along with this work; if not, write to the Free Software Foundation, 1733965Sjdp * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1833965Sjdp * 1933965Sjdp * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2033965Sjdp * or visit www.oracle.com if you need additional information or have any 2133965Sjdp * questions. 2233965Sjdp */ 2333965Sjdp 2433965Sjdp/* 2533965Sjdp * @test 2633965Sjdp * @summary Test checks output displayed with jstat -gccause. 2733965Sjdp * Test scenario: 2833965Sjdp * test several times provokes garbage collection in the debuggee application and after each garbage 2933965Sjdp * collection runs jstat. jstat should show that after garbage collection number of GC events and garbage 3033965Sjdp * collection time increase. 3133965Sjdp * @modules java.base/jdk.internal.misc 3233965Sjdp * @library /test/lib 3333965Sjdp * @library ../share 3433965Sjdp * @requires vm.opt.ExplicitGCInvokesConcurrent != true 3533965Sjdp * @run main/othervm -XX:+UsePerfData -Xmx128M GcCauseTest01 3633965Sjdp */ 3733965Sjdpimport utils.*; 3833965Sjdp 3933965Sjdppublic class GcCauseTest01 { 4033965Sjdp 4133965Sjdp public static void main(String[] args) throws Exception { 4233965Sjdp 4333965Sjdp // We will be running "jstat -gc" tool 4433965Sjdp JstatGcCauseTool jstatGcTool = new JstatGcCauseTool(ProcessHandle.current().getPid()); 4533965Sjdp 4633965Sjdp // Run once and get the results asserting that they are reasonable 4733965Sjdp JstatGcCauseResults measurement1 = jstatGcTool.measure(); 4833965Sjdp measurement1.assertConsistency(); 4933965Sjdp 5033965Sjdp GcProvoker gcProvoker = new GcProvoker(); 5133965Sjdp 5233965Sjdp // Provoke GC then run the tool again and get the results asserting that they are reasonable 5333965Sjdp gcProvoker.provokeGc(); 5433965Sjdp JstatGcCauseResults measurement2 = jstatGcTool.measure(); 5533965Sjdp measurement2.assertConsistency(); 5633965Sjdp 5733965Sjdp // Assert the increase in GC events and time between the measurements 5833965Sjdp JstatResults.assertGCEventsIncreased(measurement1, measurement2); 5933965Sjdp JstatResults.assertGCTimeIncreased(measurement1, measurement2); 6033965Sjdp 6133965Sjdp // Provoke GC 3rd time then run the tool 3rd time twice and get the results 6233965Sjdp // asserting that they are reasonable 6333965Sjdp gcProvoker.provokeGc(); 6433965Sjdp JstatGcCauseResults measurement3 = jstatGcTool.measure(); 6533965Sjdp measurement3.assertConsistency(); 6633965Sjdp 6733965Sjdp // Assert the increase in GC events and time between the measurements 6833965Sjdp JstatResults.assertGCEventsIncreased(measurement2, measurement3); 6933965Sjdp JstatResults.assertGCTimeIncreased(measurement2, measurement3); 7033965Sjdp } 7133965Sjdp} 7233965Sjdp