You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/12/04 16:28:49 UTC

[groovy] branch danielsun/tweak-ccs-further updated (1cb0a991d0 -> 66bcf77182)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch danielsun/tweak-ccs-further
in repository https://gitbox.apache.org/repos/asf/groovy.git


 discard 1cb0a991d0 GROOVY-10772: Hold `MethodHandleWrapper` with `SoftReference`
     new 66bcf77182 GROOVY-10772: Hold `MethodHandleWrapper` with `SoftReference`

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (1cb0a991d0)
            \
             N -- N -- N   refs/heads/danielsun/tweak-ccs-further (66bcf77182)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java   | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)


[groovy] 01/01: GROOVY-10772: Hold `MethodHandleWrapper` with `SoftReference`

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/tweak-ccs-further
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 66bcf7718227111333ce078e7f4b7c116ab4f729
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Dec 5 00:16:30 2022 +0800

    GROOVY-10772: Hold `MethodHandleWrapper` with `SoftReference`
---
 .../groovy/vmplugin/v8/CacheableCallSite.java      | 37 ++++++++++------------
 1 file changed, 16 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java b/src/main/java/org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java
index f998dd781e..5f69dd87da 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v8/CacheableCallSite.java
@@ -38,12 +38,12 @@ public class CacheableCallSite extends MutableCallSite {
     private static final int CACHE_SIZE = SystemUtil.getIntegerSafe("groovy.indy.callsite.cache.size", 4);
     private static final float LOAD_FACTOR = 0.75f;
     private static final int INITIAL_CAPACITY = (int) Math.ceil(CACHE_SIZE / LOAD_FACTOR) + 1;
-    private volatile MethodHandleWrapper latestHitMethodHandleWrapper = null;
+    private volatile SoftReference<MethodHandleWrapper> methodHandleWrapperSoftReference = null;
     private final AtomicLong fallbackCount = new AtomicLong();
     private MethodHandle defaultTarget;
     private MethodHandle fallbackTarget;
     private final Map<String, SoftReference<MethodHandleWrapper>> lruCache =
-            new LinkedHashMap<>(INITIAL_CAPACITY, LOAD_FACTOR, true) {
+            new LinkedHashMap<String, SoftReference<MethodHandleWrapper>>(INITIAL_CAPACITY, LOAD_FACTOR, true) {
                 private static final long serialVersionUID = 7785958879964294463L;
 
                 @Override
@@ -58,30 +58,29 @@ public class CacheableCallSite extends MutableCallSite {
 
     public MethodHandleWrapper getAndPut(String className, MemoizeCache.ValueProvider<? super String, ? extends MethodHandleWrapper> valueProvider) {
         MethodHandleWrapper result = null;
+        SoftReference<MethodHandleWrapper> resultSoftReference;
         synchronized (lruCache) {
-            final SoftReference<MethodHandleWrapper> methodHandleWrapperSoftReference = lruCache.get(className);
-            if (null != methodHandleWrapperSoftReference) {
-                result = methodHandleWrapperSoftReference.get();
-
-                if (null == result) {
-                    removeAllStaleEntriesOfLruCache();
-                }
+            resultSoftReference = lruCache.get(className);
+            if (null != resultSoftReference) {
+                result = resultSoftReference.get();
+                if (null == result) removeAllStaleEntriesOfLruCache();
             }
 
             if (null == result) {
                 result = valueProvider.provide(className);
-                lruCache.put(className, new SoftReference<>(result));
+                resultSoftReference = new SoftReference<>(result);
+                lruCache.put(className, resultSoftReference);
             }
         }
-        final MethodHandleWrapper lhmh = latestHitMethodHandleWrapper;
+        final SoftReference<MethodHandleWrapper> mhwsr = methodHandleWrapperSoftReference;
+        final MethodHandleWrapper methodHandleWrapper = null == mhwsr ? null : mhwsr.get();
 
-        if (lhmh == result) {
+        if (methodHandleWrapper == result) {
             result.incrementLatestHitCount();
         } else {
             result.resetLatestHitCount();
-            if (null != lhmh) lhmh.resetLatestHitCount();
-
-            latestHitMethodHandleWrapper = result;
+            if (null != methodHandleWrapper) methodHandleWrapper.resetLatestHitCount();
+            methodHandleWrapperSoftReference = resultSoftReference;
         }
 
         return result;
@@ -91,13 +90,9 @@ public class CacheableCallSite extends MutableCallSite {
         synchronized (lruCache) {
             final SoftReference<MethodHandleWrapper> methodHandleWrapperSoftReference;
             methodHandleWrapperSoftReference = lruCache.put(name, new SoftReference<>(mhw));
-            if (null == methodHandleWrapperSoftReference) {
-                return null;
-            }
+            if (null == methodHandleWrapperSoftReference) return null;
             final MethodHandleWrapper methodHandleWrapper = methodHandleWrapperSoftReference.get();
-            if (null == methodHandleWrapper) {
-                removeAllStaleEntriesOfLruCache();
-            }
+            if (null == methodHandleWrapper) removeAllStaleEntriesOfLruCache();
             return methodHandleWrapper;
         }
     }