Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Temporary WFLY-12373 Weld MSC Contention issue Workaround #12570

Merged
merged 3 commits into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public class Jsr299BindingsInterceptor implements org.jboss.invocation.Intercept
private final InterceptionType interceptionType;
private final ComponentInterceptorSupport interceptorSupport;
private final Supplier<InterceptorBindings> interceptorBindingsSupplier;
private volatile InterceptorBindings interceptorBindings;

private Jsr299BindingsInterceptor(final InterceptionType interceptionType, final ComponentInterceptorSupport interceptorSupport, final Supplier<InterceptorBindings> interceptorBindingsSupplier) {
this.interceptionType = interceptionType;
Expand Down Expand Up @@ -97,11 +96,7 @@ private Object doMethodInterception(InvocationContext invocationContext, Interce
public Object processInvocation(final InterceptorContext context) throws Exception {
final ComponentInstance componentInstance = context.getPrivateData(ComponentInstance.class);
final InterceptorInstances interceptorInstances = interceptorSupport.getInterceptorInstances(componentInstance);
InterceptorBindings interceptorBindings = this.interceptorBindings;
if (interceptorBindings == null) {
// Cache the bindings as reading the interceptorBindingsSupplier is contended
interceptorBindings = this.interceptorBindings = interceptorBindingsSupplier.get();
}
final InterceptorBindings interceptorBindings = interceptorBindingsSupplier.get();
switch (interceptionType) {
case AROUND_INVOKE:
return doMethodInterception(context.getInvocationContext(), InterceptionType.AROUND_INVOKE, interceptorInstances, interceptorBindings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ public class WeldClassIntrospector implements EEClassIntrospector, Service {
private static final ServiceName SERVICE_NAME = ServiceName.of("weld", "weldClassIntrospector");
private final Consumer<EEClassIntrospector> eeClassIntrospectorConsumer;
private final Supplier<BeanManager> beanManagerSupplier;
// Cache the BeanManage to avoid contended calls to the beanManagerSupplier
private volatile BeanManager beanManager;
private final ConcurrentMap<Class<?>, InjectionTarget<?>> injectionTargets = new ConcurrentHashMap<>();

private WeldClassIntrospector(final Consumer<EEClassIntrospector> eeClassIntrospectorConsumer, final Supplier<BeanManager> beanManagerSupplier) {
Expand All @@ -68,6 +66,7 @@ public static ServiceName serviceName(DeploymentUnit deploymentUnit) {
@Override
public ManagedReferenceFactory createFactory(Class<?> clazz) {

final BeanManager beanManager = this.beanManagerSupplier.get();
final InjectionTarget injectionTarget = getInjectionTarget(clazz);
return new ManagedReferenceFactory() {
@Override
Expand All @@ -94,7 +93,7 @@ private InjectionTarget getInjectionTarget(Class<?> clazz) {
if (target != null) {
return target;
}
final BeanManagerImpl beanManager = BeanManagerProxy.unwrap(this.beanManager);
final BeanManagerImpl beanManager = BeanManagerProxy.unwrap(beanManagerSupplier.get());
Bean<?> bean = null;
Set<Bean<?>> beans = new HashSet<>(beanManager.getBeans(clazz, Any.Literal.INSTANCE));
Iterator<Bean<?>> it = beans.iterator();
Expand All @@ -120,6 +119,7 @@ private InjectionTarget getInjectionTarget(Class<?> clazz) {

@Override
public ManagedReference createInstance(final Object instance) {
final BeanManager beanManager = beanManagerSupplier.get();
final InjectionTarget injectionTarget = getInjectionTarget(instance.getClass());
final CreationalContext context = beanManager.createCreationalContext(null);
injectionTarget.inject(instance, context);
Expand All @@ -129,14 +129,12 @@ public ManagedReference createInstance(final Object instance) {

@Override
public void start(final StartContext startContext) throws StartException {
beanManager = beanManagerSupplier.get();
eeClassIntrospectorConsumer.accept(this);
}

@Override
public void stop(StopContext stopContext) {
injectionTargets.clear();
beanManager = null;
}

private static class WeldManagedReference implements ManagedReference {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public class Jsr299BindingsCreateInterceptor implements org.jboss.invocation.Int
private final String ejbName;
private final ComponentInterceptorSupport interceptorSupport;
private volatile BeanManagerImpl beanManager;
private volatile InterceptorBindings interceptorBindings;

public Jsr299BindingsCreateInterceptor(final Supplier<WeldBootstrapService> weldContainerSupplier,
final Supplier<InterceptorBindings> interceptorBindingsSupplier,
Expand Down Expand Up @@ -93,11 +92,7 @@ public Object processInvocation(InterceptorContext interceptorContext) throws Ex
bean = beanManager.getBean(descriptor);
}
}
InterceptorBindings interceptorBindings = this.interceptorBindings;
if (interceptorBindings == null) {
// Cache the bindings as reading the interceptorBindingsSupplier is contended
interceptorBindings = this.interceptorBindings = interceptorBindingsSupplier.get();
}
InterceptorBindings interceptorBindings = interceptorBindingsSupplier.get();

final ComponentInstance componentInstance = interceptorContext.getPrivateData(ComponentInstance.class);
InterceptorInstances existing = interceptorSupport.getInterceptorInstances(componentInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public class WeldSecurityServices implements Service, SecurityServices {
// that doesn't matter, just to make it harder for someone to modify this class and
// accidentally introduce any unnecessary loading of ServerSecurityManager
private final Supplier<?> securityManagerSupplier;
// Cache the object obtained from securityManagerSupplier to avoid contended reads of the supplier
private volatile Object securityManagerRef;

public WeldSecurityServices(final Consumer<SecurityServices> securityServicesConsumer, final Supplier<?> securityManagerSupplier) {
this.securityServicesConsumer = securityServicesConsumer;
Expand All @@ -68,7 +66,6 @@ public void start(final StartContext context) throws StartException {

@Override
public void stop(final StopContext context) {
securityManagerRef = null;
securityServicesConsumer.accept(null);
}

Expand All @@ -81,7 +78,7 @@ public Principal getPrincipal() {

// Use 'Object' initially to avoid loading ServerSecurityManager (which may not be present)
// until we know for sure we need it.
final Object securityManager = getSecurityManagerRef();
final Object securityManager = securityManagerSupplier != null ? securityManagerSupplier.get() : null;
if (securityManager == null)
throw WeldLogger.ROOT_LOGGER.securityNotEnabled();
if (WildFlySecurityManager.isChecking()) {
Expand Down Expand Up @@ -126,14 +123,6 @@ private SecurityDomain getCurrentSecurityDomain() {
}
}

private Object getSecurityManagerRef() {
Object result = this.securityManagerRef;
if (result == null && this.securityManagerSupplier != null) {
result = this.securityManagerRef = securityManagerSupplier.get();
}
return result;
}

static class WeldSecurityContext implements org.jboss.weld.security.spi.SecurityContext, PrivilegedAction<Void> {

private final SecurityContext ctx;
Expand Down