changeset 55952:f5657f30bb01

8213501: Deploy ExceptionJniWrapper for a few tests Summary: Add more tests to be using the wrapper Reviewed-by: phh, amenkov, sspitsyn, dholmes, cjplummer
author jcbeyler
date Tue, 23 Apr 2019 08:11:38 -0700
parents a9953a8ccd66
children 69cfd80f8706
files make/test/JtregNativeHotspot.gmk test/hotspot/jtreg/TEST.groups test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.cpp test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.hpp
diffstat 27 files changed, 561 insertions(+), 342 deletions(-) [+]
line wrap: on
line diff
--- a/make/test/JtregNativeHotspot.gmk	Tue Apr 23 16:50:17 2019 +0200
+++ b/make/test/JtregNativeHotspot.gmk	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -736,6 +736,7 @@
 BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libdisposeenv002 := $(NSK_JVMTI_AGENT_INCLUDES)
 BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libdisposeenv001 := $(NSK_JVMTI_AGENT_INCLUDES)
 BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libexception001 := $(NSK_JVMTI_AGENT_INCLUDES)
+BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libexceptionjni001 := $(NSK_JVMTI_AGENT_INCLUDES)
 BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libresexhausted := $(NSK_JVMTI_AGENT_INCLUDES)
 BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libgcstart001 := $(NSK_JVMTI_AGENT_INCLUDES)
 BUILD_HOTSPOT_JTREG_LIBRARIES_CFLAGS_libgcstart002 := $(NSK_JVMTI_AGENT_INCLUDES)
@@ -1375,6 +1376,7 @@
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_librawmonenter004 += -lpthread
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_librawmonenter001 += -lpthread
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libdealloc001 += -lpthread
+    BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libexceptionjni001 += -lpthread
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libisfldsin003 += -lpthread
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libisfldsin002 += -lpthread
     BUILD_HOTSPOT_JTREG_LIBRARIES_LIBS_libthrgrpinfo001 += -lpthread
--- a/test/hotspot/jtreg/TEST.groups	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/TEST.groups	Tue Apr 23 08:11:38 2019 -0700
@@ -438,7 +438,8 @@
 
 # JVMTI tests
 vmTestbase_nsk_jvmti = \
-  vmTestbase/nsk/jvmti
+  vmTestbase/nsk/jvmti \
+  vmTestbase/nsk/share/ExceptionCheckingJniEnv
 
 # JDWP tests
 vmTestbase_nsk_jdwp = \
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/attach002Agent00.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 #include <jvmti.h>
 #include <aod.h>
 #include <jvmti_aod.h>
+#include "ExceptionCheckingJniEnv.hpp"
 
 extern "C" {
 
@@ -67,23 +68,15 @@
 
 #define ATTACH002_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach002/attach002Target"
 
-int registerNativeMethods(JNIEnv* jni) {
+void registerNativeMethods(JNIEnv* jni_env) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     jclass appClass;
     JNINativeMethod nativeMethods[] = {
             { (char*) "agentGotCapabilities", (char*) "()Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach002_attach002Target_agentGotCapabilities } };
     jint nativeMethodsNumber = 1;
 
-    appClass = jni->FindClass(ATTACH002_TARGET_APP_CLASS_NAME);
-    if (!NSK_JNI_VERIFY(jni, appClass != NULL)) {
-        return NSK_FALSE;
-    }
-
-    if (!NSK_JNI_VERIFY(jni,
-            (jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber) == 0))) {
-        return NSK_FALSE;
-    }
-
-    return NSK_TRUE;
+    appClass = jni->FindClass(ATTACH002_TARGET_APP_CLASS_NAME, TRACE_JNI_CALL);
+    jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber, TRACE_JNI_CALL);
 }
 
 void JNICALL  classLoadHandler(
@@ -201,9 +194,7 @@
     if (!NSK_VERIFY(jvmti != NULL))
         return JNI_ERR;
 
-    if (!NSK_VERIFY(registerNativeMethods(jni))) {
-        return JNI_ERR;
-    }
+    registerNativeMethods(jni);
 
     memset(&caps, 0, sizeof(caps));
     caps.can_generate_all_class_hook_events = 1;
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach002/libattach002Agent00.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
  * questions.
  */
 
+#include "ExceptionCheckingJniEnv.cpp"
 #include "native_thread.cpp"
 #include "nsk_tools.cpp"
 #include "jni_tools.cpp"
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/attach021Agent00.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 #include <jvmti.h>
 #include <aod.h>
 #include <jvmti_aod.h>
+#include "ExceptionCheckingJniEnv.hpp"
 
 extern "C" {
 
@@ -87,24 +88,16 @@
      */
 }
 
-int registerNativeMethods(JNIEnv* jni) {
+void registerNativeMethods(JNIEnv* jni_env) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     jclass appClass;
     JNINativeMethod nativeMethods[] = {
             { (char*) "setTagFor", (char*) "(Ljava/lang/Object;)Z", (void*) Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_setTagFor },
             { (char*) "shutdownAgent", (char*) "()V", (void*) Java_nsk_jvmti_AttachOnDemand_attach021_attach021Target_shutdownAgent } };
     jint nativeMethodsNumber = 2;
 
-    appClass = jni->FindClass(ATTACH021_TARGET_APP_CLASS_NAME);
-    if (!NSK_JNI_VERIFY(jni, appClass != NULL)) {
-        return NSK_FALSE;
-    }
-
-    if (!NSK_JNI_VERIFY(jni,
-            (jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber) == 0))) {
-        return NSK_FALSE;
-    }
-
-    return NSK_TRUE;
+    appClass = jni->FindClass(ATTACH021_TARGET_APP_CLASS_NAME, TRACE_JNI_CALL);
+    jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber, TRACE_JNI_CALL);
 }
 
 #ifdef STATIC_BUILD
@@ -138,9 +131,7 @@
     if (!NSK_VERIFY(jvmti != NULL))
         return JNI_ERR;
 
-    if (!NSK_VERIFY(registerNativeMethods(jni))) {
-        return JNI_ERR;
-    }
+    registerNativeMethods(jni);
 
     memset(&caps, 0, sizeof(caps));
     caps.can_tag_objects = 1;
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach021/libattach021Agent00.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
  * questions.
  */
 
+#include "ExceptionCheckingJniEnv.cpp"
 #include "native_thread.cpp"
 #include "nsk_tools.cpp"
 #include "jni_tools.cpp"
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/attach022Agent00.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
 #include <jvmti.h>
 #include <aod.h>
 #include <jvmti_aod.h>
+#include "ExceptionCheckingJniEnv.hpp"
 
 extern "C" {
 
@@ -64,7 +65,6 @@
 JNIEXPORT jboolean JNICALL
 Java_nsk_jvmti_AttachOnDemand_attach022_attach022Target_shutdownAgent(JNIEnv * jni,
         jclass klass, jint expectedTaggedObjectsCounter) {
-
     if (taggedObjectsCounter != expectedTaggedObjectsCounter) {
         success = 0;
         NSK_COMPLAIN2("ERROR: unexpected taggedObjectsCounter: %d (expected value is %d)\n", taggedObjectsCounter, expectedTaggedObjectsCounter);
@@ -97,24 +97,16 @@
 
 #define ATTACH022_TARGET_APP_CLASS_NAME "nsk/jvmti/AttachOnDemand/attach022/attach022Target"
 
-int registerNativeMethods(JNIEnv* jni) {
+void registerNativeMethods(JNIEnv* jni_env) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     jclass appClass;
     JNINativeMethod nativeMethods[] = {
             { (char*)"shutdownAgent", (char*)"(I)Z",
               (void*) Java_nsk_jvmti_AttachOnDemand_attach022_attach022Target_shutdownAgent } };
     jint nativeMethodsNumber = 1;
 
-    appClass = jni->FindClass(ATTACH022_TARGET_APP_CLASS_NAME);
-    if (!NSK_JNI_VERIFY(jni, appClass != NULL)) {
-        return NSK_FALSE;
-    }
-
-    if (!NSK_JNI_VERIFY(jni,
-            (jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber) == 0))) {
-        return NSK_FALSE;
-    }
-
-    return NSK_TRUE;
+    appClass = jni->FindClass(ATTACH022_TARGET_APP_CLASS_NAME, TRACE_JNI_CALL);
+    jni->RegisterNatives(appClass, nativeMethods, nativeMethodsNumber, TRACE_JNI_CALL);
 }
 
 void JNICALL vmObjectAllocHandler(jvmtiEnv * jvmti,
@@ -190,9 +182,7 @@
     if (!NSK_VERIFY(jvmti != NULL))
         return JNI_ERR;
 
-    if (!NSK_VERIFY(registerNativeMethods(jni))) {
-        return JNI_ERR;
-    }
+    registerNativeMethods(jni);
 
     if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("ObjectTagMonitor", &objectTagMonitor))) {
         return JNI_ERR;
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach022/libattach022Agent00.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
  * questions.
  */
 
+#include "ExceptionCheckingJniEnv.cpp"
 #include "native_thread.cpp"
 #include "nsk_tools.cpp"
 #include "jni_tools.cpp"
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/ap04t003.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,7 +25,7 @@
 #include <string.h>
 #include <jvmti.h>
 #include "agent_common.h"
-
+#include "ExceptionCheckingJniEnv.hpp"
 #include "nsk_tools.h"
 #include "jni_tools.h"
 #include "JVMTITools.h"
@@ -305,7 +305,7 @@
 
 /***********************************************************************/
 
-static int startThread(JNIEnv* jni, jthread threadObj) {
+static int startThread(jthread threadObj) {
     int success = NSK_TRUE;
 
     /* enter startLock */
@@ -334,46 +334,26 @@
 }
 
 /** Create thread object for new agent thread. */
-static jthread newThreadObj(JNIEnv* jni) {
+static jthread newThreadObj(JNIEnv* jni_env) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     jclass thrClass;
     jmethodID cid;
-    jthread result = NULL;
 
-    thrClass = jni->FindClass("java/lang/Thread");
-    if (!NSK_JNI_VERIFY(jni, thrClass != NULL)) {
-        nsk_jvmti_setFailStatus();
-        return result;
-    }
-
-    cid = jni->GetMethodID(thrClass, "<init>", "()V");
-    if (!NSK_JNI_VERIFY(jni, cid != NULL)) {
-        nsk_jvmti_setFailStatus();
-        return result;
-    }
-
-    result = jni->NewObject(thrClass, cid);
-    if (!NSK_JNI_VERIFY(jni, result != NULL)) {
-        nsk_jvmti_setFailStatus();
-        return result;
-    }
-
-    return result;
+    thrClass = jni->FindClass("java/lang/Thread", TRACE_JNI_CALL);
+    cid = jni->GetMethodID(thrClass, "<init>", "()V", TRACE_JNI_CALL);
+    return jni->NewObject(thrClass, cid, TRACE_JNI_CALL);
 }
 
 /***********************************************************************/
 
 /** Clean counters and start new agent thread with agent_start() body. */
-static int prepareToIteration (JNIEnv* jni) {
+static int prepareToIteration(JNIEnv* jni) {
     jthread threadObj = NULL;
 
     setCounter(&iterationCount, 0);
     setCounter(&objectCount, 0);
 
     threadObj = newThreadObj(jni);
-    if (!NSK_VERIFY(threadObj != NULL)) {
-        nsk_jvmti_setFailStatus();
-        return NSK_FALSE;
-    }
 
     /* enter endLock */
     if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(endLock))) {
@@ -381,11 +361,11 @@
     }
 
     NSK_DISPLAY0("Starting new agent thread...\n");
-    return startThread(jni, threadObj);
+    return startThread(threadObj);
 }
 
 /** Wait for new agent thread to complete. */
-static void afterIteration (JNIEnv* jni) {
+static void afterIteration() {
 
     /* notify new agent thread (in case if not yet notified) */
     notifyThread();
@@ -433,7 +413,7 @@
     }
     NSK_DISPLAY0("IterateOverHeap finished.\n");
 
-    afterIteration(jni);
+    afterIteration();
 
     found = getCounter(&objectCount);
     NSK_DISPLAY1("Found tagged objects: %d\n", found);
@@ -464,7 +444,7 @@
     }
     NSK_DISPLAY0("IterateOverReachableObjects finished.\n");
 
-    afterIteration(jni);
+    afterIteration();
 
     found = getCounter(&objectCount);
     NSK_DISPLAY1("Found tagged objects: %d\n", found);
@@ -495,7 +475,7 @@
     }
     NSK_DISPLAY0("IterateOverInstancesOfClass finished.\n");
 
-    afterIteration(jni);
+    afterIteration();
 
     found = getCounter(&objectCount);
     NSK_DISPLAY1("Found tagged objects: %d\n", found);
@@ -509,20 +489,16 @@
 }
 
 JNIEXPORT void JNICALL
-Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni,
+Java_nsk_jvmti_scenarios_allocation_AP04_ap04t003_runIterateOverObjectsReachableFromObject(JNIEnv* jni_env,
                                                                                            jclass  klass) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     jobject root = NULL;
     int modified = 0;
     int found = 0;
 
-    root = jni->GetStaticObjectField(debugeeClass, rootFieldID);
-    if (!NSK_JNI_VERIFY(jni, root != NULL)) {
-        NSK_COMPLAIN0("GetStaticObjectField returned NULL for 'root' field value\n\n");
-        nsk_jvmti_setFailStatus();
-        return;
-    }
+    root = jni->GetStaticObjectField(debugeeClass, rootFieldID, TRACE_JNI_CALL);
 
-    if (!prepareToIteration(jni))
+    if (!prepareToIteration(jni_env))
         return;
 
     NSK_DISPLAY0("Calling IterateOverObjectsReachableFromObject...\n");
@@ -533,7 +509,7 @@
     }
     NSK_DISPLAY0("IterateOverObjectsReachableFromObject finished.\n");
 
-    afterIteration(jni);
+    afterIteration();
 
     found = getCounter(&objectCount);
     NSK_DISPLAY1("Found tagged objects: %d\n", found);
@@ -547,8 +523,8 @@
 }
 
 static void JNICALL
-agentProc(jvmtiEnv* jvmti, JNIEnv* jni, void* arg) {
-
+agentProc(jvmtiEnv* jvmti, JNIEnv* jni_env, void* arg) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     NSK_DISPLAY0("Wait for debugee start\n\n");
     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
         return;
@@ -560,16 +536,11 @@
         return;
     }
 
-    debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass);
-    if (!NSK_JNI_VERIFY(jni, debugeeClass != NULL))
-        return;
+    debugeeClass = (jclass) jni->NewGlobalRef(debugeeClass, TRACE_JNI_CALL);
 
     NSK_DISPLAY1("Find ID of 'root' field: %s\n", ROOT_SIGNATURE);
-    rootFieldID = jni->GetStaticFieldID(debugeeClass, "root", ROOT_SIGNATURE);
-    if (!NSK_JNI_VERIFY(jni, rootFieldID != NULL)) {
-        nsk_jvmti_setFailStatus();
-        return;
-    }
+    rootFieldID = jni->GetStaticFieldID(debugeeClass, "root",
+                                        ROOT_SIGNATURE, TRACE_JNI_CALL);
 
     NSK_DISPLAY0("Let debugee to run test cases\n");
     if (!NSK_VERIFY(nsk_jvmti_resumeSync()))
@@ -579,7 +550,7 @@
     if (!NSK_VERIFY(nsk_jvmti_waitForSync(timeout)))
         return;
 
-    NSK_TRACE(jni->DeleteGlobalRef(debugeeClass));
+    jni->DeleteGlobalRef(debugeeClass, TRACE_JNI_CALL);
     NSK_TRACE(jvmti->DestroyRawMonitor(counterMonitor_ptr));
     NSK_TRACE(jvmti->DestroyRawMonitor(startLock));
     NSK_TRACE(jvmti->DestroyRawMonitor(runLock));
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/allocation/AP04/ap04t003/libap04t003.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
  * questions.
  */
 
+#include "ExceptionCheckingJniEnv.cpp"
 #include "native_thread.cpp"
 #include "nsk_tools.cpp"
 #include "jni_tools.cpp"
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/bi01t001.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
 #include <string.h>
 #include "jvmti.h"
 #include "agent_common.h"
+#include "ExceptionCheckingJniEnv.hpp"
 #include "jni_tools.h"
 #include "jvmti_tools.h"
 
@@ -47,23 +48,20 @@
  */
 JNIEXPORT jboolean JNICALL
 Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t001_setNewByteCode(JNIEnv *jni_env,
-                        jobject o, jbyteArray byteCode) {
-
+                                                              jobject o,
+                                                              jbyteArray byteCode) {
+    ExceptionCheckingJniEnvPtr jni(jni_env);
     jbyte* elements;
     jboolean isCopy;
 
-    newClassSize = jni_env->GetArrayLength(byteCode);
-    if (!NSK_JNI_VERIFY(jni_env, newClassSize > 0)) {
+    newClassSize = jni->GetArrayLength(byteCode, TRACE_JNI_CALL);
+    if (newClassSize <= 0) {
         nsk_jvmti_setFailStatus();
         return NSK_FALSE;
     }
     NSK_DISPLAY1("\t... got array size: %d\n", newClassSize);
 
-    elements = jni_env->GetByteArrayElements(byteCode, &isCopy);
-    if (!NSK_JNI_VERIFY(jni_env, elements != NULL)) {
-        nsk_jvmti_setFailStatus();
-        return NSK_FALSE;
-    }
+    elements = jni->GetByteArrayElements(byteCode, &isCopy, TRACE_JNI_CALL);
     NSK_DISPLAY1("\t... got elements list: 0x%p\n", (void*)elements);
 
     if (!NSK_JVMTI_VERIFY(jvmti->Allocate(newClassSize, &newClassBytes))) {
@@ -80,7 +78,7 @@
     NSK_DISPLAY1("\t... copied bytecode: %d bytes\n", (int)newClassSize);
 
     NSK_DISPLAY1("\t... release elements list: 0x%p\n", (void*)elements);
-    NSK_TRACE(jni_env->ReleaseByteArrayElements(byteCode, elements, JNI_ABORT));
+    jni->ReleaseByteArrayElements(byteCode, elements, JNI_ABORT, TRACE_JNI_CALL);
     NSK_DISPLAY0("\t... released\n");
     return NSK_TRUE;
 }
@@ -94,11 +92,8 @@
 JNIEXPORT void JNICALL
 Java_nsk_jvmti_scenarios_bcinstr_BI01_bi01t001_setClass(JNIEnv *jni_env,
                         jobject o, jclass cls) {
-
-    oldClassDef.klass = (jclass) jni_env->NewGlobalRef(cls);
-    if (!NSK_JNI_VERIFY(jni_env, oldClassDef.klass != NULL)) {
-        nsk_jvmti_setFailStatus();
-    }
+    ExceptionCheckingJniEnvPtr jni(jni_env);
+    oldClassDef.klass = (jclass) jni->NewGlobalRef(cls, TRACE_JNI_CALL);
 }
 
 /* ============================================================================= */
@@ -154,6 +149,7 @@
 /** Agent algorithm. */
 static void JNICALL
 agentProc(jvmtiEnv* jvmti, JNIEnv* agentJNI, void* arg) {
+    ExceptionCheckingJniEnvPtr jni(agentJNI);
 
     /*Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1*/
     NSK_DISPLAY0("Wait for debuggee to read new byte codes nsk_jvmti_waitForSync#1\n");
@@ -214,7 +210,7 @@
     if (!nsk_jvmti_waitForSync(timeout))
         return;
 
-    agentJNI->DeleteGlobalRef(oldClassDef.klass);
+    jni->DeleteGlobalRef(oldClassDef.klass, TRACE_JNI_CALL);
 
     NSK_DISPLAY0("Let debuggee to finish\n");
     if (!nsk_jvmti_resumeSync())
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/bcinstr/BI01/bi01t001/libbi01t001.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
  * questions.
  */
 
+#include "ExceptionCheckingJniEnv.cpp"
 #include "native_thread.cpp"
 #include "nsk_tools.cpp"
 #include "jni_tools.cpp"
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/BooleanArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jboolean JNICALL Java_nsk_share_gc_lock_jni_BooleanArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jbooleanArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jbooleanArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jbooleanArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jboolean*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jboolean*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -65,11 +65,11 @@
                         hash = JNI_FALSE;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ByteArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -36,7 +36,7 @@
  */
 JNIEXPORT jbyte JNICALL Java_nsk_share_gc_lock_jni_ByteArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jbyteArray arr;
@@ -45,18 +45,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jbyteArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jbyteArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jbyte*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jbyte*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -64,11 +64,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/CharArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_CharArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jcharArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jcharArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jcharArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         current_time = 0;
         enterTime /= 1000;
         while (current_time - start_time < enterTime) {
-                pa = (jchar*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jchar*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -65,11 +65,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/DoubleArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jdouble JNICALL Java_nsk_share_gc_lock_jni_DoubleArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jdoubleArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jdoubleArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jdoubleArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jdouble*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jdouble*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash += pa[i];
@@ -65,11 +65,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/FloatArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jfloat JNICALL Java_nsk_share_gc_lock_jni_FloatArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jfloatArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jfloatArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jfloatArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jfloat*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jfloat*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash += pa[i];
@@ -65,11 +65,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/IntArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jint JNICALL Java_nsk_share_gc_lock_jni_IntArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jintArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jintArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jintArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jint*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jint*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -65,11 +65,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/LongArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jlong JNICALL Java_nsk_share_gc_lock_jni_LongArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jlongArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jlongArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jlongArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jlong*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jlong*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -65,11 +65,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/ShortArrayCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jshort JNICALL Java_nsk_share_gc_lock_jni_ShortArrayCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jshortArray arr;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        arr = (jshortArray) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        arr = (jshortArray) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetArrayLength(arr);
+        size = jni->GetArrayLength(arr, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = (jshort*) env->GetPrimitiveArrayCritical(arr, NULL);
+                pa = (jshort*) jni->GetPrimitiveArrayCritical(arr, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -65,11 +65,11 @@
                         hash = 0;
                 }
                 mssleep((long) sleepTime);
-                env->ReleasePrimitiveArrayCritical(arr, pa, 0);
+                jni->ReleasePrimitiveArrayCritical(arr, pa, 0, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, arr);
+        jni->SetObjectField(o, objFieldId, arr, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jni/StringCriticalLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@
  */
 JNIEXPORT jchar JNICALL Java_nsk_share_gc_lock_jni_StringCriticalLocker_criticalNative
 (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jsize size, i;
         jstring str;
@@ -46,18 +46,18 @@
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        str = (jstring) env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        str = (jstring) jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
-        size = env->GetStringLength(str);
+        size = jni->GetStringLength(str, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                pa = env->GetStringCritical(str, NULL);
+                pa = jni->GetStringCritical(str, NULL, TRACE_JNI_CALL);
                 if (pa != NULL) {
                         for (i = 0; i < size; ++i)
                                 hash ^= pa[i];
@@ -65,11 +65,11 @@
                         hash = JNI_FALSE;
                 }
                 mssleep((long) sleepTime);
-                env->ReleaseStringCritical(str, pa);
+                jni->ReleaseStringCritical(str, pa, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, str);
+        jni->SetObjectField(o, objFieldId, str, TRACE_JNI_CALL);
         return hash;
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIGlobalRefLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -38,29 +38,29 @@
  */
 JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIGlobalRefLocker_criticalNative
   (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jobject obj;
         jobject gref;
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        obj = env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        obj = jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                gref = env->NewGlobalRef(obj);
+                gref = jni->NewGlobalRef(obj, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
-                env->DeleteGlobalRef(gref);
+                jni->DeleteGlobalRef(gref, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, obj);
+        jni->SetObjectField(o, objFieldId, obj, TRACE_JNI_CALL);
 }
 
 }
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNILocalRefLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,29 +37,29 @@
  */
 JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNILocalRefLocker_criticalNative
   (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jobject obj;
         jobject gref;
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        obj = env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        obj = jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                gref = env->NewLocalRef(obj);
+                gref = jni->NewLocalRef(obj, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
-                env->DeleteLocalRef(gref);
+                jni->DeleteLocalRef(gref, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, obj);
+        jni->SetObjectField(o, objFieldId, obj, TRACE_JNI_CALL);
 }
 
 }
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIRefLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,35 +37,35 @@
  */
 JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIRefLocker_criticalNative
   (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jobject obj;
         jobject gref, lref, gwref;
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
 
-        obj = env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        obj = jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                gref = env->NewGlobalRef(obj);
-                lref = env->NewLocalRef(obj);
-                gwref = env->NewWeakGlobalRef(obj);
+                gref = jni->NewGlobalRef(obj, TRACE_JNI_CALL);
+                lref = jni->NewLocalRef(obj, TRACE_JNI_CALL);
+                gwref = jni->NewWeakGlobalRef(obj, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
-                env->DeleteGlobalRef(gref);
-                env->DeleteLocalRef(lref);
-                env->DeleteWeakGlobalRef(gwref);
+                jni->DeleteGlobalRef(gref, TRACE_JNI_CALL);
+                jni->DeleteLocalRef(lref, TRACE_JNI_CALL);
+                jni->DeleteWeakGlobalRef(gwref, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, obj);
+        jni->SetObjectField(o, objFieldId, obj, TRACE_JNI_CALL);
 }
 
 }
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/gc/lock/jniref/JNIWeakGlobalRefLocker.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -37,30 +37,30 @@
  */
 JNIEXPORT void JNICALL Java_nsk_share_gc_lock_jniref_JNIWeakGlobalRefLocker_criticalNative
   (JNIEnv *jni_env, jobject o, jlong enterTime, jlong sleepTime) {
-        ExceptionCheckingJniEnvPtr env(jni_env);
+        ExceptionCheckingJniEnvPtr jni(jni_env);
 
         jobject obj;
         jobject gref;
         time_t start_time, current_time;
 
         if (objFieldId == NULL) {
-                jclass klass = env->GetObjectClass(o);
-                objFieldId = env->GetFieldID(klass, "obj", "Ljava/lang/Object;");
+                jclass klass = jni->GetObjectClass(o, TRACE_JNI_CALL);
+                objFieldId = jni->GetFieldID(klass, "obj", "Ljava/lang/Object;", TRACE_JNI_CALL);
         }
-        obj = env->GetObjectField(o, objFieldId);
-        env->SetObjectField(o, objFieldId, NULL);
+        obj = jni->GetObjectField(o, objFieldId, TRACE_JNI_CALL);
+        jni->SetObjectField(o, objFieldId, NULL, TRACE_JNI_CALL);
 
         start_time = time(NULL);
         enterTime /= 1000;
         current_time = 0;
         while (current_time - start_time < enterTime) {
-                gref = env->NewWeakGlobalRef(obj);
+                gref = jni->NewWeakGlobalRef(obj, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
-                env->DeleteWeakGlobalRef(gref);
+                jni->DeleteWeakGlobalRef(gref, TRACE_JNI_CALL);
                 mssleep((long) sleepTime);
                 current_time = time(NULL);
         }
-        env->SetObjectField(o, objFieldId, obj);
+        jni->SetObjectField(o, objFieldId, obj, TRACE_JNI_CALL);
 }
 
 }
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.cpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.cpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Google and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,62 +26,164 @@
 #include <string.h>
 
 #include "ExceptionCheckingJniEnv.hpp"
+#include "nsk_tools.h"
 
 namespace {
 
+static const char* get_dirname(const char* fullname) {
+  const char* p;
+  const char* base = fullname;;
+
+  if (fullname == NULL) {
+    return NULL;
+  }
+
+  for (p = fullname; *p != '\0'; p++) {
+    if (*p == '/' || *p == '\\') {
+      base = p + 1;
+    }
+  }
+  return base;
+}
+
 template<class T = void*>
 class JNIVerifier {
  public:
-  JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_msg)
-      : _env(env), _base_msg(base_msg), _return_error(NULL) {
+  JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message,
+              int line, const char* file)
+      : _env(env), _base_message(base_message), _error_message(NULL),
+        _line(line), _file(get_dirname(file)) {
+  }
+
+  // Until C++11 is supported, we have to write multiple template constructors.
+  template <typename U>
+  JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message,
+              U parameter,
+              int line, const char* file)
+      : _env(env), _base_message(base_message), _error_message(NULL),
+        _line(line), _file(get_dirname(file)) {
+          PrintPreCall(parameter);
+  }
+
+  template <typename U, typename V>
+  JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message,
+              U parameter1,
+              V parameter2,
+              int line, const char* file)
+      : _env(env), _base_message(base_message), _error_message(NULL),
+        _line(line), _file(get_dirname(file)) {
+          PrintPreCall(parameter1, parameter2);
+  }
+
+  template <typename U, typename V, typename W>
+  JNIVerifier(ExceptionCheckingJniEnv *env, const char* base_message,
+              U parameter1, V parameter2, W parameter3,
+              int line, const char* file)
+      : _env(env), _base_message(base_message), _error_message(NULL),
+        _line(line), _file(get_dirname(file)) {
+          PrintPreCall(parameter1, parameter2, parameter3);
   }
 
   ~JNIVerifier() {
+    PrintPostCall();
+
     JNIEnv* jni_env = _env->GetJNIEnv();
-    if (jni_env->ExceptionCheck()) {
-      _env->HandleError(_base_msg);
+    if (jni_env->ExceptionCheck() && !_error_message) {
+      _error_message = "internal error";
+    }
+
+    if (_error_message != NULL) {
+      GenerateErrorMessage();
+    }
+  }
+
+  int DecimalToAsciiRec(char *str, long line) {
+    if (line == 0) {
+      return 0;
+    }
+
+    int remainder = line % 10;
+    long quotient = line / 10;
+
+    int pos = DecimalToAsciiRec(str, quotient);
+    str[pos] = '0' + remainder;
+    return pos + 1;
+  }
+
+  // Implementing a simple version of sprintf for "%d"...
+  void DecimalToAscii(char *str, int line) {
+    // Go to long so that the INT_MIN case can be handled seemlessly.
+    long internal_line = line;
+    if (internal_line == 0) {
+      str[0] = '0';
+      str[1] = '\0';
       return;
     }
 
-    if (_return_error != NULL) {
-      ProcessReturnError();
+    if (internal_line < 0) {
+      *str = '-';
+      internal_line *= -1;
+      str++;
     }
+
+    str[DecimalToAsciiRec(str, internal_line)] = '\0';
   }
 
-  void ProcessReturnError() {
+  void GenerateErrorMessage() {
     // This is error prone, but:
     //   - Seems like we cannot use std::string (due to windows/solaris not
     //   building when used, seemingly due to exception libraries not linking).
     //   - Seems like we cannot use sprintf due to VS2013 (JDK-8213622).
     //
     //   We are aiming to do:
-    //     snprintf(full_message, len, "%s : %s", _base_msg, _return_error);
+    //     snprintf(full_message, len, "JNI method %s : %s from %s : %d", _base_message, _error_message,
+    //              _file, _line);
     //   but will use strlen + memcpy instead.
-    size_t base_len = strlen(_base_msg);
+    const char* pre_message = "JNI method ";
     const char* between_msg = " : ";
-    size_t between_len = strlen(between_msg);
-    size_t return_len = strlen(_return_error);
+    const char* from_msg = " from ";
 
-    // +1 for the '\0'
-    size_t len = base_len + between_len + return_len + 1;
+    const char* file_name = _file ? _file : "Unknown File";
+    const char* strs[] = {
+      pre_message,
+      _base_message,
+      between_msg,
+      _error_message,
+      from_msg,
+      file_name,
+      between_msg,
+    };
+
+    size_t msg_number = sizeof(strs) / sizeof(strs[0]);
+    size_t len = 0;
+    for (size_t i = 0; i < msg_number; i++) {
+      len += strlen(strs[i]);
+    }
+
+    // 32-bit signed means 11 characters due to the '-'.
+    const int MAX_INTEGER_DIGITS = 11;
+    // Add for the line number and 1 for the '\0'.
+    len += MAX_INTEGER_DIGITS + 1;
 
     char* full_message = (char*) malloc(len);
     if (full_message == NULL) {
-      _env->HandleError(_return_error);
+      _env->HandleError(_error_message);
       return;
     }
 
-    // Now we construct the string using memcpy to not use sprintf/std::string
+    // Now we construct the string using strcat to not use sprintf/std::string
     // instead of:
-    //     snprintf(full_message, len, "%s : %s", _base_msg, _return_error);
-    memcpy(full_message, _base_msg, base_len);
-    memcpy(full_message + base_len, between_msg, between_len);
-    memcpy(full_message + base_len + between_len, _return_error, return_len);
-    full_message[len - 1] = '\0';
+    //     snprintf(full_message, len, "JNI method %s : %s from %s:%d", _base_message,
+    //         _error_message, _file, _line);
+    full_message[0] = '\0';
+    for (size_t i = 0; i < msg_number; i++) {
+      strcat(full_message, strs[i]);
+    }
 
-    // -1 due to the '\0' not counted by strlen but is counted for the allocation.
-    if (strlen(full_message) != len - 1) {
-      _env->GetJNIEnv()->FatalError("Length of message is not what was expected");
+    DecimalToAscii(full_message, _line);
+
+    if (strlen(full_message) >= len) {
+      _env->GetJNIEnv()->FatalError("Final length of message is not what was expected");
     }
 
     _env->HandleError(full_message);
@@ -90,95 +192,240 @@
 
   T ResultNotNull(T ptr) {
     if (ptr == NULL) {
-      _return_error = "Return is NULL";
+      _error_message = "Return is NULL";
     }
     return ptr;
   }
 
+  T ResultIsZero(T value) {
+    if (value != 0) {
+      _error_message = "Return is not zero";
+    }
+    return value;
+  }
+
+  void PrintPreCallHeader() {
+    if (!nsk_getVerboseMode()) {
+      return;
+    }
+
+    fprintf(stdout, ">> Calling JNI method %s from %s:%d\n",
+            _base_message, _file, _line);
+    fprintf(stdout, ">> Calling with these parameter(s):\n");
+  }
+
+  // Until we can actually link with C++ more uniformely across architectures,
+  // we have to do this...
+  template<class U>
+  void PrintParameter(U* ptr) {
+    fprintf(stdout, "\t%p\n", ptr);
+  }
+
+  void PrintParameter(int value) {
+    fprintf(stdout, "\t%d\n", value);
+  }
+
+  // Until C++11 is supported, we have to write multiple PrintPreCall.
+  template<class U>
+  void PrintPreCall(U first_parameter) {
+    if (!nsk_getVerboseMode()) {
+      return;
+    }
+
+    PrintPreCallHeader();
+    PrintParameter(first_parameter);
+  }
+
+  template<class U, class V>
+  void PrintPreCall(U parameter1, V parameter2) {
+    if (!nsk_getVerboseMode()) {
+      return;
+    }
+
+    PrintPreCallHeader();
+    PrintParameter(parameter1);
+    PrintParameter(parameter2);
+  }
+
+  template<class U, class V, class W>
+  void PrintPreCall(U parameter1, V parameter2, W parameter3) {
+    if (!nsk_getVerboseMode()) {
+      return;
+    }
+
+    PrintPreCallHeader();
+    PrintParameter(parameter1);
+    PrintParameter(parameter2);
+    PrintParameter(parameter3);
+  }
+
+  void PrintPostCall() {
+    if (!nsk_getVerboseMode()) {
+      return;
+    }
+
+    fprintf(stderr, "<< Called JNI method %s from %s:%d\n",
+            _base_message, _file, _line);
+  }
+
  private:
   ExceptionCheckingJniEnv* _env;
-  const char* const _base_msg;
-  const char* _return_error;
+  const char* const _base_message;
+  const char* _error_message;
+  int _line;
+  const char* const _file;
 };
 
 }
 
-jclass ExceptionCheckingJniEnv::GetObjectClass(jobject obj) {
-  JNIVerifier<jclass> marker(this, "GetObjectClass");
+jclass ExceptionCheckingJniEnv::FindClass(const char *class_name,
+                                          int line, const char* file_name) {
+  JNIVerifier<jclass> marker(this, "FindClass", class_name, line, file_name);
+  return marker.ResultNotNull(_jni_env->FindClass(class_name));
+}
+
+jint ExceptionCheckingJniEnv::RegisterNatives(jclass clazz,
+                                              const JNINativeMethod *methods,
+                                              jint nMethods,
+                                              int line,
+                                              const char* file_name) {
+  JNIVerifier<jint> marker(this, "RegisterNatives", methods, nMethods, line, file_name);
+  return marker.ResultIsZero(_jni_env->RegisterNatives(clazz, methods, nMethods));
+}
+
+jclass ExceptionCheckingJniEnv::GetObjectClass(jobject obj, int line,
+                                               const char* file_name) {
+  JNIVerifier<jclass> marker(this, "GetObjectClass", obj, line, file_name);
   return marker.ResultNotNull(_jni_env->GetObjectClass(obj));
 }
 
-jfieldID ExceptionCheckingJniEnv::GetFieldID(jclass klass, const char *name, const char* type) {
-  JNIVerifier<jfieldID> marker(this, "GetFieldID");
+jfieldID ExceptionCheckingJniEnv::GetStaticFieldID(jclass klass, const char *name,
+                                                   const char* type,
+                                                   int line, const char* file_name) {
+  JNIVerifier<jfieldID> marker(this, "GetStaticFieldID", klass, name, type,
+                               line, file_name);
+  return marker.ResultNotNull(_jni_env->GetStaticFieldID(klass, name, type));
+}
+
+jfieldID ExceptionCheckingJniEnv::GetFieldID(jclass klass, const char *name,
+                                             const char* type,
+                                             int line, const char* file_name) {
+  JNIVerifier<jfieldID> marker(this, "GetFieldID", klass, name, type, line, file_name);
   return marker.ResultNotNull(_jni_env->GetFieldID(klass, name, type));
 }
 
-jobject ExceptionCheckingJniEnv::GetObjectField(jobject obj, jfieldID field) {
-  JNIVerifier<jobject> marker(this, "GetObjectField");
+jobject ExceptionCheckingJniEnv::GetStaticObjectField(jclass klass, jfieldID field,
+                                                      int line, const char* file_name) {
+  JNIVerifier<jobject> marker(this, "GetStaticObjectField", klass, field,
+                              line, file_name);
+  return marker.ResultNotNull(_jni_env->GetStaticObjectField(klass, field));
+}
+
+jobject ExceptionCheckingJniEnv::GetObjectField(jobject obj, jfieldID field,
+                                                int line, const char* file_name) {
+  JNIVerifier<jobject> marker(this, "GetObjectField", obj, field, line, file_name);
   return marker.ResultNotNull(_jni_env->GetObjectField(obj, field));
 }
 
-void ExceptionCheckingJniEnv::SetObjectField(jobject obj, jfieldID field, jobject value) {
-  JNIVerifier<> marker(this, "SetObjectField");
+void ExceptionCheckingJniEnv::SetObjectField(jobject obj, jfieldID field, jobject value,
+                                             int line, const char* file_name) {
+  JNIVerifier<> marker(this, "SetObjectField", obj, field, value, line, file_name);
   _jni_env->SetObjectField(obj, field, value);
 }
 
-jobject ExceptionCheckingJniEnv::NewGlobalRef(jobject obj) {
-  JNIVerifier<jobject> marker(this, "NewGlobalRef");
+jobject ExceptionCheckingJniEnv::NewGlobalRef(jobject obj, int line, const char* file_name) {
+  JNIVerifier<jobject> marker(this, "NewGlobalRef", obj, line, file_name);
   return marker.ResultNotNull(_jni_env->NewGlobalRef(obj));
 }
 
-void ExceptionCheckingJniEnv::DeleteGlobalRef(jobject obj) {
-  JNIVerifier<> marker(this, "DeleteGlobalRef");
+void ExceptionCheckingJniEnv::DeleteGlobalRef(jobject obj, int line, const char* file_name) {
+  JNIVerifier<> marker(this, "DeleteGlobalRef", obj, line, file_name);
   _jni_env->DeleteGlobalRef(obj);
 }
 
-jobject ExceptionCheckingJniEnv::NewLocalRef(jobject obj) {
-  JNIVerifier<jobject> marker(this, "NewLocalRef");
+jobject ExceptionCheckingJniEnv::NewLocalRef(jobject obj, int line, const char* file_name) {
+  JNIVerifier<jobject> marker(this, "NewLocalRef", obj, line, file_name);
   return marker.ResultNotNull(_jni_env->NewLocalRef(obj));
 }
 
-void ExceptionCheckingJniEnv::DeleteLocalRef(jobject obj) {
-  JNIVerifier<> marker(this, "DeleteLocalRef");
+void ExceptionCheckingJniEnv::DeleteLocalRef(jobject obj, int line, const char* file_name) {
+  JNIVerifier<> marker(this, "DeleteLocalRef", obj, line, file_name);
   _jni_env->DeleteLocalRef(obj);
 }
 
-jweak ExceptionCheckingJniEnv::NewWeakGlobalRef(jobject obj) {
-  JNIVerifier<jweak> marker(this, "NewWeakGlobalRef");
+jweak ExceptionCheckingJniEnv::NewWeakGlobalRef(jobject obj, int line, const char* file_name) {
+  JNIVerifier<jweak> marker(this, "NewWeakGlobalRef", obj, line, file_name);
   return marker.ResultNotNull(_jni_env->NewWeakGlobalRef(obj));
 }
 
-void ExceptionCheckingJniEnv::DeleteWeakGlobalRef(jweak weak_ref) {
-  JNIVerifier<> marker(this, "DeleteWeakGlobalRef");
+void ExceptionCheckingJniEnv::DeleteWeakGlobalRef(jweak weak_ref, int line, const char* file_name) {
+  JNIVerifier<> marker(this, "DeleteWeakGlobalRef", weak_ref, line, file_name);
   _jni_env->DeleteWeakGlobalRef(weak_ref);
 }
 
-jsize ExceptionCheckingJniEnv::GetArrayLength(jarray array) {
-  JNIVerifier<> marker(this, "GetArrayLength");
+jsize ExceptionCheckingJniEnv::GetArrayLength(jarray array, int line, const char* file_name) {
+  JNIVerifier<> marker(this, "GetArrayLength", array, line, file_name);
   return _jni_env->GetArrayLength(array);
 }
 
-jsize ExceptionCheckingJniEnv::GetStringLength(jstring str) {
-  JNIVerifier<> marker(this, "GetStringLength");
+jsize ExceptionCheckingJniEnv::GetStringLength(jstring str, int line, const char* file_name) {
+  JNIVerifier<> marker(this, "GetStringLength", str, line, file_name);
   return _jni_env->GetStringLength(str);
 }
 
-void* ExceptionCheckingJniEnv::GetPrimitiveArrayCritical(jarray array, jboolean* isCopy) {
-  JNIVerifier<> marker(this, "GetPrimitiveArrayCritical");
-  return marker.ResultNotNull(_jni_env->GetPrimitiveArrayCritical(array, isCopy));
+void* ExceptionCheckingJniEnv::GetPrimitiveArrayCritical(jarray array, jboolean* is_copy,
+                                                         int line, const char* file_name) {
+  JNIVerifier<> marker(this, "GetPrimitiveArrayCritical", array, is_copy, line, file_name);
+  return marker.ResultNotNull(_jni_env->GetPrimitiveArrayCritical(array, is_copy));
 }
 
-void ExceptionCheckingJniEnv::ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode) {
-  JNIVerifier<> marker(this, "ReleasePrimitiveArrayCritical");
+void ExceptionCheckingJniEnv::ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode,
+                                                            int line, const char* file_name) {
+  JNIVerifier<> marker(this, "ReleasePrimitiveArrayCritical", array, carray, mode,
+                       line, file_name);
   _jni_env->ReleasePrimitiveArrayCritical(array, carray, mode);
 }
 
-const jchar* ExceptionCheckingJniEnv::GetStringCritical(jstring str, jboolean* isCopy) {
-  JNIVerifier<const jchar*> marker(this, "GetPrimitiveArrayCritical");
-  return marker.ResultNotNull(_jni_env->GetStringCritical(str, isCopy));
+const jchar* ExceptionCheckingJniEnv::GetStringCritical(jstring str, jboolean* is_copy,
+                                                        int line, const char* file_name) {
+  JNIVerifier<const jchar*> marker(this, "GetPrimitiveArrayCritical", str, is_copy,
+                                   line, file_name);
+  return marker.ResultNotNull(_jni_env->GetStringCritical(str, is_copy));
 }
 
-void ExceptionCheckingJniEnv::ReleaseStringCritical(jstring str, const jchar* carray) {
-  JNIVerifier<> marker(this, "ReleaseStringCritical");
+void ExceptionCheckingJniEnv::ReleaseStringCritical(jstring str, const jchar* carray,
+                                                    int line, const char* file_name) {
+  JNIVerifier<> marker(this, "ReleaseStringCritical", str, carray, line, file_name);
   _jni_env->ReleaseStringCritical(str, carray);
 }
+
+jbyte* ExceptionCheckingJniEnv::GetByteArrayElements(jbyteArray array, jboolean* is_copy,
+                                                   int line, const char* file_name) {
+  JNIVerifier<jbyte*> marker(this, "GetByteArrayElements", array, is_copy, line, file_name);
+  return marker.ResultNotNull(_jni_env->GetByteArrayElements(array, is_copy));
+}
+
+void ExceptionCheckingJniEnv::ReleaseByteArrayElements(jbyteArray array, jbyte* byte_array, jint mode,
+                                                       int line, const char* file_name) {
+  JNIVerifier<> marker(this, "ReleaseByteArrayElements", array, byte_array, mode,
+                       line, file_name);
+  _jni_env->ReleaseByteArrayElements(array, byte_array, mode);
+}
+
+jmethodID ExceptionCheckingJniEnv::GetMethodID(jclass klass, const char* name, const char* sig,
+                                               int line, const char* file_name) {
+  JNIVerifier<jmethodID> marker(this, "GetMethodID", klass, name, sig, line, file_name);
+  return marker.ResultNotNull(_jni_env->GetMethodID(klass, name, sig));
+}
+
+jobject ExceptionCheckingJniEnv::NewObject(jclass klass, jmethodID methodID,
+                                           int line, const char* file_name, ...) {
+  // In the case of NewObject, we miss the extra arguments passed to NewObject sadly.
+  JNIVerifier<jobject> marker(this, "NewObject", klass, methodID, line, file_name);
+
+  va_list args;
+  va_start(args, file_name);
+  jobject result = marker.ResultNotNull(_jni_env->NewObjectV(klass, methodID, args));
+  va_end(args);
+  return result;
+}
--- a/test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.hpp	Tue Apr 23 16:50:17 2019 +0200
+++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jni/ExceptionCheckingJniEnv.hpp	Tue Apr 23 08:11:38 2019 -0700
@@ -1,6 +1,6 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2018, Google and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2019, Google and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -46,40 +46,65 @@
  *
  *  Can be simplified to:
  * ... ExceptionCheckingJniEnv* env ...
- *  jclass klass = env->GetObjectClass(o);
+ *  jclass klass = env->GetObjectClass(o, TRACE_JNI_CALL);
  *
  *  Where now the JNI Exception checking and the NULL return checking are done
  *  internally and will perform whatever action the ErrorHandler requires.
  *
+ *  Note the TRACE_JNI_CALL parameter that allows to trace where the call is
+ *  happening from for debugging.
+ *
  *  By default, the error handler describes the exception via the JNI
  *  ExceptionDescribe method and calls FatalError.
- *
- *  Note: at a future date, this will also include the tracing mechanism done in
- *  NSK_VERIFY, which will thus embed its logic into the ExceptionCheckingJniEnv
- *  and clearing that up for the code readers and writers.
  */
+
+#define TRACE_JNI_CALL __LINE__, __FILE__
+
 class ExceptionCheckingJniEnv {
  public:
   // JNIEnv API redefinitions.
-  jfieldID GetFieldID(jclass klass, const char *name, const char* type);
-  jclass GetObjectClass(jobject obj);
-  jobject GetObjectField(jobject obj, jfieldID field);
-  void SetObjectField(jobject obj, jfieldID field, jobject value);
+  jclass FindClass(const char *name, int line, const char* file_name);
 
-  jsize GetArrayLength(jarray array);
-  jsize GetStringLength(jstring str);
+  jfieldID GetStaticFieldID(jclass klass, const char* name, const char* type,
+                            int line, const char* file_name);
+  jfieldID GetFieldID(jclass klass, const char* name, const char* type,
+                      int line, const char* file_name);
+  jmethodID GetMethodID(jclass klass, const char* name, const char* sig,
+                        int line, const char* file_name);
 
-  void* GetPrimitiveArrayCritical(jarray array, jboolean* isCopy);
-  void ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode);
-  const jchar* GetStringCritical(jstring str, jboolean* isCopy);
-  void ReleaseStringCritical(jstring str, const jchar* carray);
+  jclass GetObjectClass(jobject obj, int line, const char* file_name);
+  jobject GetObjectField(jobject obj, jfieldID field, int line, const char* file_name);
+  jobject GetStaticObjectField(jclass kls, jfieldID field, int line, const char* file_name);
+  void SetObjectField(jobject obj, jfieldID field, jobject value,
+                      int line, const char* file_name);
 
-  jobject NewGlobalRef(jobject obj);
-  void DeleteGlobalRef(jobject obj);
-  jobject NewLocalRef(jobject ref);
-  void DeleteLocalRef(jobject ref);
-  jweak NewWeakGlobalRef(jobject obj);
-  void DeleteWeakGlobalRef(jweak obj);
+  jsize GetArrayLength(jarray array, int line, const char* file_name);
+  jsize GetStringLength(jstring str, int line, const char* file_name);
+
+  void* GetPrimitiveArrayCritical(jarray array, jboolean* isCopy,
+                                  int line, const char* file_name);
+  void ReleasePrimitiveArrayCritical(jarray array, void* carray, jint mode,
+                                     int line, const char* file_name);
+  const jchar* GetStringCritical(jstring str, jboolean* isCopy,
+                                 int line, const char* file_name);
+  void ReleaseStringCritical(jstring str, const jchar* carray,
+                             int line, const char* file_name);
+
+  jbyte* GetByteArrayElements(jbyteArray array, jboolean* isCopy,
+                              int line, const char* file_name);
+  void ReleaseByteArrayElements(jbyteArray array, jbyte* byte_array, jint mode,
+                                int line, const char* file_name);
+  jint RegisterNatives(jclass clazz, const JNINativeMethod *methods, jint nMethods,
+                       int line, const char* file_name);
+
+  jobject NewObject(jclass kls, jmethodID methodID,
+                    int line, const char* file_name, ...);
+  jobject NewGlobalRef(jobject obj, int line, const char* file_name);
+  void DeleteGlobalRef(jobject obj, int line, const char* file_name);
+  jobject NewLocalRef(jobject ref, int line, const char* file_name);
+  void DeleteLocalRef(jobject ref, int line, const char* file_name);
+  jweak NewWeakGlobalRef(jobject obj, int line, const char* file_name);
+  void DeleteWeakGlobalRef(jweak obj, int line, const char* file_name);
 
   // ExceptionCheckingJniEnv methods.
   JNIEnv* GetJNIEnv() {