Java Code Examples for org.springframework.asm.MethodVisitor#visitIntInsn()

The following examples show how to use org.springframework.asm.MethodVisitor#visitIntInsn() . 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: CodeFlow.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Produce the correct bytecode to build an array. The opcode to use and the
 * signature to pass along with the opcode can vary depending on the signature
 * of the array type.
 * @param mv the methodvisitor into which code should be inserted
 * @param size the size of the array
 * @param arraytype the type of the array
 */
public static void insertNewArrayCode(MethodVisitor mv, int size, String arraytype) {
	insertOptimalLoad(mv, size);
	if (arraytype.length() == 1) {
		mv.visitIntInsn(NEWARRAY, CodeFlow.arrayCodeFor(arraytype));
	}
	else {
		if (arraytype.charAt(0) == '[') {
			// Handling the nested array case here.
			// If vararg is [[I then we want [I and not [I;
			if (CodeFlow.isReferenceTypeArray(arraytype)) {
				mv.visitTypeInsn(ANEWARRAY, arraytype + ";");
			}
			else {
				mv.visitTypeInsn(ANEWARRAY, arraytype);
			}
		}
		else {
			mv.visitTypeInsn(ANEWARRAY, arraytype.substring(1));
		}
	}
}
 
Example 2
Source File: CodeFlow.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Produce the correct bytecode to build an array. The opcode to use and the
 * signature to pass along with the opcode can vary depending on the signature
 * of the array type.
 * @param mv the methodvisitor into which code should be inserted
 * @param size the size of the array
 * @param arraytype the type of the array
 */
public static void insertNewArrayCode(MethodVisitor mv, int size, String arraytype) {
	insertOptimalLoad(mv, size);
	if (arraytype.length() == 1) {
		mv.visitIntInsn(NEWARRAY, CodeFlow.arrayCodeFor(arraytype));
	}
	else {
		if (arraytype.charAt(0) == '[') {
			// Handling the nested array case here.
			// If vararg is [[I then we want [I and not [I;
			if (CodeFlow.isReferenceTypeArray(arraytype)) {
				mv.visitTypeInsn(ANEWARRAY, arraytype + ";");
			}
			else {
				mv.visitTypeInsn(ANEWARRAY, arraytype);
			}
		}
		else {
			mv.visitTypeInsn(ANEWARRAY, arraytype.substring(1));
		}
	}
}
 
Example 3
Source File: CodeFlow.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Produce the correct bytecode to build an array. The opcode to use and the
 * signature to pass along with the opcode can vary depending on the signature
 * of the array type.
 * @param mv the methodvisitor into which code should be inserted
 * @param size the size of the array
 * @param arraytype the type of the array
 */
public static void insertNewArrayCode(MethodVisitor mv, int size, String arraytype) {
	insertOptimalLoad(mv, size);
	if (arraytype.length() == 1) {
		mv.visitIntInsn(NEWARRAY, CodeFlow.arrayCodeFor(arraytype));
	}
	else {
		if (arraytype.charAt(0) == '[') {
			// Handling the nested array case here. If vararg
			// is [[I then we want [I and not [I;
			if (CodeFlow.isReferenceTypeArray(arraytype)) {
				mv.visitTypeInsn(ANEWARRAY, arraytype+";");
			}
			else {
				mv.visitTypeInsn(ANEWARRAY, arraytype);
			}
		}
		else {
			mv.visitTypeInsn(ANEWARRAY, arraytype.substring(1));
		}
	}
}
 
Example 4
Source File: CodeFlow.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Produce the correct bytecode to build an array. The opcode to use and the
 * signature to pass along with the opcode can vary depending on the signature
 * of the array type.
 * @param mv the methodvisitor into which code should be inserted
 * @param size the size of the array
 * @param arraytype the type of the array
 */
public static void insertNewArrayCode(MethodVisitor mv, int size, String arraytype) {
	insertOptimalLoad(mv, size);
	if (arraytype.length() == 1) {
		mv.visitIntInsn(NEWARRAY, CodeFlow.arrayCodeFor(arraytype));
	}
	else {
		if (arraytype.charAt(0) == '[') {
			// Handling the nested array case here. If vararg
			// is [[I then we want [I and not [I;
			if (CodeFlow.isReferenceTypeArray(arraytype)) {
				mv.visitTypeInsn(ANEWARRAY, arraytype+";");
			}
			else {
				mv.visitTypeInsn(ANEWARRAY, arraytype);
			}
		}
		else {
			mv.visitTypeInsn(ANEWARRAY, arraytype.substring(1));
		}
	}
}
 
Example 5
Source File: CodeFlow.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Create the optimal instruction for loading a number on the stack.
 * @param mv where to insert the bytecode
 * @param value the value to be loaded
 */
public static void insertOptimalLoad(MethodVisitor mv, int value) {
	if (value < 6) {
		mv.visitInsn(ICONST_0+value);
	}
	else if (value < Byte.MAX_VALUE) {
		mv.visitIntInsn(BIPUSH, value);
	}
	else if (value < Short.MAX_VALUE) {
		mv.visitIntInsn(SIPUSH, value);
	}
	else {
		mv.visitLdcInsn(value);
	}
}
 
Example 6
Source File: CodeFlow.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Create the optimal instruction for loading a number on the stack.
 * @param mv where to insert the bytecode
 * @param value the value to be loaded
 */
public static void insertOptimalLoad(MethodVisitor mv, int value) {
	if (value < 6) {
		mv.visitInsn(ICONST_0+value);
	}
	else if (value < Byte.MAX_VALUE) {
		mv.visitIntInsn(BIPUSH, value);
	}
	else if (value < Short.MAX_VALUE) {
		mv.visitIntInsn(SIPUSH, value);
	}
	else {
		mv.visitLdcInsn(value);
	}
}
 
Example 7
Source File: CodeFlow.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the optimal instruction for loading a number on the stack.
 * @param mv where to insert the bytecode
 * @param value the value to be loaded
 */
public static void insertOptimalLoad(MethodVisitor mv, int value) {
	if (value < 6) {
		mv.visitInsn(ICONST_0+value);
	}
	else if (value < Byte.MAX_VALUE) {
		mv.visitIntInsn(BIPUSH, value);
	}
	else if (value < Short.MAX_VALUE) {
		mv.visitIntInsn(SIPUSH, value);
	}
	else {
		mv.visitLdcInsn(value);
	}
}
 
Example 8
Source File: CodeFlow.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Create the optimal instruction for loading a number on the stack.
 * @param mv where to insert the bytecode
 * @param value the value to be loaded
 */
public static void insertOptimalLoad(MethodVisitor mv, int value) {
	if (value < 6) {
		mv.visitInsn(ICONST_0+value);
	}
	else if (value < Byte.MAX_VALUE) {
		mv.visitIntInsn(BIPUSH, value);
	}
	else if (value < Short.MAX_VALUE) {
		mv.visitIntInsn(SIPUSH, value);
	}
	else {
		mv.visitLdcInsn(value);
	}
}