test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp
author jcbeyler
Tue, 23 Apr 2019 08:11:38 -0700
changeset 54599 f5657f30bb01
parent 52132 04d4f1e4aff2
child 54744 be7839b9493f
permissions -rw-r--r--
8213501: Deploy ExceptionJniWrapper for a few tests Summary: Add more tests to be using the wrapper Reviewed-by: phh, amenkov, sspitsyn, dholmes, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     1
/*
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
     2
 * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     4
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     8
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    14
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    18
 *
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    21
 * questions.
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    22
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    23
#include <jni.h>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    24
#include <stdio.h>
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    25
#include <time.h>
52132
04d4f1e4aff2 8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents: 51774
diff changeset
    26
#include "ExceptionCheckingJniEnv.hpp"
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    27
#include "jni_tools.h"
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    28
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 49934
diff changeset
    29
extern "C" {
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 49934
diff changeset
    30
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    31
static jfieldID objFieldId = NULL;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    32
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    33
/*
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    34
 * Class:     nsk_share_gc_lock_jni_FloatArrayCriticalLocker
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    35
 * Method:    criticalNative
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    36
 * Signature: ([Z)Z
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    37
 */
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    38
JNIEXPORT jfloat JNICALL Java_nsk_share_gc_lock_jni_FloatArrayCriticalLocker_criticalNative
52132
04d4f1e4aff2 8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents: 51774
diff changeset
    39
(JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    40
        ExceptionCheckingJniEnvPtr jni(jni_env);
52132
04d4f1e4aff2 8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents: 51774
diff changeset
    41
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    42
        jsize size, i;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    43
        jfloatArray arr;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    44
        jfloat *pa;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    45
        jfloat hash = 0;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    46
        time_t start_time, current_time;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    47
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    48
        if (objFieldId == NULL) {
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    49
                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    50
                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    51
        }
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    52
        arr = (jfloatArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    53
        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
52132
04d4f1e4aff2 8212083: Handle remaining gc/lock native code and fix two strings
jcbeyler
parents: 51774
diff changeset
    54
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    55
        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    56
        start_time = time(NULL);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    57
        enterTime /= 1000;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    58
        current_time = 0;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    59
        while (current_time - start_time < enterTime) {
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    60
                pa = (jfloat*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    61
                if (pa != NULL) {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    62
                        for (i = 0; i < size; ++i)
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    63
                                hash += pa[i];
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    64
                } else {
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    65
                        hash = 0;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    66
                }
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    67
                mssleep((long) sleepTime);
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    68
                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    69
                mssleep((long) sleepTime);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    70
                current_time = time(NULL);
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    71
        }
54599
f5657f30bb01 8213501: Deploy ExceptionJniWrapper for a few tests
jcbeyler
parents: 52132
diff changeset
    72
        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
49934
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    73
        return hash;
44839fbb20db 8199643: [TESTBUG] Open source common VM testbase code
iignatyev
parents:
diff changeset
    74
}
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 49934
diff changeset
    75
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 49934
diff changeset
    76
}