List of usage examples for org.objectweb.asm Opcodes ISTORE
int ISTORE
To view the source code for org.objectweb.asm Opcodes ISTORE.
Click Source Link
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void generateTransition(MethodVisitor mv, DfaState source, DfaState target) { if (source.isTerminal() && source != target) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_M1); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I"); }// ww w .j a v a2 s . c o m mv.visitIntInsn(Opcodes.SIPUSH, target.getIndex()); mv.visitVarInsn(Opcodes.ISTORE, 5); if (target.isTerminal() && source != target) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitIntInsn(Opcodes.SIPUSH, target.getDomains()[0]); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I"); } debug(mv, "DFA: " + source.getIndex() + " -> " + target.getIndex() + " " + Arrays.toString(target.getDomains())); if (target.isTerminal()) { Label noReluctant = new Label(); mv.visitVarInsn(Opcodes.ILOAD, 4); mv.visitJumpInsn(Opcodes.IFEQ, noReluctant); mv.visitIincInsn(2, 1); debug(mv, "DFA reached terminal state"); mv.visitJumpInsn(Opcodes.GOTO, saveLabel); mv.visitLabel(noReluctant); } if (source.getIndex() + 1 == target.getIndex()) { mv.visitIincInsn(2, 1); generateLengthGuard(mv); mv.visitJumpInsn(Opcodes.GOTO, stateLabels[target.getIndex()]); } else { mv.visitJumpInsn(Opcodes.GOTO, continueLabel); } }
From source file:org.testeoa.estatica.AdapterDUG.java
License:Open Source License
@Override public void visitVarInsn(int opcode, int var) { String ins = getInstrucao(opcode) + " " + var; addInstrucao(ins);// ww w . ja v a 2 s . co m // Anlise do Fluxo de Dados if (opcode >= Opcodes.ILOAD && opcode <= Opcodes.ALOAD) { addUso(var); } if (opcode >= Opcodes.ISTORE && opcode <= Opcodes.ASTORE) { addDef(var); } super.visitVarInsn(opcode, var); }
From source file:pku.sei.checkedcoverage.slicing.Slicer.java
License:Creative Commons License
/** * select the last location that was not checked, and create new slice criterion for it. * remove the relative lines from unchecked lines, until all location are sliced. * @return the new created slice location for every class. *//*from w w w .j a v a 2 s .c o m*/ public static HashMap<String, TreeSet<Long>> sliceForUnchecked() { System.out.println("Trying to add checks"); HashMap<String, TreeSet<Long>> sliceCreated = new HashMap<String, TreeSet<Long>>(); HashMap<String, HashSet<Instruction>> uncheckedMap = getUncheckedMap(); Iterator<String> it = uncheckedMap.keySet().iterator(); List<String> cris = new ArrayList<String>(); int crisNr = 0; while (it.hasNext()) { String key = it.next(); sliceCreated.put(key, new TreeSet<Long>()); HashSet<Instruction> insts = uncheckedMap.get(key); TreeSet<Integer> unchecked = new TreeSet<Integer>(); HashMap<Integer, String> critInfoMap = new HashMap<Integer, String>(); HashMap<Integer, HashSet<String>> varsMap = new HashMap<Integer, HashSet<String>>(); for (Instruction inst : insts) { if (inst.getType().equals(InstructionType.FIELD) || inst.getType().equals(InstructionType.VAR)) { unchecked.add(inst.getLineNumber()); if (!critInfoMap.containsKey(inst.getLineNumber())) { critInfoMap.put(inst.getLineNumber(), inst.getMethod().getReadClass().getName() + "." + inst.getMethod().getName()); } if (!varsMap.containsKey(inst.getLineNumber())) { varsMap.put(inst.getLineNumber(), new HashSet<String>()); } if (inst.getType().equals(InstructionType.FIELD)) { FieldInstruction fieldinst = (FieldInstruction) inst; varsMap.get(inst.getLineNumber()).add(fieldinst.getFieldName()); } else if (inst.getType().equals(InstructionType.VAR)) { VarInstruction varinst = (VarInstruction) inst; if (varinst.getOpcode() == Opcodes.DSTORE || varinst.getOpcode() == Opcodes.ASTORE || varinst.getOpcode() == Opcodes.LSTORE || varinst.getOpcode() == Opcodes.ISTORE || varinst.getOpcode() == Opcodes.FSTORE || varinst.getOpcode() == Opcodes.RET) { String varname = inst.getMethod().getLocalVariables()[varinst.getLocalVarIndex()] .getName(); varsMap.get(inst.getLineNumber()).add(varname); } } } } while (!unchecked.isEmpty()) { int last = unchecked.last(); String cri = critInfoMap.get(last) + ":" + last + ":*"; cris.add(cri); System.out.println(++crisNr + " new check(s) added!" + cri); unchecked.removeAll(sliceUnchecked(cri)); sliceCreated.get(key).add((long) last); unchecked.remove(last); } } System.out.println("Done!"); return sliceCreated; }
From source file:pku.sei.checkedcoverage.slicing.Slicer.java
License:Creative Commons License
public void process(ThreadId threadId, final List<SlicingCriterion> sc, boolean multithreaded) throws InterruptedException { DependencesExtractor<SlicerInstance> depExtractor = DependencesExtractor.forTrace(this.trace, SlicerInstanceFactory.instance); for (ProgressMonitor mon : this.progressMonitors) depExtractor.addProgressMonitor(mon); VisitorCapability[] capabilities = { VisitorCapability.CONTROL_DEPENDENCES, VisitorCapability.DATA_DEPENDENCES_READ_AFTER_WRITE, VisitorCapability.INSTRUCTION_EXECUTIONS, VisitorCapability.METHOD_ENTRY_LEAVE, VisitorCapability.CONTROL_DEPENDENCES }; if (this.untracedCallVisitors.size() > 0) capabilities[capabilities.length - 1] = VisitorCapability.UNTRACED_METHOD_CALLS; final List<SliceVisitor> sliceVisitors0 = Slicer.this.sliceVisitors; final List<UntracedCallVisitor> untracedCallVisitors0 = Slicer.this.untracedCallVisitors; depExtractor.registerVisitor(new DependencesVisitorAdapter<SlicerInstance>() { private final List<SlicingCriterionInstance> slicingCritInst = instantiateSlicingCriteria(sc); @SuppressWarnings("unchecked") private IntegerMap<Object>[] interestingLocalVariables = (IntegerMap<Object>[]) new IntegerMap<?>[0]; private long[] critOccurenceNumbers = new long[2]; // 0 if not in a criterion private final SliceVisitor[] sliceVisitorsArray = sliceVisitors0 .toArray(new SliceVisitor[sliceVisitors0.size()]); private final UntracedCallVisitor[] untracedCallsVisitorsArray = untracedCallVisitors0 .toArray(new UntracedCallVisitor[untracedCallVisitors0.size()]); private ReadMethod enteredMethod; private List<SlicingCriterionInstance> instantiateSlicingCriteria(List<SlicingCriterion> criteria) { if (criteria.isEmpty()) return Collections.emptyList(); else if (criteria.size() == 1) return Collections.singletonList(criteria.get(0).getInstance()); else { List<SlicingCriterionInstance> instances = new ArrayList<SlicingCriterionInstance>( criteria.size()); for (SlicingCriterion crit : criteria) instances.add(crit.getInstance()); return instances; }/* www .j a v a2 s . c o m*/ } @Override public void visitInstructionExecution(SlicerInstance instance) { int stackDepth = instance.getStackDepth(); if (this.critOccurenceNumbers.length <= stackDepth) { long[] newCritOccurenceNumbers = new long[2 * Math.max(this.critOccurenceNumbers.length, stackDepth)]; System.arraycopy(this.critOccurenceNumbers, 0, newCritOccurenceNumbers, 0, this.critOccurenceNumbers.length); this.critOccurenceNumbers = newCritOccurenceNumbers; } Instruction instruction = instance.getInstruction(); for (SlicingCriterionInstance crit : this.slicingCritInst) { if (crit.matches(instance)) { this.critOccurenceNumbers[stackDepth] = crit.getOccurenceNumber(); assert (this.critOccurenceNumbers[stackDepth] > 0); // for each criterion, there are three cases: // - track all data read in this line // - track a given set of local variables // - track the control dependences of this instruction // only in the last case, the instructions from that line are added to the dynamic slice if (crit.matchAllData()) { instance.allDataInteresting = true; instance.onlyIfAfterCriterion = true; instance.onDynamicSlice = true; // it's not really on the dynamic slice, but we have to set this instance.criterionDistance = 0; } else { if (crit.hasLocalVariables()) { if (this.interestingLocalVariables.length <= stackDepth) { @SuppressWarnings("unchecked") IntegerMap<Object>[] newInterestingLocalVariables = (IntegerMap<Object>[]) new IntegerMap<?>[Math .max(stackDepth + 1, this.interestingLocalVariables.length * 3 / 2)]; System.arraycopy(this.interestingLocalVariables, 0, newInterestingLocalVariables, 0, this.interestingLocalVariables.length); this.interestingLocalVariables = newInterestingLocalVariables; } List<LocalVariable> localVariables = crit.getLocalVariables(); if (this.interestingLocalVariables[stackDepth] == null) this.interestingLocalVariables[stackDepth] = new IntegerMap<Object>( localVariables.size() * 4 / 3 + 1); for (LocalVariable i : localVariables) this.interestingLocalVariables[stackDepth].put(i.getIndex(), null); } else { Instruction insn = instruction; if (insn.getType() != InstructionType.LABEL) for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(instance); instance.onDynamicSlice = true; instance.criterionDistance = 0; } } } else if (this.critOccurenceNumbers[stackDepth] != 0) { this.critOccurenceNumbers[stackDepth] = 0; } } if (this.interestingLocalVariables.length > stackDepth && this.interestingLocalVariables[stackDepth] != null) { switch (instruction.getOpcode()) { case Opcodes.ISTORE: case Opcodes.ASTORE: case Opcodes.LSTORE: case Opcodes.FSTORE: case Opcodes.DSTORE: VarInstruction varInsn = (VarInstruction) instruction; if (this.interestingLocalVariables[stackDepth].containsKey(varInsn.getLocalVarIndex())) { this.interestingLocalVariables[stackDepth].remove(varInsn.getLocalVarIndex()); if (this.interestingLocalVariables[stackDepth].isEmpty()) this.interestingLocalVariables[stackDepth] = null; for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(instance); instance.onDynamicSlice = true; // and we want to know where the data comes from... instance.allDataInteresting = true; instance.criterionDistance = 0; } break; case Opcodes.INVOKEINTERFACE: case Opcodes.INVOKESPECIAL: case Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: if (this.enteredMethod != null) { MethodInvocationInstruction mtdInvInsn = (MethodInvocationInstruction) instruction; int paramCount = instruction.getOpcode() == INVOKESTATIC ? 0 : 1; for (int param = mtdInvInsn.getParameterCount() - 1; param >= 0; --param) paramCount += mtdInvInsn.parameterIsLong(param) ? 2 : 1; boolean enteredMethodMatches = this.enteredMethod.getName() .equals(mtdInvInsn.getInvokedMethodName()) && this.enteredMethod.getDesc().equals(mtdInvInsn.getInvokedMethodDesc()); if (enteredMethodMatches) { boolean localVarsMatched = false; for (int varNr = 0; varNr < paramCount; ++varNr) { if (this.interestingLocalVariables[stackDepth].containsKey(varNr)) { this.interestingLocalVariables[stackDepth].remove(varNr); if (this.interestingLocalVariables[stackDepth].isEmpty()) this.interestingLocalVariables[stackDepth] = null; localVarsMatched = true; instance.onDynamicSlice = true; // and we want to know where the data comes from... // TODO instance.allDataInteresting = true; instance.criterionDistance = 0; } } if (localVarsMatched) for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(instance); } } } } this.enteredMethod = null; } @Override public void visitControlDependence(SlicerInstance from, SlicerInstance to) { if (from.onDynamicSlice) { Instruction insn = to.getInstruction(); if (insn.getType() == InstructionType.LABEL || insn.getOpcode() == Opcodes.GOTO) { if (to.predecessors == null) to.predecessors = Collections.singleton(from); else { if (to.predecessors.size() == 1) to.predecessors = new HashSet<SlicerInstance>(to.predecessors); to.predecessors.add(from); } if (from.criterionDistance < to.criterionDistance) to.criterionDistance = from.criterionDistance; } else if (from.predecessors != null) { assert (!from.predecessors.isEmpty()); for (SlicerInstance pred : from.predecessors) { int distance = pred.criterionDistance + 1; delegateControlSliceDependence(pred, to, distance); if (distance < to.criterionDistance) to.criterionDistance = distance; } } else { int distance = from.criterionDistance + 1; delegateControlSliceDependence(from, to, distance); if (distance < to.criterionDistance) to.criterionDistance = distance; } to.onDynamicSlice = true; } } private void delegateControlSliceDependence(SlicerInstance from, SlicerInstance to, int distance) { for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitSliceDependence(from, to, null, distance); // since "to" controls the execution of "from", we want to track all data dependences of "to" // to find out why it took this decision // exception: method invocations; here we only want to track why the method was executed, // but not the data that it consumed // important to check that "from" comes from inside the method which is called by "from" boolean calledMethodDependence = false; if (to.getInstruction().getType() == InstructionType.METHODINVOCATION) { MethodInvocationInstruction mtdInv = (MethodInvocationInstruction) to.getInstruction(); ReadMethod calledMethod = from.getInstruction().getMethod(); if (mtdInv.getInvokedMethodName().equals(calledMethod.getName()) && mtdInv.getInvokedMethodDesc().equals(calledMethod.getDesc())) { calledMethodDependence = true; } } if (!calledMethodDependence) { to.allDataInteresting = true; } } @Override public void visitDataDependence(SlicerInstance from, SlicerInstance to, Collection<? extends Variable> fromVars, Variable toVar, DataDependenceType type) throws InterruptedException { assert type == DataDependenceType.READ_AFTER_WRITE; if (from.onDynamicSlice && // from must definitively be on the dynamic slice ((from.allDataInteresting && (!from.onlyIfAfterCriterion || this.critOccurenceNumbers[to.getStackDepth()] == 0)) || // and either we want to track all data dependencies (from.interestingVariable != null && ( // or (if the interestingVariable is set) ... from.interestingVariable.equals(toVar) || // the interestingVariable must be the one we are just visiting (from.moreInterestingVariables != null && from.moreInterestingVariables.contains(toVar)))))) { // or it must be in the set of more variables Instruction insn = to.getInstruction(); assert insn.getType() != InstructionType.LABEL; if (from.onlyIfAfterCriterion) { to.criterionDistance = 0; for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitMatchedInstance(to); } else { int distance = from.criterionDistance + 1; if (distance < to.criterionDistance) to.criterionDistance = distance; for (SliceVisitor vis : this.sliceVisitorsArray) vis.visitSliceDependence(from, to, toVar, distance); } if (!fromVars.isEmpty()) { Iterator<? extends Variable> varIt = fromVars.iterator(); assert varIt .hasNext() : "Iterator of a non-empty collection should have at least one element"; Variable first = varIt.next(); if (to.interestingVariable == null || to.interestingVariable.equals(first)) { to.interestingVariable = first; first = varIt.hasNext() ? varIt.next() : null; } if (first != null) { if (to.moreInterestingVariables == null) to.moreInterestingVariables = new HashSet<Variable>(8); to.moreInterestingVariables.add(first); while (varIt.hasNext()) to.moreInterestingVariables.add(varIt.next()); } } to.onDynamicSlice = true; } } @Override public void visitMethodLeave(ReadMethod method, int stackDepth) throws InterruptedException { if (this.interestingLocalVariables.length > stackDepth && this.interestingLocalVariables[stackDepth] != null) { this.interestingLocalVariables[stackDepth] = null; } } @Override public void visitMethodEntry(ReadMethod method, int stackDepth) throws InterruptedException { if (this.interestingLocalVariables.length > stackDepth && this.interestingLocalVariables[stackDepth] != null) { this.enteredMethod = method; this.interestingLocalVariables[stackDepth] = null; } } @Override public void visitUntracedMethodCall(SlicerInstance instrInstance) throws InterruptedException { for (UntracedCallVisitor vis : this.untracedCallsVisitorsArray) vis.visitUntracedMethodCall(instrInstance); } }, capabilities); depExtractor.processBackwardTrace(threadId, multithreaded); }
From source file:portablejim.veinminer.asm.ItemInWorldManagerTransformer.java
License:Open Source License
private int insertCallAfterTryHarvestBlockFunction(MethodNode curMethod, String obfuscatedClassName, int startIndex) throws IndexOutOfBoundsException { LocalVariablesSorter varSorter = new LocalVariablesSorter(curMethod.access, curMethod.desc, curMethod); String worldType = typemap.get(getCorrectName("theWorld")); String playerType = typemap.get(getCorrectName("thisPlayerMP")); while (!isMethodWithName(curMethod.instructions.get(startIndex), "tryHarvestBlock")) { ++startIndex;/* w w w . ja va2s . co m*/ } do { --startIndex; } while (curMethod.instructions.get(startIndex).getType() == AbstractInsnNode.VAR_INSN); int blockVarIndex = varSorter.newLocal(Type.getType(BlockID.class)); curMethod.instructions.insert(curMethod.instructions.get(startIndex), buildBlockIdFunctionCall(obfuscatedClassName, worldType, blockVarIndex)); ++startIndex; while (!isMethodWithName(curMethod.instructions.get(startIndex), "tryHarvestBlock")) { ++startIndex; } // Add variable to store result int newVarIndex = varSorter.newLocal(Type.BOOLEAN_TYPE); VarInsnNode newVar = new VarInsnNode(Opcodes.ISTORE, newVarIndex); curMethod.instructions.insert(curMethod.instructions.get(startIndex), newVar); ++startIndex; // Add in function call to call function InsnList veinMinerFunctionCall = new InsnList(); veinMinerFunctionCall .add(new FieldInsnNode(Opcodes.GETSTATIC, targetClassName, "instance", targetClassType)); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, 0)); veinMinerFunctionCall.add(new FieldInsnNode(Opcodes.GETFIELD, obfuscatedClassName.replace(".", "/"), getCorrectName("theWorld"), typemap.get(getCorrectName("theWorld")))); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, 0)); veinMinerFunctionCall.add(new FieldInsnNode(Opcodes.GETFIELD, obfuscatedClassName.replace(".", "/"), getCorrectName("thisPlayerMP"), typemap.get(getCorrectName("thisPlayerMP")))); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 1)); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 2)); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, 3)); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ILOAD, newVarIndex)); veinMinerFunctionCall.add(new VarInsnNode(Opcodes.ALOAD, blockVarIndex)); String blockIdClassType = String.format("L%s;", blockIdClassName); veinMinerFunctionCall.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, targetClassName, targetMethodName, String.format(targetMethodType, worldType, playerType, blockIdClassType))); curMethod.instructions.insert(curMethod.instructions.get(startIndex), veinMinerFunctionCall); ++startIndex; // Get rid of un-needed POP. while (curMethod.instructions.get(startIndex).getOpcode() != Opcodes.POP) { ++startIndex; } curMethod.instructions.remove(curMethod.instructions.get(startIndex)); return startIndex; }
From source file:scouter.agent.asm.ApicallASM.java
License:Apache License
private void capReturn() { Type tp = returnType;//from w w w . j a va 2 s.c o m if (tp == null || tp.equals(Type.VOID_TYPE)) { mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESUBCALL, END_METHOD, END_SIGNATURE, false); return; } int i = newLocal(tp); switch (tp.getSort()) { case Type.BOOLEAN: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.BYTE: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.CHAR: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.SHORT: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.INT: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.LONG: mv.visitVarInsn(Opcodes.LSTORE, i); mv.visitVarInsn(Opcodes.LLOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.LLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FSTORE, i); mv.visitVarInsn(Opcodes.FLOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.FLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DSTORE, i); mv.visitVarInsn(Opcodes.DLOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.DLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; default: mv.visitVarInsn(Opcodes.ASTORE, i); mv.visitVarInsn(Opcodes.ALOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ALOAD, i);// return mv.visitInsn(Opcodes.ACONST_NULL);// throwable } mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESUBCALL, END_METHOD, END_SIGNATURE, false); }
From source file:scouter.agent.asm.CapReturnASM.java
License:Apache License
private void capReturn() { Type tp = returnType;//from w w w. java2s .c om if (tp == null || tp.equals(Type.VOID_TYPE)) { pushCommon(); mv.visitInsn(ACONST_NULL); mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE, false); return; } int i = newLocal(tp); switch (tp.getSort()) { case Type.BOOLEAN: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false); break; case Type.BYTE: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false); break; case Type.CHAR: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false); break; case Type.SHORT: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false); break; case Type.INT: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); break; case Type.LONG: mv.visitVarInsn(Opcodes.LSTORE, i); mv.visitVarInsn(Opcodes.LLOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.LLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FSTORE, i); mv.visitVarInsn(Opcodes.FLOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.FLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false); break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DSTORE, i); mv.visitVarInsn(Opcodes.DLOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.DLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false); break; default: mv.visitVarInsn(Opcodes.ASTORE, i); mv.visitVarInsn(Opcodes.ALOAD, i); pushCommon(); mv.visitVarInsn(Opcodes.ALOAD, i); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, CLASS, METHOD, SIGNATURE, false); }
From source file:scouter.agent.asm.jdbc.PsExecuteMV.java
License:Apache License
@Override public void visitInsn(int opcode) { if ((opcode >= IRETURN && opcode <= RETURN)) { int lvPosReturn; switch (returnType.getSort()) { case Type.ARRAY: if (returnType.getElementType().getSort() == Type.INT) { lvPosReturn = newLocal(returnType); mv.visitVarInsn(Opcodes.ASTORE, lvPosReturn); mv.visitVarInsn(Opcodes.ALOAD, lvPosReturn); mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ALOAD, lvPosReturn); mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "getIntArraySum", "([I)I", false); } else { mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); AsmUtil.PUSH(mv, -1);//w ww .j ava2s. c om } break; case Type.BOOLEAN: case Type.INT: lvPosReturn = newLocal(returnType); mv.visitVarInsn(Opcodes.ISTORE, lvPosReturn); mv.visitVarInsn(Opcodes.ILOAD, lvPosReturn); mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ILOAD, lvPosReturn); if (returnType.getSort() == Type.BOOLEAN) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "toInt", "(Z)I", false); } break; default: mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); AsmUtil.PUSH(mv, -1); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE, false); } mv.visitInsn(opcode); }
From source file:scouter.agent.asm.jdbc.StExecuteMV.java
License:Apache License
@Override public void visitInsn(int opcode) { if ((opcode >= IRETURN && opcode <= RETURN)) { int lvPosReturn; switch (returnType.getSort()) { case Type.ARRAY: if (returnType.getElementType().getSort() == Type.INT) { lvPosReturn = newLocal(returnType); mv.visitVarInsn(Opcodes.ASTORE, lvPosReturn); mv.visitVarInsn(Opcodes.ALOAD, lvPosReturn); mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ALOAD, lvPosReturn); mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "getIntArraySum", "([I)I", false); } else { mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); AsmUtil.PUSH(mv, -1);// w ww.j ava 2s . co m } break; case Type.BOOLEAN: case Type.INT: int i = newLocal(returnType); mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitVarInsn(Opcodes.ILOAD, i); if (returnType.getSort() == Type.BOOLEAN) { mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, "toInt", "(Z)I", false); } break; default: mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); AsmUtil.PUSH(mv, -1); } mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACESQL, END_METHOD, END_SIGNATURE, false); } mv.visitInsn(opcode); }
From source file:scouter.agent.asm.ServiceASM.java
License:Apache License
private void capReturn() { Type tp = returnType;/*from ww w .j a v a 2 s. c o m*/ if (tp == null || tp.equals(Type.VOID_TYPE)) { mv.visitVarInsn(Opcodes.ALOAD, statIdx); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACEMAIN, END_METHOD, END_SIGNATURE, false); return; } int i = newLocal(tp); switch (tp.getSort()) { case Type.BOOLEAN: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.BYTE: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.CHAR: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.SHORT: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.INT: mv.visitVarInsn(Opcodes.ISTORE, i); mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ILOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.LONG: mv.visitVarInsn(Opcodes.LSTORE, i); mv.visitVarInsn(Opcodes.LLOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.LLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.FLOAT: mv.visitVarInsn(Opcodes.FSTORE, i); mv.visitVarInsn(Opcodes.FLOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.FLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; case Type.DOUBLE: mv.visitVarInsn(Opcodes.DSTORE, i); mv.visitVarInsn(Opcodes.DLOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.DLOAD, i); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false); mv.visitInsn(Opcodes.ACONST_NULL);// throwable break; default: mv.visitVarInsn(Opcodes.ASTORE, i); mv.visitVarInsn(Opcodes.ALOAD, i); mv.visitVarInsn(Opcodes.ALOAD, statIdx);// stat mv.visitVarInsn(Opcodes.ALOAD, i);// return mv.visitInsn(Opcodes.ACONST_NULL);// throwable } mv.visitMethodInsn(Opcodes.INVOKESTATIC, TRACEMAIN, END_METHOD, END_SIGNATURE, false); }