commit | 5b3ce4393966dc797e4fe8171ea78c072632a204 | [log] [tgz] |
---|---|---|
author | Carsten Hammer <carsten.hammer@t-online.de> | Tue Dec 08 21:11:32 2020 +0100 |
committer | Jeff Johnston <jjohnstn@redhat.com> | Thu Mar 24 17:37:16 2022 -0400 |
tree | a0a2630b29d7346e3e4f38d645375fcb12d489e2 | |
parent | d98d99584bea6e6bbb1ab9f25420216c910c6901 [diff] |
Bug 569562 - use double-check locking idiom for performance Reduce synchronization scope for few methods to the minimum according to the well known double-check idiom. The duration of the test org.eclipse.jdt.ui.tests.quickfix.CleanUpStressTest.testAllCleanUps() drops a few seconds with this change. Besides there are a few cases where methods are changed that did not use the synchronize keyword. It should not be slower this way but safer. But it is not clear if it really is needed. Basically this change should have been applied already when the code was migrated to depend as minimum on java 5. I did not change all code affected but a few cases. Here a quote from Joshua Bloch (see last link) If you need high-performance lazy initializing of an instance field, use the double-check idiom with a volatile field. This idiom wasn't guaranteed to work until release 5.0, when the platform got a new memory model. The idiom is very fast but also complicated and delicate, so don't be tempted to modify it in any way. Just copy and paste -- normally not a good idea, but appropriate here: // Double-check idiom for lazy initialization of instance fields private volatile FieldType field; private FieldType getField() { FieldType result = field; if (result != null) // First check (no locking) return result; synchronized(this) { if (field == null) // Second check (with locking) field = computeFieldValue(); return field; } } see https://docs.google.com/document/d/1mAeEgQu4H4ADxa03k7YaVDjIP5vJBvjVIjg3DIvoc8E/edit don't use https://www.oracle.com/technical-resources/articles/javase/bloch-effective-08-qa.html Change-Id: I7eb783a7feef0d544fcbd4c30938668032be8b12 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de> Reviewed-on: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/173560 Tested-by: JDT Bot <jdt-bot@eclipse.org> Reviewed-by: Jeff Johnston <jjohnstn@redhat.com>
Thanks for your interest in this project.
The JDT UI implements the user interface for the Java IDE. This includes views like Package Explorer and JUnit, the Java and properties files editors, Java search, and refactorings. Website: http://www.eclipse.org/jdt/ui/
Contributions to JDT UI are most welcome. There are many ways to contribute, from entering high quality bug reports, to contributing code or documentation changes. For a complete guide, see the [How to Contribute] 1 page on the team wiki.
Information regarding source code management, builds, coding standards, and more.
Before your contribution can be accepted by the project, you need to create and electronically sign the Eclipse Foundation Contributor License Agreement (CLA).
Public forum for Eclipse JDT users.
This project uses Bugzilla to track ongoing development and issues.
Be sure to search for existing bugs before you create another one. Remember that contributions are always welcome!
Contact the project developers via the project's “dev” list.