8005873: JRuby test_respond_to.rb asserts with: MT-unsafe modification of inline cache
Reviewed-by: vlivanov, jrose, psandoz
--- a/jdk/src/share/classes/java/lang/invoke/LambdaForm.java Tue Jun 03 12:52:59 2014 +0400
+++ b/jdk/src/share/classes/java/lang/invoke/LambdaForm.java Tue Jun 03 14:58:47 2014 +0400
@@ -607,7 +607,7 @@
assert(m.getName().equals("interpret" + sig.substring(sig.indexOf('_'))));
LambdaForm form = new LambdaForm(sig);
form.vmentry = m;
- mt.form().setCachedLambdaForm(MethodTypeForm.LF_COUNTER, form);
+ form = mt.form().setCachedLambdaForm(MethodTypeForm.LF_COUNTER, form);
// FIXME: get rid of PREPARED_FORMS; use MethodTypeForm cache only
forms.put(sig, form);
}
--- a/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java Tue Jun 03 12:52:59 2014 +0400
+++ b/jdk/src/share/classes/java/lang/invoke/MethodHandleImpl.java Tue Jun 03 14:58:47 2014 +0400
@@ -692,8 +692,7 @@
lform = new LambdaForm("guardWithCatch", lambdaType.parameterCount(), names);
- basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWC, lform);
- return lform;
+ return basicType.form().setCachedLambdaForm(MethodTypeForm.LF_GWC, lform);
}
static
--- a/jdk/src/share/classes/java/lang/invoke/MethodTypeForm.java Tue Jun 03 12:52:59 2014 +0400
+++ b/jdk/src/share/classes/java/lang/invoke/MethodTypeForm.java Tue Jun 03 14:58:47 2014 +0400
@@ -91,8 +91,10 @@
return lambdaForms[which];
}
- public LambdaForm setCachedLambdaForm(int which, LambdaForm form) {
- // Should we perform some sort of CAS, to avoid racy duplication?
+ synchronized public LambdaForm setCachedLambdaForm(int which, LambdaForm form) {
+ // Simulate a CAS, to avoid racy duplication of results.
+ LambdaForm prev = lambdaForms[which];
+ if (prev != null) return prev;
return lambdaForms[which] = form;
}