Java Code Examples for org.objectweb.asm.tree.InsnList#toArray()

The following examples show how to use org.objectweb.asm.tree.InsnList#toArray() . 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: ConfigureMapReduceAdapter.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * It modifies existing setup/configure , cleanup/close methods by adding
 * jumbune logging related instructions.
 *
 * @param mn - current method node
 * @param isSetup - true if its setup method, false if its cleanup method
 */
private void modifyConfigureMethods(MethodNode mn, boolean isSetup) {
	if (isSetup) {
		LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
				.getMessage(MessageConstants.LOG_MODIFY_SETUP_METHOD),
				getClassName()));
	} else {
		LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
				.getMessage(MessageConstants.LOG_MODIFY_CLEANUP_METHODD),
				getClassName()));
	}
	InsnList insnList = mn.instructions;
	AbstractInsnNode[] insnArr = insnList.toArray();

	for (AbstractInsnNode abstractInsnNode : insnArr) {
		if (Opcodes.RETURN >= abstractInsnNode.getOpcode()
				&& Opcodes.IRETURN <= abstractInsnNode.getOpcode()) {
			InsnList il = new InsnList();

			il.add(prepareMapReduceForJumbuneInstructions(isSetup, mn));

			insnList.insertBefore(abstractInsnNode, il);
			break;
		}
	}
}
 
Example 2
Source File: Code.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
public static int getLabelCount(InsnList instructions) {
	int i = 0;
	for (AbstractInsnNode ain : instructions.toArray()) {
		if (ain instanceof LabelNode) {
			i++;
		}
	}
	return i;
}
 
Example 3
Source File: Code.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
public static LabelNode getLabelByIndex(InsnList instructions, int index) {
	int i = 0;
	for (AbstractInsnNode ain : instructions.toArray()) {
		if (ain instanceof LabelNode) {
			if(i == index) {
				return (LabelNode) ain;
			}
			i++;
		}
	}
	return null;
}
 
Example 4
Source File: MethodUtils.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
public static Map<LabelNode, LabelNode> getLabelMap(InsnList list) {
	Map<LabelNode, LabelNode> map = new HashMap<>();
	for (AbstractInsnNode ain : list.toArray()) {
		if (ain instanceof LabelNode) {
			map.put((LabelNode) ain, new LabelNode());
		}
	}
	return map;
}
 
Example 5
Source File: StringObfuscationCipherVMT11.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
private void removeUnwantedCalls(InsnList decryption) {
	// TODO remove unwanted methodinsnnodes
	for (AbstractInsnNode ain : decryption.toArray()) {
		if (ain.getOpcode() == INVOKEDYNAMIC) {
			InvokeDynamicInsnNode idin = (InvokeDynamicInsnNode) ain;
			if (idin.desc.equals("(IJ)Ljava/lang/String;")) {
				decryption.insertBefore(idin, new InsnNode(POP2));
				decryption.insert(idin, new LdcInsnNode("<clinit> decryption invokedynamic string undecrypted"));
				decryption.set(idin, new InsnNode(POP));
			}
		}
	}
}
 
Example 6
Source File: ReturnAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * visit end method for intrumentation	
 */
@Override
public void visitEnd() {
	for (Object o : methods) {
		MethodNode mn = (MethodNode) o;

		if (validateMethods(mn)
				&& InstrumentUtil.validateMethodName(mn.name, "<clinit>")
				&& mn.name.indexOf("access$") < 0) {

			logger.debug("instrumenting " + getClassName() + "##" + mn.name);

			InsnList insnList = mn.instructions;
			AbstractInsnNode[] insnArr = insnList.toArray();
			for (AbstractInsnNode abstractInsnNode : insnArr) {
				if (Opcodes.RETURN >= abstractInsnNode.getOpcode()
						&& Opcodes.IRETURN <= abstractInsnNode.getOpcode()) {
					String msg = new StringBuilder("[Return] [method] [] ")
							.toString();

					String cSymbol = env.getClassSymbol(getClassName());
					String mSymbol = env.getMethodSymbol(getClassName(), cSymbol, mn.name);

					InsnList il = InstrumentUtil.addReturnLogging(
							cSymbol, mSymbol, msg);
					insnList.insertBefore(abstractInsnNode, il);
				}
			}
		}
		mn.visitMaxs(0, 0);
	}
	accept(cv);
}
 
Example 7
Source File: OpUtils.java    From zelixkiller with GNU General Public License v3.0 4 votes vote down vote up
public static void print(InsnList instructions) {
	for (AbstractInsnNode ain : instructions.toArray()) {
		Logger.logLow(toString(ain));
	}
}
 
Example 8
Source File: MethodEntryExitAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
* visit end method for intrumentation	
*/
@Override
public void visitEnd() {
	for (Object o : methods) {
		MethodNode mn = (MethodNode) o;

		// filtering the methods
		if (!(validateMapReduceClinitMethod(mn.name,MAP_METHOD , REDUCE_METHOD,CLINIT_METHOD)
				|| checkMethodNameAndArgumentLength(mn)
				|| (mn.access & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC)) {

			InsnList insnList = mn.instructions;
			AbstractInsnNode[] insnArr = insnList.toArray();

			// adding entry logging
			logger.debug(MessageFormat.format(InstrumentationMessageLoader
					.getMessage(MessageConstants.LOG_METHOD_ENTRY),
					getClassName() + "##" + mn.name + "##" + mn.desc));

			String logMsg = InstrumentationMessageLoader
					.getMessage(MessageConstants.ENTERED_METHOD);
			
			String cSymbol = env.getClassSymbol(getClassName());
			String mSymbol = env.getMethodSymbol(getClassName(),cSymbol, mn.name);
			
			InsnList il = InstrumentUtil.addLogMessage(cSymbol,
					mSymbol, logMsg);
			insnList.insertBefore(insnList.getFirst(), il);

			for (AbstractInsnNode abstractInsnNode : insnArr) {
				if (Opcodes.RETURN >= abstractInsnNode.getOpcode()
						&& Opcodes.IRETURN <= abstractInsnNode.getOpcode()) {
					// adding exit logging
					logger.debug(MessageFormat.format(
							InstrumentationMessageLoader
									.getMessage(MessageConstants.LOG_METHOD_EXIT),
							getClassName() + "##" + mn.name));

					logMsg = InstrumentationMessageLoader
							.getMessage(MessageConstants.EXITING_METHOD);
					cSymbol = env.getClassSymbol(getClassName());
					mSymbol = env.getMethodSymbol(getClassName(),cSymbol,mn.name);
					il = InstrumentUtil.addLogMessage(cSymbol,
							mSymbol, logMsg);

					// inserting the list at the associated label node
					AbstractInsnNode prevNode = abstractInsnNode
							.getPrevious();
					while (!(prevNode instanceof LabelNode)) {
						prevNode = prevNode.getPrevious();
					}
					insnList.insert(prevNode, il);
				}
			}
		}
		mn.visitMaxs(0, 0);
	}
	accept(cv);
}
 
Example 9
Source File: TimerAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * visit end method for intrumentation	
 */
@SuppressWarnings("unchecked")
@Override
public void visitEnd() {
	if (isMapperClass() || isReducerClass()) {
		for (Object o : methods) {
			MethodNode mn = (MethodNode) o;
			if (InstrumentUtil.validateMapReduceMethod(mn)) {
				logger.debug("instrumenting " + getClassName() + "##"
						+ mn.name);
				InsnList list = mn.instructions;
				AbstractInsnNode[] insnArr = list.toArray();
				int variable = mn.maxLocals;

				// adding variable declaration
				InsnList il = new InsnList();
				LabelNode newLabel = new LabelNode();
				il.add(newLabel);
				il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
						"java/lang/System", "currentTimeMillis", Type
								.getMethodDescriptor(Type.LONG_TYPE)));
				il.add(new VarInsnNode(Opcodes.LSTORE, variable));
				list.insertBefore(list.getFirst(), il);

				// adding local variable
				LabelNode begin = new LabelNode();
				LabelNode end = new LabelNode();
				list.insertBefore(list.getFirst(), begin);
				list.insert(list.getLast(), end);
				Type type = Type.LONG_TYPE;
				LocalVariableNode lv = new LocalVariableNode("startMethod",
						type.getDescriptor(), null, begin, end, variable);
				mn.localVariables.add(lv);

				// finding the return statement
				for (AbstractInsnNode abstractInsnNode : insnArr) {
					if (abstractInsnNode.getOpcode() >= Opcodes.IRETURN
							&& abstractInsnNode.getOpcode() <= Opcodes.RETURN) {
						// adding logging statement
						String msg = new StringBuilder(
								"[Method executed] [time] ").toString();
						String cSymbol = env.getClassSymbol(getClassName());
						String mSymbol = env.getMethodSymbol(getClassName(), cSymbol, mn.name);
						InsnList il1 = InstrumentUtil.addTimerLogging(
								cSymbol,mSymbol, variable, msg);

						list.insertBefore(abstractInsnNode, il1);
					}
				}
			}
			mn.visitMaxs(0, 0);
		}
	}
	accept(cv);
}
 
Example 10
Source File: ProfileAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 11
Source File: MREntryExitAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * visit end for instrumentation of map-reduce methods
 */
@Override
public void visitEnd() {
	if (isMapperClass() || isReducerClass()) {
		for (Object o : methods) {
			MethodNode mn = (MethodNode) o;
			/**
			 * Valid map/reduce method
			 */
			if (InstrumentUtil.validateMapReduceMethod(mn)) {
				InsnList insnList = mn.instructions;
				AbstractInsnNode[] insnArr = insnList.toArray();

				// adding entry logging
				LOGGER.debug(MessageFormat.format(
						InstrumentationMessageLoader
								.getMessage(MessageConstants.LOG_MAPREDUCE_METHOD_ENTRY),
						getClassName() + "##" + mn.name + "##" + mn.desc));
				String logMsg = new StringBuilder(
						MessageFormat.format(
								InstrumentationMessageLoader
										.getMessage(MessageConstants.ENTERED_MAPREDUCE),
								mn.name)).toString();

				// setting the logger number in ThreadLocal
				InsnList il1 = new InsnList();
				il1.add(new LabelNode());
				il1.add(new VarInsnNode(Opcodes.ALOAD, 0));
				il1.add(new FieldInsnNode(
						Opcodes.GETFIELD,
						ConfigurationUtil.convertQualifiedClassNameToInternalName(getClassName()),
						InstrumentConstants.FIELD_LOGGERNUMBER, "I"));
				il1.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
						CLASSNAME_MAPREDUCEEXECUTIL, "setLoggerNumber",
						Type.getMethodDescriptor(Type.VOID_TYPE,
								Type.INT_TYPE)));
				
				String symbol = env.getClassSymbol(getClassName());
				il1.add(InstrumentUtil.addLogMessage(symbol,
						mn.name, logMsg));

				il1.add(addMapCounter(mn));
				insnList.insertBefore(insnList.getFirst(), il1);

				// traversing the instructions for exit logging
				for (AbstractInsnNode abstractInsnNode : insnArr) {
					// return statement
					if (abstractInsnNode.getOpcode() >= Opcodes.IRETURN
							&& abstractInsnNode.getOpcode() <= Opcodes.RETURN) {
						LOGGER.debug(MessageFormat.format(
								InstrumentationMessageLoader
										.getMessage(MessageConstants.LOG_MAPREDUCE_METHOD_EXIT),
								getClassName() + "##" + mn.name));
						String logMsg2 = new StringBuilder(
								MessageFormat.format(
										InstrumentationMessageLoader
												.getMessage(MessageConstants.EXITING_MAPREDUCE),
										mn.name)).toString();
						
						symbol = getLogClazzName(); 
						InsnList il = InstrumentUtil.addLogMessage(
								symbol, mn.name, logMsg2);
						insnList.insert(abstractInsnNode.getPrevious(), il);
					}
				}
			}
			mn.visitMaxs(0, 0);
		}
	}
	accept(cv);
}
 
Example 12
Source File: SubmitCaseAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 13
Source File: ContextWriteValidationAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * This method first copies the key/value to new temporary variables and
 * pass these variables to either PatternMatcher class or the class
 * specified by user. The call to these classes is embedded in Log method so
 * the result returned will be printed. To summarize this method will modify
 * context.write method for copying parameters to local variables and it
 * will then add a call for Log class which prints the result of
 * validation/matching by taking in message a call to these
 * PatternMatcher/User defined validation class. Sample output:
 * 
 * context.write(tempKey = key, tempVal = value); Log.info("result " +
 * PatternMatcher.match(tempVal, regEx)); Log.info("validation result " +
 * UserSpecifiedClass.method(tempVal));
 */
@Override
public void visitEnd() {
	JobConfig jobConfig = (JobConfig)getConfig();
	if (validateUserValidationClass(jobConfig.getUserValidations(),
			getClassName())
			|| validateRegexValidationClass(jobConfig.getRegex(),
					getClassName())) {
		for (int i = 0; i < methods.size(); i++) {
			MethodNode mn = (MethodNode) methods.get(i);
			int variableIndex = mn.maxLocals;
			/**
			 * context.write/output.collect has been written in the
			 * map/reduce methods and other user defined functions. Applying
			 * filter to skip synthetic methods.
			 */
			if (!InstrumentUtil.isSysntheticAccess(mn.access)) {
				InsnList insnList = mn.instructions;
				AbstractInsnNode[] insnArr = insnList.toArray();
				int writeCount = 0;
				for (int j = 0; j < insnArr.length; j++) {
					AbstractInsnNode abstractInsnNode = insnArr[j];

					if (abstractInsnNode instanceof MethodInsnNode) {
						MethodInsnNode min = (MethodInsnNode) abstractInsnNode;

						// write method
						if (InstrumentUtil.isOutputMethod(min)) {

							LOG.debug(MessageFormat.format(
									InstrumentationMessageLoader
											.getMessage(MessageConstants.LOG_ADDING_REGEX_VALIDATION_CALL),
									getClassName() + "##" + mn.name,
									writeCount++));

							InstructionsBean insBean = MethodByteCodeUtil
									.readMethodAndCopyParamToTemporaryVariables(
											min.getPrevious(),
											variableIndex, insnList,
											mn.localVariables);

							// Add the instance of temporary key/value index
							// to ContextWriteParams
							ContextWriteParams
									.getInstance()
									.setTempKeyVariableIndex(
											insBean.getTemporaryVariablesIndexList()
													.get(KEY_INDEX));
							ContextWriteParams
									.getInstance()
									.setTempValueVariableIndex(
											insBean.getTemporaryVariablesIndexList()
													.get(VALUE_INDEX));

							InsnList patternValidationInsnList = new InsnList();
							LOG.debug("***** Just going to add validations  keyIndex "
									+ insBean
											.getTemporaryVariablesIndexList()
											.get(KEY_INDEX)
									+ " Value Index "
									+ insBean
											.getTemporaryVariablesIndexList()
											.get(VALUE_INDEX));

							LOG.debug("ContextWriteParams.getInstance() KEY --  "
									+ ContextWriteParams.getInstance()
											.getTempKeyVariableIndex());
							addValidations(patternValidationInsnList, 
									insBean, mn);

							if (patternValidationInsnList != null
									&& patternValidationInsnList.size() > 0) {
								insnList.insert(abstractInsnNode,
										patternValidationInsnList);
							}
						}
					}
				}
			}
			mn.visitMaxs(0, 0);
		}
	}
	accept(cv);
}
 
Example 14
Source File: ContextWriteLogAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void visitEnd() {
	if (isMapperClass() || isReducerClass()) {
		for (Object o : methods) {
			MethodNode mn = (MethodNode) o;
			InsnList insnList = mn.instructions;
			AbstractInsnNode[] insnArr = insnList.toArray();
			int writeCount = 0;

			// traversing the instructions
			for (AbstractInsnNode abstractInsnNode : insnArr) {
				if (abstractInsnNode instanceof MethodInsnNode) {
					MethodInsnNode min = (MethodInsnNode) abstractInsnNode;

					// write method
					if (InstrumentUtil.isOutputMethod(min)) {
						writeCount++;
						LOGGER.debug(MessageFormat.format(
								InstrumentationMessageLoader
										.getMessage(MessageConstants.LOG_MAPREDUCE_CTXWRITE_CALL),
								getClassName() + "##" + mn.name, writeCount));
						String logMsg = null;

						// mapper
						if (isMapperClass()) {
							logMsg = InstrumentationMessageLoader
									.getMessage(MessageConstants.MAPPER_CONTEXT_WRITE);
						}
						// combiner or reducer
						else if (isReducerClass()) {
							logMsg = InstrumentationMessageLoader
									.getMessage(MessageConstants.REDUCER_CONTEXT_WRITE);
						}

						InsnList il = InstrumentUtil
								.addMapReduceContextWriteLogging(
										getLogClazzName(), mn.name, logMsg);

						insnList.insertBefore(abstractInsnNode, il);

						// setting loggernumber to ThreadLocal
						InsnList lll = new InsnList();
						lll.add(new LabelNode());
						lll.add(new VarInsnNode(Opcodes.ALOAD, 0));
						lll.add(new FieldInsnNode(
								Opcodes.GETFIELD,
								ConfigurationUtil.convertQualifiedClassNameToInternalName(getClassName()),
								InstrumentConstants.FIELD_LOGGERNUMBER, "I"));
						lll.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
								CLASSNAME_MAPREDUCEEXECUTIL,
								"setLoggerNumber", Type
										.getMethodDescriptor(
												Type.VOID_TYPE,
												Type.INT_TYPE)));

						insnList.insert(abstractInsnNode, lll);
					}
				}
			}
			mn.visitMaxs(0, 0);
		}
	}
	accept(cv);
}
 
Example 15
Source File: PartitionerAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * method for instrumenting jar for debugging partitioner
 */
@Override
public void visitEnd() {
	if (isMapperClass()) {
		LOG.debug("Instrumenting jar for debugging partitioner !!");
		for (int i = 0; i < methods.size(); i++) {
			MethodNode mn = (MethodNode) methods.get(i);
			final int variableIndex = mn.maxLocals;

			if (InstrumentUtil.validateMapMethod(mn)) {
				InsnList insnList = mn.instructions;
				AbstractInsnNode[] insnArr = insnList.toArray();

				// Get the index of temporary variables of key and value
				int keyVariableIndex = ContextWriteParams.getInstance()
						.getTempKeyVariableIndex();
				int valueVariableIndex = ContextWriteParams.getInstance()
						.getTempValueVariableIndex();

				LOG.debug("Index set in ContextWriteParams  "
						+ keyVariableIndex + " Index of Value  "
						+ valueVariableIndex + " for class "
						+ getClassName());

				for (AbstractInsnNode abstractInsnNode : insnArr) {
					if (abstractInsnNode instanceof MethodInsnNode) {
						MethodInsnNode min = (MethodInsnNode) abstractInsnNode;

						if (InstrumentUtil.isOutputMethod(min)) {
							// If both the key and value index are 0 that
							// means its yet not copied to temporary
							// variables just copy these params to temporary
							// variables
							if (keyVariableIndex == 0
									&& valueVariableIndex == 0) {
								LOG.debug("Since params are not copied to temporary variables do it now !!!!! "
										+ " \n previous to context.write  "
										+ min.getPrevious()
										+ " variableIndex "
										+ variableIndex
										+ " insnList " + insnList.size());
								InstructionsBean insBean = MethodByteCodeUtil
										.readMethodAndCopyParamToTemporaryVariables(
												min.getPrevious(),
												variableIndex, insnList,
												mn.localVariables);
								LOG.debug("After the instructions were added size of insnList :: "
										+ insnList.size());
								// Add the instance of temporary key/value
								// index to ContextWriteParams
								keyVariableIndex = insBean
										.getTemporaryVariablesIndexList()
										.get(KEY_INDEX);
								valueVariableIndex = insBean
										.getTemporaryVariablesIndexList()
										.get(VALUE_INDEX);

								ContextWriteParams.getInstance()
										.setTempKeyVariableIndex(
												keyVariableIndex);
								ContextWriteParams.getInstance()
										.setTempValueVariableIndex(
												valueVariableIndex);
							}
							// Add instructions for detecting the time taken
							// in partitioning
							insnList.insert(
									abstractInsnNode,
									getInsnListForCalculatePartitioningTime(
											keyVariableIndex,
											valueVariableIndex));
						}
					}
				}
			}
			mn.visitMaxs(0, 0);
		}
	}
	accept(cv);
}
 
Example 16
Source File: JobAdapter.java    From jumbune with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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);
}