List of usage examples for org.objectweb.asm Opcodes ACONST_NULL
int ACONST_NULL
To view the source code for org.objectweb.asm Opcodes ACONST_NULL.
Click Source Link
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
/** * Implementing "static reflection" for the method getFooRaw so the * interpreter uses a switch instruction for ***GetRaw * based on the hash values of String names in this namespace. *///from www . java 2 s .co m private static void writeMethodGetRaw(ClassWriter cw, String className, String methodName, EnvironmentClass environmentClass, EnvSymbolNames symbolNames) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(Ljava/lang/String;)" + environmentClass.descriptor(), null, null); mv.visitCode(); Label beginFunction = new Label(); mv.visitLabel(beginFunction); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I"); mv.visitVarInsn(Opcodes.ISTORE, 2); Label beginLoop = new Label(); mv.visitLabel(beginLoop); Relation<String, Integer> hashCodeRelation = symbolNames.makeHashCodeRelation(environmentClass); ArrayList<Integer> sortedCodes = new ArrayList<Integer>(hashCodeRelation.secondSet()); Collections.sort(sortedCodes); Label returnNull = new Label(); getRawHelper(mv, className, hashCodeRelation, environmentClass, sortedCodes, returnNull); mv.visitLabel(returnNull); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); Label endFunction = new Label(); mv.visitLabel(endFunction); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, beginFunction, endFunction, 0); mv.visitLocalVariable("queryString", "Ljava/lang/String;", null, beginFunction, endFunction, 1); mv.visitLocalVariable("queryHashCode", "I", null, beginLoop, endFunction, 2); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(2, 3); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeNullGetter(ClassWriter cw, String className, String methodName, String signature) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, signature, null, null); mv.visitCode();//from w w w . j a v a 2 s. c om Label l0 = new Label(); mv.visitLabel(l0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); Label l1 = new Label(); mv.visitLabel(l1); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l1, 0); mv.visitLocalVariable("str", "Ljava/lang/String;", null, l0, l1, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(1, 2); mv.visitEnd(); }
From source file:com.sun.fortress.compiler.environments.TopLevelEnvGen.java
License:Open Source License
private static void writeRemoveMethod(ClassWriter cw, String className, String methodName, String invokeMethod, EnvironmentClass environmentClass) { MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, methodName, "(Ljava/lang/String;)V", null, null); mv.visitCode();/*from w ww .j a v a2 s .c o m*/ Label l0 = new Label(); mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, className, invokeMethod, "(Ljava/lang/String;" + environmentClass.descriptor() + ")V"); Label l1 = new Label(); mv.visitLabel(l1); mv.visitInsn(Opcodes.RETURN); Label l2 = new Label(); mv.visitLabel(l2); mv.visitLocalVariable("this", Naming.internalToDesc(className), null, l0, l2, 0); mv.visitLocalVariable("name", "Ljava/lang/String;", null, l0, l2, 1); // See comment above on ClassWriter.COMPUTE_FRAMES mv.visitMaxs(3, 2); mv.visitEnd(); }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
private static byte[] instantiateWrappedArrow(String name, List<String> parameters) { ManglingClassWriter cw = new ManglingClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); /*/*from w ww . j a v a 2s . c o m*/ * extends AbstractArrow[\parameters\] * * private final Arrow[\Object...Object\] wrappee * * Arrow[\Object...Object\] getWrappee() * * WrappedArrow[\parameters\](Arrow[\Object...Object\] _wrappee) * * public range_parameter apply( domain_parameters ) = * (range_parameter) wrappee.apply( domain_parameters ) */ Triple<List<String>, List<String>, String> stuff = normalizeArrowParameters(parameters); List<String> flat_params_and_ret = stuff.getA(); List<String> tupled_params_and_ret = stuff.getB(); String tupleType = stuff.getC(); List<String> flat_obj_params_and_ret = Useful.applyToAll(flat_params_and_ret, toJLO); List<String> norm_obj_params_and_ret = normalizeArrowParametersAndReturn(flat_obj_params_and_ret); List<String> norm_params_and_ret = normalizeArrowParametersAndReturn(flat_params_and_ret); String extendsClass = stringListToGeneric(ABSTRACT_ARROW, norm_params_and_ret); // List<String> objectified_parameters = Useful.applyToAll(flat_params_and_ret, toJLO); //String obj_sig = stringListToGeneric("AbstractArrow", objectified_parameters); String obj_intf_sig = stringListToGeneric(Naming.ARROW_TAG, norm_obj_params_and_ret); String wrappee_name = "wrappee"; //extends AbstractArrow[\parameters\] cw.visit(JVM_BYTECODE_VERSION, ACC_PUBLIC + ACC_SUPER, name, null, extendsClass, null); // private final Arrow[\Object...Object\] wrappee cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, wrappee_name, Naming.internalToDesc(obj_intf_sig), null /* for non-generic */, null /* instance has no value */); // WrappedArrow[\parameters\](Arrow[\Object...Object\] _wrappee) MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "(" + Naming.internalToDesc(obj_intf_sig) + ")V", null, null); mv.visitCode(); // super() mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKESPECIAL, extendsClass, "<init>", "()V"); // this.wrappee = wrappee mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 1); mv.visitFieldInsn(PUTFIELD, name, wrappee_name, Naming.internalToDesc(obj_intf_sig)); // done mv.visitInsn(RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); // getWrappee mv = cw.visitMethod(ACC_PUBLIC, getWrappee, "()" + Naming.internalToDesc(obj_intf_sig), null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name, wrappee_name, Naming.internalToDesc(obj_intf_sig)); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); // public range_parameter apply( domain_parameters ) = // (range_parameter) wrappee.apply( domain_parameters ) String flattened_apply_sig; if (parameters.size() == 2 && parameters.get(0).equals(Naming.INTERNAL_SNOWMAN)) flattened_apply_sig = arrowParamsToJVMsig(parameters.subList(1, 2)); else flattened_apply_sig = arrowParamsToJVMsig(flat_params_and_ret); String obj_apply_sig = arrowParamsToJVMsig(flat_obj_params_and_ret); mv = cw.visitMethod(ACC_PUBLIC, Naming.APPLY_METHOD, flattened_apply_sig, null, null); mv.visitCode(); // load wrappee for delegation mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name, wrappee_name, Naming.internalToDesc(obj_intf_sig)); // Push parameters. // i is indexed so that it corresponds to parameters pushed, even though // the types are ignored here (for now). for (int i = 0; i < flat_params_and_ret.size() - 1; i++) { String t = flat_params_and_ret.get(i); if (!t.equals(Naming.INTERNAL_SNOWMAN)) { mv.visitVarInsn(ALOAD, i + 1); } else { /* we are calling the object-interface version of this, * we need something on the stack, or else it will fail. * * This is also a naming/refactoring FAIL; this information * needs to come from somewhere else. */ mv.visitInsn(Opcodes.ACONST_NULL); // mv.visitMethodInsn(Opcodes.INVOKESTATIC, // Naming.runtimeValues + "FVoid", "make", // "()" + Naming.internalToDesc(Naming.runtimeValues + "FVoid")); } } mv.visitMethodInsn(INVOKEINTERFACE, obj_intf_sig, Naming.APPLY_METHOD, obj_apply_sig); // mv.visitTypeInsn(Opcodes.CHECKCAST, parameters.get(parameters.size()-1)); generalizedCastTo(mv, flat_params_and_ret.get(flat_params_and_ret.size() - 1)); // done mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); //getRTTI - forwards to wrapped arrow { mv = cw.visitMethod(ACC_PUBLIC, Naming.RTTI_GETTER, "()" + Naming.RTTI_CONTAINER_DESC, null, null); mv.visitCode(); // load wrappee for delegation mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, name, wrappee_name, Naming.internalToDesc(obj_intf_sig)); //invoke interface getRTTI method mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, Naming.ANY_TYPE_CLASS, Naming.RTTI_GETTER, Naming.STATIC_PARAMETER_GETTER_SIG); mv.visitInsn(ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
public static void pushArgs(MethodVisitor mv, int first_arg, int n_args, List<Boolean> nulls) { int nulls_pushed = 0; for (int arg = 0; arg < n_args; arg++) { if (nulls.get(arg)) { mv.visitInsn(Opcodes.ACONST_NULL); nulls_pushed++;/*from ww w. ja v a2 s . c om*/ } else { mv.visitVarInsn(Opcodes.ALOAD, arg + first_arg - nulls_pushed); } } }
From source file:com.sun.fortress.runtimeSystem.InstantiatingClassloader.java
License:Open Source License
public static void pushArgsIntoArray(MethodVisitor mv, int first_arg, int n_args, int array_offset, List<Boolean> nulls) { int nulls_pushed = 0; for (int arg = 0; arg < n_args; arg++) { mv.visitVarInsn(Opcodes.ALOAD, array_offset); mv.visitLdcInsn(arg); //index is the static param number if (nulls.get(arg)) { mv.visitInsn(Opcodes.ACONST_NULL); nulls_pushed++;/*w w w . ja va 2s . c o m*/ } else { mv.visitVarInsn(Opcodes.ALOAD, arg + first_arg - nulls_pushed); } mv.visitInsn(Opcodes.AASTORE); } mv.visitVarInsn(ALOAD, array_offset); }
From source file:com.trigersoft.jaque.expression.ExpressionMethodVisitor.java
License:Apache License
@Override public void visitInsn(int opcode) { Expression e;/* w w w.ja v a 2 s .c o m*/ Expression first; Expression second; switch (opcode) { case Opcodes.ARRAYLENGTH: e = Expression.arrayLength(_exprStack.pop()); break; case Opcodes.ACONST_NULL: e = Expression.constant(null, Object.class); break; case Opcodes.IALOAD: case Opcodes.LALOAD: case Opcodes.FALOAD: case Opcodes.DALOAD: case Opcodes.AALOAD: case Opcodes.BALOAD: case Opcodes.CALOAD: case Opcodes.SALOAD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.arrayIndex(second, first); break; case Opcodes.DCONST_0: e = Expression.constant(0d, Double.TYPE); break; case Opcodes.DCONST_1: e = Expression.constant(1d, Double.TYPE); break; case Opcodes.FCMPG: case Opcodes.FCMPL: case Opcodes.DCMPG: case Opcodes.DCMPL: case Opcodes.LCMP: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.FCONST_0: e = Expression.constant(0f, Float.TYPE); break; case Opcodes.FCONST_1: e = Expression.constant(1f, Float.TYPE); break; case Opcodes.FCONST_2: e = Expression.constant(2f, Float.TYPE); break; case Opcodes.ICONST_M1: e = Expression.constant(-1, Integer.TYPE); break; case Opcodes.ICONST_0: e = Expression.constant(0, Integer.TYPE); break; case Opcodes.ICONST_1: e = Expression.constant(1, Integer.TYPE); break; case Opcodes.ICONST_2: e = Expression.constant(2, Integer.TYPE); break; case Opcodes.ICONST_3: e = Expression.constant(3, Integer.TYPE); break; case Opcodes.ICONST_4: e = Expression.constant(4, Integer.TYPE); break; case Opcodes.ICONST_5: e = Expression.constant(5, Integer.TYPE); break; case Opcodes.LCONST_0: e = Expression.constant(0l, Long.TYPE); break; case Opcodes.LCONST_1: e = Expression.constant(1l, Long.TYPE); break; case Opcodes.IADD: case Opcodes.LADD: case Opcodes.FADD: case Opcodes.DADD: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.add(second, first); break; case Opcodes.ISUB: case Opcodes.LSUB: case Opcodes.FSUB: case Opcodes.DSUB: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.subtract(second, first); break; case Opcodes.IMUL: case Opcodes.LMUL: case Opcodes.FMUL: case Opcodes.DMUL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.multiply(second, first); break; case Opcodes.IDIV: case Opcodes.LDIV: case Opcodes.FDIV: case Opcodes.DDIV: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.divide(second, first); break; case Opcodes.IREM: case Opcodes.LREM: case Opcodes.FREM: case Opcodes.DREM: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.modulo(second, first); break; case Opcodes.INEG: case Opcodes.LNEG: case Opcodes.FNEG: case Opcodes.DNEG: first = _exprStack.pop(); e = Expression.negate(first); break; case Opcodes.ISHL: case Opcodes.LSHL: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.leftShift(second, first); break; case Opcodes.ISHR: case Opcodes.LSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IUSHR: case Opcodes.LUSHR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.rightShift(second, first); break; case Opcodes.IAND: case Opcodes.LAND: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseAnd(second, first); break; case Opcodes.IOR: case Opcodes.LOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.bitwiseOr(second, first); break; case Opcodes.IXOR: case Opcodes.LXOR: first = _exprStack.pop(); second = _exprStack.pop(); e = Expression.exclusiveOr(second, first); break; case Opcodes.I2B: case Opcodes.I2C: case Opcodes.I2S: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup2[opcode - Opcodes.I2B]); break; case Opcodes.I2L: case Opcodes.I2F: case Opcodes.I2D: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.I2L + 1]); break; case Opcodes.L2I: case Opcodes.L2F: case Opcodes.L2D: int l2l = opcode > Opcodes.L2I ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.L2I + l2l]); break; case Opcodes.F2I: case Opcodes.F2L: case Opcodes.F2D: int f2f = opcode == Opcodes.F2D ? 1 : 0; first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.F2I + f2f]); break; case Opcodes.D2I: case Opcodes.D2L: case Opcodes.D2F: first = _exprStack.pop(); e = Expression.convert(first, NumericTypeLookup[opcode - Opcodes.D2I]); break; case Opcodes.IRETURN: case Opcodes.LRETURN: case Opcodes.FRETURN: case Opcodes.DRETURN: case Opcodes.ARETURN: go(null); return; case Opcodes.SWAP: first = _exprStack.pop(); second = _exprStack.pop(); _exprStack.push(first); _exprStack.push(second); case Opcodes.DUP: case Opcodes.DUP_X1: case Opcodes.DUP_X2: case Opcodes.DUP2: case Opcodes.DUP2_X1: case Opcodes.DUP2_X2: // our stack is not divided to words int base = (opcode - Opcodes.DUP) % 3; base++; dup(_exprStack, base, base - 1); return; case Opcodes.NOP: return; case Opcodes.RETURN: default: throw notLambda(opcode); } _exprStack.push(e); }
From source file:com.xruby.compiler.codegen.MethodGenerator.java
License:BSD License
public void pushNull() { visitInsn(Opcodes.ACONST_NULL); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.CodeEmitterTest.java
@Test public void requireSimpleAdd() throws Exception { UnitGenerator unit = new UnitGenerator("foo", source); unit.addInterface(Callable.class); MethodGenerator gen = unit.createMethod("call"); gen.setReturnType(AnyTypeWidget.getInstance()); final BytecodeExpression leftExpr = source.constant(1); final BytecodeExpression rightExpr = source.constant(1); gen.add(new BytecodeSequence() { @Override//from www .j av a 2s . c o m public void generate(CodeEmitter code) { Label hasNull = new Label(); CodeEmitter.Unification unify = code.unifiedEmit(leftExpr, rightExpr, hasNull); code.getMethodVisitor().visitInsn(Opcodes.IADD); code.box(BaseTypeAdapter.INT32); code.getMethodVisitor().visitInsn(Opcodes.ARETURN); if (unify.nullPossible) { code.getMethodVisitor().visitLabel(hasNull); code.getMethodVisitor().visitInsn(Opcodes.ACONST_NULL); code.getMethodVisitor().visitInsn(Opcodes.ARETURN); } } }); source.build(); Class<? extends Callable> clazz = (Class<? extends Callable>) source.getGeneratedClass(unit); Callable c = clazz.newInstance(); Assert.assertEquals(2, c.call()); }
From source file:com.yahoo.yqlplus.engine.internal.bytecode.CodeEmitterTest.java
@Test public void requireWidenAdd() throws Exception { UnitGenerator unit = new UnitGenerator("foo", source); unit.addInterface(Callable.class); MethodGenerator gen = unit.createMethod("call"); gen.setReturnType(AnyTypeWidget.getInstance()); final BytecodeExpression leftExpr = source.constant(1); final BytecodeExpression rightExpr = source.constant(1L); gen.add(new BytecodeSequence() { @Override/*from w w w .j a v a 2s. com*/ public void generate(CodeEmitter code) { Label hasNull = new Label(); CodeEmitter.Unification unify = code.unifiedEmit(leftExpr, rightExpr, hasNull); code.getMethodVisitor().visitInsn(Opcodes.LADD); code.box(BaseTypeAdapter.INT64); code.getMethodVisitor().visitInsn(Opcodes.ARETURN); if (unify.nullPossible) { code.getMethodVisitor().visitLabel(hasNull); code.getMethodVisitor().visitInsn(Opcodes.ACONST_NULL); code.getMethodVisitor().visitInsn(Opcodes.ARETURN); } } }); source.build(); Class<? extends Callable> clazz = (Class<? extends Callable>) source.getGeneratedClass(unit); Callable c = clazz.newInstance(); Assert.assertEquals(2L, c.call()); }