You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by dj...@apache.org on 2011/06/05 19:47:34 UTC
svn commit: r1132463 - in
/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving:
AbstractWovenProxyAdapter.java WovenProxyGenerator.java
Author: djencks
Date: Sun Jun 5 17:47:33 2011
New Revision: 1132463
URL: http://svn.apache.org/viewvc?rev=1132463&view=rev
Log:
ARIES-669 mark SerialVersionUID and static_init_foo methods synthetic
Modified:
aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/AbstractWovenProxyAdapter.java
aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyGenerator.java
Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/AbstractWovenProxyAdapter.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/AbstractWovenProxyAdapter.java?rev=1132463&r1=1132462&r2=1132463&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/AbstractWovenProxyAdapter.java (original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/AbstractWovenProxyAdapter.java Sun Jun 5 17:47:33 2011
@@ -172,7 +172,7 @@ abstract class AbstractWovenProxyAdapter
ClassLoader loader) {
// We wrap the writer in a StaticInitMerger so we don't have to worry about
// our generated static init clashing with an existing one!
- super(new StaticInitMerger("static_init_" + UU_ID, writer));
+ super(new MyStaticInitMerger("static_init_" + UU_ID, writer));
typeBeingWoven = Type.getType("L" + className.replace('.', '/') + ";");
this.loader = loader;
}
@@ -520,7 +520,7 @@ abstract class AbstractWovenProxyAdapter
methodStaticFieldName, METHOD_TYPE.getDescriptor(), null, null)
.visitEnd();
}
- GeneratorAdapter staticAdapter = new GeneratorAdapter(ACC_STATIC,
+ GeneratorAdapter staticAdapter = new GeneratorAdapter(ACC_STATIC | ACC_SYNTHETIC,
new Method("<clinit>", Type.VOID_TYPE, NO_ARGS), null, null, cv);
for (Entry<String, TypeMethod> entry : transformedMethods.entrySet()) {
@@ -609,7 +609,7 @@ abstract class AbstractWovenProxyAdapter
* Get a generator for a method, this be annotated with the "invisibility"
* annotations (and ensured synthetic)
*
- * @param methodSignature
+ * @param method
* @return
*/
private final GeneratorAdapter getMethodGenerator(int access, Method method) {
@@ -620,4 +620,95 @@ abstract class AbstractWovenProxyAdapter
ga.visitCode();
return ga;
}
+
+ /**
+ * This is a copy of the asm StaticInitMerger class modified
+ * to mark the generated static init method synthetic
+ */
+ /***
+ * ASM: a very small and fast Java bytecode manipulation framework
+ * Copyright (c) 2000-2007 INRIA, France Telecom
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+ public static class MyStaticInitMerger extends ClassAdapter {
+
+ private String name;
+
+ private MethodVisitor clinit;
+
+ private final String prefix;
+
+ private int counter;
+
+ public MyStaticInitMerger(final String prefix, final ClassVisitor cv) {
+ super(cv);
+ this.prefix = prefix;
+ }
+
+ public void visit(
+ final int version,
+ final int access,
+ final String name,
+ final String signature,
+ final String superName,
+ final String[] interfaces) {
+ cv.visit(version, access, name, signature, superName, interfaces);
+ this.name = name;
+ }
+
+ public MethodVisitor visitMethod(
+ final int access,
+ final String name,
+ final String desc,
+ final String signature,
+ final String[] exceptions) {
+ MethodVisitor mv;
+ if ("<clinit>".equals(name)) {
+ int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC;
+ String n = prefix + counter++;
+ mv = cv.visitMethod(a, n, desc, signature, exceptions);
+
+ if (clinit == null) {
+ clinit = cv.visitMethod(a, name, desc, null, null);
+ }
+ clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc);
+ } else {
+ mv = cv.visitMethod(access, name, desc, signature, exceptions);
+ }
+ return mv;
+ }
+
+ public void visitEnd() {
+ if (clinit != null) {
+ clinit.visitInsn(Opcodes.RETURN);
+ clinit.visitMaxs(0, 0);
+ }
+ cv.visitEnd();
+ }
+ }
+
}
\ No newline at end of file
Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyGenerator.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyGenerator.java?rev=1132463&r1=1132462&r2=1132463&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyGenerator.java (original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyGenerator.java Sun Jun 5 17:47:33 2011
@@ -24,10 +24,7 @@ import static org.objectweb.asm.Opcodes.
import java.math.BigDecimal;
-import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.ClassVisitor;
-import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.*;
import org.objectweb.asm.commons.SerialVersionUIDAdder;
/**
@@ -51,11 +48,51 @@ public final class WovenProxyGenerator
ClassVisitor weavingAdapter = new WovenProxyAdapter(cWriter, className, loader);
//Wrap our outer layer to add the original SerialVersionUID if it was previously being defaulted
- weavingAdapter = new SerialVersionUIDAdder(weavingAdapter);
+ weavingAdapter = new MySerialVersionUIDAdder(weavingAdapter);
// If we are Java 1.6 + then we need to skip frames as they will be recomputed
cReader.accept(weavingAdapter, IS_AT_LEAST_JAVA_6 ? ClassReader.SKIP_FRAMES : 0);
return cWriter.toByteArray();
}
-}
\ No newline at end of file
+
+ /**
+ * same as the ASM class it extends except marks the new SerialVersionUID filed synthetic
+ */
+ private static class MySerialVersionUIDAdder extends SerialVersionUIDAdder {
+ /**
+ * Creates a new {@link org.objectweb.asm.commons.SerialVersionUIDAdder}.
+ *
+ * @param cv a {@link org.objectweb.asm.ClassVisitor} to which this visitor will delegate
+ * calls.
+ */
+ public MySerialVersionUIDAdder(ClassVisitor cv) {
+ super(cv);
+ }
+
+ /*
+ * Add the SVUID if class doesn't have one
+ */
+ public void visitEnd() {
+ // compute SVUID and add it to the class
+ if (computeSVUID && !hasSVUID) {
+ try {
+ cv.visitField(Opcodes.ACC_FINAL + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC,
+ "serialVersionUID",
+ "J",
+ null,
+ new Long(computeSVUID()));
+ } catch (Throwable e) {
+ throw new RuntimeException("Error while computing SVUID for "
+ + name, e);
+ }
+ }
+ computeSVUID = false;
+ super.visitEnd();
+ }
+
+
+ }
+
+
+}