annotate graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugHistogramImpl.java @ 19258:8c5f514d02c4

LoopUnswicthing: add metric for rejected loops
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Mon, 09 Feb 2015 15:13:00 +0100
parents cda2a7d1dcff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 */
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.debug.internal;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
25 import java.util.*;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
26
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
27 import com.oracle.graal.debug.*;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
28
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 public class DebugHistogramImpl implements DebugHistogram {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 private final String name;
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
32 private HashMap<Object, CountedValue> map = new HashMap<>();
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
33
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
34 public DebugHistogramImpl(String name) {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 this.name = name;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 public void add(Object value) {
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
39 CountedValue cv = map.get(value);
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
40 if (cv == null) {
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
41 map.put(value, new CountedValue(1, value));
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 } else {
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
43 cv.inc();
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
15954
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
47 public void add(Object value, long count) {
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
48 CountedValue cv = map.get(value);
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
49 if (cv == null) {
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
50 map.put(value, new CountedValue(count, value));
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
51 } else {
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
52 cv.add(count);
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
53 }
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
54 }
cda2a7d1dcff long values and scale on DebugHistogram
Lukas Stadler <lukas.stadler@oracle.com>
parents: 11551
diff changeset
55
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 @Override
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
57 public String getName() {
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 return name;
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
59 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60
11551
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
61 public List<CountedValue> getValues() {
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
62 ArrayList<CountedValue> res = new ArrayList<>(map.values());
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
63 Collections.sort(res);
63b4694d3627 split DebugHistogram printing out into separate service
Doug Simon <doug.simon@oracle.com>
parents: 9104
diff changeset
64 return res;
9103
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 }
e7541d478e38 Added DebugHistory utility and corresponding unit tests.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 }