changeset 54318:c0037e86ec02

8218727: vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/TestDescription.java crash in native library Reviewed-by: sspitsyn, gadams
author dtitov
date Thu, 28 Mar 2019 04:26:36 +0000
parents 5b5bd291ca32
children 55025f677f68
files test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.cpp test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.cpp
diffstat 2 files changed, 56 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.cpp	Thu Mar 28 01:43:11 2019 +0100
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM04/em04t001/em04t001.cpp	Thu Mar 28 04:26:36 2019 +0000
@@ -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
@@ -29,7 +29,6 @@
 #include "jvmti_tools.h"
 #include "JVMTITools.h"
 #include "nsk_list.h"
-#include "nsk_mutex.h"
 
 extern "C" {
 
@@ -49,8 +48,8 @@
     int sign;
 } nsk_jvmti_DCG_params;
 
-static MUTEX* mutex = NULL;
-
+static jrawMonitorID syncLock = NULL;
+static volatile int callbacksEnabled = NSK_TRUE;
 /* ============================================================================= */
 
 /* callbacks */
@@ -60,6 +59,12 @@
     nsk_jvmti_DCG_params *rec;
     int b;
 
+    jvmti->RawMonitorEnter(syncLock);
+    if (!callbacksEnabled) {
+        jvmti->RawMonitorExit(syncLock);
+        return;
+    }
+
     rec = (nsk_jvmti_DCG_params *)malloc(sizeof(nsk_jvmti_DCG_params));
     strncpy(rec->name, name, NAME_LENGTH);
     rec->name[NAME_LENGTH - 1] = '\0';
@@ -69,16 +74,13 @@
 
     NSK_DISPLAY3("received: 0x%p %7d %s\n", rec->address, rec->length, rec->name);
 
-    MUTEX_acquire(mutex);
-
     b = NSK_VERIFY(nsk_list_add(plist, rec));
 
-    MUTEX_release(mutex);
-
     if (!b) {
         nsk_jvmti_setFailStatus();
         free((void *)rec);
     }
+    jvmti->RawMonitorExit(syncLock);
 }
 
 void JNICALL
@@ -87,6 +89,13 @@
 
     int i;
     nsk_jvmti_DCG_params *rec;
+
+    jvmti->RawMonitorEnter(syncLock);
+    if (!callbacksEnabled) {
+        jvmti->RawMonitorExit(syncLock);
+        return;
+    }
+
     int count = nsk_list_getCount(plist);
     int compLength = NAME_LENGTH - 1;
 
@@ -99,11 +108,13 @@
             if (strncmp(rec->name, name, compLength) != 0) {
                 NSK_DISPLAY2("\t<%s> was renamed to <%s>\n", rec->name, name);
             }
+            jvmti->RawMonitorExit(syncLock);
             return;
         }
 
     }
     NSK_DISPLAY3("NOT FOUND: 0x%p %7d %s\n", address, length, name);
+    jvmti->RawMonitorExit(syncLock);
 
 }
 
@@ -151,6 +162,9 @@
     if (!NSK_JVMTI_VERIFY(jvmti->GenerateEvents(JVMTI_EVENT_DYNAMIC_CODE_GENERATED)))
         nsk_jvmti_setFailStatus();
 
+    jvmti->RawMonitorEnter(syncLock);
+    callbacksEnabled = NSK_FALSE;
+
     {
         int i;
         const nsk_jvmti_DCG_params *rec;
@@ -168,6 +182,8 @@
 
     }
 
+    jvmti->RawMonitorExit(syncLock);
+
     NSK_DISPLAY0("Let debuggee to finish\n");
     if (!nsk_jvmti_resumeSync())
         return;
@@ -190,10 +206,6 @@
 #endif
 jint Agent_Initialize(JavaVM *jvm, char *options, void *reserved) {
 
-    mutex = MUTEX_create();
-    if (!mutex)
-        return JNI_ERR;
-
     if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
         return JNI_ERR;
 
@@ -203,6 +215,11 @@
     if (!NSK_VERIFY(jvmti != NULL))
         return JNI_ERR;
 
+    if (!NSK_JVMTI_VERIFY(jvmti->CreateRawMonitor("_syncLock", &syncLock))) {
+        nsk_jvmti_setFailStatus();
+        return JNI_ERR;
+    }
+
     plist = (const void *)nsk_list_create();
     if (!NSK_VERIFY(plist != NULL))
         return JNI_ERR;
@@ -239,9 +256,8 @@
         nsk_jvmti_setFailStatus();
     }
 
-    if (mutex) {
-        MUTEX_destroy(mutex);
-        mutex = NULL;
+    if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock))) {
+        nsk_jvmti_setFailStatus();
     }
 }
 
--- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.cpp	Thu Mar 28 01:43:11 2019 +0100
+++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/scenarios/events/EM07/em07t002/em07t002.cpp	Thu Mar 28 04:26:36 2019 +0000
@@ -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
@@ -44,6 +44,7 @@
 
 #define NAME_LENGTH 50
 const void *plist = NULL;
+static volatile int callbacksEnabled = NSK_TRUE;
 
 typedef struct nsk_jvmti_CompiledMethodIDStruct {
     jmethodID method;
@@ -63,8 +64,15 @@
     char *sign;
     char *genc;
 
+    jvmti->RawMonitorEnter(syncLock);
+    if (!callbacksEnabled) {
+        jvmti->RawMonitorExit(syncLock);
+        return;
+    }
+
     if (!NSK_JVMTI_VERIFY(jvmti_env->GetMethodName(method, &name, &sign, &genc))) {
         nsk_jvmti_setFailStatus();
+        jvmti->RawMonitorExit(syncLock);
         return;
     }
 
@@ -105,6 +113,9 @@
         if (!NSK_JVMTI_VERIFY(jvmti_env->Deallocate((unsigned char*)genc))) {
             nsk_jvmti_setFailStatus();
         }
+
+    jvmti->RawMonitorExit(syncLock);
+
 }
 
 void JNICALL
@@ -113,7 +124,13 @@
 
     nsk_jvmti_CompiledMethod *rec;
 
+    jvmti->RawMonitorEnter(syncLock);
+    if (!callbacksEnabled) {
+        jvmti->RawMonitorExit(syncLock);
+        return;
+    }
     int count = nsk_list_getCount(plist);
+
     int i;
 
     for (i = 0; i < count; i ++) {
@@ -122,21 +139,16 @@
             NSK_DISPLAY0(">>>JVMTI_EVENT_COMPILED_METHOD_UNLOAD received for\n");
             NSK_DISPLAY1("\t\tmethod: %s\n", rec->name);
 
-            if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorEnter(syncLock)))
-                nsk_jvmti_setFailStatus();
-
             methodUnloadCount++;
 
-            if (!NSK_JVMTI_VERIFY(jvmti->RawMonitorExit(syncLock)))
-                nsk_jvmti_setFailStatus();
-
             free(rec);
             nsk_list_remove(plist, i);
+            jvmti->RawMonitorExit(syncLock);
             return;
         }
 
     }
-
+    jvmti->RawMonitorExit(syncLock);
 }
 
 /* ============================================================================= */
@@ -210,6 +222,9 @@
             return;
     }
 
+    jvmti->RawMonitorEnter(syncLock);
+    callbacksEnabled = NSK_FALSE;
+
     {
         int count = nsk_list_getCount(plist);
 
@@ -221,6 +236,8 @@
 
     }
 
+    jvmti->RawMonitorExit(syncLock);
+
     if (!NSK_JVMTI_VERIFY(jvmti->DestroyRawMonitor(syncLock)))
         nsk_jvmti_setFailStatus();