本文整理汇总了Java中net.bytebuddy.implementation.bytecode.StackSize类的典型用法代码示例。如果您正苦于以下问题:Java StackSize类的具体用法?Java StackSize怎么用?Java StackSize使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StackSize类属于net.bytebuddy.implementation.bytecode包,在下文中一共展示了StackSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
final int opcode;
Size size = new Size(-StackSize.of(variableType).getSize() * 2, 0);
if (variableType == int.class || variableType == boolean.class) {
opcode = Opcodes.IF_ICMPEQ;
} else if (variableType == long.class) {
methodVisitor.visitInsn(Opcodes.LCMP);
opcode = Opcodes.IFEQ;
} else if (variableType == float.class) {
methodVisitor.visitInsn(Opcodes.FCMPG);
opcode = Opcodes.IFEQ;
} else if (variableType == double.class) {
methodVisitor.visitInsn(Opcodes.DCMPG);
opcode = Opcodes.IFEQ;
} else {
// Reference type comparison assumes the result of Object.equals is already on the stack.
opcode = Opcodes.IFNE;
// There is only a boolean on the stack, so we only consume one item, unlike the others that
// consume both.
size = new Size(-1, 0);
}
methodVisitor.visitJumpInsn(opcode, destination);
return size;
}
示例2: drainStack
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
/**
* Drains the stack to only contain the top value. For this, the value on top of the stack is temporarily stored
* in the local variable array until all values on the stack are popped off. Subsequently, the top value is pushed
* back onto the operand stack.
*
* @param store The opcode used for storing the top value.
* @param load The opcode used for loading the top value.
* @param size The size of the value on top of the operand stack.
* @return The minimal size of the local variable array that is required to perform the operation.
*/
public int drainStack(int store, int load, StackSize size) {
int difference = current.get(current.size() - 1).getSize() - size.getSize();
if (current.size() == 1 && difference == 0) {
return 0;
} else {
super.visitVarInsn(store, freeIndex);
if (difference == 1) {
super.visitInsn(Opcodes.POP);
} else if (difference != 0) {
throw new IllegalStateException("Unexpected remainder on the operand stack: " + difference);
}
doDrain(current.subList(0, current.size() - 1));
super.visitVarInsn(load, freeIndex);
return freeIndex + size.getSize();
}
}
示例3: doDrain
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
/**
* Drains all supplied elements of the operand stack.
*
* @param stackSizes The stack sizes of the elements to drain.
*/
private void doDrain(List<StackSize> stackSizes) {
ListIterator<StackSize> iterator = stackSizes.listIterator(stackSizes.size());
while (iterator.hasPrevious()) {
StackSize current = iterator.previous();
switch (current) {
case SINGLE:
super.visitInsn(Opcodes.POP);
break;
case DOUBLE:
super.visitInsn(Opcodes.POP2);
break;
default:
throw new IllegalStateException("Unexpected stack size: " + current);
}
}
}
示例4: apply
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
Size size = IntegerConstant.forValue(stackManipulations.size()).apply(methodVisitor, implementationContext);
// The array's construction does not alter the stack's size.
size = size.aggregate(arrayCreator.apply(methodVisitor, implementationContext));
int index = 0;
for (StackManipulation stackManipulation : stackManipulations) {
methodVisitor.visitInsn(Opcodes.DUP);
size = size.aggregate(StackSize.SINGLE.toIncreasingSize());
size = size.aggregate(IntegerConstant.forValue(index++).apply(methodVisitor, implementationContext));
size = size.aggregate(stackManipulation.apply(methodVisitor, implementationContext));
methodVisitor.visitInsn(arrayCreator.getStorageOpcode());
size = size.aggregate(sizeDecrease);
}
return size;
}
示例5: testDrainFreeList
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Test
public void testDrainFreeList() throws Exception {
StackAwareMethodVisitor methodVisitor = new StackAwareMethodVisitor(this.methodVisitor, methodDescription);
methodVisitor.visitLdcInsn(1);
methodVisitor.visitVarInsn(Opcodes.ISTORE, 41);
methodVisitor.visitLdcInsn(1);
methodVisitor.visitLdcInsn(1);
assertThat(methodVisitor.drainStack(Opcodes.ISTORE, Opcodes.ILOAD, StackSize.SINGLE), is(43));
InOrder inOrder = inOrder(this.methodVisitor);
inOrder.verify(this.methodVisitor).visitLdcInsn(1);
inOrder.verify(this.methodVisitor).visitVarInsn(Opcodes.ISTORE, 41);
inOrder.verify(this.methodVisitor, times(2)).visitLdcInsn(1);
inOrder.verify(this.methodVisitor).visitVarInsn(Opcodes.ISTORE, 42);
inOrder.verify(this.methodVisitor).visitInsn(Opcodes.POP);
inOrder.verify(this.methodVisitor).visitVarInsn(Opcodes.ILOAD, 42);
verifyNoMoreInteractions(this.methodVisitor);
}
示例6: testStackSize
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Test
public void testStackSize() throws Exception {
assertThat(describe(void.class).getStackSize(), is(StackSize.ZERO));
assertThat(describe(boolean.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(byte.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(short.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(char.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(int.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(long.class).getStackSize(), is(StackSize.DOUBLE));
assertThat(describe(float.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(double.class).getStackSize(), is(StackSize.DOUBLE));
assertThat(describe(Object.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(SampleClass.class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(Object[].class).getStackSize(), is(StackSize.SINGLE));
assertThat(describe(long[].class).getStackSize(), is(StackSize.SINGLE));
}
示例7: testGenericArrayType
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Test
public void testGenericArrayType() throws Exception {
TypeDescription.Generic typeDescription = describeType(SimpleGenericArrayType.class.getDeclaredField(FOO));
assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.GENERIC_ARRAY));
assertThat(typeDescription.getStackSize(), is(StackSize.SINGLE));
assertThat(typeDescription.getDeclaredFields().size(), is(0));
assertThat(typeDescription.getDeclaredMethods().size(), is(0));
assertThat(typeDescription.getSuperClass(), is(TypeDescription.Generic.OBJECT));
assertThat(typeDescription.getInterfaces(), is(TypeDescription.ARRAY_INTERFACES));
assertThat(typeDescription.getActualName(), is(SimpleGenericArrayType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.getTypeName(), is(SimpleGenericArrayType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.toString(), is(SimpleGenericArrayType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.hashCode(),
is(TypeDefinition.Sort.describe(SimpleGenericArrayType.class.getDeclaredField(FOO).getGenericType()).hashCode()));
assertThat(typeDescription, is(TypeDefinition.Sort.describe(SimpleGenericArrayType.class.getDeclaredField(FOO).getGenericType())));
assertThat(typeDescription, CoreMatchers.not(TypeDefinition.Sort.describe(SimpleGenericArrayType.class.getDeclaredField(FOO).getType())));
assertThat(typeDescription, CoreMatchers.not(new Object()));
assertThat(typeDescription.equals(null), is(false));
assertThat(typeDescription.getComponentType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(typeDescription.getComponentType().getTypeArguments().size(), is(1));
assertThat(typeDescription.getComponentType().getTypeArguments().getOnly().getSort(), is(TypeDefinition.Sort.NON_GENERIC));
assertThat(typeDescription.getComponentType().getTypeArguments().getOnly().asErasure().represents(String.class), is(true));
assertThat(typeDescription.getTypeName(), is(SimpleGenericArrayType.class.getDeclaredField(FOO).getGenericType().toString()));
}
示例8: testGenericArrayOfGenericComponentType
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Test
public void testGenericArrayOfGenericComponentType() throws Exception {
TypeDescription.Generic typeDescription = describeType(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO));
assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.GENERIC_ARRAY));
assertThat(typeDescription.getStackSize(), is(StackSize.SINGLE));
assertThat(typeDescription.getDeclaredFields().size(), is(0));
assertThat(typeDescription.getDeclaredMethods().size(), is(0));
assertThat(typeDescription.getOwnerType(), nullValue(TypeDescription.Generic.class));
assertThat(typeDescription.getSuperClass(), is(TypeDescription.Generic.OBJECT));
assertThat(typeDescription.getInterfaces(), is(TypeDescription.ARRAY_INTERFACES));
assertThat(typeDescription.getActualName(), is(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.getTypeName(), is(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.toString(), is(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.hashCode(),
is(TypeDefinition.Sort.describe(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getGenericType()).hashCode()));
assertThat(typeDescription, is(TypeDefinition.Sort.describe(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getGenericType())));
assertThat(typeDescription, CoreMatchers.not(TypeDefinition.Sort.describe(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getType())));
assertThat(typeDescription, CoreMatchers.not(new Object()));
assertThat(typeDescription.equals(null), is(false));
assertThat(typeDescription.getComponentType().getSort(), is(TypeDefinition.Sort.PARAMETERIZED));
assertThat(typeDescription.getComponentType().getTypeArguments().size(), is(1));
assertThat(typeDescription.getComponentType().getTypeArguments().getOnly().getSort(), is(TypeDefinition.Sort.VARIABLE));
assertThat(typeDescription.getComponentType().getTypeArguments().getOnly().asErasure().represents(String.class), is(true));
assertThat(typeDescription.getTypeName(), is(GenericArrayOfGenericComponentType.class.getDeclaredField(FOO).getGenericType().toString()));
}
示例9: testTypeVariableType
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Test
public void testTypeVariableType() throws Exception {
TypeDescription.Generic typeDescription = describeType(SimpleTypeVariableType.class.getDeclaredField(FOO));
assertThat(typeDescription.getSort(), is(TypeDefinition.Sort.VARIABLE));
assertThat(typeDescription.getActualName(), is(SimpleTypeVariableType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.getTypeName(), is(SimpleTypeVariableType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.toString(), is(SimpleTypeVariableType.class.getDeclaredField(FOO).getGenericType().toString()));
assertThat(typeDescription.hashCode(),
is(TypeDefinition.Sort.describe(SimpleTypeVariableType.class.getDeclaredField(FOO).getGenericType()).hashCode()));
assertThat(typeDescription, is(TypeDefinition.Sort.describe(SimpleTypeVariableType.class.getDeclaredField(FOO).getGenericType())));
assertThat(typeDescription,
CoreMatchers.not(TypeDefinition.Sort.describe(SimpleTypeVariableType.class.getDeclaredField(FOO).getType())));
assertThat(typeDescription, CoreMatchers.not(new Object()));
assertThat(typeDescription.equals(null), is(false));
assertThat(typeDescription.getSymbol(), is(T));
assertThat(typeDescription.getUpperBounds().size(), is(1));
assertThat(typeDescription.getUpperBounds().getOnly(), is(TypeDescription.Generic.OBJECT));
assertThat(typeDescription.getUpperBounds().getOnly().getStackSize(), is(StackSize.SINGLE));
assertThat(typeDescription.getTypeName(), is(SimpleTypeVariableType.class.getDeclaredField(FOO).getGenericType().toString()));
MatcherAssert.assertThat(typeDescription.getTypeVariableSource(), is((TypeVariableSource) new TypeDescription.ForLoadedType(SimpleTypeVariableType.class)));
assertThat(typeDescription.getTypeVariableSource().getTypeVariables().size(), is(1));
assertThat(typeDescription.getTypeVariableSource().getTypeVariables().getOnly(), is(typeDescription));
}
示例10: setUp
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
when(declaringType.asErasure()).thenReturn(declaringType);
when(methodDescription.getDeclaringType()).thenReturn(declaringType);
when(methodDescription.getInternalName()).thenReturn(FOO);
when(methodDescription.getParameters()).thenReturn((ParameterList) parameterList);
when(parameterList.asTypeList()).thenReturn(typeList);
when(declaringType.getDescriptor()).thenReturn(BAR);
when(typeList.asErasures()).thenReturn(rawTypeList);
when(rawTypeList.iterator()).thenReturn(Collections.singletonList(parameterType).iterator());
when(parameterType.getDescriptor()).thenReturn(QUX);
when(fieldDescription.getType()).thenReturn(genericFieldType);
when(fieldDescription.isStatic()).thenReturn(true);
when(genericFieldType.asErasure()).thenReturn(fieldType);
when(genericFieldType.getStackSize()).thenReturn(StackSize.SINGLE);
when(fieldDescription.getDeclaringType()).thenReturn(declaringType);
when(declaringType.getInternalName()).thenReturn(BAZ);
when(fieldDescription.getInternalName()).thenReturn(FOO);
when(fieldDescription.getDescriptor()).thenReturn(QUX);
when(fieldDescription.asDefined()).thenReturn(fieldDescription);
when(implementationContext.getClassFileVersion()).thenReturn(classFileVersion);
when(implementationContext.getInstrumentedType()).thenReturn(instrumentedType);
}
示例11: setUp
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
when(declaringType.getInternalName()).thenReturn(FOO);
when(fieldDescription.getInternalName()).thenReturn(BAR);
when(fieldDescription.getDeclaringType()).thenReturn(declaringType);
when(declaringType.getDescriptor()).thenReturn("L" + QUX + ";");
when(implementationContext.cache(new FieldConstant(fieldDescription), new TypeDescription.ForLoadedType(Field.class)))
.thenReturn(cacheField);
when(cacheField.getDeclaringType()).thenReturn(cacheDeclaringType);
when(cacheField.isStatic()).thenReturn(true);
when(declaringType.getName()).thenReturn(BAZ);
when(cacheDeclaringType.getInternalName()).thenReturn(BAZ);
when(cacheField.getName()).thenReturn(FOO + BAR);
when(cacheField.getType()).thenReturn(genericCacheFieldType);
when(genericCacheFieldType.asErasure()).thenReturn(cacheFieldType);
when(genericCacheFieldType.getStackSize()).thenReturn(StackSize.SINGLE);
when(cacheField.getInternalName()).thenReturn(FOO + BAR);
when(cacheField.getDescriptor()).thenReturn(QUX + BAZ);
when(implementationContext.getClassFileVersion()).thenReturn(classFileVersion);
when(implementationContext.getInstrumentedType()).thenReturn(instrumentedType);
}
示例12: setUp
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
when(methodDescription.asDefined()).thenReturn(methodDescription);
when(methodDescription.getReturnType()).thenReturn(returnType);
when(methodDescription.getDeclaringType()).thenReturn(declaringType);
when(returnType.getStackSize()).thenReturn(StackSize.ZERO);
when(firstType.getStackSize()).thenReturn(StackSize.ZERO);
when(firstType.getDescriptor()).thenReturn(FOO);
when(secondType.getDescriptor()).thenReturn(BAR);
when(secondType.getStackSize()).thenReturn(StackSize.ZERO);
when(returnType.getStackSize()).thenReturn(StackSize.ZERO);
when(methodDescription.getInternalName()).thenReturn(QUX);
when(methodDescription.getDescriptor()).thenReturn(BAZ);
when(declaringType.getDescriptor()).thenReturn(BAR);
when(methodDescription.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(methodDescription, firstType, secondType));
}
示例13: FieldAccessTest
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
public FieldAccessTest(boolean isStatic,
StackSize fieldSize,
int getterChange,
int getterMaximum,
int getterOpcode,
int putterChange,
int putterMaximum,
int putterOpcode) {
this.isStatic = isStatic;
this.fieldSize = fieldSize;
this.getterChange = getterChange;
this.getterMaximum = getterMaximum;
this.getterOpcode = getterOpcode;
this.putterChange = putterChange;
this.putterMaximum = putterMaximum;
this.putterOpcode = putterOpcode;
}
示例14: setUp
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
when(methodDescription.getDeclaringType()).thenReturn(declaringType);
when(declaringType.getStackSize()).thenReturn(StackSize.SINGLE);
when(firstParameterType.getStackSize()).thenReturn(StackSize.SINGLE);
when(firstParameterType.asErasure()).thenReturn(firstRawParameterType);
when(firstParameterType.asGenericType()).thenReturn(firstParameterType);
when(secondParameterType.asErasure()).thenReturn(secondRawParameterType);
when(secondParameterType.getStackSize()).thenReturn(StackSize.SINGLE);
when(secondParameterType.asGenericType()).thenReturn(secondParameterType);
when(methodDescription.getParameters()).thenReturn(new ParameterList.Explicit.ForTypes(methodDescription, firstParameterType, secondParameterType));
when(bridgeMethod.getDeclaringType()).thenReturn(declaringType);
when(secondRawParameterType.getInternalName()).thenReturn(FOO);
when(firstParameterType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(firstParameterType);
when(secondParameterType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(secondParameterType);
}
示例15: testCreationUsing
import net.bytebuddy.implementation.bytecode.StackSize; //导入依赖的package包/类
protected void testCreationUsing(Class<?> componentType, int storageOpcode) throws Exception {
defineComponentType(componentType);
CollectionFactory arrayFactory = ArrayFactory.forType(this.componentType);
StackManipulation arrayStackManipulation = arrayFactory.withValues(Collections.singletonList(stackManipulation));
assertThat(arrayStackManipulation.isValid(), is(true));
verify(stackManipulation, atLeast(1)).isValid();
StackManipulation.Size size = arrayStackManipulation.apply(methodVisitor, implementationContext);
assertThat(size.getSizeImpact(), is(1));
assertThat(size.getMaximalSize(), is(3 + StackSize.of(componentType).toIncreasingSize().getSizeImpact()));
verify(methodVisitor).visitInsn(Opcodes.ICONST_1);
verifyArrayCreation(methodVisitor);
verify(methodVisitor).visitInsn(Opcodes.DUP);
verify(methodVisitor).visitInsn(Opcodes.ICONST_0);
verify(stackManipulation).apply(methodVisitor, implementationContext);
verify(methodVisitor).visitInsn(storageOpcode);
verifyNoMoreInteractions(methodVisitor);
verifyNoMoreInteractions(stackManipulation);
}