jamesfredley commented on code in PR #2374:
URL: https://github.com/apache/groovy/pull/2374#discussion_r2752135608
##########
src/main/java/org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java:
##########
@@ -124,4 +124,22 @@ public MethodHandle getFallbackTarget() {
public void setFallbackTarget(MethodHandle fallbackTarget) {
this.fallbackTarget = fallbackTarget;
}
+
+ /**
+ * Clear the cache entirely. Called when metaclass changes to ensure
+ * stale method handles are discarded.
+ * <p>
+ * This method synchronizes on the lruCache to ensure atomicity with
+ * concurrent {@link #getAndPut} operations.
+ */
+ public void clearCache() {
+ // Clear the latest hit reference and the LRU cache atomically
+ synchronized (lruCache) {
+ latestHitMethodHandleWrapperSoftReference = null;
+ lruCache.clear();
+ }
+
Review Comment:
Going back to original code before last change - the synchronization was
inconsistent. Updated in commit 868cfc5714 to keep the volatile field access
outside the synchronized block, consistent with how `getAndPut()` accesses the
same field (lines 75-84). Volatile provides sufficient visibility guarantees
for this field. Added Javadoc explaining this design decision.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]