Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp
42283 views
/*1* Copyright (c) 2007, 2020, 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.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#include <jni.h>23#include <stdio.h>24#include <time.h>25#include "ExceptionCheckingJniEnv.hpp"26#include "jni_tools.h"2728extern "C" {2930static jfieldID objFieldId = NULL;3132/*33* Class: nsk_share_gc_lock_jni_IntArrayCriticalLocker34* Method: criticalNative35* Signature: ([Z)Z36*/37JNIEXPORT jint JNICALL Java_nsk_share_gc_lock_jni_IntArrayCriticalLocker_criticalNative38(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {39ExceptionCheckingJniEnvPtr ec_jni(jni_env);4041jsize size, i;42jintArray arr;43jint *pa;44jint hash = 0;45time_t start_time, current_time;4647if (objFieldId == NULL) {48jclass klass = ec_jni->GetObjectClass(o, TRACE_JNI_CALL);49objFieldId = ec_jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);50}51arr = (jintArray) ec_jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);52ec_jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);5354size = ec_jni->GetArrayLength(arr, TRACE_JNI_CALL);55start_time = time(NULL);56enterTime /= 1000;57current_time = 0;58while (difftime(current_time, start_time) < enterTime) {59hash = 0;60pa = (jint*) ec_jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);61if (pa != NULL) {62for (i = 0; i < size; ++i) {63hash ^= pa[i];64}65} else {66jni_env->FatalError("GetPrimitiveArrayCritical returned NULL");67}68mssleep((long) sleepTime);69ec_jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);70mssleep((long) sleepTime);71current_time = time(NULL);72}73ec_jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);74return hash;75}7677}787980