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 File: OpOr.java From spring-analysis-note with MIT License | 6 votes |
@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 #2
Source File: OpOr.java From java-technology-stack with MIT License | 6 votes |
@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 #3
Source File: OpAnd.java From java-technology-stack with MIT License | 6 votes |
@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 #4
Source File: MicaBeanMapEmitter.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
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 #5
Source File: OpAnd.java From lams with GNU General Public License v2.0 | 6 votes |
@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 File: Enhancer.java From java-technology-stack with MIT License | 6 votes |
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 #7
Source File: Enhancer.java From java-technology-stack with MIT License | 6 votes |
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 File: OpOr.java From lams with GNU General Public License v2.0 | 6 votes |
@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 #9
Source File: OpAnd.java From spring-analysis-note with MIT License | 6 votes |
@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 File: Elvis.java From lams with GNU General Public License v2.0 | 6 votes |
@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 #11
Source File: OpAnd.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 File: Enhancer.java From spring-analysis-note with MIT License | 6 votes |
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 #13
Source File: Enhancer.java From spring-analysis-note with MIT License | 6 votes |
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 #14
Source File: OpOr.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 #15
Source File: MicaBeanMapEmitter.java From mica with GNU Lesser General Public License v3.0 | 6 votes |
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 #16
Source File: Elvis.java From spring4-understanding with Apache License 2.0 | 6 votes |
@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 File: LocalVariableTableParameterNameDiscoverer.java From lams with GNU General Public License v2.0 | 5 votes |
@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 #18
Source File: LocalVariableTableParameterNameDiscoverer.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 #19
Source File: Ternary.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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); if (!CodeFlow.isPrimitive(cf.lastDescriptor())) { CodeFlow.insertUnboxInsns(mv, 'Z', cf.lastDescriptor()); } 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)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } cf.exitCompilationScope(); mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); this.children[2].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
Example #20
Source File: Ternary.java From java-technology-stack with MIT License | 5 votes |
@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 #21
Source File: OpNE.java From lams with GNU General Public License v2.0 | 5 votes |
@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 #22
Source File: OperatorNot.java From lams with GNU General Public License v2.0 | 5 votes |
@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 #23
Source File: Ternary.java From lams with GNU General Public License v2.0 | 5 votes |
@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); if (!CodeFlow.isPrimitive(cf.lastDescriptor())) { CodeFlow.insertUnboxInsns(mv, 'Z', cf.lastDescriptor()); } 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)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } cf.exitCompilationScope(); mv.visitJumpInsn(GOTO, endOfIf); mv.visitLabel(elseTarget); cf.enterCompilationScope(); this.children[2].generateCode(mv, cf); if (!CodeFlow.isPrimitive(this.exitTypeDescriptor)) { CodeFlow.insertBoxIfNecessary(mv, cf.lastDescriptor().charAt(0)); } cf.exitCompilationScope(); mv.visitLabel(endOfIf); cf.pushDescriptor(this.exitTypeDescriptor); }
Example #24
Source File: Elvis.java From java-technology-stack with MIT License | 5 votes |
@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 #25
Source File: OpNE.java From java-technology-stack with MIT License | 5 votes |
@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 #26
Source File: OperatorNot.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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 #27
Source File: Ternary.java From spring-analysis-note with MIT License | 5 votes |
@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 #28
Source File: MicaBeanMapEmitter.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
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 #29
Source File: MicaBeanCopier.java From mica with GNU Lesser General Public License v3.0 | 5 votes |
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 #30
Source File: Enhancer.java From spring-analysis-note with MIT License | 5 votes |
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(); }