src/java.base/share/classes/java/lang/invoke/MethodHandle.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Cdiff src/java.base/share/classes/java/lang/invoke/MethodHandle.java

src/java.base/share/classes/java/lang/invoke/MethodHandle.java

Print this page
rev 11258 : 8069591: Customize LambdaForms which are invoked using MH.invoke/invokeExact
Reviewed-by: ?

*** 432,441 **** --- 432,443 ---- private final MethodType type; /*private*/ final LambdaForm form; // form is not private so that invokers can easily fetch it /*private*/ MethodHandle asTypeCache; // asTypeCache is not private so that invokers can easily fetch it + /*non-public*/ byte customizationCount; + // customizationCount should be accessible from invokers /** * Reports the type of this method handle. * Every invocation of this method handle via {@code invokeExact} must exactly match this type. * @return the method handle type
*** 452,464 **** // @param type type (permanently assigned) of the new method handle /*non-public*/ MethodHandle(MethodType type, LambdaForm form) { type.getClass(); // explicit NPE form.getClass(); // explicit NPE this.type = type; ! this.form = form; ! form.prepare(); // TO DO: Try to delay this step until just before invocation. } /** * Invokes the method handle, allowing any caller type descriptor, but requiring an exact type match. * The symbolic type descriptor at the call site of {@code invokeExact} must --- 454,466 ---- // @param type type (permanently assigned) of the new method handle /*non-public*/ MethodHandle(MethodType type, LambdaForm form) { type.getClass(); // explicit NPE form.getClass(); // explicit NPE this.type = type; ! this.form = form.uncustomize(); ! this.form.prepare(); // TO DO: Try to delay this step until just before invocation. } /** * Invokes the method handle, allowing any caller type descriptor, but requiring an exact type match. * The symbolic type descriptor at the call site of {@code invokeExact} must
*** 1423,1438 **** --- 1425,1452 ---- * but it is likely that the new one will be preferred for new executions. * Use with discretion. */ /*non-public*/ void updateForm(LambdaForm newForm) { + assert(newForm.customized == null || newForm.customized == this); if (form == newForm) return; newForm.prepare(); // as in MethodHandle.<init> UNSAFE.putObject(this, FORM_OFFSET, newForm); UNSAFE.fullFence(); } + /** Craft a LambdaForm customized for this particular MethodHandle */ + /*non-public*/ + void customize() { + if (form.customized == null) { + LambdaForm newForm = form.customize(this); + updateForm(newForm); + } else { + assert(form.customized == this); + } + } + private static final long FORM_OFFSET; static { try { FORM_OFFSET = UNSAFE.objectFieldOffset(MethodHandle.class.getDeclaredField("form")); } catch (ReflectiveOperationException ex) {
src/java.base/share/classes/java/lang/invoke/MethodHandle.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File