You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2020/09/06 21:52:30 UTC

[GitHub] [lucene-solr] uschindler commented on a change in pull request #1837: LUCENE-7882: First idea of using Java 15 hidden anonymous classes for Lucene expressions

uschindler commented on a change in pull request #1837:
URL: https://github.com/apache/lucene-solr/pull/1837#discussion_r484117905



##########
File path: lucene/expressions/src/java/org/apache/lucene/expressions/js/JavascriptCompiler.java
##########
@@ -85,7 +88,33 @@
     }
   }
   
-  private static final int CLASSFILE_VERSION = Opcodes.V1_8;
+  /** Method handle to invoke Java 15's way to define hidden classes.
+   * The method handle uses a private lookup of {@link JavascriptCompiler} to define
+   * classes (this ensures we can create classes in our package without extra permissions).
+   * The classes are initialized and have no strong relationship to our classloader.
+   * This ensures they can be unloaded.
+   * Signature of MH: {@code static Lookup defineHiddenClass(byte[] bc)}
+   * The MH is {@code null} if an earlier JDK is used. 
+   * @see "https://openjdk.java.net/jeps/371"
+   */
+  private static final MethodHandle MH_defineHiddenClass;
+  static {
+    final Lookup publicLookup = MethodHandles.publicLookup();
+    MethodHandle mh;
+    try {
+      final Object emptyOptions = Array.newInstance(
+          publicLookup.findClass(Lookup.class.getName().concat("$ClassOption")), 0);
+      mh = publicLookup.findVirtual(Lookup.class, "defineHiddenClass",
+          MethodType.methodType(Lookup.class, byte[].class, boolean.class, emptyOptions.getClass()));
+      mh = mh.bindTo(MethodHandles.lookup()); // private lookup of JavascriptCompiler!
+      mh = MethodHandles.insertArguments(mh.asFixedArity(), 1, true, emptyOptions);
+    } catch (ReflectiveOperationException e) {
+      mh = null;
+    }
+    MH_defineHiddenClass = mh;
+  }
+  
+  private static final int CLASSFILE_VERSION = Opcodes.V11;

Review comment:
       Actually this should have been done on master already! We are on Java 11, so classfile format should be Java 11, too.




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

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



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