changeset 1130:63844ec679a4

7901299: Optimize SampleBuffer footprint: should use less buckets
author shade
date Fri, 13 Feb 2015 15:04:47 +0300
parents 7c2b3d0880da
children f4bcdb5ff6c4
files jmh-core/src/main/java/org/openjdk/jmh/util/SampleBuffer.java
diffstat 1 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/SampleBuffer.java	Fri Feb 13 12:27:39 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/SampleBuffer.java	Fri Feb 13 15:04:47 2015 +0300
@@ -33,18 +33,19 @@
     private static final long serialVersionUID = 6124923853916845327L;
 
     private static final int PRECISION_BITS = 10;
+    private static final int BUCKETS = Long.SIZE - PRECISION_BITS;
 
     private final int[][] hdr;
 
     public SampleBuffer() {
-        hdr = new int[64][];
-        for (int p = 0; p < 64; p++) {
+        hdr = new int[BUCKETS][];
+        for (int p = 0; p < BUCKETS; p++) {
             hdr[p] = new int[1 << PRECISION_BITS];
         }
     }
 
     public void half() {
-        for (int i = 0; i < 64; i++) {
+        for (int i = 0; i < hdr.length; i++) {
             for (int j = 0; j < hdr[i].length; j++) {
                 int nV = hdr[i][j] / 2;
                 if (nV != 0) { // prevent halving to zero
@@ -55,8 +56,7 @@
     }
 
     public void add(long sample) {
-        int msb = 64 - Long.numberOfLeadingZeros(sample);
-        int bucket = Math.max(0, msb - PRECISION_BITS);
+        int bucket = Math.max(0, BUCKETS - Long.numberOfLeadingZeros(sample));
         int subBucket = (int) (sample >> bucket);
         hdr[bucket][subBucket]++;
     }