JDK-6565585 : (reflect) Method.invoke() has a needless critical section, causing large slowdowns
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-06-05
  • Updated: 2012-09-28
  • Resolved: 2011-05-17
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b138Fixed
Related Reports
Relates :  
Relates :  
Description
java.lang.reflect.Method.invoke has a critical section which it doesn't really need, and which slows it down.

While investigating 6565458 (a code generation problem) I noticed that the fix to 6446522 added synchronizations to the hot path of reflective invokes.  This successfully removed the race condition reported for 6446522, but made the generated code very complex.

I saw a simple way to speed up Method.invoke significantly by removing the critical section.  The 6565458 test case gets a 3X speedup, since that micro-benchmark is simple enough to inline everything.  As we improve our inlining heuristics, more use cases will see benefits from removing the critical section.

The critical section is also potentially a bottleneck in large concurrent systems.

Comments
PUBLIC COMMENTS Updated webrev http://cr.openjdk.java.net/~mduigou/6565585/1/webrev/
22-03-2011

SUGGESTED FIX Webrev posted to : http://cr.openjdk.java.net/~mduigou/6565585/0/webrev/ Message posted to core-dev: http://mail.openjdk.java.net/pipermail/core-libs-dev/2011-March/006227.html
17-03-2011

PUBLIC COMMENTS Webrev posted to : http://cr.openjdk.java.net/~mduigou/6565585/0/webrev/ Message posted to core-dev: http://mail.openjdk.java.net/pipermail/core-libs-dev/2011-March/006227.html
17-03-2011

SUGGESTED FIX I have updated both patches and separated out the microbenchmarks to match current jdk7 source. jtreg for jdk/test/java/lang jdk/test/java/util passes for both patches. The two patches are both solutions to the problem. The 'Method.patch.zip' patch modifies only java.lang.reflect.Method whereas 'AccessibleObject.patch.zip' modifies java.lang.reflect.{AccessibleObject|Constructor|Field|Method} using the same technique as used for the Method only patch. Barring objections I will publish the more general patch as a webrev to core-dev on Thursday March 17th, 2011.
15-03-2011

EVALUATION Provided patch should be applied.
20-06-2007

SUGGESTED FIX Attached is a patch which replaces the synchronizations by volatile references. It also refactors all the slow code out of the method, which helps the JIT's inlining heuristics. With the current heuristics, the slimmer method is less likely to fall afoul of bug 6565458 and similar failure modes. Finally, the changes remove a doubled reference to another volatile variable. This also simplifies the generated code by commoning up the corresponding load instruction used in the fast execution path
05-06-2007