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

JFR: getField(String) should be able to access nested fields

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 16
    • hotspot
    • None
    • jfr
    • behavioral
    • minimal
    • Users are not able to create fields with "." in the name, so there can be no ambiguity. Non-nested field access will work exactly as before
    • Java API
    • JDK

      Summary

      Clarify that RecordedObject::hasField(String) can access nested fields and add support for nested field access to EventType::getField(String).

      Problem

      JDK Flight Recorder can emit events with composite/struct values, for example methods and classes. To index into a nested value it is possible to use a ".", for example RecordedEvent::getValue("allocatedClass.name").

      It is however not possible to access metadata about a value the same way, for example RecordedObject::hasField("allocatedClass.name") or EventType::getField("allocationClass.name"). This is inconvenient if you want to check if a field exist before you call getValue(String), or if you want to access metadata about a value, for example the unit.

      Solution

      The solution is to update the specification for RecordedObject:hasField(String) so it says that it is possible to use nested access, the implementation already supports it.

      Also add support for nested field access for EventType::getField(String) and update the specification accordingly.

      Specification

      jdk.jfr.RecordedObject

       /**
         * Returns {@code true} if a field with the given name exists,  {@code false} otherwise.
      +  * <p>
      +  * It's possible to index into a nested field by using {@code "."} (for
      +  * instance {@code "thread.group.parent.name}").
         *
         * @param name name of the field to get, not {@code null}
         *
         * @return {@code true} if the field exists, {@code false} otherwise
         *
         * @see #getFields()
         */
        public boolean hasField(String name) {

      jdk.jfr.EventType

       /**
         * Returns the field with the specified name, or {@code null} if it doesn't
         * exist.
      +  * <p>
      +  * It's possible to index into a nested field by using {@code "."} (for
      +  * instance {@code "thread.group.parent.name}").
         *
         * @param name of the field to get, not {@code null}
         *
        * @return a value descriptor that describes the field, or {@code null} if
        *         the field with the specified name doesn't exist
        */
       public ValueDescriptor getField(String name) {

            egahlin Erik Gahlin
            egahlin Erik Gahlin
            Markus Grönlund
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: