1 /*
   2  * Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4990825
  27  * @summary prolog size and overflow sanity checks
  28  *
  29  * @run main/othervm -XX:+UsePerfData PrologSizeSanityCheck
  30  */
  31 
  32 import sun.jvmstat.monitor.*;
  33 
  34 public class PrologSizeSanityCheck {
  35 
  36     private static final String sizeName = "sun.perfdata.size";
  37     private static final String usedName = "sun.perfdata.used";
  38     private static final String overflowName = "sun.perfdata.overflow";
  39     private static final int K = 1024;
  40 
  41     public static void main(String args[]) throws Exception {
  42 
  43         VmIdentifier vmid = new VmIdentifier("0");
  44         MonitoredHost localhost = MonitoredHost.getMonitoredHost("localhost");
  45         MonitoredVm self = localhost.getMonitoredVm(vmid);
  46 
  47         IntegerMonitor prologSize = (IntegerMonitor)self.findByName(sizeName);
  48         IntegerMonitor prologUsed = (IntegerMonitor)self.findByName(usedName);
  49         IntegerMonitor prologOverflow =
  50                 (IntegerMonitor)self.findByName(overflowName);
  51 
  52         if (prologOverflow.intValue() != 0) {
  53             throw new RuntimeException("jvmstat memory buffer overflow: "
  54                     + sizeName + "=" + prologSize.intValue()
  55                     + usedName + "=" + prologUsed.intValue()
  56                     + overflowName + "=" + prologOverflow.intValue()
  57                     + " : PerfDataMemorySize must be increased");
  58         }
  59 
  60         if (prologUsed.intValue() + 3*K >= prologSize.intValue()) {
  61           /*
  62            * we want to leave at least 3K of space to allow for long
  63            * string names in the various path oriented strings and for
  64            * the command line argument and vm argument strings. 3K is
  65            * somewhat of an arbitrary figure, but it is based on failure
  66            * scenarios observed in SQE when jvmstat was originally
  67            * introduced in 1.4.1.
  68            */
  69             throw new RuntimeException(
  70                    "jvmstat memory buffer usage approaching size: "
  71                     + sizeName + "=" + prologSize.intValue()
  72                     + usedName + "=" + prologUsed.intValue()
  73                     + " : consider increasing PerfDataMemorySize");
  74         }
  75     }
  76 }