Commit 0f39c2fc authored by Lubomir Bulej's avatar Lubomir Bulej

Unified white space to simplify upcoming merges.

parent 0d3f8595
......@@ -4,7 +4,7 @@ package ch.usi.dag.disl.dynamiccontext;
* <p>
* Provides access to dynamic information available at runtime at the location
* where the snippet is inlined.
*
*
* <p>
* <ul>
* <li>{@link #getThis()}</li>
......@@ -33,12 +33,12 @@ public interface DynamicContext {
/**
* <p>
* Returns the value of a particular item on the JVM operand stack.
*
*
* <p>
* <b>Note:</b> Each item index corresponds to one operand on the stack.
* Both primitive and wide values are considered to be a single item, i.e.,
* the index of the corresponding stack slot is determined automatically.
*
*
* @param itemIndex
* <p>
* index of the item on the operand stack, must be positive and
......@@ -58,12 +58,12 @@ public interface DynamicContext {
/**
* <p>
* Returns the value of a particular method argument.
*
*
* <p>
* <b>Note:</b> Each argument index corresponds to one method argument, be
* it primitive or wide, i.e., the index of the corresponding local variable
* slot is determined automatically.
*
*
* @param argumentIndex
* <p>
* index of the desired method argument, must be positive and not
......@@ -84,12 +84,12 @@ public interface DynamicContext {
* Returns the value of a local variable occupying a particular local
* variable slot (or two slots, in case of wide types such as long and
* double).
*
*
* <p>
* <b>Note:</b> Each slot index corresponds to one local variable slot. The
* value of wide values is obtained from two consecutive local variable
* slots, starting with the given slot index.
*
*
* @param slotIndex
* <p>
* index of the desired local variable slot, must be positive and
......
This diff is collapsed.
......@@ -4,225 +4,225 @@ import org.objectweb.asm.tree.AbstractInsnNode;
public enum AsmOpcodes {
// NOTE this opcode list is generated from org.objectweb.asm.Opcodes.java
// This list should be in sync with corresponding file which is supplied
// with asm
// NOTE this opcode list is generated from org.objectweb.asm.Opcodes.java
// This list should be in sync with corresponding file which is supplied
// with asm
// NOTE The commented one are not used by ASM
NOP(0),
ACONST_NULL(1),
ICONST_M1(2),
ICONST_0(3),
ICONST_1(4),
ICONST_2(5),
ICONST_3(6),
ICONST_4(7),
ICONST_5(8),
LCONST_0(9),
LCONST_1(10),
FCONST_0(11),
FCONST_1(12),
FCONST_2(13),
DCONST_0(14),
DCONST_1(15),
BIPUSH(16),
SIPUSH(17),
LDC(18),
//LDC_W(19),
//LDC2_W(20),
ILOAD(21),
LLOAD(22),
FLOAD(23),
DLOAD(24),
ALOAD(25),
//ILOAD_0(26),
//ILOAD_1(27),
//ILOAD_2(28),
//ILOAD_3(29),
//LLOAD_0(30),
//LLOAD_1(31),
//LLOAD_2(32),
//LLOAD_3(33),
//FLOAD_0(34),
//FLOAD_1(35),
//FLOAD_2(36),
//FLOAD_3(37),
//DLOAD_0(38),
//DLOAD_1(39),
//DLOAD_2(40),
//DLOAD_3(41),
//ALOAD_0(42),
//ALOAD_1(43),
//ALOAD_2(44),
//ALOAD_3(45),
IALOAD(46),
LALOAD(47),
FALOAD(48),
DALOAD(49),
AALOAD(50),
BALOAD(51),
CALOAD(52),
SALOAD(53),
ISTORE(54),
LSTORE(55),
FSTORE(56),
DSTORE(57),
ASTORE(58),
//ISTORE_0(59),
//ISTORE_1(60),
//ISTORE_2(61),
//ISTORE_3(62),
//LSTORE_0(63),
//LSTORE_1(64),
//LSTORE_2(65),
//LSTORE_3(66),
//FSTORE_0(67),
//FSTORE_1(68),
//FSTORE_2(69),
//FSTORE_3(70),
//DSTORE_0(71),
//DSTORE_1(72),
//DSTORE_2(73),
//DSTORE_3(74),
//ASTORE_0(75),
//ASTORE_1(76),
//ASTORE_2(77),
//ASTORE_3(78),
IASTORE(79),
LASTORE(80),
FASTORE(81),
DASTORE(82),
AASTORE(83),
BASTORE(84),
CASTORE(85),
SASTORE(86),
POP(87),
POP2(88),
DUP(89),
DUP_X1(90),
DUP_X2(91),
DUP2(92),
DUP2_X1(93),
DUP2_X2(94),
SWAP(95),
IADD(96),
LADD(97),
FADD(98),
DADD(99),
ISUB(100),
LSUB(101),
FSUB(102),
DSUB(103),
IMUL(104),
LMUL(105),
FMUL(106),
DMUL(107),
IDIV(108),
LDIV(109),
FDIV(110),
DDIV(111),
IREM(112),
LREM(113),
FREM(114),
DREM(115),
INEG(116),
LNEG(117),
FNEG(118),
DNEG(119),
ISHL(120),
LSHL(121),
ISHR(122),
LSHR(123),
IUSHR(124),
LUSHR(125),
IAND(126),
LAND(127),
IOR(128),
LOR(129),
IXOR(130),
LXOR(131),
IINC(132),
I2L(133),
I2F(134),
I2D(135),
L2I(136),
L2F(137),
L2D(138),
F2I(139),
F2L(140),
F2D(141),
D2I(142),
D2L(143),
D2F(144),
I2B(145),
I2C(146),
I2S(147),
LCMP(148),
FCMPL(149),
FCMPG(150),
DCMPL(151),
DCMPG(152),
IFEQ(153),
IFNE(154),
IFLT(155),
IFGE(156),
IFGT(157),
IFLE(158),
IF_ICMPEQ(159),
IF_ICMPNE(160),
IF_ICMPLT(161),
IF_ICMPGE(162),
IF_ICMPGT(163),
IF_ICMPLE(164),
IF_ACMPEQ(165),
IF_ACMPNE(166),
GOTO(167),
JSR(168),
RET(169),
TABLESWITCH(170),
LOOKUPSWITCH(171),
IRETURN(172),
LRETURN(173),
FRETURN(174),
DRETURN(175),
ARETURN(176),
RETURN(177),
GETSTATIC(178),
PUTSTATIC(179),
GETFIELD(180),
PUTFIELD(181),
INVOKEVIRTUAL(182),
INVOKESPECIAL(183),
INVOKESTATIC(184),
INVOKEINTERFACE(185),
INVOKEDYNAMIC(186),
NEW(187),
NEWARRAY(188),
ANEWARRAY(189),
ARRAYLENGTH(190),
ATHROW(191),
CHECKCAST(192),
INSTANCEOF(193),
MONITORENTER(194),
MONITOREXIT(195),
//WIDE(196),
MULTIANEWARRAY(197),
IFNULL(198),
IFNONNULL(199),
//GOTO_W(200),
//JSR_W(201),
;
private int number;
AsmOpcodes(int number) {
this.number = number;
}
public int getNumber() {
return number;
}
// NOTE The commented one are not used by ASM
NOP(0),
ACONST_NULL(1),
ICONST_M1(2),
ICONST_0(3),
ICONST_1(4),
ICONST_2(5),
ICONST_3(6),
ICONST_4(7),
ICONST_5(8),
LCONST_0(9),
LCONST_1(10),
FCONST_0(11),
FCONST_1(12),
FCONST_2(13),
DCONST_0(14),
DCONST_1(15),
BIPUSH(16),
SIPUSH(17),
LDC(18),
//LDC_W(19),
//LDC2_W(20),
ILOAD(21),
LLOAD(22),
FLOAD(23),
DLOAD(24),
ALOAD(25),
//ILOAD_0(26),
//ILOAD_1(27),
//ILOAD_2(28),
//ILOAD_3(29),
//LLOAD_0(30),
//LLOAD_1(31),
//LLOAD_2(32),
//LLOAD_3(33),
//FLOAD_0(34),
//FLOAD_1(35),
//FLOAD_2(36),
//FLOAD_3(37),
//DLOAD_0(38),
//DLOAD_1(39),
//DLOAD_2(40),
//DLOAD_3(41),
//ALOAD_0(42),
//ALOAD_1(43),
//ALOAD_2(44),
//ALOAD_3(45),
IALOAD(46),
LALOAD(47),
FALOAD(48),
DALOAD(49),
AALOAD(50),
BALOAD(51),
CALOAD(52),
SALOAD(53),
ISTORE(54),
LSTORE(55),
FSTORE(56),
DSTORE(57),
ASTORE(58),
//ISTORE_0(59),
//ISTORE_1(60),
//ISTORE_2(61),
//ISTORE_3(62),
//LSTORE_0(63),
//LSTORE_1(64),
//LSTORE_2(65),
//LSTORE_3(66),
//FSTORE_0(67),
//FSTORE_1(68),
//FSTORE_2(69),
//FSTORE_3(70),
//DSTORE_0(71),
//DSTORE_1(72),
//DSTORE_2(73),
//DSTORE_3(74),
//ASTORE_0(75),
//ASTORE_1(76),
//ASTORE_2(77),
//ASTORE_3(78),
IASTORE(79),
LASTORE(80),
FASTORE(81),
DASTORE(82),
AASTORE(83),
BASTORE(84),
CASTORE(85),
SASTORE(86),
POP(87),
POP2(88),
DUP(89),
DUP_X1(90),
DUP_X2(91),
DUP2(92),
DUP2_X1(93),
DUP2_X2(94),
SWAP(95),
IADD(96),
LADD(97),
FADD(98),
DADD(99),
ISUB(100),
LSUB(101),
FSUB(102),
DSUB(103),
IMUL(104),
LMUL(105),
FMUL(106),
DMUL(107),
IDIV(108),
LDIV(109),
FDIV(110),
DDIV(111),
IREM(112),
LREM(113),
FREM(114),
DREM(115),
INEG(116),
LNEG(117),
FNEG(118),
DNEG(119),
ISHL(120),
LSHL(121),
ISHR(122),
LSHR(123),
IUSHR(124),
LUSHR(125),
IAND(126),
LAND(127),
IOR(128),
LOR(129),
IXOR(130),
LXOR(131),
IINC(132),
I2L(133),
I2F(134),
I2D(135),
L2I(136),
L2F(137),
L2D(138),
F2I(139),
F2L(140),
F2D(141),
D2I(142),
D2L(143),
D2F(144),
I2B(145),
I2C(146),
I2S(147),
LCMP(148),
FCMPL(149),
FCMPG(150),
DCMPL(151),
DCMPG(152),
IFEQ(153),
IFNE(154),
IFLT(155),
IFGE(156),
IFGT(157),
IFLE(158),
IF_ICMPEQ(159),
IF_ICMPNE(160),
IF_ICMPLT(161),
IF_ICMPGE(162),
IF_ICMPGT(163),
IF_ICMPLE(164),
IF_ACMPEQ(165),
IF_ACMPNE(166),
GOTO(167),
JSR(168),
RET(169),
TABLESWITCH(170),
LOOKUPSWITCH(171),
IRETURN(172),
LRETURN(173),
FRETURN(174),
DRETURN(175),
ARETURN(176),
RETURN(177),
GETSTATIC(178),
PUTSTATIC(179),
GETFIELD(180),
PUTFIELD(181),
INVOKEVIRTUAL(182),
INVOKESPECIAL(183),
INVOKESTATIC(184),
INVOKEINTERFACE(185),
INVOKEDYNAMIC(186),
NEW(187),
NEWARRAY(188),
ANEWARRAY(189),
ARRAYLENGTH(190),
ATHROW(191),
CHECKCAST(192),
INSTANCEOF(193),
MONITORENTER(194),
MONITOREXIT(195),
//WIDE(196),
MULTIANEWARRAY(197),
IFNULL(198),
IFNONNULL(199),
//GOTO_W(200),
//JSR_W(201),
;
private int number;
AsmOpcodes(int number) {
this.number = number;
}
public int getNumber() {
return number;
}
public static AsmOpcodes valueOf (final AbstractInsnNode insn) {
for (final AsmOpcodes opcode : values ()) {
......@@ -230,7 +230,7 @@ public enum AsmOpcodes {
return opcode;
}
}
return null;
}
}
......@@ -16,146 +16,146 @@ import org.objectweb.asm.tree.TryCatchBlockNode;
public class BasicBlockCalc {
/**
* Returns all basic blocks of a given method node.
*/
public static List <AbstractInsnNode> getAll (
final InsnList instructions, final List <TryCatchBlockNode> tryCatchBlocks,
final boolean isPrecise
) {
//
// A holder for instructions that mark the beginning of a basic block.
//
// We override the add() method to automatically skip all virtual
// instructions that are added.
//
// We also override the addAll() method to ensure that our modified
// add() method is used to add the individual elements, because there
// is no contract in HashSet or Collection to guarantee that.
//
@SuppressWarnings ("serial")
Set <AbstractInsnNode> bbStarts = new HashSet <AbstractInsnNode> () {
@Override
public boolean add (AbstractInsnNode insn) {
return super.add (AsmHelper.skipVirtualInsnsForward (insn));
}
@Override
public boolean addAll (Collection <? extends AbstractInsnNode> insns) {
boolean result = false;
for (final AbstractInsnNode insn : insns) {
final boolean modified = add (insn);
result = result || modified;
}
return result;
}
};
//
// The first instruction starts a basic block.
//
bbStarts.add (instructions.getFirst ());
//
// Scan all the instructions, identify those that terminate their basic
// block and collect the starting instructions of the basic blocks
// that follow them.
//
for (final AbstractInsnNode insn : AsmHelper.allInsnsFrom (instructions)) {
SWITCH: switch (insn.getType ()) {
//
// IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
// IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
// IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL, and IFNONNULL.
//
// For all jump instructions, a basic block starts where the
// instruction jumps.
//
// For conditional jumps or jumps to subroutines, a basic block
// also starts with the next instruction.
//
// The GOTO instruction changes the control flow unconditionally,
// so only one basic block follows it.
//
case AbstractInsnNode.JUMP_INSN: {
bbStarts.add (((JumpInsnNode) insn).label);
if (insn.getOpcode () != Opcodes.GOTO) {
//
// There must be a valid (non-virtual) instruction
// following a conditional/subroutine jump instruction.
//
AbstractInsnNode nextInsn = AsmHelper.nextNonVirtualInsn (insn);
if (nextInsn != null) {
bbStarts.add (nextInsn);
}
}
break SWITCH;
}
//
// LOOKUPSWITCH, TABLESWITCH
//
// For the LOOKUPSWITCH and TABLESWITCH instructions, all the
// targets in the table represent a new basic block, including
// the default target.
//
// Since they are two unrelated classes in ASM, we have to handle
// each case separately, yet with the same code.
//
case AbstractInsnNode.LOOKUPSWITCH_INSN: {
final LookupSwitchInsnNode lsInsn = (LookupSwitchInsnNode) insn;
bbStarts.addAll (lsInsn.labels);
bbStarts.add (lsInsn.dflt);
break SWITCH;
}
case AbstractInsnNode.TABLESWITCH_INSN: {
final TableSwitchInsnNode tsInsn = (TableSwitchInsnNode) insn;
bbStarts.addAll (tsInsn.labels);
bbStarts.add (tsInsn.dflt);
break SWITCH;
}
//
// Don't do anything for other instruction types.
//
default:
break SWITCH;
}
//
// In case of precise basic block marking, any instruction that
// might throw an exception is potentially the last instruction of
// a basic block, with the next instruction the beginning of the
// next basic block.
//
if (isPrecise && AsmHelper.mightThrowException (insn)) {
bbStarts.add (insn.getNext ());
}
}
//
// All exception handlers start a basic block as well.
//
for (final TryCatchBlockNode tryCatchBlock : tryCatchBlocks) {
bbStarts.add (tryCatchBlock.handler);
}
//
// Sort the basic block starting instructions. A LinkedHashSet would
// not help here, because we were adding entries out-of-order (jumps).
//
List <AbstractInsnNode> result = new ArrayList <AbstractInsnNode> ();
for (final AbstractInsnNode insn : AsmHelper.allInsnsFrom (instructions)) {
if (bbStarts.contains (insn)) {
result.add (insn);
}
}
return result;
}
/**
* Returns all basic blocks of a given method node.
*/
public static List <AbstractInsnNode> getAll (
final InsnList instructions, final List <TryCatchBlockNode> tryCatchBlocks,
final boolean isPrecise
) {
//
// A holder for instructions that mark the beginning of a basic block.
//
// We override the add() method to automatically skip all virtual
// instructions that are added.
//
// We also override the addAll() method to ensure that our modified
// add() method is used to add the individual elements, because there
// is no contract in HashSet or Collection to guarantee that.
//
@SuppressWarnings ("serial")
Set <AbstractInsnNode> bbStarts = new HashSet <AbstractInsnNode> () {
@Override
public boolean add (AbstractInsnNode insn) {
return super.add (AsmHelper.skipVirtualInsnsForward (insn));
}
@Override
public boolean addAll (Collection <? extends AbstractInsnNode> insns) {
boolean result = false;
for (final AbstractInsnNode insn : insns) {
final boolean modified = add (insn);
result = result || modified;
}
return result;
}
};
//
// The first instruction starts a basic block.
//
bbStarts.add (instructions.getFirst ());
//
// Scan all the instructions, identify those that terminate their basic
// block and collect the starting instructions of the basic blocks
// that follow them.
//
for (final AbstractInsnNode insn : AsmHelper.allInsnsFrom (instructions)) {
SWITCH: switch (insn.getType ()) {
//
// IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
// IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
// IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL, and IFNONNULL.
//
// For all jump instructions, a basic block starts where the
// instruction jumps.
//
// For conditional jumps or jumps to subroutines, a basic block
// also starts with the next instruction.