Skip to content

Commit

Permalink
Merge pull request quarkusio#4577 from mkouba/issue-4552-ic
Browse files Browse the repository at this point in the history
Cleanup and optimize InvocationContext implementation
  • Loading branch information
mkouba authored Oct 18, 2019
2 parents c894ad6 + e7ba46a commit 7bd8980
Show file tree
Hide file tree
Showing 20 changed files with 603 additions and 488 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@

import javax.interceptor.InvocationContext;

import io.quarkus.arc.AroundInvokeInvocationContext;
import io.quarkus.arc.InvocationContextImpl;
import io.quarkus.arc.ArcInvocationContext;

public class InterceptorBindings {

@SuppressWarnings("unchecked")
public static Set<Annotation> getInterceptorBindings(InvocationContext invocationContext) {
if (invocationContext instanceof InvocationContextImpl) {
return ((InvocationContextImpl) invocationContext).getInterceptorBindings();
} else if (invocationContext instanceof AroundInvokeInvocationContext) {
return ((AroundInvokeInvocationContext) invocationContext).getInterceptorBindings();
}
return null;
return (Set<Annotation>) invocationContext.getContextData().get(ArcInvocationContext.KEY_INTERCEPTOR_BINDINGS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -960,19 +960,20 @@ protected void implementCreate(ClassOutput classOutput, ClassCreator beanCreator
Types.getPackageName(beanCreator.getClassName())));
}

// InvocationContextImpl.aroundConstruct(constructor,aroundConstructs,forward).proceed()
ResultHandle invocationContextHandle = create.invokeStaticMethod(
MethodDescriptors.INVOCATION_CONTEXT_AROUND_CONSTRUCT, constructorHandle,
MethodDescriptors.INVOCATION_CONTEXTS_AROUND_CONSTRUCT, constructorHandle,
aroundConstructsHandle, func.getInstance(), bindingsHandle);
TryBlock tryCatch = create.tryBlock();
CatchBlockCreator exceptionCatch = tryCatch.addCatch(Exception.class);
// throw new RuntimeException(e)
exceptionCatch.throwException(RuntimeException.class, "Error invoking aroundConstructs",
exceptionCatch.getCaughtException());
tryCatch.assign(instanceHandle,
tryCatch.invokeInterfaceMethod(
MethodDescriptor.ofMethod(InvocationContext.class, "proceed", Object.class),
invocationContextHandle));
// InvocationContextImpl.aroundConstruct(constructor,aroundConstructs,forward).proceed()
tryCatch.invokeInterfaceMethod(MethodDescriptors.INVOCATION_CONTEXT_PROCEED,
invocationContextHandle);
// instance = InvocationContext.getTarget()
tryCatch.assign(instanceHandle, tryCatch.invokeInterfaceMethod(MethodDescriptors.INVOCATION_CONTEXT_GET_TARGET,
invocationContextHandle));

} else {
create.assign(instanceHandle, newInstanceHandle(bean, beanCreator, create, create, providerTypeName, baseName,
Expand Down Expand Up @@ -1079,7 +1080,7 @@ protected void implementCreate(ClassOutput classOutput, ClassCreator beanCreator

// InvocationContextImpl.postConstruct(instance,postConstructs).proceed()
ResultHandle invocationContextHandle = create.invokeStaticMethod(
MethodDescriptors.INVOCATION_CONTEXT_POST_CONSTRUCT, instanceHandle,
MethodDescriptors.INVOCATION_CONTEXTS_POST_CONSTRUCT, instanceHandle,
postConstructsHandle, bindingsHandle);

TryBlock tryCatch = create.tryBlock();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package io.quarkus.arc.processor;

import io.quarkus.arc.AbstractInvocationContext;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.AroundInvokeInvocationContext;
import io.quarkus.arc.ClientProxy;
import io.quarkus.arc.CreationalContextImpl;
import io.quarkus.arc.FixedValueSupplier;
import io.quarkus.arc.InjectableBean;
import io.quarkus.arc.InjectableContext;
import io.quarkus.arc.InjectableInterceptor;
import io.quarkus.arc.InjectableReferenceProvider;
import io.quarkus.arc.InvocationContextImpl;
import io.quarkus.arc.InvocationContextImpl.InterceptorInvocation;
import io.quarkus.arc.InterceptorInvocation;
import io.quarkus.arc.InvocationContexts;
import io.quarkus.arc.MapValueSupplier;
import io.quarkus.arc.Reflections;
import io.quarkus.arc.SubclassMethodMetadata;
import io.quarkus.gizmo.MethodDescriptor;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
Expand Down Expand Up @@ -80,6 +79,10 @@ final class MethodDescriptors {
"postConstruct",
InterceptorInvocation.class, InjectableInterceptor.class, Object.class);

static final MethodDescriptor INTERCEPTOR_INVOCATION_PRE_DESTROY = MethodDescriptor.ofMethod(InterceptorInvocation.class,
"preDestroy",
InterceptorInvocation.class, InjectableInterceptor.class, Object.class);

static final MethodDescriptor INTERCEPTOR_INVOCATION_AROUND_CONSTRUCT = MethodDescriptor.ofMethod(
InterceptorInvocation.class, "aroundConstruct",
InterceptorInvocation.class, InjectableInterceptor.class, Object.class);
Expand Down Expand Up @@ -131,26 +134,33 @@ final class MethodDescriptors {
static final MethodDescriptor EVENT_CONTEXT_GET_METADATA = MethodDescriptor.ofMethod(EventContext.class, "getMetadata",
EventMetadata.class);

static final MethodDescriptor INVOCATION_CONTEXT_AROUND_INVOKE = MethodDescriptor.ofMethod(
AroundInvokeInvocationContext.class,
"create",
AbstractInvocationContext.class, Object.class, Method.class, Function.class, Object[].class, List.class, Set.class);
static final MethodDescriptor INVOCATION_CONTEXTS_PERFORM_AROUND_INVOKE = MethodDescriptor.ofMethod(
InvocationContexts.class,
"performAroundInvoke",
Object.class, Object.class, Method.class, Function.class, Object[].class, List.class,
Set.class);

static final MethodDescriptor INVOCATION_CONTEXT_AROUND_CONSTRUCT = MethodDescriptor.ofMethod(InvocationContextImpl.class,
static final MethodDescriptor INVOCATION_CONTEXTS_AROUND_CONSTRUCT = MethodDescriptor.ofMethod(
InvocationContexts.class,
"aroundConstruct",
InvocationContextImpl.class, Constructor.class, List.class, Supplier.class, Set.class);
InvocationContext.class, Constructor.class, List.class, Supplier.class, Set.class);

static final MethodDescriptor INVOCATION_CONTEXT_POST_CONSTRUCT = MethodDescriptor.ofMethod(InvocationContextImpl.class,
static final MethodDescriptor INVOCATION_CONTEXTS_POST_CONSTRUCT = MethodDescriptor.ofMethod(
InvocationContexts.class,
"postConstruct",
InvocationContextImpl.class, Object.class, List.class, Set.class);
InvocationContext.class, Object.class, List.class, Set.class);

static final MethodDescriptor INVOCATION_CONTEXT_PRE_DESTROY = MethodDescriptor.ofMethod(InvocationContextImpl.class,
static final MethodDescriptor INVOCATION_CONTEXTS_PRE_DESTROY = MethodDescriptor.ofMethod(InvocationContexts.class,
"preDestroy",
InvocationContextImpl.class, Object.class, List.class, Set.class);
InvocationContext.class, Object.class, List.class, Set.class);

static final MethodDescriptor INVOCATION_CONTEXT_PROCEED = MethodDescriptor.ofMethod(InvocationContext.class, "proceed",
Object.class);

static final MethodDescriptor INVOCATION_CONTEXT_GET_TARGET = MethodDescriptor.ofMethod(InvocationContext.class,
"getTarget",
Object.class);

static final MethodDescriptor CREATIONAL_CTX_ADD_DEP_TO_PARENT = MethodDescriptor.ofMethod(CreationalContextImpl.class,
"addDependencyToParent", void.class,
InjectableBean.class, Object.class, CreationalContext.class);
Expand All @@ -172,6 +182,10 @@ final class MethodDescriptors {
static final MethodDescriptor GET_IDENTIFIER = MethodDescriptor.ofMethod(InjectableBean.class, "getIdentifier",
String.class);

static final MethodDescriptor SUBCLASS_METHOD_METADATA_CONSTRUCTOR = MethodDescriptor.ofConstructor(
SubclassMethodMetadata.class,
List.class, Method.class, Set.class);

private MethodDescriptors() {
}

Expand Down
Loading

0 comments on commit 7bd8980

Please sign in to comment.