--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Thu Jan 29 10:27:30 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandle.java Thu Jan 29 10:27:30 2015 -0800
@@ -434,6 +434,8 @@
// 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.
@@ -454,9 +456,9 @@
type.getClass(); // explicit NPE
form.getClass(); // explicit NPE
this.type = type;
- this.form = form;
+ this.form = form.uncustomize();
- form.prepare(); // TO DO: Try to delay this step until just before invocation.
+ this.form.prepare(); // TO DO: Try to delay this step until just before invocation.
}
/**
@@ -1425,12 +1427,24 @@
*/
/*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 {