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

Cross-header layout resolution does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • repo-panama
    • repo-panama
    • tools

      Consider the following headers:

      $ cat a.h

      #include "b.h"

      struct Foo {
         struct Bar bar;
         int x;
      };


      $ cat b.h

      struct Bar {
        int y;
      };


      Extract the headers as follows:

      jextract a.h -d classes

      Then consider the following program:

      $ cat TestUnresolved.java

      import java.foreign.*;

      class TestUnresolved {
         public static void main(String[] args) {
            try (Scope sc = Scope.globalScope().fork()) {
               sc.allocateStruct(a.Foo.class);
            }
         }
      }


      And run it like this:

      java -cp classes TestUnresolved.java

      The following exception will be reported:

      Exception in thread "main" java.lang.UnsupportedOperationException: bitsSize on Unresolved
      at java.base/java.foreign.layout.Unresolved.bitsSize(Unresolved.java:76)
      at java.base/java.util.stream.ReferencePipeline$5$1.accept(ReferencePipeline.java:229)
      at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948)
      at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
      at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
      at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913)
      at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
      at java.base/java.util.stream.LongPipeline.reduce(LongPipeline.java:474)
      at java.base/java.util.stream.LongPipeline.sum(LongPipeline.java:432)
      at java.base/java.foreign.layout.Group.bitsSize(Group.java:119)
      at java.base/java.foreign.memory.LayoutType.bytesSize(LayoutType.java:49)
      at java.base/jdk.internal.foreign.ScopeImpl.allocateInternal(ScopeImpl.java:130)
      at java.base/jdk.internal.foreign.ScopeImpl.allocate(ScopeImpl.java:156)
      at java.base/jdk.internal.foreign.ScopeImpl.allocateStruct(ScopeImpl.java:162)
      at TestUnresolved.main(TestUnresolved.java:6)


      That is, layout resolution fails, because the name "Bar" is defined in an header that is different from the one in which the unresolved reference "${Bar}" occurs.

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: