org.springframework.asm.Label Java Examples

The following examples show how to use org.springframework.asm.Label. 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 Project: mica   Author: lets-mica   File: MicaBeanMapEmitter.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private void generateGet(Class type, final Map<String, PropertyDescriptor> getters) {
	final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, BEAN_MAP_GET, null);
	e.load_arg(0);
	e.checkcast(Type.getType(type));
	e.load_arg(1);
	e.checkcast(Constants.TYPE_STRING);
	EmitUtils.string_switch(e, getNames(getters), Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
		@Override
		public void processCase(Object key, Label end) {
			PropertyDescriptor pd = getters.get(key);
			MethodInfo method = ReflectUtils.getMethodInfo(pd.getReadMethod());
			e.invoke(method);
			e.box(method.getSignature().getReturnType());
			e.return_value();
		}

		@Override
		public void processDefault() {
			e.aconst_null();
			e.return_value();
		}
	});
	e.end_method();
}
 
Example #2
Source Project: mica   Author: lets-mica   File: MicaBeanMapEmitter.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
private void generateGetPropertyType(final Map allProps, String[] allNames) {
	final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, GET_PROPERTY_TYPE, null);
	e.load_arg(0);
	EmitUtils.string_switch(e, allNames, Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
		@Override
		public void processCase(Object key, Label end) {
			PropertyDescriptor pd = (PropertyDescriptor) allProps.get(key);
			EmitUtils.load_class(e, Type.getType(pd.getPropertyType()));
			e.return_value();
		}

		@Override
		public void processDefault() {
			e.aconst_null();
			e.return_value();
		}
	});
	e.end_method();
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitGetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null);
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.getfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			e.pop(); // stack height
			e.aconst_null();
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitSetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.load_this();
			e.load_arg(1);
			e.checkcast(callbackTypes[key]);
			e.putfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			// TODO: error?
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #5
Source Project: spring-analysis-note   Author: Vip-Augus   File: OpAnd.java    License: MIT License 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFNE, elseTarget);
	mv.visitLdcInsn(0); // FALSE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #6
Source Project: spring-analysis-note   Author: Vip-Augus   File: OpOr.java    License: MIT License 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFEQ, elseTarget);
	mv.visitLdcInsn(1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #7
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitGetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, GET_CALLBACK, null);
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.getfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			e.pop(); // stack height
			e.aconst_null();
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #8
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 6 votes vote down vote up
private void emitSetCallback(ClassEmitter ce, int[] keys) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, SET_CALLBACK, null);
	e.load_arg(0);
	e.process_switch(keys, new ProcessSwitchCallback() {
		public void processCase(int key, Label end) {
			e.load_this();
			e.load_arg(1);
			e.checkcast(callbackTypes[key]);
			e.putfield(getCallbackField(key));
			e.goTo(end);
		}

		public void processDefault() {
			// TODO: error?
		}
	});
	e.return_value();
	e.end_method();
}
 
Example #9
Source Project: java-technology-stack   Author: codeEngraver   File: OpAnd.java    License: MIT License 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFNE, elseTarget);
	mv.visitLdcInsn(0); // FALSE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #10
Source Project: java-technology-stack   Author: codeEngraver   File: OpOr.java    License: MIT License 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFEQ, elseTarget);
	mv.visitLdcInsn(1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #11
Source Project: lams   Author: lamsfoundation   File: OpAnd.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFNE, elseTarget);
	mv.visitLdcInsn(0); // FALSE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #12
Source Project: lams   Author: lamsfoundation   File: OpOr.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFEQ, elseTarget);
	mv.visitLdcInsn(1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #13
Source Project: lams   Author: lamsfoundation   File: Elvis.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// exit type descriptor can be null if both components are literal expressions
	computeExitTypeDescriptor();
	this.children[0].generateCode(mv, cf);
	CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitInsn(DUP);
	mv.visitJumpInsn(IFNULL, elseTarget);
	// Also check if empty string, as per the code in the interpreted version
	mv.visitInsn(DUP);
	mv.visitLdcInsn("");
	mv.visitInsn(SWAP);
	mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false);
	mv.visitJumpInsn(IFEQ, endOfIf);  // if not empty, drop through to elseTarget
	mv.visitLabel(elseTarget);
	mv.visitInsn(POP);
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	}
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #14
Source Project: spring4-understanding   Author: langtianya   File: OpAnd.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// Pseudo: if (!leftOperandValue) { result=false; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFNE, elseTarget);
	mv.visitLdcInsn(0); // FALSE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #15
Source Project: spring4-understanding   Author: langtianya   File: OpOr.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// pseudo: if (leftOperandValue) { result=true; } else { result=rightOperandValue; }
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitJumpInsn(IFEQ, elseTarget);
	mv.visitLdcInsn(1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #16
Source Project: spring4-understanding   Author: langtianya   File: Elvis.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// exit type descriptor can be null if both components are literal expressions
	computeExitTypeDescriptor();
	this.children[0].generateCode(mv, cf);
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitInsn(DUP);
	mv.visitJumpInsn(IFNULL, elseTarget);
	mv.visitJumpInsn(GOTO, endOfIf);
	mv.visitLabel(elseTarget);
	mv.visitInsn(POP);
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0));
	}
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #17
Source Project: mica   Author: lets-mica   File: MicaBeanMapEmitter.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private void generatePut(Class type, final Map<String, PropertyDescriptor> setters) {
	final CodeEmitter e = begin_method(Constants.ACC_PUBLIC, BEAN_MAP_PUT, null);
	e.load_arg(0);
	e.checkcast(Type.getType(type));
	e.load_arg(1);
	e.checkcast(Constants.TYPE_STRING);
	EmitUtils.string_switch(e, getNames(setters), Constants.SWITCH_STYLE_HASH, new ObjectSwitchCallback() {
		@Override
		public void processCase(Object key, Label end) {
			PropertyDescriptor pd = setters.get(key);
			if (pd.getReadMethod() == null) {
				e.aconst_null();
			} else {
				MethodInfo read = ReflectUtils.getMethodInfo(pd.getReadMethod());
				e.dup();
				e.invoke(read);
				e.box(read.getSignature().getReturnType());
			}
			// move old value behind bean
			e.swap();
			// new value
			e.load_arg(2);
			MethodInfo write = ReflectUtils.getMethodInfo(pd.getWriteMethod());
			e.unbox(write.getSignature().getArgumentTypes()[0]);
			e.invoke(write);
			e.return_value();
		}

		@Override
		public void processDefault() {
			// fall-through
		}
	});
	e.aconst_null();
	e.return_value();
	e.end_method();
}
 
Example #18
Source Project: mica   Author: lets-mica   File: MicaBeanCopier.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void invokeWrite(CodeEmitter e, MethodInfo write, Method writeMethod, boolean nonNull, Label l0) {
	// 返回值,判断 链式 bean
	Class<?> returnType = writeMethod.getReturnType();
	e.invoke(write);
	// 链式 bean,有返回值需要 pop
	if (!returnType.equals(Void.TYPE)) {
		e.pop();
	}
	if (nonNull) {
		e.visitLabel(l0);
	}
}
 
Example #19
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null);
	final Type thisType = getThisType(e);
	e.load_arg(2);
	e.invoke_static(thisType, SET_THREAD_CALLBACKS);
	e.new_instance(thisType);
	e.dup();
	e.load_arg(0);
	EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() {
		public void processCase(Object key, Label end) {
			MethodInfo constructor = (MethodInfo) key;
			Type types[] = constructor.getSignature().getArgumentTypes();
			for (int i = 0; i < types.length; i++) {
				e.load_arg(1);
				e.push(i);
				e.aaload();
				e.unbox(types[i]);
			}
			e.invoke_constructor(thisType, constructor.getSignature());
			e.goTo(end);
		}

		public void processDefault() {
			e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found");
		}
	});
	e.aconst_null();
	e.invoke_static(thisType, SET_THREAD_CALLBACKS);
	e.return_value();
	e.end_method();
}
 
Example #20
Source Project: spring-analysis-note   Author: Vip-Augus   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitCurrentCallback(CodeEmitter e, int index) {
	e.load_this();
	e.getfield(getCallbackField(index));
	e.dup();
	Label end = e.make_label();
	e.ifnonnull(end);
	e.pop(); // stack height
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.getfield(getCallbackField(index));
	e.mark(end);
}
 
Example #21
Source Project: spring-analysis-note   Author: Vip-Augus   File: LocalVariableTableParameterNameDiscoverer.java    License: MIT License 5 votes vote down vote up
@Override
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
	this.hasLvtInfo = true;
	for (int i = 0; i < this.lvtSlotIndex.length; i++) {
		if (this.lvtSlotIndex[i] == index) {
			this.parameterNames[i] = name;
		}
	}
}
 
Example #22
Source Project: spring-analysis-note   Author: Vip-Augus   File: Ternary.java    License: MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// May reach here without it computed if all elements are literals
	computeExitTypeDescriptor();
	cf.enterCompilationScope();
	this.children[0].generateCode(mv, cf);
	String lastDesc = cf.lastDescriptor();
	Assert.state(lastDesc != null, "No last descriptor");
	if (!CodeFlow.isPrimitive(lastDesc)) {
		CodeFlow.insertUnboxInsns(mv, 'Z', lastDesc);
	}
	cf.exitCompilationScope();
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitJumpInsn(IFEQ, elseTarget);
	cf.enterCompilationScope();
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		lastDesc = cf.lastDescriptor();
		Assert.state(lastDesc != null, "No last descriptor");
		CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitJumpInsn(GOTO, endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	this.children[2].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		lastDesc = cf.lastDescriptor();
		Assert.state(lastDesc != null, "No last descriptor");
		CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #23
Source Project: spring-analysis-note   Author: Vip-Augus   File: OperatorNot.java    License: MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	this.children[0].generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitJumpInsn(IFNE,elseTarget);
	mv.visitInsn(ICONST_1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	mv.visitInsn(ICONST_0); // FALSE
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #24
Source Project: spring-analysis-note   Author: Vip-Augus   File: OpNE.java    License: MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	cf.loadEvaluationContext(mv);
	String leftDesc = getLeftOperand().exitTypeDescriptor;
	String rightDesc = getRightOperand().exitTypeDescriptor;
	boolean leftPrim = CodeFlow.isPrimitive(leftDesc);
	boolean rightPrim = CodeFlow.isPrimitive(rightDesc);

	cf.enterCompilationScope();
	getLeftOperand().generateCode(mv, cf);
	cf.exitCompilationScope();
	if (leftPrim) {
		CodeFlow.insertBoxIfNecessary(mv, leftDesc.charAt(0));
	}
	cf.enterCompilationScope();
	getRightOperand().generateCode(mv, cf);
	cf.exitCompilationScope();
	if (rightPrim) {
		CodeFlow.insertBoxIfNecessary(mv, rightDesc.charAt(0));
	}

	String operatorClassName = Operator.class.getName().replace('.', '/');
	String evaluationContextClassName = EvaluationContext.class.getName().replace('.', '/');
	mv.visitMethodInsn(INVOKESTATIC, operatorClassName, "equalityCheck",
			"(L" + evaluationContextClassName + ";Ljava/lang/Object;Ljava/lang/Object;)Z", false);

	// Invert the boolean
	Label notZero = new Label();
	Label end = new Label();
	mv.visitJumpInsn(IFNE, notZero);
	mv.visitInsn(ICONST_1);
	mv.visitJumpInsn(GOTO, end);
	mv.visitLabel(notZero);
	mv.visitInsn(ICONST_0);
	mv.visitLabel(end);

	cf.pushDescriptor("Z");
}
 
Example #25
Source Project: spring-analysis-note   Author: Vip-Augus   File: Elvis.java    License: MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// exit type descriptor can be null if both components are literal expressions
	computeExitTypeDescriptor();
	cf.enterCompilationScope();
	this.children[0].generateCode(mv, cf);
	String lastDesc = cf.lastDescriptor();
	Assert.state(lastDesc != null, "No last descriptor");
	CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
	cf.exitCompilationScope();
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitInsn(DUP);
	mv.visitJumpInsn(IFNULL, elseTarget);
	// Also check if empty string, as per the code in the interpreted version
	mv.visitInsn(DUP);
	mv.visitLdcInsn("");
	mv.visitInsn(SWAP);
	mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z",false);
	mv.visitJumpInsn(IFEQ, endOfIf);  // if not empty, drop through to elseTarget
	mv.visitLabel(elseTarget);
	mv.visitInsn(POP);
	cf.enterCompilationScope();
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		lastDesc = cf.lastDescriptor();
		Assert.state(lastDesc != null, "No last descriptor");
		CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #26
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitNewInstanceMultiarg(ClassEmitter ce, List constructors) {
	final CodeEmitter e = ce.begin_method(Constants.ACC_PUBLIC, MULTIARG_NEW_INSTANCE, null);
	final Type thisType = getThisType(e);
	e.load_arg(2);
	e.invoke_static(thisType, SET_THREAD_CALLBACKS);
	e.new_instance(thisType);
	e.dup();
	e.load_arg(0);
	EmitUtils.constructor_switch(e, constructors, new ObjectSwitchCallback() {
		public void processCase(Object key, Label end) {
			MethodInfo constructor = (MethodInfo) key;
			Type types[] = constructor.getSignature().getArgumentTypes();
			for (int i = 0; i < types.length; i++) {
				e.load_arg(1);
				e.push(i);
				e.aaload();
				e.unbox(types[i]);
			}
			e.invoke_constructor(thisType, constructor.getSignature());
			e.goTo(end);
		}

		public void processDefault() {
			e.throw_exception(ILLEGAL_ARGUMENT_EXCEPTION, "Constructor not found");
		}
	});
	e.aconst_null();
	e.invoke_static(thisType, SET_THREAD_CALLBACKS);
	e.return_value();
	e.end_method();
}
 
Example #27
Source Project: java-technology-stack   Author: codeEngraver   File: Enhancer.java    License: MIT License 5 votes vote down vote up
private void emitCurrentCallback(CodeEmitter e, int index) {
	e.load_this();
	e.getfield(getCallbackField(index));
	e.dup();
	Label end = e.make_label();
	e.ifnonnull(end);
	e.pop(); // stack height
	e.load_this();
	e.invoke_static_this(BIND_CALLBACKS);
	e.load_this();
	e.getfield(getCallbackField(index));
	e.mark(end);
}
 
Example #28
Source Project: java-technology-stack   Author: codeEngraver   File: LocalVariableTableParameterNameDiscoverer.java    License: MIT License 5 votes vote down vote up
@Override
public void visitLocalVariable(String name, String description, String signature, Label start, Label end, int index) {
	this.hasLvtInfo = true;
	for (int i = 0; i < this.lvtSlotIndex.length; i++) {
		if (this.lvtSlotIndex[i] == index) {
			this.parameterNames[i] = name;
		}
	}
}
 
Example #29
Source Project: java-technology-stack   Author: codeEngraver   File: Ternary.java    License: MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	// May reach here without it computed if all elements are literals
	computeExitTypeDescriptor();
	cf.enterCompilationScope();
	this.children[0].generateCode(mv, cf);
	String lastDesc = cf.lastDescriptor();
	Assert.state(lastDesc != null, "No last descriptor");
	if (!CodeFlow.isPrimitive(lastDesc)) {
		CodeFlow.insertUnboxInsns(mv, 'Z', lastDesc);
	}
	cf.exitCompilationScope();
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitJumpInsn(IFEQ, elseTarget);
	cf.enterCompilationScope();
	this.children[1].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		lastDesc = cf.lastDescriptor();
		Assert.state(lastDesc != null, "No last descriptor");
		CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitJumpInsn(GOTO, endOfIf);
	mv.visitLabel(elseTarget);
	cf.enterCompilationScope();
	this.children[2].generateCode(mv, cf);
	if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) {
		lastDesc = cf.lastDescriptor();
		Assert.state(lastDesc != null, "No last descriptor");
		CodeFlow.insertBoxIfNecessary(mv, lastDesc.charAt(0));
	}
	cf.exitCompilationScope();
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}
 
Example #30
Source Project: java-technology-stack   Author: codeEngraver   File: OperatorNot.java    License: MIT License 5 votes vote down vote up
@Override
public void generateCode(MethodVisitor mv, CodeFlow cf) {
	this.children[0].generateCode(mv, cf);
	cf.unboxBooleanIfNecessary(mv);
	Label elseTarget = new Label();
	Label endOfIf = new Label();
	mv.visitJumpInsn(IFNE,elseTarget);
	mv.visitInsn(ICONST_1); // TRUE
	mv.visitJumpInsn(GOTO,endOfIf);
	mv.visitLabel(elseTarget);
	mv.visitInsn(ICONST_0); // FALSE
	mv.visitLabel(endOfIf);
	cf.pushDescriptor(this.exitTypeDescriptor);
}