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
18f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughespackage libcore.io;
19adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
207e25eff38a191d9c19e45093f4fde5102fb09d78Elliott Hughesimport java.io.FileDescriptor;
21adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectimport java.io.IOException;
220568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughesimport java.nio.ByteBuffer;
238510524dab13e0acc1babf22cbc55002fb122777Elliott Hughesimport java.nio.ByteOrder;
24adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
25adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/**
26f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes * Unsafe access to memory.
27adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */
28f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughespublic final class Memory {
29f934c3d2c8dd9e6bc5299cef41adace2a671637dElliott Hughes    private Memory() { }
30adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
31adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    /**
328fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes     * Used to optimize nio heap buffer bulk get operations. 'dst' must be a primitive array.
336944bea4a129dc2d4be687c72f2a9f228ec532bcElliott Hughes     * 'dstOffset' is measured in units of 'sizeofElements' bytes.
346944bea4a129dc2d4be687c72f2a9f228ec532bcElliott Hughes     */
358fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes    public static native void unsafeBulkGet(Object dst, int dstOffset, int byteCount,
366944bea4a129dc2d4be687c72f2a9f228ec532bcElliott Hughes            byte[] src, int srcOffset, int sizeofElements, boolean swap);
376944bea4a129dc2d4be687c72f2a9f228ec532bcElliott Hughes
386944bea4a129dc2d4be687c72f2a9f228ec532bcElliott Hughes    /**
398fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes     * Used to optimize nio heap buffer bulk put operations. 'src' must be a primitive array.
408fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes     * 'srcOffset' is measured in units of 'sizeofElements' bytes.
418fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes     */
428fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes    public static native void unsafeBulkPut(byte[] dst, int dstOffset, int byteCount,
438fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes            Object src, int srcOffset, int sizeofElements, boolean swap);
448fbc397fc09158bee0bc0cb231c609c4c6e9fc15Elliott Hughes
45af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    public static int peekInt(byte[] src, int offset, ByteOrder order) {
46af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        if (order == ByteOrder.BIG_ENDIAN) {
47af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            return (((src[offset++] & 0xff) << 24) |
48af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 16) |
49af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  8) |
50af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset  ] & 0xff) <<  0));
51af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        } else {
52af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            return (((src[offset++] & 0xff) <<  0) |
53af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  8) |
54af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 16) |
55af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset  ] & 0xff) << 24));
56af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        }
57af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    }
58af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes
59af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    public static long peekLong(byte[] src, int offset, ByteOrder order) {
60af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        if (order == ByteOrder.BIG_ENDIAN) {
61af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            int h = ((src[offset++] & 0xff) << 24) |
62af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 16) |
63af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  8) |
64af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  0);
65af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            int l = ((src[offset++] & 0xff) << 24) |
66af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 16) |
67af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  8) |
68af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset  ] & 0xff) <<  0);
69af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            return (((long) h) << 32L) | ((long) l) & 0xffffffffL;
70af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        } else {
71af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            int l = ((src[offset++] & 0xff) <<  0) |
72af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  8) |
73af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 16) |
74af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 24);
75af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            int h = ((src[offset++] & 0xff) <<  0) |
76af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) <<  8) |
77af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset++] & 0xff) << 16) |
78af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes                    ((src[offset  ] & 0xff) << 24);
79af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            return (((long) h) << 32L) | ((long) l) & 0xffffffffL;
80af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        }
81af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    }
82af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes
83af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    public static short peekShort(byte[] src, int offset, ByteOrder order) {
84af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        if (order == ByteOrder.BIG_ENDIAN) {
85af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            return (short) ((src[offset] << 8) | (src[offset + 1] & 0xff));
86af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        } else {
87af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            return (short) ((src[offset + 1] << 8) | (src[offset] & 0xff));
88af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        }
89af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    }
90af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes
91af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    public static void pokeInt(byte[] dst, int offset, int value, ByteOrder order) {
92af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        if (order == ByteOrder.BIG_ENDIAN) {
93af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >> 24) & 0xff);
94af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >> 16) & 0xff);
95af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >>  8) & 0xff);
96af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset  ] = (byte) ((value >>  0) & 0xff);
97af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        } else {
98af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >>  0) & 0xff);
99af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >>  8) & 0xff);
100af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >> 16) & 0xff);
101af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset  ] = (byte) ((value >> 24) & 0xff);
102af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        }
103af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    }
104af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes
105af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    public static void pokeLong(byte[] dst, int offset, long value, ByteOrder order) {
106af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        if (order == ByteOrder.BIG_ENDIAN) {
107af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            int i = (int) (value >> 32);
108af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 24) & 0xff);
109af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 16) & 0xff);
110af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  8) & 0xff);
111af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  0) & 0xff);
112af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            i = (int) value;
113af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 24) & 0xff);
114af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 16) & 0xff);
115af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  8) & 0xff);
116af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset  ] = (byte) ((i >>  0) & 0xff);
117af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        } else {
118af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            int i = (int) value;
119af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  0) & 0xff);
120af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  8) & 0xff);
121af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 16) & 0xff);
122af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 24) & 0xff);
123af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            i = (int) (value >> 32);
124af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  0) & 0xff);
125af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >>  8) & 0xff);
126af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((i >> 16) & 0xff);
127af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset  ] = (byte) ((i >> 24) & 0xff);
128af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        }
129af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    }
130af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes
131af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    public static void pokeShort(byte[] dst, int offset, short value, ByteOrder order) {
132af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        if (order == ByteOrder.BIG_ENDIAN) {
133af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >> 8) & 0xff);
134af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset  ] = (byte) ((value >> 0) & 0xff);
135af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        } else {
136af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset++] = (byte) ((value >> 0) & 0xff);
137af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes            dst[offset  ] = (byte) ((value >> 8) & 0xff);
138af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes        }
139af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes    }
140af301fb0e674665dae3e9cb94344558923ec8e0aElliott Hughes
1410568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes    /**
1420568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * Copies 'byteCount' bytes from the source to the destination. The objects are either
1430568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * instances of DirectByteBuffer or byte[]. The offsets in the byte[] case must include
1440568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * the Buffer.arrayOffset if the array came from a Buffer.array call. We could make this
1450568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * private and provide the four type-safe variants, but then ByteBuffer.put(ByteBuffer)
1460568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * would need to work out which to call based on whether the source and destination buffers
1470568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * are direct or not.
1480568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     *
1490568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     * @hide make type-safe before making public?
1500568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes     */
1510568a63ba1086a78ffb4cff68dd2eac4f9908e13Elliott Hughes    public static native void memmove(Object dstObject, int dstOffset, Object srcObject, int srcOffset, long byteCount);
152adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
1530121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native byte peekByte(long address);
154329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko
155329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    public static int peekInt(long address, boolean swap) {
156329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        int result = peekIntNative(address);
157329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        if (swap) {
158329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko            result = Integer.reverseBytes(result);
159329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        }
160329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        return result;
161329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    }
162329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    private static native int peekIntNative(long address);
163329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko
164329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    public static long peekLong(long address, boolean swap) {
165329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        long result = peekLongNative(address);
166329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        if (swap) {
167329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko            result = Long.reverseBytes(result);
168329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        }
169329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        return result;
170329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    }
171329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    private static native long peekLongNative(long address);
172329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko
173329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    public static short peekShort(long address, boolean swap) {
174329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        short result = peekShortNative(address);
175329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        if (swap) {
176329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko            result = Short.reverseBytes(result);
177329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        }
178329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        return result;
179329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    }
180329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    private static native short peekShortNative(long address);
1810121106d9dc1ba713b53822886355e4d9339e852Joel Dice
1820121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekByteArray(long address, byte[] dst, int dstOffset, int byteCount);
1830121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekCharArray(long address, char[] dst, int dstOffset, int charCount, boolean swap);
1840121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekDoubleArray(long address, double[] dst, int dstOffset, int doubleCount, boolean swap);
1850121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekFloatArray(long address, float[] dst, int dstOffset, int floatCount, boolean swap);
1860121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekIntArray(long address, int[] dst, int dstOffset, int intCount, boolean swap);
1870121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekLongArray(long address, long[] dst, int dstOffset, int longCount, boolean swap);
1880121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void peekShortArray(long address, short[] dst, int dstOffset, int shortCount, boolean swap);
1890121106d9dc1ba713b53822886355e4d9339e852Joel Dice
1900121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeByte(long address, byte value);
191329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko
192329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    public static void pokeInt(long address, int value, boolean swap) {
193329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        if (swap) {
194329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko            value = Integer.reverseBytes(value);
195329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        }
196329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        pokeIntNative(address, value);
197329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    }
198329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    private static native void pokeIntNative(long address, int value);
199329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko
200329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    public static void pokeLong(long address, long value, boolean swap) {
201329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        if (swap) {
202329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko            value = Long.reverseBytes(value);
203329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        }
204329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        pokeLongNative(address, value);
205329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    }
206329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    private static native void pokeLongNative(long address, long value);
207329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko
208329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    public static void pokeShort(long address, short value, boolean swap) {
209329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        if (swap) {
210329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko            value = Short.reverseBytes(value);
211329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        }
212329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko        pokeShortNative(address, value);
213329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    }
214329af9cb39b3cd325a6ac6d1bc906af8877eff9fVladimir Marko    private static native void pokeShortNative(long address, short value);
2150121106d9dc1ba713b53822886355e4d9339e852Joel Dice
2160121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeByteArray(long address, byte[] src, int offset, int count);
2170121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeCharArray(long address, char[] src, int offset, int count, boolean swap);
2180121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeDoubleArray(long address, double[] src, int offset, int count, boolean swap);
2190121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeFloatArray(long address, float[] src, int offset, int count, boolean swap);
2200121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeIntArray(long address, int[] src, int offset, int count, boolean swap);
2210121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeLongArray(long address, long[] src, int offset, int count, boolean swap);
2220121106d9dc1ba713b53822886355e4d9339e852Joel Dice    public static native void pokeShortArray(long address, short[] src, int offset, int count, boolean swap);
223adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project}
224