annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/debug/BenchmarkCounters.java @ 19403:7e2c87dae93e

Create static final NodeClass field named TYPE in Node subclasses.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 16 Feb 2015 15:43:03 +0100
parents a8a2cc98eb55
children 61d3cb8e1280
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 package com.oracle.graal.hotspot.debug;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
25 import java.io.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
26 import java.util.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import java.util.concurrent.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
28 import java.util.concurrent.atomic.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
29
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30 import sun.misc.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32 import com.oracle.graal.api.meta.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 14906
diff changeset
33 import com.oracle.graal.compiler.common.*;
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15193
diff changeset
34 import com.oracle.graal.compiler.common.type.*;
16578
9793d86c21c5 use TTY in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16480
diff changeset
35 import com.oracle.graal.debug.*;
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19096
diff changeset
36 import com.oracle.graal.graph.*;
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37 import com.oracle.graal.hotspot.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38 import com.oracle.graal.hotspot.bridge.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39 import com.oracle.graal.hotspot.meta.*;
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
40 import com.oracle.graal.hotspot.replacements.*;
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
41 import com.oracle.graal.nodeinfo.*;
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
42 import com.oracle.graal.nodes.HeapAccess.BarrierType;
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43 import com.oracle.graal.nodes.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44 import com.oracle.graal.nodes.calc.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45 import com.oracle.graal.nodes.debug.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 import com.oracle.graal.nodes.extended.*;
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
47 import com.oracle.graal.nodes.spi.*;
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48 import com.oracle.graal.options.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49 import com.oracle.graal.replacements.nodes.*;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
51 import edu.umd.cs.findbugs.annotations.*;
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
52
11874
e0041af765c5 some more javadoc for benchmark counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11852
diff changeset
53 /**
e0041af765c5 some more javadoc for benchmark counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11852
diff changeset
54 * This class contains infrastructure to maintain counters based on {@link DynamicCounterNode}s. The
e0041af765c5 some more javadoc for benchmark counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11852
diff changeset
55 * infrastructure is enabled by specifying either the GenericDynamicCounters or
14906
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14776
diff changeset
56 * BenchmarkDynamicCounters option.
f3a5036cc13c javadoc fixes
Bernhard Urban <bernhard.urban@jku.at>
parents: 14776
diff changeset
57 * <p>
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
58 *
14578
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
59 * The counters are kept in a special area allocated for each native JavaThread object, and the
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
60 * number of counters is configured using {@code -XX:GraalCounterSize=value}.
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
61 * {@code -XX:+/-GraalCountersExcludeCompiler} configures whether to exclude compiler threads
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
62 * (defaults to true).
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
63 *
11874
e0041af765c5 some more javadoc for benchmark counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11852
diff changeset
64 * The subsystems that use the logging need to have their own options to turn on the counters, and
e0041af765c5 some more javadoc for benchmark counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11852
diff changeset
65 * insert DynamicCounterNodes when they're enabled.
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
66 *
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
67 * Counters will be displayed as a rate (per second) if their group name starts with "~", otherwise
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
68 * they will be displayed as a total number.
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
69 *
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
70 * <h1>Example</h1> In order to create statistics about allocations within the DaCapo pmd benchmark
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
71 * the following steps are necessary:
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
72 * <ul>
14578
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
73 * <li>Set {@code -XX:GraalCounterSize=value}. The actual required value depends on the granularity
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
74 * of the profiling, 10000 should be enough for most cases.</li>
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
75 * <li>Also: {@code -XX:+/-GraalCountersExcludeCompiler} specifies whether the numbers generated by
d927132f45a4 update comments on BenchmarkCounters (-XX options instead of preprocessor defs)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14163
diff changeset
76 * compiler threads should be excluded (default: true).</li>
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
77 * <li>Start the DaCapo pmd benchmark with
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
78 * {@code "-G:BenchmarkDynamicCounters=err, starting ====, PASSED in "} and
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
79 * {@code -G:+ProfileAllocations}.</li>
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
80 * <li>The numbers will only include allocation from compiled code!</li>
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
81 * <li>The counters can be further configured by modifying the
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
82 * {@link NewObjectSnippets#PROFILE_MODE} field.</li>
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
83 * </ul>
11874
e0041af765c5 some more javadoc for benchmark counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11852
diff changeset
84 */
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
85 public class BenchmarkCounters {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
86
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 static class Options {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
88
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
89 //@formatter:off
18674
ecb9d0cedbab First draft of option classification.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18649
diff changeset
90 @Option(help = "Turn on the benchmark counters, and displays the results on VM shutdown", type = OptionType.Debug)
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
91 private static final OptionValue<Boolean> GenericDynamicCounters = new OptionValue<>(false);
18674
ecb9d0cedbab First draft of option classification.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18649
diff changeset
92 @Option(help = "Turn on the benchmark counters, and displays the results every n milliseconds", type = OptionType.Debug)
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
93 private static final OptionValue<Integer> TimedDynamicCounters = new OptionValue<>(-1);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
94
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
95 @Option(help = "Turn on the benchmark counters, and listen for specific patterns on System.out/System.err:%n" +
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
96 "Format: (err|out),start pattern,end pattern (~ matches multiple digits)%n" +
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
97 "Examples:%n" +
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
98 " dacapo = 'err, starting =====, PASSED in'%n" +
18674
ecb9d0cedbab First draft of option classification.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18649
diff changeset
99 " specjvm2008 = 'out,Iteration ~ (~s) begins:,Iteration ~ (~s) ends:'", type = OptionType.Debug)
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
100 private static final OptionValue<String> BenchmarkDynamicCounters = new OptionValue<>(null);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
101 //@formatter:on
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
102 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
103
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
104 private static final boolean DUMP_STATIC = false;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
105
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
106 public static boolean enabled = false;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
107
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
108 public static final ConcurrentHashMap<String, Integer> indexes = new ConcurrentHashMap<>();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
109 public static final ArrayList<String> groups = new ArrayList<>();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
110 public static long[] delta;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
111 public static final ArrayList<AtomicLong> staticCounters = new ArrayList<>();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
112
14776
07dd21c7d533 revived use of FindBugs annotations
Doug Simon <doug.simon@oracle.com>
parents: 14724
diff changeset
113 @SuppressFBWarnings(value = "AT_OPERATION_SEQUENCE_ON_CONCURRENT_ABSTRACTION", justification = "concurrent abstraction calls are in synchronized block")
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
114 private static int getIndex(DynamicCounterNode counter, StructuredGraph currentGraph) {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
115 if (!enabled) {
13796
8cd953e97e2d rework of benchmark counters: fix size at VM entry, not at build time
Lukas Stadler <lukas.stadler@jku.at>
parents: 12430
diff changeset
116 throw new GraalInternalError("counter nodes shouldn't exist when counters are not enabled: " + counter.getGroup() + ", " + counter.getName());
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
117 }
15353
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
118 String name;
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
119 String group = counter.getGroup();
15353
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
120 if (counter.isWithContext()) {
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
121 name = counter.getName() + " @ ";
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
122 if (currentGraph.method() != null) {
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
123 StackTraceElement stackTraceElement = currentGraph.method().asStackTraceElement(0);
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
124 if (stackTraceElement != null) {
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
125 name += " " + stackTraceElement.toString();
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
126 } else {
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
127 name += currentGraph.method().format("%h.%n");
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
128 }
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
129 }
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
130 if (currentGraph.name != null) {
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
131 name += " (" + currentGraph.name + ")";
15353
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
132 }
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
133 name += "#" + group;
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
134
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
135 } else {
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
136 name = counter.getName() + "#" + group;
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
137 }
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
138 Integer index = indexes.get(name);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
139 if (index == null) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
140 synchronized (BenchmarkCounters.class) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
141 index = indexes.get(name);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
142 if (index == null) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
143 index = indexes.size();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
144 indexes.put(name, index);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
145 groups.add(group);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
146 staticCounters.add(new AtomicLong());
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
147 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
148 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
149 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
150 assert groups.get(index).equals(group) : "mismatching groups: " + groups.get(index) + " vs. " + group;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
151 if (counter.getIncrement().isConstant()) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 17197
diff changeset
152 staticCounters.get(index).addAndGet(counter.getIncrement().asJavaConstant().asLong());
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
153 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
154 return index;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
155 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
156
15353
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
157 private static synchronized void dump(PrintStream out, double seconds, long[] counters, int maxRows) {
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
158 if (!groups.isEmpty()) {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
159 out.println("====== dynamic counters (" + staticCounters.size() + " in total) ======");
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
160 for (String group : new TreeSet<>(groups)) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
161 if (group != null) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
162 if (DUMP_STATIC) {
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
163 dumpCounters(out, seconds, counters, true, group, maxRows);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
164 }
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
165 dumpCounters(out, seconds, counters, false, group, maxRows);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
166 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
167 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
168 out.println("============================");
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
169
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
170 clear(counters);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
171 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
172 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
173
15353
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
174 private static synchronized void clear(long[] counters) {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
175 delta = counters;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
176 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
177
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
178 private static synchronized void dumpCounters(PrintStream out, double seconds, long[] counters, boolean staticCounter, String group, int maxRows) {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
179 TreeMap<Long, String> sorted = new TreeMap<>();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
180
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
181 // collect the numbers
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
182 long[] array;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
183 if (staticCounter) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
184 array = new long[indexes.size()];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
185 for (int i = 0; i < array.length; i++) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
186 array[i] = staticCounters.get(i).get();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
187 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
188 } else {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
189 array = counters.clone();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
190 for (int i = 0; i < array.length; i++) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
191 array[i] -= delta[i];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
192 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
193 }
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
194 // sort the counters by putting them into a sorted map
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
195 long sum = 0;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
196 for (Map.Entry<String, Integer> entry : indexes.entrySet()) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
197 int index = entry.getValue();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
198 if (groups.get(index).equals(group)) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
199 sum += array[index];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
200 sorted.put(array[index] * array.length + index, entry.getKey().substring(0, entry.getKey().length() - group.length() - 1));
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
201 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
202 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
203
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
204 if (sum > 0) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
205 long cutoff = sorted.size() < 10 ? 1 : Math.max(1, sum / 100);
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
206 int cnt = sorted.size();
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
207
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
208 // remove everything below cutoff and keep at most maxRows
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
209 Iterator<Map.Entry<Long, String>> iter = sorted.entrySet().iterator();
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
210 while (iter.hasNext()) {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
211 Map.Entry<Long, String> entry = iter.next();
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
212 long counter = entry.getKey() / array.length;
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
213 if (counter < cutoff || cnt > maxRows) {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
214 iter.remove();
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
215 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
216 cnt--;
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
217 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
218
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
219 if (staticCounter) {
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
220 out.println("=========== " + group + " (static counters):");
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
221 for (Map.Entry<Long, String> entry : sorted.entrySet()) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
222 long counter = entry.getKey() / array.length;
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
223 out.format(Locale.US, "%,19d %3d%% %s\n", counter, percentage(counter, sum), entry.getValue());
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
224 }
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
225 out.format(Locale.US, "%,19d total\n", sum);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
226 } else {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
227 if (group.startsWith("~")) {
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
228 out.println("=========== " + group + " (dynamic counters), time = " + seconds + " s:");
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
229 for (Map.Entry<Long, String> entry : sorted.entrySet()) {
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
230 long counter = entry.getKey() / array.length;
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
231 out.format(Locale.US, "%,19d/s %3d%% %s\n", (long) (counter / seconds), percentage(counter, sum), entry.getValue());
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
232 }
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
233 out.format(Locale.US, "%,19d/s total\n", (long) (sum / seconds));
11893
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
234 } else {
ec267141f753 more javadoc and output tweaks for dynamic counters
Lukas Stadler <lukas.stadler@jku.at>
parents: 11874
diff changeset
235 out.println("=========== " + group + " (dynamic counters):");
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
236 for (Map.Entry<Long, String> entry : sorted.entrySet()) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
237 long counter = entry.getKey() / array.length;
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
238 out.format(Locale.US, "%,19d %3d%% %s\n", counter, percentage(counter, sum), entry.getValue());
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
239 }
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
240 out.format(Locale.US, "%,19d total\n", sum);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
241 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
242 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
243 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
244 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
245
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
246 private static long percentage(long counter, long sum) {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
247 return (counter * 200 + 1) / sum / 2;
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
248 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
249
15353
520ab37fb5b6 show Truffle call target names in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
250 private abstract static class CallbackOutputStream extends OutputStream {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
251
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
252 protected final PrintStream delegate;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
253 private final byte[][] patterns;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
254 private final int[] positions;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
255
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
256 public CallbackOutputStream(PrintStream delegate, String... patterns) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
257 this.delegate = delegate;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
258 this.positions = new int[patterns.length];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
259 this.patterns = new byte[patterns.length][];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
260 for (int i = 0; i < patterns.length; i++) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
261 this.patterns[i] = patterns[i].getBytes();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
262 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
263 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
264
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
265 protected abstract void patternFound(int index);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
266
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
267 @Override
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
268 public void write(int b) throws IOException {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
269 try {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
270 delegate.write(b);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
271 for (int i = 0; i < patterns.length; i++) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
272 int j = positions[i];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
273 byte[] cs = patterns[i];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
274 byte patternChar = cs[j];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
275 if (patternChar == '~' && Character.isDigit(b)) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
276 // nothing to do...
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
277 } else {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
278 if (patternChar == '~') {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
279 patternChar = cs[++positions[i]];
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
280 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
281 if (b == patternChar) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
282 positions[i]++;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
283 } else {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
284 positions[i] = 0;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
285 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
286 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
287 if (positions[i] == patterns[i].length) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
288 positions[i] = 0;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
289 patternFound(i);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
290 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
291 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
292 } catch (RuntimeException e) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
293 e.printStackTrace(delegate);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
294 throw e;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
295 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
296 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
297 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
298
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
299 public static void initialize(final CompilerToVM compilerToVM) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
300 final class BenchmarkCountersOutputStream extends CallbackOutputStream {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
301
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
302 private long startTime;
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
303 private boolean running;
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
304 private boolean waitingForEnd;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
305
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
306 private BenchmarkCountersOutputStream(PrintStream delegate, String start, String end) {
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
307 super(delegate, new String[]{"\n", end, start});
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
308 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
309
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
310 @Override
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
311 protected void patternFound(int index) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
312 switch (index) {
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
313 case 2:
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
314 startTime = System.nanoTime();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
315 BenchmarkCounters.clear(compilerToVM.collectCounters());
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
316 running = true;
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
317 break;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
318 case 1:
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
319 if (running) {
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
320 waitingForEnd = true;
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
321 }
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
322 break;
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
323 case 0:
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
324 if (waitingForEnd) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
325 waitingForEnd = false;
15366
a2f4ffc18d9d more fixes in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15353
diff changeset
326 running = false;
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
327 BenchmarkCounters.dump(delegate, (System.nanoTime() - startTime) / 1000000000d, compilerToVM.collectCounters(), 100);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
328 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
329 break;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
330 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
331 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
332 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
333
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
334 if (Options.BenchmarkDynamicCounters.getValue() != null) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
335 String[] arguments = Options.BenchmarkDynamicCounters.getValue().split(",");
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
336 if (arguments.length == 0 || (arguments.length % 3) != 0) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
337 throw new GraalInternalError("invalid arguments to BenchmarkDynamicCounters: (err|out),start,end,(err|out),start,end,... (~ matches multiple digits)");
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
338 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
339 for (int i = 0; i < arguments.length; i += 3) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
340 if (arguments[i].equals("err")) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
341 System.setErr(new PrintStream(new BenchmarkCountersOutputStream(System.err, arguments[i + 1], arguments[i + 2])));
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
342 } else if (arguments[i].equals("out")) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
343 System.setOut(new PrintStream(new BenchmarkCountersOutputStream(System.out, arguments[i + 1], arguments[i + 2])));
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
344 } else {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
345 throw new GraalInternalError("invalid arguments to BenchmarkDynamicCounters: err|out");
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
346 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
347 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
348 enabled = true;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
349 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
350 if (Options.GenericDynamicCounters.getValue()) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
351 enabled = true;
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
352 }
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
353 if (Options.TimedDynamicCounters.getValue() > 0) {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
354 Thread thread = new Thread() {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
355 long lastTime = System.nanoTime();
16578
9793d86c21c5 use TTY in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16480
diff changeset
356 PrintStream out = TTY.cachedOut;
14724
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
357
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
358 @Override
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
359 public void run() {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
360 while (true) {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
361 try {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
362 Thread.sleep(Options.TimedDynamicCounters.getValue());
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
363 } catch (InterruptedException e) {
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
364 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
365 long time = System.nanoTime();
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
366 dump(out, (time - lastTime) / 1000000000d, compilerToVM.collectCounters(), 10);
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
367 lastTime = time;
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
368 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
369 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
370 };
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
371 thread.setDaemon(true);
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
372 thread.setPriority(Thread.MAX_PRIORITY);
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
373 thread.start();
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
374 enabled = true;
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
375 }
c3ec1e4494b8 update BenchmarkCounters (add TimedDynamicCounters, fix -XX:+GraalCountersExcludeCompiler)
Lukas Stadler <lukas.stadler@oracle.com>
parents: 14578
diff changeset
376 if (enabled) {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
377 clear(compilerToVM.collectCounters());
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
378 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
379 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
380
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
381 public static void shutdown(CompilerToVM compilerToVM, long compilerStartTime) {
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
382 if (Options.GenericDynamicCounters.getValue()) {
16578
9793d86c21c5 use TTY in BenchmarkCounters
Lukas Stadler <lukas.stadler@oracle.com>
parents: 16480
diff changeset
383 dump(TTY.cachedOut, (System.nanoTime() - compilerStartTime) / 1000000000d, compilerToVM.collectCounters(), 100);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
384 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
385 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
386
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
387 private static final LocationIdentity COUNTER_ARRAY_LOCATION = NamedLocationIdentity.mutable("COUNTER_ARRAY_LOCATION");
18698
abd10b6ef99d Benchmark counters should have their own LocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18674
diff changeset
388 private static final LocationIdentity COUNTER_LOCATION = NamedLocationIdentity.mutable("COUNTER_LOCATION");
abd10b6ef99d Benchmark counters should have their own LocationIdentity
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 18674
diff changeset
389
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
390 @NodeInfo(nameTemplate = "CounterIndex")
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19096
diff changeset
391 private static final class CounterIndexNode extends FloatingNode implements LIRLowerable {
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
392
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19096
diff changeset
393 public static final NodeClass TYPE = NodeClass.get(CounterIndexNode.class);
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
394 protected final Object counter;
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
395 protected final int countersSize;
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
396
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
397 protected CounterIndexNode(Stamp stamp, DynamicCounterNode counter, int countersSize) {
19403
7e2c87dae93e Create static final NodeClass field named TYPE in Node subclasses.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 19096
diff changeset
398 super(TYPE, stamp);
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
399 this.countersSize = countersSize;
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
400 this.counter = counter;
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
401 }
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
402
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
403 @Override
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
404 public void generate(NodeLIRBuilderTool generator) {
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
405 int index = BenchmarkCounters.getIndex((DynamicCounterNode) counter, graph());
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
406 if (index >= countersSize) {
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
407 throw new GraalInternalError("too many counters, reduce number of counters or increase -XX:GraalCounterSize=... (current value: " + countersSize + ")");
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
408 }
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
409
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
410 generator.setResult(this, JavaConstant.forIntegerKind(getKind(), index));
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
411 }
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
412 }
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
413
12430
c0e660b07e02 introduced HotSpotRegistersProvider interface
Doug Simon <doug.simon@oracle.com>
parents: 12429
diff changeset
414 public static void lower(DynamicCounterNode counter, HotSpotRegistersProvider registers, HotSpotVMConfig config, Kind wordKind) {
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
415 StructuredGraph graph = counter.graph();
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
416
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18698
diff changeset
417 ReadRegisterNode thread = graph.add(new ReadRegisterNode(registers.getThreadRegister(), wordKind, true, false));
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
418
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
419 CounterIndexNode index = graph.unique(new CounterIndexNode(StampFactory.forKind(wordKind), counter, config.graalCountersSize));
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
420 ConstantLocationNode arrayLocation = graph.unique(new ConstantLocationNode(COUNTER_ARRAY_LOCATION, config.graalCountersThreadOffset));
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18698
diff changeset
421 ReadNode readArray = graph.add(new ReadNode(thread, arrayLocation, StampFactory.forKind(wordKind), BarrierType.NONE));
19096
a8a2cc98eb55 allocation profiling fixes
Lukas Stadler <lukas.stadler@oracle.com>
parents: 18845
diff changeset
422 IndexedLocationNode location = graph.unique(new IndexedLocationNode(COUNTER_LOCATION, 0, index, Unsafe.ARRAY_LONG_INDEX_SCALE));
18845
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18698
diff changeset
423 ReadNode read = graph.add(new ReadNode(readArray, location, StampFactory.forKind(Kind.Long), BarrierType.NONE));
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18698
diff changeset
424 AddNode add = graph.unique(new AddNode(read, counter.getIncrement()));
f57d86eb036f removed Node factory methods
Doug Simon <doug.simon@oracle.com>
parents: 18698
diff changeset
425 WriteNode write = graph.add(new WriteNode(readArray, add, location, BarrierType.NONE));
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
426
15368
44dcd95a4bf6 fix NPE in BenchmarkCounters, remove exclusion based on prefix
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15366
diff changeset
427 graph.addBeforeFixed(counter, thread);
44dcd95a4bf6 fix NPE in BenchmarkCounters, remove exclusion based on prefix
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15366
diff changeset
428 graph.addBeforeFixed(counter, readArray);
44dcd95a4bf6 fix NPE in BenchmarkCounters, remove exclusion based on prefix
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15366
diff changeset
429 graph.addBeforeFixed(counter, read);
44dcd95a4bf6 fix NPE in BenchmarkCounters, remove exclusion based on prefix
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15366
diff changeset
430 graph.addBeforeFixed(counter, write);
11852
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
431 graph.removeFixed(counter);
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
432 }
d7964e96b0b0 move benchmark counters into separate class and make them correct for multithreaded applications
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
433 }