Path: blob/master/test/hotspot/jtreg/gc/libCriticalNative.c
40930 views
/*1* Copyright (c) 2018, Red Hat, Inc. and/or its affiliates.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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "jni.h"2526JNIEXPORT jlong JNICALL JavaCritical_gc_CriticalNative_sum127(jint length, jlong* a) {28jlong sum = 0;29jint index;30for (index = 0; index < length; index ++) {31sum += a[index];32}3334return sum;35}3637JNIEXPORT jlong JNICALL JavaCritical_gc_CriticalNative_sum238(jlong a1, jint a2_length, jint* a2, jint a4_length, jint* a4, jint a6_length, jlong* a6, jint a8_length, jint* a8) {39jlong sum = a1;40jint index;41for (index = 0; index < a2_length; index ++) {42sum += a2[index];43}4445for (index = 0; index < a4_length; index ++) {46sum += a4[index];47}4849for (index = 0; index < a6_length; index ++) {50sum += a6[index];51}5253for (index = 0; index < a8_length; index ++) {54sum += a8[index];55}56return sum;57}5859JNIEXPORT jlong JNICALL Java_gc_CriticalNative_sum160(JNIEnv *env, jclass jclazz, jlongArray a) {61jlong sum = 0;62jsize len = (*env)->GetArrayLength(env, a);63jsize index;64jlong* arr = (jlong*)(*env)->GetPrimitiveArrayCritical(env, a, 0);65for (index = 0; index < len; index ++) {66sum += arr[index];67}6869(*env)->ReleasePrimitiveArrayCritical(env, a, arr, 0);70return sum;71}7273JNIEXPORT jlong JNICALL Java_gc_CriticalNative_sum274(JNIEnv *env, jclass jclazz, jlong a1, jintArray a2, jintArray a3, jlongArray a4, jintArray a5) {75jlong sum = a1;76jsize index;77jsize len;78jint* a2_arr;79jint* a3_arr;80jlong* a4_arr;81jint* a5_arr;8283len = (*env)->GetArrayLength(env, a2);84a2_arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a2, 0);85for (index = 0; index < len; index ++) {86sum += a2_arr[index];87}88(*env)->ReleasePrimitiveArrayCritical(env, a2, a2_arr, 0);8990len = (*env)->GetArrayLength(env, a3);91a3_arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a3, 0);92for (index = 0; index < len; index ++) {93sum += a3_arr[index];94}95(*env)->ReleasePrimitiveArrayCritical(env, a3, a3_arr, 0);9697len = (*env)->GetArrayLength(env, a4);98a4_arr = (jlong*)(*env)->GetPrimitiveArrayCritical(env, a4, 0);99for (index = 0; index < len; index ++) {100sum += a4_arr[index];101}102(*env)->ReleasePrimitiveArrayCritical(env, a4, a4_arr, 0);103104len = (*env)->GetArrayLength(env, a5);105a5_arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a5, 0);106for (index = 0; index < len; index ++) {107sum += a5_arr[index];108}109(*env)->ReleasePrimitiveArrayCritical(env, a5, a5_arr, 0);110111return sum;112}113114115JNIEXPORT jboolean JNICALL JavaCritical_gc_CriticalNative_isNull116(jint length, jint* a) {117return (a == NULL) && (length == 0);118}119120JNIEXPORT jboolean JNICALL Java_gc_CriticalNative_isNull121(JNIEnv *env, jclass jclazz, jintArray a) {122if (a == NULL) return JNI_TRUE;123jsize len = (*env)->GetArrayLength(env, a);124jint* arr = (jint*)(*env)->GetPrimitiveArrayCritical(env, a, 0);125jboolean is_null = (arr == NULL) && (len == 0);126(*env)->ReleasePrimitiveArrayCritical(env, a, arr, 0);127return is_null;128}129130131132