Mercurial > hg > truffle
annotate graal/com.oracle.jvmci.debug/src/com/oracle/jvmci/debug/DebugHistogram.java @ 21594:cc9e15bbbd3c
SSAMoveResolver: add support for non-virtual stack slots.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Fri, 29 May 2015 12:08:54 +0200 |
parents | b1530a6cce8c |
children |
rev | line source |
---|---|
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
1 /* |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
4 * |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
8 * |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
14 * |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
18 * |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
22 */ |
21554
b1530a6cce8c
renamed com.oracle.graal.[debug|options|hotspotvmconfig]* modules to com.oracle.jvmci.[debug|options|hotspotvmconfig]* modules (JBS:GRAAL-53)
Doug Simon <doug.simon@oracle.com>
parents:
15954
diff
changeset
|
23 package com.oracle.jvmci.debug; |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
24 |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
25 import java.util.*; |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
26 |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
27 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
28 * Facility for recording value frequencies. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
29 */ |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
30 public interface DebugHistogram { |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
31 |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
32 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
33 * Gets the name specified when this objected was {@linkplain Debug#createHistogram(String) |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
34 * created}. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
35 */ |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
36 String getName(); |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
37 |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
38 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
39 * Increments the count for a given value. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
40 */ |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
41 void add(Object value); |
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
42 |
15954
cda2a7d1dcff
long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14586
diff
changeset
|
43 void add(Object value, long count); |
cda2a7d1dcff
long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14586
diff
changeset
|
44 |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
45 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
46 * A value and a frequency. The ordering imposed by {@link #compareTo(CountedValue)} places |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
47 * values with higher frequencies first. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
48 */ |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
49 public class CountedValue implements Comparable<CountedValue> { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
50 |
15954
cda2a7d1dcff
long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14586
diff
changeset
|
51 private long count; |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
52 private final Object value; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
53 |
15954
cda2a7d1dcff
long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14586
diff
changeset
|
54 public CountedValue(long count, Object value) { |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
55 this.count = count; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
56 this.value = value; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
57 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
58 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
59 public int compareTo(CountedValue o) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
60 if (count < o.count) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
61 return 1; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
62 } else if (count > o.count) { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
63 return -1; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
64 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
65 return 0; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
66 } |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
67 |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
68 @Override |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
69 public String toString() { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
70 return count + " -> " + value; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
71 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
72 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
73 public void inc() { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
74 count++; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
75 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
76 |
15954
cda2a7d1dcff
long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14586
diff
changeset
|
77 public void add(long n) { |
14586
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
14573
diff
changeset
|
78 count += n; |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
14573
diff
changeset
|
79 } |
d2fe05d5cc96
added support for lazy computation of names for use with Debug
Doug Simon <doug.simon@oracle.com>
parents:
14573
diff
changeset
|
80 |
15954
cda2a7d1dcff
long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents:
14586
diff
changeset
|
81 public long getCount() { |
11551
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
82 return count; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
83 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
84 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
85 public Object getValue() { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
86 return value; |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
87 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
88 } |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
89 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
90 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
91 * Gets a list of the counted values, sorted in descending order of frequency. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
92 */ |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
93 List<CountedValue> getValues(); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
94 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
95 /** |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
96 * Interface for a service that can render a visualization of a histogram. |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
97 */ |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
98 public interface Printer { |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
99 |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
100 void print(DebugHistogram histogram); |
63b4694d3627
split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents:
9103
diff
changeset
|
101 } |
9103
e7541d478e38
Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff
changeset
|
102 } |