Java Code Examples for org.objectweb.asm.tree.MethodInsnNode#getPrevious()
The following examples show how to use
org.objectweb.asm.tree.MethodInsnNode#getPrevious() .
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: MethodByteCodeUtil.java From jumbune with GNU Lesser General Public License v3.0 | 6 votes |
private static AbstractInsnNode getParamStartNodeOfUDClassMethodCall(MethodInsnNode node, List<LocalVariableNode> locaVariables) { String owner = node.owner; List<Integer> descriptionMatchingLocalVariables = new ArrayList<Integer>(); for (LocalVariableNode localVar : locaVariables) { if (localVar.desc.contains(owner)) { descriptionMatchingLocalVariables.add(localVar.index); } } boolean isOtherClassVariableFound = false; AbstractInsnNode previousNode = node.getPrevious(); while (previousNode != null && !isOtherClassVariableFound) { if (previousNode instanceof VarInsnNode) { VarInsnNode varInsnNode = (VarInsnNode) previousNode; Integer indexOfUDC = descriptionMatchingLocalVariables.indexOf(varInsnNode.var); if (indexOfUDC != -1) { return previousNode; } previousNode = previousNode.getPrevious(); return previousNode; } } return null; }
Example 2
Source File: MethodByteCodeUtil.java From jumbune with GNU Lesser General Public License v3.0 | 5 votes |
/** * Deciding factors for Anonymous object creation 1) The current method is init e.g. new MyClass() 2) The current method is valueOf and its * previous node is LDC, IntInsn, or Insn e.g new Double(23.3), 123, false */ public static boolean isAnonymousInitialization(MethodInsnNode min) { AbstractInsnNode previousNode = min.getPrevious(); if ("<init>".equals(min.name)){ return true; } if ("valueOf".equals(min.name) && (previousNode instanceof LdcInsnNode) || (previousNode instanceof IntInsnNode) || (previousNode instanceof InsnNode)){ return true; } return false; }
Example 3
Source File: ChainedTaskMethodAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
/** * <p> * Finds information about the ChainReducer.setReducer() & * ChainReducer.addMapper() methods * </p> * * @param min * Method instruction node which represents the above methods * @param isMapTask * Whether the task is map or reduce * @see ChainReducer#setReducer(JobConf, Class, Class, Class, Class, Class, * boolean, JobConf) * @see ChainReducer#addMapper(JobConf, Class, Class, Class, Class, Class, * boolean, JobConf) */ private void preProcessChainedTask(MethodInsnNode min, boolean isMapTask) { AbstractInsnNode ain = null; // getting variable index of the task conf object ain = min.getPrevious(); int taskConfIndex = getTaskJobConfIndex(ain); InsnList insnToMove = null; // if the task conf is passed as new JobConf() or using a method call, // we need to move these instructions above, add a new local variable // for // the conf & pass this local variable to the method call if (ain instanceof MethodInsnNode) { addLocalJobConf(taskConfIndex); // add a new VarInsnNode to load the new conf AbstractInsnNode vin = new VarInsnNode(Opcodes.ALOAD, taskConfIndex); instructions.insert(ain, vin); insnToMove = deleteInsnsAndMove(ain); // storing the value returned by the moved insn to the conf variable insnToMove.add(new VarInsnNode(Opcodes.ASTORE, taskConfIndex)); // setting the newly added vin as the current node for further // traversal, as we have removed the above ain node. ain = vin; } // getting node which represents parameter for Mapper/Reducer class AbstractInsnNode mrClassParamNode = getMRClassParamNode(ain); Object mrClassParam = getMRClassParam(mrClassParamNode); // getting variable index for Job Conf object AbstractInsnNode jobNode = getJobConfNode(mrClassParamNode); int jobVariableIndex = ((VarInsnNode) jobNode).var; // insert the instructions to be moved if (insnToMove != null) { instructions.insertBefore(jobNode, insnToMove); } if (isMapTask) { addMapJobAndTaskConfToIndex(taskConfIndex, mrClassParam, jobVariableIndex); } else { addReducerJobAndTaskConfToIndex(taskConfIndex, mrClassParam, jobVariableIndex); } }
Example 4
Source File: ProfileAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void visitEnd() { for (Object o : methods) { MethodNode mn = (MethodNode) o; InsnList insnList = mn.instructions; AbstractInsnNode[] insnArr = insnList.toArray(); /** * Finding the method instruction nodes whose owner is mapreduce.Job * and it submits the job */ for (AbstractInsnNode abstractInsnNode : insnArr) { if (abstractInsnNode instanceof MethodInsnNode) { MethodInsnNode min = (MethodInsnNode) abstractInsnNode; // finding job submission if (InstrumentUtil.isJobSubmissionMethod(min)) { LOGGER.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.JOB_SUBMISSION_FOUND), getClassName() + "##" + mn.name)); // validating that the owner of the method call is if (InstrumentUtil.isOwnerJob(min)) { LOGGER.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.LOG_OWNER_IS_JOB), getClassName() + "##" + mn.name)); AbstractInsnNode ain = min.getPrevious(); while (!(ain instanceof VarInsnNode)) { ain = ain.getPrevious(); } /* VarInsnNode vin = (VarInsnNode) ain; int jobVariableIndex = vin.var; InsnList il = null; // old api check if (getOwnerType(min).getInternalName().equals( CLASSNAME_JOB_CONF)) { il = addProfilingForOldAPI(jobVariableIndex); } else { il = addProfiling(jobVariableIndex); } insnList.insertBefore(vin, il); */ } } } } mn.visitMaxs(0, 0); } accept(cv); }
Example 5
Source File: SubmitCaseAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void visitEnd() { for (Object o : methods) { MethodNode mn = (MethodNode) o; InsnList insnList = mn.instructions; AbstractInsnNode[] insnArr = insnList.toArray(); /** * Finding the method instruction nodes whose owner is mapreduce.Job * and it submits the job */ for (AbstractInsnNode abstractInsnNode : insnArr) { if (abstractInsnNode instanceof MethodInsnNode) { MethodInsnNode min = (MethodInsnNode) abstractInsnNode; // finding job submission if (min.name.equals(EnumJobSubmitMethods.JOB_SUBMIT .toString())) { LOGGER.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.JOB_SUBMISSION_FOUND), getClassName() + "##" + mn.name)); // validating that the owner of the method call is if (min.owner.equals(EnumJobSubmitMethods.JOB_SUBMIT .getOwner().getInternalName())) { LOGGER.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.LOG_OWNER_IS_JOB), getClassName() + "##" + mn.name)); AbstractInsnNode ain = min.getPrevious(); while (!(ain instanceof VarInsnNode)) { ain = ain.getPrevious(); } VarInsnNode vin = (VarInsnNode) ain; int jobVariableIndex = vin.var; InsnList il = null; il = handleJobSubmitcase(mn, jobVariableIndex); insnList.insert(min, il); } } } } mn.visitMaxs(0, 0); } accept(cv); }
Example 6
Source File: JobAdapter.java From jumbune with GNU Lesser General Public License v3.0 | 4 votes |
/** * Visit end. * * @see org.jumbune.debugger.instrumentation.adapter.BaseAdapter#visitEnd() */ @Override public void visitEnd() { for (Object o : methods) { MethodNode mn = (MethodNode) o; InsnList insnList = mn.instructions; AbstractInsnNode[] insnArr = insnList.toArray(); LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader .getMessage(MessageConstants.LOG_INSTRUMENTING_METHOD), getClassName() + "##" + mn.name)); // traversing in reverse order as job submission comes at the end of // the method for (AbstractInsnNode abstractInsnNode : insnArr) { if (abstractInsnNode instanceof MethodInsnNode) { MethodInsnNode min = (MethodInsnNode) abstractInsnNode; // finding job submission if (InstrumentUtil.isJobSubmissionMethod(min)) { LOGGER.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.JOB_SUBMISSION_FOUND), getClassName())); // validating if the owner is mapreduce.Job or JobClient if (InstrumentUtil.isOwnerJob(min)) { LOGGER.debug(MessageFormat.format( InstrumentationMessageLoader .getMessage(MessageConstants.LOG_OWNER_IS_JOB), getClassName())); // finding index of job variable AbstractInsnNode ain = min.getPrevious(); while (!(ain instanceof VarInsnNode)) { ain = ain.getPrevious(); } VarInsnNode vin = (VarInsnNode) ain; int jobVariableIndex = vin.var; InsnList il = new InsnList(); // classpath is to be passed as libjars il.add(addClasspath(jobVariableIndex, getOwnerType(min))); // // output path modification il.add(modifyOutputPath(jobVariableIndex, getOwnerType(min))); insnList.insertBefore(vin, il); // Disabling the profiling for the pure jar - old // api if (getOwnerType(min).getInternalName().equals( CLASSNAME_JOB_CONF)) { il.add(new LabelNode()); il.add(new VarInsnNode(Opcodes.ALOAD, jobVariableIndex)); il.add(new LdcInsnNode(false)); il.add(new MethodInsnNode( Opcodes.INVOKEVIRTUAL, CLASSNAME_JOB_CONF, "setProfileEnabled", Type .getMethodDescriptor( Type.VOID_TYPE, Type.BOOLEAN_TYPE))); } else { il.add(new LabelNode()); il.add(new VarInsnNode(Opcodes.ALOAD, jobVariableIndex)); il.add(new MethodInsnNode( Opcodes.INVOKEVIRTUAL, CLASSNAME_MR_JOB, "getConfiguration", Type.getMethodDescriptor(Type .getType(Configuration.class)))); il.add(new LdcInsnNode(PROFILE_TASK)); il.add(new LdcInsnNode(Boolean.toString(false))); il.add(new MethodInsnNode( Opcodes.INVOKEVIRTUAL, CLASSNAME_HADOOP_CONFIGURATION, "set", Type.getMethodDescriptor( Type.VOID_TYPE, TYPE_STRING, TYPE_STRING))); } insnList.insertBefore(vin, il); } } } } mn.visitMaxs(0, 0); } accept(cv); }