< prev index next >

test/hotspot/jtreg/serviceability/jvmti/events/MonitorContendedEntered/mcontentered01/libmcontentered01.cpp

Print this page

 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 #include <stdio.h>
 25 #include <string.h>
 26 #include <jvmti.h>
 27 #include "jvmti_common.hpp"
 28 #include "jvmti_thread.hpp"
 29 
 30 extern "C" {
 31 
 32 /* ========================================================================== */
 33 
 34 /* scaffold objects */
 35 static JNIEnv *jni = nullptr;
 36 static jvmtiEnv *jvmti = nullptr;
 37 static jlong timeout = 0;
 38 
 39 /* test objects */
 40 static jthread expected_thread = nullptr;
 41 static jobject expected_object = nullptr;
 42 static volatile int eventsCount = 0;
 43 
 44 
 45 /* Check GetPotentialCapabilities function
 46  */
 47 void JNICALL
 48 MonitorContendedEntered(jvmtiEnv *jvmti, JNIEnv *jni, jthread thr, jobject obj) {
 49 
 50   LOG("MonitorContendedEntered event:\n\tthread: %p, object: %p, expected object: %p\n",thr, obj, expected_object);
 51 
 52   print_thread_info(jvmti, jni, thr);
 53 
 54   if (expected_thread == nullptr) {
 55     jni->FatalError("expected_thread is null.");

110     return JNI_FALSE;
111   }
112 
113   return JNI_TRUE;
114 }
115 
116 static int clean() {
117   jvmtiError err;
118   /* disable MonitorContendedEntered event */
119   err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,nullptr);
120   if (err != JVMTI_ERROR_NONE) {
121     set_agent_fail_status();
122   }
123   return JNI_TRUE;
124 }
125 
126 /* agent algorithm
127  */
128 static void JNICALL
129 agentProc(jvmtiEnv *jvmti, JNIEnv *agentJNI, void *arg) {
130   jni = agentJNI;
131 
132 /* wait for initial sync */
133   if (!agent_wait_for_sync(timeout))
134     return;
135 
136   if (!prepare()) {
137     set_agent_fail_status();
138     return;
139   }
140 
141   /* clear events count */
142   eventsCount = 0;
143 
144   /* resume debugee to catch MonitorContendedEntered event */
145   if (!((agent_resume_sync() == JNI_TRUE) && (agent_wait_for_sync(timeout) == JNI_TRUE))) {
146     return;
147   }
148 
149   LOG("Number of MonitorContendedEntered events: %d\n", eventsCount);
150 

 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 
 24 #include <stdio.h>
 25 #include <string.h>
 26 #include <jvmti.h>
 27 #include "jvmti_common.hpp"
 28 #include "jvmti_thread.hpp"
 29 
 30 extern "C" {
 31 
 32 /* ========================================================================== */
 33 
 34 /* scaffold objects */

 35 static jvmtiEnv *jvmti = nullptr;
 36 static jlong timeout = 0;
 37 
 38 /* test objects */
 39 static jthread expected_thread = nullptr;
 40 static jobject expected_object = nullptr;
 41 static volatile int eventsCount = 0;
 42 
 43 
 44 /* Check GetPotentialCapabilities function
 45  */
 46 void JNICALL
 47 MonitorContendedEntered(jvmtiEnv *jvmti, JNIEnv *jni, jthread thr, jobject obj) {
 48 
 49   LOG("MonitorContendedEntered event:\n\tthread: %p, object: %p, expected object: %p\n",thr, obj, expected_object);
 50 
 51   print_thread_info(jvmti, jni, thr);
 52 
 53   if (expected_thread == nullptr) {
 54     jni->FatalError("expected_thread is null.");

109     return JNI_FALSE;
110   }
111 
112   return JNI_TRUE;
113 }
114 
115 static int clean() {
116   jvmtiError err;
117   /* disable MonitorContendedEntered event */
118   err = jvmti->SetEventNotificationMode(JVMTI_DISABLE,JVMTI_EVENT_MONITOR_CONTENDED_ENTERED,nullptr);
119   if (err != JVMTI_ERROR_NONE) {
120     set_agent_fail_status();
121   }
122   return JNI_TRUE;
123 }
124 
125 /* agent algorithm
126  */
127 static void JNICALL
128 agentProc(jvmtiEnv *jvmti, JNIEnv *agentJNI, void *arg) {

129 
130 /* wait for initial sync */
131   if (!agent_wait_for_sync(timeout))
132     return;
133 
134   if (!prepare()) {
135     set_agent_fail_status();
136     return;
137   }
138 
139   /* clear events count */
140   eventsCount = 0;
141 
142   /* resume debugee to catch MonitorContendedEntered event */
143   if (!((agent_resume_sync() == JNI_TRUE) && (agent_wait_for_sync(timeout) == JNI_TRUE))) {
144     return;
145   }
146 
147   LOG("Number of MonitorContendedEntered events: %d\n", eventsCount);
148 
< prev index next >