Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/management/HotspotCompilation.java
38827 views
/*1* Copyright (c) 2003, 2012, 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 {78int index;79String name;80StringCounter method;81LongCounter type;82LongCounter compiles;83LongCounter time;84CompilerThreadInfo(String bname, int index) {85String basename = bname + "." + index + ".";86this.name = bname + "-" + index;87this.method = (StringCounter) lookup(basename + "method");88this.type = (LongCounter) lookup(basename + "type");89this.compiles = (LongCounter) lookup(basename + "compiles");90this.time = (LongCounter) lookup(basename + "time");91}92CompilerThreadInfo(String bname) {93String basename = bname + ".";94this.name = bname;95this.method = (StringCounter) lookup(basename + "method");96this.type = (LongCounter) lookup(basename + "type");97this.compiles = (LongCounter) lookup(basename + "compiles");98this.time = (LongCounter) lookup(basename + "time");99}100101CompilerThreadStat getCompilerThreadStat() {102MethodInfo minfo = new MethodInfo(method.stringValue(),103(int) type.longValue(),104-1);105return new CompilerThreadStat(name,106compiles.longValue(),107time.longValue(),108minfo);109}110}111private CompilerThreadInfo[] threads;112private int numActiveThreads; // number of active compiler threads113114private Map<String, Counter> counters;115private Counter lookup(String name) {116Counter c = null;117118// Only one counter exists with the specified name in the119// current implementation. We first look up in the SUN_CI namespace120// since most counters are in SUN_CI namespace.121122if ((c = counters.get(SUN_CI + name)) != null) {123return c;124}125if ((c = counters.get(COM_SUN_CI + name)) != null) {126return c;127}128if ((c = counters.get(JAVA_CI + name)) != null) {129return c;130}131132// FIXME: should tolerate if counter doesn't exist133throw new AssertionError("Counter " + name + " does not exist");134}135136private void initCompilerCounters() {137// Build a tree map of the current list of performance counters138counters = new TreeMap<>();139for (Counter c: getInternalCompilerCounters()) {140counters.put(c.getName(), c);141}142143compilerThreads = (LongCounter) lookup("threads");144totalCompiles = (LongCounter) lookup("totalCompiles");145totalBailouts = (LongCounter) lookup("totalBailouts");146totalInvalidates = (LongCounter) lookup("totalInvalidates");147nmethodCodeSize = (LongCounter) lookup("nmethodCodeSize");148nmethodSize = (LongCounter) lookup("nmethodSize");149lastMethod = (StringCounter) lookup("lastMethod");150lastSize = (LongCounter) lookup("lastSize");151lastType = (LongCounter) lookup("lastType");152lastFailedMethod = (StringCounter) lookup("lastFailedMethod");153lastFailedType = (LongCounter) lookup("lastFailedType");154lastInvalidatedMethod = (StringCounter) lookup("lastInvalidatedMethod");155lastInvalidatedType = (LongCounter) lookup("lastInvalidatedType");156157numActiveThreads = (int) compilerThreads.longValue();158159// Allocate CompilerThreadInfo for compilerThread and adaptorThread160threads = new CompilerThreadInfo[numActiveThreads+1];161162// AdaptorThread has index 0163if (counters.containsKey(SUN_CI + "adapterThread.compiles")) {164threads[0] = new CompilerThreadInfo("adapterThread", 0);165numActiveThreads++;166} else {167threads[0] = null;168}169170for (int i = 1; i < threads.length; i++) {171threads[i] = new CompilerThreadInfo("compilerThread", i-1);172}173}174175public int getCompilerThreadCount() {176return numActiveThreads;177}178179public long getTotalCompileCount() {180return totalCompiles.longValue();181}182183public long getBailoutCompileCount() {184return totalBailouts.longValue();185}186187public long getInvalidatedCompileCount() {188return totalInvalidates.longValue();189}190191public long getCompiledMethodCodeSize() {192return nmethodCodeSize.longValue();193}194195public long getCompiledMethodSize() {196return nmethodSize.longValue();197}198199public java.util.List<CompilerThreadStat> getCompilerThreadStats() {200List<CompilerThreadStat> list = new ArrayList<>(threads.length);201int i = 0;202if (threads[0] == null) {203// no adaptor thread204i = 1;205}206for (; i < threads.length; i++) {207list.add(threads[i].getCompilerThreadStat());208}209return list;210}211212public MethodInfo getLastCompile() {213return new MethodInfo(lastMethod.stringValue(),214(int) lastType.longValue(),215(int) lastSize.longValue());216}217218public MethodInfo getFailedCompile() {219return new MethodInfo(lastFailedMethod.stringValue(),220(int) lastFailedType.longValue(),221-1);222}223224public MethodInfo getInvalidatedCompile() {225return new MethodInfo(lastInvalidatedMethod.stringValue(),226(int) lastInvalidatedType.longValue(),227-1);228}229230public java.util.List<Counter> getInternalCompilerCounters() {231return jvm.getInternalCounters(CI_COUNTER_NAME_PATTERN);232}233}234235236