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

   Finally here is an example Classfile output with this PR for this code: 
   
   ```java
     public void testNamespacesWithoutDirectMH() throws Exception {
       Map<String, MethodHandle> functions =
           Map.of(
               "foo.bar",
               MethodHandles.constant(double.class, 9),
               "bar.foo",
               MethodHandles.identity(double.class));
       Expression expr = compile("foo.bar() + bar.foo(7)", functions);
       assertEquals(16, expr.evaluate(null), DELTA);
     }
   ```
   
   ```
   //  (version 24 : 68.0, no super bit)
   public final class 
org.apache.lucene.expressions.js.JavascriptCompiler$CompiledExpression extends 
org.apache.lucene.expressions.Expression {
     
     // Method descriptor #6 (Ljava/lang/String;[Ljava/lang/String;)V
     // Stack: 3, Locals: 3
     public JavascriptCompiler$CompiledExpression(java.lang.String arg0, 
java.lang.String[] arg1);
       0  aload_0 [this]
       1  aload_1 [arg0]
       2  aload_2 [arg1]
       3  invokespecial 
org.apache.lucene.expressions.Expression(java.lang.String, java.lang.String[]) 
[8]
       6  return
   
     
     // Method descriptor #10 ([Lorg/apache/lucene/search/DoubleValues;)D
     // Stack: 5, Locals: 2
     public double evaluate(org.apache.lucene.search.DoubleValues[] arg0) 
throws java.io.IOException;
        0  ldc <Dynamic> 0 func0 java.lang.invoke.MethodHandle [23]
        2  invokevirtual java.lang.invoke.MethodHandle.invokeExact() : double 
[29]
        5  ldc <Dynamic> 1 func1 java.lang.invoke.MethodHandle [34]
        7  ldc2_w <Double 7.0> [35]
       10  invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) : 
double [39]
       13  dadd
       14  dreturn
       15  aload_0 [this]
       16  invokestatic 
org.apache.lucene.expressions.js.JavascriptCompiler.patchStackTrace(java.lang.Throwable,
 org.apache.lucene.expressions.Expression) : java.lang.Throwable [45]
       19  athrow
         Exception Table:
           [pc: 0, pc: 15] -> 15 when : java.lang.Throwable
         Stack map table: number of frames 1
           [pc: 15, same_locals_1_stack_item, stack: {java.lang.Throwable}]
   
   Bootstrap methods:
     0 : # 19 invokestatic 
org/apache/lucene/expressions/js/JavascriptCompiler.dynamicConstantBootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/invoke/MethodHandle;
        Method arguments:
                #12 foo.bar,
     1 : # 19 invokestatic 
org/apache/lucene/expressions/js/JavascriptCompiler.dynamicConstantBootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/invoke/MethodHandle;
        Method arguments:
                #31 bar.foo
   }
   ```
   
   The previous version as generated by the old code in branch_10x is:
   
   ```
   //  (version 21 : 65.0, super bit)
   public final class 
org.apache.lucene.expressions.js.JavascriptCompiler$CompiledExpression extends 
org.apache.lucene.expressions.Expression {
     
     // Method descriptor #6 (Ljava/lang/String;[Ljava/lang/String;)V
     // Stack: 3, Locals: 3
     public JavascriptCompiler$CompiledExpression(java.lang.String arg0, 
java.lang.String[] arg1);
       0  aload_0 [this]
       1  aload_1 [arg0]
       2  aload_2 [arg1]
       3  invokespecial 
org.apache.lucene.expressions.Expression(java.lang.String, java.lang.String[]) 
[8]
       6  return
   
     
     // Method descriptor #10 ([Lorg/apache/lucene/search/DoubleValues;)D
     // Stack: 5, Locals: 2
     public double evaluate(org.apache.lucene.search.DoubleValues[] arg0) 
throws java.io.IOException;
        0  ldc <Dynamic> 0 func0 java.lang.invoke.MethodHandle [27]
        2  invokevirtual java.lang.invoke.MethodHandle.invokeExact() : double 
[33]
        5  ldc <Dynamic> 1 func1 java.lang.invoke.MethodHandle [38]
        7  ldc2_w <Double 7.0> [39]
       10  invokevirtual java.lang.invoke.MethodHandle.invokeExact(double) : 
double [43]
       13  dadd
       14  dreturn
       15  aload_0 [this]
       16  invokestatic 
org.apache.lucene.expressions.js.JavascriptCompiler.patchStackTrace(java.lang.Throwable,
 org.apache.lucene.expressions.Expression) : java.lang.Throwable [47]
       19  athrow
         Exception Table:
           [pc: 0, pc: 14] -> 15 when : java.lang.Throwable
         Stack map table: number of frames 1
           [pc: 15, same_locals_1_stack_item, stack: {java.lang.Throwable}]
   
   Bootstrap methods:
     0 : # 23 invokestatic 
org/apache/lucene/expressions/js/JavascriptCompiler.dynamicConstantBootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/invoke/MethodHandle;
        Method arguments:
                #16 foo.bar,
     1 : # 23 invokestatic 
org/apache/lucene/expressions/js/JavascriptCompiler.dynamicConstantBootstrap:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/invoke/MethodHandle;
        Method arguments:
                #35 bar.foo
   }
   ```
   
   This is the same code, all operators are identical. Only differences in 
constant pool. The changes here are only the class flags no longer having 
obsolete `ACC_SUPER` and the Classfile API automatically generates class files 
for the current Java version (no need to configure anything).


-- 
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