Path: blob/master/test/hotspot/jtreg/serviceability/tmtools/jstat/utils/JstatGcCapacityResults.java
41159 views
/*1* Copyright (c) 2015, 2020, 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*/2223/*24* Results of running the JstatGcTool ("jstat -gccapacity <pid>")25*26* Output example:27* NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC CGC28* 0.0 4194304.0 6144.0 0.0 2048.0 4096.0 0.0 4194304.0 2048.0 2048.0 0.0 1056768.0 7680.0 0.0 1048576.0 768.0 4 0 029*30* Output description:31* NGCMN Minimum new generation capacity (KB).32* NGCMX Maximum new generation capacity (KB).33* NGC Current new generation capacity (KB).34* S0C Current survivor space 0 capacity (KB).35* S1C Current survivor space 1 capacity (KB).36* EC Current eden space capacity (KB).37* OGCMN Minimum old generation capacity (KB).38* OGCMX Maximum old generation capacity (KB).39* OGC Current old generation capacity (KB).40* OC Current old space capacity (KB).41* MCMN Minimum metaspace capacity (KB).42* MCMX Maximum metaspace capacity (KB).43* MC Current metaspace capacity (KB).44* YGC Number of Young generation GC Events.45* FGC Number of Full GC Events.46*/47package utils;4849import common.ToolResults;50import java.lang.management.GarbageCollectorMXBean;51import java.lang.management.ManagementFactory;52import java.util.Arrays;53import java.util.List;5455public class JstatGcCapacityResults extends JstatResults {5657public JstatGcCapacityResults(ToolResults rawResults) {58super(rawResults);59}6061/**62* Checks the overall consistency of the results reported by the tool63*/64@Override65public void assertConsistency() {6667// Check exit code68assertThat(getExitCode() == 0, "Unexpected exit code: " + getExitCode());6970// Check Young Gen consistency71float NGCMN = getFloatValue("NGCMN");72assertThat(NGCMN >= 0, "NGCMN < 0 (min generation capacity is negative)");73float NGCMX = getFloatValue("NGCMX");74assertThat(NGCMX >= NGCMN, "NGCMN > NGCMX (min generation capacity > max generation capacity)");7576float NGC = getFloatValue("NGC");77assertThat(NGC >= NGCMN, "NGC < NGCMN (generation capacity < min generation capacity)");78assertThat(NGC <= NGCMX, "NGC > NGCMX (generation capacity > max generation capacity)");7980float S0C = getFloatValue("S0C");81assertThat(S0C <= NGC, "S0C > NGC (survivor space 0 capacity > new generation capacity)");8283float S1C = getFloatValue("S1C");84assertThat(S1C <= NGC, "S1C > NGC (survivor space 1 capacity > new generation capacity)");8586float EC = getFloatValue("EC");87assertThat(EC <= NGC, "EC > NGC (eden space capacity > new generation capacity)");8889// Verify relative size of NGC and S0C + S1C + EC.90// The rule depends on if the tenured GC is parallel or not.91// For parallell GC: NGC >= S0C + S1C + EC92// For non-parallell GC: NGC == S0C + S1C + EC93boolean isTenuredParallelGC = isTenuredParallelGC();94String errMsg = String.format(95"NGC %s (S0C + S1C + EC) (NGC = %.1f, S0C = %.1f, S1C = %.1f, EC = %.1f, (S0C + S1C + EC) = %.1f)",96isTenuredParallelGC ? "<" : "!=", NGC, S0C, S1C, EC, S0C + S1C + EC);97if (isTenuredParallelGC) {98assertThat(NGC >= S0C + S1C + EC, errMsg);99} else {100assertThat(checkFloatIsSum(NGC, S0C, S1C, EC), errMsg);101}102103// Check Old Gen consistency104float OGCMN = getFloatValue("OGCMN");105assertThat(OGCMN >= 0, "OGCMN < 0 (min generation capacity is negative)");106float OGCMX = getFloatValue("OGCMX");107assertThat(OGCMX >= OGCMN, "OGCMN > OGCMX (min generation capacity > max generation capacity)");108109float OGC = getFloatValue("OGC");110assertThat(OGC >= OGCMN, "OGC < OGCMN (generation capacity < min generation capacity)");111assertThat(OGC <= OGCMX, "OGC > OGCMX (generation capacity > max generation capacity)");112float OC = getFloatValue("OC");113assertThat(OC == OGC, "OC != OGC (old generation capacity != old space capacity (these values should be equal since old space is made up only from one old generation))");114115// Check Metaspace consistency116float MCMN = getFloatValue("MCMN");117float MCMX = getFloatValue("MCMX");118assertThat(MCMX >= MCMN, "MCMN > MCMX (min generation capacity > max generation capacity)");119float MC = getFloatValue("MC");120assertThat(MC >= MCMN, "MC < MCMN (generation capacity < min generation capacity)");121assertThat(MC <= MCMX, "MGC > MCMX (generation capacity > max generation capacity)");122}123124/**125* Check if the tenured generation are currently using a parallel GC.126*/127protected static boolean isTenuredParallelGC() {128// Currently the only parallel GC for the tenured generation is PS MarkSweep.129List<String> parallelGCs = Arrays.asList(new String[] { "PS MarkSweep"});130try {131List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();132for (GarbageCollectorMXBean bean : beans) {133if (parallelGCs.contains(bean.getName())) {134return true;135}136}137} catch (Exception e) {138e.printStackTrace();139}140return false;141}142}143144145