if (unsafe.compareAndSwapInt(t, intOffset, 0, 1)) {
System.out.println("Unexpectedly succeeding compareAndSwapInt(t, intOffset, 0, 1)");
} if (!unsafe.compareAndSwapInt(t, intOffset, intValue, 0)) {
System.out.println( "Unexpectedly not succeeding compareAndSwapInt(t, intOffset, intValue, 0)");
} if (!unsafe.compareAndSwapInt(t, intOffset, 0, 1)) {
System.out.println("Unexpectedly not succeeding compareAndSwapInt(t, intOffset, 0, 1)");
} // Exercise sun.misc.Unsafe.compareAndSwapInt using the same // integer (1) for the `expectedValue` and `newValue` arguments. if (!unsafe.compareAndSwapInt(t, intOffset, 1, 1)) {
System.out.println("Unexpectedly not succeeding compareAndSwapInt(t, intOffset, 1, 1)");
}
if (unsafe.compareAndSwapLong(t, longOffset, 0, 1)) {
System.out.println("Unexpectedly succeeding compareAndSwapLong(t, longOffset, 0, 1)");
} if (!unsafe.compareAndSwapLong(t, longOffset, longValue, 0)) {
System.out.println( "Unexpectedly not succeeding compareAndSwapLong(t, longOffset, longValue, 0)");
} if (!unsafe.compareAndSwapLong(t, longOffset, 0, 1)) {
System.out.println( "Unexpectedly not succeeding compareAndSwapLong(t, longOffset, 0, 1)");
} // Exercise sun.misc.Unsafe.compareAndSwapLong using the same // integer (1) for the `expectedValue` and `newValue` arguments. if (!unsafe.compareAndSwapLong(t, longOffset, 1, 1)) {
System.out.println( "Unexpectedly not succeeding compareAndSwapLong(t, longOffset, 1, 1)");
}
// We do not use `null` as argument to sun.misc.Unsafe.compareAndSwapObject // in those tests, as this value is not affected by heap poisoning // (which uses address negation to poison and unpoison heap object // references). This way, when heap poisoning is enabled, we can // better exercise its implementation within that method. if (unsafe.compareAndSwapObject(t, objectOffset, new Object(), new Object())) {
System.out.println("Unexpectedly succeeding " + "compareAndSwapObject(t, objectOffset, new Object(), new Object())");
}
Object objectValue2 = new Object(); if (!unsafe.compareAndSwapObject(t, objectOffset, objectValue, objectValue2)) {
System.out.println("Unexpectedly not succeeding " + "compareAndSwapObject(t, objectOffset, objectValue, objectValue2)");
}
Object objectValue3 = new Object(); if (!unsafe.compareAndSwapObject(t, objectOffset, objectValue2, objectValue3)) {
System.out.println("Unexpectedly not succeeding " + "compareAndSwapObject(t, objectOffset, objectValue2, objectValue3)");
} // Exercise sun.misc.Unsafe.compareAndSwapObject using the same // object (`objectValue3`) for the `expectedValue` and `newValue` arguments. if (!unsafe.compareAndSwapObject(t, objectOffset, objectValue3, objectValue3)) {
System.out.println("Unexpectedly not succeeding " + "compareAndSwapObject(t, objectOffset, objectValue3, objectValue3)");
} // Exercise sun.misc.Unsafe.compareAndSwapObject using the same // object (`t`) for the `obj` and `newValue` arguments. if (!unsafe.compareAndSwapObject(t, objectOffset, objectValue3, t)) {
System.out.println("Unexpectedly not succeeding " + "compareAndSwapObject(t, objectOffset, objectValue3, t)");
} // Exercise sun.misc.Unsafe.compareAndSwapObject using the same // object (`t`) for the `obj`, `expectedValue` and `newValue` arguments. if (!unsafe.compareAndSwapObject(t, objectOffset, t, t)) {
System.out.println("Unexpectedly not succeeding " + "compareAndSwapObject(t, objectOffset, t, t)");
} // Exercise sun.misc.Unsafe.compareAndSwapObject using the same // object (`t`) for the `obj` and `expectedValue` arguments. if (!unsafe.compareAndSwapObject(t, objectOffset, t, new Object())) {
System.out.println("Unexpectedly not succeeding " + "compareAndSwapObject(t, objectOffset, t, new Object())");
}
}
privatestaticvoid testGetAndPutVolatile(Unsafe unsafe) throws NoSuchFieldException {
TestVolatileClass tv = new TestVolatileClass();
// Regression test for "copyMemory" operations hitting a DCHECK() for float/double arrays. privatestaticvoid testCopyMemoryPrimitiveArrays(Unsafe unsafe) { int size = 4 * 1024; long memory = unsafeTestMalloc(size);
int floatSize = 4; float[] inputFloats = newfloat[size / floatSize]; for (int i = 0; i != inputFloats.length; ++i) {
inputFloats[i] = ((float)i) + 0.5f;
} float[] outputFloats = newfloat[size / floatSize];
unsafe.copyMemoryFromPrimitiveArray(inputFloats, 0, memory, size);
unsafe.copyMemoryToPrimitiveArray(memory, outputFloats, 0, size); for (int i = 0; i != inputFloats.length; ++i) {
check(inputFloats[i], outputFloats[i], "unsafe.copyMemory/float");
}
int doubleSize = 8; double[] inputDoubles = newdouble[size / doubleSize]; for (int i = 0; i != inputDoubles.length; ++i) {
inputDoubles[i] = ((double)i) + 0.5;
} double[] outputDoubles = newdouble[size / doubleSize];
unsafe.copyMemoryFromPrimitiveArray(inputDoubles, 0, memory, size);
unsafe.copyMemoryToPrimitiveArray(memory, outputDoubles, 0, size); for (int i = 0; i != inputDoubles.length; ++i) {
check(inputDoubles[i], outputDoubles[i], "unsafe.copyMemory/double");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.