changeset 842:0842ed1cdb69

util: multisets should count in longs to accomodate profiler usages.
author shade
date Thu, 26 Jun 2014 18:36:58 +0400
parents abb1bcb09247
children 5b9c5c60a11c
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/util/HashMultiset.java jmh-core/src/main/java/org/openjdk/jmh/util/Multiset.java jmh-core/src/main/java/org/openjdk/jmh/util/MultisetStatistics.java jmh-core/src/main/java/org/openjdk/jmh/util/Multisets.java jmh-core/src/main/java/org/openjdk/jmh/util/TreeMultiset.java
diffstat 6 files changed, 35 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 18:19:18 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Thu Jun 26 18:36:58 2014 +0400
@@ -283,7 +283,7 @@
 
         Map<String, Long> totalCounts = new HashMap<String, Long>();
         for (String event : EVENTS) {
-            totalCounts.put(event, (long) events.get(event).size());
+            totalCounts.put(event, events.get(event).size());
         }
 
         SortedSet<Region> interestingRegions = new TreeSet<Region>(Region.BEGIN_COMPARATOR);
@@ -309,7 +309,7 @@
                 printDottedLine(pw, "Region " + cnt);
                 for (ASMLine line : r.code) {
                     for (String event : EVENTS) {
-                        int count = (line.addr != null) ? r.events.get(event).count(line.addr) : 0;
+                        long count = (line.addr != null) ? r.events.get(event).count(line.addr) : 0;
                         if (count > 0) {
                             pw.printf("%6.2f%%  ", 100.0 * count / totalCounts.get(event));
                         } else {
@@ -321,7 +321,7 @@
 
                 printDottedLine(pw, null);
                 for (String event : EVENTS) {
-                    int count = r.events.get(event).size();
+                    long count = r.events.get(event).size();
                     if (count > 0) {
                         pw.printf("%6.2f%%  ", 100.0 * count / totalCounts.get(event));
                     } else {
@@ -343,7 +343,7 @@
         Multiset<String> allRegions = new HashMultiset<String>();
         for (Region r : regions) {
             for (String event : EVENTS) {
-                int count = r.events.get(event).size();
+                long count = r.events.get(event).size();
                 allRegions.add(event, count);
             }
         }
@@ -385,7 +385,7 @@
                 PrintWriter pwAsm = new PrintWriter(asm);
                 for (ASMLine line : assembly.lines) {
                     for (String event : EVENTS) {
-                        int count = (line.addr != null) ? events.get(event).count(line.addr) : 0;
+                        long count = (line.addr != null) ? events.get(event).count(line.addr) : 0;
                         if (count > 0) {
                             pwAsm.printf("%6.2f%%  ", 100.0 * count / totalCounts.get(event));
                         } else {
@@ -437,7 +437,7 @@
                 HashMultiset<Long> r = new HashMultiset<Long>();
                 for (ASMLine line : regionLines) {
                     if (line.addr == null) continue;
-                    int count = events.get(event).count(line.addr);
+                    long count = events.get(event).count(line.addr);
                     r.add(line.addr, count);
                 }
                 eventsByAddr.put(event, r);
@@ -688,7 +688,7 @@
             return new Comparator<Region>() {
                 @Override
                 public int compare(Region o1, Region o2) {
-                    return Integer.valueOf(o2.getEventCount(event)).compareTo(o1.getEventCount(event));
+                    return Long.valueOf(o2.getEventCount(event)).compareTo(o1.getEventCount(event));
                 }
             };
         }
@@ -705,7 +705,7 @@
             this.events = events;
         }
 
-        int getEventCount(String event) {
+        long getEventCount(String event) {
             return events.get(event).size();
         }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/HashMultiset.java	Thu Jun 26 18:19:18 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/HashMultiset.java	Thu Jun 26 18:36:58 2014 +0400
@@ -32,11 +32,11 @@
 
 public class HashMultiset<T> implements Multiset<T>, Serializable {
 
-    private final Map<T, Integer> map;
-    private int size;
+    private final Map<T, Long> map;
+    private long size;
 
     public HashMultiset() {
-        map = new HashMap<T, Integer>();
+        map = new HashMap<T, Long>();
     }
 
     @Override
@@ -45,10 +45,10 @@
     }
 
     @Override
-    public void add(T element, int add) {
-        Integer count = map.get(element);
+    public void add(T element, long add) {
+        Long count = map.get(element);
         if (count == null) {
-            count = 0;
+            count = 0L;
         }
         count += add;
         size += add;
@@ -60,8 +60,8 @@
     }
 
     @Override
-    public int count(T element) {
-        Integer count = map.get(element);
+    public long count(T element) {
+        Long count = map.get(element);
         return (count == null) ? 0 : count;
     }
 
@@ -71,7 +71,7 @@
     }
 
     @Override
-    public int size() {
+    public long size() {
         return size;
     }
 
@@ -96,7 +96,7 @@
     @Override
     public int hashCode() {
         int result = map.hashCode();
-        result = 31 * result + size;
+        result = 31 * result + (int) (size ^ (size >>> 32));
         return result;
     }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Multiset.java	Thu Jun 26 18:19:18 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Multiset.java	Thu Jun 26 18:36:58 2014 +0400
@@ -46,14 +46,14 @@
      * @param element element to add
      * @param count number of elements to add
      */
-    void add(T element, int count);
+    void add(T element, long count);
 
     /**
      * Count the elements in multiset
      * @param element element
      * @return number of matching elements in the set; zero, if no elements
      */
-    int count(T element);
+    long count(T element);
 
     /**
      * Answers if Multiset is empty
@@ -67,7 +67,7 @@
      *
      * @return number of elements
      */
-    int size();
+    long size();
 
     /**
      * Answers the collection of keys
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/MultisetStatistics.java	Thu Jun 26 18:19:18 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/MultisetStatistics.java	Thu Jun 26 18:36:58 2014 +0400
@@ -32,7 +32,7 @@
         values = new TreeMultiset<Double>();
     }
 
-    public void addValue(double d, int count) {
+    public void addValue(double d, long count) {
         values.add(d, count);
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Multisets.java	Thu Jun 26 18:19:18 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Multisets.java	Thu Jun 26 18:36:58 2014 +0400
@@ -34,15 +34,15 @@
 
     public static <T> Collection<T> countHighest(Multiset<T> set, int top) {
         // crude and inefficient
-        PriorityQueue<Pair<T, Integer>> q = new PriorityQueue<Pair<T, Integer>>(10, new Comparator<Pair<T, Integer>>() {
+        PriorityQueue<Pair<T, Long>> q = new PriorityQueue<Pair<T, Long>>(10, new Comparator<Pair<T, Long>>() {
             @Override
-            public int compare(Pair<T, Integer> o1, Pair<T, Integer> o2) {
+            public int compare(Pair<T, Long> o1, Pair<T, Long> o2) {
                 return o2.k2.compareTo(o1.k2);
             }
         });
 
         for (T key : set.keys()) {
-            q.add(new Pair<T, Integer>(key, set.count(key)));
+            q.add(new Pair<T, Long>(key, set.count(key)));
         }
 
         List<T> result = new ArrayList<T>();
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/TreeMultiset.java	Thu Jun 26 18:19:18 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/TreeMultiset.java	Thu Jun 26 18:36:58 2014 +0400
@@ -32,11 +32,11 @@
 
 public class TreeMultiset<T extends Comparable<T>> implements Multiset<T>, Serializable {
 
-    private final Map<T, Integer> map;
-    private int size;
+    private final Map<T, Long> map;
+    private long size;
 
     public TreeMultiset() {
-        map = new TreeMap<T, Integer>();
+        map = new TreeMap<T, Long>();
     }
 
     @Override
@@ -45,10 +45,10 @@
     }
 
     @Override
-    public void add(T element, int add) {
-        Integer count = map.get(element);
+    public void add(T element, long add) {
+        Long count = map.get(element);
         if (count == null) {
-            count = 0;
+            count = 0L;
         }
         count += add;
         size += add;
@@ -60,8 +60,8 @@
     }
 
     @Override
-    public int count(T element) {
-        Integer count = map.get(element);
+    public long count(T element) {
+        Long count = map.get(element);
         return (count == null) ? 0 : count;
     }
 
@@ -71,7 +71,7 @@
     }
 
     @Override
-    public int size() {
+    public long size() {
         return size;
     }
 
@@ -96,7 +96,7 @@
     @Override
     public int hashCode() {
         int result = map.hashCode();
-        result = 31 * result + size;
+        result = 31 * result + (int) (size ^ (size >>> 32));
         return result;
     }
 }