List of usage examples for org.objectweb.asm MethodVisitor visitMethodInsn
public void visitMethodInsn(final int opcode, final String owner, final String name, final String descriptor, final boolean isInterface)
From source file:com.yahoo.yqlplus.engine.internal.compiler.EqualsExpression.java
@Override public void generate(CodeEmitter code) { // a bit of a hack; should not need to go to dynamic invocation for this unless one arg is ANY MethodVisitor mv = code.getMethodVisitor(); Label hasNull = new Label(); CodeEmitter.Unification unified = code.unifiedEmit(leftExpr, rightExpr, hasNull); if (unified.type.isPrimitive()) { emitPrimitiveEquals(code, unified.type); } else {//from www . ja va 2 s . c o m mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Object.class), "equals", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), false); if (negate) { emitNegate(mv); } } if (unified.nullPossible) { Label done = new Label(); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(hasNull); emitFalse(code); mv.visitLabel(done); } }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.AnyTypeWidget.java
@Override public ComparisonAdapter getComparisionAdapter() { Preconditions.checkState(!isPrimitive(), "BaseTypeWidget should not be handling a primitive type"); return new ComparisonAdapter() { @Override//ww w. j a va2s . c om public void coerceBoolean(CodeEmitter scope, Label isTrue, Label isFalse, Label isNull) { // null or true scope.nullTest(AnyTypeWidget.getInstance(), isNull); Label popTrue = new Label(); scope.emitInstanceOf(AnyTypeWidget.getInstance(), Boolean.class, popTrue); final MethodVisitor mv = scope.getMethodVisitor(); mv.visitMethodInsn(Opcodes.GETSTATIC, Type.getInternalName(Boolean.class), "TRUE", Type.getMethodDescriptor(Type.getType(Boolean.class)), false); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(Boolean.class), "equals", Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Object.class)), false); mv.visitJumpInsn(Opcodes.IFEQ, isFalse); mv.visitJumpInsn(Opcodes.GOTO, isTrue); mv.visitLabel(popTrue); scope.pop(AnyTypeWidget.getInstance()); mv.visitJumpInsn(Opcodes.GOTO, isTrue); } }; }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.EmptyObjectSerializer.java
@Override public BytecodeSequence serializeTo(final BytecodeExpression source, final BytecodeExpression generator) { switch (encoding) { case JSON:/* w ww .j a v a2s.c om*/ return new BytecodeSequence() { @Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); final BytecodeExpression gen = code.evaluateOnce(generator); code.exec(gen); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), "writeStartObject", Type.getMethodDescriptor(Type.VOID_TYPE), false); code.exec(gen); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), "writeEndObject", Type.getMethodDescriptor(Type.VOID_TYPE), false); } }; case TBIN: throw new TodoException(); default: throw new UnsupportedOperationException(); } }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.InvokeExpression.java
@Override public void generate(CodeEmitter code) { if (op != Opcodes.INVOKESTATIC) { target.generate(code);//w ww.ja v a 2 s . c o m } for (BytecodeExpression arg : arguments) { arg.generate(code); } MethodVisitor mv = code.getMethodVisitor(); mv.visitMethodInsn(op, owner.getInternalName(), methodName, descriptor, op == Opcodes.INVOKEINTERFACE); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IterateFirstSequence.java
@Override public void generate(CodeEmitter start) { CodeEmitter code = start.createScope(); Label done = new Label(); Label isNull = new Label(); MethodVisitor mv = code.getMethodVisitor(); BytecodeExpression tgt = code.evaluateOnce(target); tgt.generate(code);//from w ww. j av a 2s .co m code.emitInstanceCheck(tgt.getType(), Iterable.class, isNull); AssignableValue iterator = code.allocate(Iterator.class); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterable.class), "iterator", Type.getMethodDescriptor(Type.getType(Iterator.class)), true); code.exec(iterator.write(code.adapt(Iterator.class))); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "hasNext", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), true); mv.visitJumpInsn(Opcodes.IFEQ, isNull); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "next", Type.getMethodDescriptor(Type.getType(Object.class)), true); code.cast(valueType, AnyTypeWidget.getInstance(), isNull); mv.visitJumpInsn(Opcodes.GOTO, done); mv.visitLabel(isNull); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitLabel(done); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IterateSequence.java
@Override public void generate(CodeEmitter code) { Label done = new Label(); Label next = new Label(); MethodVisitor mv = code.getMethodVisitor(); BytecodeExpression tgt = code.evaluateOnce(target); code.exec(tgt);/* ww w . j av a 2 s .c o m*/ code.emitInstanceCheck(tgt.getType(), Iterable.class, done); AssignableValue item = this.item == null ? code.allocate(valueType) : this.item; AssignableValue iterator = code.allocate(Iterator.class); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterable.class), "iterator", Type.getMethodDescriptor(Type.getType(Iterator.class)), true); code.exec(iterator.write(code.adapt(Iterator.class))); mv.visitLabel(next); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "hasNext", Type.getMethodDescriptor(Type.BOOLEAN_TYPE), true); mv.visitJumpInsn(Opcodes.IFEQ, done); code.exec(iterator.read()); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(Iterator.class), "next", Type.getMethodDescriptor(Type.getType(Object.class)), true); code.cast(valueType, AnyTypeWidget.getInstance()); // , next); // don't skip nulls code.exec(item.write(item.getType())); loop.item(code, item.read(), done, next); mv.visitJumpInsn(Opcodes.GOTO, next); mv.visitLabel(done); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.IteratingSerializing.java
@Override public BytecodeSequence serializeTo(final BytecodeExpression source, final BytecodeExpression generator) { switch (encoding) { case JSON://from w w w . j av a 2s . c om return new BytecodeSequence() { @Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); final BytecodeExpression gen = code.evaluateOnce(generator); gen.generate(code); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), "writeStartArray", Type.getMethodDescriptor(Type.VOID_TYPE), false); code.exec(iterateAdapter.iterate(source, new IterateAdapter.IterateLoop() { @Override public void item(CodeEmitter code, BytecodeExpression item, Label abortLoop, Label nextItem) { code.exec(valueTypeSerializer.serializeTo(item, gen)); } })); gen.generate(code); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), "writeEndArray", Type.getMethodDescriptor(Type.VOID_TYPE), false); } }; case TBIN: // TODO: implement iterable TBin serialization (whoops, it requires you to know the count to write an array... hm?) // we may need to copy into a list throw new TodoException(); default: throw new UnsupportedOperationException(); } }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.JacksonParsePrimitive.java
@Override public void generate(CodeEmitter code) { parser.generate(code);/* w w w. jav a 2 s . co m*/ MethodVisitor mv = code.getMethodVisitor(); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonParser.class), "nextToken", Type.getMethodDescriptor(Type.getType(JsonToken.class)), false); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonToken.class), "ordinal", Type.getMethodDescriptor(Type.INT_TYPE), false); IntegerSwitchSequence seq = new IntegerSwitchSequence(); switch (getType().getJVMType().getSort()) { case Type.BOOLEAN: { seq.put(JsonToken.VALUE_TRUE.ordinal(), new InstructionConstant(getType(), -1)); seq.put(JsonToken.VALUE_FALSE.ordinal(), new InstructionConstant(getType(), 0)); break; } case Type.SHORT: { seq.put(JsonToken.VALUE_NUMBER_INT.ordinal(), new JacksonGet(Type.SHORT_TYPE, "getShortValue")); seq.put(JsonToken.VALUE_NUMBER_FLOAT.ordinal(), new JacksonGet(Type.SHORT_TYPE, "getShortValue")); break; } case Type.INT: { seq.put(JsonToken.VALUE_NUMBER_INT.ordinal(), new JacksonGet(Type.INT_TYPE, "getIntValue")); seq.put(JsonToken.VALUE_NUMBER_FLOAT.ordinal(), new JacksonGet(Type.INT_TYPE, "getIntValue")); break; } case Type.FLOAT: { seq.put(JsonToken.VALUE_NUMBER_INT.ordinal(), new JacksonGet(Type.FLOAT_TYPE, "getFloatValue")); seq.put(JsonToken.VALUE_NUMBER_FLOAT.ordinal(), new JacksonGet(Type.FLOAT_TYPE, "getFloatValue")); break; } case Type.LONG: { seq.put(JsonToken.VALUE_NUMBER_INT.ordinal(), new JacksonGet(Type.LONG_TYPE, "getLongValue")); seq.put(JsonToken.VALUE_NUMBER_FLOAT.ordinal(), new JacksonGet(Type.LONG_TYPE, "getLongValue")); break; } case Type.DOUBLE: { seq.put(JsonToken.VALUE_NUMBER_INT.ordinal(), new JacksonGet(Type.DOUBLE_TYPE, "getDoubleValue")); seq.put(JsonToken.VALUE_NUMBER_FLOAT.ordinal(), new JacksonGet(Type.DOUBLE_TYPE, "getDoubleValue")); break; } case Type.CHAR: { LocalCodeChunk chunk = new LocalBatchCode(new LocalFrame()); chunk.add(new JacksonGet(Type.getType(String.class), "getText")); chunk.add(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { MethodVisitor mv = code.getMethodVisitor(); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(String.class), "charAt", Type.getMethodDescriptor(Type.CHAR_TYPE, Type.INT_TYPE), false); } }); seq.put(JsonToken.VALUE_STRING.ordinal(), chunk); break; } default: throw new UnsupportedOperationException("Unknown primitive type: " + getType().getJVMType()); } seq.setDefaultSequence(new BytecodeSequence() { @Override public void generate(CodeEmitter code) { code.emitThrow(IllegalArgumentException.class, new StringConstantExpression(String .format("JSON type cannot be parsed into expected type '%s'", getType().getTypeName()))); } }); code.exec(seq); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.JacksonSerializeObject.java
@Override public void generate(CodeEmitter code) { jsonGenerator.generate(code);//from w w w . j a va 2s. c o m source.generate(code); MethodVisitor mv = code.getMethodVisitor(); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), "writeObject", Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class)), false); }
From source file:com.yahoo.yqlplus.engine.internal.plan.types.base.JacksonSerializePrimitive.java
@Override public void generate(CodeEmitter code) { jsonGenerator.generate(code);//from w w w.j a v a2s .c om source.generate(code); MethodVisitor mv = code.getMethodVisitor(); String desc = Type.getMethodDescriptor(Type.VOID_TYPE, source.getType().getJVMType()); String name; switch (source.getType().getJVMType().getSort()) { case Type.BOOLEAN: name = "writeBoolean"; break; case Type.SHORT: case Type.INT: case Type.FLOAT: case Type.LONG: case Type.DOUBLE: name = "writeNumber"; break; case Type.BYTE: case Type.CHAR: name = "writeObject"; desc = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(Object.class)); code.box(source.getType()); break; default: throw new UnsupportedOperationException("Unknown primitive type: " + source.getType().getJVMType()); } mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, Type.getInternalName(JsonGenerator.class), name, desc, false); }