test/hotspot/jtreg/vmTestbase/nsk/stress/strace/strace005.cpp
author jcbeyler
Wed, 21 Nov 2018 10:46:45 -0800
changeset 52642 9cfc8b0c45fd
parent 51941 0f7d0bb6cfe2
permissions -rw-r--r--
8214149: Move out assignments when not using NSK*VERIFY macros Summary: Move out the assignments from ifs Reviewed-by: sspitsyn, cjplummer
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) 2003, 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 <stdio.h>
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    25
#include "nsk_strace.h"
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    26
#include "nsk_tools.h"
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    27
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    28
extern "C" {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    29
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    30
static const char *Stest_cn="nsk/stress/strace/strace005";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    31
static jclass stackOverflowErrorClass;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    32
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    33
JNIEXPORT jint JNICALL
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    34
JNI_OnLoad(JavaVM *vm, void *reserved)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    35
{
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    36
    JNIEnv *env;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    37
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    38
    if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) {
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    39
        printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    40
        return 0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    41
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    42
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    43
    FIND_CLASS(stackOverflowErrorClass, "java/lang/StackOverflowError");
52642
9cfc8b0c45fd 8214149: Move out assignments when not using NSK*VERIFY macros
jcbeyler
parents: 51941
diff changeset
    44
    stackOverflowErrorClass = (jclass) env->NewGlobalRef(stackOverflowErrorClass);
9cfc8b0c45fd 8214149: Move out assignments when not using NSK*VERIFY macros
jcbeyler
parents: 51941
diff changeset
    45
    if (stackOverflowErrorClass == NULL) {
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    46
        printf("Can't create global ref for stack overflow class\n");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    47
        return 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
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    50
    return JNI_VERSION;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    51
}
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    52
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    53
JNIEXPORT void JNICALL
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    54
JNI_OnUnload(JavaVM *vm, void *reserved)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    55
{
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    56
    JNIEnv *env;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    57
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    58
    if (vm->GetEnv((void **) &env, JNI_VERSION) != JNI_OK) {
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    59
        if (stackOverflowErrorClass != NULL) {
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    60
            env->DeleteGlobalRef(stackOverflowErrorClass);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    61
        }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    62
    } else {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    63
        printf("%s:%d: Failed to call GetEnv\n", __FILE__, __LINE__);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    64
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    65
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    66
}
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    67
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    68
JNIEXPORT void JNICALL
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    69
Java_nsk_stress_strace_strace005Thread_recursiveMethod2(JNIEnv *env, jobject obj)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    70
{
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    71
    jfieldID field;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    72
    jmethodID method;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    73
    jint currDepth;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    74
    jclass testClass, threadClass;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    75
    jint maxDepth;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    76
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    77
    FIND_CLASS(testClass, Stest_cn);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    78
    GET_OBJECT_CLASS(threadClass, obj);
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
    GET_STATIC_INT_FIELD(maxDepth, testClass, "DEPTH");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    81
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    82
    /* currDepth++ */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    83
    GET_INT_FIELD(currDepth, obj, threadClass, "currentDepth");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    84
    currDepth++;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    85
    SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    86
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    87
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    88
    if (maxDepth - currDepth > 0)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    89
    {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    90
        GET_STATIC_METHOD_ID(method, threadClass, "yield", "()V");
51941
0f7d0bb6cfe2 8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents: 51774
diff changeset
    91
        env->CallStaticVoidMethod(threadClass, method);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    92
        EXCEPTION_CHECK(stackOverflowErrorClass, currDepth);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    93
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    94
        GET_METHOD_ID(method, threadClass, "recursiveMethod1", "()V");
51941
0f7d0bb6cfe2 8211036: Remove the NSK_STUB macros from vmTestbase for non jvmti
jcbeyler
parents: 51774
diff changeset
    95
        env->CallVoidMethod(obj, method);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    96
        EXCEPTION_CHECK(stackOverflowErrorClass, currDepth);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    97
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    98
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    99
    currDepth--;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   100
    GET_OBJECT_CLASS(threadClass, obj);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   101
    SET_INT_FIELD(obj, threadClass, "currentDepth", currDepth);
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   102
}
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   103
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   104
}