uschindler commented on PR #15089:
URL: https://github.com/apache/lucene/pull/15089#issuecomment-3200079780

   > I have a backport ready and will open a PR when it confirms to work. The 
backport is two fold:
   > 
   > * The ByteBuffer varhandle is generated refelctively
   > * The MemorySegment one is in the Java 21 Sourceset, so it can use the new 
Method. I just had to extract the API of MethodHandles class, too.
   > 
   > So basically it is still minimal-invasive in 10.x.
   
   Small correction: The backuport for the MemorySegemnt part is more 
complicated, because retrieving the VarHandle in the preview API is different 
that in the released Java 22+ API. I havea solution, will post a PR for 
backporting later.
   
   But let's see how it works for main (if it worth backporting).
   
   The issue is described in this helper method:
   
   ```java
     /**
      * Hack: The preview API changed after release in Java 22:
      * <ul>
      * <li>In Java 21 the preview API requires {@code 
MethodHandles#memorySegmentViewVarHandle(layout)}.
      * <li>In the released API (Java 22) it requires to use {@code 
layout.varHandle()}, which includes the offset coordinate.
      * </ul>
      * The new API existed before, but with different semantics, so we lookup 
the first one and
      * if the method does not exist (we can compile against our stubs and see 
it, but at runtime
      * it may have disappeared), we use the new API.
      */
     private static VarHandle getLayoutVarHandle(ValueLayout layout) {
       try {
         return MethodHandles.memorySegmentViewVarHandle(layout);
       } catch (@SuppressWarnings("unused") NoSuchMethodError e) {
         return layout.varHandle();
       }
     }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to