Bug 520460 - [OTDRE] Load negative constants with ASM

Signed-off-by: Lars Schuetze <laze1989@gmail.com>
diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AbstractTransformableClassNode.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AbstractTransformableClassNode.java
index 6dd3ad4..01d4555 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AbstractTransformableClassNode.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/AbstractTransformableClassNode.java
@@ -322,11 +322,11 @@
 	 * using the most compact possible format. 

 	 */

 	protected AbstractInsnNode createLoadIntConstant(int constant) {

-		if (constant <= 5)

+		if (constant >= 0 && constant <= 5)

 			return new InsnNode(Opcodes.ICONST_0+constant);

-		else if (constant < Byte.MAX_VALUE)

+		else if (constant > Byte.MIN_VALUE && constant < Byte.MAX_VALUE)

 			return new IntInsnNode(Opcodes.BIPUSH, constant);

-		else if (constant < Short.MAX_VALUE)

+		else if (constant > Short.MIN_VALUE && constant < Short.MAX_VALUE)

 			return new IntInsnNode(Opcodes.SIPUSH, constant);		

 		else

 			return new LdcInsnNode(constant);

diff --git a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/CreateCallAllBindingsCallInOrgMethod.java b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/CreateCallAllBindingsCallInOrgMethod.java
index 6d2e080..e7ba69d 100644
--- a/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/CreateCallAllBindingsCallInOrgMethod.java
+++ b/plugins/org.eclipse.objectteams.otredyn/src/org/eclipse/objectteams/otredyn/bytecode/asm/CreateCallAllBindingsCallInOrgMethod.java
@@ -107,12 +107,10 @@
 		// put this on the stack

 		newInstructions.add(new VarInsnNode(Opcodes.ALOAD, 0));

 		// put boundMethodId on the stack

-		newInstructions.add(createLoadIntConstant(boundMethodId));

-		if (method.name.equals("<init>")) { // set bit 0x8000000 to signal the ctor

-			newInstructions.add(createLoadIntConstant(0xffffffff));

-			newInstructions.add(createLoadIntConstant(0x7fffffff)); // 0x80000000 causes NPE in ASM :(

-			newInstructions.add(new InsnNode(Opcodes.IXOR)); // indirectly creates the desired 0x80000000

-			newInstructions.add(new InsnNode(Opcodes.IOR));

+		if(method.name.equals("<init>")) { // set bit 0x8000000 to signal the ctor

+			newInstructions.add(createLoadIntConstant(0x8000_0000 | boundMethodId));

+		} else {

+			newInstructions.add(createLoadIntConstant(boundMethodId));

 		}

 		// box the arguments

 		newInstructions.add(getBoxingInstructions(args, false));