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