test/hotspot/jtreg/vmTestbase/nsk/monitoring/share/StackTraceController.c
changeset 49958 cc29d7717e3a
equal deleted inserted replaced
49957:746229cc1ab0 49958:cc29d7717e3a
       
     1 /*
       
     2  * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 #include <jni.h>
       
    25 #include <stdio.h>
       
    26 #include "jni_tools.h"
       
    27 
       
    28 #ifdef __cplusplus
       
    29 extern "C" {
       
    30 #endif
       
    31 
       
    32 #define GET_OBJECT_CLASS(_class, _obj)\
       
    33     if (!NSK_JNI_VERIFY(env, (_class = \
       
    34             NSK_CPP_STUB2(GetObjectClass, env, _obj)) != NULL))\
       
    35         return 2
       
    36 
       
    37 #define CALL_STATIC_VOID_NOPARAM(_class, _methodName)\
       
    38     GET_STATIC_METHOD_ID(method, _class, _methodName, "()V");\
       
    39     if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallStaticVoidMethod, env,\
       
    40                             _class, method)))\
       
    41         return 2
       
    42 
       
    43 #define GET_STATIC_METHOD_ID(_methodID, _class, _methodName, _sig)\
       
    44     if (!NSK_JNI_VERIFY(env, (_methodID = \
       
    45             NSK_CPP_STUB4(GetStaticMethodID, env, _class,\
       
    46                 _methodName, _sig)) != NULL))\
       
    47         return 2
       
    48 
       
    49 #define GET_METHOD_ID(_methodID, _class, _methodName, _sig)\
       
    50     if (!NSK_JNI_VERIFY(env, (_methodID = \
       
    51             NSK_CPP_STUB4(GetMethodID, env, _class,\
       
    52                 _methodName, _sig)) != NULL))\
       
    53         return 2
       
    54 
       
    55 #define CALL_VOID_NOPARAM(_obj, _class, _methodName)\
       
    56     GET_METHOD_ID(method, _class, _methodName, "()V");\
       
    57     if (!NSK_JNI_VERIFY_VOID(env, NSK_CPP_STUB3(CallVoidMethod, env, _obj,\
       
    58                                                     method)))\
       
    59         return 2
       
    60 
       
    61 JNIEXPORT jint JNICALL
       
    62 Java_nsk_monitoring_stress_thread_RunningThread_recursionNative(JNIEnv *env,
       
    63          jobject obj, jint maxDepth, jint currentDepth, jboolean returnToJava) {
       
    64     jmethodID method;
       
    65     jclass threadClass;
       
    66 
       
    67     GET_OBJECT_CLASS(threadClass, obj);
       
    68     currentDepth++;
       
    69 
       
    70     if (maxDepth > currentDepth) {
       
    71         CALL_STATIC_VOID_NOPARAM(threadClass, "yield");
       
    72 
       
    73         if (returnToJava) {
       
    74             GET_METHOD_ID(method, threadClass, "recursionJava", "(II)V");
       
    75             if (!NSK_JNI_VERIFY_VOID(env,
       
    76                                      NSK_CPP_STUB5(CallIntMethod, env, obj,
       
    77                                                    method, maxDepth,
       
    78                                                    currentDepth))) {
       
    79                 return 1;
       
    80             }
       
    81         } else {
       
    82             GET_METHOD_ID(method, threadClass, "recursionNative", "(IIZ)I");
       
    83             if (!NSK_JNI_VERIFY_VOID(env,
       
    84                                      NSK_CPP_STUB6(CallIntMethod, env, obj,
       
    85                                                    method, maxDepth,
       
    86                                                    currentDepth,
       
    87                                                    returnToJava))) {
       
    88                 return 1;
       
    89             }
       
    90         }
       
    91     }
       
    92     CALL_VOID_NOPARAM(obj, threadClass, "waitForSign");
       
    93     return 0;
       
    94 }
       
    95 
       
    96 #ifdef __cplusplus
       
    97 }
       
    98 #endif