1 | /* |
2 | * Copyright (c) 1996, 1998, Oracle and/or its affiliates. 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. Oracle designates this |
8 | * particular file as subject to the "Classpath" exception as provided |
9 | * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 | * or visit www.oracle.com if you need additional information or have any |
23 | * questions. |
24 | */ |
25 | |
26 | #include "jni.h" |
27 | #include "jvm.h" |
28 | #include "java_lang_reflect_Array.h" |
29 | |
30 | /* |
31 | * Native code for java.lang.reflect.Array. |
32 | * |
33 | * TODO: Performance |
34 | */ |
35 | |
36 | /* |
37 | * |
38 | */ |
39 | JNIEXPORT jint JNICALL |
40 | Java_java_lang_reflect_Array_getLength(JNIEnv *env, jclass ignore, jobject arr) |
41 | { |
42 | return JVM_GetArrayLength(env, arr); |
43 | } |
44 | |
45 | /* |
46 | * |
47 | */ |
48 | JNIEXPORT jobject JNICALL |
49 | Java_java_lang_reflect_Array_get(JNIEnv *env, jclass ignore, jobject arr, |
50 | jint index) |
51 | { |
52 | return JVM_GetArrayElement(env, arr, index); |
53 | } |
54 | |
55 | JNIEXPORT jboolean JNICALL |
56 | Java_java_lang_reflect_Array_getBoolean(JNIEnv *env, jclass ignore, jobject arr, |
57 | jint index) |
58 | { |
59 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_BOOLEAN).z; |
60 | } |
61 | |
62 | JNIEXPORT jbyte JNICALL |
63 | Java_java_lang_reflect_Array_getByte(JNIEnv *env, jclass ignore, jobject arr, |
64 | jint index) |
65 | { |
66 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_BYTE).b; |
67 | } |
68 | |
69 | JNIEXPORT jchar JNICALL |
70 | Java_java_lang_reflect_Array_getChar(JNIEnv *env, jclass ignore, jobject arr, |
71 | jint index) |
72 | { |
73 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_CHAR).c; |
74 | } |
75 | |
76 | JNIEXPORT jshort JNICALL |
77 | Java_java_lang_reflect_Array_getShort(JNIEnv *env, jclass ignore, jobject arr, |
78 | jint index) |
79 | { |
80 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_SHORT).s; |
81 | } |
82 | |
83 | JNIEXPORT jint JNICALL |
84 | Java_java_lang_reflect_Array_getInt(JNIEnv *env, jclass ignore, jobject arr, |
85 | jint index) |
86 | { |
87 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_INT).i; |
88 | } |
89 | |
90 | JNIEXPORT jlong JNICALL |
91 | Java_java_lang_reflect_Array_getLong(JNIEnv *env, jclass ignore, jobject arr, |
92 | jint index) |
93 | { |
94 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_LONG).j; |
95 | } |
96 | |
97 | JNIEXPORT jfloat JNICALL |
98 | Java_java_lang_reflect_Array_getFloat(JNIEnv *env, jclass ignore, jobject arr, |
99 | jint index) |
100 | { |
101 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_FLOAT).f; |
102 | } |
103 | |
104 | JNIEXPORT jdouble JNICALL |
105 | Java_java_lang_reflect_Array_getDouble(JNIEnv *env, jclass ignore, jobject arr, |
106 | jint index) |
107 | { |
108 | return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_DOUBLE).d; |
109 | } |
110 | |
111 | /* |
112 | * |
113 | */ |
114 | JNIEXPORT void JNICALL |
115 | Java_java_lang_reflect_Array_set(JNIEnv *env, jclass ignore, jobject arr, |
116 | jint index, jobject val) |
117 | { |
118 | JVM_SetArrayElement(env, arr, index, val); |
119 | } |
120 | |
121 | JNIEXPORT void JNICALL |
122 | Java_java_lang_reflect_Array_setBoolean(JNIEnv *env, jclass ignore, |
123 | jobject arr, jint index, jboolean z) |
124 | { |
125 | jvalue v; |
126 | v.z = z; |
127 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_BOOLEAN); |
128 | } |
129 | |
130 | JNIEXPORT void JNICALL |
131 | Java_java_lang_reflect_Array_setByte(JNIEnv *env, jclass ignore, |
132 | jobject arr, jint index, jbyte b) |
133 | { |
134 | jvalue v; |
135 | v.b = b; |
136 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_BYTE); |
137 | } |
138 | |
139 | JNIEXPORT void JNICALL |
140 | Java_java_lang_reflect_Array_setChar(JNIEnv *env, jclass ignore, |
141 | jobject arr, jint index, jchar c) |
142 | { |
143 | jvalue v; |
144 | v.c = c; |
145 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_CHAR); |
146 | } |
147 | |
148 | JNIEXPORT void JNICALL |
149 | Java_java_lang_reflect_Array_setShort(JNIEnv *env, jclass ignore, |
150 | jobject arr, jint index, jshort s) |
151 | { |
152 | jvalue v; |
153 | v.s = s; |
154 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_SHORT); |
155 | } |
156 | |
157 | JNIEXPORT void JNICALL |
158 | Java_java_lang_reflect_Array_setInt(JNIEnv *env, jclass ignore, |
159 | jobject arr, jint index, jint i) |
160 | { |
161 | jvalue v; |
162 | v.i = i; |
163 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_INT); |
164 | } |
165 | |
166 | JNIEXPORT void JNICALL |
167 | Java_java_lang_reflect_Array_setLong(JNIEnv *env, jclass ignore, |
168 | jobject arr, jint index, jlong j) |
169 | { |
170 | jvalue v; |
171 | v.j = j; |
172 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_LONG); |
173 | } |
174 | |
175 | JNIEXPORT void JNICALL |
176 | Java_java_lang_reflect_Array_setFloat(JNIEnv *env, jclass ignore, |
177 | jobject arr, jint index, jfloat f) |
178 | { |
179 | jvalue v; |
180 | v.f = f; |
181 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_FLOAT); |
182 | } |
183 | |
184 | JNIEXPORT void JNICALL |
185 | Java_java_lang_reflect_Array_setDouble(JNIEnv *env, jclass ignore, |
186 | jobject arr, jint index, jdouble d) |
187 | { |
188 | jvalue v; |
189 | v.d = d; |
190 | JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_DOUBLE); |
191 | } |
192 | |
193 | /* |
194 | * |
195 | */ |
196 | JNIEXPORT jobject JNICALL |
197 | Java_java_lang_reflect_Array_newArray(JNIEnv *env, jclass ignore, |
198 | jclass eltClass, jint length) |
199 | { |
200 | return JVM_NewArray(env, eltClass, length); |
201 | } |
202 | |
203 | JNIEXPORT jobject JNICALL |
204 | Java_java_lang_reflect_Array_multiNewArray(JNIEnv *env, jclass ignore, |
205 | jclass eltClass, jintArray dim) |
206 | { |
207 | return JVM_NewMultiArray(env, eltClass, dim); |
208 | } |
209 | |