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 2020/07/09 08:56:35 UTC
[groovy] 01/01: Remove `GroovyClassValuePreJava7`
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9631
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit a043b37833c68e0c63a90af00b09c72f8a458008
Author: Daniel Sun <su...@apache.org>
AuthorDate: Thu Jul 9 16:55:20 2020 +0800
Remove `GroovyClassValuePreJava7`
---
.../groovy/reflection/GroovyClassValueFactory.java | 6 +-
.../reflection/GroovyClassValuePreJava7.java | 106 ---------------------
.../groovy/util/AbstractConcurrentMap.java | 2 +-
.../groovy/util/AbstractConcurrentMapBase.java | 8 +-
.../codehaus/groovy/util/ManagedConcurrentMap.java | 2 +-
5 files changed, 6 insertions(+), 118 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/reflection/GroovyClassValueFactory.java b/src/main/java/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
index 0565f92..cbc047f 100644
--- a/src/main/java/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
+++ b/src/main/java/org/codehaus/groovy/reflection/GroovyClassValueFactory.java
@@ -29,11 +29,7 @@ class GroovyClassValueFactory {
* See https://bugs.openjdk.java.net/browse/JDK-8136353
* This issue does not exist on IBM Java (J9) so use ClassValue by default on that JVM.
*/
- private static final boolean USE_CLASSVALUE = Boolean.parseBoolean(SystemUtil.getSystemPropertySafe("groovy.use.classvalue", "true"));
-
public static <T> GroovyClassValue<T> createGroovyClassValue(ComputeValue<T> computeValue) {
- return (USE_CLASSVALUE)
- ? new GroovyClassValueJava7<>(computeValue)
- : new GroovyClassValuePreJava7<>(computeValue);
+ return new GroovyClassValueJava7<>(computeValue);
}
}
diff --git a/src/main/java/org/codehaus/groovy/reflection/GroovyClassValuePreJava7.java b/src/main/java/org/codehaus/groovy/reflection/GroovyClassValuePreJava7.java
deleted file mode 100644
index 02f893c..0000000
--- a/src/main/java/org/codehaus/groovy/reflection/GroovyClassValuePreJava7.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.reflection;
-
-import org.codehaus.groovy.util.Finalizable;
-import org.codehaus.groovy.util.ManagedConcurrentMap;
-import org.codehaus.groovy.util.ReferenceBundle;
-
-/** Approximation of Java 7's {@link java.lang.ClassValue} that works on earlier versions of Java.
- * Note that this implementation isn't as good at Java 7's; it doesn't allow for some GC'ing that Java 7 would allow.
- * But, it's good enough for our use.
- *
- * @param <T>
- */
-class GroovyClassValuePreJava7<T> implements GroovyClassValue<T> {
- private static final ReferenceBundle weakBundle = ReferenceBundle.getWeakBundle();
-
- private class EntryWithValue extends ManagedConcurrentMap.EntryWithValue<Class<?>,T>{
-
- public EntryWithValue(GroovyClassValuePreJava7Segment segment, Class<?> key, int hash) {
- super(weakBundle, segment, key, hash, computeValue.computeValue(key));
- }
-
- @Override
- public void setValue(T value) {
- if(value!=null) super.setValue(value);
- }
-
- @Override
- public void finalizeReference() {
- T value = getValue();
- if (value instanceof Finalizable) {
- ((Finalizable) value).finalizeReference();
- }
- super.finalizeReference();
- }
- }
-
- private class GroovyClassValuePreJava7Segment extends ManagedConcurrentMap.Segment<Class<?>,T> {
-
- private static final long serialVersionUID = 1289753977947029168L;
-
- GroovyClassValuePreJava7Segment(ReferenceBundle bundle, int initialCapacity) {
- super(bundle, initialCapacity);
- }
-
- @Override
- protected EntryWithValue createEntry(Class<?> key, int hash,
- T unused) {
- return new EntryWithValue(this, key, hash);
- }
- }
-
- private class GroovyClassValuePreJava7Map extends ManagedConcurrentMap<Class<?>,T> {
-
- public GroovyClassValuePreJava7Map() {
- super(weakBundle);
- }
-
- @Override
- protected GroovyClassValuePreJava7Segment createSegment(Object segmentInfo, int cap) {
- ReferenceBundle bundle = (ReferenceBundle) segmentInfo;
- if (bundle==null) throw new IllegalArgumentException("bundle must not be null ");
- return new GroovyClassValuePreJava7Segment(bundle, cap);
- }
-
- }
-
- private final ComputeValue<T> computeValue;
-
- private final GroovyClassValuePreJava7Map map = new GroovyClassValuePreJava7Map();
-
- public GroovyClassValuePreJava7(ComputeValue<T> computeValue){
- this.computeValue = computeValue;
- }
-
- @Override
- public T get(Class<?> type) {
- // the value isn't use in the getOrPut call - see the EntryWithValue constructor above
- T value = ((EntryWithValue)map.getOrPut(type, null)).getValue();
- //all entries are guaranteed to be EntryWithValue. Value can only be null if computeValue returns null
- return value;
- }
-
- @Override
- public void remove(Class<?> type) {
- map.remove(type);
- }
-
-}
diff --git a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
index 6168877..66ccc34 100644
--- a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
+++ b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMap.java
@@ -20,7 +20,7 @@ package org.codehaus.groovy.util;
public abstract class AbstractConcurrentMap<K, V> extends AbstractConcurrentMapBase {
- public AbstractConcurrentMap(Object segmentInfo) {
+ public AbstractConcurrentMap(ReferenceBundle segmentInfo) {
super(segmentInfo);
}
diff --git a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java
index 01f84af..ba66374 100644
--- a/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java
+++ b/src/main/java/org/codehaus/groovy/util/AbstractConcurrentMapBase.java
@@ -21,15 +21,13 @@ package org.codehaus.groovy.util;
import java.util.Collection;
import java.util.LinkedList;
-public abstract class AbstractConcurrentMapBase {
+public abstract class AbstractConcurrentMapBase<K, V> {
protected static final int MAXIMUM_CAPACITY = 1 << 30;
- static final int MAX_SEGMENTS = 1 << 16;
- static final int RETRIES_BEFORE_LOCK = 2;
final int segmentMask;
final int segmentShift;
protected final Segment[] segments;
- public AbstractConcurrentMapBase(Object segmentInfo) {
+ public AbstractConcurrentMapBase(ReferenceBundle segmentInfo) {
int sshift = 0;
int ssize = 1;
while (ssize < 16) {
@@ -51,7 +49,7 @@ public abstract class AbstractConcurrentMapBase {
this.segments[i] = createSegment(segmentInfo, cap);
}
- protected abstract Segment createSegment(Object segmentInfo, int cap);
+ protected abstract Segment createSegment(ReferenceBundle segmentInfo, int cap);
protected static <K> int hash(K key) {
int h = System.identityHashCode(key);
diff --git a/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java b/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java
index d1cf760..fb2bb11 100644
--- a/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java
+++ b/src/main/java/org/codehaus/groovy/util/ManagedConcurrentMap.java
@@ -26,7 +26,7 @@ public class ManagedConcurrentMap<K,V> extends AbstractConcurrentMap<K,V> {
if (bundle==null) throw new IllegalArgumentException("bundle must not be null");
}
- protected Segment<K,V> createSegment(Object segmentInfo, int cap) {
+ protected Segment<K,V> createSegment(ReferenceBundle segmentInfo, int cap) {
ReferenceBundle bundle = (ReferenceBundle) segmentInfo;
if (bundle==null) throw new IllegalArgumentException("bundle must not be null");
return new ManagedConcurrentMap.Segment<K,V>(bundle, cap);