org.objectweb.asm.Label Java Examples

The following examples show how to use org.objectweb.asm.Label. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrayIndexAdapter.java    From yql-plus with Apache License 2.0 6 votes vote down vote up
@Override
public BytecodeExpression length(final BytecodeExpression inputExpr) {
    return new BaseTypeExpression(BaseTypeAdapter.INT32) {
        @Override
        public void generate(CodeEmitter code) {
            Label done = new Label();
            Label isNull = new Label();
            MethodVisitor mv = code.getMethodVisitor();
            code.exec(inputExpr);
            boolean nullable = code.nullTest(inputExpr.getType(), isNull);
            mv.visitInsn(Opcodes.ARRAYLENGTH);
            if (nullable) {
                mv.visitJumpInsn(Opcodes.GOTO, done);
                mv.visitLabel(isNull);
                mv.visitInsn(Opcodes.ICONST_0);
                mv.visitLabel(done);
            }
        }
    };
}
 
Example #2
Source File: OperatorTests.java    From Despector with MIT License 6 votes vote down vote up
@Test
public void testDiv() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(III)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    mv.visitIntInsn(ILOAD, 1);
    mv.visitIntInsn(ILOAD, 2);
    mv.visitInsn(IDIV);
    mv.visitIntInsn(ISTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "I", null, start, end, 0);
    mv.visitLocalVariable("a", "I", null, start, end, 1);
    mv.visitLocalVariable("b", "I", null, start, end, 2);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = a / b;";
    Assert.assertEquals(good, insn);
}
 
Example #3
Source File: EmitUtils.java    From cglib with Apache License 2.0 6 votes vote down vote up
/**
 * Process an array on the stack. Assumes the top item on the stack
 * is an array of the specified type. For each element in the array,
 * puts the element on the stack and triggers the callback.
 * @param type the type of the array (type.isArray() must be true)
 * @param callback the callback triggered for each element
 */
public static void process_array(CodeEmitter e, Type type, ProcessArrayCallback callback) {
    Type componentType = TypeUtils.getComponentType(type);
    Local array = e.make_local();
    Local loopvar = e.make_local(Type.INT_TYPE);
    Label loopbody = e.make_label();
    Label checkloop = e.make_label();
    e.store_local(array);
    e.push(0);
    e.store_local(loopvar);
    e.goTo(checkloop);
    
    e.mark(loopbody);
    e.load_local(array);
    e.load_local(loopvar);
    e.array_load(componentType);
    callback.processElement(componentType);
    e.iinc(loopvar, 1);
    
    e.mark(checkloop);
    e.load_local(loopvar);
    e.load_local(array);
    e.arraylength();
    e.if_icmp(e.LT, loopbody);
}
 
Example #4
Source File: BinaryIntExpressionHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * writes a std compare. This involves the tokens IF_ICMPEQ, IF_ICMPNE, 
 * IF_ICMPEQ, IF_ICMPNE, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE and IF_ICMPLT
 * @param type the token type
 * @return true if a successful std compare write
 */
protected boolean writeStdCompare(int type, boolean simulate) {
    type = type-COMPARE_NOT_EQUAL;
    // look if really compare
    if (type<0||type>7) return false;

    if (!simulate) {
        MethodVisitor mv = getController().getMethodVisitor();
        OperandStack operandStack = getController().getOperandStack();
        // operands are on the stack already
        int bytecode = stdCompareCodes[type];
        Label l1 = new Label();
        mv.visitJumpInsn(bytecode,l1);
        mv.visitInsn(ICONST_1);
        Label l2 = new Label();
        mv.visitJumpInsn(GOTO, l2);
        mv.visitLabel(l1);
        mv.visitInsn(ICONST_0);
        mv.visitLabel(l2);
        operandStack.replace(ClassHelper.boolean_TYPE, 2);
    }
    return true;
}
 
Example #5
Source File: OperatorTests.java    From Despector with MIT License 6 votes vote down vote up
@Test
public void testTypeConstant() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "(I)V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    mv.visitLabel(start);
    Label end = new Label();
    mv.visitLdcInsn(Type.getType("Ljava/lang/String;"));
    mv.visitIntInsn(ASTORE, 0);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);
    mv.visitLocalVariable("i", "Ljava/lang/Class;", null, start, end, 0);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "i = String.class;";
    Assert.assertEquals(good, insn);
}
 
Example #6
Source File: InstructionBuilder.java    From jaxrs-analyzer with Apache License 2.0 6 votes vote down vote up
public static Instruction buildFieldInstruction(final int opcode, final String ownerClass, final String name, final String desc, final Label label) {
    // TODO remove
    if (org.objectweb.asm.Type.getObjectType(ownerClass).getClassName().equals(ownerClass.replace('.', '/')))
        throw new AssertionError("!");

    final String opcodeName = OPCODES[opcode];

    switch (opcode) {
        case GETSTATIC:
            final Object value = getStaticValue(name, ownerClass);
            return new GetStaticInstruction(ownerClass, name, desc, value, label);
        case PUTSTATIC:
            return new SizeChangingInstruction(opcodeName, 0, 1, label);
        case GETFIELD:
            return new GetFieldInstruction(ownerClass, name, desc, label);
        case PUTFIELD:
            return new SizeChangingInstruction(opcodeName, 0, 2, label);
        default:
            throw new IllegalArgumentException("Opcode " + opcode + " not a field instruction");
    }
}
 
Example #7
Source File: InsnListPrinter.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void visitInsnList(InsnList list) {
	text.clear();
	if (labelNames == null) {
		labelNames = new HashMap<Label, String>();
	} else {
		labelNames.clear();
	}

	buildingLabelMap = true;
	for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
		if (insn.getType() == 8) {
			visitLabel(((LabelNode) insn).getLabel());
		}
	}

	text.clear();
	buildingLabelMap = false;

	for (AbstractInsnNode insn = list.getFirst(); insn != null; insn = insn.getNext()) {
		_visitInsn(insn);
	}
}
 
Example #8
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public void visitLocalVariable(
    final String name,
    final String descriptor,
    final String signature,
    final Label start,
    final Label end,
    final int index) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  checkUnqualifiedName(version, name, "name");
  checkDescriptor(version, descriptor, false);
  checkLabel(start, true, START_LABEL);
  checkLabel(end, true, END_LABEL);
  checkUnsignedShort(index, INVALID_LOCAL_VARIABLE_INDEX);
  int startInsnIndex = labelInsnIndices.get(start).intValue();
  int endInsnIndex = labelInsnIndices.get(end).intValue();
  if (endInsnIndex < startInsnIndex) {
    throw new IllegalArgumentException(
        "Invalid start and end labels (end must be greater than start)");
  }
  super.visitLocalVariable(name, descriptor, signature, start, end, index);
}
 
Example #9
Source File: RemoveConditionalMutator.java    From pitest with Apache License 2.0 6 votes vote down vote up
@Override
public void visitJumpInsn(final int opcode, final Label label) {

  if (canMutate(opcode)) {
    final MutationIdentifier newId = this.context.registerMutation(
        this.factory, this.description);

    if (this.context.shouldMutate(newId)) {
      emptyStack(opcode);
      if (!RemoveConditionalMutator.this.replaceWith) {
        super.visitJumpInsn(Opcodes.GOTO, label);
      }
    } else {
      this.mv.visitJumpInsn(opcode, label);
    }
  } else {
    this.mv.visitJumpInsn(opcode, label);
  }

}
 
Example #10
Source File: MethodTests.java    From Despector with MIT License 6 votes vote down vote up
@Test
public void testStaticInvoke() {
    TestMethodBuilder builder = new TestMethodBuilder("test_mth", "()V");
    MethodVisitor mv = builder.getGenerator();
    Label start = new Label();
    Label end = new Label();
    mv.visitLabel(start);
    mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
    mv.visitLdcInsn("Hello World!");
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false);
    mv.visitLabel(end);
    mv.visitInsn(RETURN);

    String insn = TestHelper.getAsString(builder.finish(), "test_mth");
    String good = "System.out.println(\"Hello World!\");";
    Assert.assertEquals(good, insn);
}
 
Example #11
Source File: EntityPlayerVisitor.java    From ForgeWurst with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void visitCode()
{
	System.out.println("EntityPlayerVisitor.JumpVisitor.visitCode()");
	
	super.visitCode();
	mv.visitVarInsn(Opcodes.ALOAD, 0);
	mv.visitMethodInsn(Opcodes.INVOKESTATIC,
		"net/wurstclient/forge/compatibility/WEventFactory",
		"entityPlayerJump",
		"(Lnet/minecraft/entity/player/EntityPlayer;)Z", false);
	Label l1 = new Label();
	mv.visitJumpInsn(Opcodes.IFNE, l1);
	mv.visitInsn(Opcodes.RETURN);
	mv.visitLabel(l1);
	mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
}
 
Example #12
Source File: ContinuableMethodNode.java    From tascalate-javaflow with Apache License 2.0 5 votes vote down vote up
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
    MethodInsnNode mnode = new MethodInsnNode(opcode, owner, name, desc);
    if (opcode == INVOKESPECIAL || "<init>".equals(name)) {
        methods.add(mnode);
    }
    if (needsFrameGuard(opcode, owner, name, desc)) {
        Label label = new Label();
        super.visitLabel(label);
        labels.add(label);
        nodes.add(mnode);
    }
    instructions.add(mnode);
}
 
Example #13
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitTableSwitchInsn(final int min, final int max, final Label dflt, final Label... labels) {
  buf.setLength(0);
  buf.append(tab2).append("TABLESWITCH\n");
  for (int i = 0; i < labels.length; ++i) {
    buf.append(tab3).append(min + i).append(": ");
    appendLabel(labels[i]);
    buf.append('\n');
  }
  buf.append(tab3).append("default: ");
  appendLabel(dflt);
  buf.append('\n');
  text.add(buf.toString());
}
 
Example #14
Source File: GizmoMethodVisitor.java    From gizmo with Apache License 2.0 5 votes vote down vote up
public void visitIntInsn(final int opcode, final int operand) {
    checkMethod();
    final int lineNumber = cv.getLineNumber();
    cv.append(getOpString(opcode)).append(' ').append(operand).newLine();
    final Label label = new Label();
    super.visitLabel(label);
    super.visitLineNumber(lineNumber, label);
    super.visitIntInsn(opcode, operand);
}
 
Example #15
Source File: AdviceAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) {
  super.visitLookupSwitchInsn(dflt, keys, labels);
  if (isConstructor && !superClassConstructorCalled) {
    popValue();
    addForwardJumps(dflt, labels);
  }
}
 
Example #16
Source File: RuleMethod.java    From grappa with Apache License 2.0 5 votes vote down vote up
@Override
public void visitLookupSwitchInsn(final Label dflt, final int[] keys,
    final Label[] labels)
{
    usedLabels.add(getLabelNode(dflt));
    for (final Label label : labels)
        usedLabels.add(getLabelNode(label));
    super.visitLookupSwitchInsn(dflt, keys, labels);
}
 
Example #17
Source File: AdviceAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public void visitLookupSwitchInsn(final Label dflt, final int[] keys, final Label[] labels) {
  super.visitLookupSwitchInsn(dflt, keys, labels);
  if (isConstructor && !superClassConstructorCalled) {
    popValue();
    addForwardJumps(dflt, labels);
  }
}
 
Example #18
Source File: CodeEmitter.java    From yql-plus with Apache License 2.0 5 votes vote down vote up
public void emitStringSwitch(Map<String, Label> labels, Label defaultCase, boolean caseInsensitive) {
    MethodVisitor mv = getMethodVisitor();
    if (caseInsensitive) {
        mv.visitFieldInsn(GETSTATIC, "java/util/Locale", "ENGLISH", "Ljava/util/Locale;");
        mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "toUpperCase", "(Ljava/util/Locale;)Ljava/lang/String;", false);
    }
    mv.visitInsn(DUP);
    AssignableValue tmp = allocate(String.class);
    tmp.write(BaseTypeAdapter.STRING).generate(this);
    mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
    Multimap<Integer, SwitchLabel> keys = ArrayListMultimap.create();
    for (Map.Entry<String, Label> e : labels.entrySet()) {
        String name = e.getKey();
        if (caseInsensitive) {
            name = name.toUpperCase(Locale.ENGLISH);
        }
        keys.put(name.hashCode(), new SwitchLabel(name, e.getValue()));
    }
    List<Integer> codes = Lists.newArrayList(keys.keySet());
    Collections.sort(codes);
    int[] k = new int[codes.size()];
    Label[] kl = new Label[codes.size()];
    for (int i = 0; i < k.length; ++i) {
        k[i] = codes.get(i);
        kl[i] = new Label();
    }
    mv.visitLookupSwitchInsn(defaultCase, k, kl);
    for (int i = 0; i < k.length; ++i) {
        mv.visitLabel(kl[i]);
        for (SwitchLabel switchLabel : keys.get(k[i])) {
            mv.visitLdcInsn(switchLabel.name);
            tmp.read().generate(this);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
            mv.visitJumpInsn(IFNE, switchLabel.label);
        }
        mv.visitJumpInsn(GOTO, defaultCase);
    }
}
 
Example #19
Source File: ExpressionNeg.java    From datakernel with Apache License 2.0 5 votes vote down vote up
@Override
	public Type load(Context ctx) {
		GeneratorAdapter g = ctx.getGeneratorAdapter();
		Type argType = arg.load(ctx);
		int argSort = argType.getSort();

		if (argSort == Type.DOUBLE || argSort == Type.FLOAT || argSort == Type.LONG || argSort == Type.INT) {
			g.math(GeneratorAdapter.NEG, argType);
			return argType;
		}
		if (argSort == Type.BYTE || argSort == Type.SHORT || argSort == Type.CHAR) {
//			g.cast(argType, INT_TYPE);
			g.math(GeneratorAdapter.NEG, INT_TYPE);
			return argType;
		}

		if (argSort == Type.BOOLEAN) {
			Label labelTrue = new Label();
			Label labelExit = new Label();
			g.push(true);
			g.ifCmp(BOOLEAN_TYPE, GeneratorAdapter.EQ, labelTrue);
			g.push(true);
			g.goTo(labelExit);

			g.mark(labelTrue);
			g.push(false);

			g.mark(labelExit);
			return INT_TYPE;
		}

		throw new RuntimeException(format("%s is not primitive. %s",
				ctx.toJavaType(argType),
				exceptionInGeneratedClass(ctx))
		);
	}
 
Example #20
Source File: OffHeapAugmentor.java    From Concurnas with MIT License 5 votes vote down vote up
private void createConstuctorWithDefaultInit(){
//add initUncreatable and boolean[]
  	
  	{//toBinary
	MethodVisitor mv = super.visitMethod(ACC_PUBLIC, "<init>", "(Lcom/concurnas/bootstrap/runtime/InitUncreatable;[Z)V", null, null);
	mv.visitCode();
	mv.visitLabel(new Label());
	
	mv.visitVarInsn(ALOAD, 0);
	
	if(superclassname.equals("java/lang/Object")){
		mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
	}else if(superclassname.equals("com/concurnas/bootstrap/runtime/cps/CObject")){
		mv.visitMethodInsn(INVOKESPECIAL, "com/concurnas/bootstrap/runtime/cps/CObject", "<init>", "()V");
	}else{
		mv.visitVarInsn(ALOAD, 1);
		mv.visitVarInsn(ALOAD, 2);
		mv.visitMethodInsn(INVOKESPECIAL, superclassname, "<init>", "(Lcom/concurnas/bootstrap/runtime/InitUncreatable;[Z)V");
	}
	
	mv.visitVarInsn(ALOAD, 0);
	mv.visitVarInsn(ALOAD, 1);
	mv.visitVarInsn(ALOAD, 2);
	mv.visitMethodInsn(INVOKESPECIAL, classname, "defaultFieldInit$", "(Lcom/concurnas/bootstrap/runtime/InitUncreatable;[Z)V");
	mv.visitInsn(RETURN);
	mv.visitMaxs(2, 2);
	mv.visitEnd();
}
  	
  }
 
Example #21
Source File: AnalyzerAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitJumpInsn(final int opcode, final Label label) {
  super.visitJumpInsn(opcode, label);
  execute(opcode, 0, null);
  if (opcode == Opcodes.GOTO) {
    this.locals = null;
    this.stack = null;
  }
}
 
Example #22
Source File: Textifier.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitTryCatchBlock(
    final Label start, final Label end, final Label handler, final String type) {
  stringBuilder.setLength(0);
  stringBuilder.append(tab2).append("TRYCATCHBLOCK ");
  appendLabel(start);
  stringBuilder.append(' ');
  appendLabel(end);
  stringBuilder.append(' ');
  appendLabel(handler);
  stringBuilder.append(' ');
  appendDescriptor(INTERNAL_NAME, type);
  stringBuilder.append('\n');
  text.add(stringBuilder.toString());
}
 
Example #23
Source File: ASMContentHandler.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public final void begin(final String name, final Attributes attrs) {
  Label start = getLabel(attrs.getValue("start"));
  Label end = getLabel(attrs.getValue("end"));
  Label handler = getLabel(attrs.getValue("handler"));
  String type = attrs.getValue("type");
  getCodeVisitor().visitTryCatchBlock(start, end, handler, type);
}
 
Example #24
Source File: SwitchMutator.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public void visitTableSwitchInsn(final int i, final int i1,
    final Label defaultLabel, final Label... labels) {
  final Label newDefault = firstDifferentLabel(labels, defaultLabel);
  if ((newDefault != null) && shouldMutate()) {
    final Label[] newLabels = swapLabels(labels, defaultLabel, newDefault);
    super.visitTableSwitchInsn(i, i1, newDefault, newLabels);
  } else {
    super.visitTableSwitchInsn(i, i1, defaultLabel, labels);
  }
}
 
Example #25
Source File: AvoidStringSwitchedMethodAdapter.java    From pitest with Apache License 2.0 5 votes vote down vote up
@Override
public void visitLineNumber(int line, Label start) {
  super.visitLineNumber(line, start);
  // if compiler emits a line number switch statement (probably) contains user
  // generated code
  enableMutation();
}
 
Example #26
Source File: ClassParserUsingASM.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) {
    sawBranchTo(dflt);
    for (Label lbl : labels) {
        sawBranchTo(lbl);
    }
    identityState = IdentityMethodState.NOT;
    super.visitTableSwitchInsn(min, max, dflt, labels);
}
 
Example #27
Source File: BuildStackInfoAdapter.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
public LocalVariable(String name, String declaredDescriptor, Label from, Label to, int index) {
    this.name = name;
    this.fromLine = getLineNumber(from);
    this.toLine = getLineNumber(to);
    if (this.toLine[0] == -1)
        this.toLine[0] = Integer.MAX_VALUE;
    this.index = index;
    this.declaredDescriptor = declaredDescriptor;
}
 
Example #28
Source File: ConstructorThisInterpreterTest.java    From AVM with MIT License 5 votes vote down vote up
private MethodNode buildTestConstructor() {
    MethodNode methodVisitor = new MethodNode(Opcodes.ACC_PUBLIC, "<init>", "(Lorg/aion/avm/core/persistence/ConstructorThisInterpreterTest;I)V", null, null);
    methodVisitor.visitCode();
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
    methodVisitor.visitInsn(Opcodes.ICONST_5);
    methodVisitor.visitVarInsn(Opcodes.ILOAD, 2);
    Label label2 = new Label();
    methodVisitor.visitJumpInsn(Opcodes.IF_ICMPNE, label2);
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    Label label3 = new Label();
    methodVisitor.visitJumpInsn(Opcodes.GOTO, label3);
    methodVisitor.visitLabel(label2);
    methodVisitor.visitFrame(Opcodes.F_FULL, 3, new Object[] {"org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", Opcodes.INTEGER}, 0, new Object[] {});
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitLabel(label3);
    methodVisitor.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] {"org/aion/avm/core/persistence/ConstructorThisInterpreterTest"});
    methodVisitor.visitVarInsn(Opcodes.ILOAD, 2);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I");
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    methodVisitor.visitInsn(Opcodes.ICONST_1);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I");
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 1);
    methodVisitor.visitInsn(Opcodes.ICONST_2);
    methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, "org/aion/avm/core/persistence/ConstructorThisInterpreterTest", "bar", "I");
    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(2, 3);
    methodVisitor.visitEnd();
    return methodVisitor;
}
 
Example #29
Source File: SizeChangingInstruction.java    From jaxrs-analyzer with Apache License 2.0 5 votes vote down vote up
public SizeChangingInstruction(final String description, final int numberOfPushes, final int numberOfPops, final Label label) {
    super(description, label);

    if (numberOfPushes < 0 || numberOfPops < 0)
        throw new IllegalArgumentException("Number of pushes and pops cannot be negative");

    this.numberOfPushes = numberOfPushes;
    this.numberOfPops = numberOfPops;
}
 
Example #30
Source File: ModuleHashesAttribute.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
protected Attribute read(
    final ClassReader classReader,
    final int offset,
    final int length,
    final char[] charBuffer,
    final int codeAttributeOffset,
    final Label[] labels) {
  int currentOffset = offset;

  String hashAlgorithm = classReader.readUTF8(currentOffset, charBuffer);
  currentOffset += 2;

  int numModules = classReader.readUnsignedShort(currentOffset);
  currentOffset += 2;

  ArrayList<String> moduleList = new ArrayList<String>(numModules);
  ArrayList<byte[]> hashList = new ArrayList<byte[]>(numModules);

  for (int i = 0; i < numModules; ++i) {
    String module = classReader.readModule(currentOffset, charBuffer);
    currentOffset += 2;
    moduleList.add(module);

    int hashLength = classReader.readUnsignedShort(currentOffset);
    currentOffset += 2;
    byte[] hash = new byte[hashLength];
    for (int j = 0; j < hashLength; ++j) {
      hash[j] = (byte) (classReader.readByte(currentOffset) & 0xFF);
      currentOffset += 1;
    }
    hashList.add(hash);
  }
  return new ModuleHashesAttribute(hashAlgorithm, moduleList, hashList);
}