Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8295303

cleanup debug agent's confusing use of EI_GC_FINISH

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 20
    • 20
    • core-svc
    • b23

      The debug agent deals with 3 types of events: JVMTI (per the spec), JDWP (per the spec), and an event indexing that the debug agent refers to as EI (Event Index) events. We have the following EI_GC_FINISH event. Note there is no EI_CLASS_UNLOAD event:

              EI_GC_FINISH = 8,

      And here are various mappings between EI_GC_FINISH and JDWP and JVMTI events

        case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
            return EI_GC_FINISH;

        case JDWP_EVENT(CLASS_UNLOAD):
            return EI_GC_FINISH;

        index2jvmti[EI_GC_FINISH - EI_min] = JVMTI_EVENT_GARBAGE_COLLECTION_FINISH;

        index2jdwp[EI_GC_FINISH - EI_min] = JDWP_EVENT(CLASS_UNLOAD);

      So there is this odd relationship between EI_GC_FINISH and the JDWP CLASS_UNLOAD event. Note that JVMTI does not have a CLASS_UNLOAD (except for unused support in the extension mechanism), and JDWP has no GC_FINISH event.

      This relationship between EI_GC_FINISH and the JDWP CLASS_UNLOAD events likely stems from the fact that at one point JVMTI_EVENT_GARBAGE_COLLECTION_FINISH was used to trigger the synthesizing all of JDWP CLASS_UNLOAD events for classes that unloaded during the last GC. That is no longer the case, and instead each time a JVMTI OBJECT_FREE event is triggered for a Class instance, the JDWP CLASS_UNLOAD is generated.

      Since JDWP CLASS_UNLOAD maps to EI_GC_FINISH, we have the following:

          node = getHandlerChain(EI_GC_FINISH)->first;

      By looking at this line of code, you would never guess that this is how you fetch the event handler chain for JDWP CLASS_UNLOAD EventRequests, but it is.

      I think the best way to clean this up is to simply rename EI_GC_FINISH to EI_CLASS_UNLOAD. However, that still leaves the EI_GC_FINISH to JVMTI_EVENT_GARBAGE_COLLECTION_FINISH mapping to deal with. I think it is not needed. When we get a JVMTI_EVENT_GARBAGE_COLLECTION_FINISH, this is all we ever do with it:

      static void JNICALL
      cbGarbageCollectionFinish(jvmtiEnv *jvmti_env)
      {
          LOG_CB(("cbGarbageCollectionFinish"));
          ++garbageCollected;
          LOG_MISC(("END cbGarbageCollectionFinish"));
      }

      So the event is not passed around at all, and doesn't trigger other events or mapping to a JDWP event. It is never used as an "event index". This means jvmti2EventIndex should assert if it is ever passed in, since following mapping should never be needed:

              case JVMTI_EVENT_GARBAGE_COLLECTION_FINISH:
                  return EI_GC_FINISH;

            cjplummer Chris Plummer
            cjplummer Chris Plummer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: