Path: blob/master/test/jdk/sun/jvmstat/perfdata/PrologSanity/PrologSizeSanityCheck.java
41152 views
/*1* Copyright (c) 2004, 2017, 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* @test25* @bug 499082526* @summary prolog size and overflow sanity checks27*28* @run main/othervm -XX:+UsePerfData PrologSizeSanityCheck29*/3031import sun.jvmstat.monitor.*;3233public class PrologSizeSanityCheck {3435private static final String sizeName = "sun.perfdata.size";36private static final String usedName = "sun.perfdata.used";37private static final String overflowName = "sun.perfdata.overflow";38private static final int K = 1024;3940public static void main(String args[]) throws Exception {4142VmIdentifier vmid = new VmIdentifier("0");43MonitoredHost localhost = MonitoredHost.getMonitoredHost("localhost");44MonitoredVm self = localhost.getMonitoredVm(vmid);4546IntegerMonitor prologSize = (IntegerMonitor)self.findByName(sizeName);47IntegerMonitor prologUsed = (IntegerMonitor)self.findByName(usedName);48IntegerMonitor prologOverflow =49(IntegerMonitor)self.findByName(overflowName);5051if (prologOverflow.intValue() != 0) {52throw new RuntimeException("jvmstat memory buffer overflow: "53+ sizeName + "=" + prologSize.intValue()54+ usedName + "=" + prologUsed.intValue()55+ overflowName + "=" + prologOverflow.intValue()56+ " : PerfDataMemorySize must be increased");57}5859if (prologUsed.intValue() + 3*K >= prologSize.intValue()) {60/*61* we want to leave at least 3K of space to allow for long62* string names in the various path oriented strings and for63* the command line argument and vm argument strings. 3K is64* somewhat of an arbitrary figure, but it is based on failure65* scenarios observed in SQE when jvmstat was originally66* introduced in 1.4.1.67*/68throw new RuntimeException(69"jvmstat memory buffer usage approaching size: "70+ sizeName + "=" + prologSize.intValue()71+ usedName + "=" + prologUsed.intValue()72+ " : consider increasing PerfDataMemorySize");73}74}75}767778