jdk/src/share/native/java/nio/Bits.c
author alanb
Sun, 31 Aug 2008 18:32:59 +0100
changeset 1151 4070cecdb99d
parent 895 67f1dc69ad10
child 1247 b4c26443dee5
permissions -rw-r--r--
6570619: (bf) DirectByteBuffer.get/put(byte[]) does not scale well Reviewed-by: iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2003 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * WARNING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * Do not replace instances of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *   if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *     size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *   else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *     size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *   size = (length > MBYTE ? MBYTE : length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This expression causes a c compiler assertion failure when compiling on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * 32-bit sparc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
#define MBYTE 1048576
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
#define GETCRITICAL(bytes, env, obj) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    bytes = (*env)->GetPrimitiveArrayCritical(env, obj, NULL); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    if (bytes == NULL) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        JNU_ThrowInternalError(env, "Unable to get array"); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#define RELEASECRITICAL(bytes, env, obj, mode) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    (*env)->ReleasePrimitiveArrayCritical(env, obj, bytes, mode); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#define SWAPSHORT(x) ((jshort)(((x) << 8) | (((x) >> 8) & 0xff)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define SWAPINT(x)   ((jint)((SWAPSHORT((jshort)(x)) << 16) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                            (SWAPSHORT((jshort)((x) >> 16)) & 0xffff)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
#define SWAPLONG(x)  ((jlong)(((jlong)SWAPINT((jint)(x)) << 32) | \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                              ((jlong)SWAPINT((jint)((x) >> 32)) & 0xffffffff)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
Java_java_nio_Bits_copyFromShortArray(JNIEnv *env, jobject this, jobject src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                      jlong srcPos, jlong dstAddr, jlong length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    jbyte *bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    size_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    jshort *srcShort, *dstShort, *endShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    jshort tmpShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
    79
    dstShort = (jshort *)jlong_to_ptr(dstAddr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    while (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        /* do not change this if-else statement, see WARNING above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        GETCRITICAL(bytes, env, src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        srcShort = (jshort *)(bytes + srcPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        endShort = srcShort + (size / sizeof(jshort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        while (srcShort < endShort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
          tmpShort = *srcShort++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
          *dstShort++ = SWAPSHORT(tmpShort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        RELEASECRITICAL(bytes, env, src, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        length -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        dstAddr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        srcPos += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
Java_java_nio_Bits_copyToShortArray(JNIEnv *env, jobject this, jlong srcAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                                    jobject dst, jlong dstPos, jlong length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    jbyte *bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    size_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    jshort *srcShort, *dstShort, *endShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    jshort tmpShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   114
    srcShort = (jshort *)jlong_to_ptr(srcAddr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    while (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /* do not change this if-else statement, see WARNING above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        GETCRITICAL(bytes, env, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        dstShort = (jshort *)(bytes + dstPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        endShort = srcShort + (size / sizeof(jshort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        while (srcShort < endShort) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            tmpShort = *srcShort++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            *dstShort++ = SWAPSHORT(tmpShort);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        RELEASECRITICAL(bytes, env, dst, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        length -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        srcAddr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        dstPos += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
Java_java_nio_Bits_copyFromIntArray(JNIEnv *env, jobject this, jobject src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                                    jlong srcPos, jlong dstAddr, jlong length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    jbyte *bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    size_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    jint *srcInt, *dstInt, *endInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    jint tmpInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   149
    dstInt = (jint *)jlong_to_ptr(dstAddr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    while (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        /* do not change this code, see WARNING above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        GETCRITICAL(bytes, env, src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        srcInt = (jint *)(bytes + srcPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        endInt = srcInt + (size / sizeof(jint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        while (srcInt < endInt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            tmpInt = *srcInt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            *dstInt++ = SWAPINT(tmpInt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        RELEASECRITICAL(bytes, env, src, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        length -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        dstAddr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        srcPos += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
Java_java_nio_Bits_copyToIntArray(JNIEnv *env, jobject this, jlong srcAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                  jobject dst, jlong dstPos, jlong length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    jbyte *bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    size_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    jint *srcInt, *dstInt, *endInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    jint tmpInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   184
    srcInt = (jint *)jlong_to_ptr(srcAddr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    while (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        /* do not change this code, see WARNING above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        GETCRITICAL(bytes, env, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        dstInt = (jint *)(bytes + dstPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        endInt = srcInt + (size / sizeof(jint));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        while (srcInt < endInt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            tmpInt = *srcInt++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            *dstInt++ = SWAPINT(tmpInt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        RELEASECRITICAL(bytes, env, dst, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        length -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        srcAddr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        dstPos += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
Java_java_nio_Bits_copyFromLongArray(JNIEnv *env, jobject this, jobject src,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                                     jlong srcPos, jlong dstAddr, jlong length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    jbyte *bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    size_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    jlong *srcLong, *dstLong, *endLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    jlong tmpLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   219
    dstLong = (jlong *)jlong_to_ptr(dstAddr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    while (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        /* do not change this code, see WARNING above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        GETCRITICAL(bytes, env, src);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        srcLong = (jlong *)(bytes + srcPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        endLong = srcLong + (size / sizeof(jlong));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        while (srcLong < endLong) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            tmpLong = *srcLong++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            *dstLong++ = SWAPLONG(tmpLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        RELEASECRITICAL(bytes, env, src, JNI_ABORT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        length -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        dstAddr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        srcPos += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
Java_java_nio_Bits_copyToLongArray(JNIEnv *env, jobject this, jlong srcAddr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                   jobject dst, jlong dstPos, jlong length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    jbyte *bytes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    size_t i, size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    jlong *srcLong, *dstLong, *endLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    jlong tmpLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   254
    srcLong = (jlong *)jlong_to_ptr(srcAddr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    while (length > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /* do not change this code, see WARNING above */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (length > MBYTE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            size = MBYTE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            size = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        GETCRITICAL(bytes, env, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        dstLong = (jlong *)(bytes + dstPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        endLong = srcLong + (size / sizeof(jlong));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        while (srcLong < endLong) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            tmpLong = *srcLong++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            *dstLong++ = SWAPLONG(tmpLong);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        RELEASECRITICAL(bytes, env, dst, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        length -= size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        srcAddr += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        dstPos += size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
}