GcCauseTest01.java revision 9990:91be2fb6db87
138494Sobrien/* 2174313Sobrien * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 338494Sobrien * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 438494Sobrien * 538494Sobrien * This code is free software; you can redistribute it and/or modify it 638494Sobrien * under the terms of the GNU General Public License version 2 only, as 738494Sobrien * published by the Free Software Foundation. 838494Sobrien * 938494Sobrien * This code is distributed in the hope that it will be useful, but WITHOUT 1038494Sobrien * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1138494Sobrien * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1238494Sobrien * version 2 for more details (a copy is included in the LICENSE file that 1338494Sobrien * accompanied this code). 1438494Sobrien * 1538494Sobrien * You should have received a copy of the GNU General Public License version 1638494Sobrien * 2 along with this work; if not, write to the Free Software Foundation, 1738494Sobrien * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1838494Sobrien * 1938494Sobrien * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2042633Sobrien * or visit www.oracle.com if you need additional information or have any 2138494Sobrien * questions. 2238494Sobrien */ 2338494Sobrien 2438494Sobrien/* 2538494Sobrien * @test 2638494Sobrien * @summary Test checks output displayed with jstat -gccause. 2738494Sobrien * Test scenario: 2838494Sobrien * test several times provokes garbage collection in the debuggee application and after each garbage 2938494Sobrien * collection runs jstat. jstat should show that after garbage collection number of GC events and garbage 3038494Sobrien * collection time increase. 3138494Sobrien * @library /test/lib/share/classes 3238494Sobrien * @library ../share 3338494Sobrien * @ignore 8147848 3438494Sobrien * @build common.* 3538494Sobrien * @build utils.* 3638494Sobrien * 3738494Sobrien * @run main/othervm -XX:+UsePerfData GcCauseTest01 3838494Sobrien */ 3938494Sobrienimport utils.*; 40174313Sobrien 4138494Sobrienpublic class GcCauseTest01 { 4238494Sobrien 4338494Sobrien public static void main(String[] args) throws Exception { 4438494Sobrien 4538494Sobrien // We will be running "jstat -gc" tool 4638494Sobrien JstatGcCauseTool jstatGcTool = new JstatGcCauseTool(ProcessHandle.current().getPid()); 4738494Sobrien 4838494Sobrien // Run once and get the results asserting that they are reasonable 4938494Sobrien JstatGcCauseResults measurement1 = jstatGcTool.measure(); 5038494Sobrien measurement1.assertConsistency(); 5138494Sobrien 5241145Sobrien GcProvoker gcProvoker = GcProvoker.createGcProvoker(); 5341145Sobrien 5441145Sobrien // Provoke GC then run the tool again and get the results asserting that they are reasonable 5541145Sobrien gcProvoker.provokeGc(); 5641145Sobrien JstatGcCauseResults measurement2 = jstatGcTool.measure(); 5738494Sobrien measurement2.assertConsistency(); 5838494Sobrien 5938494Sobrien // Assert the increase in GC events and time between the measurements 6038494Sobrien JstatResults.assertGCEventsIncreased(measurement1, measurement2); 6138494Sobrien JstatResults.assertGCTimeIncreased(measurement1, measurement2); 6238494Sobrien 6338494Sobrien // Provoke GC 3rd time then run the tool 3rd time twice and get the results 6438494Sobrien // asserting that they are reasonable 6538494Sobrien gcProvoker.provokeGc(); 6638494Sobrien JstatGcCauseResults measurement3 = jstatGcTool.measure(); 6738494Sobrien measurement3.assertConsistency(); 6838494Sobrien 6938494Sobrien // Assert the increase in GC events and time between the measurements 7038494Sobrien JstatResults.assertGCEventsIncreased(measurement2, measurement3); 7138494Sobrien JstatResults.assertGCTimeIncreased(measurement2, measurement3); 7238494Sobrien } 7338494Sobrien} 7438494Sobrien