下面列出了怎么用org.objectweb.asm.tree.VarInsnNode的API类实例代码及写法,或者点击链接到github查看源代码。
public static void processMethodHandleInvoke(ClassNode classNode, String newMethodDesc, MethodInsnNode invoke) {
String newMethodName = String.format("methodhandle$%s$%s", invoke.name, String.valueOf(invoke.desc.hashCode()).replace("-", ""));
MethodNode invokeWrapper = new MethodNode(Opcodes.ASM7,
Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC,
newMethodName, newMethodDesc, null, new String[0]);
int localVarsPosition = 0;
for (Type arg : Type.getArgumentTypes(newMethodDesc)) {
invokeWrapper.instructions.add(new VarInsnNode(arg.getOpcode(Opcodes.ILOAD), localVarsPosition));
localVarsPosition += arg.getSize();
}
invokeWrapper.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, invoke.owner, invoke.name, invoke.desc, false));
invokeWrapper.instructions.add(new InsnNode(Type.getReturnType(newMethodDesc).getOpcode(Opcodes.IRETURN)));
classNode.methods.add(invokeWrapper);
}
public VariableProvider(MethodNode method) {
this();
if (!Modifier.isStatic(method.access)) registerExisting(0, Type.getType("Ljava/lang/Object;"));
for (Type argumentType : Type.getArgumentTypes(method.desc)) {
registerExisting(argumentType.getSize() + max - 1, argumentType);
}
argumentSize = max;
for (AbstractInsnNode abstractInsnNode : method.instructions.toArray()) {
if (abstractInsnNode instanceof VarInsnNode) {
registerExisting(((VarInsnNode) abstractInsnNode).var, Utils.getType((VarInsnNode) abstractInsnNode));
}
}
}
/**
* <p>
* This method provides instruction to log counter information
* </p>
*
* @param className
* Class which has called the logger
* @param methodName
* Method in which the logger has been called
* @param logMethod
* log method
* @param logMsgPrefix
* log message
* @param field
* field which store the counter
* @return Instructions
*/
public static InsnList addCounterLoggingOldApi(String className,
String methodName, String logMethod, String logMsgPrefix,
String field) {
String method = "getMapReduceExecutionInfoOldApi";
InsnList il = new InsnList();
il.add(new LabelNode());
il.add(new LdcInsnNode(className));
il.add(new LdcInsnNode(methodName));
il.add(new LdcInsnNode(logMethod));
il.add(new LdcInsnNode(logMsgPrefix));
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil
.convertQualifiedClassNameToInternalName(className), field,
Type.INT_TYPE.getDescriptor()));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_LOGUTIL,
method, Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING,
TYPE_STRING, TYPE_STRING, TYPE_STRING, Type.INT_TYPE)));
return il;
}
private void check(ClassNode cn, MethodNode mn, TryCatchBlockNode tcb, LabelNode handler) {
AbstractInsnNode ain = handler;
while (ain.getOpcode() == -1) { // skip labels and frames
ain = ain.getNext();
}
if (ain.getOpcode() == ATHROW) {
removeTCB(mn, tcb);
} else if (ain instanceof MethodInsnNode && ain.getNext().getOpcode() == ATHROW) {
MethodInsnNode min = (MethodInsnNode) ain;
if (min.owner.equals(cn.name)) {
MethodNode getter = ClassUtils.getMethod(cn, min.name, min.desc);
AbstractInsnNode getterFirst = getter.instructions.getFirst();
while (getterFirst.getOpcode() == -1) {
getterFirst = ain.getNext();
}
if (getterFirst instanceof VarInsnNode && getterFirst.getNext().getOpcode() == ARETURN) {
if (((VarInsnNode) getterFirst).var == 0) {
removeTCB(mn, tcb);
}
}
}
}
}
private void addTraceStart() {
InsnList il = new InsnList();
int methodParametersIndex = addMethodParametersVariable(il);
addGetMethodInvocation(il);
addStoreMethod(il);
addGetCallback(il);
il.add(new VarInsnNode(Opcodes.ALOAD, this.methodVarIndex));
il.add(new VarInsnNode(Opcodes.ALOAD, methodParametersIndex));
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
"org/brutusin/instrumentation/Callback", "onStart",
"(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/String;", false));
this.executionIdIndex = getFistAvailablePosition();
il.add(new VarInsnNode(Opcodes.ASTORE, this.executionIdIndex));
this.mn.maxLocals++;
this.startNode = new LabelNode();
this.mn.instructions.insert(startNode);
this.mn.instructions.insert(il);
}
private static InsnList createInstructions(Deque<Character> watermark, int offset) {
int xorKey = RandomUtils.getRandomInt();
int watermarkChar = watermark.pop() ^ xorKey;
int indexXorKey = RandomUtils.getRandomInt();
int watermarkIndex = watermark.size() ^ indexXorKey;
InsnList instructions = new InsnList();
instructions.add(ASMUtils.getNumberInsn(xorKey));
instructions.add(ASMUtils.getNumberInsn(watermarkChar));
instructions.add(ASMUtils.getNumberInsn(indexXorKey));
instructions.add(ASMUtils.getNumberInsn(watermarkIndex));
// Local variable x where x is the max locals allowed in method can be the top of a long or double so we add 1
instructions.add(new VarInsnNode(ISTORE, offset + 1));
instructions.add(new VarInsnNode(ISTORE, offset + 2));
instructions.add(new VarInsnNode(ISTORE, offset + 3));
instructions.add(new VarInsnNode(ISTORE, offset + 4));
return instructions;
}
public void addGetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) {
Assert.requireNonNull(methodName, "methodName");
Assert.requireNonNull(fieldNode, "fieldNode");
// no argument is ().
final String desc = "()" + fieldNode.getDesc();
final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null);
final InsnList instructions = getInsnList(methodNode);
// load this.
instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
// get fieldNode.
instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc()));
// return of type.
final Type type = Type.getType(fieldNode.getDesc());
instructions.add(new InsnNode(type.getOpcode(Opcodes.IRETURN)));
addMethodNode0(methodNode);
}
@Inject(description = "Add hook that allows the method to be canceled")
public void inject(MethodNode main) {
AbstractInsnNode preNode = main.instructions.getFirst();
AbstractInsnNode postNode =
ASMHelper.findPattern(main.instructions.getFirst(), new int[]{RETURN}, "x");
Objects.requireNonNull(preNode, "Find pattern failed for preNode");
Objects.requireNonNull(postNode, "Find pattern failed for postNode");
LabelNode endJump = new LabelNode();
InsnList insnPre = new InsnList();
insnPre.add(new VarInsnNode(FLOAD, 1));
insnPre.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onHurtcamEffect));
insnPre.add(new JumpInsnNode(IFNE, endJump));
main.instructions.insertBefore(preNode, insnPre);
main.instructions.insertBefore(postNode, endJump);
}
@Inject(description = "Add hook before everything")
public void inject(MethodNode method) {
AbstractInsnNode node = method.instructions.getFirst();
Objects.requireNonNull(node, "Failed to find node.");
LabelNode label = new LabelNode();
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 1)); // enum
list.add(new VarInsnNode(ALOAD, 2)); // blockpos
list.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onWorldCheckLightFor));
list.add(new JumpInsnNode(IFEQ, label));
list.add(new InsnNode(ICONST_0));
list.add(new InsnNode(IRETURN));
list.add(label);
method.instructions.insertBefore(node, list);
}
private int addMethodParametersVariable(InsnList il) {
il.add(TreeInstructions.getPushInstruction(this.methodArguments.length));
il.add(new TypeInsnNode(Opcodes.ANEWARRAY, "java/lang/Object"));
int methodParametersIndex = getFistAvailablePosition();
il.add(new VarInsnNode(Opcodes.ASTORE, methodParametersIndex));
this.mn.maxLocals++;
for (int i = 0; i < this.methodArguments.length; i++) {
il.add(new VarInsnNode(Opcodes.ALOAD, methodParametersIndex));
il.add(TreeInstructions.getPushInstruction(i));
il.add(TreeInstructions.getLoadInst(methodArguments[i],
getArgumentPosition(i)));
MethodInsnNode mNode = TreeInstructions
.getWrapperContructionInst(methodArguments[i]);
if (mNode != null) {
il.add(mNode);
}
il.add(new InsnNode(Opcodes.AASTORE));
}
return methodParametersIndex;
}
@Inject(description = "Changes in layer code so that we can change it")
public void inject(MethodNode main) {
AbstractInsnNode node =
ASMHelper.findPattern(main.instructions.getFirst(), new int[]{INVOKEVIRTUAL}, "x");
Objects.requireNonNull(node, "Find pattern failed for node");
InsnList insnList = new InsnList();
// starting after INVOKEVIRTUAL on Block.getBlockLayer()
insnList.add(new VarInsnNode(ASTORE, 3)); // store the result from getBlockLayer()
insnList.add(new VarInsnNode(ALOAD, 0)); // push this
insnList.add(new VarInsnNode(ALOAD, 1)); // push block state
insnList.add(new VarInsnNode(ALOAD, 3)); // push this.getBlockLayer() result
insnList.add(
new VarInsnNode(ALOAD, 2)); // push the block layer of the block we are comparing to
insnList.add(
ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onRenderBlockInLayer));
// now our result is on the stack
main.instructions.insert(node, insnList);
}
private InsnList getReturnTraceInstructions() {
InsnList il = new InsnList();
int retunedVariablePosition = getFistAvailablePosition();
il.add(TreeInstructions.getStoreInst(this.methodReturnType, retunedVariablePosition));
this.variableCreated(this.methodReturnType); // Actualizamos el offset
addGetCallback(il);
il.add(new VarInsnNode(Opcodes.ALOAD, this.methodVarIndex));
il.add(TreeInstructions.getLoadInst(this.methodReturnType, retunedVariablePosition));
MethodInsnNode mNode = TreeInstructions.getWrapperContructionInst(this.methodReturnType);
if (mNode != null) {
il.add(mNode);
}
il.add(new VarInsnNode(Opcodes.ALOAD, this.executionIdIndex));
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
"org/brutusin/instrumentation/Callback", "onFinish",
"(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)V", false));
il.add(TreeInstructions.getLoadInst(this.methodReturnType, retunedVariablePosition));
return il;
}
public boolean isCompatible(VarInsnNode varInsnNode)
{
VarCode varCode;
if (AsmUtils.isLoadCode(varInsnNode.getOpcode()))
{
if (AsmUtils.isLoadCode(this.getOpcode()))
{
return false;
}
return ((StoreCode) this).isCompatible(new LoadCode(varInsnNode));
}
else if (AsmUtils.isStoreCode(varInsnNode.getOpcode()))
{
if (AsmUtils.isStoreCode(this.getOpcode()))
{
return false;
}
return ((LoadCode) this).isCompatible(new StoreCode(varInsnNode));
}
else
{
throw new AnalyzeError("Unexpected VarInsnNode Opcode!");
}
}
private InsnList getThrowTraceInstructions() {
InsnList il = new InsnList();
int exceptionVariablePosition = getFistAvailablePosition();
il.add(new VarInsnNode(Opcodes.ASTORE, exceptionVariablePosition));
this.methodOffset++; // Actualizamos el offset
addGetCallback(il);
il.add(new VarInsnNode(Opcodes.ALOAD, this.methodVarIndex));
il.add(new VarInsnNode(Opcodes.ALOAD, exceptionVariablePosition));
il.add(new VarInsnNode(Opcodes.ALOAD, this.executionIdIndex));
il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
"org/brutusin/instrumentation/Callback", "onThrowableThrown",
"(Ljava/lang/Object;Ljava/lang/Throwable;Ljava/lang/String;)V", false));
il.add(new VarInsnNode(Opcodes.ALOAD, exceptionVariablePosition));
return il;
}
@Override
public void transform(ClassNode cnode) {
Game.logger().info("Transforming IForgeRegistryEntry class for correct NOVA mod id mapping.");
ObfMapping mapping = new ObfMapping("net/minecraftforge/fml/common/registry/IForgeRegistryEntry$Impl", "setRegistryName", "(Ljava/lang/String;)Lnet/minecraftforge/fml/common/registry/IForgeRegistryEntry;");
MethodNode method = ASMHelper.findMethod(mapping, cnode);
if (method == null) {
throw new IllegalStateException("[NOVA] Lookup " + mapping + " failed!");
}
Game.logger().info("Transforming method {}", method.name);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 5));
list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v1_11_2/asm/StaticForwarder", "isNovaPrefix", "(Ljava/lang/String;)Z", false));
list.add(new JumpInsnNode(IFNE, (LabelNode) method.instructions.get(120)));
method.instructions.insert(method.instructions.get(101), list);
Game.logger().info("Injected instruction to method: {}", method.name);
}
private void transformAddPrefix(ClassNode cnode) {
ObfMapping mapping = new ObfMapping("net/minecraftforge/fml/common/registry/GameData", "addPrefix", "(Ljava/lang/String;)Ljava/lang/String;");
MethodNode method = ASMHelper.findMethod(mapping, cnode);
if (method == null) {
throw new IllegalStateException("[NOVA] Lookup " + mapping + " failed!");
}
Game.logger().info("Transforming method {}", method.name);
@SuppressWarnings("unchecked")
JumpInsnNode prev = (JumpInsnNode) method.instructions.get(49);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 4));
list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v18/asm/StaticForwarder", "isNovaPrefix", "(Ljava/lang/String;)Z", false));
list.add(new JumpInsnNode(IFNE, prev.label));
method.instructions.insert(prev, list);
Game.logger().info("Injected instruction to method: {}", method.name);
}
@MethodPatch(
mcpName = "handleChunkData",
notchName = "a",
mcpDesc = "(Lnet/minecraft/network/play/server/SPacketChunkData;)V",
notchDesc = "(Lje;)V")
public void handleChunkData(MethodNode methodNode, PatchManager.Environment env) {
final InsnList insnList = new InsnList();
insnList.add(new VarInsnNode(ALOAD, 1));
insnList.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "handleChunkDataHook", env == PatchManager.Environment.IDE ? "(Lnet/minecraft/network/play/server/SPacketChunkData;)V" : "(Lje;)V", false));
methodNode.instructions.insertBefore(ASMUtil.bottom(methodNode), insnList);
}
public static String toString(AbstractInsnNode ain) {
String s = getOpcodeText(ain.getOpcode());
switch (ain.getType()) {
case AbstractInsnNode.FIELD_INSN:
FieldInsnNode fin = (FieldInsnNode) ain;
return s + " " + fin.owner + "#" + fin.name + " " + fin.desc;
case AbstractInsnNode.METHOD_INSN:
MethodInsnNode min = (MethodInsnNode) ain;
return s + " " + min.owner + "#" + min.name + min.desc;
case AbstractInsnNode.VAR_INSN:
VarInsnNode vin = (VarInsnNode) ain;
return s + " " + vin.var;
case AbstractInsnNode.TYPE_INSN:
TypeInsnNode tin = (TypeInsnNode) ain;
return s + " " + tin.desc;
case AbstractInsnNode.MULTIANEWARRAY_INSN:
MultiANewArrayInsnNode mnin = (MultiANewArrayInsnNode) ain;
return s + " " + mnin.dims + " " + mnin.desc;
case AbstractInsnNode.JUMP_INSN:
JumpInsnNode jin = (JumpInsnNode) ain;
return s + " " + getIndex(jin.label);
case AbstractInsnNode.LDC_INSN:
LdcInsnNode ldc = (LdcInsnNode) ain;
return s + " " + ldc.cst.toString();
case AbstractInsnNode.INT_INSN:
return s + " " + getIntValue(ain);
case AbstractInsnNode.IINC_INSN:
IincInsnNode iinc = (IincInsnNode) ain;
return s + " " + iinc.var + " +" + iinc.incr;
case AbstractInsnNode.FRAME:
FrameNode fn = (FrameNode) ain;
return s + " " + getOpcodeText(fn.type) + " " + fn.local.size() + " " + fn.stack.size();
case AbstractInsnNode.LABEL:
LabelNode ln = (LabelNode) ain;
return s + " " + getIndex(ln);
}
return s;
}
private AbstractInsnNode invokeConstantHandler(Type constantType, Target target, Extension extraStack, InsnList before, InsnList after) {
InjectorData handler = new InjectorData(target, "constant modifier");
this.validateParams(handler, constantType, constantType);
if (!this.isStatic) {
before.insert(new VarInsnNode(Opcodes.ALOAD, 0));
extraStack.add();
}
if (handler.captureTargetArgs > 0) {
this.pushArgs(target.arguments, after, target.getArgIndices(), 0, handler.captureTargetArgs, extraStack);
}
return this.invokeHandler(after);
}
public static VarInsnNode getLoadInst(Type type, int position) {
int opCode = -1;
switch (type.getDescriptor().charAt(0)) {
case 'B':
opCode = Opcodes.ILOAD;
break;
case 'C':
opCode = Opcodes.ILOAD;
break;
case 'D':
opCode = Opcodes.DLOAD;
break;
case 'F':
opCode = Opcodes.FLOAD;
break;
case 'I':
opCode = Opcodes.ILOAD;
break;
case 'J':
opCode = Opcodes.LLOAD;
break;
case 'L':
opCode = Opcodes.ALOAD;
break;
case '[':
opCode = Opcodes.ALOAD;
break;
case 'Z':
opCode = Opcodes.ILOAD;
break;
case 'S':
opCode = Opcodes.ILOAD;
break;
default:
throw new ClassFormatError("Invalid method signature: "
+ type.getDescriptor());
}
return new VarInsnNode(opCode, position);
}
@Override
public EvaluationFunctor<Number> compare(Type lt, Type rt, ComparisonExpr.ValueComparisonType type) {
String name = lt.getClassName() + type.name() + rt.getClassName() + "RETint";
if(cache.containsKey(name)) {
return _get(name);
}
String desc = "(" + lt.getDescriptor() + rt.getDescriptor() + ")I";
MethodNode m = makeBase(name, desc);
{
Type opType = TypeUtils.resolveBinOpType(lt, rt);
InsnList insns = new InsnList();
insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(lt), 0));
cast(insns, lt, opType);
insns.add(new VarInsnNode(TypeUtils.getVariableLoadOpcode(rt), lt.getSize()));
cast(insns, rt, opType);
int op;
if (opType == Type.DOUBLE_TYPE) {
op = type == ComparisonExpr.ValueComparisonType.GT ? Opcodes.DCMPG : Opcodes.DCMPL;
} else if (opType == Type.FLOAT_TYPE) {
op = type == ComparisonExpr.ValueComparisonType.GT ? Opcodes.FCMPG : Opcodes.FCMPL;
} else if (opType == Type.LONG_TYPE) {
op = Opcodes.LCMP;
} else {
throw new IllegalArgumentException();
}
insns.add(new InsnNode(op));
insns.add(new InsnNode(Opcodes.IRETURN));
m.node.instructions = insns;
}
return buildBridge(m);
}
@Override
public VarInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = (JsonObject) json;
int opcode = jsonObject.get("opcode").getAsInt();
int var = jsonObject.get("var").getAsInt();
return new VarInsnNode(opcode, var);
}
/**
* Translate a single {@link AbstractInsnNode} to an {@link InstructionFilter}.
* @param ain Instruction to convert.
* @return A filter an an equivilent to the inputted instruction.
*/
public static InstructionFilter translate(AbstractInsnNode ain) {
if (ain instanceof LdcInsnNode) {
return new LdcInstructionFilter(((LdcInsnNode) ain).cst);
} else if (ain instanceof TypeInsnNode) {
return new TypeInstructionFilter(ain.getOpcode(), ((TypeInsnNode) ain).desc);
} else if (ain instanceof FieldInsnNode) {
return new FieldInstructionFilter(ain.getOpcode(), ((FieldInsnNode) ain).owner, ((FieldInsnNode) ain).name, ((FieldInsnNode) ain).desc);
} else if (ain instanceof MethodInsnNode) {
return new MethodInstructionFilter(ain.getOpcode(), ((MethodInsnNode) ain).owner, ((MethodInsnNode) ain).name, ((MethodInsnNode) ain).desc);
} else if (ain instanceof VarInsnNode) {
return new VarInstructionFilter(ain.getOpcode(), ((VarInsnNode) ain).var);
} else if (ain instanceof InsnNode) {
return new InsnInstructionFilter(ain.getOpcode());
} else if (ain instanceof IincInsnNode) {
return new IincInstructionFilter(((IincInsnNode) ain).incr, ((IincInsnNode) ain).var);
} else if (ain instanceof JumpInsnNode) {
return new JumpInstructionFilter(ain.getOpcode());
} else if (ain instanceof LabelNode) {
return InstructionFilter.ACCEPT_ALL; // TODO: Cache labels and check. // TODO: That's a fucking stupid idea.
} else if (ain instanceof MultiANewArrayInsnNode) {
return new MultiANewArrayInstructionFilter(((MultiANewArrayInsnNode) ain).desc, ((MultiANewArrayInsnNode) ain).dims);
} else if(ain instanceof IntInsnNode) {
return new IntInstructionFilter((IntInsnNode) ain);
} else {
return InstructionFilter.ACCEPT_ALL;
}
}
@Override
public boolean accept(AbstractInsnNode t) {
if (!(t instanceof VarInsnNode))
return false;
VarInsnNode vin = (VarInsnNode) t;
return opcodeFilter.accept(vin) && varFilter.accept(vin.var);
}
/**
* <p>
* This method provides instruction to inject method call to load the logger
* </p>.
*
* @return InsnList Instructions
*/
private InsnList loadLogger() {
LOGGER.debug(MessageFormat.format(InstrumentationMessageLoader
.getMessage(MessageConstants.LOG_LOAD_LOGGER), getClassName()));
InsnList il = new InsnList();
il.add(new LabelNode());
String logFileDir = workerLogLocation.substring(0, workerLogLocation.lastIndexOf('/') + 1);
// getting task attempt id
il.add(new LdcInsnNode(logFileDir));
il.add(new VarInsnNode(Opcodes.ALOAD, 1));
il.add(new LdcInsnNode(isMapperClass()));
String methodDesc = null;
if (isOldApiClazz()) {
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil
.convertQualifiedClassNameToInternalName(getClassName()),
InstrumentConstants.FIELD_LOADLOGGER, "Z"));
il.add(new VarInsnNode(Opcodes.ALOAD, 0));
il.add(new FieldInsnNode(Opcodes.GETFIELD, ConfigurationUtil
.convertQualifiedClassNameToInternalName(getClassName()),
InstrumentConstants.FIELD_LOGGERNUMBER, "I"));
methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING,
TYPE_JOBCONF, Type.BOOLEAN_TYPE, Type.BOOLEAN_TYPE,
Type.INT_TYPE);
} else {
methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING,
TYPE_TASKINPUTOUTPUTCONTEXT, Type.BOOLEAN_TYPE);
}
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, Type
.getInternalName(MapReduceExecutionUtil.class),
"configureLogging", methodDesc));
return il;
}
/**
* <p>
* This method provides instructions to add method call to modify output
* path
* </p>.
*
* @param jobVariableIndex Index of job variable
* @param type the type
* @return Instructions
*/
private InsnList modifyOutputPath(int jobVariableIndex, Type type) {
LOGGER.debug("passed class name in modifyOutputPath is "
+ type.getInternalName());
InsnList il = new InsnList();
il.add(new LabelNode());
il.add(new VarInsnNode(Opcodes.ALOAD, jobVariableIndex));
il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_JOB_UTIL,
"modifyOutputPath", Type.getMethodDescriptor(Type.VOID_TYPE,
type)));
return il;
}
public static void loadNode(ListIterator<AbstractInsnNode> iterator, Object paramType, int index) {
if (Opcodes.INTEGER.equals(paramType)) {
iterator.add(new VarInsnNode(Opcodes.ILOAD, index));
} else if (Opcodes.LONG.equals(paramType)) {
iterator.add(new VarInsnNode(Opcodes.LLOAD, index));
} else if (Opcodes.FLOAT.equals(paramType)) {
iterator.add(new VarInsnNode(Opcodes.FLOAD, index));
} else if (Opcodes.DOUBLE.equals(paramType)) {
iterator.add(new VarInsnNode(Opcodes.DLOAD, index));
} else {
iterator.add(new VarInsnNode(Opcodes.ALOAD, index));
}
}
LoadCode(VarInsnNode varInsnNode)
{
super(varInsnNode);
if (! AsmUtils.isLoadCode(this.getOpcode()))
{
throw new IllegalArgumentException("Expected STORE opcode");
}
}
private void packArgs(InsnList insns, String clArgs, MethodInsnNode targetMethod) {
String factoryDesc = Bytecode.changeDescriptorReturnType(targetMethod.desc, "L" + clArgs + ";");
insns.add(new MethodInsnNode(Opcodes.INVOKESTATIC, clArgs, "of", factoryDesc, false));
insns.add(new InsnNode(Opcodes.DUP));
if (!this.isStatic) {
insns.add(new VarInsnNode(Opcodes.ALOAD, 0));
insns.add(new InsnNode(Opcodes.SWAP));
}
}
@Inject(description = "Add hook before first slippery motion calculation")
public void injectFirst(MethodNode node) {
// at first underState.getBlock().getSlipperiness(...)
AbstractInsnNode first =
ASMHelper.findPattern(
node,
INVOKEVIRTUAL,
LDC,
FMUL,
FSTORE,
NONE,
NONE,
NONE,
LDC,
FLOAD,
FLOAD,
FMUL,
FLOAD,
FMUL,
FDIV,
FSTORE,
NONE,
NONE,
ALOAD,
GETFIELD,
IFEQ);
Objects.requireNonNull(first, "Could not find first slip motion node");
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
list.add(new VarInsnNode(ALOAD, 6));
list.add(new InsnNode(ICONST_0));
list.add(
ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onEntityBlockSlipApply));
// top of stack should be a modified or unmodified slippery float
node.instructions.insert(first, list); // insert after
}