当前位置: 首页>>代码示例>>Java>>正文


Java StackManipulation.apply方法代码示例

本文整理汇总了Java中net.bytebuddy.implementation.bytecode.StackManipulation.apply方法的典型用法代码示例。如果您正苦于以下问题:Java StackManipulation.apply方法的具体用法?Java StackManipulation.apply怎么用?Java StackManipulation.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.bytebuddy.implementation.bytecode.StackManipulation的用法示例。


在下文中一共展示了StackManipulation.apply方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
    MethodDescription instrumentedMethod) {

  checkMethodSignature(instrumentedMethod);

  try {
    StackManipulation stack = buildStack();
    StackManipulation.Size finalStackSize = stack.apply(methodVisitor, implementationContext);

    return new Size(finalStackSize.getMaximalSize(),
        instrumentedMethod.getStackSize() + 2); // 2 stack slots for a single local variable

  } catch (NoSuchMethodException | NoSuchFieldException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:bramp,项目名称:unsafe,代码行数:17,代码来源:CopierImplementation.java

示例2: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    int numArgs = instrumentedMethod.getParameters().asTypeList().getStackSize();
    /**
     * Load the desired id
     * relative to the method arguments.
     * The idea here would be to load references
     * to declared variables
     */
    //references start with zero if its an instance or zero if its static
    //think of it like an implicit self in python without actually being defined
    int start = instrumentedMethod.isStatic() ? 1 : 0;
    StackManipulation arg0 = MethodVariableAccess.REFERENCE
                    .loadOffset(numArgs + start + OpCodeUtil.getAloadInstructionForReference(refId));
    StackManipulation.Size size = arg0.apply(methodVisitor, implementationContext);
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:19,代码来源:LoadDeclaredInternalReference.java

示例3: testConstantCreationModernInvisible

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testConstantCreationModernInvisible() throws Exception {
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
    when(declaringType.isVisibleTo(instrumentedType)).thenReturn(false);
    StackManipulation stackManipulation = new FieldConstant(fieldDescription);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(2));
    verify(methodVisitor).visitLdcInsn(BAZ);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
            Type.getInternalName(Class.class),
            "forName",
            Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)),
            false);
    verify(methodVisitor).visitLdcInsn(BAR);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL,
            "java/lang/Class",
            "getDeclaredField",
            "(Ljava/lang/String;)Ljava/lang/reflect/Field;",
            false);
    verifyNoMoreInteractions(methodVisitor);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:FieldConstantTest.java

示例4: testClassConstantModernInvisible

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testClassConstantModernInvisible() throws Exception {
    when(typeDescription.isVisibleTo(instrumentedType)).thenReturn(false);
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(true);
    when(typeDescription.getName()).thenReturn(FOO);
    StackManipulation stackManipulation = ClassConstant.of(typeDescription);
    assertThat(stackManipulation.isValid(), is(true));
    StackManipulation.Size size = stackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(1));
    verify(typeDescription).getName();
    verify(typeDescription).isVisibleTo(instrumentedType);
    verify(typeDescription, times(9)).represents(any(Class.class));
    verifyNoMoreInteractions(typeDescription);
    verify(methodVisitor).visitLdcInsn(FOO);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
            Type.getInternalName(Class.class),
            "forName",
            Type.getMethodDescriptor(Type.getType(Class.class), Type.getType(String.class)),
            false);
    verifyNoMoreInteractions(methodVisitor);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:ClassConstantReferenceTest.java

示例5: testTrivialBoxing

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testTrivialBoxing() throws Exception {
    StackManipulation stackManipulation = PrimitiveUnboxingDelegate.forReferenceType(referenceTypeDescription)
            .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(interimMaximum));
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKEVIRTUAL,
            Type.getInternalName(referenceType),
            unboxingMethodName,
            unboxingMethodDescriptor,
            false);
    verify(methodVisitor).visitInsn(wideningOpcode);
    verifyNoMoreInteractions(methodVisitor);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:17,代码来源:PrimitiveUnboxingDelegateWideningTest.java

示例6: testBoxing

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testBoxing() throws Exception {
    StackManipulation boxingStackManipulation = PrimitiveBoxingDelegate.forPrimitive(primitiveTypeDescription)
            .assignBoxedTo(targetType, chainedAssigner, Assigner.Typing.STATIC);
    assertThat(boxingStackManipulation.isValid(), is(true));
    StackManipulation.Size size = boxingStackManipulation.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(sizeChange));
    assertThat(size.getMaximalSize(), is(0));
    verify(primitiveTypeDescription).represents(primitiveType);
    verify(primitiveTypeDescription, atLeast(1)).represents(any(Class.class));
    verifyNoMoreInteractions(primitiveTypeDescription);
    verify(chainedAssigner).assign(referenceTypeDescription.asGenericType(), targetType, Assigner.Typing.STATIC);
    verifyNoMoreInteractions(chainedAssigner);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESTATIC,
            referenceTypeDescription.getInternalName(),
            VALUE_OF,
            boxingMethodDescriptor,
            false);
    verifyNoMoreInteractions(methodVisitor);
    verify(stackManipulation, atLeast(1)).isValid();
    verify(stackManipulation).apply(methodVisitor, implementationContext);
    verifyNoMoreInteractions(stackManipulation);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:24,代码来源:PrimitiveBoxingDelegateTest.java

示例7: AssertStackManipulationsAreSame

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
/**
 * Ctor.
 * 
 * @param sm Stack manipulation to assert on.
 * @param sm2 Stack manipulation to compare with
 */
public AssertStackManipulationsAreSame(StackManipulation sm, StackManipulation sm2) {
    super(
        sm,
        mv -> {
            Implementation.Context ctx = EasyMock.mock(Implementation.Context.class);
            sm2.apply(mv, ctx);
        }
    );
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:16,代码来源:AssertStackManipulationsAreSame.java

示例8: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1
    StackManipulation compound = assignOperation();
    StackManipulation.Size size = compound.apply(methodVisitor, implementationContext);
    //resolve the opType to store in the array and retrieve the load command
    StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).load();
    size = size.aggregate(store.apply(methodVisitor, implementationContext));
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:12,代码来源:RelativeRetrieveArrayValueAppender.java

示例9: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //resolve the opType to store in the array and retrieve the store command
    StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).load();
    StackManipulation.Size size = store.apply(methodVisitor, implementationContext);
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:9,代码来源:ArrayRetrieve.java

示例10: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //resolve the opType to store in the array and retrieve the store command
    StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store();
    StackManipulation.Size size = store.apply(methodVisitor, implementationContext);
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:9,代码来源:AssignOpAppender.java

示例11: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1
    StackManipulation compound = assignOperation();
    StackManipulation.Size size = compound.apply(methodVisitor, implementationContext);
    //resolve the opType to store in the array and retrieve the store command
    StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store();
    size = size.aggregate(store.apply(methodVisitor, implementationContext));
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:12,代码来源:RelativeAssignNoValueArrayValueAppender.java

示例12: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //initialize the stack with the array access with this as reference 0 and the array (first argument) as reference 1
    StackManipulation compound = assignOperation();
    StackManipulation.Size size = compound.apply(methodVisitor, implementationContext);
    //resolve the opType to store in the array and retrieve the store command
    StackManipulation store = ArrayAccess.of(typePool.describe("int").resolve()).store();
    size = size.aggregate(store.apply(methodVisitor, implementationContext));
    //set the return opType (ALWAYS REMEMBER TO DO THIS)
    StackManipulation returnOp = MethodReturn.VOID;
    size = size.aggregate(returnOp.apply(methodVisitor, implementationContext));
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:15,代码来源:AssignArrayValueAppender.java

示例13: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //references start with zero if its an instance or zero if its static
    //think of it like an implicit self in python without actually being defined
    StackManipulation arg0 = MethodVariableAccess.REFERENCE.loadOffset(refId);
    StackManipulation.Size size = arg0.apply(methodVisitor, implementationContext);
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:10,代码来源:RelativeLoadDeclaredInternalReference.java

示例14: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    //references start with zero if its an instance or zero if its static
    //think of it like an implicit self in python without actually being defined
    StackManipulation arg0 = MethodVariableAccess.INTEGER.loadOffset(refId);
    StackManipulation.Size size = arg0.apply(methodVisitor, implementationContext);
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:10,代码来源:LoadDeclaredInternalInteger.java

示例15: testBiPush

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testBiPush() throws Exception {
    StackManipulation doubleConstant = DoubleConstant.forValue(value);
    assertThat(doubleConstant.isValid(), is(true));
    StackManipulation.Size size = doubleConstant.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(2));
    assertThat(size.getMaximalSize(), is(2));
    verify(methodVisitor).visitLdcInsn(value);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:12,代码来源:DoubleConstantTest.java


注:本文中的net.bytebuddy.implementation.bytecode.StackManipulation.apply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。