1adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/*
2adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  Licensed to the Apache Software Foundation (ASF) under one or more
3adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  contributor license agreements.  See the NOTICE file distributed with
4adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  this work for additional information regarding copyright ownership.
5adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  The ASF licenses this file to You under the Apache License, Version 2.0
6adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  (the "License"); you may not use this file except in compliance with
7adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  the License.  You may obtain a copy of the License at
8adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
9adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *     http://www.apache.org/licenses/LICENSE-2.0
10adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
11adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
12adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
13adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  See the License for the specific language governing permissions and
15adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  limitations under the License.
16adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */
17adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
18c73a5be50cdd804ff3c12e7b43da08c33cdd6f21Elliott Hughespackage java.nio;
19adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
203676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughesimport dalvik.system.VMRuntime;
217e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughesimport java.io.FileDescriptor;
22040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughesimport java.io.IOException;
23040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughesimport java.nio.channels.FileChannel.MapMode;
247e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughesimport libcore.io.ErrnoException;
257e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughesimport libcore.io.Libcore;
26f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughesimport libcore.io.Memory;
277e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughesimport static libcore.io.OsConstants.*;
288510524dab13e0acc1babf22cbc55002fb122777Elliott Hughes
29ae704b984c10a63883cc366e823d53902d6ac7a9Elliott Hughesclass MemoryBlock {
30040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    /**
31040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes     * Handles calling munmap(2) on a memory-mapped region.
32040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes     */
33eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes    private static class MemoryMappedBlock extends MemoryBlock {
34040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        private MemoryMappedBlock(int address, long byteCount) {
35040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes            super(address, byteCount);
36040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
37040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
38040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        @Override public void free() {
39c73a5be50cdd804ff3c12e7b43da08c33cdd6f21Elliott Hughes            if (address != 0) {
407e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                try {
417e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                    Libcore.os.munmap(address, size);
427e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                } catch (ErrnoException errnoException) {
437e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                    // The RI doesn't throw, presumably on the assumption that you can't get into
447e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                    // a state where munmap(2) could return an error.
457e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                    throw new AssertionError(errnoException);
467e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes                }
47c73a5be50cdd804ff3c12e7b43da08c33cdd6f21Elliott Hughes                address = 0;
48040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes            }
49040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
50040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
51040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        @Override protected void finalize() throws Throwable {
52040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes            free();
53040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
54040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    }
55040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
56040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    /**
573676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes     * Non-movable heap blocks are byte arrays on the Java heap that the GC
583676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes     * guarantees not to move. Used to implement DirectByteBuffer.
593676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes     *
603676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes     * Losing the strong reference to the array is sufficient
613676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes     * to allow the GC to reclaim the storage. No finalizer needed.
62040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes     */
633676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes    private static class NonMovableHeapBlock extends MemoryBlock {
643676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes        private byte[] array;
653676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes
663676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes        private NonMovableHeapBlock(byte[] array, int address, long byteCount) {
67040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes            super(address, byteCount);
683676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes            this.array = array;
69040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
70040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
7138f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes        @Override public byte[] array() {
7238f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes            return array;
7338f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes        }
7438f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes
75040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        @Override public void free() {
763676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes            array = null;
773676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes            address = 0;
78040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
79040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    }
80040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
81040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    /**
82040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes     * Represents a block of memory we don't own. (We don't take ownership of memory corresponding
83040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes     * to direct buffers created by the JNI NewDirectByteBuffer function.)
84040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes     */
85eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes    private static class UnmanagedBlock extends MemoryBlock {
86040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        private UnmanagedBlock(int address, long byteCount) {
87040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes            super(address, byteCount);
88040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
89040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    }
90040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
914d68282a79fb0417f43efdef41b9a920385bddedElliott Hughes    // TODO: should be long on 64-bit devices; int for performance.
92c73a5be50cdd804ff3c12e7b43da08c33cdd6f21Elliott Hughes    protected int address;
934d68282a79fb0417f43efdef41b9a920385bddedElliott Hughes    protected final long size;
94f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes
957e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes    public static MemoryBlock mmap(FileDescriptor fd, long offset, long size, MapMode mapMode) throws IOException {
96040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        if (size == 0) {
977e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            // You can't mmap(2) a zero-length region, but Java allows it.
98eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes            return new MemoryBlock(0, 0);
99040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        }
1007e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        // Check just those errors mmap(2) won't detect.
1017e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        if (offset < 0 || size < 0 || offset > Integer.MAX_VALUE || size > Integer.MAX_VALUE) {
1027e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            throw new IllegalArgumentException("offset=" + offset + " size=" + size);
1037e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        }
1047e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        int prot;
1057e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        int flags;
1067e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        if (mapMode == MapMode.PRIVATE) {
1077e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            prot = PROT_READ|PROT_WRITE;
1087e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            flags = MAP_PRIVATE;
1097e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        } else if (mapMode == MapMode.READ_ONLY) {
1107e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            prot = PROT_READ;
1117e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            flags = MAP_SHARED;
1127e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        } else { // mapMode == MapMode.READ_WRITE
1137e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            prot = PROT_READ|PROT_WRITE;
1147e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            flags = MAP_SHARED;
1157e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        }
1167e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        try {
1177e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            int address = (int) Libcore.os.mmap(0L, size, prot, flags, fd, offset);
1187e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            return new MemoryMappedBlock(address, size);
1197e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        } catch (ErrnoException errnoException) {
1207e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes            throw errnoException.rethrowAsIOException();
1217e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughes        }
122040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    }
123040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
12427c11c7c7b1fc023cb6464bd551aceef300e39b6Elliott Hughes    public static MemoryBlock allocate(int byteCount) {
1253676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes        VMRuntime runtime = VMRuntime.getRuntime();
1263676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes        byte[] array = (byte[]) runtime.newNonMovableArray(byte.class, byteCount);
1273676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes        int address = (int) runtime.addressOf(array);
1283676bd288bce270a51b1c51f1052b76e83e71412Elliott Hughes        return new NonMovableHeapBlock(array, address, byteCount);
129040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    }
130040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
131eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes    public static MemoryBlock wrapFromJni(int address, long byteCount) {
132040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes        return new UnmanagedBlock(address, byteCount);
133040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes    }
134040bb9d72f4a406a40f40e198857a8a27e3de688Elliott Hughes
135eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes    private MemoryBlock(int address, long size) {
136c73a5be50cdd804ff3c12e7b43da08c33cdd6f21Elliott Hughes        this.address = address;
137adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        this.size = size;
138adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
139adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
14038f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes    // Used to support array/arrayOffset/hasArray for direct buffers.
14138f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes    public byte[] array() {
14238f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes        return null;
14338f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes    }
14438f919c84cc2714ae2564ea1a04e2ced9c5aad04Elliott Hughes
145adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public void free() {
146adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
147adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
1486116e6265924a0983bb462e3441c8c4a0bb7e47eElliott Hughes    public final void pokeByte(int offset, byte value) {
149f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeByte(address + offset, value);
150adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
151adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
152692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeByteArray(int offset, byte[] src, int srcOffset, int byteCount) {
153f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeByteArray(address + offset, src, srcOffset, byteCount);
154adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
155f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes
156692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeCharArray(int offset, char[] src, int srcOffset, int charCount, boolean swap) {
157f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeCharArray(address + offset, src, srcOffset, charCount, swap);
158adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
159adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
160692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeDoubleArray(int offset, double[] src, int srcOffset, int doubleCount, boolean swap) {
161f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeDoubleArray(address + offset, src, srcOffset, doubleCount, swap);
162adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
163bfb0099cc4c8eca744eeda0f20e5b3644f1a4cb9Owen Lin
164692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeFloatArray(int offset, float[] src, int srcOffset, int floatCount, boolean swap) {
165f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeFloatArray(address + offset, src, srcOffset, floatCount, swap);
166692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    }
167692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes
168692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeIntArray(int offset, int[] src, int srcOffset, int intCount, boolean swap) {
169f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeIntArray(address + offset, src, srcOffset, intCount, swap);
170692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    }
171692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes
172692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeLongArray(int offset, long[] src, int srcOffset, int longCount, boolean swap) {
173f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeLongArray(address + offset, src, srcOffset, longCount, swap);
174692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    }
175692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes
176692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void pokeShortArray(int offset, short[] src, int srcOffset, int shortCount, boolean swap) {
177f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeShortArray(address + offset, src, srcOffset, shortCount, swap);
178bfb0099cc4c8eca744eeda0f20e5b3644f1a4cb9Owen Lin    }
179adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
1801b9018762e87e3dda69020248817011efd5a40dcElliott Hughes    public final byte peekByte(int offset) {
181f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        return Memory.peekByte(address + offset);
182adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
183adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
184692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void peekByteArray(int offset, byte[] dst, int dstOffset, int byteCount) {
185f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekByteArray(address + offset, dst, dstOffset, byteCount);
186692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    }
187692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes
188961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    public final void peekCharArray(int offset, char[] dst, int dstOffset, int charCount, boolean swap) {
189f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekCharArray(address + offset, dst, dstOffset, charCount, swap);
190961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
191961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
192961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    public final void peekDoubleArray(int offset, double[] dst, int dstOffset, int doubleCount, boolean swap) {
193f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekDoubleArray(address + offset, dst, dstOffset, doubleCount, swap);
194961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
195961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
196961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    public final void peekFloatArray(int offset, float[] dst, int dstOffset, int floatCount, boolean swap) {
197f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekFloatArray(address + offset, dst, dstOffset, floatCount, swap);
198961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
199961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
200692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    public final void peekIntArray(int offset, int[] dst, int dstOffset, int intCount, boolean swap) {
201f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekIntArray(address + offset, dst, dstOffset, intCount, swap);
202adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
203adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
204961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    public final void peekLongArray(int offset, long[] dst, int dstOffset, int longCount, boolean swap) {
205f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekLongArray(address + offset, dst, dstOffset, longCount, swap);
206961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
207961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
208961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    public final void peekShortArray(int offset, short[] dst, int dstOffset, int shortCount, boolean swap) {
209f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.peekShortArray(address + offset, dst, dstOffset, shortCount, swap);
210961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
211961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
2126116e6265924a0983bb462e3441c8c4a0bb7e47eElliott Hughes    public final void pokeShort(int offset, short value, ByteOrder order) {
213f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeShort(address + offset, value, order.needsSwap);
214adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
215adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
2161b9018762e87e3dda69020248817011efd5a40dcElliott Hughes    public final short peekShort(int offset, ByteOrder order) {
217f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        return Memory.peekShort(address + offset, order.needsSwap);
218adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
219adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
2206116e6265924a0983bb462e3441c8c4a0bb7e47eElliott Hughes    public final void pokeInt(int offset, int value, ByteOrder order) {
221f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeInt(address + offset, value, order.needsSwap);
222adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
223adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
2241b9018762e87e3dda69020248817011efd5a40dcElliott Hughes    public final int peekInt(int offset, ByteOrder order) {
225f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        return Memory.peekInt(address + offset, order.needsSwap);
226adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
227adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
2286116e6265924a0983bb462e3441c8c4a0bb7e47eElliott Hughes    public final void pokeLong(int offset, long value, ByteOrder order) {
229f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        Memory.pokeLong(address + offset, value, order.needsSwap);
230adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
231adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
2321b9018762e87e3dda69020248817011efd5a40dcElliott Hughes    public final long peekLong(int offset, ByteOrder order) {
233f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes        return Memory.peekLong(address + offset, order.needsSwap);
234adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
235adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
236adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final int toInt() {
237c73a5be50cdd804ff3c12e7b43da08c33cdd6f21Elliott Hughes        return address;
238adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
239adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
240adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final String toString() {
241eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        return getClass().getName() + "[" + address + "]";
242adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
243f33eae7e84eb6d3b0f4e86b59605bb3de73009f3Elliott Hughes
2445839b909d9528b7726e678a4b696ed37df15d897Jesse Wilson    public final long getSize() {
245adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return size;
246adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
247adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project}
248