aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r1092653 - in /aries/trunk/proxy/proxy-impl/src: main/java/org/apache/aries/proxy/impl/weaving/ test/java/org/apache/aries/blueprint/proxy/
Date Fri, 15 Apr 2011 10:15:59 GMT
Author: mahrwald
Date: Fri Apr 15 10:15:58 2011
New Revision: 1092653

URL: http://svn.apache.org/viewvc?rev=1092653&view=rev
Log:
ARIES-633: Some more tests and fixes for SunVM problems around calling Object.super().

Added:
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassUnweavableSibling.java
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
    aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.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=1092653&r1=1092652&r2=1092653&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
Fri Apr 15 10:15:58 2011
@@ -181,10 +181,8 @@ abstract class AbstractWovenProxyAdapter
     LOGGER.debug(Constants.LOG_ENTRY, "visit", new Object[] { version, access,
         name, signature, superName, interfaces });
 
-    // We update to at least Java 1.5 because we add annotations and synthetic
-    // modifiers. Java 1.4 would not like this at all!
-    if (version < V1_5)
-      version = V1_5;
+    // always update to the most recent version of the JVM
+    version = WovenProxyGenerator.JAVA_CLASS_VERSION;
 
     superType = Type.getType("L" + superName + ";");
 
@@ -447,7 +445,7 @@ abstract class AbstractWovenProxyAdapter
 
     
     // Write a protected no-args constructor for this class
-    methodAdapter = getMethodGenerator(ACC_PROTECTED, ARGS_CONSTRUCTOR);
+    methodAdapter = getMethodGenerator(ACC_PROTECTED | ACC_SYNTHETIC, ARGS_CONSTRUCTOR);
 
     // /////////////////////////////////////////////////////
     // Implement the constructor

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=1092653&r1=1092652&r2=1092653&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 Apr 15 10:15:58 2011
@@ -22,6 +22,8 @@ import static org.objectweb.asm.Opcodes.
 import static org.objectweb.asm.Opcodes.ACC_ENUM;
 import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
 
+import java.math.BigDecimal;
+
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
@@ -32,22 +34,22 @@ import org.objectweb.asm.Opcodes;
  */
 public final class WovenProxyGenerator
 {
+  public static final int JAVA_CLASS_VERSION = new BigDecimal(System.getProperty("java.class.version")).intValue();
+  public static final boolean IS_AT_LEAST_JAVA_6 = JAVA_CLASS_VERSION >= Opcodes.V1_6;
+    
   public static final byte[] getWovenProxy(byte[] original, String className, ClassLoader
loader){
     ClassReader cReader = new ClassReader(original);
     //Don't weave interfaces, enums or annotations
     if((cReader.getAccess() & (ACC_INTERFACE | ACC_ANNOTATION | ACC_ENUM)) != 0)
       return null;
     
-    //We need to know the class version, but ASM won't tell us yet!
-    int version = ((0xFF & original[6]) << 8) + (0xFF & original[7]);
-    
     //If we are Java 1.6 + compiled then we need to compute stack frames, otherwise
     //maxs are fine (and faster)
-    ClassWriter cWriter = new ClassWriter(cReader, (version > Opcodes.V1_5) ?
-        ClassWriter.COMPUTE_FRAMES : ClassWriter.COMPUTE_MAXS);
+    ClassWriter cWriter = new ClassWriter(cReader, IS_AT_LEAST_JAVA_6 ? 
+            ClassWriter.COMPUTE_FRAMES : ClassWriter.COMPUTE_MAXS);
     ClassVisitor weavingAdapter = new WovenProxyAdapter(cWriter, className, loader);
     // If we are Java 1.6 + then we need to skip frames as they will be recomputed
-    cReader.accept(weavingAdapter, (version > Opcodes.V1_5) ? ClassReader.SKIP_FRAMES
: 0);
+    cReader.accept(weavingAdapter, IS_AT_LEAST_JAVA_6 ? ClassReader.SKIP_FRAMES : 0);
     
     return cWriter.toByteArray();
   }

Added: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassUnweavableSibling.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassUnweavableSibling.java?rev=1092653&view=auto
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassUnweavableSibling.java
(added)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/ProxyTestClassUnweavableSibling.java
Fri Apr 15 10:15:58 2011
@@ -0,0 +1,30 @@
+/*
+ * 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.blueprint.proxy;
+
+/**
+ * A class that has an unweavable super class, but there are no-noargs constructors to be
found anywhere
+ */
+public class ProxyTestClassUnweavableSibling extends ProxyTestClassUnweavableSuper {
+
+    public ProxyTestClassUnweavableSibling(int i) {
+        super(i);
+    }
+
+}

Modified: aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java?rev=1092653&r1=1092652&r2=1092653&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/test/java/org/apache/aries/blueprint/proxy/WovenProxyGeneratorTest.java
Fri Apr 15 10:15:58 2011
@@ -67,12 +67,10 @@ public class WovenProxyGeneratorTest ext
     ProxyTestClassFinalMethod.class, ProxyTestClassFinal.class, ProxyTestClassGeneric.class,
     ProxyTestClassGenericSuper.class, ProxyTestClassCovariant.class, ProxyTestClassCovariantOverride.class,
     ProxyTestClassUnweavableChild.class, ProxyTestClassUnweavableSuperWithFinalMethod.class,
-    ProxyTestClassUnweavableChildWithDefaultMethodWrongPackageParent.class};
+    ProxyTestClassUnweavableChildWithDefaultMethodWrongPackageParent.class, ProxyTestClassUnweavableSibling.class};
  
   private static final Map<String, byte[]> rawClasses = new HashMap<String, byte[]>();
   
-  private static Class<?> WOVEN_TEST_CLASS;
-  
   private static final ClassLoader weavingLoader = new ClassLoader() {
     public Class<?> loadClass(String className)  throws ClassNotFoundException
     {
@@ -117,7 +115,6 @@ public class WovenProxyGeneratorTest ext
       }
       rawClasses.put(clazz.getName(), baos.toByteArray());
     }
-    WOVEN_TEST_CLASS = weavingLoader.loadClass(TEST_CLASS.getName());
   }
 
   /**
@@ -241,6 +238,37 @@ public class WovenProxyGeneratorTest ext
     assertNotNull(ProxyTestClassUnweavableSuper.class.getDeclaredMethod("doStuff2"));
   }
   
+  @Test
+  public void testUnweavableSuperWithNoNoargsAllTheWay() throws Exception
+  {
+    Class<?> woven = getProxyClass(ProxyTestClassUnweavableSibling.class);
+    
+    assertNotNull(woven);
+    assertNotNull(woven.getConstructor(int.class).newInstance(42));
+    
+    TestListener tl = new TestListener();
+    
+    WovenProxy proxy = (WovenProxy) woven.getConstructor(int.class).newInstance(42);
+    proxy = proxy.org_apache_aries_proxy_weaving_WovenProxy_createNewProxyInstance(
+            new SingleInstanceDispatcher(proxy), tl);
+    
+    ProxyTestClassUnweavableSuper ptcuc = (ProxyTestClassUnweavableSuper) proxy;
+    assertCalled(tl, false, false, false);
+    
+    assertEquals("Hi!", ptcuc.doStuff());
+    
+    assertCalled(tl, true, true, false);
+    
+    assertEquals(ProxyTestClassUnweavableGrandParent.class.getMethod("doStuff"), 
+        tl.getLastMethod());
+    
+
+    //Because default access works on the package, and we are defined on a different classloader
+    //we can only check that the method exists, not that it is callable *sigh*
+    
+    assertNotNull(ProxyTestClassUnweavableSuper.class.getDeclaredMethod("doStuff2"));
+  }  
+  
   /**
    * Test a class whose super couldn't be woven
    */



Mime
View raw message