# HG changeset patch
# User redestad
# Date 1459640750 -7200
# Sun Apr 03 01:45:50 2016 +0200
# Node ID 89c8b946a1bf33a960a77135dc5ef49877104137
# Parent 3c5f7bf20f6b0361b0aa2ab1a803442ac701bf4f
[mq]: bunsafe
diff --git a/src/java.base/share/classes/java/io/BufferedInputStream.java b/src/java.base/share/classes/java/io/BufferedInputStream.java
--- a/src/java.base/share/classes/java/io/BufferedInputStream.java
+++ b/src/java.base/share/classes/java/io/BufferedInputStream.java
@@ -24,7 +24,6 @@
*/
package java.io;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
/**
* A BufferedInputStream
adds
@@ -68,15 +67,22 @@
protected volatile byte buf[];
/**
- * Atomic updater to provide compareAndSet for buf. This is
- * necessary because closes can be asynchronous. We use nullness
+ * Get Unsafe and offset of buf to provide compareAndSet functionality.
+ * This is necessary because closes can be asynchronous. We use nullness
* of buf[] as primary indicator that this stream is closed. (The
* "in" field is also nulled out on close.)
*/
- private static final
- AtomicReferenceFieldUpdater bufUpdater =
- AtomicReferenceFieldUpdater.newUpdater
- (BufferedInputStream.class, byte[].class, "buf");
+ private static final jdk.internal.misc.Unsafe U =
+ jdk.internal.misc.Unsafe.getUnsafe();
+ private static final long BUF_OFFSET;
+ static {
+ try {
+ BUF_OFFSET = U.objectFieldOffset
+ (BufferedInputStream.class.getDeclaredField("buf"));
+ } catch (ReflectiveOperationException e) {
+ throw new Error(e);
+ }
+ }
/**
* The index one greater than the index of the last valid byte in
@@ -232,7 +238,7 @@
nsz = marklimit;
byte nbuf[] = new byte[nsz];
System.arraycopy(buffer, 0, nbuf, 0, pos);
- if (!bufUpdater.compareAndSet(this, buffer, nbuf)) {
+ if (!U.compareAndSwapObject(this, BUF_OFFSET, buffer, nbuf)) {
// Can't replace buf if there was an async close.
// Note: This would need to be changed if fill()
// is ever made accessible to multiple threads.
@@ -476,7 +482,7 @@
public void close() throws IOException {
byte[] buffer;
while ( (buffer = buf) != null) {
- if (bufUpdater.compareAndSet(this, buffer, null)) {
+ if (U.compareAndSwapObject(this, BUF_OFFSET, buffer, null)) {
InputStream input = in;
in = null;
if (input != null)