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