From a4e56e3824145b58014de20de8a8da76ad875a62 Mon Sep 17 00:00:00 2001 From: Eclipse glassfish Bot Date: Thu, 25 Jan 2024 15:37:56 +0000 Subject: [PATCH 01/10] Prepare release org.glassfish.hk2:hk2-parent:3.0.6 --- bom/pom.xml | 2 +- class-model/pom.xml | 2 +- examples/caching/pom.xml | 2 +- examples/caching/runner/pom.xml | 2 +- examples/caching/system/pom.xml | 2 +- examples/configuration/pom.xml | 2 +- examples/configuration/webserver/pom.xml | 2 +- examples/configuration/xml/pom.xml | 2 +- examples/custom-resolver/pom.xml | 2 +- examples/events/pom.xml | 2 +- examples/events/threaded/pom.xml | 2 +- examples/operations/pom.xml | 2 +- examples/pom.xml | 2 +- examples/security-lockdown/alice/pom.xml | 2 +- examples/security-lockdown/mallory/pom.xml | 2 +- examples/security-lockdown/pom.xml | 2 +- examples/security-lockdown/runner/pom.xml | 2 +- examples/security-lockdown/system/pom.xml | 2 +- external/aopalliance/pom.xml | 2 +- external/pom.xml | 2 +- guice-bridge/pom.xml | 2 +- hk2-api/pom.xml | 2 +- hk2-configuration/hk2-integration/pom.xml | 2 +- hk2-configuration/manager/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/integration-test/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/main/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/schema/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/test1/pom.xml | 2 +- hk2-configuration/persistence/pom.xml | 2 +- hk2-configuration/persistence/property-file/pom.xml | 2 +- hk2-configuration/pom.xml | 2 +- hk2-core/pom.xml | 2 +- hk2-extras/pom.xml | 2 +- hk2-jmx/pom.xml | 2 +- hk2-locator/pom.xml | 2 +- hk2-metadata-generator/main/pom.xml | 2 +- hk2-metadata-generator/pom.xml | 2 +- hk2-metadata-generator/test1/pom.xml | 2 +- hk2-runlevel/pom.xml | 2 +- hk2-testing/ant/pom.xml | 2 +- hk2-testing/collections/pom.xml | 2 +- hk2-testing/di-tck/pom.xml | 2 +- hk2-testing/hk2-junitrunner/pom.xml | 2 +- hk2-testing/hk2-locator-extras/pom.xml | 2 +- hk2-testing/hk2-locator-no-proxies/pom.xml | 2 +- hk2-testing/hk2-locator-no-proxies2/pom.xml | 2 +- hk2-testing/hk2-mockito/pom.xml | 2 +- hk2-testing/hk2-runlevel-extras/pom.xml | 2 +- hk2-testing/hk2-testng/pom.xml | 2 +- hk2-testing/interceptor-events/pom.xml | 2 +- hk2-testing/jersey/jersey-guice/form-param/pom.xml | 2 +- hk2-testing/jersey/jersey-guice/pom.xml | 2 +- hk2-testing/jersey/pom.xml | 2 +- hk2-testing/pom.xml | 2 +- hk2-utils/pom.xml | 2 +- hk2/pom.xml | 2 +- javadocs/pom.xml | 2 +- maven-plugins/consolidatedbundle-maven-plugin/pom.xml | 2 +- maven-plugins/hk2-inhabitant-generator/pom.xml | 2 +- maven-plugins/osgiversion-maven-plugin/pom.xml | 2 +- maven-plugins/pom.xml | 2 +- osgi/adapter-tests/contract-bundle/pom.xml | 2 +- osgi/adapter-tests/faux-sdp-bundle/pom.xml | 2 +- osgi/adapter-tests/no-hk2-bundle/pom.xml | 2 +- osgi/adapter-tests/osgi-adapter-test/pom.xml | 2 +- osgi/adapter-tests/pom.xml | 2 +- osgi/adapter-tests/sdp-management-bundle/pom.xml | 2 +- osgi/adapter-tests/test-module-startup/pom.xml | 2 +- osgi/adapter/pom.xml | 2 +- osgi/pom.xml | 2 +- pom.xml | 2 +- spring-bridge/pom.xml | 2 +- 75 files changed, 75 insertions(+), 75 deletions(-) diff --git a/bom/pom.xml b/bom/pom.xml index aab18ecd59..6a6bc6d7e6 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -30,7 +30,7 @@ org.glassfish.hk2 hk2-bom - 3.0.6-SNAPSHOT + 3.0.6 pom HK2 Bom Pom diff --git a/class-model/pom.xml b/class-model/pom.xml index 7a9b8ad38b..de463657a5 100644 --- a/class-model/pom.xml +++ b/class-model/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/examples/caching/pom.xml b/examples/caching/pom.xml index f16586d363..2f2afa3cb6 100644 --- a/examples/caching/pom.xml +++ b/examples/caching/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6-SNAPSHOT + 3.0.6 caching-aop-example diff --git a/examples/caching/runner/pom.xml b/examples/caching/runner/pom.xml index 6e63fb69bc..ad221e1f62 100644 --- a/examples/caching/runner/pom.xml +++ b/examples/caching/runner/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 caching-aop-example - 3.0.6-SNAPSHOT + 3.0.6 caching-aop-example-runner diff --git a/examples/caching/system/pom.xml b/examples/caching/system/pom.xml index 940b2a06f2..fa70800bda 100644 --- a/examples/caching/system/pom.xml +++ b/examples/caching/system/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 caching-aop-example - 3.0.6-SNAPSHOT + 3.0.6 caching-aop-example-system diff --git a/examples/configuration/pom.xml b/examples/configuration/pom.xml index 35c71f5f7d..20a54e4330 100644 --- a/examples/configuration/pom.xml +++ b/examples/configuration/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6-SNAPSHOT + 3.0.6 configuration-examples diff --git a/examples/configuration/webserver/pom.xml b/examples/configuration/webserver/pom.xml index f4c4c9af31..f9e44a640f 100644 --- a/examples/configuration/webserver/pom.xml +++ b/examples/configuration/webserver/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 configuration-examples - 3.0.6-SNAPSHOT + 3.0.6 webserver-configuration-example diff --git a/examples/configuration/xml/pom.xml b/examples/configuration/xml/pom.xml index 40227ad78d..e618d42040 100644 --- a/examples/configuration/xml/pom.xml +++ b/examples/configuration/xml/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 configuration-examples - 3.0.6-SNAPSHOT + 3.0.6 xml-configuration-example diff --git a/examples/custom-resolver/pom.xml b/examples/custom-resolver/pom.xml index 784a3b8dc7..cbf258311b 100644 --- a/examples/custom-resolver/pom.xml +++ b/examples/custom-resolver/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 examples - 3.0.6-SNAPSHOT + 3.0.6 custom-resolver-example diff --git a/examples/events/pom.xml b/examples/events/pom.xml index 49564b69d1..c6acac15fd 100644 --- a/examples/events/pom.xml +++ b/examples/events/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6-SNAPSHOT + 3.0.6 event-examples diff --git a/examples/events/threaded/pom.xml b/examples/events/threaded/pom.xml index a68923a456..27c3c92e27 100644 --- a/examples/events/threaded/pom.xml +++ b/examples/events/threaded/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 event-examples - 3.0.6-SNAPSHOT + 3.0.6 threading-event-example diff --git a/examples/operations/pom.xml b/examples/operations/pom.xml index 82de39e2a3..9b4f19e11c 100644 --- a/examples/operations/pom.xml +++ b/examples/operations/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 examples - 3.0.6-SNAPSHOT + 3.0.6 operations-example diff --git a/examples/pom.xml b/examples/pom.xml index 702f8513f1..7c4dd83ada 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 examples diff --git a/examples/security-lockdown/alice/pom.xml b/examples/security-lockdown/alice/pom.xml index 6e7c55d418..1d7d8d216c 100644 --- a/examples/security-lockdown/alice/pom.xml +++ b/examples/security-lockdown/alice/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6-SNAPSHOT + 3.0.6 security-lockdown-example-alice diff --git a/examples/security-lockdown/mallory/pom.xml b/examples/security-lockdown/mallory/pom.xml index fa9ccf42e0..0a84ec068e 100644 --- a/examples/security-lockdown/mallory/pom.xml +++ b/examples/security-lockdown/mallory/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6-SNAPSHOT + 3.0.6 security-lockdown-example-mallory diff --git a/examples/security-lockdown/pom.xml b/examples/security-lockdown/pom.xml index 2b53a432a6..9e0390c03a 100644 --- a/examples/security-lockdown/pom.xml +++ b/examples/security-lockdown/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6-SNAPSHOT + 3.0.6 security-lockdown-example diff --git a/examples/security-lockdown/runner/pom.xml b/examples/security-lockdown/runner/pom.xml index ba4cd45a07..eb7b7dd910 100644 --- a/examples/security-lockdown/runner/pom.xml +++ b/examples/security-lockdown/runner/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6-SNAPSHOT + 3.0.6 security-lockdown-example-runner diff --git a/examples/security-lockdown/system/pom.xml b/examples/security-lockdown/system/pom.xml index 2ec98bc898..e5a1859a09 100644 --- a/examples/security-lockdown/system/pom.xml +++ b/examples/security-lockdown/system/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6-SNAPSHOT + 3.0.6 security-lockdown-example-system diff --git a/external/aopalliance/pom.xml b/external/aopalliance/pom.xml index f5005b0d61..e574d8d186 100644 --- a/external/aopalliance/pom.xml +++ b/external/aopalliance/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 external - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2.external diff --git a/external/pom.xml b/external/pom.xml index 0579f4b870..687a87c067 100644 --- a/external/pom.xml +++ b/external/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 external diff --git a/guice-bridge/pom.xml b/guice-bridge/pom.xml index 4a060abd6e..e94077a5cd 100644 --- a/guice-bridge/pom.xml +++ b/guice-bridge/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2-api/pom.xml b/hk2-api/pom.xml index ae3c67c3de..a191fb1231 100644 --- a/hk2-api/pom.xml +++ b/hk2-api/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2-configuration/hk2-integration/pom.xml b/hk2-configuration/hk2-integration/pom.xml index c3c41856b1..05406d3b5b 100644 --- a/hk2-configuration/hk2-integration/pom.xml +++ b/hk2-configuration/hk2-integration/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-configuration - 3.0.6-SNAPSHOT + 3.0.6 hk2-configuration-integration diff --git a/hk2-configuration/manager/pom.xml b/hk2-configuration/manager/pom.xml index f1da975d6d..d72899cb5c 100644 --- a/hk2-configuration/manager/pom.xml +++ b/hk2-configuration/manager/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-configuration - 3.0.6-SNAPSHOT + 3.0.6 hk2-configuration-hub diff --git a/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml b/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml index fd1afa4782..a9abb00537 100644 --- a/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-json diff --git a/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml b/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml index f52a807a4d..4e8657caa8 100644 --- a/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-pbuf diff --git a/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml b/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml index 10f4131f66..ed0595ef8b 100644 --- a/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-xml-integration-test diff --git a/hk2-configuration/persistence/hk2-xml/main/pom.xml b/hk2-configuration/persistence/hk2-xml/main/pom.xml index 6c9acefea0..5df39e3ec0 100644 --- a/hk2-configuration/persistence/hk2-xml/main/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/main/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-xml diff --git a/hk2-configuration/persistence/hk2-xml/pom.xml b/hk2-configuration/persistence/hk2-xml/pom.xml index 5d41de3d37..dbd98f807a 100644 --- a/hk2-configuration/persistence/hk2-xml/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-configuration-persistence - 3.0.6-SNAPSHOT + 3.0.6 hk2-xml-parent diff --git a/hk2-configuration/persistence/hk2-xml/schema/pom.xml b/hk2-configuration/persistence/hk2-xml/schema/pom.xml index b97ae970ca..cd3ad2de25 100644 --- a/hk2-configuration/persistence/hk2-xml/schema/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/schema/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-xml-schema diff --git a/hk2-configuration/persistence/hk2-xml/test1/pom.xml b/hk2-configuration/persistence/hk2-xml/test1/pom.xml index 41f121b43d..3249a707cb 100644 --- a/hk2-configuration/persistence/hk2-xml/test1/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/test1/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-xml-test diff --git a/hk2-configuration/persistence/pom.xml b/hk2-configuration/persistence/pom.xml index 799d847f95..e7990253ee 100644 --- a/hk2-configuration/persistence/pom.xml +++ b/hk2-configuration/persistence/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-configuration - 3.0.6-SNAPSHOT + 3.0.6 hk2-configuration-persistence diff --git a/hk2-configuration/persistence/property-file/pom.xml b/hk2-configuration/persistence/property-file/pom.xml index b8c63d2513..361b543cc1 100644 --- a/hk2-configuration/persistence/property-file/pom.xml +++ b/hk2-configuration/persistence/property-file/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-configuration-persistence - 3.0.6-SNAPSHOT + 3.0.6 hk2-property-file diff --git a/hk2-configuration/pom.xml b/hk2-configuration/pom.xml index 26f9c97ab5..a97e77e947 100644 --- a/hk2-configuration/pom.xml +++ b/hk2-configuration/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-configuration diff --git a/hk2-core/pom.xml b/hk2-core/pom.xml index 806681be4d..69dc4c6dbf 100644 --- a/hk2-core/pom.xml +++ b/hk2-core/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-core diff --git a/hk2-extras/pom.xml b/hk2-extras/pom.xml index d3724bddae..a7ccc107b8 100644 --- a/hk2-extras/pom.xml +++ b/hk2-extras/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2-jmx/pom.xml b/hk2-jmx/pom.xml index 3b9ef0dc46..3ef50a08da 100644 --- a/hk2-jmx/pom.xml +++ b/hk2-jmx/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2-locator/pom.xml b/hk2-locator/pom.xml index 806d64bfd9..1bfd5eba4a 100644 --- a/hk2-locator/pom.xml +++ b/hk2-locator/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-locator diff --git a/hk2-metadata-generator/main/pom.xml b/hk2-metadata-generator/main/pom.xml index 57e51477c6..9680855620 100644 --- a/hk2-metadata-generator/main/pom.xml +++ b/hk2-metadata-generator/main/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-metadata-generator-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2-metadata-generator/pom.xml b/hk2-metadata-generator/pom.xml index 20570aca3e..4e4ef427aa 100644 --- a/hk2-metadata-generator/pom.xml +++ b/hk2-metadata-generator/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-metadata-generator-parent diff --git a/hk2-metadata-generator/test1/pom.xml b/hk2-metadata-generator/test1/pom.xml index d85b656b37..2d5c415873 100644 --- a/hk2-metadata-generator/test1/pom.xml +++ b/hk2-metadata-generator/test1/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-metadata-generator-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2-runlevel/pom.xml b/hk2-runlevel/pom.xml index 47ade07357..e6eac990d2 100644 --- a/hk2-runlevel/pom.xml +++ b/hk2-runlevel/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-runlevel diff --git a/hk2-testing/ant/pom.xml b/hk2-testing/ant/pom.xml index c833347a37..6f62ab7a44 100644 --- a/hk2-testing/ant/pom.xml +++ b/hk2-testing/ant/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/collections/pom.xml b/hk2-testing/collections/pom.xml index 79477180dd..7f7482f079 100644 --- a/hk2-testing/collections/pom.xml +++ b/hk2-testing/collections/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6-SNAPSHOT + 3.0.6 hk2-collections-tests diff --git a/hk2-testing/di-tck/pom.xml b/hk2-testing/di-tck/pom.xml index 4486638f7e..18c101ee07 100644 --- a/hk2-testing/di-tck/pom.xml +++ b/hk2-testing/di-tck/pom.xml @@ -22,7 +22,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6-SNAPSHOT + 3.0.6 hk2-di-tck-runner diff --git a/hk2-testing/hk2-junitrunner/pom.xml b/hk2-testing/hk2-junitrunner/pom.xml index a4c6ecba80..5dac25460d 100644 --- a/hk2-testing/hk2-junitrunner/pom.xml +++ b/hk2-testing/hk2-junitrunner/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/hk2-locator-extras/pom.xml b/hk2-testing/hk2-locator-extras/pom.xml index 98c08428b5..17fc248ef8 100644 --- a/hk2-testing/hk2-locator-extras/pom.xml +++ b/hk2-testing/hk2-locator-extras/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/hk2-locator-no-proxies/pom.xml b/hk2-testing/hk2-locator-no-proxies/pom.xml index fded9a80b1..6856e0622a 100644 --- a/hk2-testing/hk2-locator-no-proxies/pom.xml +++ b/hk2-testing/hk2-locator-no-proxies/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/hk2-locator-no-proxies2/pom.xml b/hk2-testing/hk2-locator-no-proxies2/pom.xml index 3a1611e1a1..578169369d 100644 --- a/hk2-testing/hk2-locator-no-proxies2/pom.xml +++ b/hk2-testing/hk2-locator-no-proxies2/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/hk2-mockito/pom.xml b/hk2-testing/hk2-mockito/pom.xml index fd5041c717..8a1c736f1b 100644 --- a/hk2-testing/hk2-mockito/pom.xml +++ b/hk2-testing/hk2-mockito/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6-SNAPSHOT + 3.0.6 hk2-mockito diff --git a/hk2-testing/hk2-runlevel-extras/pom.xml b/hk2-testing/hk2-runlevel-extras/pom.xml index 56120e55f7..a598fc7d10 100644 --- a/hk2-testing/hk2-runlevel-extras/pom.xml +++ b/hk2-testing/hk2-runlevel-extras/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/hk2-testng/pom.xml b/hk2-testing/hk2-testng/pom.xml index 347d21f8f0..a052c4b6fe 100644 --- a/hk2-testing/hk2-testng/pom.xml +++ b/hk2-testing/hk2-testng/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/interceptor-events/pom.xml b/hk2-testing/interceptor-events/pom.xml index e5eb640117..d994dcacfc 100644 --- a/hk2-testing/interceptor-events/pom.xml +++ b/hk2-testing/interceptor-events/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6-SNAPSHOT + 3.0.6 interceptor-events diff --git a/hk2-testing/jersey/jersey-guice/form-param/pom.xml b/hk2-testing/jersey/jersey-guice/form-param/pom.xml index 1fd960abf3..76a1638949 100644 --- a/hk2-testing/jersey/jersey-guice/form-param/pom.xml +++ b/hk2-testing/jersey/jersey-guice/form-param/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../../../pom.xml diff --git a/hk2-testing/jersey/jersey-guice/pom.xml b/hk2-testing/jersey/jersey-guice/pom.xml index 376c422381..7ae1c7af71 100644 --- a/hk2-testing/jersey/jersey-guice/pom.xml +++ b/hk2-testing/jersey/jersey-guice/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../../pom.xml diff --git a/hk2-testing/jersey/pom.xml b/hk2-testing/jersey/pom.xml index 5f562eaed3..949ab69515 100644 --- a/hk2-testing/jersey/pom.xml +++ b/hk2-testing/jersey/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 ../../pom.xml diff --git a/hk2-testing/pom.xml b/hk2-testing/pom.xml index d8bd9680c6..c36813fec8 100644 --- a/hk2-testing/pom.xml +++ b/hk2-testing/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-testing diff --git a/hk2-utils/pom.xml b/hk2-utils/pom.xml index 494fb5af23..f02587edfd 100644 --- a/hk2-utils/pom.xml +++ b/hk2-utils/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/hk2/pom.xml b/hk2/pom.xml index 972fc0957e..6d91b57d20 100644 --- a/hk2/pom.xml +++ b/hk2/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2 diff --git a/javadocs/pom.xml b/javadocs/pom.xml index f27eba237d..8fbaf9196c 100644 --- a/javadocs/pom.xml +++ b/javadocs/pom.xml @@ -22,7 +22,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 hk2-javadocs HK2 Javadocs diff --git a/maven-plugins/consolidatedbundle-maven-plugin/pom.xml b/maven-plugins/consolidatedbundle-maven-plugin/pom.xml index e6f6e77c4f..f5006413c4 100644 --- a/maven-plugins/consolidatedbundle-maven-plugin/pom.xml +++ b/maven-plugins/consolidatedbundle-maven-plugin/pom.xml @@ -25,7 +25,7 @@ org.glassfish.hk2 maven-plugins - 3.0.6-SNAPSHOT + 3.0.6 consolidatedbundle-maven-plugin diff --git a/maven-plugins/hk2-inhabitant-generator/pom.xml b/maven-plugins/hk2-inhabitant-generator/pom.xml index c9aae874f9..999f2fc561 100644 --- a/maven-plugins/hk2-inhabitant-generator/pom.xml +++ b/maven-plugins/hk2-inhabitant-generator/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 maven-plugins - 3.0.6-SNAPSHOT + 3.0.6 hk2-inhabitant-generator diff --git a/maven-plugins/osgiversion-maven-plugin/pom.xml b/maven-plugins/osgiversion-maven-plugin/pom.xml index b0cbc3ac8a..b3b730418e 100644 --- a/maven-plugins/osgiversion-maven-plugin/pom.xml +++ b/maven-plugins/osgiversion-maven-plugin/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 maven-plugins - 3.0.6-SNAPSHOT + 3.0.6 osgiversion-maven-plugin diff --git a/maven-plugins/pom.xml b/maven-plugins/pom.xml index 1fe2eff91b..d810bdc70b 100644 --- a/maven-plugins/pom.xml +++ b/maven-plugins/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 maven-plugins diff --git a/osgi/adapter-tests/contract-bundle/pom.xml b/osgi/adapter-tests/contract-bundle/pom.xml index 341ae39a7c..156bf3ef61 100644 --- a/osgi/adapter-tests/contract-bundle/pom.xml +++ b/osgi/adapter-tests/contract-bundle/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6-SNAPSHOT + 3.0.6 contract-bundle diff --git a/osgi/adapter-tests/faux-sdp-bundle/pom.xml b/osgi/adapter-tests/faux-sdp-bundle/pom.xml index 8ba9ff585c..eca9ce5c63 100644 --- a/osgi/adapter-tests/faux-sdp-bundle/pom.xml +++ b/osgi/adapter-tests/faux-sdp-bundle/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6-SNAPSHOT + 3.0.6 faux-sdp-bundle diff --git a/osgi/adapter-tests/no-hk2-bundle/pom.xml b/osgi/adapter-tests/no-hk2-bundle/pom.xml index 9ea077cad3..eb9cf370dd 100644 --- a/osgi/adapter-tests/no-hk2-bundle/pom.xml +++ b/osgi/adapter-tests/no-hk2-bundle/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6-SNAPSHOT + 3.0.6 no-hk2-bundle diff --git a/osgi/adapter-tests/osgi-adapter-test/pom.xml b/osgi/adapter-tests/osgi-adapter-test/pom.xml index 782882dd1c..8d588696a6 100644 --- a/osgi/adapter-tests/osgi-adapter-test/pom.xml +++ b/osgi/adapter-tests/osgi-adapter-test/pom.xml @@ -22,7 +22,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 osgi-adapter-test diff --git a/osgi/adapter-tests/pom.xml b/osgi/adapter-tests/pom.xml index da8ed43de1..08a0a01b6f 100644 --- a/osgi/adapter-tests/pom.xml +++ b/osgi/adapter-tests/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 diff --git a/osgi/adapter-tests/sdp-management-bundle/pom.xml b/osgi/adapter-tests/sdp-management-bundle/pom.xml index d7a6e498c7..44b8620719 100644 --- a/osgi/adapter-tests/sdp-management-bundle/pom.xml +++ b/osgi/adapter-tests/sdp-management-bundle/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6-SNAPSHOT + 3.0.6 sdp-management-bundle diff --git a/osgi/adapter-tests/test-module-startup/pom.xml b/osgi/adapter-tests/test-module-startup/pom.xml index e7c839b00a..6261230305 100644 --- a/osgi/adapter-tests/test-module-startup/pom.xml +++ b/osgi/adapter-tests/test-module-startup/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6-SNAPSHOT + 3.0.6 test-module-startup diff --git a/osgi/adapter/pom.xml b/osgi/adapter/pom.xml index dd8e732b68..5f23bba50a 100644 --- a/osgi/adapter/pom.xml +++ b/osgi/adapter/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi - 3.0.6-SNAPSHOT + 3.0.6 osgi-adapter diff --git a/osgi/pom.xml b/osgi/pom.xml index f65d036b7b..44fba821fb 100644 --- a/osgi/pom.xml +++ b/osgi/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 osgi diff --git a/pom.xml b/pom.xml index 08108375b4..59a74df34f 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 pom GlassFish HK2 diff --git a/spring-bridge/pom.xml b/spring-bridge/pom.xml index 9e9114b443..e91f8dbcf6 100644 --- a/spring-bridge/pom.xml +++ b/spring-bridge/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6-SNAPSHOT + 3.0.6 org.glassfish.hk2 From 33a0cf78cb00c3bd0b5b2a9333b00c42f8492b69 Mon Sep 17 00:00:00 2001 From: Eclipse glassfish Bot Date: Thu, 25 Jan 2024 15:45:31 +0000 Subject: [PATCH 02/10] Prepare next development cycle for 3.0.7-SNAPSHOT --- class-model/pom.xml | 2 +- examples/caching/pom.xml | 2 +- examples/caching/runner/pom.xml | 2 +- examples/caching/system/pom.xml | 2 +- examples/configuration/pom.xml | 2 +- examples/configuration/webserver/pom.xml | 2 +- examples/configuration/xml/pom.xml | 2 +- examples/custom-resolver/pom.xml | 2 +- examples/events/pom.xml | 2 +- examples/events/threaded/pom.xml | 2 +- examples/operations/pom.xml | 2 +- examples/pom.xml | 2 +- examples/security-lockdown/alice/pom.xml | 2 +- examples/security-lockdown/mallory/pom.xml | 2 +- examples/security-lockdown/pom.xml | 2 +- examples/security-lockdown/runner/pom.xml | 2 +- examples/security-lockdown/system/pom.xml | 2 +- external/aopalliance/pom.xml | 2 +- external/pom.xml | 2 +- guice-bridge/pom.xml | 2 +- hk2-api/pom.xml | 2 +- hk2-configuration/hk2-integration/pom.xml | 2 +- hk2-configuration/manager/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/integration-test/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/main/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/schema/pom.xml | 2 +- hk2-configuration/persistence/hk2-xml/test1/pom.xml | 2 +- hk2-configuration/persistence/pom.xml | 2 +- hk2-configuration/persistence/property-file/pom.xml | 2 +- hk2-configuration/pom.xml | 2 +- hk2-core/pom.xml | 2 +- hk2-extras/pom.xml | 2 +- hk2-jmx/pom.xml | 2 +- hk2-locator/pom.xml | 2 +- hk2-metadata-generator/main/pom.xml | 2 +- hk2-metadata-generator/pom.xml | 2 +- hk2-metadata-generator/test1/pom.xml | 2 +- hk2-runlevel/pom.xml | 2 +- hk2-testing/ant/pom.xml | 2 +- hk2-testing/collections/pom.xml | 2 +- hk2-testing/hk2-junitrunner/pom.xml | 2 +- hk2-testing/hk2-locator-extras/pom.xml | 2 +- hk2-testing/hk2-locator-no-proxies/pom.xml | 2 +- hk2-testing/hk2-locator-no-proxies2/pom.xml | 2 +- hk2-testing/hk2-mockito/pom.xml | 2 +- hk2-testing/hk2-runlevel-extras/pom.xml | 2 +- hk2-testing/hk2-testng/pom.xml | 2 +- hk2-testing/interceptor-events/pom.xml | 2 +- hk2-testing/jersey/jersey-guice/form-param/pom.xml | 2 +- hk2-testing/jersey/jersey-guice/pom.xml | 2 +- hk2-testing/jersey/pom.xml | 2 +- hk2-testing/pom.xml | 2 +- hk2-utils/pom.xml | 2 +- hk2/pom.xml | 2 +- maven-plugins/consolidatedbundle-maven-plugin/pom.xml | 2 +- maven-plugins/hk2-inhabitant-generator/pom.xml | 2 +- maven-plugins/osgiversion-maven-plugin/pom.xml | 2 +- maven-plugins/pom.xml | 2 +- osgi/adapter-tests/contract-bundle/pom.xml | 2 +- osgi/adapter-tests/faux-sdp-bundle/pom.xml | 2 +- osgi/adapter-tests/no-hk2-bundle/pom.xml | 2 +- osgi/adapter-tests/pom.xml | 2 +- osgi/adapter-tests/sdp-management-bundle/pom.xml | 2 +- osgi/adapter-tests/test-module-startup/pom.xml | 2 +- osgi/adapter/pom.xml | 2 +- osgi/pom.xml | 2 +- pom.xml | 2 +- spring-bridge/pom.xml | 2 +- 71 files changed, 71 insertions(+), 71 deletions(-) diff --git a/class-model/pom.xml b/class-model/pom.xml index de463657a5..87379fb2a2 100644 --- a/class-model/pom.xml +++ b/class-model/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/examples/caching/pom.xml b/examples/caching/pom.xml index 2f2afa3cb6..6dd44bcb5d 100644 --- a/examples/caching/pom.xml +++ b/examples/caching/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6 + 3.0.7-SNAPSHOT caching-aop-example diff --git a/examples/caching/runner/pom.xml b/examples/caching/runner/pom.xml index ad221e1f62..f94830ad8f 100644 --- a/examples/caching/runner/pom.xml +++ b/examples/caching/runner/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 caching-aop-example - 3.0.6 + 3.0.7-SNAPSHOT caching-aop-example-runner diff --git a/examples/caching/system/pom.xml b/examples/caching/system/pom.xml index fa70800bda..35dc8e1f7f 100644 --- a/examples/caching/system/pom.xml +++ b/examples/caching/system/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 caching-aop-example - 3.0.6 + 3.0.7-SNAPSHOT caching-aop-example-system diff --git a/examples/configuration/pom.xml b/examples/configuration/pom.xml index 20a54e4330..32af40e12a 100644 --- a/examples/configuration/pom.xml +++ b/examples/configuration/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6 + 3.0.7-SNAPSHOT configuration-examples diff --git a/examples/configuration/webserver/pom.xml b/examples/configuration/webserver/pom.xml index f9e44a640f..09abde8bdc 100644 --- a/examples/configuration/webserver/pom.xml +++ b/examples/configuration/webserver/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 configuration-examples - 3.0.6 + 3.0.7-SNAPSHOT webserver-configuration-example diff --git a/examples/configuration/xml/pom.xml b/examples/configuration/xml/pom.xml index e618d42040..889c5e2fb8 100644 --- a/examples/configuration/xml/pom.xml +++ b/examples/configuration/xml/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 configuration-examples - 3.0.6 + 3.0.7-SNAPSHOT xml-configuration-example diff --git a/examples/custom-resolver/pom.xml b/examples/custom-resolver/pom.xml index cbf258311b..f6d6b7e101 100644 --- a/examples/custom-resolver/pom.xml +++ b/examples/custom-resolver/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 examples - 3.0.6 + 3.0.7-SNAPSHOT custom-resolver-example diff --git a/examples/events/pom.xml b/examples/events/pom.xml index c6acac15fd..c5f6c4a885 100644 --- a/examples/events/pom.xml +++ b/examples/events/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6 + 3.0.7-SNAPSHOT event-examples diff --git a/examples/events/threaded/pom.xml b/examples/events/threaded/pom.xml index 27c3c92e27..3fd24307a2 100644 --- a/examples/events/threaded/pom.xml +++ b/examples/events/threaded/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 event-examples - 3.0.6 + 3.0.7-SNAPSHOT threading-event-example diff --git a/examples/operations/pom.xml b/examples/operations/pom.xml index 9b4f19e11c..88e80b7b36 100644 --- a/examples/operations/pom.xml +++ b/examples/operations/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 examples - 3.0.6 + 3.0.7-SNAPSHOT operations-example diff --git a/examples/pom.xml b/examples/pom.xml index 7c4dd83ada..ca6de07ece 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT examples diff --git a/examples/security-lockdown/alice/pom.xml b/examples/security-lockdown/alice/pom.xml index 1d7d8d216c..d5ddaeb4c3 100644 --- a/examples/security-lockdown/alice/pom.xml +++ b/examples/security-lockdown/alice/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6 + 3.0.7-SNAPSHOT security-lockdown-example-alice diff --git a/examples/security-lockdown/mallory/pom.xml b/examples/security-lockdown/mallory/pom.xml index 0a84ec068e..a6b90a1717 100644 --- a/examples/security-lockdown/mallory/pom.xml +++ b/examples/security-lockdown/mallory/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6 + 3.0.7-SNAPSHOT security-lockdown-example-mallory diff --git a/examples/security-lockdown/pom.xml b/examples/security-lockdown/pom.xml index 9e0390c03a..6b4ff3c6ee 100644 --- a/examples/security-lockdown/pom.xml +++ b/examples/security-lockdown/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 examples - 3.0.6 + 3.0.7-SNAPSHOT security-lockdown-example diff --git a/examples/security-lockdown/runner/pom.xml b/examples/security-lockdown/runner/pom.xml index eb7b7dd910..cba64f657a 100644 --- a/examples/security-lockdown/runner/pom.xml +++ b/examples/security-lockdown/runner/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6 + 3.0.7-SNAPSHOT security-lockdown-example-runner diff --git a/examples/security-lockdown/system/pom.xml b/examples/security-lockdown/system/pom.xml index e5a1859a09..0b7a3c091c 100644 --- a/examples/security-lockdown/system/pom.xml +++ b/examples/security-lockdown/system/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 security-lockdown-example - 3.0.6 + 3.0.7-SNAPSHOT security-lockdown-example-system diff --git a/external/aopalliance/pom.xml b/external/aopalliance/pom.xml index e574d8d186..f4630dd2a6 100644 --- a/external/aopalliance/pom.xml +++ b/external/aopalliance/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 external - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2.external diff --git a/external/pom.xml b/external/pom.xml index 687a87c067..bb61b78f71 100644 --- a/external/pom.xml +++ b/external/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT external diff --git a/guice-bridge/pom.xml b/guice-bridge/pom.xml index e94077a5cd..3c47dfa322 100644 --- a/guice-bridge/pom.xml +++ b/guice-bridge/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2-api/pom.xml b/hk2-api/pom.xml index a191fb1231..3f94c21c0f 100644 --- a/hk2-api/pom.xml +++ b/hk2-api/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2-configuration/hk2-integration/pom.xml b/hk2-configuration/hk2-integration/pom.xml index 05406d3b5b..ab8445bdfa 100644 --- a/hk2-configuration/hk2-integration/pom.xml +++ b/hk2-configuration/hk2-integration/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-configuration - 3.0.6 + 3.0.7-SNAPSHOT hk2-configuration-integration diff --git a/hk2-configuration/manager/pom.xml b/hk2-configuration/manager/pom.xml index d72899cb5c..e2047746d5 100644 --- a/hk2-configuration/manager/pom.xml +++ b/hk2-configuration/manager/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-configuration - 3.0.6 + 3.0.7-SNAPSHOT hk2-configuration-hub diff --git a/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml b/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml index a9abb00537..975ebc5b6a 100644 --- a/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/hk2-json/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-json diff --git a/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml b/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml index 4e8657caa8..3724a2d9ca 100644 --- a/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/hk2-pbuf/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-pbuf diff --git a/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml b/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml index ed0595ef8b..4ec5252b24 100644 --- a/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/integration-test/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-xml-integration-test diff --git a/hk2-configuration/persistence/hk2-xml/main/pom.xml b/hk2-configuration/persistence/hk2-xml/main/pom.xml index 5df39e3ec0..bd9cb36983 100644 --- a/hk2-configuration/persistence/hk2-xml/main/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/main/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-xml diff --git a/hk2-configuration/persistence/hk2-xml/pom.xml b/hk2-configuration/persistence/hk2-xml/pom.xml index dbd98f807a..cb6545f7c2 100644 --- a/hk2-configuration/persistence/hk2-xml/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-configuration-persistence - 3.0.6 + 3.0.7-SNAPSHOT hk2-xml-parent diff --git a/hk2-configuration/persistence/hk2-xml/schema/pom.xml b/hk2-configuration/persistence/hk2-xml/schema/pom.xml index cd3ad2de25..d7864a8ad5 100644 --- a/hk2-configuration/persistence/hk2-xml/schema/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/schema/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-xml-schema diff --git a/hk2-configuration/persistence/hk2-xml/test1/pom.xml b/hk2-configuration/persistence/hk2-xml/test1/pom.xml index 3249a707cb..6ab239797d 100644 --- a/hk2-configuration/persistence/hk2-xml/test1/pom.xml +++ b/hk2-configuration/persistence/hk2-xml/test1/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-xml-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-xml-test diff --git a/hk2-configuration/persistence/pom.xml b/hk2-configuration/persistence/pom.xml index e7990253ee..90ca3e47a1 100644 --- a/hk2-configuration/persistence/pom.xml +++ b/hk2-configuration/persistence/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-configuration - 3.0.6 + 3.0.7-SNAPSHOT hk2-configuration-persistence diff --git a/hk2-configuration/persistence/property-file/pom.xml b/hk2-configuration/persistence/property-file/pom.xml index 361b543cc1..ce4e4175ca 100644 --- a/hk2-configuration/persistence/property-file/pom.xml +++ b/hk2-configuration/persistence/property-file/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-configuration-persistence - 3.0.6 + 3.0.7-SNAPSHOT hk2-property-file diff --git a/hk2-configuration/pom.xml b/hk2-configuration/pom.xml index a97e77e947..926e529ba2 100644 --- a/hk2-configuration/pom.xml +++ b/hk2-configuration/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-configuration diff --git a/hk2-core/pom.xml b/hk2-core/pom.xml index 69dc4c6dbf..7a4b8d88d3 100644 --- a/hk2-core/pom.xml +++ b/hk2-core/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-core diff --git a/hk2-extras/pom.xml b/hk2-extras/pom.xml index a7ccc107b8..938ba3f847 100644 --- a/hk2-extras/pom.xml +++ b/hk2-extras/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2-jmx/pom.xml b/hk2-jmx/pom.xml index 3ef50a08da..fe79d1c4d7 100644 --- a/hk2-jmx/pom.xml +++ b/hk2-jmx/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2-locator/pom.xml b/hk2-locator/pom.xml index 1bfd5eba4a..38c8cd3692 100644 --- a/hk2-locator/pom.xml +++ b/hk2-locator/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-locator diff --git a/hk2-metadata-generator/main/pom.xml b/hk2-metadata-generator/main/pom.xml index 9680855620..d4f39b739c 100644 --- a/hk2-metadata-generator/main/pom.xml +++ b/hk2-metadata-generator/main/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-metadata-generator-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2-metadata-generator/pom.xml b/hk2-metadata-generator/pom.xml index 4e4ef427aa..e55d7111c4 100644 --- a/hk2-metadata-generator/pom.xml +++ b/hk2-metadata-generator/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-metadata-generator-parent diff --git a/hk2-metadata-generator/test1/pom.xml b/hk2-metadata-generator/test1/pom.xml index 2d5c415873..34a38daf5f 100644 --- a/hk2-metadata-generator/test1/pom.xml +++ b/hk2-metadata-generator/test1/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-metadata-generator-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2-runlevel/pom.xml b/hk2-runlevel/pom.xml index e6eac990d2..45efcccff1 100644 --- a/hk2-runlevel/pom.xml +++ b/hk2-runlevel/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-runlevel diff --git a/hk2-testing/ant/pom.xml b/hk2-testing/ant/pom.xml index 6f62ab7a44..e6b1994531 100644 --- a/hk2-testing/ant/pom.xml +++ b/hk2-testing/ant/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/collections/pom.xml b/hk2-testing/collections/pom.xml index 7f7482f079..d7ba2f72bc 100644 --- a/hk2-testing/collections/pom.xml +++ b/hk2-testing/collections/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6 + 3.0.7-SNAPSHOT hk2-collections-tests diff --git a/hk2-testing/hk2-junitrunner/pom.xml b/hk2-testing/hk2-junitrunner/pom.xml index 5dac25460d..7af8008e0a 100644 --- a/hk2-testing/hk2-junitrunner/pom.xml +++ b/hk2-testing/hk2-junitrunner/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/hk2-locator-extras/pom.xml b/hk2-testing/hk2-locator-extras/pom.xml index 17fc248ef8..7133e1dbaf 100644 --- a/hk2-testing/hk2-locator-extras/pom.xml +++ b/hk2-testing/hk2-locator-extras/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/hk2-locator-no-proxies/pom.xml b/hk2-testing/hk2-locator-no-proxies/pom.xml index 6856e0622a..93245ab339 100644 --- a/hk2-testing/hk2-locator-no-proxies/pom.xml +++ b/hk2-testing/hk2-locator-no-proxies/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/hk2-locator-no-proxies2/pom.xml b/hk2-testing/hk2-locator-no-proxies2/pom.xml index 578169369d..a4a0dd431b 100644 --- a/hk2-testing/hk2-locator-no-proxies2/pom.xml +++ b/hk2-testing/hk2-locator-no-proxies2/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/hk2-mockito/pom.xml b/hk2-testing/hk2-mockito/pom.xml index 8a1c736f1b..0b63400f1d 100644 --- a/hk2-testing/hk2-mockito/pom.xml +++ b/hk2-testing/hk2-mockito/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6 + 3.0.7-SNAPSHOT hk2-mockito diff --git a/hk2-testing/hk2-runlevel-extras/pom.xml b/hk2-testing/hk2-runlevel-extras/pom.xml index a598fc7d10..10f6d733d3 100644 --- a/hk2-testing/hk2-runlevel-extras/pom.xml +++ b/hk2-testing/hk2-runlevel-extras/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/hk2-testng/pom.xml b/hk2-testing/hk2-testng/pom.xml index a052c4b6fe..f40ef13bf0 100644 --- a/hk2-testing/hk2-testng/pom.xml +++ b/hk2-testing/hk2-testng/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/interceptor-events/pom.xml b/hk2-testing/interceptor-events/pom.xml index d994dcacfc..9998100d63 100644 --- a/hk2-testing/interceptor-events/pom.xml +++ b/hk2-testing/interceptor-events/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6 + 3.0.7-SNAPSHOT interceptor-events diff --git a/hk2-testing/jersey/jersey-guice/form-param/pom.xml b/hk2-testing/jersey/jersey-guice/form-param/pom.xml index 76a1638949..e907aedc75 100644 --- a/hk2-testing/jersey/jersey-guice/form-param/pom.xml +++ b/hk2-testing/jersey/jersey-guice/form-param/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../../../pom.xml diff --git a/hk2-testing/jersey/jersey-guice/pom.xml b/hk2-testing/jersey/jersey-guice/pom.xml index 7ae1c7af71..881316fc5e 100644 --- a/hk2-testing/jersey/jersey-guice/pom.xml +++ b/hk2-testing/jersey/jersey-guice/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../../pom.xml diff --git a/hk2-testing/jersey/pom.xml b/hk2-testing/jersey/pom.xml index 949ab69515..c1ed56b8a7 100644 --- a/hk2-testing/jersey/pom.xml +++ b/hk2-testing/jersey/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT ../../pom.xml diff --git a/hk2-testing/pom.xml b/hk2-testing/pom.xml index c36813fec8..a006696e7f 100644 --- a/hk2-testing/pom.xml +++ b/hk2-testing/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-testing diff --git a/hk2-utils/pom.xml b/hk2-utils/pom.xml index f02587edfd..a0a317dad4 100644 --- a/hk2-utils/pom.xml +++ b/hk2-utils/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/hk2/pom.xml b/hk2/pom.xml index 6d91b57d20..6ed904b02c 100644 --- a/hk2/pom.xml +++ b/hk2/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2 diff --git a/maven-plugins/consolidatedbundle-maven-plugin/pom.xml b/maven-plugins/consolidatedbundle-maven-plugin/pom.xml index f5006413c4..2042746468 100644 --- a/maven-plugins/consolidatedbundle-maven-plugin/pom.xml +++ b/maven-plugins/consolidatedbundle-maven-plugin/pom.xml @@ -25,7 +25,7 @@ org.glassfish.hk2 maven-plugins - 3.0.6 + 3.0.7-SNAPSHOT consolidatedbundle-maven-plugin diff --git a/maven-plugins/hk2-inhabitant-generator/pom.xml b/maven-plugins/hk2-inhabitant-generator/pom.xml index 999f2fc561..76f5cc815c 100644 --- a/maven-plugins/hk2-inhabitant-generator/pom.xml +++ b/maven-plugins/hk2-inhabitant-generator/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 maven-plugins - 3.0.6 + 3.0.7-SNAPSHOT hk2-inhabitant-generator diff --git a/maven-plugins/osgiversion-maven-plugin/pom.xml b/maven-plugins/osgiversion-maven-plugin/pom.xml index b3b730418e..6bd1ec1028 100644 --- a/maven-plugins/osgiversion-maven-plugin/pom.xml +++ b/maven-plugins/osgiversion-maven-plugin/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 maven-plugins - 3.0.6 + 3.0.7-SNAPSHOT osgiversion-maven-plugin diff --git a/maven-plugins/pom.xml b/maven-plugins/pom.xml index d810bdc70b..ccfb7a150c 100644 --- a/maven-plugins/pom.xml +++ b/maven-plugins/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT maven-plugins diff --git a/osgi/adapter-tests/contract-bundle/pom.xml b/osgi/adapter-tests/contract-bundle/pom.xml index 156bf3ef61..153f1476da 100644 --- a/osgi/adapter-tests/contract-bundle/pom.xml +++ b/osgi/adapter-tests/contract-bundle/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6 + 3.0.7-SNAPSHOT contract-bundle diff --git a/osgi/adapter-tests/faux-sdp-bundle/pom.xml b/osgi/adapter-tests/faux-sdp-bundle/pom.xml index eca9ce5c63..57b0c578ce 100644 --- a/osgi/adapter-tests/faux-sdp-bundle/pom.xml +++ b/osgi/adapter-tests/faux-sdp-bundle/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6 + 3.0.7-SNAPSHOT faux-sdp-bundle diff --git a/osgi/adapter-tests/no-hk2-bundle/pom.xml b/osgi/adapter-tests/no-hk2-bundle/pom.xml index eb9cf370dd..361e527a7d 100644 --- a/osgi/adapter-tests/no-hk2-bundle/pom.xml +++ b/osgi/adapter-tests/no-hk2-bundle/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6 + 3.0.7-SNAPSHOT no-hk2-bundle diff --git a/osgi/adapter-tests/pom.xml b/osgi/adapter-tests/pom.xml index 08a0a01b6f..dbad14706a 100644 --- a/osgi/adapter-tests/pom.xml +++ b/osgi/adapter-tests/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 diff --git a/osgi/adapter-tests/sdp-management-bundle/pom.xml b/osgi/adapter-tests/sdp-management-bundle/pom.xml index 44b8620719..643d18f379 100644 --- a/osgi/adapter-tests/sdp-management-bundle/pom.xml +++ b/osgi/adapter-tests/sdp-management-bundle/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6 + 3.0.7-SNAPSHOT sdp-management-bundle diff --git a/osgi/adapter-tests/test-module-startup/pom.xml b/osgi/adapter-tests/test-module-startup/pom.xml index 6261230305..36384bbb0e 100644 --- a/osgi/adapter-tests/test-module-startup/pom.xml +++ b/osgi/adapter-tests/test-module-startup/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6 + 3.0.7-SNAPSHOT test-module-startup diff --git a/osgi/adapter/pom.xml b/osgi/adapter/pom.xml index 5f23bba50a..c32b0d38e3 100644 --- a/osgi/adapter/pom.xml +++ b/osgi/adapter/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 osgi - 3.0.6 + 3.0.7-SNAPSHOT osgi-adapter diff --git a/osgi/pom.xml b/osgi/pom.xml index 44fba821fb..0189a4a268 100644 --- a/osgi/pom.xml +++ b/osgi/pom.xml @@ -23,7 +23,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT osgi diff --git a/pom.xml b/pom.xml index 59a74df34f..a3b178d9a3 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT pom GlassFish HK2 diff --git a/spring-bridge/pom.xml b/spring-bridge/pom.xml index e91f8dbcf6..6274317111 100644 --- a/spring-bridge/pom.xml +++ b/spring-bridge/pom.xml @@ -24,7 +24,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 From cc02378da03f79cec81b9c9821568b4de1ba5a87 Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 7 Feb 2024 16:47:10 +0100 Subject: [PATCH 03/10] Update pom.xml --- bom/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bom/pom.xml b/bom/pom.xml index 6a6bc6d7e6..b2be84c8a7 100644 --- a/bom/pom.xml +++ b/bom/pom.xml @@ -30,7 +30,7 @@ org.glassfish.hk2 hk2-bom - 3.0.6 + 3.0.7-SNAPSHOT pom HK2 Bom Pom From fc57120b86a4818b664b210e0655e73efa95c4f2 Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 7 Feb 2024 21:42:52 +0100 Subject: [PATCH 04/10] Update pom.xml --- hk2-testing/di-tck/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hk2-testing/di-tck/pom.xml b/hk2-testing/di-tck/pom.xml index 18c101ee07..2925de0aa1 100644 --- a/hk2-testing/di-tck/pom.xml +++ b/hk2-testing/di-tck/pom.xml @@ -22,7 +22,7 @@ org.glassfish.hk2 hk2-testing - 3.0.6 + 3.0.7-SNAPSHOT hk2-di-tck-runner From 66efde61206897a5644cf37290e98b76805aad09 Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 7 Feb 2024 21:43:14 +0100 Subject: [PATCH 05/10] Update pom.xml --- osgi/adapter-tests/osgi-adapter-test/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osgi/adapter-tests/osgi-adapter-test/pom.xml b/osgi/adapter-tests/osgi-adapter-test/pom.xml index 8d588696a6..ff6e310d7f 100644 --- a/osgi/adapter-tests/osgi-adapter-test/pom.xml +++ b/osgi/adapter-tests/osgi-adapter-test/pom.xml @@ -22,7 +22,7 @@ org.glassfish.hk2 osgi-adapter-tests-parent - 3.0.6 + 3.0.7-SNAPSHOT org.glassfish.hk2 osgi-adapter-test From c017823d4a3a3e938c46bf9ed5334d71de4b6acf Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 7 Feb 2024 21:43:39 +0100 Subject: [PATCH 06/10] Update pom.xml --- javadocs/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javadocs/pom.xml b/javadocs/pom.xml index 8fbaf9196c..f283637ad1 100644 --- a/javadocs/pom.xml +++ b/javadocs/pom.xml @@ -22,7 +22,7 @@ org.glassfish.hk2 hk2-parent - 3.0.6 + 3.0.7-SNAPSHOT hk2-javadocs HK2 Javadocs From e986c7ed97cad4cfa59a6549877d05083944c5f8 Mon Sep 17 00:00:00 2001 From: Andrew Pielage Date: Wed, 14 Feb 2024 11:41:59 +0000 Subject: [PATCH 07/10] Update OSGi Enterprise to 7.0.0 Signed-off-by: Andrew Pielage --- class-model/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/class-model/pom.xml b/class-model/pom.xml index 87379fb2a2..8463aa3694 100644 --- a/class-model/pom.xml +++ b/class-model/pom.xml @@ -75,7 +75,7 @@ org.osgi - org.osgi.enterprise + osgi.enterprise provided diff --git a/pom.xml b/pom.xml index 43169ecb35..38d4418845 100644 --- a/pom.xml +++ b/pom.xml @@ -322,8 +322,8 @@ org.osgi - org.osgi.enterprise - 5.0.0 + osgi.enterprise + 7.0.0 org.apache.felix From b7a71e40aa1d1c0e88f2ae1ab2b81bad6919056c Mon Sep 17 00:00:00 2001 From: Arjan Tijms Date: Wed, 7 Feb 2024 16:43:28 +0100 Subject: [PATCH 08/10] Merge pull request #963 from jbescos/reentrantlock Replace synchronized by ReentrantLock Signed-off-by: Jorge Bescos Gascon --- .../hk2/classmodel/reflect/Parser.java | 33 +- .../classmodel/reflect/ParsingContext.java | 21 +- .../reflect/impl/AnnotatedElementImpl.java | 15 +- .../reflect/impl/ClassModelImpl.java | 13 +- .../reflect/impl/ExtensibleTypeImpl.java | 48 ++- .../impl/ParameterizedInterfaceModelImpl.java | 13 +- .../hk2/classmodel/reflect/impl/TypeImpl.java | 22 +- .../classmodel/reflect/impl/TypeProxy.java | 32 +- .../hk2/classmodel/reflect/impl/TypesCtr.java | 11 +- .../classmodel/reflect/impl/TypesImpl.java | 7 +- .../reflect/test/ClassModelTestsUtils.java | 10 +- .../internal/BankingServiceImpl.java | 81 ++-- .../org/glassfish/hk2/api/MultiException.java | 15 +- .../internal/ServiceLocatorFactoryImpl.java | 37 +- .../hk2/utilities/AliasDescriptor.java | 119 +++--- .../hk2/utilities/BuilderHelper.java | 22 +- .../hk2/utilities/DescriptorImpl.java | 356 +++++++++++----- .../hk2/utilities/ImmediateContext.java | 46 +- .../internal/ConfigurationListener.java | 16 +- .../internal/ConfiguredByContext.java | 30 +- .../ConfiguredByInjectionResolver.java | 96 +++-- .../DelegatingNamedActiveDescriptor.java | 25 +- .../hub/internal/BeanDatabaseImpl.java | 37 +- .../configuration/hub/internal/HubImpl.java | 30 +- .../hub/internal/InstanceImpl.java | 14 +- .../configuration/hub/internal/TypeImpl.java | 23 +- .../internal/WriteableBeanDatabaseImpl.java | 220 ++++++---- .../hub/internal/WriteableTypeImpl.java | 176 +++++--- .../hub/test/AbstractCountingListener.java | 42 +- .../hk2/pbuf/internal/PBufParser.java | 35 +- .../hk2/xml/internal/ChildDataModel.java | 20 +- .../hk2/xml/internal/JAUtilities.java | 63 +-- .../glassfish/hk2/xml/internal/ModelImpl.java | 150 ++++--- .../hk2/xml/internal/ParentedModel.java | 22 +- .../hk2/xml/internal/UnkeyedDiff.java | 35 +- .../clazz/AnnotationAltAnnotationImpl.java | 178 ++++---- .../internal/alt/clazz/ClassAltClassImpl.java | 60 +-- .../alt/clazz/MethodAltMethodImpl.java | 58 ++- .../AnnotationMirrorAltAnnotationImpl.java | 395 +++++++++--------- .../alt/papi/ArrayTypeAltClassImpl.java | 38 +- .../alt/papi/ElementAltMethodImpl.java | 106 +++-- .../alt/papi/TypeElementAltClassImpl.java | 118 +++--- .../xml/jaxb/internal/BaseHK2JAXBBean.java | 37 +- .../properties/PropertyFileBean.java | 24 +- .../internal/PropertyFileHandleImpl.java | 15 +- .../sun/enterprise/module/ModuleMetadata.java | 27 +- .../AbstractModulesRegistryImpl.java | 79 ++-- .../common_impl/AbstractRepositoryImpl.java | 30 +- .../common_impl/DirectoryBasedRepository.java | 184 ++++---- .../module/impl/ClassLoaderProxy.java | 21 +- .../enterprise/module/impl/HK2Factory.java | 20 +- .../module/impl/ModuleClassLoader.java | 22 +- .../enterprise/module/impl/ModuleImpl.java | 145 ++++--- .../internal/CrossOverDescriptor.java | 21 +- .../extras/operation/OperationContext.java | 65 ++- .../internal/OperationHandleImpl.java | 56 ++- .../internal/OperationManagerImpl.java | 24 +- .../internal/SingleOperationManager.java | 25 +- .../internal/DynamicConfigurationImpl.java | 15 +- .../jvnet/hk2/internal/IndexedListData.java | 97 +++-- .../internal/InstantiationServiceImpl.java | 99 +++-- .../hk2/internal/PerLocatorUtilities.java | 22 +- .../jvnet/hk2/internal/ProxyUtilities.java | 21 +- .../jvnet/hk2/internal/ServiceHandleImpl.java | 50 ++- .../hk2/internal/ServiceLocatorImpl.java | 42 +- .../jvnet/hk2/internal/SingletonContext.java | 9 +- .../jvnet/hk2/internal/SystemDescriptor.java | 47 ++- .../org/jvnet/hk2/internal/Utilities.java | 43 +- .../internal/AsyncRunLevelContext.java | 211 +++++++--- .../runlevel/internal/CurrentTaskFuture.java | 314 ++++++++++---- .../hk2/utilities/cache/LRUHybridCache.java | 10 +- .../cache/internal/LRUCacheCheapRead.java | 10 +- .../cache/internal/WeakCARCacheImpl.java | 107 +++-- .../utilities/general/ValidatorUtilities.java | 41 +- .../general/internal/WeakHashClockImpl.java | 203 +++++---- .../spring/bridge/api/SpringScopeImpl.java | 53 ++- 76 files changed, 3343 insertions(+), 1734 deletions(-) diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/Parser.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/Parser.java index e0a468f36c..a96be05b7c 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/Parser.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/Parser.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2023 Contributors to the Eclipse Foundation - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -39,6 +39,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.logging.Level; import java.util.logging.Logger; @@ -62,6 +63,8 @@ public class Parser implements Closeable { private final ParsingContext context; private final Map processedURI = Collections.synchronizedMap(new HashMap()); + private final ReentrantLock thislock = new ReentrantLock(); + private final ReentrantLock futuresLock = new ReentrantLock(); private final Stack> futures = new Stack<>(); private final ExecutorService executorService; private final boolean ownES; @@ -90,13 +93,14 @@ public Exception[] awaitTermination(int timeOut, TimeUnit unit) throws Interrupt context.logger.log(Level.FINE, "Await iterating at " + System.currentTimeMillis() + " waiting for " + futures.size()); } Future f; - synchronized(futures) { + futuresLock.lock(); try { f = futures.pop(); } catch(EmptyStackException e) { // it's ok, another thread took the load from us. f = null; - } + } finally { + futuresLock.unlock(); } if (f!=null) { try { @@ -298,8 +302,11 @@ public Result call() throws Exception { } } }); - synchronized(futures) { + futuresLock.lock(); + try { futures.add(future); + } finally { + futuresLock.unlock(); } if (immediateShutdown) { es.shutdown(); @@ -310,12 +317,22 @@ public Result call() throws Exception { } } - private synchronized Types getResult(URI uri) { - return processedURI.get(uri.getSchemeSpecificPart()); + private Types getResult(URI uri) { + thislock.lock(); + try { + return processedURI.get(uri.getSchemeSpecificPart()); + } finally { + thislock.unlock(); + } } - private synchronized void saveResult(URI uri, Types types) { - this.processedURI.put(uri.getPath(), types); + private void saveResult(URI uri, Types types) { + thislock.lock(); + try { + this.processedURI.put(uri.getPath(), types); + } finally { + thislock.unlock(); + } } private void doJob(final ArchiveAdapter adapter, final Runnable doneHook) throws Exception { diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/ParsingContext.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/ParsingContext.java index e58db7e1c9..bad604a670 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/ParsingContext.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/ParsingContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019 Payara Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutorService; +import java.util.concurrent.locks.ReentrantLock; import java.net.URI; import java.util.logging.Logger; @@ -149,6 +150,7 @@ public ParsingContext build() { final Logger logger; final ParsingConfig config; final ResourceLocator locator; + final ReentrantLock lock = new ReentrantLock(); private ParsingContext(Builder builder) { // Runtime runtime = Runtime.getRuntime(); @@ -178,13 +180,18 @@ public boolean modelUnAnnotatedMembers() { Map builders = new HashMap(); - public synchronized TypeBuilder getTypeBuilder(URI definingURI) { - TypeBuilder builder = builders.get(definingURI); - if (builder==null) { - builder = new TypesImpl(types, definingURI); - builders.put(definingURI, builder); + public TypeBuilder getTypeBuilder(URI definingURI) { + lock.lock(); + try { + TypeBuilder builder = builders.get(definingURI); + if (builder==null) { + builder = new TypesImpl(types, definingURI); + builders.put(definingURI, builder); + } + return builder; + } finally { + lock.unlock(); } - return builder; } /** diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/AnnotatedElementImpl.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/AnnotatedElementImpl.java index aeaf771009..a80ce72876 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/AnnotatedElementImpl.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/AnnotatedElementImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import org.glassfish.hk2.classmodel.reflect.*; +import java.util.concurrent.locks.ReentrantLock; import java.util.*; /** @@ -26,7 +27,8 @@ * @author Jerome Dochez */ public class AnnotatedElementImpl implements AnnotatedElement { - + + private final ReentrantLock lock = new ReentrantLock(); private final String name; private final List annotations = new ArrayList(); @@ -42,8 +44,13 @@ public String getName() { return name; } - synchronized void addAnnotation(AnnotationModel annotation) { - annotations.add(annotation); + void addAnnotation(AnnotationModel annotation) { + lock.lock(); + try { + annotations.add(annotation); + } finally { + lock.unlock(); + } } @Override diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ClassModelImpl.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ClassModelImpl.java index cc9f992280..7c5f9061b3 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ClassModelImpl.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ClassModelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -19,12 +19,14 @@ import org.glassfish.hk2.classmodel.reflect.*; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; /** * Implementation of a class model */ public class ClassModelImpl extends ExtensibleTypeImpl implements ClassModel { + private final ReentrantLock lock = new ReentrantLock(); final List fields = new ArrayList<>(); public ClassModelImpl(String name, TypeProxy sink, TypeProxy parent) { @@ -32,8 +34,13 @@ public ClassModelImpl(String name, TypeProxy sink, TypeProxy parent) { } @Override - synchronized void addField(FieldModel field) { - fields.add(field); + void addField(FieldModel field) { + lock.lock(); + try { + fields.add(field); + } finally { + lock.unlock(); + } } @Override diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ExtensibleTypeImpl.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ExtensibleTypeImpl.java index ed759bc35e..19938b3814 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ExtensibleTypeImpl.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ExtensibleTypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,12 +18,14 @@ import org.glassfish.hk2.classmodel.reflect.*; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; /** * Implementation of an extensible type (Class or Interface) */ public abstract class ExtensibleTypeImpl extends TypeImpl implements ExtensibleType { + private final ReentrantLock lock = new ReentrantLock(); protected TypeProxy parent; private final List staticFields = new ArrayList<>(); private final List> implementedIntf = new ArrayList<>(); @@ -76,22 +78,37 @@ public String getSimpleName() { return simpleName; } - public synchronized TypeProxy setParent(final TypeProxy parent) { - if (null == this.parent) { - this.parent = parent; + public TypeProxy setParent(final TypeProxy parent) { + lock.lock(); + try { + if (null == this.parent) { + this.parent = parent; + } + return this.parent; + } finally { + lock.unlock(); } - return this.parent; } - synchronized void isImplementing(TypeProxy intf) { - implementedIntf.add(intf); + void isImplementing(TypeProxy intf) { + try { + lock.lock(); + implementedIntf.add(intf); + } finally { + lock.unlock(); + } } - synchronized void isImplementing(ParameterizedInterfaceModelImpl pim) { - if (pim.getRawInterface() instanceof InterfaceModel) { - implementedIntf.add((TypeProxy) pim.getRawInterfaceProxy()); + void isImplementing(ParameterizedInterfaceModelImpl pim) { + try { + lock.lock(); + if (pim.getRawInterface() instanceof InterfaceModel) { + implementedIntf.add((TypeProxy) pim.getRawInterfaceProxy()); + } + implementedParameterizedIntf.add(pim); + } finally { + lock.unlock(); } - implementedParameterizedIntf.add(pim); } @Override @@ -132,8 +149,13 @@ public Collection allSubTypes() { return allTypes; } - synchronized void addStaticField(FieldModel field) { - staticFields.add(field); + void addStaticField(FieldModel field) { + try { + lock.lock(); + staticFields.add(field); + } finally { + lock.unlock(); + } } void addField(FieldModel field) { diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ParameterizedInterfaceModelImpl.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ParameterizedInterfaceModelImpl.java index 4520cf2a3d..4326f52fdd 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ParameterizedInterfaceModelImpl.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/ParameterizedInterfaceModelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -19,6 +19,7 @@ import org.glassfish.hk2.classmodel.reflect.ParameterizedInterfaceModel; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; import java.util.stream.Collectors; import org.glassfish.hk2.classmodel.reflect.ExtensibleType; @@ -29,6 +30,7 @@ */ class ParameterizedInterfaceModelImpl implements ParameterizedInterfaceModel { + private final ReentrantLock lock = new ReentrantLock(); final TypeProxy rawInterface; final List parameterizedTypes = new ArrayList<>(); @@ -36,8 +38,13 @@ class ParameterizedInterfaceModelImpl implements ParameterizedInterfaceModel { this.rawInterface = rawInterface; } - synchronized void addParameterizedType(ParameterizedInterfaceModel type) { - parameterizedTypes.add(type); + void addParameterizedType(ParameterizedInterfaceModel type) { + lock.lock(); + try { + parameterizedTypes.add(type); + } finally { + lock.unlock(); + } } @Override diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeImpl.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeImpl.java index 307e4002c3..9d4e06f172 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeImpl.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -22,6 +22,7 @@ import java.io.File; import java.io.IOException; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; import java.net.URI; /** @@ -31,6 +32,7 @@ */ public class TypeImpl extends AnnotatedElementImpl implements Type { + private final ReentrantLock lock = new ReentrantLock(); private final TypeProxy sink; private final List methods = new ArrayList(); private final Set definingURIs= new HashSet(); @@ -46,8 +48,13 @@ public Collection getDefiningURIs() { return Collections.unmodifiableSet(definingURIs); } - synchronized void addDefiningURI(URI uri) { - definingURIs.add(uri); + void addDefiningURI(URI uri) { + lock.lock(); + try { + definingURIs.add(uri); + } finally { + lock.unlock(); + } } @Override @@ -60,8 +67,13 @@ public boolean wasDefinedIn(Collection uris) { return false; } - synchronized void addMethod(MethodModelImpl m) { - methods.add(m); + void addMethod(MethodModelImpl m) { + lock.lock(); + try { + methods.add(m); + } finally { + lock.unlock(); + } } @Override diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeProxy.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeProxy.java index eb32ae0346..646bafff5c 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeProxy.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypeProxy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -19,6 +19,7 @@ import org.glassfish.hk2.classmodel.reflect.*; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; /** * Proxy for types, used in place until the type can be properly instantiated. @@ -35,6 +36,8 @@ public class TypeProxy { private final List fieldRefs = new ArrayList(); private final List subTypeRefs = new ArrayList(); private final List implementations = new ArrayList(); + // Referenced also by TypesImpl + final ReentrantLock lock = new ReentrantLock(); /** @@ -76,24 +79,39 @@ public interface Notifier { public void valueSet(T value); } - public synchronized void addFieldRef(FieldModel field) { - fieldRefs.add(field); + public void addFieldRef(FieldModel field) { + lock.lock(); + try { + fieldRefs.add(field); + } finally { + lock.unlock(); + } } public List getRefs() { return Collections.unmodifiableList(fieldRefs); } - public synchronized void addSubTypeRef(Type subType) { - subTypeRefs.add(subType); + public void addSubTypeRef(Type subType) { + lock.lock(); + try { + subTypeRefs.add(subType); + } finally { + lock.unlock(); + } } public List getSubTypeRefs() { return Collections.unmodifiableList(subTypeRefs); } - public synchronized void addImplementation(ClassModel classModel) { - implementations.add(classModel); + public void addImplementation(ClassModel classModel) { + lock.lock(); + try { + implementations.add(classModel); + } finally { + lock.unlock(); + } } public List getImplementations() { diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesCtr.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesCtr.java index 607df7cb1b..83365b74f1 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesCtr.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesCtr.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,6 +22,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.locks.ReentrantLock; /** * contains all the parsed types references. @@ -93,11 +94,14 @@ public TypeProxy getHolder(String name, Class type) { TypeProxy tmp = unknownTypesStorage.get(name); // in our unknown type pool ? if (tmp!=null) { - synchronized (unknownTypesStorage) { + unknownTypesStorageLock.lock(); + try { typeProxy = unknownTypesStorage.remove(name); if (typeProxy == null) { typeProxy = tmp; - } + } + } finally { + unknownTypesStorageLock.unlock(); } if (typeProxy!=null) { TypeProxy old = typeStorage.putIfAbsent(name, typeProxy); @@ -160,6 +164,7 @@ public Collection getAllTypes() { private final ConcurrentMap>> storage= new ConcurrentHashMap>>(); + private final ReentrantLock unknownTypesStorageLock = new ReentrantLock(); /** * Map of encountered types which we don't know if it is an interface, class or annotation */ diff --git a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesImpl.java b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesImpl.java index 95119351fd..f310ebcc70 100755 --- a/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesImpl.java +++ b/class-model/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/TypesImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -55,7 +55,8 @@ public TypeImpl getType(int access, String name, TypeProxy parent) { Class requestedType = getType(access); TypeProxy typeProxy = types.getHolder(name, requestedType); - synchronized(typeProxy) { + typeProxy.lock.lock(); + try { final Type type = typeProxy.get(); TypeImpl result; if (null == type) { @@ -78,6 +79,8 @@ public TypeImpl getType(int access, String name, TypeProxy parent) { } return impl; } + } finally { + typeProxy.lock.unlock(); } } diff --git a/class-model/src/test/java/org/glassfish/hk2/classmodel/reflect/test/ClassModelTestsUtils.java b/class-model/src/test/java/org/glassfish/hk2/classmodel/reflect/test/ClassModelTestsUtils.java index 2b12db2d20..8e2150d4b5 100755 --- a/class-model/src/test/java/org/glassfish/hk2/classmodel/reflect/test/ClassModelTestsUtils.java +++ b/class-model/src/test/java/org/glassfish/hk2/classmodel/reflect/test/ClassModelTestsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -27,6 +27,7 @@ import java.util.Collections; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; /** * Created by IntelliJ IDEA. @@ -39,13 +40,14 @@ public class ClassModelTestsUtils { static Types types = null; + private final static ReentrantLock lock = new ReentrantLock(); private final static ClassModelTestsUtils instance = new ClassModelTestsUtils(); public static Types getTypes() throws IOException, InterruptedException { - synchronized(instance) { - + lock.lock(); + try { if (types == null) { File userDir = new File(System.getProperty("user.dir")); File modelDir = new File(userDir, "target" + File.separator + "test-classes"); @@ -80,6 +82,8 @@ public boolean modelUnAnnotatedMembers() { types = pc.getTypes(); } } + } finally { + lock.unlock(); } return types; } diff --git a/examples/operations/src/main/java/org/glassfish/examples/operations/application/internal/BankingServiceImpl.java b/examples/operations/src/main/java/org/glassfish/examples/operations/application/internal/BankingServiceImpl.java index e80cdbc6ec..6098f1dd6f 100755 --- a/examples/operations/src/main/java/org/glassfish/examples/operations/application/internal/BankingServiceImpl.java +++ b/examples/operations/src/main/java/org/glassfish/examples/operations/application/internal/BankingServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -52,52 +53,68 @@ public class BankingServiceImpl implements BankingService { @Inject private WithdrawalService withdrawerAgent; + private final ReentrantLock lock = new ReentrantLock(); private final Map> depositors = new HashMap>(); private final Map> withdrawers = new HashMap>(); - private synchronized OperationHandle getDepositBankHandle(String bank) { - OperationHandle depositor = depositors.get(bank); - if (depositor == null) { - // create and start it - depositor = manager.createOperation(DepositScopeImpl.INSTANCE); - depositors.put(bank, depositor); + private OperationHandle getDepositBankHandle(String bank) { + lock.lock(); + try { + OperationHandle depositor = depositors.get(bank); + if (depositor == null) { + // create and start it + depositor = manager.createOperation(DepositScopeImpl.INSTANCE); + depositors.put(bank, depositor); + } + + return depositor; + } finally { + lock.unlock(); } - - return depositor; } - private synchronized OperationHandle getWithdrawerBankHandle(String bank) { - OperationHandle withdrawer = withdrawers.get(bank); - if (withdrawer == null) { - // create and start it - withdrawer = manager.createOperation(WithdrawalScopeImpl.INSTANCE); - withdrawers.put(bank, withdrawer); + private OperationHandle getWithdrawerBankHandle(String bank) { + lock.lock(); + try { + OperationHandle withdrawer = withdrawers.get(bank); + if (withdrawer == null) { + // create and start it + withdrawer = manager.createOperation(WithdrawalScopeImpl.INSTANCE); + withdrawers.put(bank, withdrawer); + } + + return withdrawer; + } finally { + lock.unlock(); } - - return withdrawer; } /* (non-Javadoc) * @see org.glassfish.examples.operations.application.BankingService#transferFunds(java.lang.String, long, java.lang.String, long, int) */ @Override - public synchronized int transferFunds(String withdrawlBank, long withdrawlAccount, + public int transferFunds(String withdrawlBank, long withdrawlAccount, String depositorBank, long depositAccount, int funds) { - OperationHandle depositor = getDepositBankHandle(depositorBank); - OperationHandle withdrawer = getWithdrawerBankHandle(withdrawlBank); - - // Set the context for the transfer - depositor.resume(); - withdrawer.resume(); - - // At this point the scopes are set properly, we can just call the service! + lock.lock(); try { - return transferAgent.doTransfer(depositAccount, withdrawlAccount, funds); - } - finally { - // Turn off the two scopes - withdrawer.suspend(); - depositor.suspend(); + OperationHandle depositor = getDepositBankHandle(depositorBank); + OperationHandle withdrawer = getWithdrawerBankHandle(withdrawlBank); + + // Set the context for the transfer + depositor.resume(); + withdrawer.resume(); + + // At this point the scopes are set properly, we can just call the service! + try { + return transferAgent.doTransfer(depositAccount, withdrawlAccount, funds); + } + finally { + // Turn off the two scopes + withdrawer.suspend(); + depositor.suspend(); + } + } finally { + lock.unlock(); } } diff --git a/hk2-api/src/main/java/org/glassfish/hk2/api/MultiException.java b/hk2-api/src/main/java/org/glassfish/hk2/api/MultiException.java index 04fb66bbbf..dfab2ef643 100755 --- a/hk2-api/src/main/java/org/glassfish/hk2/api/MultiException.java +++ b/hk2-api/src/main/java/org/glassfish/hk2/api/MultiException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,7 @@ import java.io.PrintWriter; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; /** * This exception can contain multiple other exceptions. @@ -34,7 +35,7 @@ public class MultiException extends HK2RuntimeException { * For serialization */ private static final long serialVersionUID = 2112432697858621044L; - private final Object lock = new byte[0]; // byte[0] is an arbitrary type that is Serializable + private final ReentrantLock lock = new ReentrantLock(); private final List throwables = new LinkedList(); private boolean reportToErrorService = true; @@ -106,8 +107,11 @@ public MultiException(Throwable th) { * not return null, but may return an empty object */ public List getErrors() { - synchronized (lock) { + lock.lock(); + try { return new LinkedList(throwables); + } finally { + lock.unlock(); } } @@ -117,8 +121,11 @@ public List getErrors() { * @param error The exception to add */ public void addError(Throwable error) { - synchronized (lock) { + lock.lock(); + try { throwables.add(error); + } finally { + lock.unlock(); } } diff --git a/hk2-api/src/main/java/org/glassfish/hk2/internal/ServiceLocatorFactoryImpl.java b/hk2-api/src/main/java/org/glassfish/hk2/internal/ServiceLocatorFactoryImpl.java index f47687e497..4f34b1a3f9 100755 --- a/hk2-api/src/main/java/org/glassfish/hk2/internal/ServiceLocatorFactoryImpl.java +++ b/hk2-api/src/main/java/org/glassfish/hk2/internal/ServiceLocatorFactoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import java.util.HashSet; import java.util.Iterator; import java.util.ServiceConfigurationError; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.api.ServiceLocatorFactory; @@ -49,7 +50,7 @@ public Boolean run() { }); - private static final Object sLock = new Object(); + private static final ReentrantLock sLock = new ReentrantLock(); private static int name_count = 0; private static final String GENERATED_NAME_PREFIX = "__HK2_Generated_"; @@ -57,7 +58,7 @@ private final static class DefaultGeneratorInitializer { private final static ServiceLocatorGenerator defaultGenerator = getGeneratorSecure(); } - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private final HashMap serviceLocators = new HashMap(); private final HashSet listeners = new HashSet(); @@ -139,8 +140,11 @@ public ServiceLocator create(String name) { */ @Override public ServiceLocator find(String name) { - synchronized (lock) { + try { + lock.lock(); return serviceLocators.get(name); + } finally { + lock.unlock(); } } @@ -155,7 +159,8 @@ public void destroy(String name) { private void destroy(String name, ServiceLocator locator) { ServiceLocator killMe = null; - synchronized (lock) { + try { + lock.lock(); if (name != null) { killMe = serviceLocators.remove(name); } @@ -180,6 +185,8 @@ private void destroy(String name, ServiceLocator locator) { } } } + } finally { + lock.unlock(); } if (killMe != null) { @@ -203,8 +210,11 @@ public ServiceLocator create(String name, } private static String getGeneratedName() { - synchronized (sLock) { + sLock.lock(); + try { return GENERATED_NAME_PREFIX + name_count++; + } finally { + sLock.unlock(); } } @@ -237,7 +247,8 @@ public ServiceLocator create(String name, ServiceLocator parent, Logger.getLogger().debug("ServiceFactoryImpl given create of " + name + " with parent " + parent + " with generator " + generator + " and policy " + policy, new Throwable()); } - synchronized (lock) { + lock.lock(); + try { ServiceLocator retVal; if (name == null) { @@ -276,6 +287,8 @@ public ServiceLocator create(String name, ServiceLocator parent, Logger.getLogger().debug("ServiceFactoryImpl created locator " + retVal); } return retVal; + } finally { + lock.unlock(); } } @@ -293,7 +306,8 @@ private ServiceLocator internalCreate(String name, ServiceLocator parent, Servic public void addListener(ServiceLocatorListener listener) { if (listener == null) throw new IllegalArgumentException(); - synchronized (lock) { + lock.lock(); + try { if (listeners.contains(listener)) return; try { @@ -307,6 +321,8 @@ public void addListener(ServiceLocatorListener listener) { } listeners.add(listener); + } finally { + lock.unlock(); } } @@ -315,8 +331,11 @@ public void addListener(ServiceLocatorListener listener) { public void removeListener(ServiceLocatorListener listener) { if (listener == null) throw new IllegalArgumentException(); - synchronized (lock) { + lock.lock(); + try { listeners.remove(listener); + } finally { + lock.unlock(); } } diff --git a/hk2-api/src/main/java/org/glassfish/hk2/utilities/AliasDescriptor.java b/hk2-api/src/main/java/org/glassfish/hk2/utilities/AliasDescriptor.java index 9dc7d3a083..c38f240a68 100755 --- a/hk2-api/src/main/java/org/glassfish/hk2/utilities/AliasDescriptor.java +++ b/hk2-api/src/main/java/org/glassfish/hk2/utilities/AliasDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Named; @@ -63,6 +64,8 @@ public class AliasDescriptor extends AbstractActiveDescriptor { */ private static final long serialVersionUID = 2609895430798803508L; + private final ReentrantLock lock = new ReentrantLock(); + /** * The service locator. */ @@ -226,28 +229,38 @@ public Class getScopeAnnotation() { * @see org.glassfish.hk2.api.ActiveDescriptor#getQualifierAnnotations() */ @Override - public synchronized Set getQualifierAnnotations() { - ensureInitialized(); - - if (qualifiers == null) { - qualifiers = new HashSet(descriptor.getQualifierAnnotations()); - if (getName() != null) { - qualifiers.add(new NamedImpl(getName())); + public Set getQualifierAnnotations() { + lock.lock(); + try { + ensureInitialized(); + + if (qualifiers == null) { + qualifiers = new HashSet(descriptor.getQualifierAnnotations()); + if (getName() != null) { + qualifiers.add(new NamedImpl(getName())); + } } + return qualifiers; + } finally { + lock.unlock(); } - return qualifiers; } @Override - public synchronized Set getQualifiers() { - if (qualifierNames != null) return qualifierNames; - - qualifierNames = new HashSet(descriptor.getQualifiers()); - if (getName() != null) { - qualifierNames.add(Named.class.getName()); + public Set getQualifiers() { + lock.lock(); + try { + if (qualifierNames != null) return qualifierNames; + + qualifierNames = new HashSet(descriptor.getQualifiers()); + if (getName() != null) { + qualifierNames.add(Named.class.getName()); + } + + return qualifierNames; + } finally { + lock.unlock(); } - - return qualifierNames; } /* (non-Javadoc) @@ -287,53 +300,61 @@ public ActiveDescriptor getDescriptor() { * Ensure that this descriptor has been initialized. */ @SuppressWarnings("unchecked") - private synchronized void ensureInitialized() { - if (!initialized) { - // reify the underlying descriptor if needed - if (!descriptor.isReified()) { - descriptor = (ActiveDescriptor) locator.reifyDescriptor(descriptor); - } + private void ensureInitialized() { + lock.lock(); + try { + if (!initialized) { + // reify the underlying descriptor if needed + if (!descriptor.isReified()) { + descriptor = (ActiveDescriptor) locator.reifyDescriptor(descriptor); + } - if (contract == null) { - initialized = true; - return; - } + if (contract == null) { + initialized = true; + return; + } - HK2Loader loader = descriptor.getLoader(); + HK2Loader loader = descriptor.getLoader(); - Type contractType = null; - try { - if (loader != null) { - contractType = loader.loadClass(contract); - } - else { - Class ic = descriptor.getImplementationClass(); - ClassLoader cl = null; - if (ic != null) { - cl = ic.getClassLoader(); + Type contractType = null; + try { + if (loader != null) { + contractType = loader.loadClass(contract); } - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); + else { + Class ic = descriptor.getImplementationClass(); + ClassLoader cl = null; + if (ic != null) { + cl = ic.getClassLoader(); + } + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + + contractType = cl.loadClass(contract); } - - contractType = cl.loadClass(contract); } - } - catch (ClassNotFoundException e) { - // do nothing - } + catch (ClassNotFoundException e) { + // do nothing + } - super.addContractType(contractType); + super.addContractType(contractType); - initialized = true; + initialized = true; + } + } finally { + lock.unlock(); } } @Override public int hashCode() { int retVal; - synchronized (this) { + lock.lock(); + try { retVal = descriptor.hashCode(); + } finally { + lock.unlock(); } if (getName() != null) { diff --git a/hk2-api/src/main/java/org/glassfish/hk2/utilities/BuilderHelper.java b/hk2-api/src/main/java/org/glassfish/hk2/utilities/BuilderHelper.java index a7fcfb88fc..cdfa3f4ae7 100755 --- a/hk2-api/src/main/java/org/glassfish/hk2/utilities/BuilderHelper.java +++ b/hk2-api/src/main/java/org/glassfish/hk2/utilities/BuilderHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Set; import java.util.StringTokenizer; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Descriptor; @@ -688,6 +689,7 @@ else if (addMe.getClass().isArray()) { public static ServiceHandle createConstantServiceHandle(final T obj) { return new ServiceHandle() { private Object serviceData; + private final ReentrantLock lock = new ReentrantLock(); @Override public T getService() { @@ -710,13 +712,23 @@ public void close() { } @Override - public synchronized void setServiceData(Object serviceData) { - this.serviceData = serviceData; + public void setServiceData(Object serviceData) { + lock.lock(); + try { + this.serviceData = serviceData; + } finally { + lock.unlock(); + } } @Override - public synchronized Object getServiceData() { - return serviceData; + public Object getServiceData() { + lock.lock(); + try { + return serviceData; + } finally { + lock.unlock(); + } } @Override diff --git a/hk2-api/src/main/java/org/glassfish/hk2/utilities/DescriptorImpl.java b/hk2-api/src/main/java/org/glassfish/hk2/utilities/DescriptorImpl.java index 3ec5946fc8..8e9ac446db 100755 --- a/hk2-api/src/main/java/org/glassfish/hk2/utilities/DescriptorImpl.java +++ b/hk2-api/src/main/java/org/glassfish/hk2/utilities/DescriptorImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -31,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Singleton; @@ -80,6 +81,7 @@ public class DescriptorImpl implements Descriptor, Externalizable { private final static Set EMPTY_QUALIFIER_SET = Collections.emptySet(); private final static Map> EMPTY_METADATAS_MAP = Collections.emptyMap(); + private final ReentrantLock lock = new ReentrantLock(); private Set contracts; private String implementation; private String name; @@ -203,19 +205,29 @@ public DescriptorImpl( } @Override - public synchronized Set getAdvertisedContracts() { - if (contracts == null) return EMPTY_CONTRACTS_SET; - return Collections.unmodifiableSet(contracts); + public Set getAdvertisedContracts() { + lock.lock(); + try { + if (contracts == null) return EMPTY_CONTRACTS_SET; + return Collections.unmodifiableSet(contracts); + } finally { + lock.unlock(); + } } /** * Adds an advertised contract to the set of contracts advertised by this descriptor * @param addMe The contract to add. May not be null */ - public synchronized void addAdvertisedContract(String addMe) { - if (addMe == null) return; - if (contracts == null) contracts = new LinkedHashSet(); - contracts.add(addMe); + public void addAdvertisedContract(String addMe) { + lock.lock(); + try { + if (addMe == null) return; + if (contracts == null) contracts = new LinkedHashSet(); + contracts.add(addMe); + } finally { + lock.unlock(); + } } /** @@ -223,54 +235,94 @@ public synchronized void addAdvertisedContract(String addMe) { * @param removeMe The contract to remove. May not be null * @return true if removeMe was removed from the set */ - public synchronized boolean removeAdvertisedContract(String removeMe) { - if (removeMe == null || contracts == null) return false; - return contracts.remove(removeMe); + public boolean removeAdvertisedContract(String removeMe) { + lock.lock(); + try { + if (removeMe == null || contracts == null) return false; + return contracts.remove(removeMe); + } finally { + lock.unlock(); + } } @Override - public synchronized String getImplementation() { - return implementation; + public String getImplementation() { + lock.lock(); + try { + return implementation; + } finally { + lock.unlock(); + } } /** * Sets the implementation * @param implementation The implementation this descriptor should have */ - public synchronized void setImplementation(String implementation) { - this.implementation = implementation; + public void setImplementation(String implementation) { + lock.lock(); + try { + this.implementation = implementation; + } finally { + lock.unlock(); + } } @Override - public synchronized String getScope() { - return scope; + public String getScope() { + lock.lock(); + try { + return scope; + } finally { + lock.unlock(); + } } /** * Sets the scope this descriptor should have * @param scope The scope of this descriptor */ - public synchronized void setScope(String scope) { - this.scope = scope; + public void setScope(String scope) { + lock.lock(); + try { + this.scope = scope; + } finally { + lock.unlock(); + } } @Override - public synchronized String getName() { - return name; + public String getName() { + lock.lock(); + try { + return name; + } finally { + lock.unlock(); + } } /** * Sets the name this descriptor should have * @param name The name for this descriptor */ - public synchronized void setName(String name) { - this.name = name; + public void setName(String name) { + lock.lock(); + try { + this.name = name; + } finally { + lock.unlock(); + } } @Override - public synchronized Set getQualifiers() { - if (qualifiers == null) return EMPTY_QUALIFIER_SET; - return Collections.unmodifiableSet(qualifiers); + public Set getQualifiers() { + lock.lock(); + try { + if (qualifiers == null) return EMPTY_QUALIFIER_SET; + return Collections.unmodifiableSet(qualifiers); + } finally { + lock.unlock(); + } } /** @@ -278,10 +330,15 @@ public synchronized Set getQualifiers() { * * @param addMe The fully qualified class name of the qualifier to add. May not be null */ - public synchronized void addQualifier(String addMe) { - if (addMe == null) return; - if (qualifiers == null) qualifiers = new LinkedHashSet(); - qualifiers.add(addMe); + public void addQualifier(String addMe) { + lock.lock(); + try { + if (addMe == null) return; + if (qualifiers == null) qualifiers = new LinkedHashSet(); + qualifiers.add(addMe); + } finally { + lock.unlock(); + } } /** @@ -290,44 +347,74 @@ public synchronized void addQualifier(String addMe) { * @param removeMe The fully qualifier class name of the qualifier to remove. May not be null * @return true if the given qualifier was removed */ - public synchronized boolean removeQualifier(String removeMe) { - if (removeMe == null) return false; - if (qualifiers == null) return false; - return qualifiers.remove(removeMe); + public boolean removeQualifier(String removeMe) { + lock.lock(); + try { + if (removeMe == null) return false; + if (qualifiers == null) return false; + return qualifiers.remove(removeMe); + } finally { + lock.unlock(); + } } @Override - public synchronized DescriptorType getDescriptorType() { - return descriptorType; + public DescriptorType getDescriptorType() { + lock.lock(); + try { + return descriptorType; + } finally { + lock.unlock(); + } } /** * Sets the descriptor type * @param descriptorType The descriptor type. May not be null */ - public synchronized void setDescriptorType(DescriptorType descriptorType) { - if (descriptorType == null) throw new IllegalArgumentException(); - this.descriptorType = descriptorType; + public void setDescriptorType(DescriptorType descriptorType) { + lock.lock(); + try { + if (descriptorType == null) throw new IllegalArgumentException(); + this.descriptorType = descriptorType; + } finally { + lock.unlock(); + } } @Override - public synchronized DescriptorVisibility getDescriptorVisibility() { - return descriptorVisibility; + public DescriptorVisibility getDescriptorVisibility() { + lock.lock(); + try { + return descriptorVisibility; + } finally { + lock.unlock(); + } } /** * Sets the descriptor visilibity * @param descriptorVisibility The visibility this descriptor should have */ - public synchronized void setDescriptorVisibility(DescriptorVisibility descriptorVisibility) { - if (descriptorVisibility == null) throw new IllegalArgumentException(); - this.descriptorVisibility = descriptorVisibility; + public void setDescriptorVisibility(DescriptorVisibility descriptorVisibility) { + lock.lock(); + try { + if (descriptorVisibility == null) throw new IllegalArgumentException(); + this.descriptorVisibility = descriptorVisibility; + } finally { + lock.unlock(); + } } @Override - public synchronized Map> getMetadata() { - if (metadatas == null) return EMPTY_METADATAS_MAP; - return Collections.unmodifiableMap(metadatas); + public Map> getMetadata() { + lock.lock(); + try { + if (metadatas == null) return EMPTY_METADATAS_MAP; + return Collections.unmodifiableMap(metadatas); + } finally { + lock.unlock(); + } } /** @@ -339,15 +426,20 @@ public synchronized Map> getMetadata() { * @param metadata The non-null metadata that this descriptor * should have */ - public synchronized void setMetadata(Map> metadata) { - if (metadatas == null) { - metadatas = new LinkedHashMap>(); - } - else { - metadatas.clear(); - } - - metadatas.putAll(ReflectionHelper.deepCopyMetadata(metadata)); + public void setMetadata(Map> metadata) { + lock.lock(); + try { + if (metadatas == null) { + metadatas = new LinkedHashMap>(); + } + else { + metadatas.clear(); + } + + metadatas.putAll(ReflectionHelper.deepCopyMetadata(metadata)); + } finally { + lock.unlock(); + } } /** @@ -357,10 +449,15 @@ public synchronized void setMetadata(Map> metadata) { * @param metadata The non-null but possibly empty list of fields * to add to the metadata map */ - public synchronized void addMetadata(Map> metadata) { - if (metadatas == null) metadatas = new LinkedHashMap>(); - - metadatas.putAll(ReflectionHelper.deepCopyMetadata(metadata)); + public void addMetadata(Map> metadata) { + lock.lock(); + try { + if (metadatas == null) metadatas = new LinkedHashMap>(); + + metadatas.putAll(ReflectionHelper.deepCopyMetadata(metadata)); + } finally { + lock.unlock(); + } } /** @@ -370,9 +467,14 @@ public synchronized void addMetadata(Map> metadata) { * not contain the character '=' * @param value The value to add. May not be null */ - public synchronized void addMetadata(String key, String value) { - if (metadatas == null) metadatas = new LinkedHashMap>(); - ReflectionHelper.addMetadata(metadatas, key, value); + public void addMetadata(String key, String value) { + lock.lock(); + try { + if (metadatas == null) metadatas = new LinkedHashMap>(); + ReflectionHelper.addMetadata(metadatas, key, value); + } finally { + lock.unlock(); + } } /** @@ -383,9 +485,14 @@ public synchronized void addMetadata(String key, String value) { * @param value The value to remove. May not be null * @return true if the value was removed */ - public synchronized boolean removeMetadata(String key, String value) { - if (metadatas == null) return false; - return ReflectionHelper.removeMetadata(metadatas, key, value); + public boolean removeMetadata(String key, String value) { + lock.lock(); + try { + if (metadatas == null) return false; + return ReflectionHelper.removeMetadata(metadatas, key, value); + } finally { + lock.unlock(); + } } /** @@ -394,60 +501,100 @@ public synchronized boolean removeMetadata(String key, String value) { * @param key The key of the metadata values to remove * @return true if any value was removed */ - public synchronized boolean removeAllMetadata(String key) { - if (metadatas == null) return false; - return ReflectionHelper.removeAllMetadata(metadatas, key); + public boolean removeAllMetadata(String key) { + lock.lock(); + try { + if (metadatas == null) return false; + return ReflectionHelper.removeAllMetadata(metadatas, key); + } finally { + lock.unlock(); + } } /** * Removes all metadata values */ - public synchronized void clearMetadata() { - metadatas = null; + public void clearMetadata() { + lock.lock(); + try { + metadatas = null; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.api.Descriptor#getLoader() */ @Override - public synchronized HK2Loader getLoader() { - return loader; + public HK2Loader getLoader() { + lock.lock(); + try { + return loader; + } finally { + lock.unlock(); + } } /** * Sets the loader to use with this descriptor * @param loader The loader to use with this descriptor */ - public synchronized void setLoader(HK2Loader loader) { - this.loader = loader; + public void setLoader(HK2Loader loader) { + lock.lock(); + try { + this.loader = loader; + } finally { + lock.unlock(); + } } @Override - public synchronized int getRanking() { - return rank; + public int getRanking() { + lock.lock(); + try { + return rank; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.api.Descriptor#setRanking(int) */ @Override - public synchronized int setRanking(int ranking) { - int retVal = rank; - rank = ranking; - return retVal; + public int setRanking(int ranking) { + lock.lock(); + try { + int retVal = rank; + rank = ranking; + return retVal; + } finally { + lock.unlock(); + } } @Override - public synchronized Long getServiceId() { - return id; + public Long getServiceId() { + lock.lock(); + try { + return id; + } finally { + lock.unlock(); + } } /** * Sets the service id for this descriptor * @param id the service id for this descriptor */ - public synchronized void setServiceId(Long id) { - this.id = id; + public void setServiceId(Long id) { + lock.lock(); + try { + this.id = id; + } finally { + lock.unlock(); + } } @Override @@ -501,16 +648,26 @@ public void setClassAnalysisName(String name) { } @Override - public synchronized Long getLocatorId() { - return locatorId; + public Long getLocatorId() { + lock.lock(); + try { + return locatorId; + } finally { + lock.unlock(); + } } /** * Sets the locator id for this descriptor * @param locatorId the locator id for this descriptor */ - public synchronized void setLocatorId(Long locatorId) { - this.locatorId = locatorId; + public void setLocatorId(Long locatorId) { + lock.lock(); + try { + this.locatorId = locatorId; + } finally { + lock.unlock(); + } } public int hashCode() { @@ -724,14 +881,19 @@ public static void pretty(StringBuffer sb, Descriptor d) { } - public synchronized String toString() { - StringBuffer sb = new StringBuffer("Descriptor("); - - pretty(sb, this); - - sb.append(")"); - - return sb.toString(); + public String toString() { + lock.lock(); + try { + StringBuffer sb = new StringBuffer("Descriptor("); + + pretty(sb, this); + + sb.append(")"); + + return sb.toString(); + } finally { + lock.unlock(); + } } /** diff --git a/hk2-api/src/main/java/org/glassfish/hk2/utilities/ImmediateContext.java b/hk2-api/src/main/java/org/glassfish/hk2/utilities/ImmediateContext.java index d609ee44ed..cd5d557aff 100755 --- a/hk2-api/src/main/java/org/glassfish/hk2/utilities/ImmediateContext.java +++ b/hk2-api/src/main/java/org/glassfish/hk2/utilities/ImmediateContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -48,6 +50,8 @@ */ @Singleton @Visibility(DescriptorVisibility.LOCAL) public class ImmediateContext implements Context{ + private final ReentrantLock lock = new ReentrantLock(); + private final Condition notEmpty = lock.newCondition(); private final HashMap, HandleAndService> currentImmediateServices = new HashMap, HandleAndService>(); private final HashMap, Long> creating = new HashMap, Long>(); @@ -76,7 +80,8 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, ServiceHandle root) { U retVal = null; - synchronized (this) { + lock.lock(); + try { HandleAndService has = currentImmediateServices.get(activeDescriptor); if (has != null) { return (U) has.getService(); @@ -91,7 +96,7 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, } try { - this.wait(); + notEmpty.await(); } catch (InterruptedException ie) { throw new MultiException(ie); @@ -105,13 +110,16 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, } creating.put(activeDescriptor, Thread.currentThread().getId()); + } finally { + lock.unlock(); } try { retVal = activeDescriptor.create(root); } finally { - synchronized (this) { + lock.lock(); + try { ServiceHandle discoveredRoot = null; if (root != null) { if (root.getActiveDescriptor().equals(activeDescriptor)) { @@ -124,7 +132,9 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, } creating.remove(activeDescriptor); - this.notifyAll(); + notEmpty.signalAll(); + } finally { + lock.unlock(); } } @@ -137,8 +147,13 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, * @return true if this service has been created */ @Override - public synchronized boolean containsKey(ActiveDescriptor descriptor) { - return currentImmediateServices.containsKey(descriptor); + public boolean containsKey(ActiveDescriptor descriptor) { + lock.lock(); + try { + return currentImmediateServices.containsKey(descriptor); + } finally { + lock.unlock(); + } } @Override @@ -158,7 +173,8 @@ private void destroyOne(ActiveDescriptor descriptor, List descriptor, List errorHandlers = locator.getAllServices(ImmediateErrorHandler.class); - synchronized (this) { + lock.lock(); + try { for (Map.Entry, HandleAndService> entry : new HashSet, HandleAndService>>(currentImmediateServices.entrySet())) { HandleAndService has = entry.getValue(); @@ -214,6 +233,8 @@ public void shutdown() { } + } finally { + lock.unlock(); } } @@ -250,11 +271,12 @@ public void doWork() { LinkedHashSet> newFullSet = new LinkedHashSet>(inScopeAndInThisLocator); LinkedHashSet> addMe = new LinkedHashSet>(); - synchronized (this) { + lock.lock(); + try { // First thing to do is wait until all the things in-flight have gone while (creating.size() > 0) { try { - this.wait(); + notEmpty.await(); } catch (InterruptedException ie) { throw new RuntimeException(ie); @@ -282,6 +304,8 @@ public void doWork() { destroyOne(gone, errorHandlers); } } + } finally { + lock.unlock(); } for (ActiveDescriptor ad : addMe) { diff --git a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfigurationListener.java b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfigurationListener.java index cd0d7e24df..94b68712f8 100755 --- a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfigurationListener.java +++ b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfigurationListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; import jakarta.annotation.PostConstruct; import jakarta.inject.Inject; @@ -84,7 +85,7 @@ public class ConfigurationListener implements BeanDatabaseUpdateListener { private final ConcurrentHashMap typeInformation = new ConcurrentHashMap(); - private final Object progenitorLock = new Object(); + private final ReentrantLock progenitorLock = new ReentrantLock(); private HashSet> allProgenitors = new HashSet>(); @@ -329,8 +330,11 @@ private void initialize(BeanDatabase database) { List> progenitors = locator.getDescriptors(new NoNameTypeFilter(locator, null, null)); - synchronized (progenitorLock) { + progenitorLock.lock(); + try { allProgenitors.addAll(progenitors); + } finally { + progenitorLock.unlock(); } config.addActiveDescriptor(DescriptorListener.class); @@ -523,8 +527,8 @@ private void calculateProgenitorAddsAndRemoves() { final DynamicConfiguration config = configurationService.createDynamicConfiguration(); final LinkedList> addedList = new LinkedList>(); final LinkedList> removedList = new LinkedList>(); - - synchronized (progenitorLock) { + progenitorLock.lock(); + try { HashSet> removed = new HashSet>(allProgenitors); progenitors = locator.getDescriptors(new NoNameTypeFilter(locator, null, null)); @@ -553,6 +557,8 @@ private void calculateProgenitorAddsAndRemoves() { } } + } finally { + progenitorLock.unlock(); } if (!addedList.isEmpty() || !removedList.isEmpty()) { diff --git a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByContext.java b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByContext.java index f7f4a4a559..3285cdcf7b 100755 --- a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByContext.java +++ b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Singleton; @@ -42,7 +43,7 @@ public class ConfiguredByContext implements Context { private final static ThreadLocal> workingOn = ThreadLocal.withInitial(() -> null); - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private final Map, Object> db = new HashMap<>(); /* (non-Javadoc) @@ -76,7 +77,8 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, @SuppressWarnings("unchecked") private U internalFindOrCreate(ActiveDescriptor activeDescriptor, ServiceHandle root) { - synchronized (lock) { + lock.lock(); + try { U retVal = (U) db.get(activeDescriptor); if (retVal != null) return retVal; @@ -88,6 +90,8 @@ private U internalFindOrCreate(ActiveDescriptor activeDescriptor, db.put(activeDescriptor, retVal); return retVal; + } finally { + lock.unlock(); } } @@ -96,8 +100,11 @@ private U internalFindOrCreate(ActiveDescriptor activeDescriptor, */ @Override public boolean containsKey(ActiveDescriptor descriptor) { - synchronized (lock) { + lock.lock(); + try { return db.containsKey(descriptor); + } finally { + lock.unlock(); } } @@ -107,11 +114,14 @@ public boolean containsKey(ActiveDescriptor descriptor) { @SuppressWarnings("unchecked") @Override public void destroyOne(ActiveDescriptor descriptor) { - synchronized (lock) { + lock.lock(); + try { Object destroyMe = db.remove(descriptor); if (destroyMe == null) return; ((ActiveDescriptor) descriptor).dispose(destroyMe); + } finally { + lock.unlock(); } } @@ -137,11 +147,14 @@ public boolean isActive() { */ @Override public void shutdown() { - synchronized (lock) { + lock.lock(); + try { Set> activeDescriptors = new HashSet<>(db.keySet()); for (ActiveDescriptor killMe : activeDescriptors) { destroyOne(killMe); } + } finally { + lock.unlock(); } } @@ -151,8 +164,11 @@ public void shutdown() { } /* package */ Object findOnly(ActiveDescriptor descriptor) { - synchronized (lock) { + lock.lock(); + try { return db.get(descriptor); + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByInjectionResolver.java b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByInjectionResolver.java index 9e44f6e3b9..05a0e58f7f 100755 --- a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByInjectionResolver.java +++ b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/ConfiguredByInjectionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,6 +22,7 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; import jakarta.inject.Named; @@ -48,7 +49,8 @@ public class ConfiguredByInjectionResolver implements @Inject private ConfiguredByContext context; - + + private final ReentrantLock lock = new ReentrantLock(); private final ConcurrentHashMap, BeanInfo> beanMap = new ConcurrentHashMap, BeanInfo>(); private static String getParameterNameFromConstructor(Constructor cnst, int position) { @@ -95,38 +97,43 @@ private static String getParameterNameFromMethod(Method method, int position) { * @see org.glassfish.hk2.api.InjectionResolver#resolve(org.glassfish.hk2.api.Injectee, org.glassfish.hk2.api.ServiceHandle) */ @Override - public synchronized Object resolve(Injectee injectee, ServiceHandle root) { - ActiveDescriptor injecteeParent = injectee.getInjecteeDescriptor(); - if (injecteeParent == null) return systemResolver.resolve(injectee, root); - - AnnotatedElement ae = injectee.getParent(); - if (ae == null) return systemResolver.resolve(injectee, root); - - String parameterName = null; - if (ae instanceof Field) { - parameterName = BeanUtilities.getParameterNameFromField((Field) ae, false); - } - else if (ae instanceof Constructor) { - parameterName = getParameterNameFromConstructor((Constructor) ae, injectee.getPosition()); - } - else if (ae instanceof Method){ - parameterName = getParameterNameFromMethod((Method) ae, injectee.getPosition()); - } - else { - return systemResolver.resolve(injectee, root); - } - - if (parameterName == null) return systemResolver.resolve(injectee, root); - - ActiveDescriptor workingOn = context.getWorkingOn(); - if (workingOn == null) return systemResolver.resolve(injectee, root); - - BeanInfo beanInfo = beanMap.get(workingOn); - if (beanInfo == null) { - throw new IllegalStateException("Could not find a configuration bean for " + injectee + " with descriptor " + workingOn); + public Object resolve(Injectee injectee, ServiceHandle root) { + lock.lock(); + try { + ActiveDescriptor injecteeParent = injectee.getInjecteeDescriptor(); + if (injecteeParent == null) return systemResolver.resolve(injectee, root); + + AnnotatedElement ae = injectee.getParent(); + if (ae == null) return systemResolver.resolve(injectee, root); + + String parameterName = null; + if (ae instanceof Field) { + parameterName = BeanUtilities.getParameterNameFromField((Field) ae, false); + } + else if (ae instanceof Constructor) { + parameterName = getParameterNameFromConstructor((Constructor) ae, injectee.getPosition()); + } + else if (ae instanceof Method){ + parameterName = getParameterNameFromMethod((Method) ae, injectee.getPosition()); + } + else { + return systemResolver.resolve(injectee, root); + } + + if (parameterName == null) return systemResolver.resolve(injectee, root); + + ActiveDescriptor workingOn = context.getWorkingOn(); + if (workingOn == null) return systemResolver.resolve(injectee, root); + + BeanInfo beanInfo = beanMap.get(workingOn); + if (beanInfo == null) { + throw new IllegalStateException("Could not find a configuration bean for " + injectee + " with descriptor " + workingOn); + } + + return BeanUtilities.getBeanPropertyValue(injectee.getRequiredType(), parameterName, beanInfo); + } finally { + lock.unlock(); } - - return BeanUtilities.getBeanPropertyValue(injectee.getRequiredType(), parameterName, beanInfo); } /* (non-Javadoc) @@ -145,14 +152,25 @@ public boolean isMethodParameterIndicator() { return true; } - /* package */ synchronized BeanInfo addBean(ActiveDescriptor descriptor, Object bean, String type, Object metadata) { - BeanInfo retVal = new BeanInfo(type, descriptor.getName(), bean, metadata); - beanMap.put(descriptor, retVal); - return retVal; + /* package */ BeanInfo addBean(ActiveDescriptor descriptor, Object bean, String type, Object metadata) { + lock.lock(); + try { + BeanInfo retVal = new BeanInfo(type, descriptor.getName(), bean, metadata); + beanMap.put(descriptor, retVal); + return retVal; + } finally { + lock.unlock(); + } } - /* package */ synchronized void removeBean(ActiveDescriptor descriptor) { - beanMap.remove(descriptor); + /* package */ void removeBean(ActiveDescriptor descriptor) { + + lock.lock(); + try { + beanMap.remove(descriptor); + } finally { + lock.unlock(); + } } @Override diff --git a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/DelegatingNamedActiveDescriptor.java b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/DelegatingNamedActiveDescriptor.java index 2b9d7b99b3..4e7f411f92 100755 --- a/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/DelegatingNamedActiveDescriptor.java +++ b/hk2-configuration/hk2-integration/src/main/java/org/glassfish/hk2/configuration/internal/DelegatingNamedActiveDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Named; @@ -187,7 +188,7 @@ public Long getLocatorId() { return null; } - private Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private Object cache; private boolean isSet = false; @@ -196,8 +197,11 @@ public Long getLocatorId() { */ @Override public Object getCache() { - synchronized (lock) { + lock.lock(); + try { return cache; + } finally { + lock.unlock(); } } @@ -206,8 +210,11 @@ public Object getCache() { */ @Override public boolean isCacheSet() { - synchronized (lock) { + lock.lock(); + try { return isSet; + } finally { + lock.unlock(); } } @@ -216,9 +223,12 @@ public boolean isCacheSet() { */ @Override public void setCache(Object cacheMe) { - synchronized (lock) { + lock.lock(); + try { isSet = true; cache = cacheMe; + } finally { + lock.unlock(); } } @@ -228,9 +238,12 @@ public void setCache(Object cacheMe) { */ @Override public void releaseCache() { - synchronized (lock) { + lock.lock(); + try { cache = null; isSet = false; + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/BeanDatabaseImpl.java b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/BeanDatabaseImpl.java index 88a60775d0..ef2e4a2922 100755 --- a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/BeanDatabaseImpl.java +++ b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/BeanDatabaseImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.configuration.hub.api.BeanDatabase; import org.glassfish.hk2.configuration.hub.api.Instance; @@ -32,6 +33,7 @@ */ public class BeanDatabaseImpl implements BeanDatabase { private final long revision; + private final ReentrantLock lock = new ReentrantLock(); private final HashMap types = new HashMap(); /** @@ -53,27 +55,42 @@ public class BeanDatabaseImpl implements BeanDatabase { * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#getAllTypes() */ @Override - public synchronized Set getAllTypes() { - return Collections.unmodifiableSet(new HashSet(types.values())); + public Set getAllTypes() { + lock.lock(); + try { + return Collections.unmodifiableSet(new HashSet(types.values())); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#getInstance(java.lang.String, java.lang.Object) */ @Override - public synchronized Instance getInstance(String type, String instanceKey) { - Type t = getType(type); - if (t == null) return null; - - return t.getInstance(instanceKey); + public Instance getInstance(String type, String instanceKey) { + lock.lock(); + try { + Type t = getType(type); + if (t == null) return null; + + return t.getInstance(instanceKey); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#getType(java.lang.String) */ @Override - public synchronized Type getType(String type) { - return types.get(type); + public Type getType(String type) { + lock.lock(); + try { + return types.get(type); + } finally { + lock.unlock(); + } } /* package */ long getRevision() { diff --git a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/HubImpl.java b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/HubImpl.java index 01ce8d2e1f..34bc904e4b 100755 --- a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/HubImpl.java +++ b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/HubImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,7 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; @@ -48,7 +49,7 @@ public class HubImpl implements Hub { private static final AtomicLong revisionCounter = new AtomicLong(1); - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private BeanDatabaseImpl currentDatabase = new BeanDatabaseImpl(revisionCounter.getAndIncrement()); @Inject @@ -59,8 +60,11 @@ public class HubImpl implements Hub { */ @Override public BeanDatabase getCurrentDatabase() { - synchronized (lock) { + lock.lock(); + try { return currentDatabase; + } finally { + lock.unlock(); } } @@ -69,15 +73,19 @@ public BeanDatabase getCurrentDatabase() { */ @Override public WriteableBeanDatabase getWriteableDatabaseCopy() { - synchronized (lock) { + lock.lock(); + try { return new WriteableBeanDatabaseImpl(this, currentDatabase); + } finally { + lock.unlock(); } } private int inTransaction = 0; /* package */ LinkedList prepareCurrentDatabase(WriteableBeanDatabaseImpl writeableDatabase, Object commitMessage, List changes) { - synchronized (lock) { + lock.lock(); + try { if (inTransaction > 0) { throw new IllegalStateException("This Hub is already in a transaction"); } @@ -115,12 +123,15 @@ public WriteableBeanDatabase getWriteableDatabaseCopy() { inTransaction++; return completedListeners; + } finally { + lock.unlock(); } } /* package */ void activateCurrentDatabase(WriteableBeanDatabaseImpl writeableDatabase, Object commitMessage, List changes, LinkedList completedListeners) { - synchronized (lock) { + lock.lock(); + try { inTransaction--; if (inTransaction < 0) inTransaction = 0; @@ -149,12 +160,15 @@ public WriteableBeanDatabase getWriteableDatabaseCopy() { } if (commitError != null) throw commitError; + } finally { + lock.unlock(); } } /* package */ void rollbackCurrentDatabase(WriteableBeanDatabaseImpl writeableDatabase, Object commitMessage, List changes, LinkedList completedListeners) { - synchronized (lock) { + lock.lock(); + try { inTransaction--; if (inTransaction < 0) inTransaction = 0; @@ -179,6 +193,8 @@ public WriteableBeanDatabase getWriteableDatabaseCopy() { } if (rollbackError != null) throw rollbackError; + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/InstanceImpl.java b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/InstanceImpl.java index 5f016f51b2..b570107192 100755 --- a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/InstanceImpl.java +++ b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/InstanceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,6 +16,8 @@ package org.glassfish.hk2.configuration.hub.internal; +import java.util.concurrent.locks.ReentrantLock; + import org.glassfish.hk2.configuration.hub.api.Instance; /** @@ -23,6 +25,7 @@ * */ public class InstanceImpl implements Instance { + private final ReentrantLock lock = new ReentrantLock(); private final Object bean; private Object metadata; @@ -43,8 +46,13 @@ public Object getBean() { * @see org.glassfish.hk2.configuration.hub.api.Instance#getMetadata() */ @Override - public synchronized Object getMetadata() { - return metadata; + public Object getMetadata() { + lock.lock(); + try { + return metadata; + } finally { + lock.unlock(); + } } /* (non-Javadoc) diff --git a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/TypeImpl.java b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/TypeImpl.java index ad57647107..6ddbc8ae12 100755 --- a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/TypeImpl.java +++ b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/TypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.configuration.hub.api.Instance; import org.glassfish.hk2.configuration.hub.api.Type; @@ -28,6 +29,7 @@ * */ public class TypeImpl implements Type { + private final ReentrantLock lock = new ReentrantLock(); private final String name; private final Map instances; private final ClassReflectionHelper helper; @@ -74,17 +76,26 @@ public Instance getInstance(String key) { * @see org.glassfish.hk2.configuration.hub.api.Type#getMetadata() */ @Override - public synchronized Object getMetadata() { - return metadata; + public Object getMetadata() { + lock.lock(); + try { + return metadata; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.Type#setMetadata(java.lang.Object) */ @Override - public synchronized void setMetadata(Object metadata) { - this.metadata = metadata; - + public void setMetadata(Object metadata) { + lock.lock(); + try { + this.metadata = metadata; + } finally { + lock.unlock(); + } } @Override diff --git a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableBeanDatabaseImpl.java b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableBeanDatabaseImpl.java index cb728c315c..786e81be80 100755 --- a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableBeanDatabaseImpl.java +++ b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableBeanDatabaseImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import java.util.LinkedList; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.MultiException; import org.glassfish.hk2.api.TwoPhaseResource; @@ -43,7 +44,8 @@ public class WriteableBeanDatabaseImpl implements WriteableBeanDatabase { private final HashMap types = new HashMap(); private final HubImpl hub; private final TwoPhaseResourceImpl resource = new TwoPhaseResourceImpl(); - + + private final ReentrantLock lock = new ReentrantLock(); private final LinkedList changes = new LinkedList(); private final LinkedList removedTypes = new LinkedList(); private boolean committed = false; @@ -63,8 +65,13 @@ public class WriteableBeanDatabaseImpl implements WriteableBeanDatabase { * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#getAllTypes() */ @Override - public synchronized Set getAllTypes() { - return Collections.unmodifiableSet(new HashSet(types.values())); + public Set getAllTypes() { + lock.lock(); + try { + return Collections.unmodifiableSet(new HashSet(types.values())); + } finally { + lock.unlock(); + } } /* (non-Javadoc) @@ -79,19 +86,29 @@ public Set getAllWriteableTypes() { * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#getType(java.lang.String) */ @Override - public synchronized Type getType(String type) { - return types.get(type); + public Type getType(String type) { + lock.lock(); + try { + return types.get(type); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#getInstance(java.lang.String, java.lang.Object) */ @Override - public synchronized Instance getInstance(String type, String instanceKey) { - Type t = getType(type); - if (t == null) return null; - - return t.getInstance(instanceKey); + public Instance getInstance(String type, String instanceKey) { + lock.lock(); + try { + Type t = getType(type); + if (t == null) return null; + + return t.getInstance(instanceKey); + } finally { + lock.unlock(); + } } private void checkState() { @@ -102,75 +119,95 @@ private void checkState() { * @see org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase#addType(java.lang.String) */ @Override - public synchronized WriteableType addType(String typeName) { - if (typeName == null) throw new IllegalArgumentException(); - checkState(); - - WriteableTypeImpl wti = new WriteableTypeImpl(this, typeName); - - changes.add(new ChangeImpl(Change.ChangeCategory.ADD_TYPE, - wti, - null, - null, - null, - null)); - - types.put(typeName, wti); - - return wti; + public WriteableType addType(String typeName) { + lock.lock(); + try { + if (typeName == null) throw new IllegalArgumentException(); + checkState(); + + WriteableTypeImpl wti = new WriteableTypeImpl(this, typeName); + + changes.add(new ChangeImpl(Change.ChangeCategory.ADD_TYPE, + wti, + null, + null, + null, + null)); + + types.put(typeName, wti); + + return wti; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase#removeType(java.lang.String) */ @Override - public synchronized Type removeType(String typeName) { - if (typeName == null) throw new IllegalArgumentException(); - checkState(); - - WriteableTypeImpl retVal = types.remove(typeName); - if (retVal == null) return null; - - Map instances = retVal.getInstances(); - for (String key : new HashSet(instances.keySet())) { - retVal.removeInstance(key); + public Type removeType(String typeName) { + lock.lock(); + try { + if (typeName == null) throw new IllegalArgumentException(); + checkState(); + + WriteableTypeImpl retVal = types.remove(typeName); + if (retVal == null) return null; + + Map instances = retVal.getInstances(); + for (String key : new HashSet(instances.keySet())) { + retVal.removeInstance(key); + } + + changes.add(new ChangeImpl(Change.ChangeCategory.REMOVE_TYPE, + retVal, + null, + null, + null, + null)); + + removedTypes.add(retVal); + + return retVal; + } finally { + lock.unlock(); } - - changes.add(new ChangeImpl(Change.ChangeCategory.REMOVE_TYPE, - retVal, - null, - null, - null, - null)); - - removedTypes.add(retVal); - - return retVal; } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase#getWriteableType(java.lang.String) */ @Override - public synchronized WriteableType getWriteableType(String typeName) { - checkState(); - return types.get(typeName); + public WriteableType getWriteableType(String typeName) { + lock.lock(); + try { + checkState(); + return types.get(typeName); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase#findOrAddWriteableType(java.lang.String) */ @Override - public synchronized WriteableType findOrAddWriteableType(String typeName) { - if (typeName == null) throw new IllegalArgumentException(); - checkState(); - - WriteableTypeImpl wti = types.get(typeName); - if (wti == null) { - return addType(typeName); + public WriteableType findOrAddWriteableType(String typeName) { + lock.lock(); + try { + if (typeName == null) throw new IllegalArgumentException(); + checkState(); + + WriteableTypeImpl wti = types.get(typeName); + if (wti == null) { + return addType(typeName); + } + + return wti; + } finally { + lock.unlock(); } - - return wti; } /* (non-Javadoc) @@ -179,8 +216,11 @@ public synchronized WriteableType findOrAddWriteableType(String typeName) { @Override public void commit() { Object defaultCommit; - synchronized (this) { + lock.lock(); + try { defaultCommit = commitMessage; + } finally { + lock.unlock(); } commit(defaultCommit); @@ -191,10 +231,13 @@ public void commit() { */ @Override public void commit(Object commitMessage) { - synchronized (this) { + lock.lock(); + try { checkState(); committed = true; + } finally { + lock.unlock(); } // Outside of lock @@ -211,8 +254,13 @@ public void commit(Object commitMessage) { return baseRevision; } - /* package */ synchronized void addChange(Change change) { - changes.add(change); + /* package */ void addChange(Change change) { + lock.lock(); + try { + changes.add(change); + } finally { + lock.unlock(); + } } /* (non-Javadoc) @@ -227,8 +275,13 @@ public void dumpDatabase() { * @see org.glassfish.hk2.configuration.hub.api.BeanDatabase#dumpDatabase(java.io.PrintStream) */ @Override - public synchronized void dumpDatabase(PrintStream output) { - Utilities.dumpDatabase(this, output); + public void dumpDatabase(PrintStream output) { + lock.lock(); + try { + Utilities.dumpDatabase(this, output); + } finally { + lock.unlock(); + } } /* (non-Javadoc) @@ -251,16 +304,26 @@ public TwoPhaseResource getTwoPhaseResource() { * @see org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase#getCommitMessage() */ @Override - public synchronized Object getCommitMessage() { - return commitMessage; + public Object getCommitMessage() { + lock.lock(); + try { + return commitMessage; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableBeanDatabase#setCommitMessage(java.lang.Object) */ @Override - public synchronized void setCommitMessage(Object commitMessage) { - this.commitMessage = commitMessage; + public void setCommitMessage(Object commitMessage) { + lock.lock(); + try { + this.commitMessage = commitMessage; + } finally { + lock.unlock(); + } } @@ -276,12 +339,15 @@ public void prepareDynamicConfiguration( TwoPhaseTransactionData dynamicConfiguration) throws MultiException { Object defaultCommit; - synchronized (WriteableBeanDatabaseImpl.this) { + WriteableBeanDatabaseImpl.this.lock.lock(); + try { checkState(); committed = true; defaultCommit = commitMessage; + } finally { + WriteableBeanDatabaseImpl.this.lock.unlock(); } // Outside of lock @@ -298,8 +364,11 @@ public void activateDynamicConfiguration( this.completedListeners = null; Object defaultCommit; - synchronized (WriteableBeanDatabaseImpl.this) { + WriteableBeanDatabaseImpl.this.lock.lock(); + try { defaultCommit = commitMessage; + } finally { + WriteableBeanDatabaseImpl.this.lock.unlock(); } hub.activateCurrentDatabase(WriteableBeanDatabaseImpl.this, defaultCommit, changes, completedListeners); @@ -322,10 +391,13 @@ public void rollbackDynamicConfiguration( this.completedListeners = null; Object defaultCommit; - synchronized (WriteableBeanDatabaseImpl.this) { + WriteableBeanDatabaseImpl.this.lock.lock(); + try { defaultCommit = commitMessage; + } finally { + WriteableBeanDatabaseImpl.this.lock.unlock(); } - + hub.rollbackCurrentDatabase(WriteableBeanDatabaseImpl.this, defaultCommit, changes, completedListeners); for (WriteableTypeImpl removedType : removedTypes) { diff --git a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableTypeImpl.java b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableTypeImpl.java index 995de982b3..19a14d14f1 100755 --- a/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableTypeImpl.java +++ b/hk2-configuration/manager/src/main/java/org/glassfish/hk2/configuration/hub/internal/WriteableTypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.configuration.hub.api.Change; import org.glassfish.hk2.configuration.hub.api.Instance; @@ -34,6 +35,7 @@ * */ public class WriteableTypeImpl implements WriteableType { + private final ReentrantLock lock = new ReentrantLock(); private final WriteableBeanDatabaseImpl parent; private final String name; private final HashMap beanMap = new HashMap(); @@ -66,101 +68,131 @@ public String getName() { * @see org.glassfish.hk2.configuration.hub.api.Type#getInstances() */ @Override - public synchronized Map getInstances() { - return Collections.unmodifiableMap(beanMap); + public Map getInstances() { + lock.lock(); + try { + return Collections.unmodifiableMap(beanMap); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.Type#getInstance(java.lang.Object) */ @Override - public synchronized Instance getInstance(String key) { - return beanMap.get(key); + public Instance getInstance(String key) { + lock.lock(); + try { + return beanMap.get(key); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableType#addInstance(java.lang.Object, java.lang.Object) */ @Override - public synchronized Instance addInstance(String key, Object bean) { - return addInstance(key, bean, null); + public Instance addInstance(String key, Object bean) { + lock.lock(); + try { + return addInstance(key, bean, null); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableType#addInstance(java.lang.Object, java.lang.Object) */ @Override - public synchronized Instance addInstance(String key, Object bean, Object metadata) { - if (key == null || bean == null) throw new IllegalArgumentException(); - - InstanceImpl ii = new InstanceImpl(bean, metadata); - - parent.addChange(new ChangeImpl(Change.ChangeCategory.ADD_INSTANCE, - this, - key, - ii, - null, - null)); - - beanMap.put(key, ii); - - return ii; + public Instance addInstance(String key, Object bean, Object metadata) { + lock.lock(); + try { + if (key == null || bean == null) throw new IllegalArgumentException(); + + InstanceImpl ii = new InstanceImpl(bean, metadata); + + parent.addChange(new ChangeImpl(Change.ChangeCategory.ADD_INSTANCE, + this, + key, + ii, + null, + null)); + + beanMap.put(key, ii); + + return ii; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableType#removeInstance(java.lang.Object) */ @Override - public synchronized Instance removeInstance(String key) { - if (key == null) throw new IllegalArgumentException(); - - Instance removedValue = beanMap.remove(key); - if (removedValue == null) return null; - - parent.addChange(new ChangeImpl(Change.ChangeCategory.REMOVE_INSTANCE, - this, - key, - removedValue, - null, - null)); - - return removedValue; + public Instance removeInstance(String key) { + lock.lock(); + try { + if (key == null) throw new IllegalArgumentException(); + + Instance removedValue = beanMap.remove(key); + if (removedValue == null) return null; + + parent.addChange(new ChangeImpl(Change.ChangeCategory.REMOVE_INSTANCE, + this, + key, + removedValue, + null, + null)); + + return removedValue; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.WriteableType#modifyInstance(java.lang.Object, java.lang.Object, java.beans.PropertyChangeEvent[]) */ @Override - public synchronized PropertyChangeEvent[] modifyInstance(String key, Object newBean, + public PropertyChangeEvent[] modifyInstance(String key, Object newBean, PropertyChangeEvent... propChanges) { - if (key == null || newBean == null) throw new IllegalArgumentException(); - - Instance oldInstance = beanMap.get(key); - if (oldInstance == null) { - throw new IllegalStateException("Attempting to modify bean with key " + key + " but no such bean exists"); - } - - InstanceImpl newInstance = new InstanceImpl(newBean, oldInstance.getMetadata()); - - if (propChanges.length == 0) { - propChanges = BeanReflectionHelper.getChangeEvents(helper, oldInstance.getBean(), newInstance.getBean()); - } - - beanMap.put(key, newInstance); + lock.lock(); + try { + if (key == null || newBean == null) throw new IllegalArgumentException(); + + Instance oldInstance = beanMap.get(key); + if (oldInstance == null) { + throw new IllegalStateException("Attempting to modify bean with key " + key + " but no such bean exists"); + } + + InstanceImpl newInstance = new InstanceImpl(newBean, oldInstance.getMetadata()); + + if (propChanges.length == 0) { + propChanges = BeanReflectionHelper.getChangeEvents(helper, oldInstance.getBean(), newInstance.getBean()); + } + + beanMap.put(key, newInstance); - ArrayList propChangesList = new ArrayList(propChanges.length); - for (PropertyChangeEvent pce : propChanges) { - propChangesList.add(pce); + ArrayList propChangesList = new ArrayList(propChanges.length); + for (PropertyChangeEvent pce : propChanges) { + propChangesList.add(pce); + } + + parent.addChange(new ChangeImpl(Change.ChangeCategory.MODIFY_INSTANCE, + this, + key, + newInstance, + oldInstance, + propChangesList)); + + return propChanges; + } finally { + lock.unlock(); } - - parent.addChange(new ChangeImpl(Change.ChangeCategory.MODIFY_INSTANCE, - this, - key, - newInstance, - oldInstance, - propChangesList)); - - return propChanges; } ClassReflectionHelper getHelper() { @@ -171,16 +203,26 @@ ClassReflectionHelper getHelper() { * @see org.glassfish.hk2.configuration.hub.api.Type#getMetadata() */ @Override - public synchronized Object getMetadata() { - return metadata; + public Object getMetadata() { + lock.lock(); + try { + return metadata; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.configuration.hub.api.Type#setMetadata(java.lang.Object) */ @Override - public synchronized void setMetadata(Object metadata) { - this.metadata = metadata; + public void setMetadata(Object metadata) { + lock.lock(); + try { + this.metadata = metadata; + } finally { + lock.unlock(); + } } @Override diff --git a/hk2-configuration/manager/src/test/java/org/glassfish/hk2/configuration/hub/test/AbstractCountingListener.java b/hk2-configuration/manager/src/test/java/org/glassfish/hk2/configuration/hub/test/AbstractCountingListener.java index 805fa0dabd..72e6f2deb4 100755 --- a/hk2-configuration/manager/src/test/java/org/glassfish/hk2/configuration/hub/test/AbstractCountingListener.java +++ b/hk2-configuration/manager/src/test/java/org/glassfish/hk2/configuration/hub/test/AbstractCountingListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -17,6 +17,7 @@ package org.glassfish.hk2.configuration.hub.test; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Singleton; @@ -30,20 +31,36 @@ */ @Singleton public class AbstractCountingListener implements BeanDatabaseUpdateListener { + private final ReentrantLock lock = new ReentrantLock(); private int prepareCalled; private int rollbackCalled; private int commitCalled; - public synchronized int getNumPreparesCalled() { - return prepareCalled; + public int getNumPreparesCalled() { + lock.lock(); + try { + return prepareCalled; + } finally { + lock.unlock(); + } } - public synchronized int getNumCommitsCalled() { - return commitCalled; + public int getNumCommitsCalled() { + lock.lock(); + try { + return commitCalled; + } finally { + lock.unlock(); + } } - public synchronized int getNumRollbackCalled() { - return rollbackCalled; + public int getNumRollbackCalled() { + lock.lock(); + try { + return rollbackCalled; + } finally { + lock.unlock(); + } } public void prepareAction() { @@ -59,11 +76,16 @@ public void rollbackAction() { * @see org.glassfish.hk2.configuration.hub.api.BeanDatabaseUpdateListener#prepareDatabaseChange(org.glassfish.hk2.configuration.hub.api.BeanDatabase, org.glassfish.hk2.configuration.hub.api.BeanDatabase, java.lang.Object, java.util.List) */ @Override - public synchronized void prepareDatabaseChange(BeanDatabase currentDatabase, + public void prepareDatabaseChange(BeanDatabase currentDatabase, BeanDatabase proposedDatabase, Object commitMessage, List changes) { - prepareCalled++; - prepareAction(); + lock.lock(); + try { + prepareCalled++; + prepareAction(); + } finally { + lock.unlock(); + } } /* (non-Javadoc) diff --git a/hk2-configuration/persistence/hk2-xml/hk2-pbuf/src/main/java/org/glassfish/hk2/pbuf/internal/PBufParser.java b/hk2-configuration/persistence/hk2-xml/hk2-pbuf/src/main/java/org/glassfish/hk2/pbuf/internal/PBufParser.java index 53918bd5d2..6cc525ee09 100755 --- a/hk2-configuration/persistence/hk2-xml/hk2-pbuf/src/main/java/org/glassfish/hk2/pbuf/internal/PBufParser.java +++ b/hk2-configuration/persistence/hk2-xml/hk2-pbuf/src/main/java/org/glassfish/hk2/pbuf/internal/PBufParser.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; import jakarta.inject.Named; @@ -75,6 +76,8 @@ @Named(PBufUtilities.PBUF_SERVICE_NAME) @Visibility(DescriptorVisibility.LOCAL) public class PBufParser implements XmlServiceParser { + private final ReentrantLock lockProtos = new ReentrantLock(); + private final ReentrantLock lockEnums = new ReentrantLock(); private final HashMap, Descriptors.Descriptor> allProtos = new HashMap, Descriptors.Descriptor>(); private final HashMap, Descriptors.EnumDescriptor> allEnums = new HashMap, Descriptors.EnumDescriptor>(); @@ -401,8 +404,11 @@ private DynamicMessage internalUnmarshal(ModelImpl model, byte[] bytes) throws E String protoName = getSimpleName(originalInterface); Descriptors.Descriptor descriptor; - synchronized (allProtos) { + lockProtos.lock(); + try { descriptor = allProtos.get(originalAsClass); + } finally { + lockProtos.unlock(); } if (descriptor == null) { throw new IOException("Unknown model: " + originalInterface + " with protoName=" + protoName); @@ -424,8 +430,11 @@ private DynamicMessage internalMarshal(XmlHk2ConfigurationBean bean) throws String protoName = getSimpleName(originalInterface); Descriptors.Descriptor descriptor; - synchronized (allProtos) { + lockProtos.lock(); + try { descriptor = allProtos.get(originalAsClass); + } finally { + lockProtos.unlock(); } if (descriptor == null) { @@ -515,7 +524,8 @@ private DynamicMessage internalMarshal(XmlHk2ConfigurationBean bean) throws } private void convertAllModels(ModelImpl model, Set protoFiles) throws Exception { - synchronized (allProtos) { + lockProtos.lock(); + try { Class modelClass = model.getOriginalInterfaceAsClass(); Descriptors.Descriptor dd = allProtos.get(modelClass); if (dd != null) { @@ -538,6 +548,8 @@ private void convertAllModels(ModelImpl model, Set p protoFiles.add(converted.getFile()); allProtos.put(modelClass, converted); + } finally { + lockProtos.unlock(); } } @@ -824,7 +836,8 @@ private static String getExtendedSimpleName(Class expectedType) { private String convertEnumToDescriptor(ChildDataModel childDataModel, Set knownFiles) throws Exception { - synchronized (allEnums) { + lockEnums.lock(); + try { Class expectedType = childDataModel.getChildTypeAsClass(); if (allEnums.containsKey(expectedType)) { return "." + expectedType.getName(); @@ -868,6 +881,8 @@ private String convertEnumToDescriptor(ChildDataModel childDataModel, allEnums.put(expectedType, fD); return "." + enumTypeName; + } finally { + lockEnums.unlock(); } } @@ -882,8 +897,11 @@ private Object convertFieldForMarshal(Object field, Class expectedType) { if (expectedType.isEnum()) { Descriptors.EnumDescriptor enumDescriptor; - synchronized (allEnums) { + lockEnums.lock(); + try { enumDescriptor = allEnums.get(expectedType); + } finally { + lockEnums.unlock(); } if (enumDescriptor == null) { @@ -923,8 +941,11 @@ private Object convertFieldForUnmarshal(Object field, ChildDataModel expected) { if (expectedType.isEnum()) { Descriptors.EnumDescriptor enumDescriptor; - synchronized (allEnums) { + lockEnums.lock(); + try { enumDescriptor = allEnums.get(expectedType); + } finally { + lockEnums.unlock(); } if (enumDescriptor == null) { diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ChildDataModel.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ChildDataModel.java index ced59f6d09..3a43e24e62 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ChildDataModel.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ChildDataModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -19,6 +19,7 @@ import java.io.Serializable; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.general.GeneralUtilities; @@ -44,7 +45,7 @@ public class ChildDataModel implements Serializable { TYPE_MAP.put("boolean", boolean.class); }; - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); /** Set at compile time, the type of the thing */ private String childType; @@ -113,13 +114,17 @@ public String getXmlAlias() { } public void setLoader(ClassLoader myLoader) { - synchronized (lock) { + lock.lock(); + try { this.myLoader = myLoader; + } finally { + lock.unlock(); } } public Class getChildTypeAsClass() { - synchronized (lock) { + lock.lock(); + try { if (childTypeAsClass != null) return childTypeAsClass; childTypeAsClass = TYPE_MAP.get(childType); @@ -128,12 +133,15 @@ public Class getChildTypeAsClass() { childTypeAsClass = GeneralUtilities.loadClass(myLoader, childType); return childTypeAsClass; + } finally { + lock.unlock(); } } public Class getChildListTypeAsClass() { - synchronized (lock) { + lock.lock(); + try { if (childListType == null) return null; if (childListTypeAsClass != null) return childListTypeAsClass; @@ -143,6 +151,8 @@ public Class getChildListTypeAsClass() { childListTypeAsClass = GeneralUtilities.loadClass(myLoader, childListType); return childListTypeAsClass; + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/JAUtilities.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/JAUtilities.java index 12408e46b8..a8e5c6484c 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/JAUtilities.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/JAUtilities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import java.util.LinkedHashSet; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; import javassist.ClassPool; import javassist.CtClass; @@ -74,7 +75,8 @@ public Boolean run() { public final static String REMOVE = "remove"; public final static String JAXB_DEFAULT_STRING = "##default"; public final static String JAXB_DEFAULT_DEFAULT = "\u0000"; - + + private final ReentrantLock lock = new ReentrantLock(); private final ClassReflectionHelper classReflectionHelper; private final ClassPool defaultClassPool; private final CtClass superClazz; @@ -143,38 +145,43 @@ public ModelImpl getModel(Class iFace) { return entry.getValue(); } - public synchronized void convertRootAndLeaves(Class root, boolean mustConvertAll) { - long currentTime = 0L; - if (DEBUG_GENERATION_TIMING) { - computer.numGenerated = 0; - computer.numPreGenerated = 0; + public void convertRootAndLeaves(Class root, boolean mustConvertAll) { + lock.lock(); + try { + long currentTime = 0L; + if (DEBUG_GENERATION_TIMING) { + computer.numGenerated = 0; + computer.numPreGenerated = 0; + + currentTime = System.currentTimeMillis(); + } + + ModelImpl rootModel = interface2ModelCache.compute(root).getValue(); + if (!mustConvertAll) { + if (DEBUG_GENERATION_TIMING) { + currentTime = System.currentTimeMillis() - currentTime; + + Logger.getLogger().debug("Took " + currentTime + " to perform " + + computer.numGenerated + " generations with " + + computer.numPreGenerated + " pre generated with a lazy parser"); + } + return; + } + + HashSet> cycles = new HashSet>(); + cycles.add(root); + + convertAllRootAndLeaves(rootModel, cycles); - currentTime = System.currentTimeMillis(); - } - - ModelImpl rootModel = interface2ModelCache.compute(root).getValue(); - if (!mustConvertAll) { if (DEBUG_GENERATION_TIMING) { currentTime = System.currentTimeMillis() - currentTime; - Logger.getLogger().debug("Took " + currentTime + " to perform " + + Logger.getLogger().debug("Took " + currentTime + " milliseconds to perform " + computer.numGenerated + " generations with " + - computer.numPreGenerated + " pre generated with a lazy parser"); + computer.numPreGenerated + " pre generated with a non-lazy parser"); } - return; - } - - HashSet> cycles = new HashSet>(); - cycles.add(root); - - convertAllRootAndLeaves(rootModel, cycles); - - if (DEBUG_GENERATION_TIMING) { - currentTime = System.currentTimeMillis() - currentTime; - - Logger.getLogger().debug("Took " + currentTime + " milliseconds to perform " + - computer.numGenerated + " generations with " + - computer.numPreGenerated + " pre generated with a non-lazy parser"); + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ModelImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ModelImpl.java index 278c4de2a7..d454c3d034 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ModelImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ModelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -24,6 +24,7 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; @@ -48,8 +49,10 @@ public class ModelImpl implements Model { private static final long serialVersionUID = 752816761552710497L; + private final ReentrantLock lock = new ReentrantLock(); /** For thread safety on the computed fields */ - private final static Object lock = new Object(); + // This is probably wrong, no need for static lock + private final static ReentrantLock slock = new ReentrantLock(); /** The interface from which the JAXB proxy was created, fully qualified */ private String originalInterface; @@ -261,7 +264,8 @@ public ChildDataModel getValueData() { } public Set getAllXmlWrappers() { - synchronized (lock) { + slock.lock(); + try { if (allXmlWrappers != null) return allXmlWrappers; allXmlWrappers = new LinkedHashSet(); @@ -272,6 +276,8 @@ public Set getAllXmlWrappers() { } return allXmlWrappers; + } finally { + slock.unlock(); } } @@ -280,7 +286,8 @@ public ChildDescriptor getChildDescriptor(QName xmlTag) { } public Set getUnKeyedChildren() { - synchronized (lock) { + slock.lock(); + try { if (unKeyedChildren != null) return unKeyedChildren; unKeyedChildren = new HashSet(); @@ -291,11 +298,14 @@ public Set getUnKeyedChildren() { } return unKeyedChildren; + } finally { + slock.unlock(); } } public Set getKeyedChildren() { - synchronized (lock) { + slock.lock(); + try { if (keyedChildren != null) return keyedChildren; keyedChildren = new HashSet(); @@ -306,11 +316,14 @@ public Set getKeyedChildren() { } return keyedChildren; + } finally { + slock.unlock(); } } public void setJAUtilities(JAUtilities jaUtilities, ClassLoader myLoader) { - synchronized (lock) { + slock.lock(); + try { if (this.jaUtilities != null) return; this.jaUtilities = jaUtilities; this.myLoader = myLoader; @@ -322,46 +335,60 @@ public void setJAUtilities(JAUtilities jaUtilities, ClassLoader myLoader) { for (ChildDataModel cdm : nonChildProperty.values()) { cdm.setLoader(myLoader); } + } finally { + slock.unlock(); } } public String getDefaultChildValue(String propNamespace, String propName) { QName propQName = QNameUtilities.createQName(propNamespace, propName); - synchronized (lock) { + slock.lock(); + try { ChildDataModel cd = nonChildProperty.get(propQName); if (cd == null) return null; return cd.getDefaultAsString(); + } finally { + slock.unlock(); } } public ModelPropertyType getModelPropertyType(String propNamespace, String propName) { QName propQName = QNameUtilities.createQName(propNamespace, propName); - synchronized (lock) { + slock.lock(); + try { if (nonChildProperty.containsKey(propQName)) return ModelPropertyType.FLAT_PROPERTY; if (childrenByName.containsKey(propQName)) return ModelPropertyType.TREE_ROOT; return ModelPropertyType.UNKNOWN; + } finally { + slock.unlock(); } } public Class getNonChildType(String propNamespace, String propName) { QName propQName = QNameUtilities.createQName(propNamespace, propName); - synchronized (lock) { + slock.lock(); + try { ChildDataModel cd = nonChildProperty.get(propQName); if (cd == null) return null; return cd.getChildTypeAsClass(); + } finally { + slock.unlock(); } } public ParentedModel getChild(String propNamespace, String propName) { QName propQName = QNameUtilities.createQName(propNamespace, propName); - synchronized (lock) { + slock.lock(); + try { return childrenByName.get(propQName); + } finally { + slock.unlock(); } } @@ -369,12 +396,15 @@ public ParentedModel getChild(String propNamespace, String propName) { public Class getOriginalInterfaceAsClass() { if (originalInterfaceAsClass != null) return originalInterfaceAsClass; - synchronized (lock) { + slock.lock(); + try { if (originalInterfaceAsClass != null) return originalInterfaceAsClass; originalInterfaceAsClass = GeneralUtilities.loadClass(myLoader, originalInterface); return originalInterfaceAsClass; + } finally { + slock.unlock(); } } @@ -382,24 +412,33 @@ public Class getOriginalInterfaceAsClass() { public Class getProxyAsClass() { if (translatedClassAsClass != null) return translatedClassAsClass; - synchronized (lock) { + slock.lock(); + try { if (translatedClassAsClass != null) return translatedClassAsClass; translatedClassAsClass = GeneralUtilities.loadClass(myLoader, translatedClass); return translatedClassAsClass; + } finally { + slock.unlock(); } } public Collection getAllChildren() { - synchronized (lock) { + slock.lock(); + try { return Collections.unmodifiableCollection(childrenByName.values()); + } finally { + slock.unlock(); } } public Map getChildrenProperties() { - synchronized (lock) { + slock.lock(); + try { return Collections.unmodifiableMap(childrenByName); + } finally { + slock.unlock(); } } @@ -441,52 +480,57 @@ public Map getAllElementChildren() { return retVal; } - public synchronized String getJavaNameFromKey(String key, ClassReflectionHelper reflectionHelper) { - if (keyToJavaNameMap == null) { - keyToJavaNameMap = new LinkedHashMap(); - } - - String result = keyToJavaNameMap.get(key); - if (result != null) return result; - - if (reflectionHelper == null) return null; - - Class originalInterface = getOriginalInterfaceAsClass(); - - for (MethodWrapper wrapper : reflectionHelper.getAllMethods(originalInterface)) { - Method m = wrapper.getMethod(); + public String getJavaNameFromKey(String key, ClassReflectionHelper reflectionHelper) { + lock.lock(); + try { + if (keyToJavaNameMap == null) { + keyToJavaNameMap = new LinkedHashMap(); + } - String xmlName; + String result = keyToJavaNameMap.get(key); + if (result != null) return result; - XmlElement element = m.getAnnotation(XmlElement.class); - if (element == null) { - XmlAttribute attribute = m.getAnnotation(XmlAttribute.class); - if (attribute == null) continue; - - xmlName = attribute.name(); - } - else { - xmlName = element.name(); - } + if (reflectionHelper == null) return null; - String keyName; - String javaName = getJavaNameFromGetterOrSetter(m, reflectionHelper); + Class originalInterface = getOriginalInterfaceAsClass(); - if ("##default".equals(xmlName)) { - keyName = javaName; - } - else { - keyName = xmlName; + for (MethodWrapper wrapper : reflectionHelper.getAllMethods(originalInterface)) { + Method m = wrapper.getMethod(); + + String xmlName; + + XmlElement element = m.getAnnotation(XmlElement.class); + if (element == null) { + XmlAttribute attribute = m.getAnnotation(XmlAttribute.class); + if (attribute == null) continue; + + xmlName = attribute.name(); + } + else { + xmlName = element.name(); + } + + String keyName; + String javaName = getJavaNameFromGetterOrSetter(m, reflectionHelper); + + if ("##default".equals(xmlName)) { + keyName = javaName; + } + else { + keyName = xmlName; + } + + if (!key.equals(keyName)) continue; + + // Found it! + keyToJavaNameMap.put(key, javaName); + return javaName; } - if (!key.equals(keyName)) continue; - - // Found it! - keyToJavaNameMap.put(key, javaName); - return javaName; + return null; + } finally { + lock.unlock(); } - - return null; } private static String getJavaNameFromGetterOrSetter(Method m, ClassReflectionHelper reflectionHelper) { diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ParentedModel.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ParentedModel.java index f4c182c1f5..7e845eec88 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ParentedModel.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/ParentedModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -17,6 +17,7 @@ package org.glassfish.hk2.xml.internal; import java.io.Serializable; +import java.util.concurrent.locks.ReentrantLock; import jakarta.xml.bind.annotation.adapters.XmlAdapter; @@ -34,8 +35,8 @@ */ public class ParentedModel implements Serializable { private static final long serialVersionUID = -2480798409414987937L; - - private final Object lock = new Object(); + + private final ReentrantLock lock = new ReentrantLock(); /** The interface of the child for which this is a parent */ private String childInterface; @@ -126,7 +127,8 @@ public String getOriginalMethodName() { @SuppressWarnings("unchecked") public XmlAdapter getAdapterObject() { - synchronized (lock) { + lock.lock(); + try { if (myLoader == null) { throw new IllegalStateException("Cannot call getChildModel before the classloader has been determined"); } @@ -149,12 +151,15 @@ public String getOriginalMethodName() { catch (Exception e) { throw new RuntimeException(e); } + } finally { + lock.unlock(); } } public ModelImpl getChildModel() { - synchronized (lock) { + lock.lock(); + try { if (myLoader == null) { throw new IllegalStateException("Cannot call getChildModel before the classloader has been determined"); } @@ -174,13 +179,18 @@ public ModelImpl getChildModel() { } return childModel; + } finally { + lock.unlock(); } } public void setRuntimeInformation(JAUtilities jaUtilities, ClassLoader myLoader) { - synchronized (lock) { + lock.lock(); + try { this.jaUtilities = jaUtilities; this.myLoader = myLoader; + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/UnkeyedDiff.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/UnkeyedDiff.java index b4c3141c80..8e94904c30 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/UnkeyedDiff.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/UnkeyedDiff.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.cache.CacheUtilities; import org.glassfish.hk2.utilities.cache.Computable; @@ -48,7 +49,8 @@ public Boolean run() { return Boolean.getBoolean(UNKEYED_DEBUG_PROPERTY); } }); - + + private final ReentrantLock lock = new ReentrantLock(); private final List legacyList; private final List proposedList; private final ParentedModel parentModel; @@ -90,22 +92,27 @@ public UnkeyedDiff(Object legacy[], Object proposed[], BaseHK2JAXBBean parent, P this(asList(legacy), asList(proposed), parent, parentModel); } - public synchronized Differences compute() { - if (computed) return finalSolution; - - Differences retVal = null; + public Differences compute() { + lock.lock(); try { - retVal = internalCompute(); - } - finally { - if (retVal != null) { - finalSolution = retVal; + if (computed) return finalSolution; - computed = true; + Differences retVal = null; + try { + retVal = internalCompute(); } + finally { + if (retVal != null) { + finalSolution = retVal; + + computed = true; + } + } + + return retVal; + } finally { + lock.unlock(); } - - return retVal; } private Differences internalCompute() { diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/AnnotationAltAnnotationImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/AnnotationAltAnnotationImpl.java index e377aa87b2..1e9199e660 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/AnnotationAltAnnotationImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/AnnotationAltAnnotationImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.reflection.ClassReflectionHelper; import org.glassfish.hk2.utilities.reflection.ReflectionHelper; @@ -44,7 +45,8 @@ public class AnnotationAltAnnotationImpl implements AltAnnotation { DO_NOT_HANDLE_METHODS.add("toString"); DO_NOT_HANDLE_METHODS.add("annotationType"); } - + + private final ReentrantLock lock = new ReentrantLock(); private final Annotation annotation; private final ClassReflectionHelper helper; private Map values; @@ -75,33 +77,48 @@ public String annotationType() { * @see org.glassfish.hk2.xml.internal.alt.AltAnnotation#getStringValue(java.lang.String) */ @Override - public synchronized String getStringValue(String methodName) { - if (values == null) getAnnotationValues(); - - if (XmlElementImpl.class.equals(annotation.getClass()) && - "getTypeByName".equals(methodName)) { - XmlElementImpl xei = (XmlElementImpl) annotation; - return xei.getTypeByName(); + public String getStringValue(String methodName) { + lock.lock(); + try { + if (values == null) getAnnotationValues(); + + if (XmlElementImpl.class.equals(annotation.getClass()) && + "getTypeByName".equals(methodName)) { + XmlElementImpl xei = (XmlElementImpl) annotation; + return xei.getTypeByName(); + } + + return (String) values.get(methodName); + } finally { + lock.unlock(); } - - return (String) values.get(methodName); } /* (non-Javadoc) * @see org.glassfish.hk2.xml.internal.alt.AltAnnotation#getBooleanValue(java.lang.String) */ @Override - public synchronized boolean getBooleanValue(String methodName) { - if (values == null) getAnnotationValues(); - - return (Boolean) values.get(methodName); + public boolean getBooleanValue(String methodName) { + lock.lock(); + try { + if (values == null) getAnnotationValues(); + + return (Boolean) values.get(methodName); + } finally { + lock.unlock(); + } } @Override - public synchronized String[] getStringArrayValue(String methodName) { - if (values == null) getAnnotationValues(); - - return (String[]) values.get(methodName); + public String[] getStringArrayValue(String methodName) { + lock.lock(); + try { + if (values == null) getAnnotationValues(); + + return (String[]) values.get(methodName); + } finally { + lock.unlock(); + } } @Override @@ -122,76 +139,81 @@ public AltClass getClassValue(String methodName) { * @see org.glassfish.hk2.xml.internal.alt.AltAnnotation#getAnnotationValues() */ @Override - public synchronized Map getAnnotationValues() { - if (values != null) return values; - - Map retVal = new TreeMap(); - for (Method javaAnnotationMethod : annotation.annotationType().getMethods()) { - if (javaAnnotationMethod.getParameterTypes().length != 0) continue; - if (DO_NOT_HANDLE_METHODS.contains(javaAnnotationMethod.getName())) continue; - - String key = javaAnnotationMethod.getName(); + public Map getAnnotationValues() { + lock.lock(); + try { + if (values != null) return values; - Object value; - try { - value = ReflectionHelper.invoke(annotation, javaAnnotationMethod, new Object[0], false); + Map retVal = new TreeMap(); + for (Method javaAnnotationMethod : annotation.annotationType().getMethods()) { + if (javaAnnotationMethod.getParameterTypes().length != 0) continue; + if (DO_NOT_HANDLE_METHODS.contains(javaAnnotationMethod.getName())) continue; - if (value == null) { - throw new AssertionError("Recieved null from annotation method " + javaAnnotationMethod.getName()); - } - } - catch (RuntimeException re) { - throw re; - } - catch (Throwable th) { - throw new RuntimeException(th); - } - - if (value instanceof Class) { - value = new ClassAltClassImpl((Class) value, helper); - } - else if (Enum.class.isAssignableFrom(value.getClass())) { - value = new EnumAltEnumImpl((Enum) value); - } - else if (value.getClass().isArray() && Class.class.equals(value.getClass().getComponentType())) { - Class cValue[] = (Class[]) value; + String key = javaAnnotationMethod.getName(); - AltClass[] translatedValue = new AltClass[cValue.length]; - - for (int lcv = 0; lcv < cValue.length; lcv++) { - translatedValue[lcv] = new ClassAltClassImpl(cValue[lcv], helper); + Object value; + try { + value = ReflectionHelper.invoke(annotation, javaAnnotationMethod, new Object[0], false); + + if (value == null) { + throw new AssertionError("Recieved null from annotation method " + javaAnnotationMethod.getName()); + } } - - value = translatedValue; - } - else if (value.getClass().isArray() && Enum.class.isAssignableFrom(value.getClass().getComponentType())) { - Enum eValue[] = (Enum[]) value; - - AltEnum[] translatedValue = new AltEnum[eValue.length]; - - for (int lcv = 0; lcv < eValue.length; lcv++) { - translatedValue[lcv] = new EnumAltEnumImpl(eValue[lcv]); + catch (RuntimeException re) { + throw re; + } + catch (Throwable th) { + throw new RuntimeException(th); } - value = translatedValue; - } - else if (value.getClass().isArray() && Annotation.class.isAssignableFrom(value.getClass().getComponentType())) { - Annotation aValue[] = (Annotation[]) value; - - AltAnnotation[] translatedValue = new AltAnnotation[aValue.length]; - - for (int lcv = 0; lcv < aValue.length; lcv++) { - translatedValue[lcv] = new AnnotationAltAnnotationImpl(aValue[lcv], helper); + if (value instanceof Class) { + value = new ClassAltClassImpl((Class) value, helper); + } + else if (Enum.class.isAssignableFrom(value.getClass())) { + value = new EnumAltEnumImpl((Enum) value); + } + else if (value.getClass().isArray() && Class.class.equals(value.getClass().getComponentType())) { + Class cValue[] = (Class[]) value; + + AltClass[] translatedValue = new AltClass[cValue.length]; + + for (int lcv = 0; lcv < cValue.length; lcv++) { + translatedValue[lcv] = new ClassAltClassImpl(cValue[lcv], helper); + } + + value = translatedValue; + } + else if (value.getClass().isArray() && Enum.class.isAssignableFrom(value.getClass().getComponentType())) { + Enum eValue[] = (Enum[]) value; + + AltEnum[] translatedValue = new AltEnum[eValue.length]; + + for (int lcv = 0; lcv < eValue.length; lcv++) { + translatedValue[lcv] = new EnumAltEnumImpl(eValue[lcv]); + } + + value = translatedValue; + } + else if (value.getClass().isArray() && Annotation.class.isAssignableFrom(value.getClass().getComponentType())) { + Annotation aValue[] = (Annotation[]) value; + + AltAnnotation[] translatedValue = new AltAnnotation[aValue.length]; + + for (int lcv = 0; lcv < aValue.length; lcv++) { + translatedValue[lcv] = new AnnotationAltAnnotationImpl(aValue[lcv], helper); + } + + value = translatedValue; } - value = translatedValue; + retVal.put(key, value); } - retVal.put(key, value); + values = Collections.unmodifiableMap(retVal); + return values; + } finally { + lock.unlock(); } - - values = Collections.unmodifiableMap(retVal); - return values; } @Override diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/ClassAltClassImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/ClassAltClassImpl.java index 2ceb9ee50f..11c59ba8ec 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/ClassAltClassImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/ClassAltClassImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.xml.bind.annotation.adapters.XmlAdapter; @@ -51,7 +52,8 @@ public class ClassAltClassImpl implements AltClass { public static final AltClass DOUBLE = new ClassAltClassImpl(double.class, SCALAR_HELPER); public static final AltClass OBJECT = new ClassAltClassImpl(Object.class, SCALAR_HELPER); public static final AltClass XML_ADAPTER = new ClassAltClassImpl(XmlAdapter.class, SCALAR_HELPER); - + + private final ReentrantLock lock = new ReentrantLock(); private final Class clazz; private final ClassReflectionHelper helper; private List methods; @@ -86,36 +88,46 @@ public String getSimpleName() { * @see org.glassfish.hk2.xml.internal.alt.AltClass#getAnnotations() */ @Override - public synchronized List getAnnotations() { - if (annotations != null) return annotations; - - Annotation annotationz[] = clazz.getAnnotations(); - - ArrayList retVal = new ArrayList(annotationz.length); - for (Annotation annotation : annotationz) { - retVal.add(new AnnotationAltAnnotationImpl(annotation, helper)); + public List getAnnotations() { + lock.lock(); + try { + if (annotations != null) return annotations; + + Annotation annotationz[] = clazz.getAnnotations(); + + ArrayList retVal = new ArrayList(annotationz.length); + for (Annotation annotation : annotationz) { + retVal.add(new AnnotationAltAnnotationImpl(annotation, helper)); + } + + annotations = Collections.unmodifiableList(retVal); + return annotations; + } finally { + lock.unlock(); } - - annotations = Collections.unmodifiableList(retVal); - return annotations; } /* (non-Javadoc) * @see org.glassfish.hk2.xml.internal.alt.AltClass#getMethods() */ @Override - public synchronized List getMethods() { - if (methods != null) return methods; - - Set wrappers = helper.getAllMethods(clazz); - ArrayList retVal = new ArrayList(wrappers.size()); - - for (MethodWrapper method : wrappers) { - retVal.add(new MethodAltMethodImpl(method.getMethod(), helper)); + public List getMethods() { + lock.lock(); + try { + if (methods != null) return methods; + + Set wrappers = helper.getAllMethods(clazz); + ArrayList retVal = new ArrayList(wrappers.size()); + + for (MethodWrapper method : wrappers) { + retVal.add(new MethodAltMethodImpl(method.getMethod(), helper)); + } + + methods = Collections.unmodifiableList(retVal); + return methods; + } finally { + lock.unlock(); } - - methods = Collections.unmodifiableList(retVal); - return methods; } @Override diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/MethodAltMethodImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/MethodAltMethodImpl.java index 158bbfd682..70185290ed 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/MethodAltMethodImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/clazz/MethodAltMethodImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.reflection.ClassReflectionHelper; import org.glassfish.hk2.utilities.reflection.ReflectionHelper; @@ -35,6 +36,7 @@ * */ public class MethodAltMethodImpl implements AltMethod { + private final ReentrantLock lock = new ReentrantLock(); private final Method method; private final ClassReflectionHelper helper; private List parameterTypes; @@ -73,18 +75,23 @@ public AltClass getReturnType() { * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getParameterTypes() */ @Override - public synchronized List getParameterTypes() { - if (parameterTypes != null) return parameterTypes; - - Class pTypes[] = method.getParameterTypes(); - List retVal = new ArrayList(pTypes.length); - - for (Class pType : pTypes) { - retVal.add(new ClassAltClassImpl(pType, helper)); + public List getParameterTypes() { + lock.lock(); + try { + if (parameterTypes != null) return parameterTypes; + + Class pTypes[] = method.getParameterTypes(); + List retVal = new ArrayList(pTypes.length); + + for (Class pType : pTypes) { + retVal.add(new ClassAltClassImpl(pType, helper)); + } + + parameterTypes = Collections.unmodifiableList(retVal); + return parameterTypes; + } finally { + lock.unlock(); } - - parameterTypes = Collections.unmodifiableList(retVal); - return parameterTypes; } /* (non-Javadoc) @@ -143,18 +150,23 @@ public AltAnnotation getAnnotation(String annotation) { * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getAnnotations() */ @Override - public synchronized List getAnnotations() { - if (altAnnotations != null) return altAnnotations; - - Annotation annotations[] = method.getAnnotations(); - ArrayList retVal = new ArrayList(annotations.length); - - for (Annotation annotation : annotations) { - retVal.add(new AnnotationAltAnnotationImpl(annotation, helper)); + public List getAnnotations() { + lock.lock(); + try { + if (altAnnotations != null) return altAnnotations; + + Annotation annotations[] = method.getAnnotations(); + ArrayList retVal = new ArrayList(annotations.length); + + for (Annotation annotation : annotations) { + retVal.add(new AnnotationAltAnnotationImpl(annotation, helper)); + } + + altAnnotations = Collections.unmodifiableList(retVal); + return altAnnotations; + } finally { + lock.unlock(); } - - altAnnotations = Collections.unmodifiableList(retVal); - return altAnnotations; } /* (non-Javadoc) diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/AnnotationMirrorAltAnnotationImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/AnnotationMirrorAltAnnotationImpl.java index 7c9efd9a7e..bb956c7811 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/AnnotationMirrorAltAnnotationImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/AnnotationMirrorAltAnnotationImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.concurrent.locks.ReentrantLock; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; @@ -42,6 +43,7 @@ * */ public class AnnotationMirrorAltAnnotationImpl implements AltAnnotation { + private final ReentrantLock lock = new ReentrantLock(); private final AnnotationMirror annotation; private final ProcessingEnvironment processingEnv; private String type; @@ -56,14 +58,19 @@ public AnnotationMirrorAltAnnotationImpl(AnnotationMirror annotation, Processing * @see org.glassfish.hk2.xml.internal.alt.AltAnnotation#annotationType() */ @Override - public synchronized String annotationType() { - if (type != null) return type; - - DeclaredType dt = annotation.getAnnotationType(); - TypeElement clazzType = (TypeElement) dt.asElement(); - type = Utilities.convertNameToString(clazzType.getQualifiedName()); - - return type; + public String annotationType() { + lock.lock(); + try { + if (type != null) return type; + + DeclaredType dt = annotation.getAnnotationType(); + TypeElement clazzType = (TypeElement) dt.asElement(); + type = Utilities.convertNameToString(clazzType.getQualifiedName()); + + return type; + } finally { + lock.unlock(); + } } /* (non-Javadoc) @@ -87,15 +94,20 @@ public boolean getBooleanValue(String methodName) { } @Override - public synchronized String[] getStringArrayValue(String methodName) { - getAnnotationValues(); - - Object retVal = values.get(methodName); - if (retVal == null || !(retVal instanceof String[])) { - return null; + public String[] getStringArrayValue(String methodName) { + lock.lock(); + try { + getAnnotationValues(); + + Object retVal = values.get(methodName); + if (retVal == null || !(retVal instanceof String[])) { + return null; + } + + return (String[]) values.get(methodName); + } finally { + lock.unlock(); } - - return (String[]) values.get(methodName); } @Override @@ -116,206 +128,211 @@ public AltClass getClassValue(String methodName) { * @see org.glassfish.hk2.xml.internal.alt.AltAnnotation#getAnnotationValues() */ @Override - public synchronized Map getAnnotationValues() { - if (values != null) return values; - - Map rawValues = - processingEnv.getElementUtils().getElementValuesWithDefaults(annotation); - Map retVal = new TreeMap(); - - for (Map.Entry entry : rawValues.entrySet()) { - ExecutableElement annoMethod = entry.getKey(); - AnnotationValue annoValue = entry.getValue(); + public Map getAnnotationValues() { + lock.lock(); + try { + if (values != null) return values; - String key = Utilities.convertNameToString(annoMethod.getSimpleName()); - Object value = annoValue.getValue(); + Map rawValues = + processingEnv.getElementUtils().getElementValuesWithDefaults(annotation); + Map retVal = new TreeMap(); - if (value instanceof TypeMirror) { - // The annotation method is a java.lang.Class - value = Utilities.convertTypeMirror((TypeMirror) value, processingEnv); - } - else if (value instanceof VariableElement) { - // The annotation method is an Enum - VariableElement variable = (VariableElement) value; - - TypeElement enclosing = (TypeElement) variable.getEnclosingElement(); - - String annoClassName = Utilities.convertNameToString(enclosing.getQualifiedName()); - String annoVal = Utilities.convertNameToString(variable.getSimpleName()); + for (Map.Entry entry : rawValues.entrySet()) { + ExecutableElement annoMethod = entry.getKey(); + AnnotationValue annoValue = entry.getValue(); - value = new StringAltEnumImpl(annoClassName, annoVal); - } - else if (value instanceof AnnotationMirror) { - throw new AssertionError("The annotation " + annotation + " key " + key + " has unimplemented type AnnotationMirror"); - } - else if (value instanceof List) { - // The annotation method returns an array of something - ArrayType returnType = (ArrayType) annoMethod.getReturnType(); - TypeMirror arrayTypeMirror = returnType.getComponentType(); - TypeKind arrayTypeKind = arrayTypeMirror.getKind(); + String key = Utilities.convertNameToString(annoMethod.getSimpleName()); + Object value = annoValue.getValue(); - @SuppressWarnings("unchecked") - List array = ((List) value); - - if (TypeKind.INT.equals(arrayTypeMirror.getKind())) { - int[] iValue = new int[array.size()]; + if (value instanceof TypeMirror) { + // The annotation method is a java.lang.Class + value = Utilities.convertTypeMirror((TypeMirror) value, processingEnv); + } + else if (value instanceof VariableElement) { + // The annotation method is an Enum + VariableElement variable = (VariableElement) value; - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Integer) item.getValue(); - } + TypeElement enclosing = (TypeElement) variable.getEnclosingElement(); + + String annoClassName = Utilities.convertNameToString(enclosing.getQualifiedName()); + String annoVal = Utilities.convertNameToString(variable.getSimpleName()); - value = iValue; + value = new StringAltEnumImpl(annoClassName, annoVal); } - else if (TypeKind.DECLARED.equals(arrayTypeMirror.getKind())) { - AltClass[] cValue = new AltClass[array.size()]; - AltEnum[] eValue = new AltEnum[array.size()]; - String[] sValue = new String[array.size()]; - AltAnnotation[] aValue = new AltAnnotation[array.size()]; + else if (value instanceof AnnotationMirror) { + throw new AssertionError("The annotation " + annotation + " key " + key + " has unimplemented type AnnotationMirror"); + } + else if (value instanceof List) { + // The annotation method returns an array of something + ArrayType returnType = (ArrayType) annoMethod.getReturnType(); + TypeMirror arrayTypeMirror = returnType.getComponentType(); + TypeKind arrayTypeKind = arrayTypeMirror.getKind(); + + @SuppressWarnings("unchecked") + List array = ((List) value); - boolean isClass = true; - boolean isEnum = true; - boolean isAnnos = false; - int lcv = 0; - for (AnnotationValue item : array) { - Object itemValue = item.getValue(); - if (itemValue instanceof TypeMirror) { - isClass = true; - isEnum = false; - isAnnos = false; - - cValue[lcv++] = Utilities.convertTypeMirror((TypeMirror) itemValue, processingEnv); + if (TypeKind.INT.equals(arrayTypeMirror.getKind())) { + int[] iValue = new int[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Integer) item.getValue(); } - else if (itemValue instanceof VariableElement) { - isClass = false; - isEnum = true; - isAnnos = false; - - VariableElement variable = (VariableElement) itemValue; - - TypeElement enclosing = (TypeElement) variable.getEnclosingElement(); - - String annoClassName = Utilities.convertNameToString(enclosing.getQualifiedName()); - String annoVal = Utilities.convertNameToString(variable.getSimpleName()); - - eValue[lcv++] = new StringAltEnumImpl(annoClassName, annoVal); + + value = iValue; + } + else if (TypeKind.DECLARED.equals(arrayTypeMirror.getKind())) { + AltClass[] cValue = new AltClass[array.size()]; + AltEnum[] eValue = new AltEnum[array.size()]; + String[] sValue = new String[array.size()]; + AltAnnotation[] aValue = new AltAnnotation[array.size()]; + + boolean isClass = true; + boolean isEnum = true; + boolean isAnnos = false; + int lcv = 0; + for (AnnotationValue item : array) { + Object itemValue = item.getValue(); + if (itemValue instanceof TypeMirror) { + isClass = true; + isEnum = false; + isAnnos = false; + + cValue[lcv++] = Utilities.convertTypeMirror((TypeMirror) itemValue, processingEnv); + } + else if (itemValue instanceof VariableElement) { + isClass = false; + isEnum = true; + isAnnos = false; + + VariableElement variable = (VariableElement) itemValue; + + TypeElement enclosing = (TypeElement) variable.getEnclosingElement(); + + String annoClassName = Utilities.convertNameToString(enclosing.getQualifiedName()); + String annoVal = Utilities.convertNameToString(variable.getSimpleName()); + + eValue[lcv++] = new StringAltEnumImpl(annoClassName, annoVal); + } + else if (itemValue instanceof String) { + isClass = false; + isEnum = false; + isAnnos = false; + + sValue[lcv++] = (String) itemValue; + } + else if (itemValue instanceof List) { + throw new AssertionError("Unimplemented declared List type in " + this); + } + else if (itemValue instanceof AnnotationMirror) { + isClass = false; + isEnum = false; + isAnnos = true; + + aValue[lcv++] = new AnnotationMirrorAltAnnotationImpl((AnnotationMirror) itemValue, processingEnv); + } + else { + throw new AssertionError("Unknown declared type: " + itemValue.getClass().getName()); + } } - else if (itemValue instanceof String) { - isClass = false; - isEnum = false; - isAnnos = false; - - sValue[lcv++] = (String) itemValue; + + if (isClass) { + value = cValue; } - else if (itemValue instanceof List) { - throw new AssertionError("Unimplemented declared List type in " + this); + else if (isEnum) { + value = eValue; } - else if (itemValue instanceof AnnotationMirror) { - isClass = false; - isEnum = false; - isAnnos = true; - - aValue[lcv++] = new AnnotationMirrorAltAnnotationImpl((AnnotationMirror) itemValue, processingEnv); + else if (isAnnos) { + value = aValue; } else { - throw new AssertionError("Unknown declared type: " + itemValue.getClass().getName()); + value = sValue; } } - - if (isClass) { - value = cValue; - } - else if (isEnum) { - value = eValue; - } - else if (isAnnos) { - value = aValue; - } - else { - value = sValue; + else if (TypeKind.LONG.equals(arrayTypeMirror.getKind())) { + long[] iValue = new long[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Long) item.getValue(); + } + + value = iValue; } - } - else if (TypeKind.LONG.equals(arrayTypeMirror.getKind())) { - long[] iValue = new long[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Long) item.getValue(); + else if (TypeKind.SHORT.equals(arrayTypeMirror.getKind())) { + short[] iValue = new short[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Short) item.getValue(); + } + + value = iValue; } - - value = iValue; - } - else if (TypeKind.SHORT.equals(arrayTypeMirror.getKind())) { - short[] iValue = new short[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Short) item.getValue(); + else if (TypeKind.CHAR.equals(arrayTypeMirror.getKind())) { + char[] iValue = new char[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Character) item.getValue(); + } + + value = iValue; } - - value = iValue; - } - else if (TypeKind.CHAR.equals(arrayTypeMirror.getKind())) { - char[] iValue = new char[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Character) item.getValue(); + else if (TypeKind.FLOAT.equals(arrayTypeMirror.getKind())) { + float[] iValue = new float[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Float) item.getValue(); + } + + value = iValue; } - - value = iValue; - } - else if (TypeKind.FLOAT.equals(arrayTypeMirror.getKind())) { - float[] iValue = new float[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Float) item.getValue(); + else if (TypeKind.DOUBLE.equals(arrayTypeMirror.getKind())) { + double[] iValue = new double[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Double) item.getValue(); + } + + value = iValue; } - - value = iValue; - } - else if (TypeKind.DOUBLE.equals(arrayTypeMirror.getKind())) { - double[] iValue = new double[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Double) item.getValue(); + else if (TypeKind.BOOLEAN.equals(arrayTypeMirror.getKind())) { + boolean[] iValue = new boolean[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Boolean) item.getValue(); + } + + value = iValue; } - - value = iValue; - } - else if (TypeKind.BOOLEAN.equals(arrayTypeMirror.getKind())) { - boolean[] iValue = new boolean[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Boolean) item.getValue(); + else if (TypeKind.BYTE.equals(arrayTypeMirror.getKind())) { + byte[] iValue = new byte[array.size()]; + + int lcv = 0; + for (AnnotationValue item : array) { + iValue[lcv++] = (Byte) item.getValue(); + } + + value = iValue; + } - - value = iValue; - } - else if (TypeKind.BYTE.equals(arrayTypeMirror.getKind())) { - byte[] iValue = new byte[array.size()]; - - int lcv = 0; - for (AnnotationValue item : array) { - iValue[lcv++] = (Byte) item.getValue(); + else { + throw new AssertionError("Array type " + arrayTypeKind + " is not implemented"); } - - value = iValue; - - } - else { - throw new AssertionError("Array type " + arrayTypeKind + " is not implemented"); } + + retVal.put(key, value); } - retVal.put(key, value); + values = Collections.unmodifiableMap(retVal); + return values; + } finally { + lock.unlock(); } - - values = Collections.unmodifiableMap(retVal); - return values; } @Override diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ArrayTypeAltClassImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ArrayTypeAltClassImpl.java index 84086b7468..e98debabd7 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ArrayTypeAltClassImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ArrayTypeAltClassImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.util.Collections; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.type.ArrayType; @@ -34,6 +35,7 @@ * */ public class ArrayTypeAltClassImpl implements AltClass { + private final ReentrantLock lock = new ReentrantLock(); private final ArrayType arrayType; private final ProcessingEnvironment processingEnv; private String name; @@ -123,24 +125,34 @@ else if (TypeKind.DECLARED.equals(currentMirror.getKind())) { * @see org.glassfish.hk2.xml.internal.alt.AltClass#getName() */ @Override - public synchronized String getName() { - if (name != null) return name; - - calculateNames(); - - return name; + public String getName() { + lock.lock(); + try { + if (name != null) return name; + + calculateNames(); + + return name; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.xml.internal.alt.AltClass#getSimpleName() */ @Override - public synchronized String getSimpleName() { - if (simpleName != null) return simpleName; - - calculateNames(); - - return simpleName; + public String getSimpleName() { + lock.lock(); + try { + if (simpleName != null) return simpleName; + + calculateNames(); + + return simpleName; + } finally { + lock.unlock(); + } } /* (non-Javadoc) diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ElementAltMethodImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ElementAltMethodImpl.java index 8300684788..31c8c3d5f4 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ElementAltMethodImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/ElementAltMethodImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; @@ -45,6 +46,7 @@ * */ public class ElementAltMethodImpl implements AltMethod { + private final ReentrantLock lock = new ReentrantLock(); private final ExecutableElement method; private final ProcessingEnvironment processingEnv; private List parameters; @@ -69,36 +71,46 @@ public String getName() { * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getReturnType() */ @Override - public synchronized AltClass getReturnType() { - if (returnType != null) return returnType; - - ExecutableType executable = (ExecutableType) method.asType(); - TypeMirror returnMirror = executable.getReturnType(); - - AltClass retVal = Utilities.convertTypeMirror(returnMirror, processingEnv); - - returnType = retVal; - return returnType; + public AltClass getReturnType() { + lock.lock(); + try { + if (returnType != null) return returnType; + + ExecutableType executable = (ExecutableType) method.asType(); + TypeMirror returnMirror = executable.getReturnType(); + + AltClass retVal = Utilities.convertTypeMirror(returnMirror, processingEnv); + + returnType = retVal; + return returnType; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getParameterTypes() */ @Override - public synchronized List getParameterTypes() { - if (parameters != null) return parameters; - - ExecutableType executable = (ExecutableType) method.asType(); - List paramMirrors = executable.getParameterTypes(); - - List retVal = new ArrayList(paramMirrors.size()); - - for (TypeMirror paramMirror : paramMirrors) { - retVal.add(Utilities.convertTypeMirror(paramMirror, processingEnv)); + public List getParameterTypes() { + lock.lock(); + try { + if (parameters != null) return parameters; + + ExecutableType executable = (ExecutableType) method.asType(); + List paramMirrors = executable.getParameterTypes(); + + List retVal = new ArrayList(paramMirrors.size()); + + for (TypeMirror paramMirror : paramMirrors) { + retVal.add(Utilities.convertTypeMirror(paramMirror, processingEnv)); + } + + parameters = Collections.unmodifiableList(retVal); + return parameters; + } finally { + lock.unlock(); } - - parameters = Collections.unmodifiableList(retVal); - return parameters; } /* (non-Javadoc) @@ -154,33 +166,43 @@ public AltClass getFirstTypeArgumentOfParameter(int index) { * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getAnnotation(java.lang.String) */ @Override - public synchronized AltAnnotation getAnnotation(String annotation) { - if (annotations == null) { - getAnnotations(); + public AltAnnotation getAnnotation(String annotation) { + lock.lock(); + try { + if (annotations == null) { + getAnnotations(); + } + + return annotations.get(annotation); + } finally { + lock.unlock(); } - - return annotations.get(annotation); } /* (non-Javadoc) * @see org.glassfish.hk2.xml.internal.alt.AltMethod#getAnnotations() */ @Override - public synchronized List getAnnotations() { - if (annotations != null) { - return Collections.unmodifiableList(new ArrayList(annotations.values())); - } - - Map retVal = new LinkedHashMap(); - - for (AnnotationMirror annoMirror : method.getAnnotationMirrors()) { - AnnotationMirrorAltAnnotationImpl addMe = new AnnotationMirrorAltAnnotationImpl(annoMirror, processingEnv); + public List getAnnotations() { + lock.lock(); + try { + if (annotations != null) { + return Collections.unmodifiableList(new ArrayList(annotations.values())); + } + + Map retVal = new LinkedHashMap(); - retVal.put(addMe.annotationType(), addMe); + for (AnnotationMirror annoMirror : method.getAnnotationMirrors()) { + AnnotationMirrorAltAnnotationImpl addMe = new AnnotationMirrorAltAnnotationImpl(annoMirror, processingEnv); + + retVal.put(addMe.annotationType(), addMe); + } + + annotations = Collections.unmodifiableMap(retVal); + return Collections.unmodifiableList(new ArrayList(annotations.values())); + } finally { + lock.unlock(); } - - annotations = Collections.unmodifiableMap(retVal); - return Collections.unmodifiableList(new ArrayList(annotations.values())); } @Override diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/TypeElementAltClassImpl.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/TypeElementAltClassImpl.java index e75276d4bc..e63be4766c 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/TypeElementAltClassImpl.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/internal/alt/papi/TypeElementAltClassImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import java.util.concurrent.locks.ReentrantLock; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; @@ -48,6 +49,7 @@ * */ public class TypeElementAltClassImpl implements AltClass { + private final ReentrantLock lock = new ReentrantLock(); private final TypeElement clazz; private final ProcessingEnvironment processingEnv; @@ -79,21 +81,26 @@ public String getSimpleName() { * @see org.glassfish.hk2.xml.internal.alt.AltClass#getAnnotations() */ @Override - public synchronized List getAnnotations() { - if (annotations != null) return annotations; - - List annoMirrors = processingEnv.getElementUtils().getAllAnnotationMirrors(clazz); - - ArrayList retVal = new ArrayList(annoMirrors.size()); - - for (AnnotationMirror annoMirror : annoMirrors) { - AnnotationMirrorAltAnnotationImpl anno = new AnnotationMirrorAltAnnotationImpl(annoMirror, processingEnv); + public List getAnnotations() { + lock.lock(); + try { + if (annotations != null) return annotations; + + List annoMirrors = processingEnv.getElementUtils().getAllAnnotationMirrors(clazz); + + ArrayList retVal = new ArrayList(annoMirrors.size()); + + for (AnnotationMirror annoMirror : annoMirrors) { + AnnotationMirrorAltAnnotationImpl anno = new AnnotationMirrorAltAnnotationImpl(annoMirror, processingEnv); + + retVal.add(anno); + } - retVal.add(anno); + annotations = Collections.unmodifiableList(new ArrayList(retVal)); + return annotations; + } finally { + lock.unlock(); } - - annotations = Collections.unmodifiableList(new ArrayList(retVal)); - return annotations; } private static final Set POSSIBLE_NO_HANDLE = new HashSet(Arrays.asList(new String[] { @@ -164,51 +171,56 @@ private boolean isMethodToGenerate(Element element) { * @see org.glassfish.hk2.xml.internal.alt.AltClass#getMethods() */ @Override - public synchronized List getMethods() { - if (methods != null) return methods; - - List innerElements = processingEnv.getElementUtils().getAllMembers(clazz); - - TreeMap> reorderByEnclosingClass = new TreeMap>(); - - String clazzName = getName(); - for (Element innerElementElement : innerElements) { - if (isMethodToGenerate(innerElementElement)) { - TypeElement enclosingElement = (TypeElement) innerElementElement.getEnclosingElement(); - - String enclosingName = Utilities.convertNameToString(processingEnv.getElementUtils().getBinaryName(enclosingElement)); - - List addedList = reorderByEnclosingClass.get(enclosingName); - if (addedList == null) { - addedList = new LinkedList(); + public List getMethods() { + lock.lock(); + try { + if (methods != null) return methods; + + List innerElements = processingEnv.getElementUtils().getAllMembers(clazz); + + TreeMap> reorderByEnclosingClass = new TreeMap>(); + + String clazzName = getName(); + for (Element innerElementElement : innerElements) { + if (isMethodToGenerate(innerElementElement)) { + TypeElement enclosingElement = (TypeElement) innerElementElement.getEnclosingElement(); + + String enclosingName = Utilities.convertNameToString(processingEnv.getElementUtils().getBinaryName(enclosingElement)); - reorderByEnclosingClass.put(enclosingName, addedList); + List addedList = reorderByEnclosingClass.get(enclosingName); + if (addedList == null) { + addedList = new LinkedList(); + + reorderByEnclosingClass.put(enclosingName, addedList); + } + + addedList.add(innerElementElement); } + } + + List innerElementsReordered = new ArrayList(innerElements.size()); + for (Map.Entry> listByEnclosing : reorderByEnclosingClass.entrySet()) { + String enclosingClass = listByEnclosing.getKey(); + if (clazzName.equals(enclosingClass)) continue; - addedList.add(innerElementElement); + innerElementsReordered.addAll(listByEnclosing.getValue()); } - } - - List innerElementsReordered = new ArrayList(innerElements.size()); - for (Map.Entry> listByEnclosing : reorderByEnclosingClass.entrySet()) { - String enclosingClass = listByEnclosing.getKey(); - if (clazzName.equals(enclosingClass)) continue; - innerElementsReordered.addAll(listByEnclosing.getValue()); - } - - List topClass = reorderByEnclosingClass.get(clazzName); - if (topClass != null) { - innerElementsReordered.addAll(topClass); - } - - ArrayList retVal = new ArrayList(innerElementsReordered.size()); - for (Element innerElementElement : innerElementsReordered) { - retVal.add(new ElementAltMethodImpl(innerElementElement, processingEnv)); + List topClass = reorderByEnclosingClass.get(clazzName); + if (topClass != null) { + innerElementsReordered.addAll(topClass); + } + + ArrayList retVal = new ArrayList(innerElementsReordered.size()); + for (Element innerElementElement : innerElementsReordered) { + retVal.add(new ElementAltMethodImpl(innerElementElement, processingEnv)); + } + + methods = Collections.unmodifiableList(retVal); + return methods; + } finally { + lock.unlock(); } - - methods = Collections.unmodifiableList(retVal); - return methods; } @Override diff --git a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/jaxb/internal/BaseHK2JAXBBean.java b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/jaxb/internal/BaseHK2JAXBBean.java index 6ebdce4dbf..72c44e27be 100755 --- a/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/jaxb/internal/BaseHK2JAXBBean.java +++ b/hk2-configuration/persistence/hk2-xml/main/src/main/java/org/glassfish/hk2/xml/jaxb/internal/BaseHK2JAXBBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; import jakarta.xml.bind.annotation.XmlTransient; import javax.xml.namespace.QName; @@ -79,7 +80,9 @@ public Boolean run() { private final static String EMPTY = ""; public final static char XML_PATH_SEPARATOR = '/'; - + + private final ReentrantLock lock = new ReentrantLock(); + /** * All fields, including child lists and direct children for beans * with no namespace specified (##default) @@ -221,8 +224,11 @@ public void _setProperty(String propNamespace, String propName, Object propValue if (changeControl == null) { if (active) { - synchronized (this) { + lock.lock(); + try { nBeanLikeMap.setValue(propNamespace, propName, propValue); + } finally { + lock.unlock(); } } else { @@ -434,9 +440,12 @@ private Object _getProperty(String propNamespace, String propName, Class expe if (changeControl == null) { if (active) { - synchronized (this) { + lock.lock(); + try { isSet = nBeanLikeMap.isSet(propNamespace, propName); retVal = nBeanLikeMap.getValue(propNamespace, propName); + } finally { + lock.unlock(); } } else { @@ -933,8 +942,11 @@ public boolean _doRemoveZ(String propNamespace, String childProperty, String chi public boolean _hasProperty(String propNamespace, String propName) { if (changeControl == null) { if (active) { - synchronized (this) { + lock.lock(); + try { return nBeanLikeMap.isSet(propNamespace, propName); + } finally { + lock.unlock(); } } @@ -957,8 +969,11 @@ public boolean _hasProperty(String propNamespace, String propName) { public Map _getBeanLikeMap() { if (changeControl == null) { if (active) { - synchronized (this) { + lock.lock(); + try { return Collections.unmodifiableMap(nBeanLikeMap.getBeanLikeMap(namespaceToPrefixMap)); + } finally { + lock.unlock(); } } return Collections.unmodifiableMap(nBeanLikeMap.getBeanLikeMap(namespaceToPrefixMap)); @@ -976,8 +991,11 @@ public Map _getBeanLikeMap() { public Map _getQNameMap() { if (changeControl == null) { if (active) { - synchronized (this) { + lock.lock(); + try { return Collections.unmodifiableMap(nBeanLikeMap.getQNameMap()); + } finally { + lock.unlock(); } } return Collections.unmodifiableMap(nBeanLikeMap.getQNameMap()); @@ -1300,8 +1318,11 @@ public boolean _isSet(String propName) { public boolean _isSet(String propNamespace, String propName) { if (changeControl == null) { if (active) { - synchronized (this) { + lock.lock(); + try { return nBeanLikeMap.isSet(propNamespace, propName); + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/PropertyFileBean.java b/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/PropertyFileBean.java index b2e0a64dcc..cf48f447d4 100755 --- a/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/PropertyFileBean.java +++ b/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/PropertyFileBean.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; /** * This bean configures the PropertyFileService itself. An implementation @@ -35,6 +36,7 @@ public class PropertyFileBean { /** The name of the single instance of this bean */ public final static String INSTANCE_NAME = "DEFAULT"; + private final ReentrantLock lock = new ReentrantLock(); private final HashMap> mapping = new HashMap>(); /** @@ -58,8 +60,11 @@ public PropertyFileBean(PropertyFileBean copyMe) { * @return A copy of the type name to bean class mapping */ public Map> getTypeMapping() { - synchronized (mapping) { + lock.lock(); + try { return new HashMap>(mapping); + } finally { + lock.unlock(); } } @@ -71,8 +76,11 @@ public Map> getTypeMapping() { * May not be null */ public void addTypeMapping(String typeName, Class beanClass) { - synchronized (mapping) { + lock.lock(); + try { mapping.put(typeName, beanClass); + } finally { + lock.unlock(); } } @@ -85,8 +93,11 @@ public void addTypeMapping(String typeName, Class beanClass) { * was no type mapping with the given name */ public Class removeTypeMapping(String typeName) { - synchronized (mapping) { + lock.lock(); + try { return mapping.remove(typeName); + } finally { + lock.unlock(); } } @@ -99,8 +110,11 @@ public Class removeTypeMapping(String typeName) { * was no type mapping with the given name */ public Class getTypeMapping(String typeName) { - synchronized (mapping) { + lock.lock(); + try { return mapping.get(typeName); + } finally { + lock.unlock(); } } diff --git a/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/internal/PropertyFileHandleImpl.java b/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/internal/PropertyFileHandleImpl.java index 5fed7ec697..406f22cbc2 100755 --- a/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/internal/PropertyFileHandleImpl.java +++ b/hk2-configuration/persistence/property-file/src/main/java/org/glassfish/hk2/configuration/persistence/properties/internal/PropertyFileHandleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.configuration.hub.api.Hub; import org.glassfish.hk2.configuration.hub.api.Instance; @@ -49,7 +50,7 @@ public class PropertyFileHandleImpl implements PropertyFileHandle { private final static int MAX_TRIES = 10000; private final static char SEPARATOR = '.'; - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private HashMap> lastRead = new HashMap>(); private boolean open = true; @@ -392,7 +393,8 @@ public void readProperties(Properties properties) { extractData(sFullKey, value, allBeans); } - synchronized (lock) { + lock.lock(); + try { if (!open) { throw new IllegalStateException("This handle has been closed"); } @@ -422,6 +424,8 @@ public void readProperties(Properties properties) { } lastRead = allBeans; + } finally { + lock.unlock(); } } @@ -476,7 +480,8 @@ public String getDefaultInstanceName() { */ @Override public void dispose() { - synchronized (lock) { + lock.lock(); + try { if (!open) return; open = false; @@ -500,6 +505,8 @@ public void dispose() { // success or not lastRead = allBeans; + } finally { + lock.unlock(); } } diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/ModuleMetadata.java b/hk2-core/src/main/java/com/sun/enterprise/module/ModuleMetadata.java index 37ce63e2f2..c7e91fef98 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/ModuleMetadata.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/ModuleMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import java.io.Serializable; import java.net.URL; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; /** * Holds information about /META-INF/services and /META-INF/inhabitants for a {@link Module}. @@ -42,6 +43,7 @@ public final class ModuleMetadata implements Serializable { private static long serialVersionUID = 7136851720280194479L; + private final ReentrantLock lock = new ReentrantLock(); /** * META-INF/hk2-locator/* cache */ @@ -51,16 +53,21 @@ public Map> getDescriptors() { return descriptors; } - public synchronized void addDescriptors(String serviceLocatorName, Collection descriptorsToAdd) { - List descriptorList = descriptors.get(serviceLocatorName); - - if (descriptorList == null) { - descriptorList = new ArrayList(); - - descriptors.put(serviceLocatorName, descriptorList); + public void addDescriptors(String serviceLocatorName, Collection descriptorsToAdd) { + lock.lock(); + try { + List descriptorList = descriptors.get(serviceLocatorName); + + if (descriptorList == null) { + descriptorList = new ArrayList(); + + descriptors.put(serviceLocatorName, descriptorList); + } + + descriptorList.addAll(descriptorsToAdd); + } finally { + lock.unlock(); } - - descriptorList.addAll(descriptorsToAdd); } public static final class Entry implements Serializable { diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractModulesRegistryImpl.java b/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractModulesRegistryImpl.java index d30afaac8a..7df88dd246 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractModulesRegistryImpl.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractModulesRegistryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Logger; import org.glassfish.hk2.api.ActiveDescriptor; @@ -78,6 +79,7 @@ public abstract class AbstractModulesRegistryImpl implements ModulesRegistry { protected final Map repositories = new TreeMap(); + private final ReentrantLock lock = new ReentrantLock(); private final ConcurrentMap, CopyOnWriteArrayList> runningServices = new ConcurrentHashMap,CopyOnWriteArrayList>(); @@ -221,17 +223,22 @@ protected abstract List parseInhabitants(HK2Module module, * @param repository new repository to attach to this registry * @param weight int value from 1 to 100 to specify the search order */ - public synchronized void addRepository(Repository repository, int weight) { - // check that we don't already have this repository - for (Repository repo : repositories.values()) { - if (repo.getLocation().equals(repository.getLocation())) { - throw new RuntimeException("repository at " + repository.getLocation() + " already registered"); + public void addRepository(Repository repository, int weight) { + lock.lock(); + try { + // check that we don't already have this repository + for (Repository repo : repositories.values()) { + if (repo.getLocation().equals(repository.getLocation())) { + throw new RuntimeException("repository at " + repository.getLocation() + " already registered"); + } } + while (repositories.containsKey(weight)) { + weight++; + } + repositories.put(weight, repository); + } finally { + lock.unlock(); } - while (repositories.containsKey(weight)) { - weight++; - } - repositories.put(weight, repository); } /** @@ -240,8 +247,13 @@ public synchronized void addRepository(Repository repository, int weight) { * registered in this instance. * @param repository new repository to attach to this registry */ - public synchronized void addRepository(Repository repository) { - repositories.put(100+repositories.size(), repository); + public void addRepository(Repository repository) { + lock.lock(); + try { + repositories.put(100+repositories.size(), repository); + } finally { + lock.unlock(); + } } /** @@ -251,13 +263,18 @@ public synchronized void addRepository(Repository repository) { * longer * @param name name of the repository to remove */ - public synchronized void removeRepository(String name) { - for (Integer weight : repositories.keySet()) { - Repository repo = repositories.get(weight); - if (repo.getName().equals(name)) { - repositories.remove(weight); - return; + public void removeRepository(String name) { + lock.lock(); + try { + for (Integer weight : repositories.keySet()) { + Repository repo = repositories.get(weight); + if (repo.getName().equals(name)) { + repositories.remove(weight); + return; + } } + } finally { + lock.unlock(); } } @@ -267,14 +284,19 @@ public synchronized void removeRepository(String name) { * @param name name of the repository to return * @return the repository or null if not found */ - public synchronized Repository getRepository(String name) { - for (Integer weight : repositories.keySet()) { - Repository repo = repositories.get(weight); - if (repo.getName().equals(name)) { - return repo; + public Repository getRepository(String name) { + lock.lock(); + try { + for (Integer weight : repositories.keySet()) { + Repository repo = repositories.get(weight); + if (repo.getName().equals(name)) { + return repo; + } } + return null; + } finally { + lock.unlock(); } - return null; } /** @@ -537,8 +559,13 @@ public void changed(HK2Module service) { * definition, the registry will be capable of created shared and private * HK2Module instances. */ - public synchronized HK2Module add(ModuleDefinition info) throws ResolveError { - return add(info, true); + public HK2Module add(ModuleDefinition info) throws ResolveError { + lock.lock(); + try { + return add(info, true); + } finally { + lock.unlock(); + } } public HK2Module add(ModuleDefinition info, boolean resolve) throws ResolveError { diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractRepositoryImpl.java b/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractRepositoryImpl.java index ce1792da4e..1028df6278 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractRepositoryImpl.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/AbstractRepositoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -24,6 +24,7 @@ import java.io.*; import java.net.URI; import java.util.*; +import java.util.concurrent.locks.ReentrantLock; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -37,6 +38,7 @@ * @author Sanjeeb.Sahoo@Sun.COM */ public abstract class AbstractRepositoryImpl implements Repository { + private final ReentrantLock lock = new ReentrantLock(); private final String name; private final URI location; private Map moduleDefs; @@ -189,11 +191,16 @@ public List getJarLocations() { * @param listener implementation listening to this repository changes * @return true if the listener was added successfully */ - public synchronized boolean addListener(RepositoryChangeListener listener) { - if (listeners==null) { - listeners = new ArrayList(); + public boolean addListener(RepositoryChangeListener listener) { + lock.lock(); + try { + if (listeners==null) { + listeners = new ArrayList(); + } + return listeners.add(listener); + } finally { + lock.unlock(); } - return listeners.add(listener); } /** @@ -202,11 +209,16 @@ public synchronized boolean addListener(RepositoryChangeListener listener) { * @param listener the previously registered listener * @return true if the listener was successfully unregistered */ - public synchronized boolean removeListener(RepositoryChangeListener listener) { - if (listeners==null) { - return false; + public boolean removeListener(RepositoryChangeListener listener) { + lock.lock(); + try { + if (listeners==null) { + return false; + } + return listeners.remove(listener); + } finally { + lock.unlock(); } - return listeners.remove(listener); } /** diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/DirectoryBasedRepository.java b/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/DirectoryBasedRepository.java index 4e170e6bda..dd491b10b6 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/DirectoryBasedRepository.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/common_impl/DirectoryBasedRepository.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.locks.ReentrantLock; /** * This class is a directory based repository implementation. This mean that all jar @@ -43,6 +44,7 @@ public class DirectoryBasedRepository extends AbstractRepositoryImpl { protected final File repository; + private final ReentrantLock lock = new ReentrantLock(); private final int intervalInMs = Integer.getInteger("hk2.file.directory.changeIntervalTimer", 1000); private Timer timer; private boolean isTimerThreadDaemon = false; @@ -75,28 +77,36 @@ public DirectoryBasedRepository(String name, File repository, boolean isTimerThr } @Override - public synchronized boolean addListener(RepositoryChangeListener listener) { - - final boolean returnValue = super.addListener(listener); - if (returnValue && timer==null) { - initializeSubDirectories(); - - timer = new Timer("hk2-repo-listener-"+ this.getName(), isTimerThreadDaemon); - timer.schedule(new TimerTask() { - long lastModified = repository.lastModified(); - public void run() { - synchronized(this) { - if (lastModified newModuleDefs = - new HashMap(); - List libraries = new LinkedList(); - + private void directoryChanged() { + lock.lock(); try { - loadModuleDefs(newModuleDefs, libraries); - } catch(IOException ioe) { - // we probably need to wait until the jar has finished being copied - // XXX add some form of retry - } - for(ModuleDefinition def : newModuleDefs.values()) { - if (find(def.getName(), def.getVersion())==null) { - add(def); - for (RepositoryChangeListener listener : listeners) { - listener.moduleAdded(def); - } + // not the most efficient implementation, could be revisited later + HashMap newModuleDefs = + new HashMap(); + List libraries = new LinkedList(); + + try { + loadModuleDefs(newModuleDefs, libraries); + } catch(IOException ioe) { + // we probably need to wait until the jar has finished being copied + // XXX add some form of retry } - } - for (ModuleDefinition def : findAll()) { - if (!newModuleDefs.containsKey(AbstractFactory.getInstance().createModuleId(def))) { - remove(def); - for (RepositoryChangeListener listener : listeners) { - listener.moduleRemoved(def); + for(ModuleDefinition def : newModuleDefs.values()) { + if (find(def.getName(), def.getVersion())==null) { + add(def); + for (RepositoryChangeListener listener : listeners) { + listener.moduleAdded(def); + } } } - } - List originalLibraries = super.getJarLocations(); - for (URI location : libraries) { - if (!originalLibraries.contains(location)) { - addLibrary(location); - for (RepositoryChangeListener listener : listeners) { - listener.added(location); + for (ModuleDefinition def : findAll()) { + if (!newModuleDefs.containsKey(AbstractFactory.getInstance().createModuleId(def))) { + remove(def); + for (RepositoryChangeListener listener : listeners) { + listener.moduleRemoved(def); + } } } - } - if (originalLibraries.size()>0) { - List copy = new LinkedList(); - copy.addAll(originalLibraries); - for (URI originalLocation : copy) { - if (!libraries.contains(originalLocation)) { - removeLibrary(originalLocation); + List originalLibraries = super.getJarLocations(); + for (URI location : libraries) { + if (!originalLibraries.contains(location)) { + addLibrary(location); for (RepositoryChangeListener listener : listeners) { - listener.removed(originalLocation); + listener.added(location); } } } - } - - // added or removed subdirectories ? - List previous = new LinkedList(); - previous.addAll(subDirectories); - for (File file : repository.listFiles(new FileFilter() { - public boolean accept(File pathname) { - return pathname.isDirectory(); - } - })) { - // added ? - if (!subDirectories.contains(file)) { - for (RepositoryChangeListener listener : listeners) { - listener.added(file.toURI()); + if (originalLibraries.size()>0) { + List copy = new LinkedList(); + copy.addAll(originalLibraries); + for (URI originalLocation : copy) { + if (!libraries.contains(originalLocation)) { + removeLibrary(originalLocation); + for (RepositoryChangeListener listener : listeners) { + listener.removed(originalLocation); + } + } } - subDirectories.add(file); - } else { - // known, removing it from the copied list to check - // for removal - previous.remove(file); } - } - // any left in our copy is a removed sub directory. - if (!previous.isEmpty()) { - for (File file : previous) { - for (RepositoryChangeListener listener : listeners) { - listener.removed(file.toURI()); + + // added or removed subdirectories ? + List previous = new LinkedList(); + previous.addAll(subDirectories); + for (File file : repository.listFiles(new FileFilter() { + public boolean accept(File pathname) { + return pathname.isDirectory(); + } + })) { + // added ? + if (!subDirectories.contains(file)) { + for (RepositoryChangeListener listener : listeners) { + listener.added(file.toURI()); + } + subDirectories.add(file); + } else { + // known, removing it from the copied list to check + // for removal + previous.remove(file); } - subDirectories.remove(file); } + // any left in our copy is a removed sub directory. + if (!previous.isEmpty()) { + for (File file : previous) { + for (RepositoryChangeListener listener : listeners) { + listener.removed(file.toURI()); + } + subDirectories.remove(file); + } + } + } finally { + lock.unlock(); } } diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/impl/ClassLoaderProxy.java b/hk2-core/src/main/java/com/sun/enterprise/module/impl/ClassLoaderProxy.java index 2b6de0a803..ae8cc78be2 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/impl/ClassLoaderProxy.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/impl/ClassLoaderProxy.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -23,6 +23,7 @@ import java.net.URL; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.locks.ReentrantLock; import java.io.IOException; import org.glassfish.hk2.utilities.CleanerFactory; @@ -33,6 +34,7 @@ */ public class ClassLoaderProxy extends URLClassLoader { + private final ReentrantLock lock = new ReentrantLock(); private final List surrogates = new CopyOnWriteArrayList(); private final List facadeSurrogates = new CopyOnWriteArrayList(); @@ -114,13 +116,18 @@ protected Class findClass(String name, boolean followImports) throws ClassNot /** * {@link #findClass(String)} except the classloader punch-in hack. */ - /*package*/ synchronized Class findClassDirect(String name) throws ClassNotFoundException { - Class c = findLoadedClass(name); - if(c!=null) return c; + /*package*/ Class findClassDirect(String name) throws ClassNotFoundException { + lock.lock(); try { - return super.findClass(name); - } catch (NoClassDefFoundError e) { - throw new ClassNotFoundException(e.getMessage()); + Class c = findLoadedClass(name); + if(c!=null) return c; + try { + return super.findClass(name); + } catch (NoClassDefFoundError e) { + throw new ClassNotFoundException(e.getMessage()); + } + } finally { + lock.unlock(); } } diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/impl/HK2Factory.java b/hk2-core/src/main/java/com/sun/enterprise/module/impl/HK2Factory.java index dbe6d48fef..fb36388b20 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/impl/HK2Factory.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/impl/HK2Factory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,9 @@ import com.sun.enterprise.module.common_impl.LogHelper; import com.sun.enterprise.module.common_impl.ModuleId; import com.sun.enterprise.module.ModulesRegistry; + +import java.util.concurrent.locks.ReentrantLock; + import com.sun.enterprise.module.ModuleDefinition; /** @@ -27,11 +30,18 @@ */ public class HK2Factory extends AbstractFactory { - public synchronized static void initialize() { - if (Instance != null) { - LogHelper.getDefaultLogger().fine("Singleton already initialized as " + getInstance()); + private static final ReentrantLock lock = new ReentrantLock(); + + public static void initialize() { + lock.lock(); + try { + if (Instance != null) { + LogHelper.getDefaultLogger().fine("Singleton already initialized as " + getInstance()); + } + Instance = new HK2Factory(); + } finally { + lock.unlock(); } - Instance = new HK2Factory(); } public ModulesRegistry createModulesRegistry() { diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleClassLoader.java b/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleClassLoader.java index 94de6f57e6..7da9d4949d 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleClassLoader.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleClassLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2023 Payara Foundation and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the @@ -27,6 +27,8 @@ import java.util.Enumeration; import java.util.List; import java.util.Vector; +import java.util.concurrent.locks.ReentrantLock; + import com.sun.enterprise.module.HK2Module; /** @@ -36,6 +38,7 @@ */ final class ModuleClassLoader extends ClassLoaderProxy { + private final ReentrantLock lock = new ReentrantLock(); private final ModuleImpl module; /** @@ -51,9 +54,14 @@ public ModuleClassLoader(ModuleImpl owner, URL[] shared, ClassLoader parent) { this.module = owner; } - protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - initialize(name); - return super.loadClass(name, resolve); + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + lock.lock(); + try { + initialize(name); + return super.loadClass(name, resolve); + } finally { + lock.unlock(); + } } protected Class findClass(String name) throws ClassNotFoundException { @@ -125,8 +133,8 @@ public Enumeration getResources(String name) throws IOException { */ private void initialize(String name) { if (initialized) return; - - synchronized(this) { + lock.lock(); + try { if(!initialized) { // if we are preparing, we should just not initiate initialization. if (module.getState().equals(ModuleState.PREPARING)) { @@ -139,6 +147,8 @@ private void initialize(String name) { initializerThread = Thread.currentThread().getStackTrace(); initializerClassName = name; } + } finally { + lock.unlock(); } } diff --git a/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleImpl.java b/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleImpl.java index 411b943d8d..55cc6493af 100755 --- a/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleImpl.java +++ b/hk2-core/src/main/java/com/sun/enterprise/module/impl/ModuleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -46,6 +46,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; @@ -68,7 +69,8 @@ * @author Jerome Dochez */ public final class ModuleImpl implements HK2Module { - + + private final ReentrantLock lock = new ReentrantLock(); private final ModuleDefinition moduleDef; private WeakReference publicCL; private volatile ModuleClassLoader privateCL; @@ -139,7 +141,8 @@ public ClassLoaderFacade run() { */ /*package*/ ModuleClassLoader getPrivateClassLoader() { if (privateCL==null) { - synchronized(this) { + lock.lock(); + try { if(privateCL==null) { URI[] locations = moduleDef.getLocations(); URL[] urlLocations = new URL[locations.length]; @@ -161,6 +164,8 @@ public ModuleClassLoader run() { } }); } + } finally { + lock.unlock(); } } return privateCL; @@ -281,78 +286,82 @@ List parseInhabitants(String name, List=0) - return; - - if (state==ModuleState.PREPARING) { - Utils.identifyCyclicDependency(this, Logger.getAnonymousLogger()); - throw new ResolveError("Cyclic dependency with " + getName()); - } - state = ModuleState.PREPARING; - - if (moduleDef.getImportPolicyClassName()!=null) { - try { - Class importPolicyClass = (Class) getPrivateClassLoader().loadClass(moduleDef.getImportPolicyClassName()); - ImportPolicy importPolicy = importPolicyClass.newInstance(); - importPolicy.prepare(this); - } catch(ClassNotFoundException e) { - state = ModuleState.ERROR; - throw new ResolveError(e); - } catch(java.lang.InstantiationException e) { - state = ModuleState.ERROR; - throw new ResolveError(e); - } catch(IllegalAccessException e) { - state = ModuleState.ERROR; - throw new ResolveError(e); + public void resolve() throws ResolveError { + lock.lock(); + try { + // already resolved ? + if (state==ModuleState.ERROR) + throw new ResolveError("Module " + getName() + " is in ERROR state"); + if (state.compareTo(ModuleState.RESOLVED)>=0) + return; + + if (state==ModuleState.PREPARING) { + Utils.identifyCyclicDependency(this, Logger.getAnonymousLogger()); + throw new ResolveError("Cyclic dependency with " + getName()); } - } - for (ModuleDependency dependency : moduleDef.getDependencies()) { - ModuleImpl depModule = (ModuleImpl)registry.makeModuleFor(dependency.getName(), dependency.getVersion()); - if (depModule==null) { - state = ModuleState.ERROR; - throw new ResolveError(dependency + " referenced from " - + moduleDef.getName() + " is not resolved"); + state = ModuleState.PREPARING; + + if (moduleDef.getImportPolicyClassName()!=null) { + try { + Class importPolicyClass = (Class) getPrivateClassLoader().loadClass(moduleDef.getImportPolicyClassName()); + ImportPolicy importPolicy = importPolicyClass.newInstance(); + importPolicy.prepare(this); + } catch(ClassNotFoundException e) { + state = ModuleState.ERROR; + throw new ResolveError(e); + } catch(java.lang.InstantiationException e) { + state = ModuleState.ERROR; + throw new ResolveError(e); + } catch(IllegalAccessException e) { + state = ModuleState.ERROR; + throw new ResolveError(e); + } } + for (ModuleDependency dependency : moduleDef.getDependencies()) { + ModuleImpl depModule = (ModuleImpl)registry.makeModuleFor(dependency.getName(), dependency.getVersion()); + if (depModule==null) { + state = ModuleState.ERROR; + throw new ResolveError(dependency + " referenced from " + + moduleDef.getName() + " is not resolved"); + } - //if (Utils.isLoggable(Level.INFO)) { - // Utils.getDefaultLogger().info("For module" + getName() + " adding new dependent " + module.getName()); - //} - dependencies.add(depModule); - } + //if (Utils.isLoggable(Level.INFO)) { + // Utils.getDefaultLogger().info("For module" + getName() + " adding new dependent " + module.getName()); + //} + dependencies.add(depModule); + } - // once we have proper import/export filtering for modules, we can - // build a look-up table to improve performance - - // build up the complete list of transitive dependency modules, without any duplication, - // in a breadth-first fashion. The reason we do this in breadth-first is to reduce - // the search time based on the assumption that classes tend to be discovered in close dependencies. - List transitiveDependencies = new ArrayList(); - Set transitiveDependenciesSet = new HashSet(); - LinkedList q = new LinkedList(); - q.addAll(dependencies); - while(!q.isEmpty()) { - ModuleImpl m = q.removeFirst(); - if(transitiveDependenciesSet.add(m)) { - // first time visited - transitiveDependencies.add(m); - m.resolve(); - q.addAll(m.dependencies); + // once we have proper import/export filtering for modules, we can + // build a look-up table to improve performance + + // build up the complete list of transitive dependency modules, without any duplication, + // in a breadth-first fashion. The reason we do this in breadth-first is to reduce + // the search time based on the assumption that classes tend to be discovered in close dependencies. + List transitiveDependencies = new ArrayList(); + Set transitiveDependenciesSet = new HashSet(); + LinkedList q = new LinkedList(); + q.addAll(dependencies); + while(!q.isEmpty()) { + ModuleImpl m = q.removeFirst(); + if(transitiveDependenciesSet.add(m)) { + // first time visited + transitiveDependencies.add(m); + m.resolve(); + q.addAll(m.dependencies); + } } - } - for (ModuleImpl m : transitiveDependencies) { - getPrivateClassLoader().addDelegate(m.getClassLoader()); - } + for (ModuleImpl m : transitiveDependencies) { + getPrivateClassLoader().addDelegate(m.getClassLoader()); + } - //Logger.global.info("HK2Module " + getName() + " resolved"); - state = ModuleState.RESOLVED; - for (ModuleLifecycleListener l : registry.getLifecycleListeners()) { - l.moduleResolved(this); + //Logger.global.info("HK2Module " + getName() + " resolved"); + state = ModuleState.RESOLVED; + for (ModuleLifecycleListener l : registry.getLifecycleListeners()) { + l.moduleResolved(this); + } + } finally { + lock.unlock(); } } diff --git a/hk2-extras/src/main/java/org/glassfish/hk2/extras/hk2bridge/internal/CrossOverDescriptor.java b/hk2-extras/src/main/java/org/glassfish/hk2/extras/hk2bridge/internal/CrossOverDescriptor.java index e4415a2bbd..fd5163aacb 100755 --- a/hk2-extras/src/main/java/org/glassfish/hk2/extras/hk2bridge/internal/CrossOverDescriptor.java +++ b/hk2-extras/src/main/java/org/glassfish/hk2/extras/hk2bridge/internal/CrossOverDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,7 @@ import java.lang.reflect.Type; import java.util.List; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Injectee; @@ -33,6 +34,7 @@ * */ public class CrossOverDescriptor extends AbstractActiveDescriptor { + private final ReentrantLock lock = new ReentrantLock(); private final ServiceLocator remoteLocator; private final ActiveDescriptor remote; private boolean remoteReified; @@ -67,12 +69,17 @@ public boolean isReified() { return true; } - private synchronized void checkState() { - if (remoteReified) return; - remoteReified = true; - - if (remote.isReified()) return; - remoteLocator.reifyDescriptor(remote); + private void checkState() { + lock.lock(); + try { + if (remoteReified) return; + remoteReified = true; + + if (remote.isReified()) return; + remoteLocator.reifyDescriptor(remote); + } finally { + lock.unlock(); + } } @Override diff --git a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/OperationContext.java b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/OperationContext.java index 87609afe0c..954ded7c8c 100755 --- a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/OperationContext.java +++ b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/OperationContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,8 @@ import java.util.LinkedList; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Context; @@ -62,6 +64,8 @@ @Contract public abstract class OperationContext implements Context { private SingleOperationManager manager; + private final ReentrantLock lock = new ReentrantLock(); + private final Condition condition = lock.newCondition(); private final HashMap, LinkedHashMap, Object>> operationMap = new HashMap, LinkedHashMap, Object>>(); private final HashSet> creating = new HashSet>(); @@ -79,10 +83,13 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, LinkedList> closingOperationStack; boolean closingOperation; - synchronized (this) { + lock.lock(); + try { localManager = manager; closingOperationStack = closingOperations.get(Thread.currentThread().getId()); closingOperation = (closingOperationStack != null && !closingOperationStack.isEmpty()); + } finally { + lock.unlock(); } if (localManager == null) { @@ -92,18 +99,22 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, OperationHandleImpl operation = localManager.getCurrentOperationOnThisThread(); if (operation == null) { - synchronized (this) { + lock.lock(); + try { if (!closingOperation) { throw new IllegalStateException("There is no current operation of type " + getScope().getName() + " on thread " + Thread.currentThread().getId()); } operation = closingOperationStack.get(0); + } finally { + lock.unlock(); } } LinkedHashMap, Object> serviceMap; - synchronized (this) { + lock.lock(); + try { serviceMap = operationMap.get(operation); if (serviceMap == null) { if (closingOperation || shuttingDown) { @@ -132,7 +143,7 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, // retVal is null, and this is not an explicit null, so must actually do the creation while (creating.contains(activeDescriptor)) { try { - this.wait(); + condition.await(); } catch (InterruptedException e) { throw new RuntimeException(e); @@ -148,6 +159,8 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, // Not in creating, and not created. Create it ourselves creating.add(activeDescriptor); + } finally { + lock.unlock(); } Object retVal = null; @@ -162,13 +175,16 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, success = true; } finally { - synchronized (this) { + lock.lock(); + try { if (success) { serviceMap.put(activeDescriptor, retVal); } creating.remove(activeDescriptor); - this.notifyAll(); + condition.signalAll(); + } finally { + lock.unlock(); } } @@ -181,21 +197,27 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, @Override public boolean containsKey(ActiveDescriptor descriptor) { SingleOperationManager localManager; - synchronized (this) { + lock.lock(); + try { localManager = manager; + } finally { + lock.unlock(); } if (localManager == null) return false; OperationHandleImpl operation = localManager.getCurrentOperationOnThisThread(); if (operation == null) return false; - synchronized (this) { + lock.lock(); + try { HashMap, Object> serviceMap; serviceMap = operationMap.get(operation); if (serviceMap == null) return false; return serviceMap.containsKey(descriptor); + } finally { + lock.unlock(); } } @@ -206,13 +228,16 @@ public boolean containsKey(ActiveDescriptor descriptor) { @SuppressWarnings("unchecked") @Override public void destroyOne(ActiveDescriptor descriptor) { - synchronized (this) { + lock.lock(); + try { for (HashMap, Object> serviceMap : operationMap.values()) { Object killMe = serviceMap.remove(descriptor); if (killMe == null) continue; ((ActiveDescriptor) descriptor).dispose(killMe); } + } finally { + lock.unlock(); } } @@ -222,7 +247,8 @@ public void closeOperation(OperationHandleImpl operation) { HashMap, Object> serviceMap; LinkedList> stack; - synchronized (this) { + lock.lock(); + try { stack = closingOperations.get(tid); if (stack == null) { stack = new LinkedList>(); @@ -232,6 +258,8 @@ public void closeOperation(OperationHandleImpl operation) { stack.addFirst(operation); serviceMap = operationMap.get(operation); + } finally { + lock.unlock(); } try { @@ -258,13 +286,16 @@ public void closeOperation(OperationHandleImpl operation) { } } finally { - synchronized (this) { + lock.lock(); + try { operationMap.remove(operation); stack.removeFirst(); if (stack.isEmpty()) { closingOperations.remove(tid); } + } finally { + lock.unlock(); } } } @@ -275,9 +306,12 @@ public void closeOperation(OperationHandleImpl operation) { @Override public void shutdown() { Set> toShutDown; - synchronized (this) { + lock.lock(); + try { shuttingDown = true; toShutDown = operationMap.keySet(); + } finally { + lock.unlock(); } try { @@ -286,8 +320,11 @@ public void shutdown() { } } finally { - synchronized (this) { + lock.lock(); + try { operationMap.clear(); + } finally { + lock.unlock(); } } diff --git a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationHandleImpl.java b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationHandleImpl.java index d833188e44..766947567e 100755 --- a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationHandleImpl.java +++ b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationHandleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018 Payara Foundation * * This program and the accompanying materials are made available under the @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.extras.operation.OperationHandle; @@ -34,7 +35,8 @@ public class OperationHandleImpl implements OperationHandle { private final SingleOperationManager parent; private final OperationIdentifier identifier; - private final Object operationLock; + private final ReentrantLock lock = new ReentrantLock(); + private final ReentrantLock operationLock; private OperationState state; private final HashSet activeThreads = new HashSet(); @@ -44,7 +46,7 @@ public class OperationHandleImpl implements OperationHandl /* package */ OperationHandleImpl( SingleOperationManager parent, OperationIdentifier identifier, - Object operationLock, + ReentrantLock operationLock, ServiceLocator locator) { this.parent = parent; this.identifier = identifier; @@ -65,8 +67,11 @@ public OperationIdentifier getIdentifier() { */ @Override public OperationState getState() { - synchronized (operationLock) { + operationLock.lock(); + try { return state; + } finally { + operationLock.unlock(); } } @@ -78,10 +83,13 @@ public OperationState getState() { } private void checkState() { - synchronized (operationLock) { + operationLock.lock(); + try { if (OperationState.CLOSED.equals(state)) { throw new IllegalStateException(this + " is closed"); } + } finally { + operationLock.unlock(); } } @@ -90,8 +98,11 @@ private void checkState() { */ @Override public Set getActiveThreads() { - synchronized (operationLock) { + operationLock.lock(); + try { return Collections.unmodifiableSet(activeThreads); + } finally { + operationLock.unlock(); } } @@ -100,7 +111,8 @@ public Set getActiveThreads() { */ @Override public void suspend(long threadId) { - synchronized (operationLock) { + operationLock.lock(); + try { if (OperationState.CLOSED.equals(state)) return; parent.disassociateThread(threadId, this); @@ -110,6 +122,8 @@ public void suspend(long threadId) { state = OperationState.SUSPENDED; } } + } finally { + operationLock.unlock(); } } @@ -127,7 +141,8 @@ public void suspend() { */ @Override public void resume(long threadId) throws IllegalStateException { - synchronized (operationLock) { + operationLock.lock(); + try { checkState(); if (activeThreads.contains(threadId)) return; @@ -144,6 +159,8 @@ public void resume(long threadId) throws IllegalStateException { activeThreads.add(threadId); parent.associateWithThread(threadId, this); + } finally { + operationLock.unlock(); } } @@ -164,7 +181,8 @@ public void close() { // outside the lock parent.disposeAllOperationServices(this); - synchronized (operationLock) { + operationLock.lock(); + try { for (long threadId : activeThreads) { parent.disassociateThread(threadId, this); } @@ -172,6 +190,8 @@ public void close() { activeThreads.clear(); state = OperationState.CLOSED; parent.closeOperation(this); + } finally { + operationLock.unlock(); } @@ -186,16 +206,26 @@ public void closeOperation() { * @see org.glassfish.hk2.extras.operation.OperationHandle#getOperationData() */ @Override - public synchronized Object getOperationData() { - return userData; + public Object getOperationData() { + lock.lock(); + try { + return userData; + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.extras.operation.OperationHandle#setOperationData(java.lang.Object) */ @Override - public synchronized void setOperationData(Object data) { - userData = data; + public void setOperationData(Object data) { + lock.lock(); + try { + userData = data; + } finally { + lock.unlock(); + } } @Override diff --git a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationManagerImpl.java b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationManagerImpl.java index aa46c8701b..0a0c744bbb 100755 --- a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationManagerImpl.java +++ b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/OperationManagerImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; import jakarta.inject.Singleton; @@ -34,6 +35,7 @@ */ @Singleton public class OperationManagerImpl implements OperationManager { + private final ReentrantLock lock = new ReentrantLock(); private final HashMap, SingleOperationManager> children = new HashMap, SingleOperationManager>(); @@ -47,13 +49,16 @@ public class OperationManagerImpl implements OperationManager { @Override public OperationHandle createOperation(T scope) { SingleOperationManager manager; - synchronized (this) { + lock.lock(); + try { manager = (SingleOperationManager) children.get(scope.annotationType()); if (manager == null) { manager = new SingleOperationManager(scope, locator); children.put(scope.annotationType(), manager); } + } finally { + lock.unlock(); } return manager.createOperation(); @@ -77,9 +82,12 @@ public OperationHandle createAndStartOperation(T scope @Override public Set> getCurrentOperations(T scope) { SingleOperationManager manager; - synchronized (this) { + lock.lock(); + try { manager = (SingleOperationManager) children.get(scope.annotationType()); if (manager == null) return Collections.emptySet(); + } finally { + lock.unlock(); } return manager.getAllOperations(); @@ -92,9 +100,12 @@ public Set> getCurrentOperations(T sco @Override public OperationHandle getCurrentOperation(T scope) { SingleOperationManager manager; - synchronized (this) { + lock.lock(); + try { manager = (SingleOperationManager) children.get(scope.annotationType()); if (manager == null) return null; + } finally { + lock.unlock(); } return manager.getCurrentOperationOnThisThread(); @@ -106,11 +117,14 @@ public OperationHandle getCurrentOperation(T scope) { @Override public void shutdownAllOperations(Annotation scope) { SingleOperationManager manager; - synchronized (this) { + lock.lock(); + try { manager = children.remove(scope.annotationType()); if (manager == null) return; manager.shutdown(); + } finally { + lock.unlock(); } } diff --git a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/SingleOperationManager.java b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/SingleOperationManager.java index 42d45b3730..6bc0d7fcd3 100755 --- a/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/SingleOperationManager.java +++ b/hk2-extras/src/main/java/org/glassfish/hk2/extras/operation/internal/SingleOperationManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.ServiceLocator; @@ -36,7 +37,7 @@ public class SingleOperationManager { private final static String ID_PREAMBLE = "OperationIdentifier("; - private final Object operationLock = new Object(); + private final ReentrantLock operationLock = new ReentrantLock(); private final T scope; private final HashMap, OperationHandleImpl> openScopes = new HashMap, OperationHandleImpl>(); private final HashMap> threadToHandleMap = new HashMap>(); @@ -80,7 +81,8 @@ private OperationIdentifierImpl allocateNewIdentifier() { public OperationHandleImpl createOperation() { - synchronized (operationLock) { + operationLock.lock(); + try { if (closed) { throw new IllegalStateException("This manager has been closed"); } @@ -91,6 +93,8 @@ public OperationHandleImpl createOperation() { openScopes.put(id, created); return created; + } finally { + operationLock.unlock(); } } @@ -152,26 +156,33 @@ public OperationHandleImpl createOperation() { public OperationHandleImpl getCurrentOperationOnThisThread() { long threadId = Thread.currentThread().getId(); - synchronized (operationLock) { + operationLock.lock(); + try { if (closed) return null; return getCurrentOperationOnThisThread(threadId); + } finally { + operationLock.unlock(); } } /* package */ Set> getAllOperations() { HashSet> retVal = new HashSet>(); - synchronized (operationLock) { + operationLock.lock(); + try { if (closed) return Collections.emptySet(); retVal.addAll(openScopes.values()); return Collections.unmodifiableSet(retVal); + } finally { + operationLock.unlock(); } } /* package */ void shutdown() { - synchronized (operationLock) { + operationLock.lock(); + try { if (closed) return; closed = true; @@ -183,6 +194,8 @@ public OperationHandleImpl getCurrentOperationOnThisThread() { threadToHandleMap.clear(); ServiceLocatorUtilities.removeOneDescriptor(locator, operationDescriptor); + } finally { + operationLock.unlock(); } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/DynamicConfigurationImpl.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/DynamicConfigurationImpl.java index 872bc3d24b..e38be7003c 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/DynamicConfigurationImpl.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/DynamicConfigurationImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the @@ -19,6 +19,7 @@ import java.util.Arrays; import java.util.LinkedList; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Descriptor; @@ -44,7 +45,7 @@ public class DynamicConfigurationImpl implements DynamicConfiguration { private final LinkedList allIdempotentFilters = new LinkedList(); private final LinkedList allResources = new LinkedList(); - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private boolean committed = false; /** @@ -252,18 +253,24 @@ public void registerTwoPhaseResources(TwoPhaseResource... resources) { */ @Override public void commit() throws MultiException { - synchronized (lock) { + lock.lock(); + try { checkState(); committed = true; + } finally { + lock.unlock(); } locator.addConfiguration(this); } private void checkState() { - synchronized (lock) { + lock.lock(); + try { if (committed) throw new IllegalStateException(); + } finally { + lock.unlock(); } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/IndexedListData.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/IndexedListData.java index 9bec9354b4..adb426dad1 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/IndexedListData.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/IndexedListData.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.ListIterator; +import java.util.concurrent.locks.ReentrantLock; /** * This object contains a list of values. The list is not always sorted, but will @@ -32,13 +33,15 @@ * */ public class IndexedListData { + private final ReentrantLock lock = new ReentrantLock(); private final ArrayList> unsortedList = new ArrayList>(); private volatile boolean sorted = true; public Collection> getSortedList() { if (sorted) return unsortedList; - synchronized (this) { + lock.lock(); + try { if (sorted) return unsortedList; if (unsortedList.size() <= 1) { @@ -50,54 +53,86 @@ public Collection> getSortedList() { sorted = true; return unsortedList; + } finally { + lock.unlock(); } } - public synchronized void addDescriptor(SystemDescriptor descriptor) { - unsortedList.add(descriptor); - - sorted = unsortedList.size() <= 1; - - descriptor.addList(this); + public void addDescriptor(SystemDescriptor descriptor) { + lock.lock(); + try { + unsortedList.add(descriptor); + + sorted = unsortedList.size() <= 1; + + descriptor.addList(this); + } finally { + lock.unlock(); + } } - public synchronized void removeDescriptor(SystemDescriptor descriptor) { - ListIterator> iterator = unsortedList.listIterator(); - while (iterator.hasNext()) { - SystemDescriptor candidate = iterator.next(); - if (ServiceLocatorImpl.DESCRIPTOR_COMPARATOR.compare(descriptor, candidate) == 0) { - iterator.remove(); - break; + public void removeDescriptor(SystemDescriptor descriptor) { + lock.lock(); + try { + ListIterator> iterator = unsortedList.listIterator(); + while (iterator.hasNext()) { + SystemDescriptor candidate = iterator.next(); + if (ServiceLocatorImpl.DESCRIPTOR_COMPARATOR.compare(descriptor, candidate) == 0) { + iterator.remove(); + break; + } } + + sorted = unsortedList.size() <= 1; + + descriptor.removeList(this); + } finally { + lock.unlock(); } - - sorted = unsortedList.size() <= 1; - - descriptor.removeList(this); } - public synchronized boolean isEmpty() { - return unsortedList.isEmpty(); + public boolean isEmpty() { + lock.lock(); + try { + return unsortedList.isEmpty(); + } finally { + lock.unlock(); + } } /** * Called by a SystemDescriptor when its ranking has changed */ - public synchronized void unSort() { - if (unsortedList.size() > 1) { - sorted = false; + public void unSort() { + lock.lock(); + try { + if (unsortedList.size() > 1) { + sorted = false; + } + } finally { + lock.unlock(); } } - public synchronized void clear() { - for (SystemDescriptor descriptor : unsortedList) { - descriptor.removeList(this); + public void clear() { + lock.lock(); + try { + for (SystemDescriptor descriptor : unsortedList) { + descriptor.removeList(this); + } + + unsortedList.clear(); + } finally { + lock.unlock(); } - - unsortedList.clear(); } - public synchronized int size() { - return unsortedList.size(); + public int size() { + lock.lock(); + try { + return unsortedList.size(); + } finally { + lock.unlock(); + } } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/InstantiationServiceImpl.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/InstantiationServiceImpl.java index 6b073f048d..5147836d38 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/InstantiationServiceImpl.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/InstantiationServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.LinkedList; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.DescriptorVisibility; import org.glassfish.hk2.api.Injectee; @@ -31,60 +32,76 @@ */ @Visibility(DescriptorVisibility.LOCAL) public class InstantiationServiceImpl implements InstantiationService { + private final ReentrantLock lock = new ReentrantLock(); private final HashMap> injecteeStack = new HashMap>(); /* (non-Javadoc) * @see org.glassfish.hk2.api.InstantiationService#getInstantiationData() */ @Override - public synchronized InstantiationData getInstantiationData() { - long tid = Thread.currentThread().getId(); - - LinkedList threadStack = injecteeStack.get(tid); - if (threadStack == null) return null; - if (threadStack.isEmpty()) return null; - - final Injectee head = threadStack.getLast(); - - return new InstantiationData() { - - @Override - public Injectee getParentInjectee() { - return head; - } + public InstantiationData getInstantiationData() { + lock.lock(); + try { + long tid = Thread.currentThread().getId(); - @Override - public String toString() { - return "InstantiationData(" + head + "," + System.identityHashCode(this) + ")"; - } + LinkedList threadStack = injecteeStack.get(tid); + if (threadStack == null) return null; + if (threadStack.isEmpty()) return null; + + final Injectee head = threadStack.getLast(); - }; + return new InstantiationData() { + + @Override + public Injectee getParentInjectee() { + return head; + } + + @Override + public String toString() { + return "InstantiationData(" + head + "," + System.identityHashCode(this) + ")"; + } + + }; + } finally { + lock.unlock(); + } } - public synchronized void pushInjecteeParent(Injectee injectee) { - long tid = Thread.currentThread().getId(); - - LinkedList threadStack = injecteeStack.get(tid); - if (threadStack == null) { - threadStack = new LinkedList(); - injecteeStack.put(tid, threadStack); + public void pushInjecteeParent(Injectee injectee) { + lock.lock(); + try { + long tid = Thread.currentThread().getId(); + + LinkedList threadStack = injecteeStack.get(tid); + if (threadStack == null) { + threadStack = new LinkedList(); + injecteeStack.put(tid, threadStack); + } + + threadStack.addLast(injectee); + } finally { + lock.unlock(); } - - threadStack.addLast(injectee); } - public synchronized void popInjecteeParent() { - long tid = Thread.currentThread().getId(); - - LinkedList threadStack = injecteeStack.get(tid); - if (threadStack == null) return; - - threadStack.removeLast(); - - if (threadStack.isEmpty()) { - // prevents memory leaks for long dead threads - injecteeStack.remove(tid); + public void popInjecteeParent() { + lock.lock(); + try { + long tid = Thread.currentThread().getId(); + + LinkedList threadStack = injecteeStack.get(tid); + if (threadStack == null) return; + + threadStack.removeLast(); + + if (threadStack.isEmpty()) { + // prevents memory leaks for long dead threads + injecteeStack.remove(tid); + } + } finally { + lock.unlock(); } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/PerLocatorUtilities.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/PerLocatorUtilities.java index 639b987a94..192647cc50 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/PerLocatorUtilities.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/PerLocatorUtilities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.WeakHashMap; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; @@ -39,6 +40,7 @@ * */ public class PerLocatorUtilities { + private final ReentrantLock lock = new ReentrantLock(); /** Must not be static, otherwise it can leak when using thread pools */ private final Hk2ThreadLocal, String>> threadLocalAutoAnalyzerNameCache = new Hk2ThreadLocal, String>>() { @@ -256,10 +258,15 @@ private AnnotatedElementAnnotationInfo computeElementAnnotationInfo(AnnotatedEle return hard; } - public synchronized void releaseCaches() { - hasInjectCache.removeAll(); - if (proxyUtilities != null) { - proxyUtilities.releaseCache(); + public void releaseCaches() { + lock.lock(); + try { + hasInjectCache.removeAll(); + if (proxyUtilities != null) { + proxyUtilities.releaseCache(); + } + } finally { + lock.unlock(); } } @@ -273,12 +280,15 @@ public void shutdown() { public ProxyUtilities getProxyUtilities() { if (proxyUtilities != null) return proxyUtilities; - synchronized (this) { + lock.lock(); + try { if (proxyUtilities != null) return proxyUtilities; proxyUtilities = new ProxyUtilities(); return proxyUtilities; + } finally { + lock.unlock(); } } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/ProxyUtilities.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/ProxyUtilities.java index 636ff74691..5304e31db5 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/ProxyUtilities.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/ProxyUtilities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -20,6 +20,7 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.HashMap; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Injectee; @@ -38,7 +39,8 @@ * */ public class ProxyUtilities { - private final static Object proxyCreationLock = new Object(); + private final static ReentrantLock proxyCreationLock = new ReentrantLock(); + private final ReentrantLock lock = new ReentrantLock(); private final HashMap superClassToDelegator = new HashMap(); /** @@ -89,7 +91,8 @@ public ClassLoader run() { }); DelegatingClassLoader initDelegatingLoader; - synchronized (superClassToDelegator) { + lock.lock(); + try { initDelegatingLoader = superClassToDelegator.get(loader); if (initDelegatingLoader == null) { initDelegatingLoader = AccessController.doPrivileged(new PrivilegedAction() { @@ -106,6 +109,8 @@ public DelegatingClassLoader run() { superClassToDelegator.put(loader, initDelegatingLoader); } + } finally { + lock.unlock(); } final DelegatingClassLoader delegatingLoader = initDelegatingLoader; @@ -129,7 +134,8 @@ public T run() { @SuppressWarnings("unchecked") @Override public T run() { - synchronized (proxyCreationLock) { + proxyCreationLock.lock(); + try { ProxyFactory.ClassLoaderProvider originalProvider = ProxyFactory.classLoaderProvider; ProxyFactory.classLoaderProvider = new ProxyFactory.ClassLoaderProvider() { @@ -159,6 +165,8 @@ public ClassLoader get(ProxyFactory arg0) { finally { ProxyFactory.classLoaderProvider = originalProvider; } + } finally { + proxyCreationLock.unlock(); } } @@ -216,8 +224,11 @@ public T generateProxy(Class requestedClass, } public void releaseCache() { - synchronized (superClassToDelegator) { + lock.lock(); + try { superClassToDelegator.clear(); + } finally { + lock.unlock(); } } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceHandleImpl.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceHandleImpl.java index 29fc5ce212..60171bd790 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceHandleImpl.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceHandleImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Context; @@ -42,7 +43,7 @@ public class ServiceHandleImpl implements ServiceHandle { private final ActiveDescriptor root; private final ServiceLocatorImpl locator; private final LinkedList injectees = new LinkedList(); - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); private boolean serviceDestroyed = false; private boolean serviceSet = false; @@ -68,8 +69,11 @@ public T getService() { } private Injectee getLastInjectee() { - synchronized (lock) { + lock.lock(); + try { return (injectees.isEmpty()) ? null : injectees.getLast() ; + } finally { + lock.unlock(); } } @@ -81,7 +85,8 @@ private Injectee getLastInjectee() { } } - synchronized (lock) { + lock.lock(); + try { if (serviceDestroyed) throw new IllegalStateException("Service has been disposed"); if (serviceSet) return service; @@ -95,6 +100,8 @@ private Injectee getLastInjectee() { serviceSet = true; return service; + } finally { + lock.unlock(); } } @@ -136,7 +143,8 @@ public void close() { if (!root.isReified()) return; List> localSubHandles; - synchronized (lock) { + lock.lock(); + try { serviceActive = isActive(); if (serviceDestroyed) return; @@ -146,6 +154,8 @@ public void close() { localSubHandles = new ArrayList>(subHandles); subHandles.clear(); + } finally { + lock.unlock(); } if (root.getScopeAnnotation().equals(PerLookup.class)) { @@ -175,35 +185,50 @@ else if (serviceActive) { @Override public void setServiceData(Object serviceData) { - synchronized (lock) { + lock.lock(); + try { this.serviceData = serviceData; + } finally { + lock.unlock(); } } @Override public Object getServiceData() { - synchronized (lock) { + lock.lock(); + try { return serviceData; + } finally { + lock.unlock(); } } @Override public List> getSubHandles() { - synchronized (lock) { + lock.lock(); + try { return new ArrayList>(subHandles); + } finally { + lock.unlock(); } } public void pushInjectee(Injectee push) { - synchronized (lock) { + lock.lock(); + try { injectees.add(push); + } finally { + lock.unlock(); } } public void popInjectee() { - synchronized (lock) { + lock.lock(); + try { injectees.removeLast(); + } finally { + lock.unlock(); } } @@ -213,8 +238,11 @@ public void popInjectee() { * @param subHandle A handle to add for proper destruction */ public void addSubHandle(ServiceHandleImpl subHandle) { - synchronized (lock) { + lock.lock(); + try { subHandles.add(subHandle); + } finally { + lock.unlock(); } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceLocatorImpl.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceLocatorImpl.java index a5e9d32c09..5dd241edf1 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceLocatorImpl.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/ServiceLocatorImpl.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2024 Contributors to Eclipse Foundation. - * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the @@ -43,6 +43,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; @@ -126,7 +127,7 @@ public Boolean run() { }); private final static int CACHE_SIZE = 20000; - private final static Object sLock = new Object(); + private final static ReentrantLock sLock = new ReentrantLock(); private static long currentLocatorId = 0L; /* package */ final static DescriptorComparator DESCRIPTOR_COMPARATOR = new DescriptorComparator(); @@ -163,6 +164,7 @@ public Context compute(Class a) { return _resolveContext(a); } }); + private final ReentrantLock childrenLock = new ReentrantLock(); private final Map children = new WeakHashMap(); // Must be Weak for throw away children @@ -171,6 +173,7 @@ public Context compute(Class a) { private String defaultClassAnalyzer = ClassAnalyzer.DEFAULT_IMPLEMENTATION_NAME; private volatile Unqualified defaultUnqualified = null; + private final ReentrantLock allResolversLock = new ReentrantLock(); private ConcurrentHashMap, InjectionResolver> allResolvers = new ConcurrentHashMap, InjectionResolver>(); private final Cache> injecteeToResolverCache = @@ -186,8 +189,11 @@ public InjectionResolver compute(SystemInjecteeImpl key) { private ServiceLocatorState state = ServiceLocatorState.RUNNING; private static long getAndIncrementLocatorId() { - synchronized (sLock) { + sLock.lock(); + try { return currentLocatorId++; + } finally { + sLock.unlock(); } } @@ -889,12 +895,15 @@ public void shutdown() { try { if (state.equals(ServiceLocatorState.SHUTDOWN)) return; - synchronized(children) { + childrenLock.lock(); + try { for (Iterator childIterator = children.keySet().iterator(); childIterator.hasNext();) { ServiceLocatorImpl child = childIterator.next(); childIterator.remove(); child.shutdown(); } + } finally { + childrenLock.unlock(); } if (parent != null) { @@ -952,8 +961,11 @@ public String getName() { contextCache.clear(); perLocatorUtilities.shutdown(); - synchronized (children) { + childrenLock.lock(); + try { children.clear(); + } finally { + childrenLock.unlock(); } Logger.getLogger().debug("Shutdown ServiceLocator " + this); @@ -1960,9 +1972,12 @@ private void reupInjectionResolvers() { } } - synchronized (allResolvers) { + allResolversLock.lock(); + try { allResolvers.clear(); allResolvers.putAll(newResolvers); + } finally { + allResolversLock.unlock(); } injecteeToResolverCache.clear(); } @@ -2084,8 +2099,11 @@ private void reup(List> thingsAdded, private void getAllChildren(LinkedList allMyChildren) { LinkedList addMe; - synchronized (children) { + childrenLock.lock(); + try { addMe = new LinkedList(children.keySet()); + } finally { + childrenLock.unlock(); } allMyChildren.addAll(addMe); @@ -2382,14 +2400,20 @@ public long getLocatorId() { } private void addChild(ServiceLocatorImpl child) { - synchronized (children) { + childrenLock.lock(); + try { children.put(child, null); + } finally { + childrenLock.unlock(); } } private void removeChild(ServiceLocatorImpl child) { - synchronized (children) { + childrenLock.lock(); + try { children.remove(child); + } finally { + childrenLock.unlock(); } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/SingletonContext.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/SingletonContext.java index b2c590308c..5908decd00 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/SingletonContext.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/SingletonContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -21,6 +21,7 @@ import java.util.Comparator; import java.util.List; import java.util.TreeSet; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Singleton; @@ -41,6 +42,7 @@ @Singleton public class SingletonContext implements Context { private int generationNumber = Integer.MIN_VALUE; + private final ReentrantLock lock = new ReentrantLock(); private final ServiceLocatorImpl locator; private final Cache, Object> valueCache = @@ -144,8 +146,11 @@ public void shutdown() { for (ActiveDescriptor one : all) { if (one.getScope() == null || !one.getScope().equals(Singleton.class.getName())) continue; - synchronized (this) { + lock.lock(); + try { if (one.getCache() == null) continue; + } finally { + lock.unlock(); } if (one.getLocatorId() == null || one.getLocatorId() != myLocatorId) continue; diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/SystemDescriptor.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/SystemDescriptor.java index 05bfae8d76..9d31189c91 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/SystemDescriptor.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/SystemDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020 Payara Services Ltd. * * This program and the accompanying materials are made available under the @@ -28,6 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Descriptor; @@ -72,7 +74,9 @@ public class SystemDescriptor implements ActiveDescriptor, Closeable { private boolean preAnalyzed = false; private volatile boolean closed = false; - private final Object cacheLock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); + private final ReentrantLock cacheLock = new ReentrantLock(); + private final Condition notReifyingCondition = lock.newCondition(); private boolean cacheSet = false; private T cachedValue; @@ -287,9 +291,12 @@ public boolean isCacheSet() { */ @Override public void setCache(T cacheMe) { - synchronized (cacheLock) { + cacheLock.lock(); + try { cachedValue = cacheMe; cacheSet = true; + } finally { + cacheLock.unlock(); } } @@ -299,9 +306,12 @@ public void setCache(T cacheMe) { */ @Override public void releaseCache() { - synchronized (cacheLock) { + cacheLock.lock(); + try { cacheSet = false; cachedValue = null; + } finally { + cacheLock.unlock(); } } @@ -315,8 +325,11 @@ public boolean isReified() { // reified it is never un-reified if (reified) return true; - synchronized (this) { + lock.lock(); + try { return reified; + } finally { + lock.unlock(); } } @@ -553,8 +566,11 @@ public void dispose(T instance) { private void checkState() { if (reified) return; - synchronized(this) { + lock.lock(); + try { if (!reified) throw new IllegalStateException(); + } finally { + lock.unlock(); } } @@ -648,12 +664,13 @@ public String getName() { /* package */ void reify(Class implClass, Collector collector) { if (reified) return; - synchronized(this) { + lock.lock(); + try { if (reified) return; while (reifying) { try { - this.wait(); + notReifyingCondition.await(); } catch (InterruptedException e) { collector.addThrowable(e); @@ -663,6 +680,8 @@ public String getName() { if (reified) return; reifying = true; + } finally { + lock.unlock(); } try { @@ -673,9 +692,10 @@ public String getName() { internalReify(implClass, collector); } finally { - synchronized (this) { + lock.lock(); + try { reifying = false; - this.notifyAll(); + notReifyingCondition.signalAll(); if (!collector.hasErrors()) { reified = true; @@ -683,6 +703,8 @@ public String getName() { else { collector.addThrowable(new IllegalArgumentException("Errors were discovered while reifying " + this)); } + } finally { + lock.unlock(); } } @@ -820,11 +842,14 @@ public Long getLocatorId() { public boolean close() { if (closed) return true; - synchronized (this) { + lock.lock(); + try { if (closed) return true; closed = true; return false; + } finally { + lock.unlock(); } } diff --git a/hk2-locator/src/main/java/org/jvnet/hk2/internal/Utilities.java b/hk2-locator/src/main/java/org/jvnet/hk2/internal/Utilities.java index 30fb4ff1b4..06152f5f3a 100755 --- a/hk2-locator/src/main/java/org/jvnet/hk2/internal/Utilities.java +++ b/hk2-locator/src/main/java/org/jvnet/hk2/internal/Utilities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2020, 2021 Payara Services Ltd. * * This program and the accompanying materials are made available under the @@ -44,6 +44,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.locks.ReentrantLock; import jakarta.inject.Inject; import jakarta.inject.Named; @@ -110,6 +111,7 @@ */ public class Utilities { private final static String USE_SOFT_REFERENCE_PROPERTY = "org.jvnet.hk2.properties.useSoftReference"; + private final static ReentrantLock lock = new ReentrantLock(); final static boolean USE_SOFT_REFERENCE; static { USE_SOFT_REFERENCE = AccessController.doPrivileged(new PrivilegedAction() { @@ -2257,24 +2259,29 @@ public static boolean isTypeSafe(Type requiredType, Type beanType) { * * @return true if the system can create proxies, false otherwise */ - public synchronized static boolean proxiesAvailable() { - if (proxiesAvailable != null) { - return proxiesAvailable; - } - - ClassLoader loader = Utilities.class.getClassLoader(); - if (loader == null) { - loader = ClassLoader.getSystemClassLoader(); - } - + public static boolean proxiesAvailable() { + lock.lock(); try { - loader.loadClass("javassist.util.proxy.MethodHandler"); - proxiesAvailable = true; - return true; - } - catch (Throwable th) { - proxiesAvailable = false; - return false; + if (proxiesAvailable != null) { + return proxiesAvailable; + } + + ClassLoader loader = Utilities.class.getClassLoader(); + if (loader == null) { + loader = ClassLoader.getSystemClassLoader(); + } + + try { + loader.loadClass("javassist.util.proxy.MethodHandler"); + proxiesAvailable = true; + return true; + } + catch (Throwable th) { + proxiesAvailable = false; + return false; + } + } finally { + lock.unlock(); } } diff --git a/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/AsyncRunLevelContext.java b/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/AsyncRunLevelContext.java index 63195507d3..87526a3555 100755 --- a/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/AsyncRunLevelContext.java +++ b/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/AsyncRunLevelContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -29,6 +29,8 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.locks.Condition; import java.util.logging.Level; import java.util.logging.Logger; @@ -69,6 +71,8 @@ public Boolean run() { private static final ThreadFactory THREAD_FACTORY = new RunLevelThreadFactory(); + final ReentrantLock lock = new ReentrantLock(); + private final Condition notEmpty = lock.newCondition(); private final org.glassfish.hk2.utilities.reflection.Logger hk2Logger = org.glassfish.hk2.utilities.reflection.Logger.getLogger(); private int currentLevel = RunLevel.RUNLEVEL_VAL_INITIAL; @@ -159,7 +163,8 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, Integer localModeOverride; long tid = -1L; - synchronized (this) { + lock.lock(); + try { localModeOverride = modeOverride; retVal = (U) backingMap.get(activeDescriptor); @@ -213,7 +218,7 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, } try { - this.wait(); + notEmpty.await(); } catch (InterruptedException ie) { throw new MultiException(ie); @@ -265,6 +270,8 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, localCurrentLevel = currentTask.getProposedLevel(); } } + } finally { + lock.unlock(); } Throwable error = null; @@ -308,7 +315,8 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, throw new RuntimeException(th); } finally { - synchronized (this) { + lock.lock(); + try { boolean hardCancelled = hardCancelledDescriptors.remove(activeDescriptor); if (retVal != null) { @@ -332,7 +340,7 @@ public U findOrCreate(ActiveDescriptor activeDescriptor, } creatingDescriptors.remove(activeDescriptor); - this.notifyAll(); + notEmpty.signalAll(); if (DEBUG_CONTEXT) { hk2Logger.debug("AsyncRunLevelController other threads notified cancellation path for " + oneLineDescriptor + " in thread " + tid); @@ -348,11 +356,13 @@ else if (error != null) { } creatingDescriptors.remove(activeDescriptor); - this.notifyAll(); + notEmpty.signalAll(); if (DEBUG_CONTEXT) { hk2Logger.debug("AsyncRunLevelController other threads notified for " + oneLineDescriptor + " in thread " + tid); } + } finally { + lock.unlock(); } } } @@ -364,14 +374,20 @@ else if (error != null) { * @return true if already created, false otherwise */ public boolean containsKey(ActiveDescriptor descriptor) { - synchronized (this) { + lock.lock(); + try { return backingMap.containsKey(descriptor); + } finally { + lock.unlock(); } } /* package */ boolean wouldBlockRightNow(ActiveDescriptor desc) { - synchronized (this) { + lock.lock(); + try { return creatingDescriptors.containsKey(desc); + } finally { + lock.unlock(); } } @@ -395,9 +411,12 @@ public boolean containsKey(ActiveDescriptor descriptor) { @SuppressWarnings("unchecked") public void destroyOne(ActiveDescriptor descriptor) { Object retVal = null; - synchronized (this) { + lock.lock(); + try { retVal = backingMap.remove(descriptor); if (retVal == null) return; + } finally { + lock.unlock(); } ((ActiveDescriptor) descriptor).dispose(retVal); @@ -426,41 +445,77 @@ private void validate(ActiveDescriptor descriptor, int currentLevel) throws I } - /* package */ synchronized int getCurrentLevel() { - return currentLevel; + /* package */ int getCurrentLevel() { + lock.lock(); + try { + return currentLevel; + } finally { + lock.unlock(); + } } - /* package */ synchronized void levelCancelled() { - wasCancelled = true; + /* package */ void levelCancelled() { + lock.lock(); + try { + wasCancelled = true; + } finally { + lock.unlock(); + } } - - /* package */ synchronized void setCurrentLevel(int currentLevel) { - this.currentLevel = currentLevel; + + /* package */ void setCurrentLevel(int currentLevel) { + lock.lock(); + try { + this.currentLevel = currentLevel; + } finally { + lock.unlock(); + } } - /* package */ synchronized void setPolicy(RunLevelController.ThreadingPolicy policy) { - this.policy = policy; + /* package */ void setPolicy(RunLevelController.ThreadingPolicy policy) { + lock.lock(); + try { + this.policy = policy; + } finally { + lock.unlock(); + } } - /* package */ synchronized void setExecutor(Executor executor) { - if (executor == null) { - this.executor = DEFAULT_EXECUTOR; - } - else { - this.executor = executor; + /* package */ void setExecutor(Executor executor) { + lock.lock(); + try { + if (executor == null) { + this.executor = DEFAULT_EXECUTOR; + } + else { + this.executor = executor; + } + } finally { + lock.unlock(); } } - /* package */ synchronized Executor getExecutor() { - return executor; + /* package */ Executor getExecutor() { + lock.lock(); + try { + return executor; + } finally { + lock.unlock(); + } } - /* package */ synchronized RunLevelController.ThreadingPolicy getPolicy() { - return policy; + /* package */ RunLevelController.ThreadingPolicy getPolicy() { + lock.lock(); + try { + return policy; + } finally { + lock.unlock(); + } } /* package */ List> getOrderedListOfServicesAtLevel(int level) { - synchronized (this) { + lock.lock(); + try { LinkedList> retVal = new LinkedList>(); while (!orderedCreationList.isEmpty()) { @@ -474,6 +529,8 @@ private void validate(ActiveDescriptor descriptor, int currentLevel) throws I } return retVal; + } finally { + lock.unlock(); } } @@ -487,7 +544,8 @@ private void validate(ActiveDescriptor descriptor, int currentLevel) throws I */ public RunLevelFuture proceedTo(int level) throws CurrentlyRunningException { CurrentTaskFutureWrapper localTask; - synchronized (this) { + lock.lock(); + try { boolean fullyThreaded = policy.equals(RunLevelController.ThreadingPolicy.FULLY_THREADED); if (currentTask != null) { @@ -504,6 +562,8 @@ public RunLevelFuture proceedTo(int level) throws CurrentlyRunningException { TIMER)); localTask = currentTask; + } finally { + lock.unlock(); } // Do outside the lock so that when not fully threaded we do not hold the @@ -513,8 +573,13 @@ public RunLevelFuture proceedTo(int level) throws CurrentlyRunningException { return localTask; } - /* package */ synchronized void jobDone() { - currentTask = null; + /* package */ void jobDone() { + lock.lock(); + try { + currentTask = null; + } finally { + lock.unlock(); + } } /** @@ -522,42 +587,82 @@ public RunLevelFuture proceedTo(int level) throws CurrentlyRunningException { * * @return The current task, may be null if there is no current task */ - public synchronized RunLevelFuture getCurrentFuture() { - return currentTask; + public RunLevelFuture getCurrentFuture() { + lock.lock(); + try { + return currentTask; + } finally { + lock.unlock(); + } } - /* package */ synchronized void setMaximumThreads(int maximum) { - if (maximum < 1) { - maxThreads = 1; - } - else { - maxThreads = maximum; + /* package */ void setMaximumThreads(int maximum) { + lock.lock(); + try { + if (maximum < 1) { + maxThreads = 1; + } + else { + maxThreads = maximum; + } + } finally { + lock.unlock(); } } - /* package */ synchronized int getMaximumThreads() { - return maxThreads; + /* package */ int getMaximumThreads() { + lock.lock(); + try { + return maxThreads; + } finally { + lock.unlock(); + } } - /* package */ synchronized void clearErrors() { - levelErrorMap.clear(); - wasCancelled = false; + /* package */ void clearErrors() { + lock.lock(); + try { + levelErrorMap.clear(); + wasCancelled = false; + } finally { + lock.unlock(); + } } - /* package */ synchronized void setCancelTimeout(long cancelTimeout) { - this.cancelTimeout = cancelTimeout; + /* package */ void setCancelTimeout(long cancelTimeout) { + lock.lock(); + try { + this.cancelTimeout = cancelTimeout; + } finally { + lock.unlock(); + } } - /* package */ synchronized long getCancelTimeout() { - return cancelTimeout; + /* package */ long getCancelTimeout() { + lock.lock(); + try { + return cancelTimeout; + } finally { + lock.unlock(); + } } - /* package */ synchronized Integer getModeOverride() { - return modeOverride; + /* package */ Integer getModeOverride() { + lock.lock(); + try { + return modeOverride; + } finally { + lock.unlock(); + } } - /* package */ synchronized void setModeOverride(Integer modeOverride) { - this.modeOverride = modeOverride; + /* package */ void setModeOverride(Integer modeOverride) { + lock.lock(); + try { + this.modeOverride = modeOverride; + } finally { + lock.unlock(); + } } private static class RunLevelControllerThread extends Thread { diff --git a/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/CurrentTaskFuture.java b/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/CurrentTaskFuture.java index 5cf9b7580b..97e2488a67 100755 --- a/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/CurrentTaskFuture.java +++ b/hk2-runlevel/src/main/java/org/glassfish/hk2/runlevel/internal/CurrentTaskFuture.java @@ -1,6 +1,6 @@ /* * Copyright (c) 2024 Contributors to Eclipse Foundation. - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -26,6 +26,8 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.Descriptor; @@ -52,6 +54,7 @@ * */ public class CurrentTaskFuture implements ChangeableRunLevelFuture { + private final ReentrantLock lock = new ReentrantLock(); private final AsyncRunLevelContext asyncContext; private final Executor executor; private final ServiceLocator locator; @@ -115,9 +118,12 @@ else if (currentLevel < proposedLevel) { UpAllTheWay localUpAllTheWay; DownAllTheWay localDownAllTheWay; - synchronized (this) { + lock.lock(); + try { localUpAllTheWay = upAllTheWay; localDownAllTheWay = downAllTheWay; + } finally { + lock.unlock(); } if (localUpAllTheWay != null || localDownAllTheWay != null) { @@ -148,17 +154,23 @@ else if (localDownAllTheWay != null) { @Override public boolean isUp() { - synchronized (this) { + lock.lock(); + try { if (upAllTheWay != null) return true; return false; + } finally { + lock.unlock(); } } @Override public boolean isDown() { - synchronized (this) { + lock.lock(); + try { if (downAllTheWay != null) return true; return false; + } finally { + lock.unlock(); } } @@ -168,8 +180,10 @@ public boolean isDown() { @Override public boolean cancel(boolean mayInterruptIfRunning) { // Not locking in this order can cause deadlocks - synchronized (asyncContext) { - synchronized (this) { + try { + asyncContext.lock.lock(); + try { + lock.lock(); if (done) return false; if (cancelled) return false; @@ -183,7 +197,11 @@ else if (downAllTheWay != null) { } return true; + } finally { + lock.unlock(); } + } finally { + asyncContext.lock.unlock(); } } @@ -192,8 +210,11 @@ else if (downAllTheWay != null) { */ @Override public boolean isCancelled() { - synchronized (this) { + lock.lock(); + try { return cancelled; + } finally { + lock.unlock(); } } @@ -202,15 +223,21 @@ public boolean isCancelled() { */ @Override public boolean isDone() { - synchronized (this) { + lock.lock(); + try { return done; + } finally { + lock.unlock(); } } @Override public int getProposedLevel() { - synchronized (this) { + lock.lock(); + try { return proposedLevel; + } finally { + lock.unlock(); } } @@ -218,7 +245,8 @@ public int getProposedLevel() { public int changeProposedLevel(int proposedLevel) { int oldProposedVal; boolean needGo = false; - synchronized (this) { + lock.lock(); + try { if (done) throw new IllegalStateException("Cannot change the proposed level of a future that is already complete"); if (!inCallback) throw new IllegalStateException( "changeProposedLevel must only be called from inside a RunLevelListener callback method"); @@ -263,6 +291,8 @@ else if (downAllTheWay != null) { // Should be impossible throw new AssertionError("Can not determine previous job"); } + } finally { + lock.unlock(); } if (needGo) { @@ -273,8 +303,11 @@ else if (downAllTheWay != null) { } private void setInCallback(boolean inCallback) { - synchronized (this) { + lock.lock(); + try { this.inCallback = inCallback; + } finally { + lock.unlock(); } } @@ -298,13 +331,16 @@ public Object get() throws InterruptedException, ExecutionException { public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { AllTheWay allTheWay = null; - synchronized (this) { + lock.lock(); + try { if (upAllTheWay != null) { allTheWay = upAllTheWay; } else if (downAllTheWay != null) { allTheWay = downAllTheWay; } + } finally { + lock.unlock(); } if (allTheWay == null) return null; @@ -314,13 +350,16 @@ else if (downAllTheWay != null) { try { result = allTheWay.waitForResult(timeout, unit); if (result == null) { - synchronized (this) { + lock.lock(); + try { if (upAllTheWay != null) { allTheWay = upAllTheWay; } else if (downAllTheWay != null) { allTheWay = downAllTheWay; } + } finally { + lock.unlock(); } continue; @@ -330,15 +369,21 @@ else if (downAllTheWay != null) { throw new TimeoutException(); } - synchronized (this) { + lock.lock(); + try { done = true; + } finally { + lock.unlock(); } return null; } catch (MultiException me) { - synchronized (this) { + lock.lock(); + try { done = true; + } finally { + lock.unlock(); } throw new ExecutionException(me); @@ -442,7 +487,8 @@ private interface AllTheWay { } private class UpAllTheWay implements AllTheWay { - private final Object lock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); + private final Condition condition = lock.newCondition(); private int goingTo; private final int maxThreads; @@ -477,10 +523,13 @@ private UpAllTheWay(int goingTo, CurrentTaskFuture future, } private void cancel() { - synchronized (lock) { + lock.lock(); + try { cancelled = true; asyncContext.levelCancelled(); currentJob.cancel(); + } finally { + lock.unlock(); } } @@ -488,11 +537,12 @@ private void cancel() { public Boolean waitForResult(long timeout, TimeUnit unit) throws InterruptedException, MultiException { long totalWaitTimeMillis = TimeUnit.MILLISECONDS.convert(timeout, unit); - synchronized (lock) { + lock.lock(); + try { while (totalWaitTimeMillis > 0L && !done && !repurposed) { long startTime = System.currentTimeMillis(); - lock.wait(totalWaitTimeMillis); + condition.await(totalWaitTimeMillis, TimeUnit.MILLISECONDS); long elapsedTime = System.currentTimeMillis() - startTime; totalWaitTimeMillis -= elapsedTime; @@ -505,21 +555,27 @@ public Boolean waitForResult(long timeout, TimeUnit unit) throws InterruptedExce } return done; + } finally { + lock.unlock(); } } private void setGoingTo(int goingTo, boolean repurposed) { - synchronized (lock) { + lock.lock(); + try { this.goingTo = goingTo; if (repurposed) { this.repurposed = true; } + } finally { + lock.unlock(); } } private void go() { if (useThreads) { - synchronized (lock) { + lock.lock(); + try { workingOn++; if (workingOn > goingTo) { if (!repurposed) { @@ -528,7 +584,7 @@ private void go() { done = true; } - lock.notifyAll(); + condition.signalAll(); return; } @@ -542,12 +598,15 @@ private void go() { executor.execute(currentJob); return; + } finally { + lock.unlock(); } } workingOn++; while (workingOn <= goingTo) { - synchronized (lock) { + lock.lock(); + try { if (done) break; currentJob = new UpOneLevel(workingOn, @@ -557,6 +616,8 @@ private void go() { sorters, 0, cancelTimeout); + } finally { + lock.unlock(); } currentJob.run(); @@ -564,7 +625,8 @@ private void go() { workingOn++; } - synchronized (lock) { + lock.lock(); + try { if (done) return; if (!repurposed) { @@ -573,7 +635,9 @@ private void go() { done = true; } - lock.notifyAll(); + condition.signalAll(); + } finally { + lock.unlock(); } } @@ -585,22 +649,28 @@ private void currentJobComplete(MultiException accumulatedExceptions) { downer.run(); - synchronized (lock) { + lock.lock(); + try { done = true; this.exception = accumulatedExceptions; - lock.notifyAll(); + condition.signalAll();; asyncContext.jobDone(); + } finally { + lock.unlock(); } return; } DownAllTheWay downer = null; - synchronized (lock) { + lock.lock(); + try { if (cancelled) { downer = new DownAllTheWay(workingOn - 1, null, null); } + } finally { + lock.unlock(); } if (downer != null) { @@ -608,13 +678,16 @@ private void currentJobComplete(MultiException accumulatedExceptions) { invokeOnCancelled(future, workingOn - 1, listeners); - synchronized (lock) { + lock.lock(); + try { done = true; - lock.notifyAll(); + condition.signalAll(); asyncContext.jobDone(); return; + } finally { + lock.unlock(); } } @@ -628,8 +701,8 @@ private void currentJobComplete(MultiException accumulatedExceptions) { } private class UpOneLevel implements Runnable { - private final Object lock = new Object(); - private final Object queueLock = new Object(); + private final ReentrantLock lock = new ReentrantLock(); + private final ReentrantLock queueLock = new ReentrantLock(); private final int upToThisLevel; private final CurrentTaskFuture currentTaskFuture; private final List> listeners; @@ -663,28 +736,40 @@ private UpOneLevel(int paramUpToThisLevel, } private void cancel() { - synchronized (lock) { + lock.lock(); + try { cancelled = true; hardCanceller = new CancelTimer(this); timer.schedule(hardCanceller, cancelTimeout); + } finally { + lock.unlock(); } } private void hardCancel() { - synchronized (asyncContext) { - synchronized (lock) { + asyncContext.lock.lock(); + try { + lock.lock(); + try { hardCancelled = true; + } finally { + lock.unlock(); } HashSet> poisonMe; - synchronized (queueLock) { + queueLock.lock(); + try { poisonMe = new HashSet>(outstandingHandles); outstandingHandles.clear(); + } finally { + queueLock.unlock(); } for (ServiceHandle handle : poisonMe) { asyncContext.hardCancelOne(handle.getActiveDescriptor()); } + } finally { + asyncContext.lock.unlock(); } master.currentJobComplete(null); @@ -722,7 +807,7 @@ private List> applySorters(List> jobs) { @Override public void run() { - Object jobsLock = new Object(); + ReentrantLock jobsLock = new ReentrantLock(); List> jobs = locator.getAllServiceHandles(new IndexedFilter() { @Override @@ -764,7 +849,8 @@ public String getName() { } private void fail(Throwable th, Descriptor descriptor) { - synchronized (lock) { + lock.lock(); + try { if (hardCancelled) return; ErrorInformation info = invokeOnError(currentTaskFuture, th, @@ -779,12 +865,15 @@ private void fail(Throwable th, Descriptor descriptor) { } accumulatedExceptions.addError(th); + } finally { + lock.unlock(); } } private void jobComplete() { boolean complete = false; - synchronized (lock) { + lock.lock(); + try { if (hardCancelled) return; completedJobs++; @@ -795,6 +884,8 @@ private void jobComplete() { hardCanceller = null; } } + } finally { + lock.unlock(); } if (complete) { @@ -824,6 +915,8 @@ public void run() { * */ private class DownAllTheWay implements Runnable, AllTheWay { + private final ReentrantLock lock = new ReentrantLock(); + private final Condition lockCondition = lock.newCondition(); private int goingTo; private CurrentTaskFuture future; private final List> listeners; @@ -838,6 +931,8 @@ private class DownAllTheWay implements Runnable, AllTheWay { private ActiveDescriptor lastErrorDescriptor = null; private List> queue = Collections.emptyList(); + private ReentrantLock queueLock = new ReentrantLock(); + private Condition queueCondition = queueLock.newCondition(); private boolean downHardCancelled = false; private HardCancelDownTimer hardCancelDownTimer = null; @@ -861,36 +956,51 @@ public DownAllTheWay(int goingTo, private void cancel() { List> localQueue; - - synchronized (this) { + ReentrantLock localQueueLock; + Condition localQueueCondition; + lock.lock(); + try { if (cancelled) return; // idempotent cancelled = true; if (done) return; localQueue = queue; + localQueueLock = queueLock; + localQueueCondition = queueCondition; + } finally { + lock.unlock(); } - synchronized (localQueue) { + queueLock.lock(); + try { if (localQueue.isEmpty()) return; - hardCancelDownTimer = new HardCancelDownTimer(this, localQueue); + hardCancelDownTimer = new HardCancelDownTimer(this, localQueue, localQueueLock, localQueueCondition); timer.schedule(hardCancelDownTimer, cancelTimeout, cancelTimeout); + } finally { + queueLock.unlock(); } } private void setGoingTo(int goingTo, boolean repurposed) { - synchronized (this) { + lock.lock(); + try { this.goingTo = goingTo; if (repurposed) { this.repurposed = true; } + } finally { + lock.unlock(); } } private int getGoingTo() { - synchronized (this) { + lock.lock(); + try { return goingTo; + } finally { + lock.unlock(); } } @@ -899,9 +1009,12 @@ public void run() { while (workingOn > getGoingTo()) { boolean runOnCancelled; boolean localCancelled; - synchronized (this) { + lock.lock(); + try { localCancelled = cancelled; runOnCancelled = cancelled && (future != null); + } finally { + lock.unlock(); } if (runOnCancelled) { @@ -909,16 +1022,18 @@ public void run() { invokeOnCancelled(future, workingOn, listeners); } - synchronized (this) { + lock.lock(); + try { if (localCancelled) { asyncContext.jobDone(); done = true; - - this.notifyAll(); + lockCondition.signalAll(); return; } + } finally { + lock.unlock(); } int proceedingTo = workingOn - 1; @@ -932,21 +1047,29 @@ public void run() { // But we don't call the proceedTo until all those services are gone List> localQueue = asyncContext.getOrderedListOfServicesAtLevel(workingOn); - synchronized(this) { + ReentrantLock localQueueLock = new ReentrantLock(); + Condition localQueueCondition = localQueueLock.newCondition(); + lock.lock(); + try { queue = localQueue; + queueLock = localQueueLock; + queueCondition = localQueueCondition; + } finally { + lock.unlock(); } ErrorInformation errorInfo = null; - synchronized (queue) { + queueLock.lock(); + try { for (;;) { - DownQueueRunner currentRunner = new DownQueueRunner(queue, queue, this, locator); + DownQueueRunner currentRunner = new DownQueueRunner(queueLock, queueCondition, queue, this, locator); executor.execute(currentRunner); lastError = null; for (;;) { while (!queue.isEmpty() && (lastError == null) && (downHardCancelled == false)) { try { - queue.wait(); + queueCondition.await(); } catch (InterruptedException ie) { throw new RuntimeException(ie); @@ -977,15 +1100,25 @@ public void run() { break; } } + } finally { + queueLock.unlock(); } - synchronized(this) { + lock.lock(); + try { queue = Collections.emptyList(); + queueLock = new ReentrantLock(); + queueCondition = queueLock.newCondition(); + } finally { + lock.unlock(); } if (errorInfo != null && ErrorInformation.ErrorAction.GO_TO_NEXT_LOWER_LEVEL_AND_STOP.equals(errorInfo.getAction())) { - synchronized (this) { + lock.lock(); + try { goingTo = workingOn; + } finally { + lock.unlock(); } } @@ -1002,14 +1135,17 @@ public void run() { return; } - synchronized (this) { + lock.lock(); + try { if (!repurposed) { asyncContext.jobDone(); done = true; } - this.notifyAll(); + lockCondition.signalAll(); + } finally { + lock.unlock(); } } @@ -1018,11 +1154,12 @@ public void run() { public Boolean waitForResult(long timeout, TimeUnit unit) throws InterruptedException, MultiException { long totalWaitTimeMillis = TimeUnit.MILLISECONDS.convert(timeout, unit); - synchronized (this) { + lock.lock(); + try { while (totalWaitTimeMillis > 0L && !done && !repurposed) { long startTime = System.currentTimeMillis(); - this.wait(totalWaitTimeMillis); + lockCondition.await(totalWaitTimeMillis, TimeUnit.MILLISECONDS); long elapsedTime = System.currentTimeMillis() - startTime; totalWaitTimeMillis -= elapsedTime; @@ -1031,6 +1168,8 @@ public Boolean waitForResult(long timeout, TimeUnit unit) throws InterruptedExce if (repurposed) return null; return done; + } finally { + lock.unlock(); } } @@ -1039,28 +1178,35 @@ public Boolean waitForResult(long timeout, TimeUnit unit) throws InterruptedExce private static class HardCancelDownTimer extends TimerTask { private final DownAllTheWay parent; private final List> queue; + private final ReentrantLock localQueueLock; + private final Condition localQueueCondition; private int lastQueueSize; - private HardCancelDownTimer(DownAllTheWay parent, List> queue) { + private HardCancelDownTimer(DownAllTheWay parent, List> queue, ReentrantLock localQueueLock, Condition localQueueCondition) { this.parent = parent; this.queue = queue; + this.localQueueLock = localQueueLock; + this.localQueueCondition = localQueueCondition; lastQueueSize = queue.size(); } @Override public void run() { - synchronized (queue) { + localQueueLock.lock(); + try { int currentSize = queue.size(); if (currentSize == 0) return; if (currentSize == lastQueueSize) { parent.downHardCancelled = true; - queue.notify(); + localQueueCondition.signal(); } else { lastQueueSize = currentSize; } + } finally { + localQueueLock.unlock(); } } } @@ -1068,20 +1214,20 @@ public void run() { private static class QueueRunner implements Runnable { private final ServiceLocator locator; private final AsyncRunLevelContext asyncContext; - private final Object queueLock; + private final ReentrantLock queueLock; private final List> queue; private final UpOneLevel parent; - private final Object parentLock; + private final ReentrantLock parentLock; private final int maxThreads; private ServiceHandle wouldHaveBlocked; private final HashSet> alreadyTried = new HashSet>(); private QueueRunner(ServiceLocator locator, AsyncRunLevelContext asyncContext, - Object queueLock, + ReentrantLock queueLock, List> queue, UpOneLevel parent, - Object parentLock, + ReentrantLock parentLock, int maxThreads) { this.locator = locator; this.asyncContext = asyncContext; @@ -1098,7 +1244,8 @@ public void run() { for (;;) { ServiceHandle job; boolean block; - synchronized(queueLock) { + queueLock.lock(); + try { if (runningHandle != null) parent.jobFinished(runningHandle); if (wouldHaveBlocked != null) { @@ -1140,6 +1287,8 @@ public void run() { parent.jobRunning(job); runningHandle = job; + } finally { + queueLock.unlock(); } oneJob(job, block); @@ -1200,8 +1349,11 @@ private void oneJob(ServiceHandle fService, boolean block) { boolean completed = true; try { boolean ok; - synchronized (parentLock) { + parentLock.lock(); + try { ok = (!parent.cancelled && (parent.accumulatedExceptions == null)); + } finally { + parentLock.unlock(); } if (!block && isWouldBlockRightNow(new HashSet>(), fService.getActiveDescriptor())) { @@ -1237,17 +1389,20 @@ else if (!isWasCancelled(me)) { } private static class DownQueueRunner implements Runnable { - private final Object queueLock; + private final ReentrantLock queueLock; + private final Condition queueCondition; private final List> queue; private final DownAllTheWay parent; private final ServiceLocator locator; private boolean caput; - private DownQueueRunner(Object queueLock, + private DownQueueRunner(ReentrantLock queueLock, + Condition queueCondition, List> queue, DownAllTheWay parent, ServiceLocator locator) { this.queueLock = queueLock; + this.queueCondition = queueCondition; this.queue = queue; this.parent = parent; this.locator = locator; @@ -1257,27 +1412,36 @@ private DownQueueRunner(Object queueLock, public void run() { for (;;) { ActiveDescriptor job; - synchronized (queueLock) { + queueLock.lock(); + try { if (caput) return; if (queue.isEmpty()) { - queueLock.notify(); + queueCondition.signal(); return; } job = queue.get(0); + } finally { + queueLock.unlock(); } try { locator.getServiceHandle(job).destroy(); } catch (Throwable th) { - synchronized (queueLock) { + queueLock.lock(); + try { parent.lastError = th; parent.lastErrorDescriptor = job; - queueLock.notify(); + queueCondition.signal(); + } finally { + queueLock.unlock(); } } finally { - synchronized (queueLock) { + queueLock.lock(); + try { queue.remove(job); + } finally { + queueLock.unlock(); } } } diff --git a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/LRUHybridCache.java b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/LRUHybridCache.java index 91ed76a8ae..26cb937a77 100755 --- a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/LRUHybridCache.java +++ b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/LRUHybridCache.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -26,6 +26,7 @@ import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import java.util.concurrent.locks.ReentrantLock; /** * Hybrid cache that allows explicit removals of included entries as well @@ -160,7 +161,7 @@ public void handleCycle(Object key) { private final ConcurrentHashMap.OriginThreadAwareFuture> cache = new ConcurrentHashMap.OriginThreadAwareFuture>(); private final Computable> computable; - private final Object prunningLock = new Object(); + private final ReentrantLock prunningLock = new ReentrantLock(); private final int maxCacheSize; /** @@ -258,11 +259,14 @@ public HybridCacheEntry compute(final K key) { LRUHybridCache.OriginThreadAwareFuture ft = new LRUHybridCache.OriginThreadAwareFuture(this, key); - synchronized (prunningLock) { + prunningLock.lock(); + try { if (cache.size() + 1 > maxCacheSize) { removeLRUItem(); } f = cache.putIfAbsent(key, ft); + } finally { + prunningLock.unlock(); } if (f == null) { f = ft; diff --git a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/LRUCacheCheapRead.java b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/LRUCacheCheapRead.java index afa0855e7e..cb72cc576e 100755 --- a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/LRUCacheCheapRead.java +++ b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/LRUCacheCheapRead.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.cache.CacheEntry; import org.glassfish.hk2.utilities.cache.CacheKeyFilter; @@ -41,7 +42,7 @@ */ public class LRUCacheCheapRead extends LRUCache { - final Object prunningLock = new Object(); + final ReentrantLock prunningLock = new ReentrantLock(); final int maxCacheSize; Map> cache = new ConcurrentHashMap>(); @@ -64,12 +65,15 @@ public V get(K key) { @Override public CacheEntry put(K key, V value) { CacheEntryImpl entry = new CacheEntryImpl(key, value, this); - synchronized (prunningLock) { + prunningLock.lock(); + try { if (cache.size() + 1 > maxCacheSize) { removeLRUItem(); } cache.put(key, entry); return entry; + } finally { + prunningLock.unlock(); } } diff --git a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/WeakCARCacheImpl.java b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/WeakCARCacheImpl.java index 9ecba04b73..8a5a694c97 100755 --- a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/WeakCARCacheImpl.java +++ b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/cache/internal/WeakCARCacheImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -18,6 +18,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.cache.CacheKeyFilter; import org.glassfish.hk2.utilities.cache.Computable; @@ -46,7 +47,8 @@ public class WeakCARCacheImpl implements WeakCARCache { // The target size of t1, adaptive private int p = 0; - + + private final ReentrantLock lock = new ReentrantLock(); private final AtomicLong hits = new AtomicLong(0L); private final AtomicLong tries = new AtomicLong(0L); @@ -92,7 +94,8 @@ public V compute(K key) { return value; } - synchronized (this) { + lock.lock(); + try { value = getValueFromT(key); if (value != null) { hits.getAndIncrement(); @@ -162,6 +165,8 @@ else if (inB1) { b2.remove(key); t2.put(key, new CarValue(value)); } + } finally { + lock.unlock(); } return value; @@ -211,32 +216,47 @@ private void replace() { * @see org.glassfish.hk2.utilities.cache.WeakCARCache#getKeySize() */ @Override - public synchronized int getKeySize() { - return t1.size() + t2.size() + b1.size() + b2.size(); + public int getKeySize() { + lock.lock(); + try { + return t1.size() + t2.size() + b1.size() + b2.size(); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.utilities.cache.WeakCARCache#getValueSize() */ @Override - public synchronized int getValueSize() { - return t1.size() + t2.size(); + public int getValueSize() { + lock.lock(); + try { + return t1.size() + t2.size(); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.utilities.cache.WeakCARCache#clear() */ @Override - public synchronized void clear() { - t1.clear(); - t2.clear(); - b1.clear(); - b2.clear(); - - p = 0; - - tries.set(0); - hits.set(0); + public void clear() { + lock.lock(); + try { + t1.clear(); + t2.clear(); + b1.clear(); + b2.clear(); + + p = 0; + + tries.set(0); + hits.set(0); + } finally { + lock.unlock(); + } } /* (non-Javadoc) @@ -259,44 +279,59 @@ public Computable getComputable() { * @see org.glassfish.hk2.utilities.cache.WeakCARCache#remove(java.lang.Object) */ @Override - public synchronized boolean remove(K key) { - if (t1.remove(key) == null) { - if (t2.remove(key) == null) { - if (!b1.remove(key)) { - return b2.remove(key); + public boolean remove(K key) { + lock.lock(); + try { + if (t1.remove(key) == null) { + if (t2.remove(key) == null) { + if (!b1.remove(key)) { + return b2.remove(key); + } + + return true; } return true; } return true; + } finally { + lock.unlock(); } - - return true; } /* (non-Javadoc) * @see org.glassfish.hk2.utilities.cache.WeakCARCache#releaseMatching(org.glassfish.hk2.utilities.cache.CacheKeyFilter) */ @Override - public synchronized void releaseMatching(CacheKeyFilter filter) { - if (filter == null) return; - - b2.releaseMatching(filter); - b1.releaseMatching(filter); - t1.releaseMatching(filter); - t2.releaseMatching(filter); + public void releaseMatching(CacheKeyFilter filter) { + lock.lock(); + try { + if (filter == null) return; + + b2.releaseMatching(filter); + b1.releaseMatching(filter); + t1.releaseMatching(filter); + t2.releaseMatching(filter); + } finally { + lock.unlock(); + } } /* (non-Javadoc) * @see org.glassfish.hk2.utilities.cache.WeakCARCache#clearStaleReferences() */ @Override - public synchronized void clearStaleReferences() { - t1.clearStaleReferences(); - t2.clearStaleReferences(); - b1.clearStaleReferences(); - b2.clearStaleReferences(); + public void clearStaleReferences() { + lock.lock(); + try { + t1.clearStaleReferences(); + t2.clearStaleReferences(); + b1.clearStaleReferences(); + b2.clearStaleReferences(); + } finally { + lock.unlock(); + } } private static class CarValue { diff --git a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/ValidatorUtilities.java b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/ValidatorUtilities.java index 2e02f2a0cb..804d49fb54 100755 --- a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/ValidatorUtilities.java +++ b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/ValidatorUtilities.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -19,6 +19,7 @@ import java.lang.annotation.ElementType; import java.security.AccessController; import java.security.PrivilegedAction; +import java.util.concurrent.locks.ReentrantLock; import jakarta.validation.Path; import jakarta.validation.TraversableResolver; @@ -36,6 +37,7 @@ * */ public class ValidatorUtilities { + private static final ReentrantLock slock = new ReentrantLock(); private static final TraversableResolver TRAVERSABLE_RESOLVER = new TraversableResolver() { public boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class rootBeanType, @@ -76,23 +78,28 @@ private static Validator initializeValidator() { * * @return A jakarta bean validator for validating constraints */ - public synchronized static Validator getValidator() { - if (validator == null) { - validator = AccessController.doPrivileged(new PrivilegedAction() { - - @Override - public Validator run() { - return initializeValidator(); - } - - }); - } - - if (validator == null) { - throw new IllegalStateException("Could not find a jakarta.validator"); + public static Validator getValidator() { + slock.lock(); + try { + if (validator == null) { + validator = AccessController.doPrivileged(new PrivilegedAction() { + + @Override + public Validator run() { + return initializeValidator(); + } + + }); + } + + if (validator == null) { + throw new IllegalStateException("Could not find a jakarta.validator"); + } + + return validator; + } finally { + slock.unlock(); } - - return validator; } } diff --git a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/internal/WeakHashClockImpl.java b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/internal/WeakHashClockImpl.java index e67822d1b5..8c54a9858c 100755 --- a/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/internal/WeakHashClockImpl.java +++ b/hk2-utils/src/main/java/org/glassfish/hk2/utilities/general/internal/WeakHashClockImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -22,6 +22,7 @@ import java.util.Map.Entry; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.ReentrantLock; import org.glassfish.hk2.utilities.cache.CacheKeyFilter; import org.glassfish.hk2.utilities.general.WeakHashClock; @@ -36,7 +37,8 @@ public class WeakHashClockImpl implements WeakHashClock { private final boolean isWeak; private final ConcurrentHashMap> byKeyNotWeak; private final WeakHashMap> byKey; - + + private final ReentrantLock lock = new ReentrantLock(); private final ReferenceQueue myQueue = new ReferenceQueue(); private DoubleNode head; @@ -117,7 +119,8 @@ private void removeFromDLL(DoubleNode removeMe) { public void put(final K key, final V value) { if (key == null || value == null) throw new IllegalArgumentException("key " + key + " or value " + value + " is null"); - synchronized (this) { + lock.lock(); + try { if (isWeak) { removeStale(); } @@ -130,6 +133,8 @@ public void put(final K key, final V value) { else { byKeyNotWeak.put(key, addMe); } + } finally { + lock.unlock(); } } @@ -142,10 +147,13 @@ public V get(K key) { DoubleNode node; if (isWeak) { - synchronized (this) { + lock.lock(); + try { removeStale(); node = byKey.get(key); + } finally { + lock.unlock(); } } else { @@ -164,7 +172,8 @@ public V get(K key) { public V remove(K key) { if (key == null) return null; - synchronized (this) { + lock.lock(); + try { DoubleNode node; if (isWeak) { removeStale(); @@ -180,6 +189,8 @@ public V remove(K key) { removeFromDLL(node); return node.getValue(); + } finally { + lock.unlock(); } } @@ -187,26 +198,31 @@ public V remove(K key) { * @see org.glassfish.hk2.utilities.general.WeakHashClock#releaseMatching(org.glassfish.hk2.utilities.cache.CacheKeyFilter) */ @Override - public synchronized void releaseMatching(CacheKeyFilter filter) { - if (filter == null) return; - - if (isWeak) { - removeStale(); - } - - LinkedList removeMe = new LinkedList(); - DoubleNode current = head; - while (current != null) { - K key = current.getWeakKey().get(); - if (key != null && filter.matches(key)) { - removeMe.add(key); + public void releaseMatching(CacheKeyFilter filter) { + lock.lock(); + try { + if (filter == null) return; + + if (isWeak) { + removeStale(); } - current = current.getNext(); - } - - for (K removeKey : removeMe) { - remove(removeKey); + LinkedList removeMe = new LinkedList(); + DoubleNode current = head; + while (current != null) { + K key = current.getWeakKey().get(); + if (key != null && filter.matches(key)) { + removeMe.add(key); + } + + current = current.getNext(); + } + + for (K removeKey : removeMe) { + remove(removeKey); + } + } finally { + lock.unlock(); } } @@ -216,10 +232,13 @@ public synchronized void releaseMatching(CacheKeyFilter filter) { @Override public int size() { if (isWeak) { - synchronized (this) { + lock.lock(); + try { removeStale(); return byKey.size(); + } finally { + lock.unlock(); } } @@ -257,36 +276,41 @@ private DoubleNode moveDotNoWeak() { * @see org.glassfish.hk2.utilities.general.WeakHashClock#next() */ @Override - public synchronized Entry next() { - DoubleNode hardenedNode = moveDotNoWeak(); - if (hardenedNode == null) return null; + public Entry next() { + lock.lock(); try { - final K key = hardenedNode.getHardenedKey(); - final V value = hardenedNode.getValue(); - - return new Map.Entry() { + DoubleNode hardenedNode = moveDotNoWeak(); + if (hardenedNode == null) return null; + try { + final K key = hardenedNode.getHardenedKey(); + final V value = hardenedNode.getValue(); + + return new Map.Entry() { - @Override - public K getKey() { - return key; - } + @Override + public K getKey() { + return key; + } - @Override - public V getValue() { - return value; - } + @Override + public V getValue() { + return value; + } - @Override - public V setValue(V value) { - throw new AssertionError("not implemented"); - } + @Override + public V setValue(V value) { + throw new AssertionError("not implemented"); + } + + }; + } + finally { + hardenedNode.setHardenedKey(null); - }; - } - finally { - hardenedNode.setHardenedKey(null); - - removeStale(); + removeStale(); + } + } finally { + lock.unlock(); } } @@ -294,23 +318,33 @@ public V setValue(V value) { * @see org.glassfish.hk2.utilities.general.WeakHashClock#clear() */ @Override - public synchronized void clear() { - if (isWeak) { - byKey.clear(); - } - else { - byKeyNotWeak.clear(); + public void clear() { + lock.lock(); + try { + if (isWeak) { + byKey.clear(); + } + else { + byKeyNotWeak.clear(); + } + + head = tail = dot = null; + } finally { + lock.unlock(); } - - head = tail = dot = null; } /* (non-Javadoc) * @see org.glassfish.hk2.utilities.general.WeakHashClock#clearStaleReferences() */ @Override - public synchronized void clearStaleReferences() { - removeStale(); + public void clearStaleReferences() { + lock.lock(); + try { + removeStale(); + } finally { + lock.unlock(); + } } private void removeStale() { @@ -342,32 +376,37 @@ public boolean hasWeakKeys() { } @Override - public synchronized String toString() { - StringBuffer sb = new StringBuffer("WeakHashClockImpl({"); - - boolean first = true; - DoubleNode current = dot; - if (current != null) { - do { - K key = current.getWeakKey().get(); - String keyString = (key == null) ? "null" : key.toString(); + public String toString() { + lock.lock(); + try { + StringBuffer sb = new StringBuffer("WeakHashClockImpl({"); - if (first) { - first = false; + boolean first = true; + DoubleNode current = dot; + if (current != null) { + do { + K key = current.getWeakKey().get(); + String keyString = (key == null) ? "null" : key.toString(); - sb.append(keyString); - } - else { - sb.append("," + keyString); - } + if (first) { + first = false; + + sb.append(keyString); + } + else { + sb.append("," + keyString); + } + + current = current.getNext(); + if (current == null) current = head; + } while (current != dot); + } - current = current.getNext(); - if (current == null) current = head; - } while (current != dot); + sb.append("}," + System.identityHashCode(this) + ")"); + + return sb.toString(); + } finally { + lock.unlock(); } - - sb.append("}," + System.identityHashCode(this) + ")"); - - return sb.toString(); } } diff --git a/spring-bridge/src/main/java/org/jvnet/hk2/spring/bridge/api/SpringScopeImpl.java b/spring-bridge/src/main/java/org/jvnet/hk2/spring/bridge/api/SpringScopeImpl.java index 91420abcd5..31f0d823ba 100755 --- a/spring-bridge/src/main/java/org/jvnet/hk2/spring/bridge/api/SpringScopeImpl.java +++ b/spring-bridge/src/main/java/org/jvnet/hk2/spring/bridge/api/SpringScopeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,6 +16,8 @@ package org.jvnet.hk2.spring.bridge.api; +import java.util.concurrent.locks.ReentrantLock; + import org.glassfish.hk2.api.ActiveDescriptor; import org.glassfish.hk2.api.ServiceHandle; import org.glassfish.hk2.api.ServiceLocator; @@ -29,14 +31,20 @@ * */ public class SpringScopeImpl implements Scope { + private final ReentrantLock lock = new ReentrantLock(); private ServiceLocator locator; /** * Sets the service locator to use with this scope * @param locator The (non-null) locator to use for this scope */ - public synchronized void setServiceLocator(ServiceLocator locator) { - this.locator = locator; + public void setServiceLocator(ServiceLocator locator) { + lock.lock(); + try { + this.locator = locator; + } finally { + lock.unlock(); + } } /** @@ -46,8 +54,13 @@ public synchronized void setServiceLocator(ServiceLocator locator) { * @param name The name to be used. If null an anonymous service * locator will be used */ - public synchronized void setServiceLocatorName(String name) { - locator = ServiceLocatorFactory.getInstance().create(name); + public void setServiceLocatorName(String name) { + lock.lock(); + try { + locator = ServiceLocatorFactory.getInstance().create(name); + } finally { + lock.unlock(); + } } /** @@ -56,18 +69,28 @@ public synchronized void setServiceLocatorName(String name) { * * @return The {@link ServiceLocator} to be used with this scope */ - public synchronized ServiceLocator getServiceLocator() { - return locator; + public ServiceLocator getServiceLocator() { + lock.lock(); + try { + return locator; + } finally { + lock.unlock(); + } } - private synchronized ServiceHandle getServiceFromName(String id) { - if (locator == null) throw new IllegalStateException( - "ServiceLocator must be set"); - - ActiveDescriptor best = locator.getBestDescriptor(BuilderHelper.createTokenizedFilter(id)); - if (best == null) return null; - - return locator.getServiceHandle(best); + private ServiceHandle getServiceFromName(String id) { + lock.lock(); + try { + if (locator == null) throw new IllegalStateException( + "ServiceLocator must be set"); + + ActiveDescriptor best = locator.getBestDescriptor(BuilderHelper.createTokenizedFilter(id)); + if (best == null) return null; + + return locator.getServiceHandle(best); + } finally { + lock.unlock(); + } } /* (non-Javadoc) From d9a6c05ca8a956999bc542a3e56d1d34a28ca8a8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 02:45:26 +0000 Subject: [PATCH 09/10] Bump org.springframework:spring-context from 6.1.3 to 6.1.4 Bumps [org.springframework:spring-context](https://github.com/spring-projects/spring-framework) from 6.1.3 to 6.1.4. - [Release notes](https://github.com/spring-projects/spring-framework/releases) - [Commits](https://github.com/spring-projects/spring-framework/compare/v6.1.3...v6.1.4) --- updated-dependencies: - dependency-name: org.springframework:spring-context dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 38d4418845..d9eaa19b23 100644 --- a/pom.xml +++ b/pom.xml @@ -173,7 +173,7 @@ 6.0.0 3.1.0 1.7.0 - 6.1.3 + 6.1.4 7.0.0 3.25.2 From 6d0e1900667bc96b8cc9fb5546c9ed5808a8da14 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 08:54:58 +0000 Subject: [PATCH 10/10] Bump com.google.protobuf:protobuf-java from 3.25.2 to 3.25.3 Bumps [com.google.protobuf:protobuf-java](https://github.com/protocolbuffers/protobuf) from 3.25.2 to 3.25.3. - [Release notes](https://github.com/protocolbuffers/protobuf/releases) - [Changelog](https://github.com/protocolbuffers/protobuf/blob/main/protobuf_release.bzl) - [Commits](https://github.com/protocolbuffers/protobuf/compare/v3.25.2...v3.25.3) --- updated-dependencies: - dependency-name: com.google.protobuf:protobuf-java dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d9eaa19b23..a991e45966 100644 --- a/pom.xml +++ b/pom.xml @@ -175,7 +175,7 @@ 1.7.0 6.1.4 7.0.0 - 3.25.2 + 3.25.3 ${maven.multiModuleProjectDirectory}/