Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7902718

JDK-8247444 protections for Record offsets break JOL introspection

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • None
    • None
    • tools
    • None
    • jol

    Description

      $ cat MyRecord.java
      record MyRecord(int x, int y) {}
      $ jdk-jdk-ea/bin/javac --enable-preview --release 16 MyRecord.java
      $ jdk-jdk-ea/bin/java --enable-preview -jar jol-cli/target/jol-cli.jar internals MyRecord -cp .
      # WARNING: Unable to get Instrumentation. Dynamic Attach failed. You may add this JAR as -javaagent manually, or supply -Djdk.attach.allowAttachSelf
      # WARNING: Unable to attach Serviceability Agent. You can try again with escalated privileges. Two options: a) use -Djol.tryWithSudo=true to try with sudo; b) echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
      # Running 64-bit HotSpot VM.
      # Using compressed oop with 3-bit shift.
      # Using compressed klass with 3-bit shift.
      # WARNING | Compressed references base/shifts are guessed by the experiment!
      # WARNING | Therefore, computed addresses are just guesses, and ARE NOT RELIABLE.
      # WARNING | Make sure to attach Serviceability Agent to get the reliable addresses.
      # Objects are 8 bytes aligned.
      # Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
      # Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]

      Instantiated the sample instance via MyRecord(int,int)

      java.lang.UnsupportedOperationException: can't get field offset on a record (preview): private final int MyRecord.x
      at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:649)
      at org.openjdk.jol.vm.HotspotUnsafe.fieldOffset(HotspotUnsafe.java:412)
      at org.openjdk.jol.layouters.CurrentLayouter.layout(CurrentLayouter.java:66)
      at org.openjdk.jol.info.ClassLayout.parseInstance(ClassLayout.java:100)
      at org.openjdk.jol.info.ClassLayout.parseInstance(ClassLayout.java:83)
      at org.openjdk.jol.operations.ObjectInternals.runWith(ObjectInternals.java:51)
      at org.openjdk.jol.operations.ClasspathedOperation.run(ClasspathedOperation.java:76)

      This is because JDK-8247444 introduced this check:
      https://hg.openjdk.java.net/jdk/jdk/file/ae002489df78/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java#l640

      This can be side-stepped for JOL uses that only needs to take a look at Record field/components offset.

      Attachments

        Issue Links

          Activity

            People

              shade Aleksey Shipilev
              shade Aleksey Shipilev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: