This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new c232ca2889 GROOVY-9742: GroovyClassLoader.parseClass()
StampedCommonCache.getAndPut() hang (additional flexibility)
c232ca2889 is described below
commit c232ca28898876dd4dd6db31e34510bffc86ee50
Author: Paul King <[email protected]>
AuthorDate: Fri Apr 11 21:02:19 2025 +1000
GROOVY-9742: GroovyClassLoader.parseClass() StampedCommonCache.getAndPut()
hang (additional flexibility)
---
src/main/java/groovy/lang/GroovyClassLoader.java | 3 ++-
.../groovy/runtime/memoize/CommonCache.java | 3 ++-
.../runtime/memoize/ConcurrentCommonCache.java | 3 ++-
.../runtime/memoize/FlexibleEvictableCache.java | 28 ++++++++++++++++++++++
.../groovy/runtime/memoize/StampedCommonCache.java | 3 ++-
5 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/src/main/java/groovy/lang/GroovyClassLoader.java
b/src/main/java/groovy/lang/GroovyClassLoader.java
index 05f5b09790..1c98269766 100644
--- a/src/main/java/groovy/lang/GroovyClassLoader.java
+++ b/src/main/java/groovy/lang/GroovyClassLoader.java
@@ -37,6 +37,7 @@ import org.codehaus.groovy.runtime.IOGroovyMethods;
import org.codehaus.groovy.runtime.InvokerHelper;
import org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache;
import org.codehaus.groovy.runtime.memoize.EvictableCache;
+import org.codehaus.groovy.runtime.memoize.FlexibleEvictableCache;
import org.codehaus.groovy.runtime.memoize.UnlimitedConcurrentCache;
import org.codehaus.groovy.util.URLStreams;
import org.objectweb.asm.ClassVisitor;
@@ -99,7 +100,7 @@ public class GroovyClassLoader extends URLClassLoader {
/**
* This cache contains mappings of file name to class. It is used to
bypass compilation.
*/
- protected final ConcurrentCommonCache<String, Class> sourceCache = new
ConcurrentCommonCache<>();
+ protected final FlexibleEvictableCache<String, Class> sourceCache = new
ConcurrentCommonCache<>();
private final CompilerConfiguration config;
private final String sourceEncoding;
diff --git a/src/main/java/org/codehaus/groovy/runtime/memoize/CommonCache.java
b/src/main/java/org/codehaus/groovy/runtime/memoize/CommonCache.java
index 3701f44e31..89a4166250 100644
--- a/src/main/java/org/codehaus/groovy/runtime/memoize/CommonCache.java
+++ b/src/main/java/org/codehaus/groovy/runtime/memoize/CommonCache.java
@@ -38,7 +38,7 @@ import java.util.Set;
* @param <V> type of the values
* @since 2.5.0
*/
-public class CommonCache<K, V> implements EvictableCache<K, V>,
ValueConvertable<V, Object>, Serializable {
+public class CommonCache<K, V> implements FlexibleEvictableCache<K, V>,
ValueConvertable<V, Object>, Serializable {
private static final long serialVersionUID = 934699400232698324L;
/**
* The default load factor
@@ -142,6 +142,7 @@ public class CommonCache<K, V> implements EvictableCache<K,
V>, ValueConvertable
return getAndPut(key, valueProvider, true);
}
+ @Override
public V getAndPut(K key, ValueProvider<? super K, ? extends V>
valueProvider, boolean shouldCache) {
V value = get(key);
if (null != convertValue(value)) {
diff --git
a/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
b/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
index 2f31c62ff2..ed27993ed4 100644
---
a/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
+++
b/src/main/java/org/codehaus/groovy/runtime/memoize/ConcurrentCommonCache.java
@@ -33,7 +33,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
* @since 2.5.0
*/
@ThreadSafe
-public class ConcurrentCommonCache<K, V> implements EvictableCache<K, V>,
ValueConvertable<V, Object>, Serializable {
+public class ConcurrentCommonCache<K, V> implements FlexibleEvictableCache<K,
V>, ValueConvertable<V, Object>, Serializable {
private static final long serialVersionUID = -7352338549333024936L;
private final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock();
@@ -113,6 +113,7 @@ public class ConcurrentCommonCache<K, V> implements
EvictableCache<K, V>, ValueC
return getAndPut(key, valueProvider, true);
}
+ @Override
public V getAndPut(K key, ValueProvider<? super K, ? extends V>
valueProvider, boolean shouldCache) {
V value;
diff --git
a/src/main/java/org/codehaus/groovy/runtime/memoize/FlexibleEvictableCache.java
b/src/main/java/org/codehaus/groovy/runtime/memoize/FlexibleEvictableCache.java
new file mode 100644
index 0000000000..4137d89bba
--- /dev/null
+++
b/src/main/java/org/codehaus/groovy/runtime/memoize/FlexibleEvictableCache.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.runtime.memoize;
+
+/**
+ * An EvictableCache supporting a getAndPut variant with additional control
over caching.
+ *
+ * @since 5.0.0
+ */
+public interface FlexibleEvictableCache<K, V> extends EvictableCache<K, V> {
+ V getAndPut(K key, ValueProvider<? super K, ? extends V> valueProvider,
boolean shouldCache);
+}
diff --git
a/src/main/java/org/codehaus/groovy/runtime/memoize/StampedCommonCache.java
b/src/main/java/org/codehaus/groovy/runtime/memoize/StampedCommonCache.java
index f084321d75..cd989b55b7 100644
--- a/src/main/java/org/codehaus/groovy/runtime/memoize/StampedCommonCache.java
+++ b/src/main/java/org/codehaus/groovy/runtime/memoize/StampedCommonCache.java
@@ -37,7 +37,7 @@ import java.util.concurrent.locks.StampedLock;
* @since 3.0.0
*/
@ThreadSafe
-public class StampedCommonCache<K, V> implements EvictableCache<K, V>,
ValueConvertable<V, Object>, Serializable {
+public class StampedCommonCache<K, V> implements FlexibleEvictableCache<K, V>,
ValueConvertable<V, Object>, Serializable {
private static final long serialVersionUID = 6760742552334555146L;
private final StampedLock sl = new StampedLock();
@@ -115,6 +115,7 @@ public class StampedCommonCache<K, V> implements
EvictableCache<K, V>, ValueConv
return getAndPut(key, valueProvider, true);
}
+ @Override
public V getAndPut(K key, ValueProvider<? super K, ? extends V>
valueProvider, boolean shouldCache) {
V value;