/** {@inheritDoc} */ @Override public DalvInsn withOpcode(Dop opcode) { CstInsn result = new CstInsn(opcode, getPosition(), getRegisters(), constant); if (index >= 0) { result.setIndex(index); } if (classIndex >= 0) { result.setClassIndex(classIndex); } return result; }
/** {@inheritDoc} */ @Override public boolean isCompatible(DalvInsn insn) { if (!(insn instanceof CstInsn)) { return false; } CstInsn ci = (CstInsn) insn; int cpi = ci.getIndex(); if (! unsignedFitsInShort(cpi)) { return false; } Constant cst = ci.getConstant(); if (!((cst instanceof CstMethodRef) || (cst instanceof CstType))) { return false; } RegisterSpecList regs = ci.getRegisters(); return (wordCount(regs) >= 0); }
/** {@inheritDoc} */ @Override public DalvInsn withRegisters(RegisterSpecList registers) { CstInsn result = new CstInsn(getOpcode(), getPosition(), registers, constant); if (index >= 0) { result.setIndex(index); } if (classIndex >= 0) { result.setClassIndex(classIndex); } return result; }
/** * Helper for {@link #assignIndices} which does assignment for one * instruction. * * @param insn {@code non-null;} the instruction * @param callback {@code non-null;} the callback */ private static void assignIndices(CstInsn insn, DalvCode.AssignIndicesCallback callback) { Constant cst = insn.getConstant(); int index = callback.getIndex(cst); if (index >= 0) { insn.setIndex(index); } if (cst instanceof CstMemberRef) { CstMemberRef member = (CstMemberRef) cst; CstType definer = member.getDefiningClass(); index = callback.getIndex(definer); if (index >= 0) { insn.setClassIndex(index); } } }
/** * Helper method to return an instruction comment for a constant. * * @param insn {@code non-null;} a constant-bearing instruction * @return {@code non-null;} comment string representing the constant */ protected static String cstComment(DalvInsn insn) { CstInsn ci = (CstInsn) insn; if (! ci.hasIndex()) { return ""; } StringBuilder sb = new StringBuilder(20); int index = ci.getIndex(); sb.append(ci.getConstant().typeName()); sb.append('@'); if (index < 65536) { sb.append(Hex.u2(index)); } else { sb.append(Hex.u4(index)); } return sb.toString(); }
/** {@inheritDoc} */ @Override public String insnCommentString(DalvInsn insn, boolean noteIndices) { CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant(); return literalBitsComment(value, 16); }
/** {@inheritDoc} */ @Override public void writeTo(AnnotatedOutput out, DalvInsn insn) { RegisterSpecList regs = insn.getRegisters(); int cpi = ((CstInsn) insn).getIndex(); write(out, opcodeUnit(insn, regs.get(0).getReg()), cpi); } }
/** {@inheritDoc} */ @Override public boolean isCompatible(DalvInsn insn) { if (! ALLOW_EXTENDED_OPCODES) { return false; } if (!(insn instanceof CstInsn)) { return false; } CstInsn ci = (CstInsn) insn; Constant cst = ci.getConstant(); if (!((cst instanceof CstMethodRef) || (cst instanceof CstType))) { return false; } RegisterSpecList regs = ci.getRegisters(); int sz = regs.size(); return (regs.size() == 0) || (isRegListSequential(regs) && unsignedFitsInShort(regs.get(0).getReg()) && unsignedFitsInShort(regs.getWordCount())); }
/** {@inheritDoc} */ @Override public String cstComment() { if (!hasIndex()) { return ""; } StringBuilder sb = new StringBuilder(20); sb.append(getConstant().typeName()); sb.append('@'); if (index < 65536) { sb.append(Hex.u2(index)); } else { sb.append(Hex.u4(index)); } return sb.toString(); } }
/** * Returns whether the given instruction is an invoke-static instruction. */ private static boolean isInvokeStaticInstruction(CstInsn cstInsn) { final Dop[] staticInvokeInstructions= { Dops.INVOKE_STATIC, Dops.INVOKE_STATIC_RANGE }; for (Dop dop : staticInvokeInstructions) { if (dop.equals(cstInsn.getOpcode())) { return true; } } return false; }
/** * Helper for {@link #assignIndices} which does assignment for one * instruction. * * @param insn {@code non-null;} the instruction * @param callback {@code non-null;} the callback */ private static void assignIndices(CstInsn insn, DalvCode.AssignIndicesCallback callback) { Constant cst = insn.getConstant(); int index = callback.getIndex(cst); if (index >= 0) { insn.setIndex(index); } if (cst instanceof CstMemberRef) { CstMemberRef member = (CstMemberRef) cst; CstType definer = member.getDefiningClass(); index = callback.getIndex(definer); if (index >= 0) { insn.setClassIndex(index); } } }
/** * Helper method to return an instruction comment for a constant. * * @param insn {@code non-null;} a constant-bearing instruction * @return {@code non-null;} comment string representing the constant */ protected static String cstComment(DalvInsn insn) { CstInsn ci = (CstInsn) insn; if (! ci.hasIndex()) { return ""; } StringBuilder sb = new StringBuilder(20); int index = ci.getIndex(); sb.append(ci.getConstant().typeName()); sb.append('@'); if (index < 65536) { sb.append(Hex.u2(index)); } else { sb.append(Hex.u4(index)); } return sb.toString(); }
/** {@inheritDoc} */ @Override public String insnCommentString(DalvInsn insn, boolean noteIndices) { CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant(); return literalBitsComment(value, 64); }
/** {@inheritDoc} */ @Override public void writeTo(AnnotatedOutput out, DalvInsn insn) { RegisterSpecList regs = insn.getRegisters(); int cpi = ((CstInsn) insn).getIndex(); write(out, opcodeUnit(insn, regs.get(0).getReg()), cpi); } }
/** {@inheritDoc} */ @Override public boolean isCompatible(DalvInsn insn) { if (! ALLOW_EXTENDED_OPCODES) { return false; } if (!(insn instanceof CstInsn)) { return false; } CstInsn ci = (CstInsn) insn; Constant cst = ci.getConstant(); if (!((cst instanceof CstMethodRef) || (cst instanceof CstType))) { return false; } RegisterSpecList regs = ci.getRegisters(); int sz = regs.size(); return (regs.size() == 0) || (isRegListSequential(regs) && unsignedFitsInShort(regs.get(0).getReg()) && unsignedFitsInShort(regs.getWordCount())); }
/** {@inheritDoc} */ @Override public String cstComment() { if (!hasIndex()) { return ""; } StringBuilder sb = new StringBuilder(20); sb.append(getConstant().typeName()); sb.append('@'); if (index < 65536) { sb.append(Hex.u2(index)); } else { sb.append(Hex.u4(index)); } return sb.toString(); } }
/** * Returns whether the given instruction is an invoke instruction that can * be handled by {@link #processInvokeInstruction(CstInsn)}. */ private static boolean isInvokeInstruction(CstInsn cstInsn) { final Dop[] invokeInstructions= { Dops.INVOKE_VIRTUAL, Dops.INVOKE_VIRTUAL_RANGE, Dops.INVOKE_STATIC, Dops.INVOKE_STATIC_RANGE, Dops.INVOKE_DIRECT, Dops.INVOKE_DIRECT_RANGE, Dops.INVOKE_INTERFACE, Dops.INVOKE_INTERFACE_RANGE, Dops.INVOKE_SUPER, Dops.INVOKE_SUPER_RANGE }; for (Dop dop : invokeInstructions) { if (dop.equals(cstInsn.getOpcode())) { return true; } } return false; }
/** {@inheritDoc} */ @Override public DalvInsn withOpcode(Dop opcode) { CstInsn result = new CstInsn(opcode, getPosition(), getRegisters(), constant); if (index >= 0) { result.setIndex(index); } if (classIndex >= 0) { result.setClassIndex(classIndex); } return result; }
/** {@inheritDoc} */ @Override public DalvInsn withRegisters(RegisterSpecList registers) { CstInsn result = new CstInsn(getOpcode(), getPosition(), registers, constant); if (index >= 0) { result.setIndex(index); } if (classIndex >= 0) { result.setClassIndex(classIndex); } return result; }
/** {@inheritDoc} */ @Override public boolean isCompatible(DalvInsn insn) { if (!(insn instanceof CstInsn)) { return false; } CstInsn ci = (CstInsn) insn; int cpi = ci.getIndex(); if (! unsignedFitsInShort(cpi)) { return false; } Constant cst = ci.getConstant(); if (!((cst instanceof CstMethodRef) || (cst instanceof CstType))) { return false; } RegisterSpecList regs = ci.getRegisters(); return (wordCount(regs) >= 0); }