Search in sources :

Example 56 with StackManipulation

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class TypeProxyCreationTest method testForReflectionFactoryConstruction.

@Test
public void testForReflectionFactoryConstruction() throws Exception {
    when(implementationTarget.getInstrumentedType()).thenReturn(foo);
    when(invocationFactory.invoke(eq(implementationTarget), eq(foo), any(MethodDescription.class))).thenReturn(specialMethodInvocation);
    when(specialMethodInvocation.isValid()).thenReturn(true);
    when(specialMethodInvocation.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(methodAccessorFactory.registerAccessorFor(specialMethodInvocation, MethodAccessorFactory.AccessType.DEFAULT)).thenReturn(proxyMethod);
    StackManipulation stackManipulation = new TypeProxy.ForSuperMethodByReflectionFactory(foo, implementationTarget, true, false);
    MethodVisitor methodVisitor = mock(MethodVisitor.class);
    Implementation.Context implementationContext = mock(Implementation.Context.class);
    when(implementationContext.register(any(AuxiliaryType.class))).thenReturn(new TypeDescription.ForLoadedType(FooProxyMake.class));
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(3));
    verify(implementationContext).register(any(AuxiliaryType.class));
    verifyNoMoreInteractions(implementationContext);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(FooProxyMake.class), TypeProxy.REFLECTION_METHOD, Type.getMethodDescriptor(FooProxyMake.class.getDeclaredMethod("make")), false);
    verify(methodVisitor).visitInsn(Opcodes.DUP);
    verify(methodVisitor).visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(FooProxyMake.class), TypeProxy.INSTANCE_FIELD, Type.getDescriptor(Void.class));
    verify(methodVisitor).visitVarInsn(Opcodes.ALOAD, 0);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : MethodDescription(net.bytebuddy.description.method.MethodDescription) StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Implementation(net.bytebuddy.implementation.Implementation) MethodVisitor(org.objectweb.asm.MethodVisitor) TypeDescription(net.bytebuddy.description.type.TypeDescription) Test(org.junit.Test)

Example 57 with StackManipulation

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodVariableAccessOtherTest method testIncrement.

@Test
public void testIncrement() throws Exception {
    StackManipulation stackManipulation = MethodVariableAccess.INTEGER.increment(4, 1);
    assertThat(stackManipulation.isValid(), is(true));
    MethodVisitor methodVisitor = mock(MethodVisitor.class);
    Implementation.Context implementationContext = mock(Implementation.Context.class);
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
    verify(methodVisitor).visitIincInsn(4, 1);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Implementation(net.bytebuddy.implementation.Implementation) MethodVisitor(org.objectweb.asm.MethodVisitor) Test(org.junit.Test)

Example 58 with StackManipulation

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodVariableAccessTest method testStoring.

@Test
public void testStoring() throws Exception {
    StackManipulation stackManipulation = MethodVariableAccess.of(typeDefinition).storeAt(4);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(this.size));
    assertThat(size.getMaximalSize(), is(this.size));
    verify(methodVisitor).visitVarInsn(writeCode, 4);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 59 with StackManipulation

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class MethodVariableAccessTest method testLoading.

@Test
public void testLoading() throws Exception {
    StackManipulation stackManipulation = MethodVariableAccess.of(typeDefinition).loadFrom(4);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(this.size));
    assertThat(size.getMaximalSize(), is(this.size));
    verify(methodVisitor).visitVarInsn(readCode, 4);
    verifyNoMoreInteractions(methodVisitor);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Example 60 with StackManipulation

use of org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation in project byte-buddy by raphw.

the class PrimitiveUnboxingDelegateDirectTest method testTrivialBoxing.

@Test
public void testTrivialBoxing() throws Exception {
    StackManipulation stackManipulation = PrimitiveUnboxingDelegate.forReferenceType(wrapperTypeDescription).assignUnboxedTo(primitiveTypeDescription, chainedAssigner, Assigner.Typing.STATIC);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(sizeChange));
    assertThat(size.getMaximalSize(), is(sizeChange));
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(wrapperType), unboxingMethodName, unboxingMethodDescriptor, false);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(chainedAssigner);
    verifyZeroInteractions(this.stackManipulation);
}
Also used : StackManipulation(net.bytebuddy.implementation.bytecode.StackManipulation) Test(org.junit.Test)

Aggregations

StackManipulation (net.bytebuddy.implementation.bytecode.StackManipulation)93 Test (org.junit.Test)85 TypeDescription (net.bytebuddy.description.type.TypeDescription)18 Implementation (net.bytebuddy.implementation.Implementation)5 Assigner (net.bytebuddy.implementation.bytecode.assign.Assigner)5 Goto (org.curioswitch.common.protobuf.json.bytebuddy.Goto)5 MethodDescription (net.bytebuddy.description.method.MethodDescription)4 ForLoadedType (net.bytebuddy.description.type.TypeDescription.ForLoadedType)4 Label (net.bytebuddy.jar.asm.Label)4 SetJumpTargetLabel (org.curioswitch.common.protobuf.json.bytebuddy.SetJumpTargetLabel)4 MethodVisitor (org.objectweb.asm.MethodVisitor)4 ArrayList (java.util.ArrayList)3 IfTrue (org.curioswitch.common.protobuf.json.bytebuddy.IfTrue)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)2 Type (java.lang.reflect.Type)2 FieldDescription (net.bytebuddy.description.field.FieldDescription)2 JavaConstant (net.bytebuddy.utility.JavaConstant)2 ForLoadedType (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.description.type.TypeDescription.ForLoadedType)2 DynamicType (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.dynamic.DynamicType)2 StackManipulation (org.apache.beam.vendor.bytebuddy.v1_11_0.net.bytebuddy.implementation.bytecode.StackManipulation)2