Showing the changes to java/pkg/sun/management/HotspotCompilation.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,236 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2003, 2008, 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. Oracle designates this | ||
| 8 | * particular file as subject to the "Classpath" exception as provided | ||
| 9 | * by Oracle in the LICENSE file that accompanied this code. | ||
| 10 | * | ||
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| 14 | * version 2 for more details (a copy is included in the LICENSE file that | ||
| 15 | * accompanied this code). | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU General Public License version | ||
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, | ||
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| 20 | * | ||
| 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| 22 | * or visit www.oracle.com if you need additional information or have any | ||
| 23 | * questions. | ||
| 24 | */ | ||
| 25 | |||
| 26 | package sun.management; | ||
| 27 | |||
| 28 | import java.util.regex.*; | ||
| 29 | import java.util.List; | ||
| 30 | import java.util.ListIterator; | ||
| 31 | import java.util.Iterator; | ||
| 32 | import java.util.ArrayList; | ||
| 33 | import java.util.Map; | ||
| 34 | import java.util.TreeMap; | ||
| 35 | import sun.management.counter.*; | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Implementation class of HotspotCompilationMBean interface. | ||
| 39 | * | ||
| 40 | * Internal, uncommitted management interface for Hotspot compilation | ||
| 41 | * system. | ||
| 42 | * | ||
| 43 | */ | ||
| 44 | class HotspotCompilation | ||
| 45 | implements HotspotCompilationMBean { | ||
| 46 | |||
| 47 | private VMManagement jvm; | ||
| 48 | |||
| 49 | /** | ||
| 50 | * Constructor of HotspotRuntime class. | ||
| 51 | */ | ||
| 52 | HotspotCompilation(VMManagement vm) { | ||
| 53 | jvm = vm; | ||
| 54 | initCompilerCounters(); | ||
| 55 | } | ||
| 56 | |||
| 57 | // Performance counter support | ||
| 58 | private static final String JAVA_CI = "java.ci."; | ||
| 59 | private static final String COM_SUN_CI = "com.sun.ci."; | ||
| 60 | private static final String SUN_CI = "sun.ci."; | ||
| 61 | private static final String CI_COUNTER_NAME_PATTERN = | ||
| 62 | JAVA_CI + "|" + COM_SUN_CI + "|" + SUN_CI; | ||
| 63 | |||
| 64 | private LongCounter compilerThreads; | ||
| 65 | private LongCounter totalCompiles; | ||
| 66 | private LongCounter totalBailouts; | ||
| 67 | private LongCounter totalInvalidates; | ||
| 68 | private LongCounter nmethodCodeSize; | ||
| 69 | private LongCounter nmethodSize; | ||
| 70 | private StringCounter lastMethod; | ||
| 71 | private LongCounter lastSize; | ||
| 72 | private LongCounter lastType; | ||
| 73 | private StringCounter lastFailedMethod; | ||
| 74 | private LongCounter lastFailedType; | ||
| 75 | private StringCounter lastInvalidatedMethod; | ||
| 76 | private LongCounter lastInvalidatedType; | ||
| 77 | |||
| 78 | private class CompilerThreadInfo { | ||
| 79 | int index; | ||
| 80 | String name; | ||
| 81 | StringCounter method; | ||
| 82 | LongCounter type; | ||
| 83 | LongCounter compiles; | ||
| 84 | LongCounter time; | ||
| 85 | CompilerThreadInfo(String bname, int index) { | ||
| 86 | String basename = bname + "." + index + "."; | ||
| 87 | this.name = bname + "-" + index; | ||
| 88 | this.method = (StringCounter) lookup(basename + "method"); | ||
| 89 | this.type = (LongCounter) lookup(basename + "type"); | ||
| 90 | this.compiles = (LongCounter) lookup(basename + "compiles"); | ||
| 91 | this.time = (LongCounter) lookup(basename + "time"); | ||
| 92 | } | ||
| 93 | CompilerThreadInfo(String bname) { | ||
| 94 | String basename = bname + "."; | ||
| 95 | this.name = bname; | ||
| 96 | this.method = (StringCounter) lookup(basename + "method"); | ||
| 97 | this.type = (LongCounter) lookup(basename + "type"); | ||
| 98 | this.compiles = (LongCounter) lookup(basename + "compiles"); | ||
| 99 | this.time = (LongCounter) lookup(basename + "time"); | ||
| 100 | } | ||
| 101 | |||
| 102 | CompilerThreadStat getCompilerThreadStat() { | ||
| 103 | MethodInfo minfo = new MethodInfo(method.stringValue(), | ||
| 104 | (int) type.longValue(), | ||
| 105 | -1); | ||
| 106 | return new CompilerThreadStat(name, | ||
| 107 | compiles.longValue(), | ||
| 108 | time.longValue(), | ||
| 109 | minfo); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | private CompilerThreadInfo[] threads; | ||
| 113 | private int numActiveThreads; // number of active compiler threads | ||
| 114 | |||
| 115 | private Map<String, Counter> counters; | ||
| 116 | private Counter lookup(String name) { | ||
| 117 | Counter c = null; | ||
| 118 | |||
| 119 | // Only one counter exists with the specified name in the | ||
| 120 | // current implementation. We first look up in the SUN_CI namespace | ||
| 121 | // since most counters are in SUN_CI namespace. | ||
| 122 | |||
| 123 | if ((c = (Counter) counters.get(SUN_CI + name)) != null) { | ||
| 124 | return c; | ||
| 125 | } | ||
| 126 | if ((c = (Counter) counters.get(COM_SUN_CI + name)) != null) { | ||
| 127 | return c; | ||
| 128 | } | ||
| 129 | if ((c = (Counter) counters.get(JAVA_CI + name)) != null) { | ||
| 130 | return c; | ||
| 131 | } | ||
| 132 | |||
| 133 | // FIXME: should tolerate if counter doesn't exist | ||
| 134 | throw new AssertionError("Counter " + name + " does not exist"); | ||
| 135 | } | ||
| 136 | |||
| 137 | private void initCompilerCounters() { | ||
| 138 | // Build a tree map of the current list of performance counters | ||
| 139 | ListIterator iter = getInternalCompilerCounters().listIterator(); | ||
| 140 | counters = new TreeMap<String, Counter>(); | ||
| 141 | while (iter.hasNext()) { | ||
| 142 | Counter c = (Counter) iter.next(); | ||
| 143 | counters.put(c.getName(), c); | ||
| 144 | } | ||
| 145 | |||
| 146 | compilerThreads = (LongCounter) lookup("threads"); | ||
| 147 | totalCompiles = (LongCounter) lookup("totalCompiles"); | ||
| 148 | totalBailouts = (LongCounter) lookup("totalBailouts"); | ||
| 149 | totalInvalidates = (LongCounter) lookup("totalInvalidates"); | ||
| 150 | nmethodCodeSize = (LongCounter) lookup("nmethodCodeSize"); | ||
| 151 | nmethodSize = (LongCounter) lookup("nmethodSize"); | ||
| 152 | lastMethod = (StringCounter) lookup("lastMethod"); | ||
| 153 | lastSize = (LongCounter) lookup("lastSize"); | ||
| 154 | lastType = (LongCounter) lookup("lastType"); | ||
| 155 | lastFailedMethod = (StringCounter) lookup("lastFailedMethod"); | ||
| 156 | lastFailedType = (LongCounter) lookup("lastFailedType"); | ||
| 157 | lastInvalidatedMethod = (StringCounter) lookup("lastInvalidatedMethod"); | ||
| 158 | lastInvalidatedType = (LongCounter) lookup("lastInvalidatedType"); | ||
| 159 | |||
| 160 | numActiveThreads = (int) compilerThreads.longValue(); | ||
| 161 | |||
| 162 | // Allocate CompilerThreadInfo for compilerThread and adaptorThread | ||
| 163 | threads = new CompilerThreadInfo[numActiveThreads+1]; | ||
| 164 | |||
| 165 | // AdaptorThread has index 0 | ||
| 166 | if (counters.containsKey(SUN_CI + "adapterThread.compiles")) { | ||
| 167 | threads[0] = new CompilerThreadInfo("adapterThread", 0); | ||
| 168 | numActiveThreads++; | ||
| 169 | } else { | ||
| 170 | threads[0] = null; | ||
| 171 | } | ||
| 172 | |||
| 173 | for (int i = 1; i < threads.length; i++) { | ||
| 174 | threads[i] = new CompilerThreadInfo("compilerThread", i-1); | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | public int getCompilerThreadCount() { | ||
| 179 | return numActiveThreads; | ||
| 180 | } | ||
| 181 | |||
| 182 | public long getTotalCompileCount() { | ||
| 183 | return totalCompiles.longValue(); | ||
| 184 | } | ||
| 185 | |||
| 186 | public long getBailoutCompileCount() { | ||
| 187 | return totalBailouts.longValue(); | ||
| 188 | } | ||
| 189 | |||
| 190 | public long getInvalidatedCompileCount() { | ||
| 191 | return totalInvalidates.longValue(); | ||
| 192 | } | ||
| 193 | |||
| 194 | public long getCompiledMethodCodeSize() { | ||
| 195 | return nmethodCodeSize.longValue(); | ||
| 196 | } | ||
| 197 | |||
| 198 | public long getCompiledMethodSize() { | ||
| 199 | return nmethodSize.longValue(); | ||
| 200 | } | ||
| 201 | |||
| 202 | public java.util.List<CompilerThreadStat> getCompilerThreadStats() { | ||
| 203 | List<CompilerThreadStat> list = new ArrayList<CompilerThreadStat>(threads.length); | ||
| 204 | int i = 0; | ||
| 205 | if (threads[0] == null) { | ||
| 206 | // no adaptor thread | ||
| 207 | i = 1; | ||
| 208 | } | ||
| 209 | for (; i < threads.length; i++) { | ||
| 210 | list.add(threads[i].getCompilerThreadStat()); | ||
| 211 | } | ||
| 212 | return list; | ||
| 213 | } | ||
| 214 | |||
| 215 | public MethodInfo getLastCompile() { | ||
| 216 | return new MethodInfo(lastMethod.stringValue(), | ||
| 217 | (int) lastType.longValue(), | ||
| 218 | (int) lastSize.longValue()); | ||
| 219 | } | ||
| 220 | |||
| 221 | public MethodInfo getFailedCompile() { | ||
| 222 | return new MethodInfo(lastFailedMethod.stringValue(), | ||
| 223 | (int) lastFailedType.longValue(), | ||
| 224 | -1); | ||
| 225 | } | ||
| 226 | |||
| 227 | public MethodInfo getInvalidatedCompile() { | ||
| 228 | return new MethodInfo(lastInvalidatedMethod.stringValue(), | ||
| 229 | (int) lastInvalidatedType.longValue(), | ||
| 230 | -1); | ||
| 231 | } | ||
| 232 | |||
| 233 | public java.util.List<Counter> getInternalCompilerCounters() { | ||
| 234 | return jvm.getInternalCounters(CI_COUNTER_NAME_PATTERN); | ||
| 235 | } | ||
| 236 | } | ||