Apache Lucene open-source search software
LUCENE-2792: revert slowdowns on -client vms that are unrelated to this issue
Robert Muirb6a05b1a237e
diff --git a/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java b/lucene/src/java/org/apache/lucene/util/ByteBlockPool.javaindex 3254a817a1a..552340eca6f 100644--- a/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java+++ b/lucene/src/java/org/apache/lucene/util/ByteBlockPool.java@@ -18,6 +18,7 @@ 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@@ -116,7 +117,12 @@ public final class ByteBlockPool {}public void nextBuffer() {- buffers = ArrayUtil.grow(buffers, 2+bufferUpto);+ 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;+ }buffer = buffers[1+bufferUpto] = allocator.getByteBlock();bufferUpto++;diff --git a/lucene/src/java/org/apache/lucene/util/RecyclingByteBlockAllocator.java b/lucene/src/java/org/apache/lucene/util/RecyclingByteBlockAllocator.javaindex af1a48f18b1..2ce77ce33e9 100644--- a/lucene/src/java/org/apache/lucene/util/RecyclingByteBlockAllocator.java+++ b/lucene/src/java/org/apache/lucene/util/RecyclingByteBlockAllocator.java@@ -93,7 +93,13 @@ public final class RecyclingByteBlockAllocator extends ByteBlockPool.Allocator {@Overridepublic synchronized void recycleByteBlocks(byte[][] blocks, int start, int end) {final int numBlocks = Math.min(maxBufferedBlocks - freeBlocks, end - start);- freeByteBlocks = ArrayUtil.grow(freeByteBlocks, freeBlocks + numBlocks);+ final int size = freeBlocks + numBlocks;+ if (size >= freeByteBlocks.length) {+ final byte[][] newBlocks = new byte[ArrayUtil.oversize(size,+ RamUsageEstimator.NUM_BYTES_OBJECT_REF)][];+ System.arraycopy(freeByteBlocks, 0, newBlocks, 0, freeBlocks);+ freeByteBlocks = newBlocks;+ }final int stop = start + numBlocks;for (int i = start; i < stop; i++) {freeByteBlocks[freeBlocks++] = blocks[i];diff --git a/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java b/lucene/src/java/org/apache/lucene/util/automaton/Automaton.javaindex 990dbf58298..de611379b44 100644--- a/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java+++ b/lucene/src/java/org/apache/lucene/util/automaton/Automaton.java@@ -40,6 +40,7 @@ import java.util.List;import java.util.Set;import org.apache.lucene.util.ArrayUtil;+import org.apache.lucene.util.RamUsageEstimator;/*** Finite-state automaton with regular expression operations.@@ -280,7 +281,9 @@ public class Automaton implements Serializable, Cloneable {worklist.add(t.to);t.to.number = upto;if (upto == numberedStates.length) {- numberedStates = ArrayUtil.grow(numberedStates);+ final State[] newArray = new State[ArrayUtil.oversize(1+upto, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];+ System.arraycopy(numberedStates, 0, newArray, 0, upto);+ numberedStates = newArray;}numberedStates[upto] = t.to;upto++;diff --git a/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java b/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.javaindex 965ef6025f6..ce1c19001b2 100644--- a/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java+++ b/lucene/src/java/org/apache/lucene/util/automaton/BasicOperations.java@@ -30,6 +30,7 @@package org.apache.lucene.util.automaton;import org.apache.lucene.util.ArrayUtil;+import org.apache.lucene.util.RamUsageEstimator;import java.util.ArrayList;import java.util.BitSet;@@ -458,7 +459,9 @@ final public class BasicOperations {public void add(Transition t) {if (transitions.length == count) {- transitions = ArrayUtil.grow(transitions);+ Transition[] newArray = new Transition[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];+ System.arraycopy(transitions, 0, newArray, 0, count);+ transitions = newArray;}transitions[count++] = t;}@@ -500,7 +503,9 @@ final public class BasicOperations {private PointTransitions next(int point) {// 1st time we are seeing this pointif (count == points.length) {- points = ArrayUtil.grow(points);+ final PointTransitions[] newArray = new PointTransitions[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];+ System.arraycopy(points, 0, newArray, 0, count);+ points = newArray;}PointTransitions points0 = points[count];if (points0 == null) {@@ -645,7 +650,9 @@ final public class BasicOperations {final SortedIntSet.FrozenIntSet p = statesSet.freeze(q);worklist.add(p);if (newStateUpto == newStatesArray.length) {- newStatesArray = ArrayUtil.grow(newStatesArray);+ final State[] newArray = new State[ArrayUtil.oversize(1+newStateUpto, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];+ System.arraycopy(newStatesArray, 0, newArray, 0, newStateUpto);+ newStatesArray = newArray;}newStatesArray[newStateUpto] = q;q.number = newStateUpto;diff --git a/lucene/src/java/org/apache/lucene/util/automaton/State.java b/lucene/src/java/org/apache/lucene/util/automaton/State.javaindex 148d946d4d0..6aa04e51d96 100644--- a/lucene/src/java/org/apache/lucene/util/automaton/State.java+++ b/lucene/src/java/org/apache/lucene/util/automaton/State.java@@ -29,6 +29,7 @@package org.apache.lucene.util.automaton;import org.apache.lucene.util.ArrayUtil;+import org.apache.lucene.util.RamUsageEstimator;import java.io.Serializable;import java.util.Collection;@@ -110,7 +111,9 @@ public class State implements Serializable, Comparable<State> {*/public void addTransition(Transition t) {if (numTransitions == transitionsArray.length) {- transitionsArray = ArrayUtil.grow(transitionsArray);+ final Transition[] newArray = new Transition[ArrayUtil.oversize(1+numTransitions, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];+ System.arraycopy(transitionsArray, 0, newArray, 0, numTransitions);+ transitionsArray = newArray;}transitionsArray[numTransitions++] = t;}diff --git a/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java b/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.javaindex ee252f25873..167e3458adf 100644--- a/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java+++ b/lucene/src/java/org/apache/lucene/util/automaton/UTF32ToUTF8.java@@ -17,6 +17,7 @@ package org.apache.lucene.util.automaton;* limitations under the License.*/+import org.apache.lucene.util.RamUsageEstimator;import org.apache.lucene.util.ArrayUtil;import java.util.List;@@ -298,7 +299,9 @@ final class UTF32ToUTF8 {private State newUTF8State() {State s = new State();if (utf8StateCount == utf8States.length) {- utf8States = ArrayUtil.grow(utf8States);+ final State[] newArray = new State[ArrayUtil.oversize(1+utf8StateCount, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];+ System.arraycopy(utf8States, 0, newArray, 0, utf8StateCount);+ utf8States = newArray;}utf8States[utf8StateCount] = s;s.number = utf8StateCount;