test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress006.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 52952 837f1b8442be
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     1
/*
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     2
 * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     4
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     8
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    13
 * accompanied this code).
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    14
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    18
 *
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    21
 * questions.
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    22
 */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    23
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    24
#include <jni.h>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    25
#include <stdio.h>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    26
#include <stdlib.h>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    27
#include "jnihelper.h"
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    28
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    29
extern "C" {
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    30
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    31
JNIEXPORT jboolean JNICALL
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    32
Java_nsk_stress_jni_JNIter006_refs (JNIEnv *env, jobject jobj, jobject tobj, jint LIMIT) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    33
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    34
    static jobject *globRefsArray = 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    35
    static int upper = 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    36
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    37
    jclass clazz;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    38
    jmethodID jmethod;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    39
    jboolean res=JNI_FALSE;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    40
    const char *classname = "nsk/stress/jni/JNIter006";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    41
    const char *getmethodname="get_i";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    42
    const char *setmethodname="set_i";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    43
    const char *getsig="()I";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    44
    const char *setsig="(I)V";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    45
    const char *setdone = "halt";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    46
    const char *setdonesig = "()V";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    47
    int i = 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    48
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    49
    if (upper >= LIMIT) return JNI_TRUE;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    50
52952
837f1b8442be 8215160: Normalize spaces for remaining vmTestbase tests
jcbeyler
parents: 51774
diff changeset
    51
    if (upper == 0) {
837f1b8442be 8215160: Normalize spaces for remaining vmTestbase tests
jcbeyler
parents: 51774
diff changeset
    52
        globRefsArray=(jobject*)(malloc(LIMIT*sizeof(jobject)));
837f1b8442be 8215160: Normalize spaces for remaining vmTestbase tests
jcbeyler
parents: 51774
diff changeset
    53
    }
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    54
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    55
    globRefsArray[upper]=env->NewGlobalRef(tobj); CE
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    56
    if (env->IsSameObject(tobj, globRefsArray[upper])) {
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    57
    env->DeleteLocalRef(tobj); CE
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    58
    clazz=env->GetObjectClass(globRefsArray[upper]); CE
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    59
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    60
    else {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    61
    fprintf(stderr,"Objects are different\n");
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    62
    env->MonitorExit(jobj); CE
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    63
    return res;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    64
    }
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    65
    jmethod=env->GetStaticMethodID(clazz, setmethodname, setsig); CE
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    66
    env->CallStaticVoidMethod(clazz, jmethod, (jint)upper); CE
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    67
    env->MonitorEnter(jobj); CE
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    68
    ++upper;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    69
    res=JNI_TRUE;
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    70
    env->MonitorExit(jobj); CE
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    71
/* If upper == LIMIT than flush ref's array and set */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    72
/* 'done' flag in JNIter006 class to JNI_TRUE */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    73
    if (upper == LIMIT) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    74
    fprintf(stderr,"\n\tTotal memory allocated: %zd bytes\n",
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    75
        LIMIT*sizeof(jobject));
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    76
    clazz=env->FindClass(classname); CE
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    77
    jmethod=env->GetMethodID(clazz, setdone, setdonesig); CE
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    78
    env->CallVoidMethod(jobj, jmethod); CE
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    79
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    80
    for (i=0;i<LIMIT;i++) {
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    81
        env->DeleteGlobalRef(globRefsArray[i]); CE
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    82
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    83
        free(globRefsArray);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    84
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    85
    return res;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    86
}
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    87
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    88
}