diff --git a/lucene/src/java/org/apache/lucene/index/SegmentDeletes.java b/lucene/src/java/org/apache/lucene/index/SegmentDeletes.java index d7ba1a7bd69..1bb7f028c44 100644 --- a/lucene/src/java/org/apache/lucene/index/SegmentDeletes.java +++ b/lucene/src/java/org/apache/lucene/index/SegmentDeletes.java @@ -48,19 +48,19 @@ class SegmentDeletes { Term's text is String (OBJ_HEADER + 4*INT + POINTER + OBJ_HEADER + string.length*CHAR). Integer is OBJ_HEADER + INT. */ - final static int BYTES_PER_DEL_TERM = 8*RamUsageEstimator.NUM_BYTES_OBJ_REF + 5*RamUsageEstimator.NUM_BYTES_OBJ_HEADER + 6*RamUsageEstimator.NUM_BYTES_INT; + final static int BYTES_PER_DEL_TERM = 8*RamUsageEstimator.NUM_BYTES_OBJECT_REF + 5*RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + 6*RamUsageEstimator.NUM_BYTES_INT; /* Rough logic: del docIDs are List. Say list allocates ~2X size (2*POINTER). Integer is OBJ_HEADER + int */ - final static int BYTES_PER_DEL_DOCID = 2*RamUsageEstimator.NUM_BYTES_OBJ_REF + RamUsageEstimator.NUM_BYTES_OBJ_HEADER + RamUsageEstimator.NUM_BYTES_INT; + final static int BYTES_PER_DEL_DOCID = 2*RamUsageEstimator.NUM_BYTES_OBJECT_REF + RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + RamUsageEstimator.NUM_BYTES_INT; /* Rough logic: HashMap has an array[Entry] w/ varying load factor (say 2 * POINTER). Entry is object w/ Query key, Integer val, int hash, Entry next (OBJ_HEADER + 3*POINTER + INT). Query we often undercount (say 24 bytes). Integer is OBJ_HEADER + INT. */ - final static int BYTES_PER_DEL_QUERY = 5*RamUsageEstimator.NUM_BYTES_OBJ_REF + 2*RamUsageEstimator.NUM_BYTES_OBJ_HEADER + 2*RamUsageEstimator.NUM_BYTES_INT + 24; + final static int BYTES_PER_DEL_QUERY = 5*RamUsageEstimator.NUM_BYTES_OBJECT_REF + 2*RamUsageEstimator.NUM_BYTES_OBJECT_HEADER + 2*RamUsageEstimator.NUM_BYTES_INT + 24; // TODO: many of the deletes stored here will map to // Integer.MAX_VALUE; we could be more efficient for this diff --git a/lucene/src/java/org/apache/lucene/util/ArrayUtil.java b/lucene/src/java/org/apache/lucene/util/ArrayUtil.java index fbf62507bae..765e153a899 100644 --- a/lucene/src/java/org/apache/lucene/util/ArrayUtil.java +++ b/lucene/src/java/org/apache/lucene/util/ArrayUtil.java @@ -433,7 +433,7 @@ public final class ArrayUtil { public static T[] grow(T[] array, int minSize) { if (array.length < minSize) { @SuppressWarnings("unchecked") final T[] newArray = - (T[]) Array.newInstance(array.getClass().getComponentType(), oversize(minSize, RamUsageEstimator.NUM_BYTES_OBJ_REF)); + (T[]) Array.newInstance(array.getClass().getComponentType(), oversize(minSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF)); System.arraycopy(array, 0, newArray, 0, array.length); return newArray; } else @@ -445,7 +445,7 @@ public final class ArrayUtil { } public static T[] shrink(T[] array, int targetSize) { - final int newSize = getShrinkSize(array.length, targetSize, RamUsageEstimator.NUM_BYTES_OBJ_REF); + final int newSize = getShrinkSize(array.length, targetSize, RamUsageEstimator.NUM_BYTES_OBJECT_REF); if (newSize != array.length) { @SuppressWarnings("unchecked") final T[] newArray = (T[]) Array.newInstance(array.getClass().getComponentType(), newSize); diff --git a/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java b/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java index 552340eca6f..3254a817a1a 100644 --- a/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java +++ b/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java @@ -18,7 +18,6 @@ package org.apache.lucene.util; */ import java.util.Arrays; import java.util.List; -import static org.apache.lucene.util.RamUsageEstimator.NUM_BYTES_OBJECT_REF; /** * Class that Posting and PostingVector use to write byte @@ -117,12 +116,7 @@ public final class ByteBlockPool { } public void nextBuffer() { - if (1+bufferUpto == buffers.length) { - byte[][] newBuffers = new byte[ArrayUtil.oversize(buffers.length+1, - NUM_BYTES_OBJECT_REF)][]; - System.arraycopy(buffers, 0, newBuffers, 0, buffers.length); - buffers = newBuffers; - } + buffers = ArrayUtil.grow(buffers, 2+bufferUpto); buffer = buffers[1+bufferUpto] = allocator.getByteBlock(); bufferUpto++; diff --git a/lucene/src/java/org/apache/lucene/util/RamUsageEstimator.java b/lucene/src/java/org/apache/lucene/util/RamUsageEstimator.java index 40a65a79895..fd76948ac5d 100644 --- a/lucene/src/java/org/apache/lucene/util/RamUsageEstimator.java +++ b/lucene/src/java/org/apache/lucene/util/RamUsageEstimator.java @@ -43,9 +43,10 @@ public final class RamUsageEstimator { public final static int NUM_BYTES_LONG = 8; public final static int NUM_BYTES_FLOAT = 4; public final static int NUM_BYTES_DOUBLE = 8; - public final static int NUM_BYTES_OBJ_HEADER = 8; - public final static int NUM_BYTES_OBJ_REF = Constants.JRE_IS_64BIT ? 8 : 4; - public final static int NUM_BYTES_ARRAY_HEADER = NUM_BYTES_OBJ_HEADER + NUM_BYTES_INT + NUM_BYTES_OBJ_REF; + public final static int NUM_BYTES_CHAR = 2; + public final static int NUM_BYTES_OBJECT_HEADER = 8; + public final static int NUM_BYTES_OBJECT_REF = Constants.JRE_IS_64BIT ? 8 : 4; + public final static int NUM_BYTES_ARRAY_HEADER = NUM_BYTES_OBJECT_HEADER + NUM_BYTES_INT + NUM_BYTES_OBJECT_REF; private MemoryModel memoryModel; @@ -55,9 +56,6 @@ public final class RamUsageEstimator { private int arraySize; private int classSize; - public final static int NUM_BYTES_OBJECT_REF = Constants.JRE_IS_64BIT ? 8 : 4; - public final static int NUM_BYTES_CHAR = 2; - private boolean checkInterned; /**