diff options
| author | Andy McFadden <fadden@android.com> | 2009-07-24 15:28:16 -0700 |
|---|---|---|
| committer | Andy McFadden <fadden@android.com> | 2009-07-24 15:28:16 -0700 |
| commit | bd8ecd863aa83df50d7ce8f5950d8645ab6356af (patch) | |
| tree | 516ff90b0b2ec80785701a6587078f50148f5add /nio | |
| parent | 7b9c3058da3321c57a052222cc3f8785d98caa3e (diff) | |
| download | libcore-bd8ecd863aa83df50d7ce8f5950d8645ab6356af.zip libcore-bd8ecd863aa83df50d7ce8f5950d8645ab6356af.tar.gz libcore-bd8ecd863aa83df50d7ce8f5950d8645ab6356af.tar.bz2 | |
JNI direct buffer function speedup, part 3.
This caches the effective address in a new field in the base Buffer
object. The first time something calls through one of the various
getEffectiveAddress calls, the value is set. (This seemed easier than
chasing down the constructors and factories, and also prevents bit rot
on the "slow path" in the VM.)
Diffstat (limited to 'nio')
9 files changed, 50 insertions, 8 deletions
diff --git a/nio/src/main/java/java/nio/Buffer.java b/nio/src/main/java/java/nio/Buffer.java index 9e870e4..19d8969 100644 --- a/nio/src/main/java/java/nio/Buffer.java +++ b/nio/src/main/java/java/nio/Buffer.java @@ -111,6 +111,16 @@ public abstract class Buffer { int _arrayOffset() { return 0; } + + /** + * For direct buffers, the effective address of the data. This is set + * on first use. If the field is zero, this is either not a direct + * buffer or the field has not been initialized, and you need to issue + * the getEffectiveAddress() call and use the result of that. + * + * This is strictly an optimization. + */ + int effectiveDirectAddress = 0; // END android-added /** diff --git a/nio/src/main/java/java/nio/CharToByteBufferAdapter.java b/nio/src/main/java/java/nio/CharToByteBufferAdapter.java index 14a48ff..bd340be 100644 --- a/nio/src/main/java/java/nio/CharToByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/CharToByteBufferAdapter.java @@ -65,7 +65,11 @@ final class CharToByteBufferAdapter extends CharBuffer implements DirectBuffer { public PlatformAddress getEffectiveAddress() { if (byteBuffer instanceof DirectBuffer) { - return ((DirectBuffer)byteBuffer).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } else { assert false : byteBuffer; return null; diff --git a/nio/src/main/java/java/nio/DirectByteBuffer.java b/nio/src/main/java/java/nio/DirectByteBuffer.java index 46529a5..dcdb3c1 100644 --- a/nio/src/main/java/java/nio/DirectByteBuffer.java +++ b/nio/src/main/java/java/nio/DirectByteBuffer.java @@ -247,7 +247,11 @@ abstract class DirectByteBuffer extends BaseByteBuffer implements DirectBuffer { * previously. */ public final PlatformAddress getEffectiveAddress() { - return getBaseAddress().offsetBytes(offset); + // BEGIN android-changed + PlatformAddress addr = getBaseAddress().offsetBytes(offset); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } /** diff --git a/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java b/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java index 336488b..70406ba 100644 --- a/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/DoubleToByteBufferAdapter.java @@ -65,7 +65,11 @@ final class DoubleToByteBufferAdapter extends DoubleBuffer implements DirectBuff public PlatformAddress getEffectiveAddress() { if (byteBuffer instanceof DirectBuffer) { - return ((DirectBuffer)byteBuffer).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } else { assert false : byteBuffer; return null; diff --git a/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java b/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java index 97c0528..75b9d84 100644 --- a/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/FloatToByteBufferAdapter.java @@ -65,7 +65,11 @@ final class FloatToByteBufferAdapter extends FloatBuffer implements DirectBuffer public PlatformAddress getEffectiveAddress() { if (byteBuffer instanceof DirectBuffer) { - return ((DirectBuffer)byteBuffer).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } else { assert false : byteBuffer; return null; diff --git a/nio/src/main/java/java/nio/IntToByteBufferAdapter.java b/nio/src/main/java/java/nio/IntToByteBufferAdapter.java index 91b9311..e77bec6 100644 --- a/nio/src/main/java/java/nio/IntToByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/IntToByteBufferAdapter.java @@ -65,7 +65,11 @@ final class IntToByteBufferAdapter extends IntBuffer implements DirectBuffer { public PlatformAddress getEffectiveAddress() { if (byteBuffer instanceof DirectBuffer) { - return ((DirectBuffer)byteBuffer).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } else { assert false : byteBuffer; return null; diff --git a/nio/src/main/java/java/nio/LongToByteBufferAdapter.java b/nio/src/main/java/java/nio/LongToByteBufferAdapter.java index 0bd3ce4..bcdeb2b 100644 --- a/nio/src/main/java/java/nio/LongToByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/LongToByteBufferAdapter.java @@ -65,7 +65,11 @@ final class LongToByteBufferAdapter extends LongBuffer implements DirectBuffer { public PlatformAddress getEffectiveAddress() { if (byteBuffer instanceof DirectBuffer) { - return ((DirectBuffer)byteBuffer).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } else { assert false : byteBuffer; return null; diff --git a/nio/src/main/java/java/nio/MappedByteBufferAdapter.java b/nio/src/main/java/java/nio/MappedByteBufferAdapter.java index 83a51c1..84866dc 100644 --- a/nio/src/main/java/java/nio/MappedByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/MappedByteBufferAdapter.java @@ -148,7 +148,11 @@ final class MappedByteBufferAdapter extends MappedByteBuffer implements DirectBu } public PlatformAddress getEffectiveAddress() { - return ((DirectBuffer) this.wrapped).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer) this.wrapped).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } public float getFloat() { diff --git a/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java b/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java index 41ce50c..a608bc9 100644 --- a/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java +++ b/nio/src/main/java/java/nio/ShortToByteBufferAdapter.java @@ -65,7 +65,11 @@ final class ShortToByteBufferAdapter extends ShortBuffer implements DirectBuffer public PlatformAddress getEffectiveAddress() { if (byteBuffer instanceof DirectBuffer) { - return ((DirectBuffer)byteBuffer).getEffectiveAddress(); + // BEGIN android-changed + PlatformAddress addr = ((DirectBuffer)byteBuffer).getEffectiveAddress(); + effectiveDirectAddress = addr.toInt(); + return addr; + // END android-changed } else { assert false : byteBuffer; return null; |
