[r12173]: rvmroot / trunk / testing / tests / jni / src / CriticalCopy.c  Maximize  Restore  History

Download this file

84 lines (64 with data), 2.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* This file is part of Jikes RVM (http://jikesrvm.sourceforge.net).
* The Jikes RVM project is distributed under the Common Public License (CPL).
* A copy of the license is included in the distribution, and is also
* available at http://www.opensource.org/licenses/cpl1.0.php
*
* (C) Copyright IBM Corp. 2001
*/
/* Test JNI Functions that access Java internal data directly
* Implement native methods from CriticalCopy.java
*/
#include "CriticalCopy.h"
int verbose=1;
/*
* Class: CriticalCopy
* Method: setVerboseOff
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_CriticalCopy_setVerboseOff
(JNIEnv *env, jclass cls) {
verbose=0;
}
/*
* Class: CriticalCopy
* Method: primitiveIntegerArray
* Signature: ([I)I
*/
JNIEXPORT jint JNICALL Java_CriticalCopy_primitiveIntegerArray
(JNIEnv *env, jclass cls, jintArray sourceArray) {
int i;
jint length;
jint *nativeArray;
jboolean copyFlag = JNI_TRUE;
length = (*env) -> GetArrayLength(env, sourceArray);
nativeArray = (*env) -> GetPrimitiveArrayCritical(env, sourceArray, &copyFlag);
/* check the flag to make sure we get direct access instead of a copy */
if (copyFlag==JNI_TRUE) {
printf(" > GetPrimitiveArrayCritical: expect to get a direct pointer, got a copy instead\n");
return -1;
}
if (verbose) {
printf("Array length is %d\n", length);
printf("Array address is %p\n", nativeArray);
printf("Current contents: \n");
for (i=0; i<length; i++) {
printf(" %d = %d\n", i, nativeArray[i]);
}
}
/* fill up the array with new values */
for (i=0; i<length; i++) {
nativeArray[i] = i;
}
(*env) -> ReleasePrimitiveArrayCritical(env, sourceArray, nativeArray, 0);
return 0;
}
/*
* Class: CriticalCopy
* Method: primitiveByteArray
* Signature: ([B)I
*/
JNIEXPORT jint JNICALL Java_CriticalCopy_primitiveByteArray
(JNIEnv *env, jclass cls, jbyteArray sourceArray) {
return 0;
}

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks