[openjpa] branch OPENJPA-2817_PCClassFileTransformer-exclusions updated: excluding asm too

2020-07-14 Thread rmannibucau
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch 
OPENJPA-2817_PCClassFileTransformer-exclusions
in repository https://gitbox.apache.org/repos/asf/openjpa.git


The following commit(s) were added to 
refs/heads/OPENJPA-2817_PCClassFileTransformer-exclusions by this push:
 new 96b2b12  excluding asm too
96b2b12 is described below

commit 96b2b128c180089d6999288ade928e6e183ce5da
Author: Romain Manni-Bucau 
AuthorDate: Tue Jul 14 20:25:00 2020 +0200

excluding asm too
---
 .../main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java   | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
 
b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
index 63b4d2e..45d8838 100644
--- 
a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
+++ 
b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
@@ -144,7 +144,8 @@ public class PCClassFileTransformer
 if (className.startsWith("org/apache/")) {
 final String sub = className.substring("org/apache/".length());
 if (sub.startsWith("openjpa/") ||
-sub.startsWith("commons/")) {
+sub.startsWith("commons/") ||
+sub.startsWith("xbean/")) {
 return true;
 }
 }



[openjpa] branch OPENJPA-2817_PCClassFileTransformer-exclusions created (now 763e20c)

2020-07-14 Thread rmannibucau
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a change to branch 
OPENJPA-2817_PCClassFileTransformer-exclusions
in repository https://gitbox.apache.org/repos/asf/openjpa.git.


  at 763e20c  OPENJPA-2817 dropping _transforming from 
PCClassFileTransformer and replace it by a minimal exclusion list

This branch includes the following new commits:

 new 763e20c  OPENJPA-2817 dropping _transforming from 
PCClassFileTransformer and replace it by a minimal exclusion list

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.




[openjpa] 01/01: OPENJPA-2817 dropping _transforming from PCClassFileTransformer and replace it by a minimal exclusion list

2020-07-14 Thread rmannibucau
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch 
OPENJPA-2817_PCClassFileTransformer-exclusions
in repository https://gitbox.apache.org/repos/asf/openjpa.git

commit 763e20c3777be37df7eafc62f3b103d524f51704
Author: Romain Manni-Bucau 
AuthorDate: Tue Jul 14 19:38:48 2020 +0200

OPENJPA-2817 dropping _transforming from PCClassFileTransformer and replace 
it by a minimal exclusion list
---
 .../openjpa/enhance/PCClassFileTransformer.java| 80 +++---
 1 file changed, 55 insertions(+), 25 deletions(-)

diff --git 
a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
 
b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
index 872d413..63b4d2e 100644
--- 
a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
+++ 
b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
@@ -55,7 +55,6 @@ public class PCClassFileTransformer
 private final ClassLoader _tmpLoader;
 private final Log _log;
 private final Set _names;
-private boolean _transforming = false;
 
 /**
  * Constructor.
@@ -107,6 +106,9 @@ public class PCClassFileTransformer
 _log.info(_loc.get("runtime-enhance-pcclasses"));
 }
 
+// this must be called under a proper locking, this is guaranteed by either
+// a correct concurrent classloader with transformation support OR
+// a mono-threaded access guarantee (build, deploy time enhancements).
 @Override
 public byte[] transform(ClassLoader loader, String className,
 Class redef, ProtectionDomain domain, byte[] bytes)
@@ -118,17 +120,43 @@ public class PCClassFileTransformer
 if (className == null) {
 return null;
 }
-// prevent re-entrant calls, which can occur if the enhancing
-// loader is used to also load OpenJPA libraries; this is to prevent
-// recursive enhancement attempts for internal openjpa libraries
-if (_transforming)
-return null;
-
-_transforming = true;
 
 return transform0(className, redef, bytes);
 }
 
+// very simplified flavor of
+// @apache/tomee >
+// container/openejb-core >
+// org/apache/openejb/util/classloader/URLClassLoaderFirst.java#L207
+private boolean isExcluded(final String className) {
+if (// api
+className.startsWith("javax/") ||
+className.startsWith("jakarta/") ||
+// openjpa dependencies
+className.startsWith("serp/") ||
+// jvm
+className.startsWith("java/") ||
+className.startsWith("sun/") ||
+className.startsWith("jdk/")) {
+return true;
+}
+// it is faster to use substring when multiple tests are needed
+if (className.startsWith("org/apache/")) {
+final String sub = className.substring("org/apache/".length());
+if (sub.startsWith("openjpa/") ||
+sub.startsWith("commons/")) {
+return true;
+}
+}
+if (className.startsWith("com/")) {
+final String sub = className.substring("com/".length());
+if (sub.startsWith("oracle/") || sub.startsWith("sun/")) { // jvm
+return true;
+}
+}
+return false;
+}
+
 /**
  * We have to split the transform method into two methods to avoid
  * ClassCircularityError when executing method using pure-JIT JVMs
@@ -151,7 +179,7 @@ public class PCClassFileTransformer
 try {
 PCEnhancer enhancer = new PCEnhancer(_repos.getConfiguration(),
 new Project().loadClass(new 
ByteArrayInputStream(bytes),
-_tmpLoader), _repos);
+_tmpLoader), _repos, _tmpLoader);
 
enhancer.setAddDefaultConstructor(_flags.addDefaultConstructor);
 enhancer.setEnforcePropertyRestrictions
 (_flags.enforcePropertyRestrictions);
@@ -172,7 +200,6 @@ public class PCClassFileTransformer
 throw (IllegalClassFormatException) t;
 throw new GeneralException(t);
 } finally {
-_transforming = false;
 if (returnBytes != null && _log.isTraceEnabled())
 _log.trace(_loc.get("runtime-enhance-complete", className,
 bytes.length, returnBytes.length));
@@ -182,41 +209,44 @@ public class PCClassFileTransformer
 /**
  * Return whether the given class needs enhancement.
  */
-private Boolean needsEnhance(String clsName, Class redef, byte[] bytes) {
-if (redef != null) {
-Class[] intfs = redef.getInterfaces();
+private Boolean needsEnhance(String clsName, Class redef,