Path: blob/master/src/java.base/share/native/libjava/Array.c
41149 views
/*1* Copyright (c) 1996, 1998, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni.h"26#include "jvm.h"27#include "java_lang_reflect_Array.h"2829/*30* Native code for java.lang.reflect.Array.31*32* TODO: Performance33*/3435/*36*37*/38JNIEXPORT jint JNICALL39Java_java_lang_reflect_Array_getLength(JNIEnv *env, jclass ignore, jobject arr)40{41return JVM_GetArrayLength(env, arr);42}4344/*45*46*/47JNIEXPORT jobject JNICALL48Java_java_lang_reflect_Array_get(JNIEnv *env, jclass ignore, jobject arr,49jint index)50{51return JVM_GetArrayElement(env, arr, index);52}5354JNIEXPORT jboolean JNICALL55Java_java_lang_reflect_Array_getBoolean(JNIEnv *env, jclass ignore, jobject arr,56jint index)57{58return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_BOOLEAN).z;59}6061JNIEXPORT jbyte JNICALL62Java_java_lang_reflect_Array_getByte(JNIEnv *env, jclass ignore, jobject arr,63jint index)64{65return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_BYTE).b;66}6768JNIEXPORT jchar JNICALL69Java_java_lang_reflect_Array_getChar(JNIEnv *env, jclass ignore, jobject arr,70jint index)71{72return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_CHAR).c;73}7475JNIEXPORT jshort JNICALL76Java_java_lang_reflect_Array_getShort(JNIEnv *env, jclass ignore, jobject arr,77jint index)78{79return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_SHORT).s;80}8182JNIEXPORT jint JNICALL83Java_java_lang_reflect_Array_getInt(JNIEnv *env, jclass ignore, jobject arr,84jint index)85{86return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_INT).i;87}8889JNIEXPORT jlong JNICALL90Java_java_lang_reflect_Array_getLong(JNIEnv *env, jclass ignore, jobject arr,91jint index)92{93return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_LONG).j;94}9596JNIEXPORT jfloat JNICALL97Java_java_lang_reflect_Array_getFloat(JNIEnv *env, jclass ignore, jobject arr,98jint index)99{100return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_FLOAT).f;101}102103JNIEXPORT jdouble JNICALL104Java_java_lang_reflect_Array_getDouble(JNIEnv *env, jclass ignore, jobject arr,105jint index)106{107return JVM_GetPrimitiveArrayElement(env, arr, index, JVM_T_DOUBLE).d;108}109110/*111*112*/113JNIEXPORT void JNICALL114Java_java_lang_reflect_Array_set(JNIEnv *env, jclass ignore, jobject arr,115jint index, jobject val)116{117JVM_SetArrayElement(env, arr, index, val);118}119120JNIEXPORT void JNICALL121Java_java_lang_reflect_Array_setBoolean(JNIEnv *env, jclass ignore,122jobject arr, jint index, jboolean z)123{124jvalue v;125v.z = z;126JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_BOOLEAN);127}128129JNIEXPORT void JNICALL130Java_java_lang_reflect_Array_setByte(JNIEnv *env, jclass ignore,131jobject arr, jint index, jbyte b)132{133jvalue v;134v.b = b;135JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_BYTE);136}137138JNIEXPORT void JNICALL139Java_java_lang_reflect_Array_setChar(JNIEnv *env, jclass ignore,140jobject arr, jint index, jchar c)141{142jvalue v;143v.c = c;144JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_CHAR);145}146147JNIEXPORT void JNICALL148Java_java_lang_reflect_Array_setShort(JNIEnv *env, jclass ignore,149jobject arr, jint index, jshort s)150{151jvalue v;152v.s = s;153JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_SHORT);154}155156JNIEXPORT void JNICALL157Java_java_lang_reflect_Array_setInt(JNIEnv *env, jclass ignore,158jobject arr, jint index, jint i)159{160jvalue v;161v.i = i;162JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_INT);163}164165JNIEXPORT void JNICALL166Java_java_lang_reflect_Array_setLong(JNIEnv *env, jclass ignore,167jobject arr, jint index, jlong j)168{169jvalue v;170v.j = j;171JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_LONG);172}173174JNIEXPORT void JNICALL175Java_java_lang_reflect_Array_setFloat(JNIEnv *env, jclass ignore,176jobject arr, jint index, jfloat f)177{178jvalue v;179v.f = f;180JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_FLOAT);181}182183JNIEXPORT void JNICALL184Java_java_lang_reflect_Array_setDouble(JNIEnv *env, jclass ignore,185jobject arr, jint index, jdouble d)186{187jvalue v;188v.d = d;189JVM_SetPrimitiveArrayElement(env, arr, index, v, JVM_T_DOUBLE);190}191192/*193*194*/195JNIEXPORT jobject JNICALL196Java_java_lang_reflect_Array_newArray(JNIEnv *env, jclass ignore,197jclass eltClass, jint length)198{199return JVM_NewArray(env, eltClass, length);200}201202JNIEXPORT jobject JNICALL203Java_java_lang_reflect_Array_multiNewArray(JNIEnv *env, jclass ignore,204jclass eltClass, jintArray dim)205{206return JVM_NewMultiArray(env, eltClass, dim);207}208209210