Path: blob/master/src/java.management/share/classes/sun/management/HotspotCompilation.java
41152 views
/*1* Copyright (c) 2003, 2015, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.management;2627import java.util.regex.*;28import java.util.List;29import java.util.ListIterator;30import java.util.Iterator;31import java.util.ArrayList;32import java.util.Map;33import java.util.TreeMap;34import sun.management.counter.*;3536/**37* Implementation class of HotspotCompilationMBean interface.38*39* Internal, uncommitted management interface for Hotspot compilation40* system.41*42*/43class HotspotCompilation44implements HotspotCompilationMBean {4546private VMManagement jvm;4748/**49* Constructor of HotspotRuntime class.50*/51HotspotCompilation(VMManagement vm) {52jvm = vm;53initCompilerCounters();54}5556// Performance counter support57private static final String JAVA_CI = "java.ci.";58private static final String COM_SUN_CI = "com.sun.ci.";59private static final String SUN_CI = "sun.ci.";60private static final String CI_COUNTER_NAME_PATTERN =61JAVA_CI + "|" + COM_SUN_CI + "|" + SUN_CI;6263private LongCounter compilerThreads;64private LongCounter totalCompiles;65private LongCounter totalBailouts;66private LongCounter totalInvalidates;67private LongCounter nmethodCodeSize;68private LongCounter nmethodSize;69private StringCounter lastMethod;70private LongCounter lastSize;71private LongCounter lastType;72private StringCounter lastFailedMethod;73private LongCounter lastFailedType;74private StringCounter lastInvalidatedMethod;75private LongCounter lastInvalidatedType;7677private class CompilerThreadInfo {78String name;79StringCounter method;80LongCounter type;81LongCounter compiles;82LongCounter time;83CompilerThreadInfo(String bname, int index) {84String basename = bname + "." + index + ".";85this.name = bname + "-" + index;86this.method = (StringCounter) lookup(basename + "method");87this.type = (LongCounter) lookup(basename + "type");88this.compiles = (LongCounter) lookup(basename + "compiles");89this.time = (LongCounter) lookup(basename + "time");90}9192@SuppressWarnings("deprecation")93CompilerThreadStat getCompilerThreadStat() {94MethodInfo minfo = new MethodInfo(method.stringValue(),95(int) type.longValue(),96-1);97return new CompilerThreadStat(name,98compiles.longValue(),99time.longValue(),100minfo);101}102}103private List<CompilerThreadInfo> threads;104private int numActiveThreads; // number of active compiler threads105106private Map<String, Counter> counters;107private Counter lookup(String name) {108Counter c = null;109110// Only one counter exists with the specified name in the111// current implementation. We first look up in the SUN_CI namespace112// since most counters are in SUN_CI namespace.113114if ((c = counters.get(SUN_CI + name)) != null) {115return c;116}117if ((c = counters.get(COM_SUN_CI + name)) != null) {118return c;119}120if ((c = counters.get(JAVA_CI + name)) != null) {121return c;122}123124// FIXME: should tolerate if counter doesn't exist125throw new AssertionError("Counter " + name + " does not exist");126}127128private void initCompilerCounters() {129// Build a tree map of the current list of performance counters130counters = new TreeMap<>();131for (Counter c: getInternalCompilerCounters()) {132counters.put(c.getName(), c);133}134135compilerThreads = (LongCounter) lookup("threads");136totalCompiles = (LongCounter) lookup("totalCompiles");137totalBailouts = (LongCounter) lookup("totalBailouts");138totalInvalidates = (LongCounter) lookup("totalInvalidates");139nmethodCodeSize = (LongCounter) lookup("nmethodCodeSize");140nmethodSize = (LongCounter) lookup("nmethodSize");141lastMethod = (StringCounter) lookup("lastMethod");142lastSize = (LongCounter) lookup("lastSize");143lastType = (LongCounter) lookup("lastType");144lastFailedMethod = (StringCounter) lookup("lastFailedMethod");145lastFailedType = (LongCounter) lookup("lastFailedType");146lastInvalidatedMethod = (StringCounter) lookup("lastInvalidatedMethod");147lastInvalidatedType = (LongCounter) lookup("lastInvalidatedType");148149numActiveThreads = (int) compilerThreads.longValue();150151// Allocate CompilerThreadInfo for compilerThread and adaptorThread152threads = new ArrayList<CompilerThreadInfo>();153154for (int i = 0; i < numActiveThreads; i++) {155if (counters.containsKey(SUN_CI + "compilerThread." + i + ".method")) {156threads.add(new CompilerThreadInfo("compilerThread", i));157}158}159}160161public int getCompilerThreadCount() {162return numActiveThreads;163}164165public long getTotalCompileCount() {166return totalCompiles.longValue();167}168169public long getBailoutCompileCount() {170return totalBailouts.longValue();171}172173public long getInvalidatedCompileCount() {174return totalInvalidates.longValue();175}176177public long getCompiledMethodCodeSize() {178return nmethodCodeSize.longValue();179}180181public long getCompiledMethodSize() {182return nmethodSize.longValue();183}184185@Deprecated186public List<CompilerThreadStat> getCompilerThreadStats() {187List<CompilerThreadStat> list = new ArrayList<>(threads.size());188for (CompilerThreadInfo info : threads) {189list.add(info.getCompilerThreadStat());190}191return list;192}193194public MethodInfo getLastCompile() {195return new MethodInfo(lastMethod.stringValue(),196(int) lastType.longValue(),197(int) lastSize.longValue());198}199200public MethodInfo getFailedCompile() {201return new MethodInfo(lastFailedMethod.stringValue(),202(int) lastFailedType.longValue(),203-1);204}205206public MethodInfo getInvalidatedCompile() {207return new MethodInfo(lastInvalidatedMethod.stringValue(),208(int) lastInvalidatedType.longValue(),209-1);210}211212public java.util.List<Counter> getInternalCompilerCounters() {213return jvm.getInternalCounters(CI_COUNTER_NAME_PATTERN);214}215}216217218