test/hotspot/jtreg/gc/epsilon/libCriticalNative.c
changeset 52925 9c18c9d839d3
parent 52924 420ff459906f
child 52926 38bee05fb0e4
equal deleted inserted replaced
52924:420ff459906f 52925:9c18c9d839d3
     1 /*
       
     2  * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates.
       
     3  *
       
     4  * This code is free software; you can redistribute it and/or modify it
       
     5  * under the terms of the GNU General Public License version 2 only, as
       
     6  * published by the Free Software Foundation.
       
     7  *
       
     8  * This code is distributed in the hope that it will be useful, but WITHOUT
       
     9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    11  * version 2 for more details (a copy is included in the LICENSE file that
       
    12  * accompanied this code).
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License version
       
    15  * 2 along with this work; if not, write to the Free Software Foundation,
       
    16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    17  *
       
    18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    19  * or visit www.oracle.com if you need additional information or have any
       
    20  * questions.
       
    21  *
       
    22  */
       
    23 
       
    24 #include "jni.h"
       
    25 
       
    26 JNIEXPORT jlong JNICALL JavaCritical_CriticalNativeStress_sum1
       
    27   (jint length, jlong* a) {
       
    28   jlong sum = 0;
       
    29   jint index;
       
    30   for (index = 0; index < length; index ++) {
       
    31     sum += a[index];
       
    32   }
       
    33 
       
    34   return sum;
       
    35 }
       
    36 
       
    37 JNIEXPORT jlong JNICALL  JavaCritical_CriticalNativeStress_sum2
       
    38   (jlong a1, jint a2_length, jint* a2, jint a4_length, jint* a4, jint a6_length, jlong* a6, jint a8_length, jint* a8) {
       
    39   jlong sum = a1;
       
    40   jint index;
       
    41   for (index = 0; index < a2_length; index ++) {
       
    42     sum += a2[index];
       
    43   }
       
    44 
       
    45   for (index = 0; index < a4_length; index ++) {
       
    46     sum += a4[index];
       
    47   }
       
    48 
       
    49   for (index = 0; index < a6_length; index ++) {
       
    50     sum += a6[index];
       
    51   }
       
    52 
       
    53   for (index = 0; index < a8_length; index ++) {
       
    54     sum += a8[index];
       
    55   }
       
    56   return sum;
       
    57 }
       
    58 
       
    59 JNIEXPORT jlong JNICALL Java_CriticalNativeStress_sum1
       
    60   (JNIEnv *env, jclass jclazz, jlongArray a) {
       
    61   jlong sum = 0;
       
    62   jsize len = (*env)->GetArrayLength(env, a);
       
    63   jsize index;
       
    64   jlong* arr = (jlong*)(*env)->GetPrimitiveArrayCritical(env, a, 0);
       
    65   for (index = 0; index < len; index ++) {
       
    66     sum += arr[index];
       
    67   }
       
    68 
       
    69   (*env)->ReleasePrimitiveArrayCritical(env, a, arr, 0);
       
    70   return sum;
       
    71 }
       
    72 
       
    73 JNIEXPORT jlong JNICALL Java_CriticalNativeStress_sum2
       
    74   (JNIEnv *env, jclass jclazz, jlong a1, jintArray a2, jintArray a3, jlongArray a4, jintArray a5) {
       
    75   jlong sum = a1;
       
    76   jsize index;
       
    77   jsize len;
       
    78   jint* a2_arr;
       
    79   jint* a3_arr;
       
    80   jlong* a4_arr;
       
    81   jint* a5_arr;
       
    82 
       
    83   len = (*env)->GetArrayLength(env, a2);
       
    84   a2_arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a2, 0);
       
    85   for (index = 0; index < len; index ++) {
       
    86     sum += a2_arr[index];
       
    87   }
       
    88   (*env)->ReleasePrimitiveArrayCritical(env, a2, a2_arr, 0);
       
    89 
       
    90   len = (*env)->GetArrayLength(env, a3);
       
    91   a3_arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a3, 0);
       
    92   for (index = 0; index < len; index ++) {
       
    93     sum += a3_arr[index];
       
    94   }
       
    95   (*env)->ReleasePrimitiveArrayCritical(env, a3, a3_arr, 0);
       
    96 
       
    97   len = (*env)->GetArrayLength(env, a4);
       
    98   a4_arr = (jlong*)(*env)->GetPrimitiveArrayCritical(env, a4, 0);
       
    99   for (index = 0; index < len; index ++) {
       
   100     sum += a4_arr[index];
       
   101   }
       
   102   (*env)->ReleasePrimitiveArrayCritical(env, a4, a4_arr, 0);
       
   103 
       
   104   len = (*env)->GetArrayLength(env, a5);
       
   105   a5_arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a5, 0);
       
   106   for (index = 0; index < len; index ++) {
       
   107     sum += a5_arr[index];
       
   108   }
       
   109   (*env)->ReleasePrimitiveArrayCritical(env, a5, a5_arr, 0);
       
   110 
       
   111   return sum;
       
   112 }
       
   113 
       
   114 
       
   115 JNIEXPORT jboolean JNICALL JavaCritical_CriticalNativeArgs_isNull
       
   116   (jint length, jint* a) {
       
   117   return (a == NULL) && (length == 0);
       
   118 }
       
   119 
       
   120 JNIEXPORT jboolean JNICALL Java_CriticalNativeArgs_isNull
       
   121   (JNIEnv *env, jclass jclazz, jintArray a) {
       
   122   jboolean is_null;
       
   123   jsize len = (*env)->GetArrayLength(env, a);
       
   124   jint* arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a, 0);
       
   125   is_null = (arr == NULL) && (len == 0);
       
   126   (*env)->ReleasePrimitiveArrayCritical(env, a, arr, 0);
       
   127   return is_null;
       
   128 }
       
   129