From 19015a5d33dc7ad2928ea1b29b759f07ed5a6acd Mon Sep 17 00:00:00 2001 From: Claes Redestad Date: Fri, 28 Aug 2015 13:40:44 +0200 Subject: [PATCH] 8134583: sun.management.HotspotCompilation should handle absence of per-thread perf counters Reviewed-by: jbachorik, neliasso --- .../sun/management/HotspotCompilation.java | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/jdk/src/java.management/share/classes/sun/management/HotspotCompilation.java b/jdk/src/java.management/share/classes/sun/management/HotspotCompilation.java index d8b880bf2e5..920d972664e 100644 --- a/jdk/src/java.management/share/classes/sun/management/HotspotCompilation.java +++ b/jdk/src/java.management/share/classes/sun/management/HotspotCompilation.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2015, 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 @@ -76,7 +76,6 @@ class HotspotCompilation private LongCounter lastInvalidatedType; private class CompilerThreadInfo { - int index; String name; StringCounter method; LongCounter type; @@ -90,14 +89,6 @@ class HotspotCompilation this.compiles = (LongCounter) lookup(basename + "compiles"); this.time = (LongCounter) lookup(basename + "time"); } - CompilerThreadInfo(String bname) { - String basename = bname + "."; - this.name = bname; - this.method = (StringCounter) lookup(basename + "method"); - this.type = (LongCounter) lookup(basename + "type"); - this.compiles = (LongCounter) lookup(basename + "compiles"); - this.time = (LongCounter) lookup(basename + "time"); - } CompilerThreadStat getCompilerThreadStat() { MethodInfo minfo = new MethodInfo(method.stringValue(), @@ -109,7 +100,7 @@ class HotspotCompilation minfo); } } - private CompilerThreadInfo[] threads; + private List threads; private int numActiveThreads; // number of active compiler threads private Map counters; @@ -158,18 +149,12 @@ class HotspotCompilation numActiveThreads = (int) compilerThreads.longValue(); // Allocate CompilerThreadInfo for compilerThread and adaptorThread - threads = new CompilerThreadInfo[numActiveThreads+1]; + threads = new ArrayList(); - // AdaptorThread has index 0 - if (counters.containsKey(SUN_CI + "adapterThread.compiles")) { - threads[0] = new CompilerThreadInfo("adapterThread", 0); - numActiveThreads++; - } else { - threads[0] = null; - } - - for (int i = 1; i < threads.length; i++) { - threads[i] = new CompilerThreadInfo("compilerThread", i-1); + for (int i = 0; i < numActiveThreads; i++) { + if (counters.containsKey(SUN_CI + "compilerThread." + i + ".method")) { + threads.add(new CompilerThreadInfo("compilerThread", i)); + } } } @@ -197,15 +182,10 @@ class HotspotCompilation return nmethodSize.longValue(); } - public java.util.List getCompilerThreadStats() { - List list = new ArrayList<>(threads.length); - int i = 0; - if (threads[0] == null) { - // no adaptor thread - i = 1; - } - for (; i < threads.length; i++) { - list.add(threads[i].getCompilerThreadStat()); + public List getCompilerThreadStats() { + List list = new ArrayList<>(threads.size()); + for (CompilerThreadInfo info : threads) { + list.add(info.getCompilerThreadStat()); } return list; }