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


Java StackManipulation类代码示例

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


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

示例1: result

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Override
public final Result<StackManipulation> result() {
    final TypeDescription declaringType = field.getDeclaringType().asErasure();
    final TypeDescription fieldType = field.getType().asErasure();
    if(new NaturalJavaAtom().matches(fieldType)) {
        return new SmtInvokeMethod(
            new TypeDescription.ForLoadedType(Object.class),
            ElementMatchers.named("equals")
        );
    } else {
        return new SmtInvokeMethod(
            declaringType,
            new ConjunctionMatcher<>(
                ElementMatchers.isSynthetic(),
                ElementMatchers.named("atom$equal")
            )
        );
    }
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:20,代码来源:SmtCompareAtomFields.java

示例2: SmtCombinedTest

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
public SmtCombinedTest() {
    super(
        new TestCase(
            "combines two StackManipulation tokens into one",
            new AssertTokenToRepresentExpectedStackManipulation(
                new SmtCombined(
                    new SmtLoadReference(5),
                    new SmtLoadReference(6)
                ),
                () -> new StackManipulation.Compound(
                    MethodVariableAccess.REFERENCE.loadFrom(5),
                    MethodVariableAccess.REFERENCE.loadFrom(6)
                )
            )
        )
    );
}
 
开发者ID:project-avral,项目名称:oo-atom,代码行数:18,代码来源:SmtCombinedTest.java

示例3: beforeDelegation

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Override
protected StackManipulation beforeDelegation(MethodDescription instrumentedMethod) {
  // Parameters of the wrapper invoker method:
  //   DoFnInvoker.ArgumentProvider
  // Parameters of the wrapped DoFn method:
  //   [DoFn.ProcessContext, BoundedWindow, InputProvider, OutputReceiver] in any order
  ArrayList<StackManipulation> pushParameters = new ArrayList<>();

  // To load the delegate, push `this` and then access the field
  StackManipulation pushDelegate =
      new StackManipulation.Compound(
          MethodVariableAccess.REFERENCE.loadFrom(0),
          FieldAccess.forField(delegateField).read());

  StackManipulation pushExtraContextFactory = MethodVariableAccess.REFERENCE.loadFrom(1);

  // Push the arguments in their actual order.
  for (DoFnSignature.Parameter param : signature.extraParameters()) {
    pushParameters.add(
        new StackManipulation.Compound(
            pushExtraContextFactory, getExtraContextParameter(param, pushDelegate)));
  }
  return new StackManipulation.Compound(pushParameters);
}
 
开发者ID:apache,项目名称:beam,代码行数:25,代码来源:ByteBuddyDoFnInvokerFactory.java

示例4: beforeDelegation

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Override
protected StackManipulation beforeDelegation(MethodDescription instrumentedMethod) {
  // Parameters of the wrapper invoker method:
  //   DoFn.ArgumentProvider
  // Parameters of the wrapped DoFn method:
  //   a dynamic set of allowed "extra" parameters in any order subject to
  //   validation prior to getting the DoFnSignature
  ArrayList<StackManipulation> parameters = new ArrayList<>();

  // To load the delegate, push `this` and then access the field
  StackManipulation pushDelegate =
      new StackManipulation.Compound(
          MethodVariableAccess.REFERENCE.loadFrom(0),
          FieldAccess.forField(delegateField).read());

  StackManipulation pushExtraContextFactory = MethodVariableAccess.REFERENCE.loadFrom(1);

  // Push the extra arguments in their actual order.
  for (DoFnSignature.Parameter param : signature.extraParameters()) {
    parameters.add(
        new StackManipulation.Compound(
            pushExtraContextFactory,
            ByteBuddyDoFnInvokerFactory.getExtraContextParameter(param, pushDelegate)));
  }
  return new StackManipulation.Compound(parameters);
}
 
开发者ID:apache,项目名称:beam,代码行数:27,代码来源:ByteBuddyOnTimerInvokerFactory.java

示例5: 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

示例6: 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

示例7: opFor

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
/**
 * Returns the proper stack manipulation
 * for the given operation
 * @param operation the arithmetic operation to do
 * @return the stack manipulation for the given operation
 */
public static StackManipulation opFor(Operation operation) {
    switch (operation) {
        case ADD:
            return IntegerAddition.INSTANCE;
        case SUB:
            return IntegerSubtraction.INSTANCE;
        case MUL:
            return IntegerMultiplication.INSTANCE;
        case DIV:
            return IntegerDivision.INSTANCE;
        case MOD:
            return IntegerMod.INSTANCE;
        default:
            throw new IllegalArgumentException("Illegal opType of operation ");
    }
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:23,代码来源:ByteBuddyIntArithmetic.java

示例8: inPlaceSet

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Test
public void inPlaceSet() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val =
                    new ByteBuddy().subclass(SetValueInPlace.class)
                                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                                    MethodVariableAccess.INTEGER.loadOffset(2),
                                                    MethodVariableAccess.INTEGER.loadOffset(3),
                                                    ArrayStackManipulation.store(), MethodReturn.VOID)))
                                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 1);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:21,代码来源:AssignImplementationTest.java

示例9: inPlaceDivide

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Test
public void inPlaceDivide() throws Exception {
    DynamicType.Unloaded<SetValueInPlace> val = new ByteBuddy().subclass(SetValueInPlace.class)
                    .method(ElementMatchers.isDeclaredBy(SetValueInPlace.class))
                    .intercept(new StackManipulationImplementation(new StackManipulation.Compound(
                                    MethodVariableAccess.REFERENCE.loadOffset(1),
                                    MethodVariableAccess.INTEGER.loadOffset(2), Duplication.DOUBLE,
                                    ArrayStackManipulation.load(), MethodVariableAccess.INTEGER.loadOffset(3),
                                    OpStackManipulation.div(), ArrayStackManipulation.store(), MethodReturn.VOID)))
                    .make();

    val.saveIn(new File("target"));
    SetValueInPlace dv = val.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded()
                    .newInstance();
    int[] ret = {2, 4};
    int[] assertion = {1, 4};
    dv.update(ret, 0, 2);
    assertArrayEquals(assertion, ret);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:AssignImplementationTest.java

示例10: testEmptyValue

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Test
public void testEmptyValue() throws Exception {
    when(target.getType()).thenReturn(typeDescription);
    TargetMethodAnnotationDrivenBinder.ParameterBinding<?> binding = Empty.Binder
            .INSTANCE.bind(annotationDescription,
                    source,
                    target,
                    implementationTarget,
                    assigner,
                    Assigner.Typing.STATIC);
    assertThat(binding.isValid(), is(true));
    StackManipulation.Size size = binding.apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(typeDescription.getStackSize().getSize()));
    assertThat(size.getMaximalSize(), is(typeDescription.getStackSize().getSize()));
    verify(methodVisitor).visitInsn(opcode);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:EmptyBinderTest.java

示例11: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Override
public StackManipulation apply(TypeDescription instrumentedType,
                               ByteCodeElement target,
                               TypeList.Generic arguments,
                               TypeDescription.Generic result) {
    if (!methodDescription.isAccessibleTo(instrumentedType)) {
        throw new IllegalStateException(instrumentedType + " cannot access " + methodDescription);
    }
    TypeList.Generic mapped = methodDescription.isStatic()
            ? methodDescription.getParameters().asTypeList()
            : new TypeList.Generic.Explicit(CompoundList.of(methodDescription.getDeclaringType(), methodDescription.getParameters().asTypeList()));
    if (!methodDescription.getReturnType().asErasure().isAssignableTo(result.asErasure())) {
        throw new IllegalStateException("Cannot assign return value of " + methodDescription + " to " + result);
    } else if (mapped.size() != arguments.size()) {
        throw new IllegalStateException("Cannot invoke " + methodDescription + " on " + arguments);
    }
    for (int index = 0; index < mapped.size(); index++) {
        if (!mapped.get(index).asErasure().isAssignableTo(arguments.get(index).asErasure())) {
            throw new IllegalStateException("Cannot invoke " + methodDescription + " on " + arguments);
        }
    }
    return methodDescription.isVirtual()
            ? MethodInvocation.invoke(methodDescription).virtual(target.getDeclaringType().asErasure())
            : MethodInvocation.invoke(methodDescription);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:26,代码来源:MemberSubstitution.java

示例12: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
/**
 * Applies an implementation that delegates to a invocation handler.
 *
 * @param methodVisitor         The method visitor for writing the byte code to.
 * @param implementationContext The implementation context for the current implementation.
 * @param instrumentedMethod    The method that is instrumented.
 * @param preparingManipulation A stack manipulation that applies any preparation to the operand stack.
 * @param fieldDescription      The field that contains the value for the invocation handler.
 * @return The size of the applied assignment.
 */
protected ByteCodeAppender.Size apply(MethodVisitor methodVisitor,
                                      Context implementationContext,
                                      MethodDescription instrumentedMethod,
                                      StackManipulation preparingManipulation,
                                      FieldDescription fieldDescription) {
    if (instrumentedMethod.isStatic()) {
        throw new IllegalStateException("It is not possible to apply an invocation handler onto the static method " + instrumentedMethod);
    }
    StackManipulation.Size stackSize = new StackManipulation.Compound(
            preparingManipulation,
            FieldAccess.forField(fieldDescription).read(),
            MethodVariableAccess.loadThis(),
            cacheMethods
                    ? MethodConstant.forMethod(instrumentedMethod.asDefined()).cached()
                    : MethodConstant.forMethod(instrumentedMethod.asDefined()),
            ArrayFactory.forType(TypeDescription.Generic.OBJECT).withValues(argumentValuesOf(instrumentedMethod)),
            MethodInvocation.invoke(INVOCATION_HANDLER_TYPE.getDeclaredMethods().getOnly()),
            assigner.assign(TypeDescription.Generic.OBJECT, instrumentedMethod.getReturnType(), Assigner.Typing.DYNAMIC),
            MethodReturn.of(instrumentedMethod.getReturnType())
    ).apply(methodVisitor, implementationContext);
    return new ByteCodeAppender.Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:33,代码来源:InvocationHandlerAdapter.java

示例13: prepareArgumentBinder

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static MethodDelegationBinder.ParameterBinding<?> prepareArgumentBinder(TargetMethodAnnotationDrivenBinder.ParameterBinder<?> parameterBinder,
                                                                                Class<? extends Annotation> annotationType,
                                                                                Object identificationToken) {
    doReturn(annotationType).when(parameterBinder).getHandledType();
    MethodDelegationBinder.ParameterBinding<?> parameterBinding = mock(MethodDelegationBinder.ParameterBinding.class);
    when(parameterBinding.isValid()).thenReturn(true);
    when(parameterBinding.apply(any(MethodVisitor.class), any(Implementation.Context.class))).thenReturn(new StackManipulation.Size(0, 0));
    when(parameterBinding.getIdentificationToken()).thenReturn(identificationToken);
    when(((TargetMethodAnnotationDrivenBinder.ParameterBinder) parameterBinder).bind(any(AnnotationDescription.Loadable.class),
            any(MethodDescription.class),
            any(ParameterDescription.class),
            any(Implementation.Target.class),
            any(Assigner.class),
            any(Assigner.Typing.class)))
            .thenReturn(parameterBinding);
    return parameterBinding;
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:19,代码来源:TargetMethodAnnotationDrivenBinderTest.java

示例14: 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

示例15: testNonRebasedMethodIsInvokable

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入依赖的package包/类
@Test
public void testNonRebasedMethodIsInvokable() throws Exception {
    when(invokableMethod.getDeclaringType()).thenReturn(instrumentedType);
    when(invokableMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
    when(resolution.isRebased()).thenReturn(false);
    when(resolution.getResolvedMethod()).thenReturn(invokableMethod);
    Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(rebasedSignatureToken);
    assertThat(specialMethodInvocation.isValid(), is(true));
    assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) invokableMethod));
    assertThat(specialMethodInvocation.getTypeDescription(), is(instrumentedType));
    MethodVisitor methodVisitor = mock(MethodVisitor.class);
    Implementation.Context implementationContext = mock(Implementation.Context.class);
    StackManipulation.Size size = specialMethodInvocation.apply(methodVisitor, implementationContext);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAZ, FOO, QUX, false);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:20,代码来源:RebaseImplementationTargetTest.java


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