Skip to content

Commit

Permalink
WELD-1169 ConcurrentBeanDeployer may trigger JVM deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
jharting committed Aug 6, 2012
1 parent 474a7f6 commit a0839a5
Show file tree
Hide file tree
Showing 27 changed files with 315 additions and 79 deletions.
Expand Up @@ -141,7 +141,7 @@ public AbstractEnhancedAnnotated(Annotated annotated, Map<Class<? extends Annota
this.annotationMap = immutableMap(annotationMap);
ArraySetMultimap<Class<? extends Annotation>, Annotation> metaAnnotationMap = new ArraySetMultimap<Class<? extends Annotation>, Annotation>();
for (Annotation annotation : annotationMap.values()) {
addMetaAnnotations(metaAnnotationMap, annotation, annotation.annotationType().getAnnotations(), false);
addMetaAnnotations(metaAnnotationMap, annotation, classTransformer.getReflectionCache().getAnnotations(annotation.annotationType()), false);
addMetaAnnotations(metaAnnotationMap, annotation, classTransformer.getTypeStore().get(annotation.annotationType()), false);
}
this.metaAnnotationMap = metaAnnotationMap;
Expand Down
Expand Up @@ -104,7 +104,7 @@ public class EnhancedAnnotatedTypeImpl<T> extends AbstractEnhancedAnnotated<T, C

public static <T> EnhancedAnnotatedType<T> of(SlimAnnotatedType<T> annotatedType, ClassTransformer classTransformer) {
if (annotatedType instanceof BackedAnnotatedType<?>) {
return new EnhancedAnnotatedTypeImpl<T>(annotatedType, buildAnnotationMap(annotatedType.getAnnotations()), buildAnnotationMap(annotatedType.getJavaClass().getDeclaredAnnotations()), classTransformer);
return new EnhancedAnnotatedTypeImpl<T>(annotatedType, buildAnnotationMap(annotatedType.getAnnotations()), buildAnnotationMap(classTransformer.getReflectionCache().getDeclaredAnnotations(annotatedType.getJavaClass())), classTransformer);
} else {
return new EnhancedAnnotatedTypeImpl<T>(annotatedType, buildAnnotationMap(annotatedType.getAnnotations()), buildAnnotationMap(annotatedType.getAnnotations()), classTransformer);
}
Expand Down Expand Up @@ -255,7 +255,7 @@ protected EnhancedAnnotatedTypeImpl(SlimAnnotatedType<T> annotatedType, Map<Clas

ArraySetMultimap<Class<? extends Annotation>, Annotation> declaredMetaAnnotationMap = new ArraySetMultimap<Class<? extends Annotation>, Annotation>();
for (Annotation declaredAnnotation : declaredAnnotationMap.values()) {
addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, declaredAnnotation.annotationType().getAnnotations(), true);
addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, classTransformer.getReflectionCache().getAnnotations(declaredAnnotation.annotationType()), true);
addMetaAnnotations(declaredMetaAnnotationMap, declaredAnnotation, classTransformer.getTypeStore().get(declaredAnnotation.annotationType()), true);
declaredMetaAnnotationMap.putSingleElement(declaredAnnotation.annotationType(), declaredAnnotation);
}
Expand Down
Expand Up @@ -56,11 +56,11 @@ public class EnhancedAnnotationImpl<T extends Annotation> extends EnhancedAnnota
public static <A extends Annotation> EnhancedAnnotation<A> create(SlimAnnotatedType<A> annotatedType, ClassTransformer classTransformer) {
Class<A> annotationType = annotatedType.getJavaClass();
Map<Class<? extends Annotation>, Annotation> annotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
annotationMap.putAll(buildAnnotationMap(annotationType.getAnnotations()));
annotationMap.putAll(buildAnnotationMap(classTransformer.getReflectionCache().getAnnotations(annotationType)));
annotationMap.putAll(buildAnnotationMap(classTransformer.getTypeStore().get(annotationType)));

Map<Class<? extends Annotation>, Annotation> declaredAnnotationMap = new HashMap<Class<? extends Annotation>, Annotation>();
declaredAnnotationMap.putAll(buildAnnotationMap(annotationType.getDeclaredAnnotations()));
declaredAnnotationMap.putAll(buildAnnotationMap(classTransformer.getReflectionCache().getDeclaredAnnotations(annotationType)));
declaredAnnotationMap.putAll(buildAnnotationMap(classTransformer.getTypeStore().get(annotationType)));
return new EnhancedAnnotationImpl<A>(annotatedType, annotationMap, declaredAnnotationMap, classTransformer);
}
Expand Down
@@ -1,19 +1,27 @@
package org.jboss.weld.annotated.slim.backed;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
import java.util.Set;

import org.jboss.weld.annotated.slim.BaseAnnotated;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.ReflectionCache;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.LazyValueHolder;

import com.google.common.collect.ImmutableSet;

public abstract class BackedAnnotated extends BaseAnnotated {

private final LazyValueHolder<Set<Type>> typeClosure;
private final ReflectionCache reflectionCache;

public BackedAnnotated(Type baseType, SharedObjectCache cache) {
public BackedAnnotated(Type baseType, ClassTransformer transformer) {
super(baseType);
this.typeClosure = initTypeClosure(baseType, cache);
this.typeClosure = initTypeClosure(baseType, transformer.getSharedObjectCache());
this.reflectionCache = transformer.getReflectionCache();
}

protected LazyValueHolder<Set<Type>> initTypeClosure(Type baseType, SharedObjectCache cache) {
Expand All @@ -24,4 +32,10 @@ public Set<Type> getTypeClosure() {
return typeClosure.get();
}

protected abstract AnnotatedElement getAnnotatedElement();

@Override
public Set<Annotation> getAnnotations() {
return ImmutableSet.copyOf(reflectionCache.getAnnotations(getAnnotatedElement()));
}
}
Expand Up @@ -7,40 +7,38 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Constructor;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedParameter;

import org.jboss.weld.Container;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.serialization.ConstructorHolder;
import org.jboss.weld.util.reflection.Formats;
import org.jboss.weld.util.reflection.Reflections;

import com.google.common.collect.ImmutableSet;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedConstructor<X> extends BackedAnnotatedMember<X> implements AnnotatedConstructor<X>, Serializable {

public static <X> AnnotatedConstructor<X> of(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, SharedObjectCache cache) {
return new BackedAnnotatedConstructor<X>(constructor, declaringType, cache);
public static <X> AnnotatedConstructor<X> of(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
return new BackedAnnotatedConstructor<X>(constructor, declaringType, transformer);
}

private final Constructor<X> constructor;
private final List<AnnotatedParameter<X>> parameters;

public BackedAnnotatedConstructor(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, SharedObjectCache cache) {
super(constructor.getDeclaringClass(), declaringType, cache);
public BackedAnnotatedConstructor(Constructor<X> constructor, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(constructor.getDeclaringClass(), declaringType, transformer);
this.constructor = constructor;

final Class<?>[] parameterTypes = constructor.getParameterTypes();
Expand All @@ -63,7 +61,7 @@ public BackedAnnotatedConstructor(Constructor<X> constructor, BackedAnnotatedTyp
parameterType = clazz;
position = i;
}
parameters.add(new BackedAnnotatedParameter<X>(parameterType, parameterAnnotations[position], position, this, cache));
parameters.add(new BackedAnnotatedParameter<X>(parameterType, parameterAnnotations[position], position, this, transformer));
}
this.parameters = immutableList(parameters);
} else {
Expand All @@ -79,6 +77,11 @@ public BackedAnnotatedConstructor(Constructor<X> constructor, BackedAnnotatedTyp
}
}

@Override
protected AnnotatedElement getAnnotatedElement() {
return constructor;
}

public Constructor<X> getJavaMember() {
return constructor;
}
Expand All @@ -87,10 +90,6 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return constructor.getAnnotation(annotationType);
}

public Set<Annotation> getAnnotations() {
return ImmutableSet.copyOf(constructor.getAnnotations());
}

public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return constructor.isAnnotationPresent(annotationType);
}
Expand Down
Expand Up @@ -7,35 +7,33 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.Set;

import javax.enterprise.inject.spi.AnnotatedField;

import org.jboss.weld.Container;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.serialization.FieldHolder;
import org.jboss.weld.util.reflection.Formats;

import com.google.common.collect.ImmutableSet;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedField<X> extends BackedAnnotatedMember<X> implements AnnotatedField<X>, Serializable {

public static <X, Y extends X> AnnotatedField<X> of(Field field, BackedAnnotatedType<Y> declaringType, SharedObjectCache cache) {
public static <X, Y extends X> AnnotatedField<X> of(Field field, BackedAnnotatedType<Y> declaringType, ClassTransformer transformer) {
BackedAnnotatedType<X> downcastDeclaringType = cast(declaringType);
return new BackedAnnotatedField<X>(field.getGenericType(), field, downcastDeclaringType, cache);
return new BackedAnnotatedField<X>(field.getGenericType(), field, downcastDeclaringType, transformer);
}

private final Field field;

public BackedAnnotatedField(Type baseType, Field field, BackedAnnotatedType<X> declaringType, SharedObjectCache cache) {
super(baseType, declaringType, cache);
public BackedAnnotatedField(Type baseType, Field field, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(baseType, declaringType, transformer);
this.field = field;
}

Expand All @@ -47,8 +45,9 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return field.getAnnotation(annotationType);
}

public Set<Annotation> getAnnotations() {
return ImmutableSet.copyOf(field.getAnnotations());
@Override
protected AnnotatedElement getAnnotatedElement() {
return field;
}

public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
Expand Down
Expand Up @@ -6,6 +6,7 @@
import javax.enterprise.inject.spi.AnnotatedMember;
import javax.enterprise.inject.spi.AnnotatedType;

import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.util.LazyValueHolder;
import org.jboss.weld.util.reflection.RawType;
Expand All @@ -15,8 +16,8 @@ public abstract class BackedAnnotatedMember<X> extends BackedAnnotated implement

private BackedAnnotatedType<X> declaringType;

public BackedAnnotatedMember(Type baseType, BackedAnnotatedType<X> declaringType, SharedObjectCache cache) {
super(baseType, cache);
public BackedAnnotatedMember(Type baseType, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(baseType, transformer);
this.declaringType = declaringType;
}

Expand Down
Expand Up @@ -8,39 +8,37 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedParameter;

import org.jboss.weld.Container;
import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.MemberTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.serialization.MethodHolder;
import org.jboss.weld.util.reflection.Formats;

import com.google.common.collect.ImmutableSet;

import edu.umd.cs.findbugs.annotations.SuppressWarnings;

@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedMethod<X> extends BackedAnnotatedMember<X> implements AnnotatedMethod<X>, Serializable {

public static <X, Y extends X> AnnotatedMethod<X> of(Method method, BackedAnnotatedType<Y> declaringType, SharedObjectCache cache) {
public static <X, Y extends X> AnnotatedMethod<X> of(Method method, BackedAnnotatedType<Y> declaringType, ClassTransformer transformer) {
BackedAnnotatedType<X> downcastDeclaringType = cast(declaringType);
return new BackedAnnotatedMethod<X>(method, downcastDeclaringType, cache);
return new BackedAnnotatedMethod<X>(method, downcastDeclaringType, transformer);
}

private final Method method;
private final List<AnnotatedParameter<X>> parameters;

public BackedAnnotatedMethod(Method method, BackedAnnotatedType<X> declaringType, SharedObjectCache cache) {
super(method.getGenericReturnType(), declaringType, cache);
public BackedAnnotatedMethod(Method method, BackedAnnotatedType<X> declaringType, ClassTransformer transformer) {
super(method.getGenericReturnType(), declaringType, transformer);
this.method = method;

final Type[] genericParameterTypes = method.getGenericParameterTypes();
Expand All @@ -50,7 +48,7 @@ public BackedAnnotatedMethod(Method method, BackedAnnotatedType<X> declaringType
Annotation[][] parameterAnnotations = method.getParameterAnnotations();
for (int i = 0; i < genericParameterTypes.length; i++) {
Type parameterType = genericParameterTypes[i];
parameters.add(BackedAnnotatedParameter.of(parameterType, parameterAnnotations[i], i, this, cache));
parameters.add(BackedAnnotatedParameter.of(parameterType, parameterAnnotations[i], i, this, transformer));
}
this.parameters = immutableList(parameters);
}
Expand All @@ -63,8 +61,9 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return method.getAnnotation(annotationType);
}

public Set<Annotation> getAnnotations() {
return ImmutableSet.copyOf(method.getAnnotations());
@Override
protected AnnotatedElement getAnnotatedElement() {
return method;
}

public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
Expand Down
Expand Up @@ -7,13 +7,15 @@
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Type;
import java.util.Set;

import javax.enterprise.inject.spi.AnnotatedCallable;
import javax.enterprise.inject.spi.AnnotatedParameter;

import org.jboss.weld.exceptions.InvalidObjectException;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.resources.SharedObjectCache;
import org.jboss.weld.resources.SharedObjectFacade;
import org.jboss.weld.util.LazyValueHolder;
Expand All @@ -27,16 +29,16 @@
@SuppressWarnings(value = { "SE_BAD_FIELD", "SE_NO_SUITABLE_CONSTRUCTOR", "SE_NO_SERIALVERSIONID" }, justification = "False positive from FindBugs - serialization is handled by SerializationProxy.")
public class BackedAnnotatedParameter<X> extends BackedAnnotated implements AnnotatedParameter<X>, Serializable {

public static <X> AnnotatedParameter<X> of(Type baseType, Annotation[] annotations, int position, AnnotatedCallable<X> declaringCallable, SharedObjectCache cache) {
return new BackedAnnotatedParameter<X>(baseType, annotations, position, declaringCallable, cache);
public static <X> AnnotatedParameter<X> of(Type baseType, Annotation[] annotations, int position, AnnotatedCallable<X> declaringCallable, ClassTransformer transformer) {
return new BackedAnnotatedParameter<X>(baseType, annotations, position, declaringCallable, transformer);
}

private final int position;
private final AnnotatedCallable<X> declaringCallable;
private transient Set<Annotation> annotations;

public BackedAnnotatedParameter(Type baseType, Annotation[] annotations, int position, AnnotatedCallable<X> declaringCallable, SharedObjectCache cache) {
super(baseType, cache);
public BackedAnnotatedParameter(Type baseType, Annotation[] annotations, int position, AnnotatedCallable<X> declaringCallable, ClassTransformer transformer) {
super(baseType, transformer);
this.position = position;
this.declaringCallable = declaringCallable;
this.annotations = SharedObjectFacade.wrap(ImmutableSet.copyOf(annotations));
Expand Down Expand Up @@ -64,10 +66,16 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return null;
}

@Override
public Set<Annotation> getAnnotations() {
return annotations;
}

@Override
protected AnnotatedElement getAnnotatedElement() {
return null;
}

public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
return getAnnotation(annotationType) != null;
}
Expand Down

0 comments on commit a0839a5

Please sign in to comment.