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 2019/05/10 14:53:28 UTC
[groovy] branch master updated (7753124 -> 99ad81a)
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 7753124 GROOVY-9111: Reduce the cost of transforming meta method(closes #925)
new 5e0cef8 GROOVY-9112: Clean bad smell in `GroovyClassLoader`(closes #926)
new b8a5567 Revert "GROOVY-9111: Reduce the cost of transforming meta method(closes #925)"
new 99ad81a Trivial refactoring: Rename variable names and simplify code
The 3 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:
src/main/groovy/groovy/lang/GroovyClassLoader.java | 8 ++--
src/main/groovy/groovy/lang/MetaClassImpl.java | 2 +-
.../groovy/runtime/callsite/CallSiteHelper.java | 7 +---
.../org/codehaus/groovy/vmplugin/VMPlugin.java | 11 ++----
.../org/codehaus/groovy/vmplugin/v5/Java5.java | 12 ++++--
.../org/codehaus/groovy/vmplugin/v9/Java9.java | 43 +++++++++-------------
6 files changed, 37 insertions(+), 46 deletions(-)
[groovy] 02/03: Revert "GROOVY-9111: Reduce the cost of
transforming meta method(closes #925)"
Posted by su...@apache.org.
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
commit b8a5567ead17d90f2951a08b27a76fb3ad52d444
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri May 10 22:43:44 2019 +0800
Revert "GROOVY-9111: Reduce the cost of transforming meta method(closes #925)"
This reverts commit 7753124d
---
src/main/groovy/groovy/lang/MetaClassImpl.java | 2 +-
.../java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java | 7 +------
src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java | 7 ++-----
src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java | 7 +++++++
src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java | 5 +----
5 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/src/main/groovy/groovy/lang/MetaClassImpl.java b/src/main/groovy/groovy/lang/MetaClassImpl.java
index 84c806e..171bf7c 100644
--- a/src/main/groovy/groovy/lang/MetaClassImpl.java
+++ b/src/main/groovy/groovy/lang/MetaClassImpl.java
@@ -1276,7 +1276,7 @@ public class MetaClassImpl implements MetaClass, MutableMetaClass {
}
if (method != null) {
- MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method, () -> MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
+ MetaMethod transformedMetaMethod = CallSiteHelper.transformMetaMethod(this, method, MetaClassHelper.convertToTypeArray(arguments), MetaClassImpl.class);
return transformedMetaMethod.doMethodInvoke(object, arguments);
} else {
return invokePropertyOrMissing(object, methodName, originalArguments, fromInsideClass, isCallToSuper);
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
index 1d6cdef..016c537 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/CallSiteHelper.java
@@ -23,16 +23,11 @@ import groovy.lang.MetaMethod;
import org.codehaus.groovy.vmplugin.VMPlugin;
import org.codehaus.groovy.vmplugin.VMPluginFactory;
-import java.util.function.Supplier;
-
public class CallSiteHelper {
private static final VMPlugin VM_PLUGIN = VMPluginFactory.getPlugin();
public static MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller) {
- return transformMetaMethod(metaClass, metaMethod, () -> params, caller);
+ return VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, params, caller);
}
- public static MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Supplier<Class<?>[]> paramsSupplier, Class<?> caller) {
- return VM_PLUGIN.transformMetaMethod(metaClass, metaMethod, paramsSupplier, caller);
- }
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index 170d5a1..2848615 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -26,7 +26,6 @@ import org.codehaus.groovy.ast.CompileUnit;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Method;
-import java.util.function.Supplier;
/**
* Interface to access VM version based actions.
@@ -89,11 +88,9 @@ public interface VMPlugin {
*
* @param metaClass meta class
* @param metaMethod the original meta method
- * @param paramsSupplier parameter types supplier
+ * @param params parameter types
* @param caller caller type
* @return the transformed meta method
*/
- default MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Supplier<Class<?>[]> paramsSupplier, Class<?> caller) {
- return metaMethod;
- }
+ MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller);
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index 58c6ea3..b8182d1 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -18,6 +18,8 @@
*/
package org.codehaus.groovy.vmplugin.v5;
+import groovy.lang.MetaClass;
+import groovy.lang.MetaMethod;
import org.codehaus.groovy.GroovyBugError;
import org.codehaus.groovy.ast.AnnotatedNode;
import org.codehaus.groovy.ast.AnnotationNode;
@@ -582,6 +584,11 @@ public class Java5 implements VMPlugin {
}
}
+ @Override
+ public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller) {
+ return metaMethod;
+ }
+
private static final Permission ACCESS_PERMISSION = new ReflectPermission("suppressAccessChecks");
}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index c348121..882d900 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -50,7 +50,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
@@ -173,7 +172,7 @@ public class Java9 extends Java8 {
}
@Override
- public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Supplier<Class<?>[]> paramsSupplier, Class<?> caller) {
+ public MetaMethod transformMetaMethod(MetaClass metaClass, MetaMethod metaMethod, Class<?>[] params, Class<?> caller) {
if (!(metaMethod instanceof CachedMethod)) {
return metaMethod;
}
@@ -204,7 +203,6 @@ public class Java9 extends Java8 {
classList.add(theClass);
classList.addAll(superclassList);
- Class<?>[] params = paramsSupplier.get();
for (Class<?> sc : classList) {
Optional<MetaMethod> optionalMetaMethod = getAccessibleMetaMethod(metaMethod, params, caller, sc);
if (optionalMetaMethod.isPresent()) {
@@ -221,7 +219,6 @@ public class Java9 extends Java8 {
// e.g. StringBuilder sb = new StringBuilder(); sb.setLength(0);
// `setLength` is the method of `AbstractStringBuilder`, which is `package-private`
if (declaringClass.isAssignableFrom(theClass)) {
- Class<?>[] params = paramsSupplier.get();
Optional<MetaMethod> optionalMetaMethod = getAccessibleMetaMethod(metaMethod, params, caller, theClass);
if (optionalMetaMethod.isPresent()) {
return optionalMetaMethod.get();
[groovy] 03/03: Trivial refactoring: Rename variable names and
simplify code
Posted by su...@apache.org.
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
commit 99ad81a95ef39d52ee0ee4e36e02018e03be5ac0
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri May 10 22:52:37 2019 +0800
Trivial refactoring: Rename variable names and simplify code
---
.../org/codehaus/groovy/vmplugin/VMPlugin.java | 4 +--
.../org/codehaus/groovy/vmplugin/v5/Java5.java | 5 ++-
.../org/codehaus/groovy/vmplugin/v9/Java9.java | 38 ++++++++++------------
3 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
index 2848615..103d185 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/VMPlugin.java
@@ -67,10 +67,10 @@ public interface VMPlugin {
* Check whether invoking {@link AccessibleObject#setAccessible(boolean)} on the accessible object will be completed successfully
*
* @param accessibleObject the accessible object to check
- * @param caller the caller to invoke {@code setAccessible}
+ * @param callerClass the callerClass to invoke {@code setAccessible}
* @return the check result
*/
- boolean checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> caller);
+ boolean checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> callerClass);
/**
* Set the {@code accessible} flag for this reflected object to {@code true}
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
index b8182d1..56dd1e4 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -547,12 +547,11 @@ public class Java5 implements VMPlugin {
* 2) the accessible object is a Constructor object for the Class class
*
* @param accessibleObject the accessible object to check
- * @param caller the caller to invoke {@code setAccessible}
+ * @param callerClass the callerClass to invoke {@code setAccessible}
* @return the check result
*/
@Override
- public boolean checkCanSetAccessible(AccessibleObject accessibleObject,
- Class<?> caller) {
+ public boolean checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> callerClass) {
SecurityManager sm = System.getSecurityManager();
try {
if (sm != null) {
diff --git a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
index 882d900..f6412f3 100644
--- a/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
+++ b/src/main/java/org/codehaus/groovy/vmplugin/v9/Java9.java
@@ -130,15 +130,14 @@ public class Java9 extends Java8 {
* 4) D is in a package that the module containing D opens to at least the module containing C. All packages in unnamed and open modules are open to all modules and so this method always succeeds when D is in an unnamed or open module.
*
* @param accessibleObject the accessible object to check
- * @param caller the caller to invoke {@code setAccessible}
+ * @param callerClass the callerClass to invoke {@code setAccessible}
* @return the check result
*/
- public boolean checkCanSetAccessible(AccessibleObject accessibleObject,
- Class<?> caller) {
+ public boolean checkCanSetAccessible(AccessibleObject accessibleObject, Class<?> callerClass) {
- if (!super.checkCanSetAccessible(accessibleObject, caller)) return false;
+ if (!super.checkCanSetAccessible(accessibleObject, callerClass)) return false;
- if (caller == MethodHandle.class) {
+ if (callerClass == MethodHandle.class) {
throw new IllegalCallerException(); // should not happen
}
@@ -148,21 +147,18 @@ public class Java9 extends Java8 {
Class<?> declaringClass = ((Member) accessibleObject).getDeclaringClass();
- Module callerModule = caller.getModule();
+ Module callerModule = callerClass.getModule();
Module declaringModule = declaringClass.getModule();
if (callerModule == declaringModule) return true;
if (callerModule == Object.class.getModule()) return true;
if (!declaringModule.isNamed()) return true;
- int modifiers;
- if (accessibleObject instanceof Executable) {
- modifiers = ((Executable) accessibleObject).getModifiers();
- } else {
- modifiers = ((Field) accessibleObject).getModifiers();
- }
+ int modifiers = accessibleObject instanceof Executable
+ ? ((Executable) accessibleObject).getModifiers()
+ : ((Field) accessibleObject).getModifiers();
- return checkAccessible(caller, declaringClass, modifiers, true);
+ return checkAccessible(callerClass, declaringClass, modifiers, true);
}
@@ -243,21 +239,21 @@ public class Java9 extends Java8 {
return optionalMethod.stream().map(CachedMethod::new).collect(Collectors.toList());
}
- private static boolean checkAccessible(Class<?> caller, Class<?> declaringClass, int modifiers, boolean allowIllegalAccess) {
- Module callerModule = caller.getModule();
+ private static boolean checkAccessible(Class<?> callerClass, Class<?> declaringClass, int modifiers, boolean allowIllegalAccess) {
+ Module callerModule = callerClass.getModule();
Module declaringModule = declaringClass.getModule();
String pn = declaringClass.getPackageName();
boolean unnamedModuleAccessNamedModule = !callerModule.isNamed() && declaringModule.isNamed();
boolean toCheckIllegalAccess = !allowIllegalAccess && unnamedModuleAccessNamedModule;
- // class is public and package is exported to caller
+ // class is public and package is exported to callerClass
boolean isClassPublic = Modifier.isPublic(declaringClass.getModifiers());
if (isClassPublic && declaringModule.isExported(pn, callerModule)) {
// member is public
if (Modifier.isPublic(modifiers)) {
if (toCheckIllegalAccess) {
- if (isExportedForIllegalAccess(declaringModule, pn)) return false;
+ return !isExportedForIllegalAccess(declaringModule, pn);
}
return true;
@@ -266,19 +262,19 @@ public class Java9 extends Java8 {
// member is protected-static
if (Modifier.isProtected(modifiers)
&& Modifier.isStatic(modifiers)
- && isSubclassOf(caller, declaringClass)) {
+ && isSubclassOf(callerClass, declaringClass)) {
if (toCheckIllegalAccess) {
- if (isExportedForIllegalAccess(declaringModule, pn)) return false;
+ return !isExportedForIllegalAccess(declaringModule, pn);
}
return true;
}
}
- // package is open to caller
+ // package is open to callerClass
if (declaringModule.isOpen(pn, callerModule)) {
if (toCheckIllegalAccess) {
- if (isOpenedForIllegalAccess(declaringModule, pn)) return false;
+ return !isOpenedForIllegalAccess(declaringModule, pn);
}
return true;
[groovy] 01/03: GROOVY-9112: Clean bad smell in
`GroovyClassLoader`(closes #926)
Posted by su...@apache.org.
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
commit 5e0cef8b89d4ebc5c4f0f2e3cdc394e555225cfa
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri May 10 21:52:42 2019 +0800
GROOVY-9112: Clean bad smell in `GroovyClassLoader`(closes #926)
---
src/main/groovy/groovy/lang/GroovyClassLoader.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/groovy/groovy/lang/GroovyClassLoader.java b/src/main/groovy/groovy/lang/GroovyClassLoader.java
index b270978..ac3b75f 100644
--- a/src/main/groovy/groovy/lang/GroovyClassLoader.java
+++ b/src/main/groovy/groovy/lang/GroovyClassLoader.java
@@ -93,13 +93,13 @@ public class GroovyClassLoader extends URLClassLoader {
/**
* this cache contains the loaded classes or PARSING, if the class is currently parsed
*/
- protected final Map<String, Class> classCache = new UnlimitedConcurrentCache<String, Class>();
+ protected final EvictableCache<String, Class> classCache = new UnlimitedConcurrentCache<String, Class>();
/**
* This cache contains mappings of file name to class. It is used
* to bypass compilation.
*/
- protected final Map<String, Class> sourceCache = new StampedCommonCache<String, Class>();
+ protected final StampedCommonCache<String, Class> sourceCache = new StampedCommonCache<String, Class>();
private final CompilerConfiguration config;
private String sourceEncoding;
@@ -322,7 +322,7 @@ public class GroovyClassLoader extends URLClassLoader {
// and avoid occupying Permanent Area/Metaspace repeatedly
String cacheKey = genSourceCacheKey(codeSource);
- return ((StampedCommonCache<String, Class>) sourceCache).getAndPut(
+ return sourceCache.getAndPut(
cacheKey,
new EvictableCache.ValueProvider<String, Class>() {
@Override
@@ -1157,7 +1157,7 @@ public class GroovyClassLoader extends URLClassLoader {
* @see #removeClassCacheEntry(String)
*/
public void clearCache() {
- Map<String, Class> clearedClasses = ((EvictableCache<String, Class>)classCache).clearAll();
+ Map<String, Class> clearedClasses = classCache.clearAll();
sourceCache.clear();