commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kohs...@apache.org
Subject svn commit: r359570 - /jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
Date Wed, 28 Dec 2005 17:32:52 GMT
Author: kohsuke
Date: Wed Dec 28 09:32:48 2005
New Revision: 359570

URL: http://svn.apache.org/viewcvs?rev=359570&view=rev
Log:
implemented a minimum workaround to set BCEL Repository object for resolving references correctly.
Still waiting for a response from Torsten about making more substantial changes.


Modified:
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java?rev=359570&r1=359569&r2=359570&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
Wed Dec 28 09:32:48 2005
@@ -27,6 +27,7 @@
 import org.apache.bcel.classfile.JavaClass;
 import org.apache.bcel.classfile.Method;
 import org.apache.bcel.generic.ACONST_NULL;
+import org.apache.bcel.generic.ASTORE;
 import org.apache.bcel.generic.BasicType;
 import org.apache.bcel.generic.ClassGen;
 import org.apache.bcel.generic.ConstantPoolGen;
@@ -50,7 +51,6 @@
 import org.apache.bcel.generic.TABLESWITCH;
 import org.apache.bcel.generic.TargetLostException;
 import org.apache.bcel.generic.Type;
-import org.apache.bcel.generic.ASTORE;
 import org.apache.bcel.verifier.exc.AssertionViolatedException;
 import org.apache.commons.javaflow.bytecode.Continuable;
 import org.apache.commons.javaflow.bytecode.StackRecorder;
@@ -96,6 +96,24 @@
     private boolean currentMethodStatic = false;
     public static boolean debug = false;
 
+    /**
+     * BCEL uses a repository object to load/store information related to other classes,
+     * which are sometimes necessary to perform bytecode instrumentation.
+     * <p>
+     * Can be null, in which case the global BCEL repository is assumed to work.
+     *
+     * <p>
+     * repository is a singleton instance in BCEL, so we have to be careful when changing
it.
+     * See BugZilla 38057. This is fundamentally broken.
+     */
+    private org.apache.bcel.util.Repository repository;
+
+    /**
+     * Since BCEL repository is a global resource, access needs to be controlled among
+     * {@link BcelClassTransformer} instances.
+     */
+    private static final Object repositoryLock = new Object();
+
     static {
         try {
             debug = System.getProperty(BcelClassTransformer.class.getName()+".debug")!=null;
@@ -104,7 +122,30 @@
         }
     }
 
+    public BcelClassTransformer() {
+    }
+
+    public BcelClassTransformer(org.apache.bcel.util.Repository repository) {
+        this.repository = repository;
+    }
+
     public byte[] transform(final byte[] original) {
+        if(repository==null) {
+            return doTransform(original);
+        } else {
+            synchronized(repositoryLock) {
+                org.apache.bcel.util.Repository old = Repository.getRepository();
+                Repository.setRepository(repository);
+                try {
+                    return doTransform(original);
+                } finally {
+                    Repository.setRepository(old);
+                }
+            }
+        }
+    }
+
+    private byte[] doTransform(final byte[] original) {
         
         final InputStream is = new ByteArrayInputStream(original);
         



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message