src/share/classes/java/util/Vector.java
Print this page
rev 9756 : 8020860: cluster Hashtable/Vector field updates for better transactional memory behaviour
Reviewed-by: mduigou, martin, psandoz
Contributed-by: Sandhya.Viswanathan@intel.com, Mike.Duigou@oracle.com
*** 551,561 ****
* @param index the index of the object to remove
* @throws ArrayIndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index >= size()})
*/
public synchronized void removeElementAt(int index) {
- modCount++;
if (index >= elementCount) {
throw new ArrayIndexOutOfBoundsException(index + " >= " +
elementCount);
}
else if (index < 0) {
--- 551,560 ----
*** 563,572 ****
--- 562,572 ----
}
int j = elementCount - index - 1;
if (j > 0) {
System.arraycopy(elementData, index + 1, elementData, index, j);
}
+ modCount++;
elementCount--;
elementData[elementCount] = null; /* to let gc do its work */
}
/**
*** 591,608 ****
* @param index where to insert the new component
* @throws ArrayIndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index > size()})
*/
public synchronized void insertElementAt(E obj, int index) {
- modCount++;
if (index > elementCount) {
throw new ArrayIndexOutOfBoundsException(index
+ " > " + elementCount);
}
ensureCapacityHelper(elementCount + 1);
System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
elementData[index] = obj;
elementCount++;
}
/**
* Adds the specified component to the end of this vector,
--- 591,608 ----
* @param index where to insert the new component
* @throws ArrayIndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index > size()})
*/
public synchronized void insertElementAt(E obj, int index) {
if (index > elementCount) {
throw new ArrayIndexOutOfBoundsException(index
+ " > " + elementCount);
}
ensureCapacityHelper(elementCount + 1);
System.arraycopy(elementData, index, elementData, index + 1, elementCount - index);
elementData[index] = obj;
+ modCount++;
elementCount++;
}
/**
* Adds the specified component to the end of this vector,
*** 614,625 ****
* method (which is part of the {@link List} interface).
*
* @param obj the component to be added
*/
public synchronized void addElement(E obj) {
- modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = obj;
}
/**
* Removes the first (lowest-indexed) occurrence of the argument
--- 614,625 ----
* method (which is part of the {@link List} interface).
*
* @param obj the component to be added
*/
public synchronized void addElement(E obj) {
ensureCapacityHelper(elementCount + 1);
+ modCount++;
elementData[elementCount++] = obj;
}
/**
* Removes the first (lowest-indexed) occurrence of the argument
*** 651,665 ****
*
* <p>This method is identical in functionality to the {@link #clear}
* method (which is part of the {@link List} interface).
*/
public synchronized void removeAllElements() {
- modCount++;
// Let gc do its work
for (int i = 0; i < elementCount; i++)
elementData[i] = null;
elementCount = 0;
}
/**
* Returns a clone of this vector. The copy will contain a
--- 651,665 ----
*
* <p>This method is identical in functionality to the {@link #clear}
* method (which is part of the {@link List} interface).
*/
public synchronized void removeAllElements() {
// Let gc do its work
for (int i = 0; i < elementCount; i++)
elementData[i] = null;
+ modCount++;
elementCount = 0;
}
/**
* Returns a clone of this vector. The copy will contain a
*** 776,787 ****
* @param e element to be appended to this Vector
* @return {@code true} (as specified by {@link Collection#add})
* @since 1.2
*/
public synchronized boolean add(E e) {
- modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = e;
return true;
}
/**
--- 776,787 ----
* @param e element to be appended to this Vector
* @return {@code true} (as specified by {@link Collection#add})
* @since 1.2
*/
public synchronized boolean add(E e) {
ensureCapacityHelper(elementCount + 1);
+ modCount++;
elementData[elementCount++] = e;
return true;
}
/**
*** 877,893 ****
* @param c elements to be inserted into this Vector
* @return {@code true} if this Vector changed as a result of the call
* @throws NullPointerException if the specified collection is null
* @since 1.2
*/
! public synchronized boolean addAll(Collection<? extends E> c) {
! modCount++;
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityHelper(elementCount + numNew);
System.arraycopy(a, 0, elementData, elementCount, numNew);
elementCount += numNew;
return numNew != 0;
}
/**
* Removes from this Vector all of its elements that are contained in the
--- 877,895 ----
* @param c elements to be inserted into this Vector
* @return {@code true} if this Vector changed as a result of the call
* @throws NullPointerException if the specified collection is null
* @since 1.2
*/
! public boolean addAll(Collection<? extends E> c) {
Object[] a = c.toArray();
int numNew = a.length;
+ synchronized (this) {
ensureCapacityHelper(elementCount + numNew);
System.arraycopy(a, 0, elementData, elementCount, numNew);
+ modCount++;
elementCount += numNew;
+ }
return numNew != 0;
}
/**
* Removes from this Vector all of its elements that are contained in the
*** 948,973 ****
* @throws ArrayIndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index > size()})
* @throws NullPointerException if the specified collection is null
* @since 1.2
*/
! public synchronized boolean addAll(int index, Collection<? extends E> c) {
! modCount++;
if (index < 0 || index > elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object[] a = c.toArray();
int numNew = a.length;
ensureCapacityHelper(elementCount + numNew);
int numMoved = elementCount - index;
if (numMoved > 0)
System.arraycopy(elementData, index, elementData, index + numNew,
numMoved);
System.arraycopy(a, 0, elementData, index, numNew);
elementCount += numNew;
return numNew != 0;
}
/**
* Compares the specified Object with this Vector for equality. Returns
--- 950,977 ----
* @throws ArrayIndexOutOfBoundsException if the index is out of range
* ({@code index < 0 || index > size()})
* @throws NullPointerException if the specified collection is null
* @since 1.2
*/
! public boolean addAll(int index, Collection<? extends E> c) {
if (index < 0 || index > elementCount)
throw new ArrayIndexOutOfBoundsException(index);
Object[] a = c.toArray();
int numNew = a.length;
+ synchronized(this) {
ensureCapacityHelper(elementCount + numNew);
int numMoved = elementCount - index;
if (numMoved > 0)
System.arraycopy(elementData, index, elementData, index + numNew,
numMoved);
System.arraycopy(a, 0, elementData, index, numNew);
+ modCount++;
elementCount += numNew;
+ }
return numNew != 0;
}
/**
* Compares the specified Object with this Vector for equality. Returns
*** 1045,1060 ****
* Shifts any succeeding elements to the left (reduces their index).
* This call shortens the list by {@code (toIndex - fromIndex)} elements.
* (If {@code toIndex==fromIndex}, this operation has no effect.)
*/
protected synchronized void removeRange(int fromIndex, int toIndex) {
- modCount++;
int numMoved = elementCount - toIndex;
System.arraycopy(elementData, toIndex, elementData, fromIndex,
numMoved);
// Let gc do its work
int newElementCount = elementCount - (toIndex-fromIndex);
while (elementCount != newElementCount)
elementData[--elementCount] = null;
}
--- 1049,1064 ----
* Shifts any succeeding elements to the left (reduces their index).
* This call shortens the list by {@code (toIndex - fromIndex)} elements.
* (If {@code toIndex==fromIndex}, this operation has no effect.)
*/
protected synchronized void removeRange(int fromIndex, int toIndex) {
int numMoved = elementCount - toIndex;
System.arraycopy(elementData, toIndex, elementData, fromIndex,
numMoved);
// Let gc do its work
+ modCount++;
int newElementCount = elementCount - (toIndex-fromIndex);
while (elementCount != newElementCount)
elementData[--elementCount] = null;
}