Java Code Examples for org.objectweb.asm.Opcodes#LSTORE

The following examples show how to use org.objectweb.asm.Opcodes#LSTORE . 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: BytecodeMethod.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void addVariableOperation(int opcode, int var) {
    VarOp op = new VarOp(opcode, var);
    LocalVariable lv = null;
    switch (opcode) {
        case Opcodes.ISTORE:
            lv = new LocalVariable("v"+var, "I", "I", null, null, var); break;
        case Opcodes.LSTORE:
            lv = new LocalVariable("v"+var, "J", "J", null, null, var); break;    
        case Opcodes.FSTORE:
            lv = new LocalVariable("v"+var, "F", "F", null, null, var); break;
        case Opcodes.DSTORE:
            lv = new LocalVariable("v"+var, "D", "D", null, null, var); break;
    }
    if (lv != null && !localVariables.contains(lv)) {
        localVariables.add(lv);
    }
    addInstruction(op);
}
 
Example 2
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "No action required on default option.")
public void visitVarInsn(int opcode, int offset) {
    switch (opcode) {
        case Opcodes.ISTORE:
        case Opcodes.FSTORE:
        case Opcodes.ASTORE:
            localVariableExtension = Math.max(localVariableExtension, offset + 1);
            break;
        case Opcodes.LSTORE:
        case Opcodes.DSTORE:
            localVariableExtension = Math.max(localVariableExtension, offset + 2);
            break;
    }
    super.visitVarInsn(opcode, offset);
}
 
Example 3
Source File: LocalVariableAwareMethodVisitor.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "No action required on default option.")
public void visitVarInsn(int opcode, int offset) {
    switch (opcode) {
        case Opcodes.ISTORE:
        case Opcodes.FSTORE:
        case Opcodes.ASTORE:
            freeOffset = Math.max(freeOffset, offset + 1);
            break;
        case Opcodes.LSTORE:
        case Opcodes.DSTORE:
            freeOffset = Math.max(freeOffset, offset + 2);
            break;
    }
    super.visitVarInsn(opcode, offset);
}
 
Example 4
Source File: ASMUtils.java    From radon with GNU General Public License v3.0 6 votes vote down vote up
public static int getVarOpcode(Type type, boolean store) {
    switch (type.getSort()) {
        case Type.BOOLEAN:
        case Type.CHAR:
        case Type.BYTE:
        case Type.SHORT:
        case Type.INT:
            return store ? Opcodes.ISTORE : Opcodes.ILOAD;
        case Type.FLOAT:
            return store ? Opcodes.FSTORE : Opcodes.FLOAD;
        case Type.LONG:
            return store ? Opcodes.LSTORE : Opcodes.LLOAD;
        case Type.DOUBLE:
            return store ? Opcodes.DSTORE : Opcodes.DLOAD;
        case Type.ARRAY:
        case Type.OBJECT:
            return store ? Opcodes.ASTORE : Opcodes.ALOAD;
        default:
            throw new AssertionError("Unknown type: " + type.getClassName());
    }
}
 
Example 5
Source File: LocalVariablesSorter.java    From cglib with Apache License 2.0 5 votes vote down vote up
public void visitVarInsn(final int opcode, final int var) {
    int size;
    switch (opcode) {
        case Opcodes.LLOAD:
        case Opcodes.LSTORE:
        case Opcodes.DLOAD:
        case Opcodes.DSTORE:
            size = 2;
            break;
        default:
            size = 1;
    }
    mv.visitVarInsn(opcode, remap(var, size));
}
 
Example 6
Source File: AnalyzerAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  super.visitVarInsn(opcode, var);
  boolean isLongOrDouble =
      opcode == Opcodes.LLOAD
          || opcode == Opcodes.DLOAD
          || opcode == Opcodes.LSTORE
          || opcode == Opcodes.DSTORE;
  maxLocals = Math.max(maxLocals, var + (isLongOrDouble ? 2 : 1));
  execute(opcode, var, null);
}
 
Example 7
Source File: LocalVariablesSorter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  Type varType;
  switch (opcode) {
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
      varType = Type.LONG_TYPE;
      break;
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
      varType = Type.DOUBLE_TYPE;
      break;
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
      varType = Type.FLOAT_TYPE;
      break;
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
      varType = Type.INT_TYPE;
      break;
    case Opcodes.ALOAD:
    case Opcodes.ASTORE:
    case Opcodes.RET:
      varType = OBJECT_TYPE;
      break;
    default:
      throw new IllegalArgumentException("Invalid opcode " + opcode);
  }
  super.visitVarInsn(opcode, remap(var, varType));
}
 
Example 8
Source File: InstructionAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  switch (opcode) {
    case Opcodes.ILOAD:
      load(var, Type.INT_TYPE);
      break;
    case Opcodes.LLOAD:
      load(var, Type.LONG_TYPE);
      break;
    case Opcodes.FLOAD:
      load(var, Type.FLOAT_TYPE);
      break;
    case Opcodes.DLOAD:
      load(var, Type.DOUBLE_TYPE);
      break;
    case Opcodes.ALOAD:
      load(var, OBJECT_TYPE);
      break;
    case Opcodes.ISTORE:
      store(var, Type.INT_TYPE);
      break;
    case Opcodes.LSTORE:
      store(var, Type.LONG_TYPE);
      break;
    case Opcodes.FSTORE:
      store(var, Type.FLOAT_TYPE);
      break;
    case Opcodes.DSTORE:
      store(var, Type.DOUBLE_TYPE);
      break;
    case Opcodes.ASTORE:
      store(var, OBJECT_TYPE);
      break;
    case Opcodes.RET:
      ret(var);
      break;
    default:
      throw new IllegalArgumentException();
  }
}
 
Example 9
Source File: LocalVariablesSorter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  Type varType;
  switch (opcode) {
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
      varType = Type.LONG_TYPE;
      break;
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
      varType = Type.DOUBLE_TYPE;
      break;
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
      varType = Type.FLOAT_TYPE;
      break;
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
      varType = Type.INT_TYPE;
      break;
    case Opcodes.ALOAD:
    case Opcodes.ASTORE:
    case Opcodes.RET:
      varType = OBJECT_TYPE;
      break;
    default:
      throw new IllegalArgumentException("Invalid opcode " + opcode);
  }
  super.visitVarInsn(opcode, remap(var, varType));
}
 
Example 10
Source File: VarOp.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public boolean assignFrom(AssignableExpression ex, StringBuilder b) {
    b.append("    /* VarOp.assignFrom */ ");
    switch (opcode) {
        case Opcodes.ISTORE:
            return ex.assignTo("ilocals_"+var+"_", b);
            
        case Opcodes.LSTORE:
            return ex.assignTo("llocals_"+var+"_", b);
        case Opcodes.FSTORE:
            return ex.assignTo("flocals_"+var+"_", b);
        case Opcodes.DSTORE:
            return ex.assignTo("dlocals_"+var+"_", b);
        case Opcodes.ASTORE: {
            StringBuilder sb = new StringBuilder();
            sb.append("locals[").append(var).append("].type=CN1_TYPE_INVALID;");
            boolean res = ex.assignTo("locals["+var+"].data.o", sb);
            if (!res) {
                return false;
            }
            sb.append("locals[").append(var).append("].type=CN1_TYPE_OBJECT;");
            b.append(sb);
            return true;
        }
            
    }
    b.append("\n");
    return false;
}
 
Example 11
Source File: InstructionAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  switch (opcode) {
    case Opcodes.ILOAD:
      load(var, Type.INT_TYPE);
      break;
    case Opcodes.LLOAD:
      load(var, Type.LONG_TYPE);
      break;
    case Opcodes.FLOAD:
      load(var, Type.FLOAT_TYPE);
      break;
    case Opcodes.DLOAD:
      load(var, Type.DOUBLE_TYPE);
      break;
    case Opcodes.ALOAD:
      load(var, OBJECT_TYPE);
      break;
    case Opcodes.ISTORE:
      store(var, Type.INT_TYPE);
      break;
    case Opcodes.LSTORE:
      store(var, Type.LONG_TYPE);
      break;
    case Opcodes.FSTORE:
      store(var, Type.FLOAT_TYPE);
      break;
    case Opcodes.DSTORE:
      store(var, Type.DOUBLE_TYPE);
      break;
    case Opcodes.ASTORE:
      store(var, OBJECT_TYPE);
      break;
    case Opcodes.RET:
      ret(var);
      break;
    default:
      throw new IllegalArgumentException();
  }
}
 
Example 12
Source File: ANFTransform.java    From Concurnas with MIT License 5 votes vote down vote up
public static int getStoreOp(char c){
	switch(c){
		case 'Z': return Opcodes.ISTORE ;
		case 'B': return Opcodes.ISTORE ;
		case 'S': return Opcodes.ISTORE;
		case 'I': return Opcodes.ISTORE ;
		case 'J': return Opcodes.LSTORE ;
		case 'F': return Opcodes.FSTORE ;
		case 'D': return Opcodes.DSTORE ;
		case 'C': return Opcodes.ISTORE ;
		default:
			return Opcodes.ASTORE;
}
}
 
Example 13
Source File: ClassShapeRuleTest.java    From AVM with MIT License 5 votes vote down vote up
private static byte[] createVarHeavyClass(String className, int varCount, boolean isLong) {
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    writer.visit(Opcodes.V10, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, className, null, "java/lang/Object", new String[0]);
    MethodVisitor method = writer.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, "main", "()[B", null, null);
    Object oneLong = Long.valueOf(1L);
    Object oneInt = Integer.valueOf(1);
    Object value = isLong
            ? oneLong
            : oneInt;
    int storeOpcode = isLong ? Opcodes.LSTORE : Opcodes.ISTORE;
    // visitLdcInsn uses a type check so make sure that we got the type we were expecting (some compilers try to get clever here).
    if (isLong) {
        Assert.assertTrue(value instanceof Long);
    } else {
        Assert.assertTrue(value instanceof Integer);
    }
    // Note that we will actually invalidate the local variable n-1 when writing a long, but this is just to verify that it reserves the next slot.
    for (int i = 0; i < varCount; ++i) {
        method.visitLdcInsn(value);
        method.visitVarInsn(storeOpcode, i);
    }
    method.visitInsn(Opcodes.ACONST_NULL);
    method.visitInsn(Opcodes.ARETURN);
    method.visitMaxs(0, 0);
    method.visitEnd();
    writer.visitEnd();
    return writer.toByteArray();
}
 
Example 14
Source File: TreeInstructions.java    From instrumentation with Apache License 2.0 5 votes vote down vote up
public static VarInsnNode getStoreInst(Type type, int position) {
    int opCode = -1;
    switch (type.getDescriptor().charAt(0)) {
        case 'B':
            opCode = Opcodes.ISTORE;
            break;
        case 'C':
            opCode = Opcodes.ISTORE;
            break;
        case 'D':
            opCode = Opcodes.DSTORE;
            break;
        case 'F':
            opCode = Opcodes.FSTORE;
            break;
        case 'I':
            opCode = Opcodes.ISTORE;
            break;
        case 'J':
            opCode = Opcodes.LSTORE;
            break;
        case 'L':
            opCode = Opcodes.ASTORE;
            break;
        case '[':
            opCode = Opcodes.ASTORE;
            break;
        case 'Z':
            opCode = Opcodes.ISTORE;
            break;
        case 'S':
            opCode = Opcodes.ISTORE;
            break;
        default:
            throw new ClassFormatError("Invalid method signature: "
                    + type.getDescriptor());
    }
    return new VarInsnNode(opCode, position);
}
 
Example 15
Source File: InstructionAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  switch (opcode) {
    case Opcodes.ILOAD:
      load(var, Type.INT_TYPE);
      break;
    case Opcodes.LLOAD:
      load(var, Type.LONG_TYPE);
      break;
    case Opcodes.FLOAD:
      load(var, Type.FLOAT_TYPE);
      break;
    case Opcodes.DLOAD:
      load(var, Type.DOUBLE_TYPE);
      break;
    case Opcodes.ALOAD:
      load(var, OBJECT_TYPE);
      break;
    case Opcodes.ISTORE:
      store(var, Type.INT_TYPE);
      break;
    case Opcodes.LSTORE:
      store(var, Type.LONG_TYPE);
      break;
    case Opcodes.FSTORE:
      store(var, Type.FLOAT_TYPE);
      break;
    case Opcodes.DSTORE:
      store(var, Type.DOUBLE_TYPE);
      break;
    case Opcodes.ASTORE:
      store(var, OBJECT_TYPE);
      break;
    case Opcodes.RET:
      ret(var);
      break;
    default:
      throw new IllegalArgumentException();
  }
}
 
Example 16
Source File: LocalVariablesSorter.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public void visitVarInsn(final int opcode, final int var) {
  Type varType;
  switch (opcode) {
    case Opcodes.LLOAD:
    case Opcodes.LSTORE:
      varType = Type.LONG_TYPE;
      break;
    case Opcodes.DLOAD:
    case Opcodes.DSTORE:
      varType = Type.DOUBLE_TYPE;
      break;
    case Opcodes.FLOAD:
    case Opcodes.FSTORE:
      varType = Type.FLOAT_TYPE;
      break;
    case Opcodes.ILOAD:
    case Opcodes.ISTORE:
      varType = Type.INT_TYPE;
      break;
    case Opcodes.ALOAD:
    case Opcodes.ASTORE:
    case Opcodes.RET:
      varType = OBJECT_TYPE;
      break;
    default:
      throw new IllegalArgumentException("Invalid opcode " + opcode);
  }
  super.visitVarInsn(opcode, remap(var, varType));
}
 
Example 17
Source File: JVMImpl.java    From serianalyzer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param opcode
 * @param var
 * @param s
 */
static void handleVarInsn ( int opcode, int var, JVMStackState s ) {
    Set<BaseType> v;
    switch ( opcode ) {
    case Opcodes.LLOAD:
    case Opcodes.ILOAD:
    case Opcodes.FLOAD:
    case Opcodes.DLOAD:
    case Opcodes.ALOAD:
        v = s.getVariable(var);
        if ( log.isTraceEnabled() ) {
            log.trace("LOAD " + opcode + "@" + var + ":" + v); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        }
        if ( v == null || v.isEmpty() ) {
            s.push(new BasicVariable(toType(opcode), "unknown " + var, true)); //$NON-NLS-1$
        }
        else if ( v.size() == 1 ) {
            s.push(v.iterator().next());
        }
        else {
            Set<BaseType> alts = new HashSet<>();
            for ( BaseType o : v ) {
                if ( o instanceof MultiAlternatives && ! ( (MultiAlternatives) o ).getAlternatives().isEmpty() ) {
                    alts.addAll( ( (MultiAlternatives) o ).getAlternatives());
                }
                else {
                    alts.add(o);
                }
            }
            s.push(new MultiAlternatives(alts));
        }
        break;
    case Opcodes.LSTORE:
    case Opcodes.ISTORE:
    case Opcodes.FSTORE:
    case Opcodes.DSTORE:
    case Opcodes.ASTORE:
        s.getVariable(var).add(s.pop());
        break;
    case Opcodes.RET:
        break;
    default:
        log.warn("Unimplemented opcode " + opcode); //$NON-NLS-1$
    }
}
 
Example 18
Source File: VarOp.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void appendInstruction(StringBuilder b) {
    b.append("    ");
    switch(opcode) {
        case Opcodes.ILOAD:
            b.append("(*SP).type = CN1_TYPE_INT; /* ILOAD */ \n" +
                    "    (*SP).data.i = ilocals_");
            b.append(var);
            b.append("_; \n    SP++;\n");
            return;
        case Opcodes.LLOAD:
            b.append("BC_LLOAD(");
            break;
        case Opcodes.FLOAD:
            b.append("BC_FLOAD(");
            break;
        case Opcodes.DLOAD:
            b.append("BC_DLOAD(");
            break;
        case Opcodes.ALOAD:
            b.append("BC_ALOAD(");
            break;
        case Opcodes.ISTORE:
            b.append("BC_ISTORE(");
            break;
        case Opcodes.LSTORE:
            b.append("BC_LSTORE(");
            break;
        case Opcodes.FSTORE:
            b.append("BC_FSTORE(");
            break;
        case Opcodes.DSTORE:
            b.append("BC_DSTORE(");
            break;
        case Opcodes.ASTORE:
            b.append("BC_ASTORE(");
            break;
        case Opcodes.RET:
            b.append("/* RET TODO */");
            //b.append("goto label_");
            //b.append(var);
            //b.append("; /* RET */\n");
            return;
        case Opcodes.SIPUSH:
        case Opcodes.BIPUSH:
            b.append("PUSH_INT(");
            break;
        case Opcodes.NEWARRAY:
            switch(var) {
                case 4: // boolean
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BOOLEAN, sizeof(JAVA_ARRAY_BOOLEAN), 1));\n");
                    break;
                case 5: // char
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_CHAR, sizeof(JAVA_ARRAY_CHAR), 1));\n");
                    break;
                case 6: // float
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_FLOAT, sizeof(JAVA_ARRAY_FLOAT), 1));\n");
                    break;
                case 7: // double
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_DOUBLE, sizeof(JAVA_ARRAY_DOUBLE), 1));\n");
                    break;
                case 8: // byte
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_BYTE, sizeof(JAVA_ARRAY_BYTE), 1));\n");
                    break;
                case 9: // short
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_SHORT, sizeof(JAVA_ARRAY_SHORT), 1));\n");
                    break;
                case 10: // int
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_INT, sizeof(JAVA_ARRAY_INT), 1));\n");
                    break;
                case 11: // long 
                    b.append("PUSH_OBJ(allocArray(threadStateData, POP_INT(), &class_array1__JAVA_LONG, sizeof(JAVA_ARRAY_LONG), 1));\n");
                    break;
            }
            return;
        default:
            throw new RuntimeException("Missing opcode: " + opcode);
    }
    b.append(var);
    b.append(");\n");
}
 
Example 19
Source File: MethodVisitorBuilder.java    From testability-explorer with Apache License 2.0 4 votes vote down vote up
public void visitVarInsn(final int opcode, final int var) {
  switch (opcode) {
    case Opcodes.ILOAD :
      load(var, JavaType.INT);
      break;
    case Opcodes.LLOAD :
      load(var, JavaType.LONG);
      break;
    case Opcodes.FLOAD :
      load(var, JavaType.FLOAT);
      break;
    case Opcodes.DLOAD :
      load(var, JavaType.DOUBLE);
      break;
    case Opcodes.ALOAD :
      load(var, JavaType.OBJECT);
      break;

    case Opcodes.ISTORE :
      store(var, JavaType.INT);
      break;
    case Opcodes.LSTORE :
      store(var, JavaType.LONG);
      break;
    case Opcodes.FSTORE :
      store(var, JavaType.FLOAT);
      break;
    case Opcodes.DSTORE :
      store(var, JavaType.DOUBLE);
      break;
    case Opcodes.ASTORE :
      store(var, JavaType.OBJECT);
      break;

    case Opcodes.RET :
      recorder.add(new Runnable() {
        public void run() {
          block.addOp(new RetSub(lineNumber));
        }
      });
      break;
    default :
      throw new UnsupportedOperationException("opcode: " + opcode);
  }
}
 
Example 20
Source File: VarOp.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public boolean assignFrom(CustomInvoke ex, StringBuilder b) {
    b.append("    /* VarOp.assignFrom */ ");
    StringBuilder sb = new StringBuilder();
    switch (opcode) {
        case Opcodes.ISTORE:
            if (ex.appendExpression(sb)) {
                b.append("ilocals_").append(var).append("_ = ").append(sb.toString().trim()).append(";\n");
                return true;
            }
        break;
            
        case Opcodes.LSTORE:
            if (ex.appendExpression(sb)) {
                b.append("llocals_").append(var).append("_ = ").append(sb.toString().trim()).append(";\n");
                return true;
            }
        break;
        case Opcodes.FSTORE:
            if (ex.appendExpression(sb)) {
                b.append("flocals_").append(var).append("_ = ").append(sb.toString().trim()).append(";\n");
                return true;
            }
        break;
            
        case Opcodes.DSTORE:
            if (ex.appendExpression(sb)) {
                b.append("dlocals_").append(var).append("_ = ").append(sb.toString().trim()).append(";\n");
                return true;
            }
        break;

        case Opcodes.ASTORE: {
            StringBuilder sb2 = new StringBuilder();
            //sb2.append("locals[").append(var).append("].type=CN1_TYPE_INVALID; ");
            if (ex.appendExpression(sb)) {
                sb2.append("locals[").append(var).append("].data.o = ").append(sb.toString().trim()).append(";");
                sb2.append("locals[").append(var).append("].type=CN1_TYPE_OBJECT;");
                b.append(sb2);
                return true;
            }
            
        break;
           
        }
            
    }
    //b.append("\n");
    return false;
}