test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.cpp
author iignatyev
Tue, 28 Aug 2018 14:37:34 -0700
changeset 51551 e409244ce72e
parent 50169 test/hotspot/jtreg/vmTestbase/nsk/stress/jni/libjnistress005.c@dd501973095c
child 51774 79dc492c00ab
permissions -rw-r--r--
8209611: use C++ compiler for hotspot tests Reviewed-by: vlivanov, ihse, erikj, jcbeyler
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
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    28
#ifdef __cplusplus
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
#endif
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    31
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    32
#define CHECK_EXCEPTION     { if (env->ExceptionOccurred()) { fprintf(stderr, "Unexpected exception:\n"); env->ExceptionDescribe(); env->ExceptionClear(); exit(97); } }
50169
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
JNIEXPORT void JNICALL
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    35
Java_nsk_stress_jni_JNIter005_except (JNIEnv *env, jobject jobj, jthrowable tobj) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    36
    jclass clazz;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    37
    static int Exceptcalls=0;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    38
    const char *name;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    39
    const char *mess;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    40
    jmethodID jmethod;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    41
    const char *iter = "nsk/stress/jni/JNIter005";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    42
//    const char *inc = "nsk/stress/jni/jnistress005/incCount";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    43
    const char *incSig = "()V";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    44
    const char *fldName = "counts";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    45
    const char *fldSig = "I";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    46
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    47
/*     incClazz = env->FindClass(iter); */
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    48
/*     CHECK_EXCEPTION */
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    49
/*     jmethod=env->GetStaticMethodID(incClazz, inc, incSig); */
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    50
/*     CHECK_EXCEPTION */
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    51
/*     env->CallStaticVoidMethod(incClazz, jmethod); */
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    52
/*     CHECK_EXCEPTION */
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    53
/*     jfld = env->GetFieldID(incClazz, fldName, fldSig); */
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    54
/*     printf("JNI: Count is %d\n", env->GetIntField(jobj, jfld)); */
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    55
/*     CHECK_EXCEPTION */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    56
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    57
    env->MonitorEnter(jobj);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    58
    CHECK_EXCEPTION
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    59
    if (!env->Throw(tobj)) {
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    60
    if(env->ExceptionOccurred())
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    61
        if (Exceptcalls%1000==0)
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    62
        fprintf(stderr, "NATIVE: Throw has been catched in native\n");
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    63
    env->ExceptionClear();
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    64
    ++Exceptcalls;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    65
    } else fprintf(stderr, "Throw failed\n");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    66
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    67
    env->MonitorExit(jobj);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    68
    CHECK_EXCEPTION
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    69
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    70
    switch (Exceptcalls%23) {
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    71
      case 0: name="java/lang/ArithmeticException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    72
      case 1: name="java/lang/ArrayIndexOutOfBoundsException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    73
      case 2: name="java/lang/ArrayStoreException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    74
      case 3: name="java/lang/ClassCastException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    75
      case 4: name="java/lang/ClassNotFoundException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    76
      case 5: name="java/lang/CloneNotSupportedException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    77
      case 6: name="java/lang/IllegalAccessException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    78
      case 7: name="java/lang/IllegalArgumentException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    79
      case 8: name="java/lang/IllegalMonitorStateException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    80
      case 9: name="java/lang/IllegalStateException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    81
      case 10: name="java/lang/IllegalThreadStateException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    82
      case 11: name="java/lang/IndexOutOfBoundsException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    83
      case 12: name="java/lang/InstantiationException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    84
      case 13: name="java/lang/InterruptedException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    85
      case 14: name="java/lang/NegativeArraySizeException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    86
      case 15: name="java/lang/NoSuchFieldException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    87
      case 16: name="java/lang/NoSuchMethodException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    88
      case 17: name="java/lang/NullPointerException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    89
      case 18: name="java/lang/NumberFormatException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    90
      case 19: name="java/lang/RuntimeException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    91
      case 20: name="java/lang/SecurityException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    92
      case 21: name="java/lang/StringIndexOutOfBoundsException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    93
      case 22: name="java/lang/UnsupportedOperationException"; break;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    94
      default: name="java/lang/Exception";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    95
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
    96
    mess=name;
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
    CHECK_EXCEPTION
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
    99
    clazz = env->FindClass(name);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   100
    CHECK_EXCEPTION
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   101
    if (env->ThrowNew(clazz, mess)) {
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   102
      const char *pass = "setpass";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   103
      const char *passSig = "(Z)V";
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   104
      jclass incClazz;
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   105
      fprintf(stderr, "ThrowNew failed\n");
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   106
      CHECK_EXCEPTION;
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   107
      incClazz = env->FindClass(iter);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   108
      CHECK_EXCEPTION;
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   109
      jmethod=env->GetStaticMethodID(incClazz, pass, passSig);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   110
      CHECK_EXCEPTION
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   111
      env->CallStaticVoidMethod(incClazz, jmethod, JNI_FALSE);
50169
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   112
      CHECK_EXCEPTION
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   113
    }
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   114
/*     printf("JNI: count %d\n", Exceptcalls); */
dd501973095c 8199271: [TESTBUG] open source VM testbase stress tests
lmesnik
parents:
diff changeset
   115
}
51551
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   116
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   117
#ifdef __cplusplus
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   118
}
e409244ce72e 8209611: use C++ compiler for hotspot tests
iignatyev
parents: 50169
diff changeset
   119
#endif