List of usage examples for org.objectweb.asm.tree AbstractInsnNode getOpcode
public int getOpcode()
From source file:org.mutabilitydetector.checkers.settermethod.AssignmentGuardVerifier.java
License:Apache License
private static boolean isOtherObjectNotAnInitialValue(final JumpInsn assignmentGuard, final ControlFlowBlock block) { final int indexWithinBlock = assignmentGuard.getIndexWithinBlock(); final AbstractInsnNode predecessorInsn = block.getBlockInstructionForIndex(indexWithinBlock - 2); final boolean result; if (ACONST_NULL != predecessorInsn.getOpcode()) { result = false;// w ww . j a v a 2 s . c om } else { result = true; } return result; }
From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnFinder.java
License:Apache License
private static boolean isPutfieldInstruction(final AbstractInsnNode insn) { return Opcodes.PUTFIELD == insn.getOpcode(); }
From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnFinder.java
License:Apache License
private static boolean isPutstaticInstruction(final AbstractInsnNode insn) { return Opcodes.PUTSTATIC == insn.getOpcode(); }
From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnVerifier.java
License:Apache License
private static boolean isAliasLoadInstruction(final AbstractInsnNode insn, final int aliasLocalVariable) { switch (insn.getOpcode()) { case Opcodes.ILOAD: case Opcodes.LLOAD: case Opcodes.FLOAD: case Opcodes.DLOAD: case Opcodes.ALOAD: final VarInsnNode varInsnNode = (VarInsnNode) insn; return aliasLocalVariable == varInsnNode.var; default:// w w w . j a va 2s. co m return false; } }
From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnVerifier.java
License:Apache License
private static boolean isAliasStoreInstruction(final AbstractInsnNode insn, final int aliasLocalVariable) { switch (insn.getOpcode()) { case Opcodes.ISTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: case Opcodes.ASTORE: final VarInsnNode varInsnNode = (VarInsnNode) insn; return aliasLocalVariable == varInsnNode.var; default:/*from w w w . j a v a 2 s. co m*/ return false; } }
From source file:org.mutabilitydetector.checkers.settermethod.EffectiveAssignmentInsnVerifier.java
License:Apache License
private boolean isNotPushConstantOntoStackInstruction(final AbstractInsnNode insn) { final Opcode opcode = Opcode.forInt(insn.getOpcode()); final Collection<Opcode> stackPushingConstants = Opcode.constants(); return !stackPushingConstants.contains(opcode); }
From source file:org.neptunepowered.vanilla.launch.transformer.AccessTransformer.java
License:MIT License
@Override public byte[] transform(String name, String transformedName, byte[] bytes) { if (bytes == null || !this.modifiers.containsKey(transformedName)) { return bytes; }// ww w . ja v a 2s. co m ClassNode classNode = new ClassNode(); ClassReader reader = new ClassReader(bytes); reader.accept(classNode, 0); for (Modifier m : this.modifiers.get(transformedName)) { if (m.isClass) { // Class classNode.access = m.transform(classNode.access); } else if (m.desc == null) { // Field for (FieldNode fieldNode : classNode.fields) { if (m.wildcard || fieldNode.name.equals(m.name)) { fieldNode.access = m.transform(fieldNode.access); if (!m.wildcard) { break; } } } } else { List<MethodNode> overridable = null; for (MethodNode methodNode : classNode.methods) { if (m.wildcard || (methodNode.name.equals(m.name) && methodNode.desc.equals(m.desc))) { boolean wasPrivate = (methodNode.access & ACC_PRIVATE) != 0; methodNode.access = m.transform(methodNode.access); // Constructors always use INVOKESPECIAL // if we changed from private to something else we need to replace all INVOKESPECIAL calls to // this method with INVOKEVIRTUAL // so that overridden methods will be called. Only need to scan this class, because obviously // the method was private. if (!methodNode.name.equals("<init>") && wasPrivate && (methodNode.access & ACC_PRIVATE) == 0) { if (overridable == null) { overridable = Lists.newArrayListWithExpectedSize(3); } overridable.add(methodNode); } if (!m.wildcard) { break; } } } if (overridable != null) { for (MethodNode methodNode : classNode.methods) { for (Iterator<AbstractInsnNode> itr = methodNode.instructions.iterator(); itr.hasNext();) { AbstractInsnNode insn = itr.next(); if (insn.getOpcode() == INVOKESPECIAL) { MethodInsnNode mInsn = (MethodInsnNode) insn; for (MethodNode replace : overridable) { if (replace.name.equals(mInsn.name) && replace.desc.equals(mInsn.desc)) { mInsn.setOpcode(INVOKEVIRTUAL); break; } } } } } } } } ClassWriter writer = new ClassWriter(0); classNode.accept(writer); return writer.toByteArray(); }
From source file:org.parboiled.transform.process.ImplicitActionsConverter.java
License:Apache License
private boolean isStoredIntoObjectArray(final InstructionGraphNode node) { // is the single dependent an AASTORE instruction ? final AbstractInsnNode insn = node.getInstruction(); if (insn.getOpcode() != AASTORE) return false; // Does this instruction store into an array of Object ? final List<InstructionGraphNode> dependents = getDependents(node); // an AASTORE instruction should have exactly one dependent Preconditions.checkState(dependents.size() == 1); final AbstractInsnNode newArrayInsn = dependents.get(0).getInstruction(); // which should be a n ANEWARRAY instruction Preconditions.checkState(newArrayInsn.getOpcode() == ANEWARRAY); final String desc = ((TypeInsnNode) newArrayInsn).desc; return CodegenUtils.p(Object.class).equals(desc); }
From source file:org.parboiled.transform.process.LabellingGenerator.java
License:Apache License
@Override public void process(@Nonnull final ParserClassNode classNode, @Nonnull final RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); // super methods have flag moved to the overriding method Preconditions.checkState(!method.isSuperMethod()); final InsnList instructions = method.instructions; AbstractInsnNode retInsn = instructions.getLast(); while (retInsn.getOpcode() != ARETURN) retInsn = retInsn.getPrevious(); final LabelNode label = new LabelNode(); final CodeBlock block = CodeBlock.newCodeBlock().dup().ifnull(label).ldc(getLabelText(method)) .invokeinterface(CodegenUtils.p(Rule.class), "label", CodegenUtils.sig(Rule.class, String.class)) .label(label);//from w w w . j a v a 2s . co m instructions.insertBefore(retInsn, block.getInstructionList()); }
From source file:org.parboiled.transform.process.ReturnInstructionUnifier.java
License:Apache License
@Override public void process(@Nonnull final ParserClassNode classNode, @Nonnull final RuleMethod method) throws Exception { Objects.requireNonNull(classNode, "classNode"); Objects.requireNonNull(method, "method"); AbstractInsnNode current = method.instructions.getLast(); // find last return while (current.getOpcode() != ARETURN) current = current.getPrevious(); final LabelNode lastReturnLabel = new LabelNode(); method.instructions.insertBefore(current, lastReturnLabel); // iterate backwards up to first instructions while ((current = current.getPrevious()) != null) { // replace returns with gotos if (current.getOpcode() != ARETURN) continue; final JumpInsnNode insn = new JumpInsnNode(GOTO, lastReturnLabel); method.instructions.set(current, insn); current = insn;/*from www . j a v a 2 s .com*/ } }