< prev index next >

src/share/classes/java/util/ArrayDeque.java

Print this page
rev 12533 : 8174109: Better queuing priorities
Reviewed-by: smarks

*** 34,43 **** --- 34,44 ---- package java.util; import java.io.Serializable; import java.util.function.Consumer; + import sun.misc.SharedSecrets; /** * Resizable-array implementation of the {@link Deque} interface. Array * deques have no capacity restrictions; they grow as necessary to support * usage. They are not thread-safe; in the absence of external
*** 116,131 **** */ private static final int MIN_INITIAL_CAPACITY = 8; // ****** Array allocation and resizing utilities ****** ! /** ! * Allocates empty array to hold the given number of elements. ! * ! * @param numElements the number of elements to hold ! */ ! private void allocateElements(int numElements) { int initialCapacity = MIN_INITIAL_CAPACITY; // Find the best power of two to hold elements. // Tests "<=" because arrays aren't kept full. if (numElements >= initialCapacity) { initialCapacity = numElements; --- 117,127 ---- */ private static final int MIN_INITIAL_CAPACITY = 8; // ****** Array allocation and resizing utilities ****** ! private static int calculateSize(int numElements) { int initialCapacity = MIN_INITIAL_CAPACITY; // Find the best power of two to hold elements. // Tests "<=" because arrays aren't kept full. if (numElements >= initialCapacity) { initialCapacity = numElements;
*** 137,147 **** initialCapacity++; if (initialCapacity < 0) // Too many elements, must back off initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements } ! elements = new Object[initialCapacity]; } /** * Doubles the capacity of this deque. Call only when full, i.e., * when head and tail have wrapped around to become equal. --- 133,152 ---- initialCapacity++; if (initialCapacity < 0) // Too many elements, must back off initialCapacity >>>= 1;// Good luck allocating 2 ^ 30 elements } ! return initialCapacity; ! } ! ! /** ! * Allocates empty array to hold the given number of elements. ! * ! * @param numElements the number of elements to hold ! */ ! private void allocateElements(int numElements) { ! elements = new Object[calculateSize(numElements)]; } /** * Doubles the capacity of this deque. Call only when full, i.e., * when head and tail have wrapped around to become equal.
*** 877,886 **** --- 882,893 ---- throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); // Read in size and allocate array int size = s.readInt(); + int capacity = calculateSize(size); + SharedSecrets.getJavaOISAccess().checkArray(s, Object[].class, capacity); allocateElements(size); head = 0; tail = size; // Read in all elements in the proper order.
< prev index next >