Author: struberg
Date: Mon Mar 7 18:10:20 2011
New Revision: 1078876
URL: http://svn.apache.org/viewvc?rev=1078876&view=rev
Log:
OWB-541 drop WeakHashMap and cleanup code
This seriously improves our interceptor performance (~40%)
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=1078876&r1=1078875&r2=1078876&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
Mon Mar 7 18:10:20 2011
@@ -39,7 +39,6 @@ import org.apache.webbeans.component.Owb
import org.apache.webbeans.container.InjectionResolver;
import org.apache.webbeans.context.creational.CreationalContextImpl;
import org.apache.webbeans.context.creational.DependentCreationalContext;
-import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.WebBeansUtil;
@@ -56,8 +55,6 @@ import org.apache.webbeans.util.WebBeans
*/
public abstract class AbstractInjectable implements Injectable
{
- private final static WebBeansLogger logger =
WebBeansLogger.getLogger(AbstractInjectable.class);
-
/** Owner bean of the injection point*/
protected OwbBean<?> injectionOwnerBean;
@@ -93,12 +90,7 @@ public abstract class AbstractInjectable
*/
public <T> Object inject(InjectionPoint injectionPoint)
{
- if (logger.wblWillLogDebug())
- {
- logger.debug("Injected into bean : [{0}] with injection point :
[{1}]", this.injectionOwnerBean, injectionPoint);
- }
-
- Object injected = null;
+ Object injected = null;
//Injected contextual beam
InjectionResolver instance =
injectionOwnerBean.getWebBeansContext().getBeanManagerImpl().getInjectionResolver();
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java?rev=1078876&r1=1078875&r2=1078876&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorHandler.java
Mon Mar 7 18:10:20 2011
@@ -27,7 +27,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.WeakHashMap;
+import java.util.concurrent.ConcurrentHashMap;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.ProxyFactory;
@@ -45,7 +45,6 @@ import org.apache.webbeans.decorator.Web
import org.apache.webbeans.logger.WebBeansLogger;
import org.apache.webbeans.util.ClassUtil;
import org.apache.webbeans.util.SecurityUtil;
-import org.apache.webbeans.util.WebBeansUtil;
/**
* Logic for how interceptors & decorators work in OWB.
@@ -57,8 +56,10 @@ import org.apache.webbeans.util.WebBeans
* class via methods <code>defineManagedBean(class)</code> and Those methods
further call
* <code>defineInterceptor(interceptor class)</code> and
<code>defineDecorator(decorator class)</code>
* methods. Those methods finally call
- * {@link
WebBeansUtil#defineInterceptor(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
javax.enterprise.inject.spi.ProcessInjectionTarget)} and
- * {@link
WebBeansUtil#defineDecorator(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
javax.enterprise.inject.spi.ProcessInjectionTarget)}
+ * {@link
org.apache.webbeans.util.WebBeansUtil#defineInterceptor(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
+ * javax.enterprise.inject.spi.ProcessInjectionTarget)} and
+ * {@link
org.apache.webbeans.util.WebBeansUtil#defineDecorator(org.apache.webbeans.component.creation.ManagedBeanCreatorImpl,
+ * javax.enterprise.inject.spi.ProcessInjectionTarget)}
* methods for actual configuration.
* <p>
* Let's look at the "WebBeansUtil's" methods;
@@ -92,8 +93,9 @@ import org.apache.webbeans.util.WebBeans
* instantiated by the container first time. This method can be found in the
* AbstractInjectionTargetBean" class "afterConstructor()" method. Actual
* configuration is done by the
- * {@link DefinitionUtil#defineBeanInterceptorStack(AbstractOwbBean)} and
- * {@link DefinitionUtil#defineDecoratorStack}. In
+ * {@link org.apache.webbeans.config.DefinitionUtil#defineBeanInterceptorStack
+ * (org.apache.webbeans.component.AbstractInjectionTargetBean)} and
+ * {@link org.apache.webbeans.config.DefinitionUtil#defineDecoratorStack}. In
* "DefinitionUtil.defineBeanInterceptorStack", firstly it configures
* "EJB spec. interceptors" after that configures "JSR-299 spec. interceptors."
* In "DefinitionUtil.defineDecoratorStack", it configures
@@ -148,7 +150,8 @@ public abstract class InterceptorHandler
protected OwbBean<?> bean = null;
/**Intercepted methods*/
- protected transient Map<Method, List<InterceptorData>>
interceptedMethodMap = null;
+ protected transient volatile Map<Method, List<InterceptorData>>
interceptedMethodMap = null;
+
private WebBeansContext webBeansContext;
/**
@@ -187,16 +190,7 @@ public abstract class InterceptorHandler
//Calling method name on Proxy
String methodName = method.getName();
- if(ClassUtil.isObjectMethod(methodName) &&
!methodName.equals("toString"))
- {
- // we must not log in this place because this almost takes
away half of the performance!
- // if(logger.wblWillLogTrace())
- // {
- // logger.trace("Calling method on proxy is restricted
except Object.toString(), but current method is Object. [{0}]", methodName);
- // }
- }
-
- else if (bean instanceof InjectionTargetBean<?>)
+ if (!ClassUtil.isObjectMethod(methodName) && bean instanceof
InjectionTargetBean<?>)
{
InjectionTargetBean<?> injectionTarget =
(InjectionTargetBean<?>) this.bean;
DelegateHandler delegateHandler = null;
@@ -206,7 +200,7 @@ public abstract class InterceptorHandler
if
(webBeansContext.getInterceptorUtil().isWebBeansBusinessMethod(method))
{
List<Object> decorators = null;
- if (injectionTarget.getDecoratorStack().size() > 0)
+ if (!injectionTarget.getDecoratorStack().isEmpty())
{
Class<?> proxyClass =
webBeansContext.getJavassistProxyFactory().getInterceptorProxyClasses().get(bean);
if (proxyClass == null)
@@ -227,12 +221,12 @@ public abstract class InterceptorHandler
// Run around invoke chain
List<InterceptorData> interceptorStack =
injectionTarget.getInterceptorStack();
- if (interceptorStack.size() > 0)
+ if (!interceptorStack.isEmpty())
{
if (this.interceptedMethodMap == null)
{
// lazy initialisation, because creating a
WeakHashMap is expensive!
- this.interceptedMethodMap = new
WeakHashMap<Method, List<InterceptorData>>();
+ this.interceptedMethodMap = new
ConcurrentHashMap<Method, List<InterceptorData>>();
}
if (decorators != null)
@@ -243,29 +237,38 @@ public abstract class InterceptorHandler
decoratorInterceptorDataImpl.setDefinedInInterceptorClass(true);
decoratorInterceptorDataImpl.setAroundInvoke(SecurityUtil.doPrivilegedGetDeclaredMethods(lastInterceptor.getClass())[0]);
}
- if (this.interceptedMethodMap.get(method) == null)
+
+ List<InterceptorData> interceptorMethods =
this.interceptedMethodMap.get(method);
+ if (interceptorMethods == null)
{
//Holds filtered interceptor stack
- List<InterceptorData> filteredInterceptorStack =
new ArrayList<InterceptorData>(interceptorStack);
+ List<InterceptorData> filteredInterceptorStack =
new ArrayList<InterceptorData>();
+ for (InterceptorData interceptData :
interceptorStack)
+ {
+ if (interceptData.getAroundInvoke() !=null)
+ {
+
filteredInterceptorStack.add(interceptData);
+ }
+ }
// Filter both EJB and WebBeans interceptors
InterceptorUtil.filterCommonInterceptorStackList(filteredInterceptorStack,
method);
InterceptorUtil.filterOverridenAroundInvokeInterceptor(bean.getBeanClass(),
filteredInterceptorStack);
this.interceptedMethodMap.put(method,
filteredInterceptorStack);
+ interceptorMethods = filteredInterceptorStack;
}
- List<InterceptorData> filteredInterceptorStack = new
ArrayList<InterceptorData>(this.interceptedMethodMap.get(method));
if (decoratorInterceptorDataImpl != null)
{
// created an intereceptor to run our decorators,
add it to the calculated stack
-
filteredInterceptorStack.add(decoratorInterceptorDataImpl);
+ interceptorMethods = new
ArrayList<InterceptorData>(interceptorMethods);
+
interceptorMethods.add(decoratorInterceptorDataImpl);
}
// Call Around Invokes
- if
(WebBeansUtil.isContainsInterceptorMethod(filteredInterceptorStack,
InterceptorType.AROUND_INVOKE))
+ if (!interceptorMethods.isEmpty())
{
- return callAroundInvokes(method, arguments,
InterceptorUtil.getInterceptorMethods(filteredInterceptorStack,
-
InterceptorType.AROUND_INVOKE));
+ return callAroundInvokes(method, arguments,
interceptorMethods);
}
}
@@ -282,7 +285,10 @@ public abstract class InterceptorHandler
//If not interceptor or decorator calls
//Do normal calling
boolean access = method.isAccessible();
- SecurityUtil.doPrivilegedSetAccessible(method, true);
+ if (!access)
+ {
+ SecurityUtil.doPrivilegedSetAccessible(method, true);
+ }
try
{
result = method.invoke(instance, arguments);
@@ -290,7 +296,10 @@ public abstract class InterceptorHandler
}
finally
{
- SecurityUtil.doPrivilegedSetAccessible(method, access);
+ if (!access)
+ {
+ SecurityUtil.doPrivilegedSetAccessible(method, access);
+ }
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java?rev=1078876&r1=1078875&r2=1078876&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorUtil.java
Mon Mar 7 18:10:20 2011
@@ -22,8 +22,8 @@ import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@@ -63,6 +63,11 @@ public final class InterceptorUtil
private final Class<? extends Annotation> prePassivateClass;
private final Class<? extends Annotation> postActivateClass;
+ /**
+ * all the bit flags of private static and final modifiers
+ */
+ private final int MODIFIER_STATIC_FINAL_PRIVATE = Modifier.STATIC |
Modifier.FINAL | Modifier.PRIVATE;
+
private final WebBeansContext webBeansContext;
public InterceptorUtil(WebBeansContext webBeansContext)
@@ -93,8 +98,9 @@ public final class InterceptorUtil
int modifiers = method.getModifiers();
- if (ClassUtil.isStatic(modifiers) || ClassUtil.isPrivate(modifiers) ||
ClassUtil.isFinal(modifiers))
+ if ((modifiers & MODIFIER_STATIC_FINAL_PRIVATE) != 0)
{
+ // static, final and private methods are NO business methods!
return false;
}
@@ -466,12 +472,7 @@ public final class InterceptorUtil
@SuppressWarnings("unchecked")
public static List<InterceptorData>
getInterceptorMethods(List<InterceptorData> stack, InterceptorType type)
{
- List<InterceptorData> ai = new ArrayList<InterceptorData>(); //
AroundInvoke
- List<InterceptorData> at = new ArrayList<InterceptorData>(); //
AroundTimeout
- List<InterceptorData> pa = new ArrayList<InterceptorData>(); //
PostActivate
- List<InterceptorData> pc = new ArrayList<InterceptorData>(); //
PostConstruct
- List<InterceptorData> pd = new ArrayList<InterceptorData>(); //
PreDestroy
- List<InterceptorData> pp = new ArrayList<InterceptorData>(); //
PrePassivate
+ List<InterceptorData> interceptors = new ArrayList<InterceptorData>();
Iterator<InterceptorData> it = stack.iterator();
while (it.hasNext())
@@ -482,85 +483,34 @@ public final class InterceptorUtil
if (type.equals(InterceptorType.AROUND_INVOKE))
{
m = data.getAroundInvoke();
- if (m != null)
- {
- ai.add(data);
- }
-
}
else if (type.equals(InterceptorType.AROUND_TIMEOUT))
{
m = data.getAroundTimeout();
- if (m != null)
- {
- at.add(data);
- }
-
}
else if (type.equals(InterceptorType.POST_ACTIVATE))
{
m = data.getPostActivate();
- if (m != null)
- {
- pa.add(data);
- }
-
}
else if (type.equals(InterceptorType.POST_CONSTRUCT))
{
m = data.getPostConstruct();
- if (m != null)
- {
- pc.add(data);
- }
-
}
else if (type.equals(InterceptorType.PRE_DESTROY))
{
m = data.getPreDestroy();
- if (m != null)
- {
- pd.add(data);
- }
-
}
else if (type.equals(InterceptorType.PRE_PASSIVATE))
{
m = data.getPrePassivate();
- if (m != null)
- {
- pp.add(data);
- }
-
+ }
+ if (m != null)
+ {
+ interceptors.add(data);
}
}
- if (type.equals(InterceptorType.AROUND_INVOKE))
- {
- return ai;
- }
- else if (type.equals(InterceptorType.AROUND_TIMEOUT))
- {
- return at;
- }
- else if (type.equals(InterceptorType.POST_ACTIVATE))
- {
- return pa;
- }
- else if (type.equals(InterceptorType.POST_CONSTRUCT))
- {
- return pc;
- }
- else if (type.equals(InterceptorType.PRE_DESTROY))
- {
- return pd;
- }
- else if (type.equals(InterceptorType.PRE_PASSIVATE))
- {
- return pp;
- }
-
- return Collections.EMPTY_LIST;
+ return interceptors;
}
/**
@@ -709,16 +659,20 @@ public final class InterceptorUtil
public static void filterOverridenAroundInvokeInterceptor(Class<?>
beanClass, List<InterceptorData> stack)
{
- List<InterceptorData> overridenInterceptors = new
ArrayList<InterceptorData>();
+ List<InterceptorData> overridenInterceptors = null;
Iterator<InterceptorData> it = stack.iterator();
while (it.hasNext())
{
InterceptorData interceptorData = it.next();
- if (false == interceptorData.isLifecycleInterceptor())
+ if (interceptorData.getAroundInvoke() != null)
{
InterceptorData overridenInterceptor =
getOverridenInterceptor(beanClass, interceptorData, stack);
if (null != overridenInterceptor)
{
+ if (overridenInterceptors == null)
+ {
+ overridenInterceptors = new
ArrayList<InterceptorData>();
+ }
overridenInterceptors.add(overridenInterceptor);
if (logger.wblWillLogDebug())
{
@@ -729,7 +683,10 @@ public final class InterceptorUtil
}
}
- stack.removeAll(overridenInterceptors);
+ if (overridenInterceptors != null)
+ {
+ stack.removeAll(overridenInterceptors);
+ }
}
/**
@@ -765,10 +722,6 @@ public final class InterceptorUtil
if (null != childInterceptorMethod &&
ClassUtil.isOverriden(childInterceptorMethod, superInterceptorMethod))
{
- if (logger.wblWillLogDebug())
- {
- logger.debug("KEEPING child " + interceptorData);
- }
return superInterceptorData;
}
}
Modified:
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java?rev=1078876&r1=1078875&r2=1078876&view=diff
==============================================================================
---
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
(original)
+++
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/ClassUtil.java
Mon Mar 7 18:10:20 2011
@@ -298,7 +298,7 @@ public final class ClassUtil
/**
* Check the class is inner or not
*
- * @param modifier modifier
+ * @param clazz to check
* @return true or false
*/
public static boolean isInnerClazz(Class<?> clazz)
@@ -561,12 +561,12 @@ public final class ClassUtil
return method.getParameterTypes();
}
- public static List<String> getObjectMethodNames()
+ private static Set<String> getObjectMethodNames()
{
if (objectMethodNames == null)
{
// not much syncronisation needed...
- List<String> list = new ArrayList<String>();
+ Set<String> list = new HashSet<String>();
Class<?> clazz = Object.class;
Method[] methods =
SecurityUtil.doPrivilegedGetDeclaredMethods(clazz);
@@ -579,7 +579,7 @@ public final class ClassUtil
return objectMethodNames;
}
- private static volatile List objectMethodNames= null;
+ private static volatile Set<String> objectMethodNames= null;