提交 d49cc740 编写于 作者: J jjg

Merge

...@@ -772,7 +772,7 @@ public final class Integer extends Number implements Comparable<Integer> { ...@@ -772,7 +772,7 @@ public final class Integer extends Number implements Comparable<Integer> {
int i = parseInt(integerCacheHighPropValue); int i = parseInt(integerCacheHighPropValue);
i = Math.max(i, 127); i = Math.max(i, 127);
// Maximum array size is Integer.MAX_VALUE // Maximum array size is Integer.MAX_VALUE
h = Math.min(i, Integer.MAX_VALUE - (-low)); h = Math.min(i, Integer.MAX_VALUE - (-low) -1);
} }
high = h; high = h;
......
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.lang.annotation;
/**
* The annotation type {@code java.lang.annotation.Repeatable} is
* used to indicate that the annotation type whose declaration it
* (meta-)annotates is <em>repeatable</em>. The value of
* {@code @Repeatable} indicates the <em>containing annotation
* type</em> for the repeatable annotation type.
*
* @since 1.8
* @jls 9.6 Annotation Types
* @jls 9.7 Annotations
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Repeatable {
/**
* Indicates the <em>containing annotation type</em> for the
* repeatable annotation type.
*/
Class<? extends Annotation> value();
}
...@@ -111,7 +111,7 @@ public class AtomicBoolean implements java.io.Serializable { ...@@ -111,7 +111,7 @@ public class AtomicBoolean implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public boolean weakCompareAndSet(boolean expect, boolean update) { public boolean weakCompareAndSet(boolean expect, boolean update) {
int e = expect ? 1 : 0; int e = expect ? 1 : 0;
...@@ -146,16 +146,16 @@ public class AtomicBoolean implements java.io.Serializable { ...@@ -146,16 +146,16 @@ public class AtomicBoolean implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final boolean getAndSet(boolean newValue) { public final boolean getAndSet(boolean newValue) {
for (;;) { boolean prev;
boolean current = get(); do {
if (compareAndSet(current, newValue)) prev = get();
return current; } while (!compareAndSet(prev, newValue));
} return prev;
} }
/** /**
* Returns the String representation of the current value. * Returns the String representation of the current value.
* @return the String representation of the current value. * @return the String representation of the current value
*/ */
public String toString() { public String toString() {
return Boolean.toString(get()); return Boolean.toString(get());
......
...@@ -115,11 +115,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -115,11 +115,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndSet(int newValue) { public final int getAndSet(int newValue) {
for (;;) { return unsafe.getAndSetInt(this, valueOffset, newValue);
int current = get();
if (compareAndSet(current, newValue))
return current;
}
} }
/** /**
...@@ -145,7 +141,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -145,7 +141,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public final boolean weakCompareAndSet(int expect, int update) { public final boolean weakCompareAndSet(int expect, int update) {
return unsafe.compareAndSwapInt(this, valueOffset, expect, update); return unsafe.compareAndSwapInt(this, valueOffset, expect, update);
...@@ -157,12 +153,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -157,12 +153,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndIncrement() { public final int getAndIncrement() {
for (;;) { return getAndAdd(1);
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return current;
}
} }
/** /**
...@@ -171,12 +162,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -171,12 +162,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndDecrement() { public final int getAndDecrement() {
for (;;) { return getAndAdd(-1);
int current = get();
int next = current - 1;
if (compareAndSet(current, next))
return current;
}
} }
/** /**
...@@ -186,12 +172,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -186,12 +172,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndAdd(int delta) { public final int getAndAdd(int delta) {
for (;;) { return unsafe.getAndAddInt(this, valueOffset, delta);
int current = get();
int next = current + delta;
if (compareAndSet(current, next))
return current;
}
} }
/** /**
...@@ -200,12 +181,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -200,12 +181,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int incrementAndGet() { public final int incrementAndGet() {
for (;;) { return getAndAdd(1) + 1;
int current = get();
int next = current + 1;
if (compareAndSet(current, next))
return next;
}
} }
/** /**
...@@ -214,12 +190,7 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -214,12 +190,7 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int decrementAndGet() { public final int decrementAndGet() {
for (;;) { return getAndAdd(-1) - 1;
int current = get();
int next = current - 1;
if (compareAndSet(current, next))
return next;
}
} }
/** /**
...@@ -229,17 +200,12 @@ public class AtomicInteger extends Number implements java.io.Serializable { ...@@ -229,17 +200,12 @@ public class AtomicInteger extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int addAndGet(int delta) { public final int addAndGet(int delta) {
for (;;) { return getAndAdd(delta) + delta;
int current = get();
int next = current + delta;
if (compareAndSet(current, next))
return next;
}
} }
/** /**
* Returns the String representation of the current value. * Returns the String representation of the current value.
* @return the String representation of the current value. * @return the String representation of the current value
*/ */
public String toString() { public String toString() {
return Integer.toString(get()); return Integer.toString(get());
......
...@@ -145,12 +145,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -145,12 +145,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndSet(int i, int newValue) { public final int getAndSet(int i, int newValue) {
long offset = checkedByteOffset(i); return unsafe.getAndSetInt(array, checkedByteOffset(i), newValue);
while (true) {
int current = getRaw(offset);
if (compareAndSetRaw(offset, current, newValue))
return current;
}
} }
/** /**
...@@ -182,7 +177,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -182,7 +177,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public final boolean weakCompareAndSet(int i, int expect, int update) { public final boolean weakCompareAndSet(int i, int expect, int update) {
return compareAndSet(i, expect, update); return compareAndSet(i, expect, update);
...@@ -216,12 +211,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -216,12 +211,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final int getAndAdd(int i, int delta) { public final int getAndAdd(int i, int delta) {
long offset = checkedByteOffset(i); return unsafe.getAndAddInt(array, checkedByteOffset(i), delta);
while (true) {
int current = getRaw(offset);
if (compareAndSetRaw(offset, current, current + delta))
return current;
}
} }
/** /**
...@@ -231,7 +221,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -231,7 +221,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int incrementAndGet(int i) { public final int incrementAndGet(int i) {
return addAndGet(i, 1); return getAndAdd(i, 1) + 1;
} }
/** /**
...@@ -241,7 +231,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -241,7 +231,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int decrementAndGet(int i) { public final int decrementAndGet(int i) {
return addAndGet(i, -1); return getAndAdd(i, -1) - 1;
} }
/** /**
...@@ -252,13 +242,7 @@ public class AtomicIntegerArray implements java.io.Serializable { ...@@ -252,13 +242,7 @@ public class AtomicIntegerArray implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final int addAndGet(int i, int delta) { public final int addAndGet(int i, int delta) {
long offset = checkedByteOffset(i); return getAndAdd(i, delta) + delta;
while (true) {
int current = getRaw(offset);
int next = current + delta;
if (compareAndSetRaw(offset, current, next))
return next;
}
} }
/** /**
......
...@@ -159,11 +159,11 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -159,11 +159,11 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public int getAndSet(T obj, int newValue) { public int getAndSet(T obj, int newValue) {
for (;;) { int prev;
int current = get(obj); do {
if (compareAndSet(obj, current, newValue)) prev = get(obj);
return current; } while (!compareAndSet(obj, prev, newValue));
} return prev;
} }
/** /**
...@@ -174,12 +174,12 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -174,12 +174,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public int getAndIncrement(T obj) { public int getAndIncrement(T obj) {
for (;;) { int prev, next;
int current = get(obj); do {
int next = current + 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + 1;
return current; } while (!compareAndSet(obj, prev, next));
} return prev;
} }
/** /**
...@@ -190,12 +190,12 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -190,12 +190,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public int getAndDecrement(T obj) { public int getAndDecrement(T obj) {
for (;;) { int prev, next;
int current = get(obj); do {
int next = current - 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev - 1;
return current; } while (!compareAndSet(obj, prev, next));
} return prev;
} }
/** /**
...@@ -207,12 +207,12 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -207,12 +207,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public int getAndAdd(T obj, int delta) { public int getAndAdd(T obj, int delta) {
for (;;) { int prev, next;
int current = get(obj); do {
int next = current + delta; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + delta;
return current; } while (!compareAndSet(obj, prev, next));
} return prev;
} }
/** /**
...@@ -223,12 +223,12 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -223,12 +223,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the updated value * @return the updated value
*/ */
public int incrementAndGet(T obj) { public int incrementAndGet(T obj) {
for (;;) { int prev, next;
int current = get(obj); do {
int next = current + 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + 1;
return next; } while (!compareAndSet(obj, prev, next));
} return next;
} }
/** /**
...@@ -239,12 +239,12 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -239,12 +239,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the updated value * @return the updated value
*/ */
public int decrementAndGet(T obj) { public int decrementAndGet(T obj) {
for (;;) { int prev, next;
int current = get(obj); do {
int next = current - 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev - 1;
return next; } while (!compareAndSet(obj, prev, next));
} return next;
} }
/** /**
...@@ -256,12 +256,12 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -256,12 +256,12 @@ public abstract class AtomicIntegerFieldUpdater<T> {
* @return the updated value * @return the updated value
*/ */
public int addAndGet(T obj, int delta) { public int addAndGet(T obj, int delta) {
for (;;) { int prev, next;
int current = get(obj); do {
int next = current + delta; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + delta;
return next; } while (!compareAndSet(obj, prev, next));
} return next;
} }
/** /**
...@@ -361,6 +361,36 @@ public abstract class AtomicIntegerFieldUpdater<T> { ...@@ -361,6 +361,36 @@ public abstract class AtomicIntegerFieldUpdater<T> {
return unsafe.getIntVolatile(obj, offset); return unsafe.getIntVolatile(obj, offset);
} }
public int getAndSet(T obj, int newValue) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
return unsafe.getAndSetInt(obj, offset, newValue);
}
public int getAndIncrement(T obj) {
return getAndAdd(obj, 1);
}
public int getAndDecrement(T obj) {
return getAndAdd(obj, -1);
}
public int getAndAdd(T obj, int delta) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
return unsafe.getAndAddInt(obj, offset, delta);
}
public int incrementAndGet(T obj) {
return getAndAdd(obj, 1) + 1;
}
public int decrementAndGet(T obj) {
return getAndAdd(obj, -1) - 1;
}
public int addAndGet(T obj, int delta) {
return getAndAdd(obj, delta) + delta;
}
private void ensureProtectedAccess(T obj) { private void ensureProtectedAccess(T obj) {
if (cclass.isInstance(obj)) { if (cclass.isInstance(obj)) {
return; return;
......
...@@ -129,11 +129,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -129,11 +129,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndSet(long newValue) { public final long getAndSet(long newValue) {
while (true) { return unsafe.getAndSetLong(this, valueOffset, newValue);
long current = get();
if (compareAndSet(current, newValue))
return current;
}
} }
/** /**
...@@ -159,7 +155,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -159,7 +155,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public final boolean weakCompareAndSet(long expect, long update) { public final boolean weakCompareAndSet(long expect, long update) {
return unsafe.compareAndSwapLong(this, valueOffset, expect, update); return unsafe.compareAndSwapLong(this, valueOffset, expect, update);
...@@ -171,12 +167,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -171,12 +167,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndIncrement() { public final long getAndIncrement() {
while (true) { return getAndAdd(1);
long current = get();
long next = current + 1;
if (compareAndSet(current, next))
return current;
}
} }
/** /**
...@@ -185,12 +176,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -185,12 +176,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndDecrement() { public final long getAndDecrement() {
while (true) { return getAndAdd(-1);
long current = get();
long next = current - 1;
if (compareAndSet(current, next))
return current;
}
} }
/** /**
...@@ -200,12 +186,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -200,12 +186,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndAdd(long delta) { public final long getAndAdd(long delta) {
while (true) { return unsafe.getAndAddLong(this, valueOffset, delta);
long current = get();
long next = current + delta;
if (compareAndSet(current, next))
return current;
}
} }
/** /**
...@@ -214,12 +195,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -214,12 +195,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long incrementAndGet() { public final long incrementAndGet() {
for (;;) { return getAndAdd(1) + 1;
long current = get();
long next = current + 1;
if (compareAndSet(current, next))
return next;
}
} }
/** /**
...@@ -228,12 +204,7 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -228,12 +204,7 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long decrementAndGet() { public final long decrementAndGet() {
for (;;) { return getAndAdd(-1) - 1;
long current = get();
long next = current - 1;
if (compareAndSet(current, next))
return next;
}
} }
/** /**
...@@ -243,17 +214,12 @@ public class AtomicLong extends Number implements java.io.Serializable { ...@@ -243,17 +214,12 @@ public class AtomicLong extends Number implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long addAndGet(long delta) { public final long addAndGet(long delta) {
for (;;) { return getAndAdd(delta) + delta;
long current = get();
long next = current + delta;
if (compareAndSet(current, next))
return next;
}
} }
/** /**
* Returns the String representation of the current value. * Returns the String representation of the current value.
* @return the String representation of the current value. * @return the String representation of the current value
*/ */
public String toString() { public String toString() {
return Long.toString(get()); return Long.toString(get());
......
...@@ -144,12 +144,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -144,12 +144,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndSet(int i, long newValue) { public final long getAndSet(int i, long newValue) {
long offset = checkedByteOffset(i); return unsafe.getAndSetLong(array, checkedByteOffset(i), newValue);
while (true) {
long current = getRaw(offset);
if (compareAndSetRaw(offset, current, newValue))
return current;
}
} }
/** /**
...@@ -181,7 +176,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -181,7 +176,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public final boolean weakCompareAndSet(int i, long expect, long update) { public final boolean weakCompareAndSet(int i, long expect, long update) {
return compareAndSet(i, expect, update); return compareAndSet(i, expect, update);
...@@ -215,12 +210,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -215,12 +210,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the previous value * @return the previous value
*/ */
public final long getAndAdd(int i, long delta) { public final long getAndAdd(int i, long delta) {
long offset = checkedByteOffset(i); return unsafe.getAndAddLong(array, checkedByteOffset(i), delta);
while (true) {
long current = getRaw(offset);
if (compareAndSetRaw(offset, current, current + delta))
return current;
}
} }
/** /**
...@@ -230,7 +220,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -230,7 +220,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long incrementAndGet(int i) { public final long incrementAndGet(int i) {
return addAndGet(i, 1); return getAndAdd(i, 1) + 1;
} }
/** /**
...@@ -240,7 +230,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -240,7 +230,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public final long decrementAndGet(int i) { public final long decrementAndGet(int i) {
return addAndGet(i, -1); return getAndAdd(i, -1) - 1;
} }
/** /**
...@@ -251,13 +241,7 @@ public class AtomicLongArray implements java.io.Serializable { ...@@ -251,13 +241,7 @@ public class AtomicLongArray implements java.io.Serializable {
* @return the updated value * @return the updated value
*/ */
public long addAndGet(int i, long delta) { public long addAndGet(int i, long delta) {
long offset = checkedByteOffset(i); return getAndAdd(i, delta) + delta;
while (true) {
long current = getRaw(offset);
long next = current + delta;
if (compareAndSetRaw(offset, current, next))
return next;
}
} }
/** /**
......
...@@ -98,7 +98,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -98,7 +98,7 @@ public abstract class AtomicLongFieldUpdater<T> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
* @throws ClassCastException if {@code obj} is not an instance * @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor. * of the class possessing the field established in the constructor.
*/ */
...@@ -118,7 +118,7 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -118,7 +118,7 @@ public abstract class AtomicLongFieldUpdater<T> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
* @throws ClassCastException if {@code obj} is not an instance * @throws ClassCastException if {@code obj} is not an instance
* of the class possessing the field established in the constructor. * of the class possessing the field established in the constructor.
*/ */
...@@ -162,11 +162,11 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -162,11 +162,11 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public long getAndSet(T obj, long newValue) { public long getAndSet(T obj, long newValue) {
for (;;) { long prev;
long current = get(obj); do {
if (compareAndSet(obj, current, newValue)) prev = get(obj);
return current; } while (!compareAndSet(obj, prev, newValue));
} return prev;
} }
/** /**
...@@ -177,12 +177,12 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -177,12 +177,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public long getAndIncrement(T obj) { public long getAndIncrement(T obj) {
for (;;) { long prev, next;
long current = get(obj); do {
long next = current + 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + 1;
return current; } while (!compareAndSet(obj, prev, next));
} return prev;
} }
/** /**
...@@ -193,12 +193,12 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -193,12 +193,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public long getAndDecrement(T obj) { public long getAndDecrement(T obj) {
for (;;) { long prev, next;
long current = get(obj); do {
long next = current - 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev - 1;
return current; } while (!compareAndSet(obj, prev, next));
} return prev;
} }
/** /**
...@@ -210,12 +210,12 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -210,12 +210,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the previous value * @return the previous value
*/ */
public long getAndAdd(T obj, long delta) { public long getAndAdd(T obj, long delta) {
for (;;) { long prev, next;
long current = get(obj); do {
long next = current + delta; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + delta;
return current; } while (!compareAndSet(obj, prev, next));
} return prev;
} }
/** /**
...@@ -226,12 +226,12 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -226,12 +226,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the updated value * @return the updated value
*/ */
public long incrementAndGet(T obj) { public long incrementAndGet(T obj) {
for (;;) { long prev, next;
long current = get(obj); do {
long next = current + 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + 1;
return next; } while (!compareAndSet(obj, prev, next));
} return next;
} }
/** /**
...@@ -242,12 +242,12 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -242,12 +242,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the updated value * @return the updated value
*/ */
public long decrementAndGet(T obj) { public long decrementAndGet(T obj) {
for (;;) { long prev, next;
long current = get(obj); do {
long next = current - 1; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev - 1;
return next; } while (!compareAndSet(obj, prev, next));
} return next;
} }
/** /**
...@@ -259,12 +259,12 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -259,12 +259,12 @@ public abstract class AtomicLongFieldUpdater<T> {
* @return the updated value * @return the updated value
*/ */
public long addAndGet(T obj, long delta) { public long addAndGet(T obj, long delta) {
for (;;) { long prev, next;
long current = get(obj); do {
long next = current + delta; prev = get(obj);
if (compareAndSet(obj, current, next)) next = prev + delta;
return next; } while (!compareAndSet(obj, prev, next));
} return next;
} }
private static class CASUpdater<T> extends AtomicLongFieldUpdater<T> { private static class CASUpdater<T> extends AtomicLongFieldUpdater<T> {
...@@ -345,6 +345,36 @@ public abstract class AtomicLongFieldUpdater<T> { ...@@ -345,6 +345,36 @@ public abstract class AtomicLongFieldUpdater<T> {
return unsafe.getLongVolatile(obj, offset); return unsafe.getLongVolatile(obj, offset);
} }
public long getAndSet(T obj, long newValue) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
return unsafe.getAndSetLong(obj, offset, newValue);
}
public long getAndIncrement(T obj) {
return getAndAdd(obj, 1);
}
public long getAndDecrement(T obj) {
return getAndAdd(obj, -1);
}
public long getAndAdd(T obj, long delta) {
if (obj == null || obj.getClass() != tclass || cclass != null) fullCheck(obj);
return unsafe.getAndAddLong(obj, offset, delta);
}
public long incrementAndGet(T obj) {
return getAndAdd(obj, 1) + 1;
}
public long decrementAndGet(T obj) {
return getAndAdd(obj, -1) - 1;
}
public long addAndGet(T obj, long delta) {
return getAndAdd(obj, delta) + delta;
}
private void ensureProtectedAccess(T obj) { private void ensureProtectedAccess(T obj) {
if (cclass.isInstance(obj)) { if (cclass.isInstance(obj)) {
return; return;
......
...@@ -124,7 +124,7 @@ public class AtomicReference<V> implements java.io.Serializable { ...@@ -124,7 +124,7 @@ public class AtomicReference<V> implements java.io.Serializable {
* *
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public final boolean weakCompareAndSet(V expect, V update) { public final boolean weakCompareAndSet(V expect, V update) {
return unsafe.compareAndSwapObject(this, valueOffset, expect, update); return unsafe.compareAndSwapObject(this, valueOffset, expect, update);
...@@ -136,17 +136,14 @@ public class AtomicReference<V> implements java.io.Serializable { ...@@ -136,17 +136,14 @@ public class AtomicReference<V> implements java.io.Serializable {
* @param newValue the new value * @param newValue the new value
* @return the previous value * @return the previous value
*/ */
@SuppressWarnings("unchecked")
public final V getAndSet(V newValue) { public final V getAndSet(V newValue) {
while (true) { return (V)unsafe.getAndSetObject(this, valueOffset, newValue);
V x = get();
if (compareAndSet(x, newValue))
return x;
}
} }
/** /**
* Returns the String representation of the current value. * Returns the String representation of the current value.
* @return the String representation of the current value. * @return the String representation of the current value
*/ */
public String toString() { public String toString() {
return String.valueOf(get()); return String.valueOf(get());
......
...@@ -159,13 +159,9 @@ public class AtomicReferenceArray<E> implements java.io.Serializable { ...@@ -159,13 +159,9 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* @param newValue the new value * @param newValue the new value
* @return the previous value * @return the previous value
*/ */
@SuppressWarnings("unchecked")
public final E getAndSet(int i, E newValue) { public final E getAndSet(int i, E newValue) {
long offset = checkedByteOffset(i); return (E)unsafe.getAndSetObject(array, checkedByteOffset(i), newValue);
while (true) {
E current = getRaw(offset);
if (compareAndSetRaw(offset, current, newValue))
return current;
}
} }
/** /**
...@@ -197,7 +193,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable { ...@@ -197,7 +193,7 @@ public class AtomicReferenceArray<E> implements java.io.Serializable {
* @param i the index * @param i the index
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public final boolean weakCompareAndSet(int i, E expect, E update) { public final boolean weakCompareAndSet(int i, E expect, E update) {
return compareAndSet(i, expect, update); return compareAndSet(i, expect, update);
......
...@@ -116,7 +116,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -116,7 +116,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public abstract boolean compareAndSet(T obj, V expect, V update); public abstract boolean compareAndSet(T obj, V expect, V update);
...@@ -134,7 +134,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -134,7 +134,7 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @param obj An object whose field to conditionally set * @param obj An object whose field to conditionally set
* @param expect the expected value * @param expect the expected value
* @param update the new value * @param update the new value
* @return true if successful. * @return true if successful
*/ */
public abstract boolean weakCompareAndSet(T obj, V expect, V update); public abstract boolean weakCompareAndSet(T obj, V expect, V update);
...@@ -176,11 +176,11 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -176,11 +176,11 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
* @return the previous value * @return the previous value
*/ */
public V getAndSet(T obj, V newValue) { public V getAndSet(T obj, V newValue) {
for (;;) { V prev;
V current = get(obj); do {
if (compareAndSet(obj, current, newValue)) prev = get(obj);
return current; } while (!compareAndSet(obj, prev, newValue));
} return prev;
} }
private static final class AtomicReferenceFieldUpdaterImpl<T,V> private static final class AtomicReferenceFieldUpdaterImpl<T,V>
...@@ -321,6 +321,15 @@ public abstract class AtomicReferenceFieldUpdater<T, V> { ...@@ -321,6 +321,15 @@ public abstract class AtomicReferenceFieldUpdater<T, V> {
return (V)unsafe.getObjectVolatile(obj, offset); return (V)unsafe.getObjectVolatile(obj, offset);
} }
@SuppressWarnings("unchecked")
public V getAndSet(T obj, V newValue) {
if (obj == null || obj.getClass() != tclass || cclass != null ||
(newValue != null && vclass != null &&
vclass != newValue.getClass()))
updateCheck(obj, newValue);
return (V)unsafe.getAndSetObject(obj, offset, newValue);
}
private void ensureProtectedAccess(T obj) { private void ensureProtectedAccess(T obj) {
if (cclass.isInstance(obj)) { if (cclass.isInstance(obj)) {
return; return;
......
...@@ -135,24 +135,19 @@ public class WinCommand { ...@@ -135,24 +135,19 @@ public class WinCommand {
// Win9x systems don't have a cmd.exe // Win9x systems don't have a cmd.exe
if (new File(systemDirW, "cmd.exe").exists()) { if (new File(systemDirW, "cmd.exe").exists()) {
try { out.println("Running cmd.exe tests...");
out.println("Running cmd.exe tests..."); writeFile("cdcmd.cmd", "@echo off\r\nCD\r\n");
writeFile("cdcmd.cmd", "@echo off\r\nCD\r\n"); writeFile("cdbat.bat", "@echo off\r\nCD\r\n");
writeFile("cdbat.bat", "@echo off\r\nCD\r\n"); checkCD("cmd",
checkCD("cmd", "cmd.exe",
"cmd.exe", systemDirW + "\\cmd.exe",
systemDirW + "\\cmd.exe", // Only the ".exe" extension can be omitted
// Only the ".exe" extension can be omitted systemDirW + "\\cmd",
systemDirW + "\\cmd", systemDirM + "/cmd.exe",
systemDirM + "/cmd.exe", systemDirM + "/cmd",
systemDirM + "/cmd", "/" + systemDirM + "/cmd",
"/" + systemDirM + "/cmd", "cdcmd.cmd", "./cdcmd.cmd", ".\\cdcmd.cmd",
"cdcmd.cmd", "./cdcmd.cmd", ".\\cdcmd.cmd", "cdbat.bat", "./cdbat.bat", ".\\cdbat.bat");
"cdbat.bat", "./cdbat.bat", ".\\cdbat.bat");
} finally {
new File("cdcmd.cmd").delete();
new File("cdbat.bat").delete();
}
} }
// 16-bit apps like command.com must have a console; // 16-bit apps like command.com must have a console;
......
...@@ -31,6 +31,7 @@ public class ExpectedEncoding { ...@@ -31,6 +31,7 @@ public class ExpectedEncoding {
if (args.length != 2) { if (args.length != 2) {
System.out.println("Usage:"); System.out.println("Usage:");
System.out.println("$ java ExpectedEncoding <expected file.encoding> <expected sun.jnu.encoding>"); System.out.println("$ java ExpectedEncoding <expected file.encoding> <expected sun.jnu.encoding>");
System.exit(1);
} }
String expectFileEnc = args[0]; String expectFileEnc = args[0];
String expectSunJnuEnc = args[1]; String expectSunJnuEnc = args[1];
...@@ -49,8 +50,7 @@ public class ExpectedEncoding { ...@@ -49,8 +50,7 @@ public class ExpectedEncoding {
failed = true; failed = true;
} }
if (failed) { if (failed) {
System.err.println("Test Failed"); throw new RuntimeException("Test Failed");
System.exit(1);
} }
} }
} }
...@@ -63,14 +63,16 @@ echo "Building test classes..." ...@@ -63,14 +63,16 @@ echo "Building test classes..."
"$JAVAC" -d "${TESTCLASSES}" "${TESTSRC}"/ExpectedEncoding.java "$JAVAC" -d "${TESTCLASSES}" "${TESTSRC}"/ExpectedEncoding.java
echo "" echo ""
echo "Running test for LANG=C" echo "Running test for C locale"
export LANG=C export LANG=C
export LC_ALL=C
"${JAVA}" ${TESTVMOPTS} -classpath "${TESTCLASSES}" ExpectedEncoding US-ASCII UTF-8 "${JAVA}" ${TESTVMOPTS} -classpath "${TESTCLASSES}" ExpectedEncoding US-ASCII UTF-8
result1=$? result1=$?
echo "" echo ""
echo "Running test for LANG=en_US.UTF-8" echo "Running test for en_US.UTF-8 locale"
export LANG=en_US.UTF-8 export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
"${JAVA}" ${TESTVMOPTS} -classpath "${TESTCLASSES}" ExpectedEncoding UTF-8 UTF-8 "${JAVA}" ${TESTVMOPTS} -classpath "${TESTCLASSES}" ExpectedEncoding UTF-8 UTF-8
result2=$? result2=$?
...@@ -79,11 +81,15 @@ echo "Cleanup" ...@@ -79,11 +81,15 @@ echo "Cleanup"
rm ${TESTCLASSES}/ExpectedEncoding.class rm ${TESTCLASSES}/ExpectedEncoding.class
if [ ${result1} -ne 0 ] ; then if [ ${result1} -ne 0 ] ; then
echo "Test failed for LANG=C" echo "Test failed for C locale"
echo " LANG=\"${LANG}\""
echo " LC_ALL=\"${LC_ALL}\""
exit ${result1} exit ${result1}
fi fi
if [ ${result2} -ne 0 ] ; then if [ ${result2} -ne 0 ] ; then
echo "Test failed for LANG=en_US.UTF-8" echo "Test failed for en_US.UTF-8 locale"
echo " LANG=\"${LANG}\""
echo " LC_ALL=\"${LC_ALL}\""
exit ${result2} exit ${result2}
fi fi
exit 0 exit 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册