You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "paulk-asert (via GitHub)" <gi...@apache.org> on 2026/08/17 06:38:08 UTC

[PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

paulk-asert opened a new pull request, #2798:
URL: https://github.com/apache/groovy/pull/2798

   …r and DFA-cache-cleaner threads, restore the ClassValue escape hatch
   
   A Groovy copy deployed per webapp (the common Tomcat/WEB-INF/lib topology) permanently pinned its class loader, growing metaspace on every parallel (re)deployment. Three independent pins:
   
   1. PIC-Cleaner: linking any indy call site started a never-terminating daemon thread from CacheableCallSite's static initializer, pinning the defining loader and capturing the creating context's protection domains. Stale PIC entries are now swept inline — both callers already hold the lruCache monitor and the cache is bounded (8), so the sweep is trivial; the groovy.indy.callsite.cleaner.inline flag (GROOVY-12092) is gone along with the thread it toggled, which also removes the parked-thread false positive it existed to avoid.
   
   2. DFA-cache-cleaner: each AtnManager started a never-terminating reference-queue thread whose catch-all swallowed even interrupts. The softly referenced AtnWrapper is a GC canary; its collection is now detected on the parse path when the soft reference reads null, clearing the shared DFA cache at the next parse instead of at GC time — no queue, no thread.
   
   3. java.lang.ClassValue associations on immortal (bootstrap) classes never release their value's class loader (JDK-8136353), so one dynamic dispatch on e.g. String pinned the loader. The groovy.use.classvalue=false escape hatch (present through 4.x, lost in the GROOVY-11520 collections cleanup) is restored, with the fallback rebuilt on ManagedIdentityConcurrentMap (~40 lines) rather than the removed deprecated collections. Default stays ClassValue.
   
   With 1+2 fixed, a dropped loader is collectable either with the flag or with a shutdown sweep over ClassInfo.getAllClassInfo() calling ClassInfo.remove — both verified by classloader-churn harness against the rebuilt jar; out-of-the-box default config still requires one of the two (the JVM bug is not ours to fix).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2798:
URL: https://github.com/apache/groovy/pull/2798#issuecomment-5313222479

   ## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2798?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `78.94737%` with `4 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 70.1412%. Comparing base ([`142130d`](https://app.codecov.io/gh/apache/groovy/commit/142130d38010187a509466c9beafbcbd46fa6100?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`7442977`](https://app.codecov.io/gh/apache/groovy/commit/744297765d7df06801439598eb679cc9e3b16914?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 12 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2798?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...aus/groovy/reflection/GroovyClassValueFactory.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Freflection%2FGroovyClassValueFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3JlZmxlY3Rpb24vR3Jvb3Z5Q2xhc3NWYWx1ZUZhY3RvcnkuamF2YQ==) | 50.0000% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [.../parser/antlr4/internal/atnmanager/AtnManager.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fparser%2Fantlr4%2Finternal%2Fatnmanager%2FAtnManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2dyb292eS9wYXJzZXIvYW50bHI0L2ludGVybmFsL2F0bm1hbmFnZXIvQXRuTWFuYWdlci5qYXZh) | 85.7143% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...codehaus/groovy/vmplugin/v8/CacheableCallSite.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fvmplugin%2Fv8%2FCacheableCallSite.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3ZtcGx1Z2luL3Y4L0NhY2hlYWJsZUNhbGxTaXRlLmphdmE=) | 0.0000% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree graph](https://app.codecov.io/gh/apache/groovy/pull/2798/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #2798        +/-   ##
   ==================================================
   + Coverage     70.1064%   70.1412%   +0.0348%     
   - Complexity      35774      35819        +45     
   ==================================================
     Files            1561       1563         +2     
     Lines          132373     132390        +17     
     Branches        24332      24353        +21     
   ==================================================
   + Hits            92802      92860        +58     
   + Misses          31170      31133        -37     
   + Partials         8401       8397         -4     
   ```
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2798?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...us/groovy/reflection/GroovyClassValueMapBased.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Freflection%2FGroovyClassValueMapBased.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3JlZmxlY3Rpb24vR3Jvb3Z5Q2xhc3NWYWx1ZU1hcEJhc2VkLmphdmE=) | `100.0000% <100.0000%> (ø)` | |
   | [.../parser/antlr4/internal/atnmanager/AtnManager.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fapache%2Fgroovy%2Fparser%2Fantlr4%2Finternal%2Fatnmanager%2FAtnManager.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2dyb292eS9wYXJzZXIvYW50bHI0L2ludGVybmFsL2F0bm1hbmFnZXIvQXRuTWFuYWdlci5qYXZh) | `71.7949% <85.7143%> (+17.9487%)` | :arrow_up: |
   | [...codehaus/groovy/vmplugin/v8/CacheableCallSite.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fvmplugin%2Fv8%2FCacheableCallSite.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3ZtcGx1Z2luL3Y4L0NhY2hlYWJsZUNhbGxTaXRlLmphdmE=) | `96.6667% <0.0000%> (+19.1667%)` | :arrow_up: |
   | [...aus/groovy/reflection/GroovyClassValueFactory.java](https://app.codecov.io/gh/apache/groovy/pull/2798?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Freflection%2FGroovyClassValueFactory.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L3JlZmxlY3Rpb24vR3Jvb3Z5Q2xhc3NWYWx1ZUZhY3RvcnkuamF2YQ==) | `40.0000% <50.0000%> (-10.0000%)` | :arrow_down: |
   
   ... and [14 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2798/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

Posted by "blackdrag (via GitHub)" <gi...@apache.org>.
blackdrag commented on code in PR #2798:
URL: https://github.com/apache/groovy/pull/2798#discussion_r3799723985


##########
src/spec/doc/guide-integrating.adoc:
##########
@@ -378,6 +378,43 @@ stub generation is done, for the joint compiler.
 
 However, overriding `CompilationUnit` is not recommended and should only be done if no other standard solution works.
 
+== Class loader release in managed environments
+
+Applications that load and discard Groovy repeatedly — a web container performing (parallel)
+redeployments with Groovy inside each web application, plugin systems, or any host that expects
+class loaders to be garbage collected — need one extra consideration.
+
+Groovy associates runtime metadata (`ClassInfo`) with every class it dispatches on, including
+JDK classes such as `String`. By default those associations use `java.lang.ClassValue`, which
+gives the fastest possible lookup, but a long-standing JVM issue
+(https://bugs.openjdk.org/browse/JDK-8136353[JDK-8136353]) prevents such associations on
+long-lived classes from ever releasing their value — and with it the Groovy class loader the
+value belongs to. In a container this shows up as metaspace growth on every redeployment, even
+after the old application is undeployed.
+

Review Comment:
   This is fine for the integration guide, so I do not want to block this. 
   
   But for us developers I think that is a bit too short for the complexity of ClassValue. First of all the bug you mentioned has been closed. There are follow-ups, but they are documentation issues, not something to be fixed. in that manner it works as designed.
   
   Think of it like this. With ClassValue we basically realize a chain: `key class - class association -> class value instance -> value`
   Important to note here is that the class of the ClassValue implementation itself does not prevent any unloading. It is different from a static field in the key class for example. Now if we add the value, then there is a strong association between the key class and the value. If the value is for example an empty ArrayList, then it will not prevent the unloading of the classloader for the ClassValue. But if in the Tomcat scenario with Groovy the value class is from Groovy, then the loader for Groovy will be prevented from unloading as long as the key class exists. If the key class is an immortal class like String, then even unloading Tomcat and having had Groovy loaded in an isolated class loader, would still keep that class loader around. 
   The issue mentioned at openjdk.org is actually more complicated than this. Assume we store an ArrayList again, but the element is any instance of a class of that Groovy defining class loader. Then we avoided the class problem for the value, but again got it through one level of indirection. And the real problem in this scenario is that this can be a long chain. The sort formula for Groovy is then, key = Groovy class is fine. key == JDK class, bad. The issue itself was actually for the stored value referencing the ClassValue instance. I put emphasis on the class loader here, because that is actually the case we care about.
   There is  a strategy against that: use a SoftReference for the value of ClassValue. Since the chain is now always broken there would be no issue anymore. Of course then the usage of the ClassValue must fulfill some constraints. Only getting the value no longer works, you have to check the reference and if it did not retain the class value, remove the association and recompute it. That means it must be legal to recompute the value in the first place and the recomputing cost is to be considered.
   
   Based on that I see some potentially problematic parts in Groovy:
   * ClassInfo.globalClassValue -> static + unknown keys -> problem
   * AwaitableAdapterRegistry.awaitableCache -> static + unknown keys -> problem
   * Closure.CALL_OVERRIDES -> should be ok
   
   I think we should investigate the two problems above further. So maybe to not loose this kind of context we create a followup issue?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert merged PR #2798:
URL: https://github.com/apache/groovy/pull/2798


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

Posted by "testlens-app[bot] (via GitHub)" <gi...@apache.org>.
testlens-app[bot] commented on PR #2798:
URL: https://github.com/apache/groovy/pull/2798#issuecomment-5313438592

   ## ✅ All tests passed ✅
   
   🏷️ Commit: 744297765d7df06801439598eb679cc9e3b16914
   ▶️ Tests:  110130 executed
   ⚪️ Checks: 31/31 completed
   
   ---
   _Learn more about TestLens at [testlens.app](https://testlens.app)._
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

Posted by "blackdrag (via GitHub)" <gi...@apache.org>.
blackdrag commented on code in PR #2798:
URL: https://github.com/apache/groovy/pull/2798#discussion_r3809459596


##########
src/spec/doc/guide-integrating.adoc:
##########
@@ -378,6 +378,43 @@ stub generation is done, for the joint compiler.
 
 However, overriding `CompilationUnit` is not recommended and should only be done if no other standard solution works.
 
+== Class loader release in managed environments
+
+Applications that load and discard Groovy repeatedly — a web container performing (parallel)
+redeployments with Groovy inside each web application, plugin systems, or any host that expects
+class loaders to be garbage collected — need one extra consideration.
+
+Groovy associates runtime metadata (`ClassInfo`) with every class it dispatches on, including
+JDK classes such as `String`. By default those associations use `java.lang.ClassValue`, which
+gives the fastest possible lookup, but a long-standing JVM issue
+(https://bugs.openjdk.org/browse/JDK-8136353[JDK-8136353]) prevents such associations on
+long-lived classes from ever releasing their value — and with it the Groovy class loader the
+value belongs to. In a container this shows up as metaspace growth on every redeployment, even
+after the old application is undeployed.
+

Review Comment:
   +1



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] GROOVY-12142: Stop pinning container class loaders: remove PIC-Cleane… [groovy]

Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #2798:
URL: https://github.com/apache/groovy/pull/2798#discussion_r3809315318


##########
src/spec/doc/guide-integrating.adoc:
##########
@@ -378,6 +378,43 @@ stub generation is done, for the joint compiler.
 
 However, overriding `CompilationUnit` is not recommended and should only be done if no other standard solution works.
 
+== Class loader release in managed environments
+
+Applications that load and discard Groovy repeatedly — a web container performing (parallel)
+redeployments with Groovy inside each web application, plugin systems, or any host that expects
+class loaders to be garbage collected — need one extra consideration.
+
+Groovy associates runtime metadata (`ClassInfo`) with every class it dispatches on, including
+JDK classes such as `String`. By default those associations use `java.lang.ClassValue`, which
+gives the fastest possible lookup, but a long-standing JVM issue
+(https://bugs.openjdk.org/browse/JDK-8136353[JDK-8136353]) prevents such associations on
+long-lived classes from ever releasing their value — and with it the Groovy class loader the
+value belongs to. In a container this shows up as metaspace growth on every redeployment, even
+after the old application is undeployed.
+

Review Comment:
   I created:
   
   - GROOVY-12280: AwaitableAdapterRegistry.awaitableCache pins the Groovy class loader via ClassValue associations on platform-class keys
   
   - GROOVY-12281: Investigate mitigating class-loader pinning by ClassInfo.globalClassValue under the default ClassValue implementation
   
   - GROOVY-12282: Document ClassValue usage rules for Groovy developers and record the class-loader-pinning audit



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org