On Jan 29, 2012, at 2:30 PM, Emily Jiang wrote:
> On Sat, Jan 28, 2012 at 4:36 AM, David Jencks <[email protected]>wrote:
>
>> re SyntheticSerialVerUIDAdder, I like the solution in my patch better
>> since it doesn't require computing the svuid twice which I think yours
>> does. Longer term I've opened
>> http://forge.ow2.org/tracker/index.php?func=detail&aid=316318&group_id=23&atid=350023to
>> try to get asm to support this themselves.
>>
>> Thanks for your observation. From their javadoc, it seems there should be
> a method called isHasSVUID() though. However, the method doesn't exist in
> the class(a bug). I will add a remark on your thread.
>
> protected long computeSVUID()
> throws IOException
> <http://java.sun.com/j2se/1.4.2/docs/api/java/io/IOException.html?is-external=true>
>
> Returns the value of SVUID if the class doesn't have one already. Please
> note that 0 is returned if the class already has SVUID, thus use
> isHasSVUIDto determine if the class already had an SVUID.
>
> I implement this method by using computeSUVID() to work out whether it has
> SVUID and hope to get rid of it once the method is there. Hence I used the
> exactly same signature. I did not find out I computed the svuid twice. Did
> I miss anything?
In the source I have for asm, computeSVUID doesn't cache the result, so calling
it to determine if the result is non-zero results in recalculating the value.
In any case, asm has provided a suitable method to override so we can directly
mark the field synthetic without any testing -- the new method
protected void addSVUID(long svuid) {
FieldVisitor fv = cv.visitField(Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,
"serialVersionUID",
"J",
null,
new Long(svuid));
if (fv != null) {
fv.visitEnd();
}
}
is only called when an SVUID field needs to be added.
thanks
david jencks
>
> Thanks
> Emily
>
> On Jan 27, 2012, at 10:58 AM, [email protected] wrote:
>
>> Author: ejiang
>>> Date: Fri Jan 27 18:58:20 2012
>>> New Revision: 1236823
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1236823&view=rev
>>> Log:
>>> ARIES-817: Upgrade to ASM4
>>>
>>> Added:
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/EmptyVisitor.java
>>> Modified:
>>> aries/trunk/proxy/proxy-impl/pom.xml
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassWriter.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/MethodCopyingClassAdapter.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/WovenProxyGenerator.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java
>>>
>> aries/trunk/proxy/proxy-impl/src/main/resources/org/apache/aries/proxy/nls/ProxyImplMessages.properties
>>>
>> aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
>>>
>>> Modified: aries/trunk/proxy/proxy-impl/pom.xml
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/pom.xml?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> --- aries/trunk/proxy/proxy-impl/pom.xml (original)
>>> +++ aries/trunk/proxy/proxy-impl/pom.xml Fri Jan 27 18:58:20 2012
>>> @@ -70,10 +70,10 @@
>>>
>>> <dependencies>
>>> <dependency>
>>> - <groupId>asm</groupId>
>>> + <groupId>org.ow2.asm</groupId>
>>> <artifactId>asm-all</artifactId>
>>> <optional>true</optional>
>>> - <version>3.2</version>
>>> + <version>4.0</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.slf4j</groupId>
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/AbstractWovenProxyAdapter.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -21,7 +21,6 @@ package org.apache.aries.proxy.impl.comm
>>> import java.io.IOException;
>>> import java.io.InputStream;
>>> import java.io.Serializable;
>>> -import java.lang.reflect.Modifier;
>>> import java.math.BigDecimal;
>>> import java.util.ArrayList;
>>> import java.util.Arrays;
>>> @@ -29,9 +28,9 @@ import java.util.HashMap;
>>> import java.util.HashSet;
>>> import java.util.List;
>>> import java.util.Map;
>>> -import java.util.Map.Entry;
>>> import java.util.Set;
>>> import java.util.UUID;
>>> +import java.util.Map.Entry;
>>> import java.util.concurrent.Callable;
>>>
>>> import org.apache.aries.proxy.InvocationListener;
>>> @@ -39,7 +38,6 @@ import org.apache.aries.proxy.UnableToPr
>>> import org.apache.aries.proxy.impl.NLS;
>>> import org.apache.aries.proxy.impl.gen.Constants;
>>> import org.apache.aries.proxy.weaving.WovenProxy;
>>> -import org.objectweb.asm.ClassAdapter;
>>> import org.objectweb.asm.ClassReader;
>>> import org.objectweb.asm.ClassVisitor;
>>> import org.objectweb.asm.FieldVisitor;
>>> @@ -63,7 +61,7 @@ import org.slf4j.LoggerFactory;
>>> * used to weave classes being loaded by the framework, and
>> InterfaceCombiningClassAdapter
>>> * which is used to dynamically create objects that implement multiple
>> interfaces
>>> */
>>> -public abstract class AbstractWovenProxyAdapter extends ClassAdapter
>> implements Opcodes {
>>> +public abstract class AbstractWovenProxyAdapter extends ClassVisitor
>> implements Opcodes {
>>> private static final Logger LOGGER = LoggerFactory
>>> .getLogger(AbstractWovenProxyAdapter.class);
>>>
>>> @@ -200,7 +198,7 @@ public abstract class AbstractWovenProxy
>>> */
>>> public AbstractWovenProxyAdapter(ClassVisitor writer, String className,
>>> ClassLoader loader) {
>>> - super(writer);
>>> + super(Constants.ASM4, writer);
>>> typeBeingWoven = Type.getType("L" + className.replace('.', '/') +
>> ";");
>>> this.loader = loader;
>>> }
>>> @@ -345,7 +343,7 @@ public abstract class AbstractWovenProxy
>>> //to write our init code to static_init_UUID instead
>>> staticInitMethod = new Method("static_init_" + UU_ID,
>> Type.VOID_TYPE, NO_ARGS);
>>> staticInitMethodFlags = staticInitMethodFlags | ACC_FINAL;
>>> - methodVisitorToReturn = new AdviceAdapter(cv.visitMethod(access,
>> name, desc, signature,
>>> + methodVisitorToReturn = new AdviceAdapter(Constants.ASM4,
>> cv.visitMethod(access, name, desc, signature,
>>> exceptions), access, name, desc){
>>> @Override
>>> protected void onMethodEnter()
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/ConstructorFinder.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -18,14 +18,17 @@
>>> */
>>> package org.apache.aries.proxy.impl.common;
>>>
>>> -import org.objectweb.asm.ClassAdapter;
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> +import org.apache.aries.proxy.impl.weaving.EmptyVisitor;
>>> +
>>> +import org.objectweb.asm.ClassVisitor;
>>> import org.objectweb.asm.MethodVisitor;
>>> import org.objectweb.asm.Type;
>>> -import org.objectweb.asm.commons.EmptyVisitor;
>>> +
>>>
>>> import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
>>>
>>> -public class ConstructorFinder extends ClassAdapter
>>> +public class ConstructorFinder extends ClassVisitor
>>> {
>>>
>>> private boolean hasNoArgsConstructor = false;
>>> @@ -37,7 +40,7 @@ public class ConstructorFinder extends C
>>>
>>> public ConstructorFinder()
>>> {
>>> - super(new EmptyVisitor());
>>> + super(Constants.ASM4, new EmptyVisitor(Constants.ASM4));
>>> }
>>>
>>> @Override
>>>
>>> Added:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java?rev=1236823&view=auto
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java
>> (added)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassVisitor.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -0,0 +1,57 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one
>>> + * or more contributor license agreements. See the NOTICE file
>>> + * distributed with this work for additional information
>>> + * regarding copyright ownership. The ASF licenses this file
>>> + * to you under the Apache License, Version 2.0 (the
>>> + * "License"); you may not use this file except in compliance
>>> + * with the License. You may obtain a copy of the License at
>>> + *
>>> + * http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing,
>>> + * software distributed under the License is distributed on an
>>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>>> + * KIND, either express or implied. See the License for the
>>> + * specific language governing permissions and limitations
>>> + * under the License.
>>> + */
>>> +package org.apache.aries.proxy.impl.common;
>>> +
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> +import org.objectweb.asm.ClassVisitor;
>>> +import org.objectweb.asm.ClassWriter;
>>> +import org.objectweb.asm.MethodVisitor;
>>> +import org.objectweb.asm.commons.JSRInlinerAdapter;
>>> +/**
>>> + * We need to override ASM's default behaviour in {@link
>> #getCommonSuperClass(String, String)}
>>> + * so that it doesn't load classes (which it was doing on the wrong
>> {@link ClassLoader}
>>> + * anyway...)
>>> + */
>>> +public final class OSGiFriendlyClassVisitor extends ClassVisitor {
>>> +
>>> +
>>> + private final boolean inlineJSR;
>>> +
>>> + public OSGiFriendlyClassVisitor(ClassVisitor cv, int arg1) {
>>> +
>>> + super(Constants.ASM4, cv);
>>> +
>>> + inlineJSR = arg1 == ClassWriter.COMPUTE_FRAMES;
>>> + }
>>> +
>>> +
>>> +
>>> +
>>> + @Override
>>> + public MethodVisitor visitMethod(int arg0, String arg1, String arg2,
>>> + String arg3, String[] arg4) {
>>> + MethodVisitor mv = cv.visitMethod(arg0, arg1, arg2, arg3, arg4);
>>> +
>>> + if(inlineJSR)
>>> + mv = new JSRInlinerAdapter(mv, arg0, arg1, arg2, arg3, arg4);
>>> +
>>> + return mv;
>>> + }
>>> +
>>> +}
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassWriter.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassWriter.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassWriter.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/common/OSGiFriendlyClassWriter.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -27,8 +27,6 @@ import org.apache.aries.proxy.UnableToPr
>>> import org.apache.aries.proxy.impl.NLS;
>>> import org.objectweb.asm.ClassReader;
>>> import org.objectweb.asm.ClassWriter;
>>> -import org.objectweb.asm.MethodVisitor;
>>> -import org.objectweb.asm.commons.JSRInlinerAdapter;
>>> /**
>>> * We need to override ASM's default behaviour in {@link
>> #getCommonSuperClass(String, String)}
>>> * so that it doesn't load classes (which it was doing on the wrong
>> {@link ClassLoader}
>>> @@ -40,18 +38,22 @@ public final class OSGiFriendlyClassWrit
>>> private final ClassLoader loader;
>>> private String currentClassInternalName;
>>> private String currentSuperClassInternalName;
>>> - private final boolean inlineJSR;
>>> +
>>>
>>> - public OSGiFriendlyClassWriter(ClassReader arg0, int arg1,
>> ClassLoader loader) {
>>> + public OSGiFriendlyClassWriter(ClassReader arg0, int arg1,
>> ClassLoader loader, String currentClassInternalName, String
>> currentSuperClassInternalName) {
>>> super(arg0, arg1);
>>> - inlineJSR = arg1 == COMPUTE_FRAMES;
>>> +
>>> this.loader = loader;
>>> + this.currentClassInternalName = currentClassInternalName;
>>> + this.currentSuperClassInternalName = currentSuperClassInternalName;
>>> }
>>>
>>> - public OSGiFriendlyClassWriter(int arg0, ClassLoader loader) {
>>> + public OSGiFriendlyClassWriter(int arg0, ClassLoader loader, String
>> currentClassInternalName, String currentSuperClassInternalName) {
>>> super(arg0);
>>> - inlineJSR = arg0 == COMPUTE_FRAMES;
>>> +
>>> this.loader = loader;
>>> + this.currentClassInternalName = currentClassInternalName;
>>> + this.currentSuperClassInternalName = currentSuperClassInternalName;
>>> }
>>>
>>> /**
>>> @@ -133,23 +135,6 @@ public final class OSGiFriendlyClassWrit
>>> /**
>>> * We need access to the super's name and our class name
>>> */
>>> - @Override
>>> - public final void visit(int arg0, int arg1, String arg2, String arg3,
>> String arg4,
>>> - String[] arg5) {
>>> - currentClassInternalName = arg2;
>>> - currentSuperClassInternalName = arg4;
>>> - super.visit(arg0, arg1, arg2, arg3, arg4, arg5);
>>> - }
>>> -
>>> - @Override
>>> - public MethodVisitor visitMethod(int arg0, String arg1, String arg2,
>>> - String arg3, String[] arg4) {
>>> - MethodVisitor mv = super.visitMethod(arg0, arg1, arg2, arg3, arg4);
>>> -
>>> - if(inlineJSR)
>>> - mv = new JSRInlinerAdapter(mv, arg0, arg1, arg2, arg3, arg4);
>>> -
>>> - return mv;
>>> - }
>>> +
>>>
>>> }
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/Constants.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -18,9 +18,12 @@
>>> */
>>> package org.apache.aries.proxy.impl.gen;
>>>
>>> +import org.objectweb.asm.Opcodes;
>>> +
>>> public interface Constants
>>> {
>>> final static String LOG_ENTRY = "Method entry: {}, args {}";
>>> final static String LOG_EXIT = "Method exit: {}, returning {}";
>>> final static String LOG_EXCEPTION = "Caught exception";
>>> + final static int ASM4 = Opcodes.ASM4;
>>> }
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassAdapter.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -23,7 +23,6 @@ import java.lang.reflect.InvocationHandl
>>>
>>> import org.objectweb.asm.AnnotationVisitor;
>>> import org.objectweb.asm.Attribute;
>>> -import org.objectweb.asm.ClassAdapter;
>>> import org.objectweb.asm.ClassReader;
>>> import org.objectweb.asm.ClassVisitor;
>>> import org.objectweb.asm.FieldVisitor;
>>> @@ -35,7 +34,7 @@ import org.objectweb.asm.commons.Method;
>>> import org.slf4j.Logger;
>>> import org.slf4j.LoggerFactory;
>>>
>>> -public class ProxySubclassAdapter extends ClassAdapter implements
>> Opcodes
>>> +public class ProxySubclassAdapter extends ClassVisitor implements
>> Opcodes
>>> {
>>>
>>> private static final Type STRING_TYPE = Type.getType(String.class);
>>> @@ -62,7 +61,7 @@ public class ProxySubclassAdapter extend
>>> public ProxySubclassAdapter(ClassVisitor writer, String newClassName,
>> ClassLoader loader)
>>> {
>>> // call the superclass constructor
>>> - super(writer);
>>> + super(Constants.ASM4, writer);
>>> // the writer is now the cv in the superclass of ClassAdapter
>>>
>>> LOGGER.debug(Constants.LOG_ENTRY, "ProxySubclassAdapter", new
>> Object[] { this, writer,
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/gen/ProxySubclassHierarchyAdapter.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
>>> *
>>> *
>>> */
>>> -public class ProxySubclassHierarchyAdapter implements ClassVisitor,
>> Opcodes
>>> +public class ProxySubclassHierarchyAdapter extends ClassVisitor
>> implements Opcodes
>>> {
>>>
>>> private ProxySubclassAdapter adapter = null;
>>> @@ -47,6 +47,7 @@ public class ProxySubclassHierarchyAdapt
>>>
>>> ProxySubclassHierarchyAdapter(ProxySubclassAdapter adapter,
>> Collection<String> methodsToImplement)
>>> {
>>> + super(Constants.ASM4);
>>> LOGGER.debug(Constants.LOG_ENTRY, "ProxySubclassHeirarchyAdapter",
>> new Object[] {
>>> this, adapter, methodsToImplement });
>>>
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceCombiningClassAdapter.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -26,13 +26,17 @@ import java.util.List;
>>>
>>> import org.apache.aries.proxy.UnableToProxyException;
>>> import org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter;
>>> +import org.apache.aries.proxy.impl.common.OSGiFriendlyClassVisitor;
>>> import org.apache.aries.proxy.impl.common.OSGiFriendlyClassWriter;
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> +import org.apache.aries.proxy.impl.weaving.EmptyVisitor;
>>> import org.apache.aries.proxy.weaving.WovenProxy;
>>> +import org.objectweb.asm.ClassVisitor;
>>> import org.objectweb.asm.ClassWriter;
>>> import org.objectweb.asm.MethodVisitor;
>>> import org.objectweb.asm.Opcodes;
>>> import org.objectweb.asm.Type;
>>> -import org.objectweb.asm.commons.EmptyVisitor;
>>> +
>>> import org.objectweb.asm.commons.Method;
>>>
>>> /**
>>> @@ -60,8 +64,10 @@ final class InterfaceCombiningClassAdapt
>>> */
>>> InterfaceCombiningClassAdapter(String className,
>>> ClassLoader loader, Class<? extends WovenProxy> superclass,
>> Collection<Class<?>> interfaces) {
>>> - writer = new OSGiFriendlyClassWriter(ClassWriter.COMPUTE_FRAMES,
>> loader);
>>> - adapter = new InterfaceUsingWovenProxyAdapter(writer, className,
>> loader);
>>> + super(Constants.ASM4);
>>> + writer = new OSGiFriendlyClassWriter(ClassWriter.COMPUTE_FRAMES,
>> loader, className, (superclass!=null)? superclass.getName(): null);
>>> + ClassVisitor cv = new OSGiFriendlyClassVisitor(writer,
>> ClassWriter.COMPUTE_FRAMES);
>>> + adapter = new InterfaceUsingWovenProxyAdapter(cv, className,
>> loader);
>>>
>>> this.interfaces = interfaces;
>>> this.superclass = superclass;
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/interfaces/InterfaceProxyGenerator.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -23,7 +23,6 @@ import java.lang.reflect.Constructor;
>>> import java.util.Arrays;
>>> import java.util.Collection;
>>> import java.util.Comparator;
>>> -import java.util.LinkedHashSet;
>>> import java.util.Map;
>>> import java.util.SortedSet;
>>> import java.util.TreeSet;
>>> @@ -32,9 +31,10 @@ import java.util.concurrent.Callable;
>>>
>>> import org.apache.aries.proxy.InvocationListener;
>>> import org.apache.aries.proxy.UnableToProxyException;
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> +import org.apache.aries.proxy.impl.weaving.EmptyVisitor;
>>> import org.apache.aries.proxy.weaving.WovenProxy;
>>> import org.objectweb.asm.Opcodes;
>>> -import org.objectweb.asm.commons.EmptyVisitor;
>>> import org.osgi.framework.Bundle;
>>>
>>> /**
>>> @@ -45,6 +45,12 @@ import org.osgi.framework.Bundle;
>>> */
>>> public final class InterfaceProxyGenerator extends EmptyVisitor
>> implements Opcodes {
>>>
>>> + public InterfaceProxyGenerator()
>>> + {
>>> + super(Constants.ASM4);
>>> +
>>> + }
>>> +
>>> private static final Map<Bundle, WeakReference<ProxyClassLoader>>
>> cache =
>>> new WeakHashMap<Bundle,
>> WeakReference<ProxyClassLoader>>(128);
>>>
>>>
>>> Added:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/EmptyVisitor.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/EmptyVisitor.java?rev=1236823&view=auto
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/EmptyVisitor.java
>> (added)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/EmptyVisitor.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -0,0 +1,32 @@
>>> +/*
>>> + * @start_prolog@
>>> + *
>> ============================================================================
>>> + * IBM Confidential OCO Source Materials
>>> + *
>>> + * 5724-J08, 5724-I63, 5724-H88, 5724-H89, 5655-N02, 5733-W70 Copyright
>> IBM Corp. 2010
>>> + *
>>> + * The source code for this program is not published or otherwise
>> divested
>>> + * of its trade secrets, irrespective of what has been deposited with
>> the
>>> + * U.S. Copyright Office.
>>> + *
>> ============================================================================
>>> + * @end_prolog@
>>> + *
>>> + * Change activity:
>>> + *
>>> + * Issue Date Name Description
>>> + * ----------- ----------- --------
>> ------------------------------------
>>> + */
>>> +package org.apache.aries.proxy.impl.weaving;
>>> +
>>> +import org.objectweb.asm.ClassVisitor;
>>> +
>>> +public class EmptyVisitor extends ClassVisitor
>>> +{
>>> +
>>> + public EmptyVisitor(int asmVersion)
>>> + {
>>> + super(asmVersion);
>>> +
>>> + }
>>> +
>>> +}
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/MethodCopyingClassAdapter.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/MethodCopyingClassAdapter.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/MethodCopyingClassAdapter.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/MethodCopyingClassAdapter.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -26,6 +26,7 @@ import org.apache.aries.proxy.UnableToPr
>>> import org.apache.aries.proxy.impl.NLS;
>>> import org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter;
>>> import org.apache.aries.proxy.impl.common.TypeMethod;
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> import org.objectweb.asm.AnnotationVisitor;
>>> import org.objectweb.asm.Attribute;
>>> import org.objectweb.asm.ClassReader;
>>> @@ -33,7 +34,7 @@ import org.objectweb.asm.ClassVisitor;
>>> import org.objectweb.asm.MethodVisitor;
>>> import org.objectweb.asm.Opcodes;
>>> import org.objectweb.asm.Type;
>>> -import org.objectweb.asm.commons.EmptyVisitor;
>>> +
>>> import org.objectweb.asm.commons.Method;
>>>
>>> /**
>>> @@ -65,6 +66,7 @@ final class MethodCopyingClassAdapter ex
>>> public MethodCopyingClassAdapter(ClassVisitor cv, Class<?> superToCopy,
>>> Type overridingClassType, Set<Method> knownMethods,
>>> Map<String, TypeMethod> transformedMethods) {
>>> + super(Constants.ASM4);
>>> this.cv = cv;
>>> this.superToCopy = superToCopy;
>>> this.overridingClassType = overridingClassType;
>>> @@ -132,7 +134,7 @@ final class MethodCopyingClassAdapter ex
>>> * the body with a call to the super-types implementation. The
>> original annotations
>>> * attributes etc are all copied.
>>> */
>>> - private static final class CopyingMethodAdapter extends EmptyVisitor {
>>> + private static final class CopyingMethodAdapter extends MethodVisitor
>> {
>>> /** The visitor to delegate to */
>>> private final MethodVisitor mv;
>>> /** The type that declares this method (not the one that will
>> override it) */
>>> @@ -142,11 +144,13 @@ final class MethodCopyingClassAdapter ex
>>>
>>> public CopyingMethodAdapter(MethodVisitor mv, Type superType,
>>> Method currentTransformMethod) {
>>> + super(Constants.ASM4);
>>> this.mv = mv;
>>> this.superType = superType;
>>> this.currentTransformMethod = currentTransformMethod;
>>> }
>>>
>>> + //TODO might not work for attributes
>>> @Override
>>> public final AnnotationVisitor visitAnnotation(String arg0, boolean
>> arg1) {
>>> return mv.visitAnnotation(arg0, arg1);
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/SyntheticSerialVerUIDAdder.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -18,10 +18,17 @@
>>> */
>>> package org.apache.aries.proxy.impl.weaving;
>>>
>>> +import java.io.IOException;
>>> +
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> import org.objectweb.asm.commons.SerialVersionUIDAdder;
>>> +import org.slf4j.Logger;
>>> +import org.slf4j.LoggerFactory;
>>>
>>> class SyntheticSerialVerUIDAdder extends SerialVersionUIDAdder {
>>>
>>> + private static Logger LOGGER =
>> LoggerFactory.getLogger(SyntheticSerialVerUIDAdder.class);
>>> +
>>> private WovenProxyAdapter wpa;
>>>
>>> public SyntheticSerialVerUIDAdder(WovenProxyAdapter cv) {
>>> @@ -31,7 +38,26 @@ class SyntheticSerialVerUIDAdder extends
>>>
>>> @Override
>>> public void visitEnd() {
>>> - wpa.setSVUIDGenerated(!!!hasSVUID);
>>> +
>>> + wpa.setSVUIDGenerated(!!!isHasSVUID());
>>> super.visitEnd();
>>> }
>>> +
>>> + private boolean isHasSVUID() {
>>> + try {
>>> + if (computeSVUID() == 0 ) {
>>> + // This means the class has a serial id already
>>> + return true;
>>> + } else {
>>> + return false;
>>> + }
>>> + } catch (IOException ioe) {
>>> +
>>> + LOGGER.debug(Constants.LOG_ENTRY, "cannot.compute.serial.id",
>> new Object[] { ioe });
>>> +
>>> + } finally {
>>> + return false;
>>> + }
>>> +
>>> + }
>>> }
>>>
>>> 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=1236823&r1=1236822&r2=1236823&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
>> Fri Jan 27 18:58:20 2012
>>> @@ -23,6 +23,7 @@ import static org.objectweb.asm.Opcodes.
>>> import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
>>>
>>> import org.apache.aries.proxy.impl.common.AbstractWovenProxyAdapter;
>>> +import org.apache.aries.proxy.impl.common.OSGiFriendlyClassVisitor;
>>> import org.apache.aries.proxy.impl.common.OSGiFriendlyClassWriter;
>>> import org.objectweb.asm.ClassReader;
>>> import org.objectweb.asm.ClassVisitor;
>>> @@ -41,12 +42,13 @@ public final class WovenProxyGenerator
>>>
>>> //If we are Java 1.6 + compiled then we need to compute stack
>> frames, otherwise
>>> //maxs are fine (and faster)
>>> - ClassWriter cWriter = new OSGiFriendlyClassWriter(cReader,
>> AbstractWovenProxyAdapter.IS_AT_LEAST_JAVA_6 ?
>>> - ClassWriter.COMPUTE_FRAMES : ClassWriter.COMPUTE_MAXS,
>> loader);
>>> -
>>> + int computeVal = AbstractWovenProxyAdapter.IS_AT_LEAST_JAVA_6 ?
>>> + ClassWriter.COMPUTE_FRAMES : ClassWriter.COMPUTE_MAXS;
>>> + ClassWriter cWriter = new OSGiFriendlyClassWriter(cReader,
>> computeVal, loader, cReader.getClassName(), cReader.getSuperName());
>>> + ClassVisitor cv = new OSGiFriendlyClassVisitor(cWriter, computeVal
>> );
>>> //Wrap our outer layer to add the original SerialVersionUID if it
>> was previously being defaulted
>>> ClassVisitor weavingAdapter = new SyntheticSerialVerUIDAdder(
>>> - new WovenProxyAdapter(cWriter,
>> className, loader));
>>> + new WovenProxyAdapter(cv, className,
>> loader));
>>>
>>> // If we are Java 1.6 + then we need to skip frames as they will be
>> recomputed
>>> cReader.accept(weavingAdapter,
>> AbstractWovenProxyAdapter.IS_AT_LEAST_JAVA_6 ? ClassReader.SKIP_FRAMES : 0);
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/synthesizer/Synthesizer.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -22,7 +22,9 @@ package org.apache.aries.proxy.synthesiz
>>> import java.io.FileInputStream;
>>> import java.io.FileOutputStream;
>>>
>>> +import org.apache.aries.proxy.impl.gen.Constants;
>>> import org.objectweb.asm.ClassReader;
>>> +import org.objectweb.asm.ClassVisitor;
>>> import org.objectweb.asm.ClassWriter;
>>> import org.objectweb.asm.Opcodes;
>>>
>>> @@ -46,6 +48,7 @@ public class Synthesizer
>>> for (String arg : args) {
>>> FileInputStream classInStream = null;
>>> ClassWriter writer = null;
>>> +
>>> try {
>>> //read in the class
>>> classInStream = new FileInputStream(arg);
>>> @@ -55,18 +58,11 @@ public class Synthesizer
>>> //we just need to override the visit method so we can add
>>> //the synthetic modifier, otherwise we use the methods in
>>> //a standard writer
>>> - writer = new ClassWriter(reader, 0) {
>>> - @Override
>>> - public void visit(int version, int access, String name,
>> String signature,
>>> - String superName, String[] interfaces)
>>> - {
>>> - super.visit(version, access | Opcodes.ACC_SYNTHETIC, name,
>> signature, superName,
>>> - interfaces);
>>> - }
>>> - };
>>> + writer = new ClassWriter(reader, 0) ;
>>> + ClassVisitor cv = new CustomClassVisitor((ClassVisitor)writer);
>>> //call accept on the reader to start the visits
>>> //using the writer we created as the visitor
>>> - reader.accept(writer, 0);
>>> + reader.accept(cv, 0);
>>> } finally {
>>> //close the InputStream if it is hanging around
>>> if (classInStream != null) classInStream.close();
>>> @@ -82,4 +78,22 @@ public class Synthesizer
>>> }
>>> }
>>> }
>>> +
>>> + public static class CustomClassVisitor extends ClassVisitor
>>> + {
>>> +
>>> + public CustomClassVisitor( ClassVisitor cv)
>>> + {
>>> + super(Constants.ASM4, cv);
>>> +
>>> + }
>>> + @Override
>>> + public void visit(int version, int access, String name, String
>> signature,
>>> + String superName, String[] interfaces)
>>> + {
>>> + cv.visit(version, access | Opcodes.ACC_SYNTHETIC, name,
>> signature, superName,
>>> + interfaces);
>>> + }
>>> +
>>> + }
>>> }
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/main/resources/org/apache/aries/proxy/nls/ProxyImplMessages.properties
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/resources/org/apache/aries/proxy/nls/ProxyImplMessages.properties?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/main/resources/org/apache/aries/proxy/nls/ProxyImplMessages.properties
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/main/resources/org/apache/aries/proxy/nls/ProxyImplMessages.properties
>> Fri Jan 27 18:58:20 2012
>>> @@ -47,3 +47,4 @@ no.common.superclass=The class {0} and {
>>> cannot.weave=The class {0} cannot be woven, it may not be possible for
>> the runtime to proxy this class.
>>> # {0} The class that could not be woven.
>>> fatal.weaving.failure=There was a serious error trying to weave the
>> class {0}. See the associated exception for more information.
>>> +cannot.compute.serial.id=An internal error occurred while computing
>> serial id. {0}
>>>
>>> Modified:
>> aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
>>> URL:
>> http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java?rev=1236823&r1=1236822&r2=1236823&view=diff
>>>
>> ==============================================================================
>>> ---
>> aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
>> (original)
>>> +++
>> aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/InterfaceProxyingTest.java
>> Fri Jan 27 18:58:20 2012
>>> @@ -53,7 +53,7 @@ public class InterfaceProxyingTest {
>>>
>>> private Object list = new Callable<Object>() {
>>>
>>> - @Override
>>> +
>>> public Object call() throws Exception {
>>> return null;
>>> }
>>> @@ -127,7 +127,7 @@ public class InterfaceProxyingTest {
>>>
>>> tc.setReturn(new Callable<Object>() {
>>>
>>> - @Override
>>> +
>>> public Object call() throws Exception {
>>> throw new RuntimeException();
>>> }
>>> @@ -145,7 +145,7 @@ public class InterfaceProxyingTest {
>>>
>>> tc.setReturn(new Callable<Object>() {
>>>
>>> - @Override
>>> +
>>> public Object call() throws Exception {
>>> try {
>>> throw new RuntimeException();
>>>
>>>
>>
>>
>
>
> --
> Thanks
> Emily
> =================
> Emily Jiang
> [email protected]