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 2021/08/29 04:46:17 UTC

[groovy] branch danielsun/improve-runtime-performance created (now 307e7e6)

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

sunlan pushed a change to branch danielsun/improve-runtime-performance
in repository https://gitbox.apache.org/repos/asf/groovy.git.


      at 307e7e6  Trivial tweak: avoid redundant access permission checking

This branch includes the following new commits:

     new 307e7e6  Trivial tweak: avoid redundant access permission checking

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.


[groovy] 01/01: Trivial tweak: avoid redundant access permission checking

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

sunlan pushed a commit to branch danielsun/improve-runtime-performance
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 307e7e63b86ab16a5d770a8e7cfcc3fc157902ff
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Aug 29 12:46:04 2021 +0800

    Trivial tweak: avoid redundant access permission checking
---
 .../groovy/reflection/CachedConstructor.java       |  7 +++++-
 .../codehaus/groovy/reflection/CachedMethod.java   | 25 ++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java b/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
index 0a4dd85..1546bd4 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedConstructor.java
@@ -115,7 +115,10 @@ public class CachedConstructor extends ParameterTypes {
 
     public Constructor getCachedConstructor() {
         makeAccessibleIfNecessary();
-        AccessPermissionChecker.checkAccessPermission(cachedConstructor);
+        if (!accessAllowed) {
+            AccessPermissionChecker.checkAccessPermission(cachedConstructor);
+            accessAllowed = true;
+        }
         return cachedConstructor;
     }
 
@@ -130,4 +133,6 @@ public class CachedConstructor extends ParameterTypes {
     private boolean isConstructorOfAbstractClass() {
         return Modifier.isAbstract(cachedConstructor.getDeclaringClass().getModifiers());
     }
+
+    private boolean accessAllowed = false;
 }
diff --git a/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java b/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java
index f8aae2d..838db6a 100644
--- a/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java
+++ b/src/main/java/org/codehaus/groovy/reflection/CachedMethod.java
@@ -103,11 +103,15 @@ public class CachedMethod extends MetaMethod implements Comparable {
     public final Object invoke(Object object, Object[] arguments) {
         makeAccessibleIfNecessary();
 
-        try {
-            AccessPermissionChecker.checkAccessPermission(cachedMethod);
-        } catch (CacheAccessControlException ex) {
-            throw new InvokerInvocationException(ex);
+        if (!accessAllowed) {
+            try {
+                AccessPermissionChecker.checkAccessPermission(cachedMethod);
+                accessAllowed = true;
+            } catch (CacheAccessControlException ex) {
+                throw new InvokerInvocationException(ex);
+            }
         }
+
         try {
             return cachedMethod.invoke(object, arguments);
         } catch (IllegalArgumentException | IllegalAccessException e) {
@@ -146,7 +150,11 @@ public class CachedMethod extends MetaMethod implements Comparable {
     public final Method setAccessible() {
         makeAccessibleIfNecessary();
 
-        AccessPermissionChecker.checkAccessPermission(cachedMethod);
+        if (!accessAllowed) {
+            AccessPermissionChecker.checkAccessPermission(cachedMethod);
+            accessAllowed = true;
+        }
+
 //        if (queuedToCompile.compareAndSet(false,true)) {
 //            if (isCompilable())
 //              CompileThread.addMethod(this);
@@ -372,7 +380,10 @@ public class CachedMethod extends MetaMethod implements Comparable {
 
     public Method getCachedMethod() {
         makeAccessibleIfNecessary();
-        AccessPermissionChecker.checkAccessPermission(cachedMethod);
+        if (!accessAllowed) {
+            AccessPermissionChecker.checkAccessPermission(cachedMethod);
+            accessAllowed = true;
+        }
         return cachedMethod;
     }
 
@@ -387,4 +398,6 @@ public class CachedMethod extends MetaMethod implements Comparable {
             makeAccessibleDone = true;
         }
     }
+
+    private boolean accessAllowed = false;
 }