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

JFR EventWriter does not use first string from StringPool with id 0

    XMLWordPrintable

    Details

    • Subcomponent:
      jfr
    • Resolved In Build:
      b25

      Backports

        Description

        src/jdk.jfr/share/classes/jdk/jfr/internal/StringPool.java indexes from 0 for string pool entries with:

        private final AtomicLong sidIdx = new AtomicLong();

        and entries obtained via:

        long sid = this.sidIdx.getAndIncrement();

        src/jdk.jfr/share/classes/jdk/jfr/internal/EventWriter.java writes string pool entries with:


                    long l = StringPool.addString(s);
                    if (l > 0) {
                         ...
                    }

        The first entry to the StringPool will have id 0 but will never be used for events using the EventWriter. This can be seen with a test application that repeatedly emits a custom event with string field. The string will be in the constant pool, but the actual event data will have written the entire string out.

        Something like:

        import java.lang.annotation.Annotation;
        import java.lang.reflect.Field;
        import java.lang.reflect.Method;
        import java.nio.file.Files;
        import java.util.Arrays;

        import jdk.jfr.Configuration;
        import jdk.jfr.FlightRecorder;
        import jdk.jfr.Recording;
        import jdk.jfr.Description;
        import jdk.jfr.Enabled;
        import jdk.jfr.Event;
        import jdk.jfr.Label;

        public class EventCommit {

            @Label("Basic Event")
            @Description("An event with just a message as payload")
            static class BasicEvent extends Event {
                @Label("Message")
                public String message;
            }

            public static void main(String[] args) {
                try {
                    Configuration c = Configuration.getConfiguration("default");
                    Recording r = new Recording(c);
                    r.start();
                    for (int i = 0; i < 10; i++) {
                        BasicEvent event = new BasicEvent();
                        event.message = "123456789010111213141516";
                        event.commit();
                    }
                    r.stop();
                    r.dump(Files.createTempFile("my-recording", ".jfr"));
                    r.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                jkang Jie Kang
                Reporter:
                jkang Jie Kang
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: