< prev index next >

src/jdk.jdwp.agent/share/native/libjdwp/eventHelper.c

Print this page

        

@@ -282,31 +282,43 @@
     debugMonitorNotifyAll(commandQueueLock);
     debugMonitorExit(commandQueueLock);
 }
 
 static void
+writeThreadOrFiber(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
+{
+    /*
+     * Write the fiber ref if the event matched a fiber filter, or if the event was not
+     * filtered by thread, and came in on a carrier thread running a fiber. In either
+     * case evinfo->matchesFiber will be true.
+     */
+    jthread thread = (evinfo->matchesFiber ? evinfo->fiber : evinfo->thread);
+    (void)outStream_writeObjectRef(env, out, thread);
+}
+
+static void
 writeSingleStepEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
 {
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
 }
 
 static void
 writeBreakpointEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
 {
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
 }
 
 static void
 writeFieldAccessEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
 {
     jbyte fieldClassTag;
 
     fieldClassTag = referenceTypeTag(evinfo->u.field_access.field_clazz);
 
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
     (void)outStream_writeByte(out, fieldClassTag);
     (void)outStream_writeObjectRef(env, out, evinfo->u.field_access.field_clazz);
     (void)outStream_writeFieldID(out, evinfo->u.field_access.field);
     (void)outStream_writeObjectTag(env, out, evinfo->object);

@@ -319,11 +331,11 @@
 {
     jbyte fieldClassTag;
 
     fieldClassTag = referenceTypeTag(evinfo->u.field_modification.field_clazz);
 
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
     (void)outStream_writeByte(out, fieldClassTag);
     (void)outStream_writeObjectRef(env, out, evinfo->u.field_modification.field_clazz);
     (void)outStream_writeFieldID(out, evinfo->u.field_modification.field);
     (void)outStream_writeObjectTag(env, out, evinfo->object);

@@ -333,29 +345,29 @@
 }
 
 static void
 writeExceptionEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
 {
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     writeCodeLocation(out, evinfo->clazz, evinfo->method, evinfo->location);
     (void)outStream_writeObjectTag(env, out, evinfo->object);
     (void)outStream_writeObjectRef(env, out, evinfo->object);
     writeCodeLocation(out, evinfo->u.exception.catch_clazz,
                       evinfo->u.exception.catch_method, evinfo->u.exception.catch_location);
 }
 
 static void
 writeThreadEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
 {
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
 }
 
 static void
 writeMonitorEvent(JNIEnv *env, PacketOutputStream *out, EventInfo *evinfo)
 {
     jclass klass;
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     (void)outStream_writeObjectTag(env, out, evinfo->object);
     (void)outStream_writeObjectRef(env, out, evinfo->object);
     if (evinfo->ei == EI_MONITOR_WAIT || evinfo->ei == EI_MONITOR_WAITED) {
         /* clazz of evinfo was set to class of monitor object for monitor wait event class filtering.
          * So get the method class to write location info.

@@ -390,11 +402,11 @@
     if (error != JVMTI_ERROR_NONE) {
         EXIT_ERROR(error,"signature");
     }
     status = classStatus(evinfo->clazz);
 
-    (void)outStream_writeObjectRef(env, out, evinfo->thread);
+    writeThreadOrFiber(env, out, evinfo);
     (void)outStream_writeByte(out, classTag);
     (void)outStream_writeObjectRef(env, out, evinfo->clazz);
     (void)outStream_writeString(out, signature);
     (void)outStream_writeInt(out, map2jdwpClassStatus(status));
     jvmtiDeallocate(signature);

@@ -432,10 +444,23 @@
             break;
         case EI_THREAD_START:
         case EI_THREAD_END:
             writeThreadEvent(env, out, evinfo);
             break;
+        case EI_FIBER_SCHEDULED:
+        case EI_FIBER_TERMINATED:
+            /* Note that when we wrote the evinfo->ei byte above, it was mapped to an EI_THREAD_XXX event
+             * by eventIndex2jdwp(), so we didn't actually write the FIBER ei byte.
+             */
+            writeThreadEvent(env, out, evinfo);
+            break;
+        case EI_FIBER_MOUNT:
+        case EI_FIBER_UNMOUNT:
+        case EI_CONTINUATION_RUN:
+        case EI_CONTINUATION_YIELD:
+            EXIT_ERROR(AGENT_ERROR_INVALID_EVENT_TYPE, "invalid event index");
+            break;
         case EI_CLASS_LOAD:
         case EI_CLASS_PREPARE:
             writeClassEvent(env, out, evinfo);
             break;
         case EI_MONITOR_CONTENDED_ENTER:

@@ -812,13 +837,15 @@
 /* Change all references to global in the EventInfo struct */
 static void
 saveEventInfoRefs(JNIEnv *env, EventInfo *evinfo)
 {
     jthread *pthread;
+    jthread *pfiber;
     jclass *pclazz;
     jobject *pobject;
     jthread thread;
+    jthread fiber;
     jclass clazz;
     jobject object;
     char sig;
 
     JNI_FUNC_PTR(env,ExceptionClear)(env);

@@ -827,10 +854,16 @@
         pthread = &(evinfo->thread);
         thread = *pthread;
         *pthread = NULL;
         saveGlobalRef(env, thread, pthread);
     }
+    if ( evinfo->fiber != NULL ) {
+        pfiber = &(evinfo->fiber);
+        fiber = *pfiber;
+        *pfiber = NULL;
+        saveGlobalRef(env, fiber, pfiber);
+    }
     if ( evinfo->clazz != NULL ) {
         pclazz = &(evinfo->clazz);
         clazz = *pclazz;
         *pclazz = NULL;
         saveGlobalRef(env, clazz, pclazz);

@@ -890,10 +923,13 @@
 {
     char sig;
     if ( evinfo->thread != NULL ) {
         tossGlobalRef(env, &(evinfo->thread));
     }
+    if ( evinfo->fiber != NULL ) {
+        tossGlobalRef(env, &(evinfo->fiber));
+    }
     if ( evinfo->clazz != NULL ) {
         tossGlobalRef(env, &(evinfo->clazz));
     }
     if ( evinfo->object != NULL ) {
         tossGlobalRef(env, &(evinfo->object));

@@ -1042,16 +1078,16 @@
     return suspendPolicy;
 }
 
 void
 eventHelper_recordEvent(EventInfo *evinfo, jint id, jbyte suspendPolicy,
-                         struct bag *eventBag)
+                        struct bag *eventBag)
 {
     JNIEnv *env = getEnv();
     CommandSingle *command = bagAdd(eventBag);
     if (command == NULL) {
-        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"badAdd(eventBag)");
+        EXIT_ERROR(AGENT_ERROR_OUT_OF_MEMORY,"bagAdd(eventBag)");
     }
 
     command->singleKind = COMMAND_SINGLE_EVENT;
     command->u.eventCommand.suspendPolicy = suspendPolicy;
     command->u.eventCommand.id = id;
< prev index next >