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


Java StackManipulation.Size方法代码示例

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


在下文中一共展示了StackManipulation.Size方法的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: testSuperTypeMethodIsInvokable

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

示例3: testPreservation

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testPreservation() throws Exception {
    MethodRebaseResolver.Resolution resolution = MethodRebaseResolver.Resolution.ForRebasedConstructor.of(methodDescription, rawPlaceholderType);
    assertThat(resolution.isRebased(), is(true));
    assertThat(resolution.getResolvedMethod().getDeclaringType(), is(rawTypeDescription));
    assertThat(resolution.getResolvedMethod().getInternalName(), is(MethodDescription.CONSTRUCTOR_INTERNAL_NAME));
    assertThat(resolution.getResolvedMethod().getModifiers(), is(Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PRIVATE));
    assertThat(resolution.getResolvedMethod().getReturnType(), is(TypeDescription.Generic.VOID));
    assertThat(resolution.getResolvedMethod().getParameters(), is((ParameterList<ParameterDescription.InDefinedShape>) new ParameterList.Explicit
            .ForTypes(resolution.getResolvedMethod(), parameterType, placeholderType)));
    StackManipulation.Size size = resolution.getAdditionalArguments().apply(methodVisitor, implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(1));
    verify(methodVisitor).visitInsn(Opcodes.ACONST_NULL);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:MethodRebaseResolverResolutionForRebasedConstructorTest.java

示例4: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor,
                  Context implementationContext,
                  MethodDescription instrumentedMethod) {
    FieldList<?> fieldList = instrumentedType.getDeclaredFields();
    List<StackManipulation> fieldLoadings = new ArrayList<StackManipulation>(fieldList.size());
    for (FieldDescription fieldDescription : fieldList) {
        fieldLoadings.add(new StackManipulation.Compound(MethodVariableAccess.loadThis(), FieldAccess.forField(fieldDescription).read()));
    }
    StackManipulation.Size stackSize = new StackManipulation.Compound(
            new StackManipulation.Compound(fieldLoadings),
            MethodInvocation.invoke(accessorMethod),
            assigner.assign(accessorMethod.getReturnType(), instrumentedMethod.getReturnType(), Assigner.Typing.DYNAMIC),
            MethodReturn.of(instrumentedMethod.getReturnType())
    ).apply(methodVisitor, implementationContext);
    return new Size(stackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:18,代码来源:MethodCallProxy.java

示例5: testRebasedConstructorIsInvokable

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testRebasedConstructorIsInvokable() throws Exception {
    when(rebasedMethod.isConstructor()).thenReturn(true);
    when(invokableMethod.getDeclaringType()).thenReturn(instrumentedType);
    when(resolution.isRebased()).thenReturn(true);
    when(resolution.getResolvedMethod()).thenReturn(rebasedMethod);
    when(resolution.getAdditionalArguments()).thenReturn(NullConstant.INSTANCE);
    when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
    Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(rebasedSignatureToken);
    assertThat(specialMethodInvocation.isValid(), is(true));
    assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) rebasedMethod));
    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).visitInsn(Opcodes.ACONST_NULL);
    verify(methodVisitor).visitMethodInsn(Opcodes.INVOKESPECIAL, BAZ, QUX, FOO, false);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
    assertThat(size.getSizeImpact(), is(1));
    assertThat(size.getMaximalSize(), is(1));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:23,代码来源:RebaseImplementationTargetTest.java

示例6: testRebasedMethodIsInvokable

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testRebasedMethodIsInvokable() throws Exception {
    when(invokableMethod.getDeclaringType()).thenReturn(instrumentedType);
    when(resolution.isRebased()).thenReturn(true);
    when(resolution.getResolvedMethod()).thenReturn(rebasedMethod);
    when(resolution.getAdditionalArguments()).thenReturn(StackManipulation.Trivial.INSTANCE);
    when(rebasedMethod.isSpecializableFor(instrumentedType)).thenReturn(true);
    Implementation.SpecialMethodInvocation specialMethodInvocation = makeImplementationTarget().invokeSuper(rebasedSignatureToken);
    assertThat(specialMethodInvocation.isValid(), is(true));
    assertThat(specialMethodInvocation.getMethodDescription(), is((MethodDescription) rebasedMethod));
    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, QUX, FOO, false);
    verifyNoMoreInteractions(methodVisitor);
    verifyZeroInteractions(implementationContext);
    assertThat(size.getSizeImpact(), is(0));
    assertThat(size.getMaximalSize(), is(0));
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:21,代码来源:RebaseImplementationTargetTest.java

示例7: testConstantCreationLegacy

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Test
public void testConstantCreationLegacy() throws Exception {
    when(classFileVersion.isAtLeast(ClassFileVersion.JAVA_V5)).thenReturn(false);
    when(declaringType.isVisibleTo(instrumentedType)).thenReturn(true);
    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

示例8: testSuperConstructorIsInvokable

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

示例9: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(
    MethodVisitor methodVisitor,
    Context implementationContext,
    MethodDescription instrumentedMethod) {
  Map<String, FieldDescription> fieldsByName = CodeGenUtil.fieldsByName(implementationContext);
  StackManipulation.Size operandStackSize =
      new StackManipulation.Compound(
              new TextConstant(unserializedFieldValue),
              SerializeSupport_serializeString,
              FieldAccess.forField(fieldsByName.get(fieldName)).write())
          .apply(methodVisitor, implementationContext);
  return new Size(operandStackSize.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:curioswitch,项目名称:curiostack,代码行数:15,代码来源:SetSerializedFieldName.java

示例10: appender

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
  return new ByteCodeAppender() {
    @Override
    public Size apply(
        MethodVisitor methodVisitor,
        Context implementationContext,
        MethodDescription instrumentedMethod) {
      StackManipulation.Size size =
          new StackManipulation.Compound(
                  // Load the this reference
                  MethodVariableAccess.REFERENCE.loadFrom(0),
                  // Load the delegate argument
                  MethodVariableAccess.REFERENCE.loadFrom(1),
                  // Invoke the super constructor (default constructor of Object)
                  MethodInvocation.invoke(
                      new TypeDescription.ForLoadedType(DoFnInvokerBase.class)
                          .getDeclaredMethods()
                          .filter(
                              ElementMatchers.isConstructor()
                                  .and(ElementMatchers.takesArguments(DoFn.class)))
                          .getOnly()),
                  // Return void.
                  MethodReturn.VOID)
              .apply(methodVisitor, implementationContext);
      return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
    }
  };
}
 
开发者ID:apache,项目名称:beam,代码行数:30,代码来源:ByteBuddyDoFnInvokerFactory.java

示例11: appender

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public ByteCodeAppender appender(final Target implementationTarget) {
  return new ByteCodeAppender() {
    @Override
    public Size apply(
        MethodVisitor methodVisitor,
        Context implementationContext,
        MethodDescription instrumentedMethod) {
      StackManipulation.Size size =
          new StackManipulation.Compound(
                  // Load the this reference
                  MethodVariableAccess.REFERENCE.loadFrom(0),
                  // Invoke the super constructor (default constructor of Object)
                  MethodInvocation.invoke(
                      new TypeDescription.ForLoadedType(Object.class)
                          .getDeclaredMethods()
                          .filter(
                              ElementMatchers.isConstructor()
                                  .and(ElementMatchers.takesArguments(0)))
                          .getOnly()),
                  // Load the this reference
                  MethodVariableAccess.REFERENCE.loadFrom(0),
                  // Load the delegate argument
                  MethodVariableAccess.REFERENCE.loadFrom(1),
                  // Assign the delegate argument to the delegate field
                  FieldAccess.forField(
                          implementationTarget
                              .getInstrumentedType()
                              .getDeclaredFields()
                              .filter(ElementMatchers.named(FN_DELEGATE_FIELD_NAME))
                              .getOnly())
                      .write(),
                  // Return void.
                  MethodReturn.VOID)
              .apply(methodVisitor, implementationContext);
      return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
    }
  };
}
 
开发者ID:apache,项目名称:beam,代码行数:40,代码来源:ByteBuddyOnTimerInvokerFactory.java

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

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

示例14: apply

import net.bytebuddy.implementation.bytecode.StackManipulation; //导入方法依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext,
                MethodDescription instrumentedMethod) {
    StackManipulation.Size size = loadThis
                    ? MethodVariableAccess.loadThisReferenceAndArguments(instrumentedMethod).apply(methodVisitor,
                                    implementationContext)
                    : MethodVariableAccess.loadArguments(instrumentedMethod).apply(methodVisitor,
                                    implementationContext);
    return new Size(size.getMaximalSize(), instrumentedMethod.getStackSize());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:11,代码来源:LoadArgsAppender.java

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


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