diff --git a/make/sun/tools/Makefile b/make/sun/tools/Makefile index a041eb0c7b0898429a6d6beb51edefe5b93ee2eb..ebfcff5132c21eb537f6403ec58ba0e05b9664df 100644 --- a/make/sun/tools/Makefile +++ b/make/sun/tools/Makefile @@ -49,7 +49,8 @@ AUTO_FILES_JAVA_DIRS = \ # Extra jstat files FILES_copy += \ - $(CLASSDESTDIR)/sun/tools/jstat/resources/jstat_options + $(CLASSDESTDIR)/sun/tools/jstat/resources/jstat_options \ + $(CLASSDESTDIR)/sun/tools/jstat/resources/jstat_unsupported_options # Extra jhat files JHAT_RESOURCEDIR = $(CLASSDESTDIR)/com/sun/tools/hat/resources diff --git a/src/share/classes/sun/tools/jstat/Arguments.java b/src/share/classes/sun/tools/jstat/Arguments.java index a6453203a1c785ce1aaec52f67cb9991bdcbe3d1..1519175598819033aaa7590128c19624077c5d48 100644 --- a/src/share/classes/sun/tools/jstat/Arguments.java +++ b/src/share/classes/sun/tools/jstat/Arguments.java @@ -47,6 +47,7 @@ public class Arguments { private static final String JVMSTAT_USERDIR = ".jvmstat"; private static final String OPTIONS_FILENAME = "jstat_options"; + private static final String UNSUPPORTED_OPTIONS_FILENAME = "jstat_unsupported_options"; private static final String ALL_NAMES = "\\w*"; private Comparator comparator; @@ -411,8 +412,8 @@ public class Arguments { return optionFormat; } - public URL[] optionsSources() { - URL[] sources = new URL[2]; + public List optionsSources() { + List sources = new ArrayList(); int i = 0; String filename = OPTIONS_FILENAME; @@ -421,7 +422,7 @@ public class Arguments { String userHome = System.getProperty("user.home"); String userDir = userHome + "/" + JVMSTAT_USERDIR; File home = new File(userDir + "/" + filename); - sources[i++] = home.toURL(); + sources.add(home.toURI().toURL()); } catch (Exception e) { if (debug) { System.err.println(e.getMessage()); @@ -430,8 +431,15 @@ public class Arguments { throw new IllegalArgumentException("Internal Error: Bad URL: " + e.getMessage()); } - sources[i] = this.getClass().getResource("resources/" + filename); - assert sources[i] != null; + URL u = this.getClass().getResource("resources/" + filename); + assert u != null; + sources.add(u); + + if (showUnsupported) { + u = this.getClass().getResource("resources/" + UNSUPPORTED_OPTIONS_FILENAME); + assert u != null; + sources.add(u); + } return sources; } } diff --git a/src/share/classes/sun/tools/jstat/OptionFinder.java b/src/share/classes/sun/tools/jstat/OptionFinder.java index 628bd6c9965ac904b8baba4268bc5c015e535dc2..6efa5737a78616e694d9a9dd700203c189d3e27e 100644 --- a/src/share/classes/sun/tools/jstat/OptionFinder.java +++ b/src/share/classes/sun/tools/jstat/OptionFinder.java @@ -39,9 +39,9 @@ public class OptionFinder { private static final boolean debug = false; - URL[] optionsSources; + List optionsSources; - public OptionFinder(URL[] optionsSources) { + public OptionFinder(List optionsSources) { this.optionsSources = optionsSources; } @@ -59,24 +59,25 @@ public class OptionFinder { return of; } - protected OptionFormat getOptionFormat(String option, URL[] sources) { + protected OptionFormat getOptionFormat(String option, List sources) { OptionFormat of = null; - for (int i = 0; (i < sources.length) && (of == null); i++) { + for (URL u : sources) { try { - URL u = sources[i]; Reader r = new BufferedReader( new InputStreamReader(u.openStream())); of = new Parser(r).parse(option); + if (of != null) + break; } catch (IOException e) { if (debug) { - System.err.println("Error processing " + sources[i] + System.err.println("Error processing " + u + " : " + e.getMessage()); e.printStackTrace(); } } catch (ParserException e) { // Exception in parsing the options file. - System.err.println(sources[i] + ": " + e.getMessage()); - System.err.println("Parsing of " + sources[i] + " aborted"); + System.err.println(u + ": " + e.getMessage()); + System.err.println("Parsing of " + u + " aborted"); } } return of; diff --git a/src/share/classes/sun/tools/jstat/OptionLister.java b/src/share/classes/sun/tools/jstat/OptionLister.java index d274a4082fcb236667014b00c6258fa2915a728d..5ed55647d8d71ea8cd2df7bd932107bb6df81f83 100644 --- a/src/share/classes/sun/tools/jstat/OptionLister.java +++ b/src/share/classes/sun/tools/jstat/OptionLister.java @@ -37,9 +37,9 @@ import java.io.*; */ public class OptionLister { private static final boolean debug = false; - private URL[] sources; + private List sources; - public OptionLister(URL[] sources) { + public OptionLister(List sources) { this.sources = sources; } @@ -54,9 +54,8 @@ public class OptionLister { Set options = new TreeSet(c); - for (int i = 0; i < sources.length; i++) { + for (URL u : sources) { try { - URL u = sources[i]; Reader r = new BufferedReader( new InputStreamReader(u.openStream())); Set s = new Parser(r).parseOptions(); @@ -68,8 +67,8 @@ public class OptionLister { } } catch (ParserException e) { // Exception in parsing the options file. - System.err.println(sources[i] + ": " + e.getMessage()); - System.err.println("Parsing of " + sources[i] + " aborted"); + System.err.println(u + ": " + e.getMessage()); + System.err.println("Parsing of " + u + " aborted"); } } diff --git a/src/share/classes/sun/tools/jstat/resources/jstat_options b/src/share/classes/sun/tools/jstat/resources/jstat_options index a32027d4d058f5d3f265b650996474f1924a0f95..f339965e599776d42cdc872793fcf4dd7c65c05e 100644 --- a/src/share/classes/sun/tools/jstat/resources/jstat_options +++ b/src/share/classes/sun/tools/jstat/resources/jstat_options @@ -37,7 +37,7 @@ option timestamp { option class { column { header "^Loaded^" /* Number of classes loaded */ - data java.cls.loadedClasses + data (java.cls.loadedClasses + java.cls.sharedLoadedClasses) align right scale raw width 5 @@ -45,7 +45,7 @@ option class { } column { header "^Bytes^" /* Accumulated Size of classes loaded */ - data sun.cls.loadedBytes + data (sun.cls.loadedBytes + sun.cls.sharedLoadedBytes) align right scale K width 7 @@ -53,7 +53,7 @@ option class { } column { header "^Unloaded^" /* Number of classes unloaded */ - data java.cls.unloadedClasses + data (java.cls.unloadedClasses + java.cls.sharedUnloadedClasses) align right width 5 scale raw @@ -61,7 +61,7 @@ option class { } column { header "^Bytes^" /* Accumulated size of classes unloaded */ - data sun.cls.unloadedBytes + data (sun.cls.unloadedBytes + sun.cls.sharedUnloadedBytes) align right scale K width 7 diff --git a/src/share/classes/sun/tools/jstat/resources/jstat_unsupported_options b/src/share/classes/sun/tools/jstat/resources/jstat_unsupported_options new file mode 100644 index 0000000000000000000000000000000000000000..37008e332ca020b7a74ab48b1f0ca5ca694cd8fb --- /dev/null +++ b/src/share/classes/sun/tools/jstat/resources/jstat_unsupported_options @@ -0,0 +1,228 @@ +/* + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +option classload { + column { + header "^Loaded^" /* Number of classes loaded */ + data (java.cls.loadedClasses + java.cls.sharedLoadedClasses) + align right + scale raw + width 5 + format "0" + } + column { + header "Time^" /* Accumulated time for class loading */ + data sun.cls.time/sun.os.hrt.frequency + scale sec + align right + width 10 + format "0.000" + } + column { + header "^Inited^" /* Number of initialized classes */ + data sun.cls.initializedClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Time^" /* Accumulated time for class initialization */ + data sun.cls.classInitTime.self/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "Shared^" /* Number of system classes loaded from shared archive */ + data java.cls.sharedLoadedClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Kbytes^" /* Accumulated Size of classes loaded */ + data sun.cls.sharedLoadedBytes + align right + scale K + width 7 + format "0.0" + } + column { + header "LoadTime^" /* Accumulated time for loading classes from shared archive */ + data sun.cls.sharedClassLoadTime/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "^SysClass^" /* Number of system classes loaded */ + data java.cls.loadedClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Kbytes^" /* Bytes read from system class files */ + data sun.cls.sysClassBytes + align right + scale K + width 7 + format "0.0" + } + column { + header "LoadTime^" /* Accumulated time for loading non-shared system classes */ + data sun.cls.sysClassLoadTime/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "Lookup^" /* Time spent in looking up/reading of system classes */ + data sun.cls.lookupSysClassTime/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "Parse^" /* Time spent in parsing system classes */ + data sun.cls.parseClassTime.self/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "^Linked^" /* Number of linked classes */ + data sun.cls.linkedClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Time^" /* Accumulated time for class linking */ + data sun.cls.classInitTime.self/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "^Verified^" /* Number of verified classes */ + data sun.cls.verifiedClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Time^" /* Accumulated time for class verification */ + data sun.cls.classVerifyTime.self/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "AppClass^" /* Number of loaded application classes */ + data sun.cls.appClassLoadCount + align right + scale raw + width 5 + format "0" + } + column { + header "Kbytes^" /* Bytes read from app class files */ + data sun.cls.appClassBytes + align right + scale K + width 7 + format "0.0" + } + column { + header "AppCL^" /* Accumulated time for loading app classes */ + data sun.cls.appClassLoadTime/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "^DefineClass^" /* Number of defineClass calls */ + data sun.cls.defineAppClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Time^" /* Accumulated time for defineClass */ + data sun.cls.defineAppClassTime.self/sun.os.hrt.frequency + scale raw + align right + width 10 + format "0.000" + } + column { + header "^FindClass^" /* Number of findClass calls */ + data sun.classloader.findClasses + align right + scale raw + width 5 + format "0" + } + column { + header "Time^" /* Accumulated time for findClass */ + data sun.classloader.findClassTime/1000000000 + scale raw + align right + width 10 + format "0.000" + } + column { + header "Delegation^" /* Parent class loader delegation time */ + data sun.classloader.parentDelegationTime/1000000000 + scale raw + align right + width 10 + format "0.000" + } + column { + header "URLCL Read^" /* Accumulated time for URLClassLoader reading bytes */ + data sun.urlClassLoader.readClassBytesTime/1000000000 + scale raw + align right + width 10 + format "0.000" + } +} + diff --git a/test/sun/tools/jstat/classloadOutput1.awk b/test/sun/tools/jstat/classloadOutput1.awk new file mode 100644 index 0000000000000000000000000000000000000000..66e2b5dcd18626033a7226e8ca0c96cea42cddc0 --- /dev/null +++ b/test/sun/tools/jstat/classloadOutput1.awk @@ -0,0 +1,31 @@ +# +# matching the following output specified as a pattern that verifies +# that the numerical values conform to a specific pattern, rather than +# specific values. +# +# Loaded Time Inited Time Shared Kbytes LoadTime SysClass Kbytes LoadTime Lookup Parse Linked Time Verified Time AppClass Kbytes AppCL DefineClass Time FindClass Time Delegation URLCL Read +# 956 0.115 777 0.032 0 0.0 0.000 956 3437.5 0.085 0.013 0.045 918 0.032 917 0.011 13 1.0 0.003 1 0.000 1 0.004 0.005 0.000 +# + +BEGIN { + headerlines=0; datalines=0; totallines=0 + } + +/^Loaded Time Inited Time Shared Kbytes LoadTime SysClass Kbytes LoadTime Lookup Parse Linked Time Verified Time AppClass Kbytes AppCL DefineClass Time FindClass Time Delegation URLCL Read$/ { + headerlines++; + } + +/^[ ]*[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9][ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9][ ]*[0-9]+\.[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9][ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+\.[0-9]+[ ]*[0-9]+\.[0-9]+$/ { + datalines++; + } + + { totallines++; print $0 } + +END { + if ((headerlines == 1) && (datalines == 1) && (totallines == 2)) { + exit 0 + } + else { + exit 1 + } + } diff --git a/test/sun/tools/jstat/jstatClassloadOutput1.sh b/test/sun/tools/jstat/jstatClassloadOutput1.sh new file mode 100644 index 0000000000000000000000000000000000000000..42e5bf1b0c1ba20941ebdc42c21f94c8cc45b1e5 --- /dev/null +++ b/test/sun/tools/jstat/jstatClassloadOutput1.sh @@ -0,0 +1,36 @@ +# +# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# @test +# @bug 6959965 +# @run shell jstatClassloadOutput1.sh +# @summary Test that output of 'jstat -classload 0' has expected line counts + +. ${TESTSRC-.}/../../jvmstat/testlibrary/utils.sh + +setup +verify_os + +JSTAT="${TESTJAVA}/bin/jstat" + +${JSTAT} -classload -J-Djstat.showUnsupported=true 0 2>&1 | awk -f ${TESTSRC}/classloadOutput1.awk diff --git a/test/sun/tools/jstat/jstatOptions1.sh b/test/sun/tools/jstat/jstatOptions1.sh index c8d012003086d5853ae824d3bc952b47c612d933..af9367f7915d2b365f6651fa3d4364bf7fb5ed85 100644 --- a/test/sun/tools/jstat/jstatOptions1.sh +++ b/test/sun/tools/jstat/jstatOptions1.sh @@ -32,7 +32,9 @@ setup JSTAT="${TESTJAVA}/bin/jstat" -rm -f jstat.out 2>/dev/null -${JSTAT} -options > jstat.out 2>&1 +rm -f jstat.out1 jstat.out2 2>/dev/null +${JSTAT} -options > jstat.out1 2>&1 +${JSTAT} -options -J-Djstat.showUnsupported=true > jstat.out2 2>&1 -diff -w jstat.out ${TESTSRC}/options1.out +diff -w jstat.out1 ${TESTSRC}/options1.out +diff -w jstat.out2 ${TESTSRC}/options2.out diff --git a/test/sun/tools/jstat/options2.out b/test/sun/tools/jstat/options2.out new file mode 100644 index 0000000000000000000000000000000000000000..5d05d60f0dc4451057cd1c324cf1427cb6694909 --- /dev/null +++ b/test/sun/tools/jstat/options2.out @@ -0,0 +1,13 @@ +-class +-classload +-compiler +-gc +-gccapacity +-gccause +-gcnew +-gcnewcapacity +-gcold +-gcoldcapacity +-gcpermcapacity +-gcutil +-printcompilation