You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by st...@apache.org on 2015/06/01 15:32:11 UTC

svn commit: r1682898 - in /openwebbeans/trunk/webbeans-impl/src/main: java/org/apache/webbeans/config/ java/org/apache/webbeans/proxy/ resources/META-INF/openwebbeans/

Author: struberg
Date: Mon Jun  1 13:32:10 2015
New Revision: 1682898

URL: http://svn.apache.org/r1682898
Log:
OWB-1080 support for other JVM versions in our proxies

The new configuration affects which bytecode we generate in our proxy classes
* By default we now generate Java6 bytecode instead of Java5
* A new config org.apache.webbeans.generator.javaVersion=auto supports automatically
  detecting the current JVM java.version and use this
* Switch from CALC_MAX to real FRAME calculateion for our generated bytecode
* org.apache.webbeans.generator.javaVersion=1.8 etc can be used to specify a java version 

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java?rev=1682898&r1=1682897&r2=1682898&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/OpenWebBeansConfiguration.java Mon Jun  1 13:32:10 2015
@@ -49,12 +49,6 @@ public class OpenWebBeansConfiguration
     /**Logger instance*/
     private static final Logger logger = WebBeansLoggerFacade.getLogger(OpenWebBeansConfiguration.class);
 
-    /**Default configuration files*/
-    private static final String DEFAULT_CONFIG_PROPERTIES_NAME = "META-INF/openwebbeans/openwebbeans.properties";
-    
-    /**Property of application*/
-    private final Properties configProperties = new Properties();
-        
     /**Conversation periodic delay in ms.*/
     public static final String CONVERSATION_PERIODIC_DELAY = "org.apache.webbeans.conversation.Conversation.periodicDelay";
     
@@ -144,6 +138,23 @@ public class OpenWebBeansConfiguration
      */
     public static final String EAGER_SESSION_INITIALISATION = "org.apache.webbeans.web.eagerSessionInitialisation";
 
+    /**
+     * The Java Version to use for the generated proxy classes.
+     * If "auto" then we will pick the version of the current JVM.
+     * The default is set to "1.6" as some tools in jetty/tomcat/etc still
+     * cannot properly handle Java8 (mostly due to older Eclipse JDT versions).
+     */
+    public static final String GENERATOR_JAVA_VERSIN = "org.apache.webbeans.generator.javaVersion";
+
+
+    /**Default configuration files*/
+    private static final String DEFAULT_CONFIG_PROPERTIES_NAME = "META-INF/openwebbeans/openwebbeans.properties";
+
+    private static final String AUTO_CONFIG = "auto";
+
+    /**Property of application*/
+    private final Properties configProperties = new Properties();
+
 
     private Set<String> ignoredInterfaces;
 
@@ -221,15 +232,15 @@ public class OpenWebBeansConfiguration
     private Properties doPrivilegedGetSystemProperties()
     {
         return AccessController.doPrivileged(
-                new PrivilegedAction<Properties>()
+            new PrivilegedAction<Properties>()
+            {
+                @Override
+                public Properties run()
                 {
-                    @Override
-                    public Properties run()
-                    {
-                        return System.getProperties();
-                    }
-
+                    return System.getProperties();
                 }
+
+            }
         );
     }
 
@@ -310,4 +321,15 @@ public class OpenWebBeansConfiguration
     {
         return "true".equals(getProperty(PRODUCER_INTERCEPTION_SUPPORT, "true"));
     }
+
+    public String getGeneratorJavaVersion()
+    {
+        String generatorJavaVersion = getProperty(GENERATOR_JAVA_VERSIN);
+        if (generatorJavaVersion == null || AUTO_CONFIG.equals(generatorJavaVersion))
+        {
+            return System.getProperty("java.version");
+        }
+
+        return generatorJavaVersion;
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java?rev=1682898&r1=1682897&r2=1682898&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContext.java Mon Jun  1 13:32:10 2015
@@ -76,9 +76,9 @@ public class WebBeansContext
     private final DecoratorsManager decoratorsManager = new DecoratorsManager(this);
     private final ExtensionLoader extensionLoader = new ExtensionLoader(this);
     private final InterceptorsManager interceptorsManager = new InterceptorsManager(this);
-    private final InterceptorDecoratorProxyFactory interceptorDecoratorProxyFactory = new InterceptorDecoratorProxyFactory(this);
-    private final NormalScopeProxyFactory normalScopeProxyFactory = new NormalScopeProxyFactory(this);
-    private final SubclassProxyFactory subclassProxyFactory = new SubclassProxyFactory(this);
+    private final InterceptorDecoratorProxyFactory interceptorDecoratorProxyFactory;
+    private final NormalScopeProxyFactory normalScopeProxyFactory;
+    private final SubclassProxyFactory subclassProxyFactory;
     private final OpenWebBeansConfiguration openWebBeansConfiguration;
     private final PluginLoader pluginLoader = new PluginLoader();
     private final SerializableBeanVault serializableBeanVault = new SerializableBeanVault();
@@ -141,6 +141,11 @@ public class WebBeansContext
         loaderService = getService(LoaderService.class);
         securityService = getService(SecurityService.class);
         applicationBoundaryService = getService(ApplicationBoundaryService.class);
+
+        interceptorDecoratorProxyFactory = new InterceptorDecoratorProxyFactory(this);
+        normalScopeProxyFactory = new NormalScopeProxyFactory(this);
+        subclassProxyFactory = new SubclassProxyFactory(this);
+
         beanArchiveService = getService(BeanArchiveService.class);
         conversationManager = new ConversationManager(this);
 

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1682898&r1=1682897&r2=1682898&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java Mon Jun  1 13:32:10 2015
@@ -55,6 +55,7 @@ public abstract class AbstractProxyFacto
 
     private static final Logger logger = WebBeansLoggerFacade.getLogger(AbstractProxyFactory.class);
 
+
     protected WebBeansContext webBeansContext;
 
     /**
@@ -65,6 +66,8 @@ public abstract class AbstractProxyFacto
     private Object unsafe = null;
     private Method unsafeAllocateInstance = null;
 
+    private final int javaVersion;
+
 
     /**
      * The name of the field which stores the passivationID of the Bean this proxy serves.
@@ -77,9 +80,35 @@ public abstract class AbstractProxyFacto
     protected AbstractProxyFactory(WebBeansContext webBeansContext)
     {
         this.webBeansContext = webBeansContext;
+        javaVersion = determineJavaVersion();
         initializeUnsafe();
     }
 
+    private int determineJavaVersion()
+    {
+        String javaVersionProp = webBeansContext.getOpenWebBeansConfiguration().getGeneratorJavaVersion();
+        if (javaVersionProp != null)
+        {
+            if (javaVersionProp.startsWith("1.7"))
+            {
+                return Opcodes.V1_7;
+            }
+            else if (javaVersionProp.startsWith("1.8"))
+            {
+                return Opcodes.V1_8;
+            }
+            else if (javaVersionProp.startsWith("1.9"))
+            {
+                // TODO upgrade to Java9 as soon as ASM really supports it!
+                return Opcodes.V1_8;
+            }
+        }
+
+        // the fallback default is V1_6
+        return Opcodes.V1_6;
+    }
+
+
     protected ClassLoader getProxyClassLoader(Class<?> beanClass)
     {
         return webBeansContext.getApplicationBoundaryService().getBoundaryClassLoader(beanClass);
@@ -249,7 +278,7 @@ public abstract class AbstractProxyFacto
                                  Method[] interceptedMethods, Method[] nonInterceptedMethods, Constructor<?> constructor)
             throws ProxyGenerationException
     {
-        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
+        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
         String classFileName = classToProxy.getName().replace('.', '/');
 
         String[] interfaceNames = new String[]{Type.getInternalName(getMarkerInterface())};
@@ -261,7 +290,7 @@ public abstract class AbstractProxyFacto
             superClassName = Type.getInternalName(Object.class);
         }
 
-        cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
+        cw.visit(javaVersion, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
         cw.visitSource(classFileName + ".java", null);
 
         createInstanceVariables(cw, classToProxy, classFileName);

Modified: openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1682898&r1=1682897&r2=1682898&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties Mon Jun  1 13:32:10 2015
@@ -139,3 +139,13 @@ org.apache.webbeans.proxy.mapping.javax.
 #  * any other value will be interpreted as Java regular expression for request URIs which need eager Session initialization
 org.apache.webbeans.web.eagerSessionInitialisation=false
 ################################################################################################
+
+
+######################### Java version for generated proxy classes #############################
+# The Java Version to use for the generated proxy classes.
+# If "auto" then we will pick the version of the current JVM.
+# The default is set to "1.6" as some tools in jetty/tomcat/etc still
+# cannot properly handle Java8 (mostly due to older Eclipse JDT versions).
+org.apache.webbeans.generator.javaVersion=1.6
+################################################################################################
+