本文整理汇总了Java中org.objectweb.asm.tree.analysis.Frame.getLocal方法的典型用法代码示例。如果您正苦于以下问题:Java Frame.getLocal方法的具体用法?Java Frame.getLocal怎么用?Java Frame.getLocal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.tree.analysis.Frame
的用法示例。
在下文中一共展示了Frame.getLocal方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSource
import org.objectweb.asm.tree.analysis.Frame; //导入方法依赖的package包/类
private AbstractInsnNode getSource(MethodNode methodNode, Frame<SourceValue>[] frames, AbstractInsnNode now, int... wants) {
Frame<SourceValue> currentFrame = frames[methodNode.instructions.indexOf(now)];
SourceValue currentValue;
for (int want : wants)
if (want == now.getOpcode()) return now;
switch (now.getOpcode()) {
case ALOAD: {
currentValue = currentFrame.getLocal(((VarInsnNode) now).var);
break;
}
case ASTORE: {
currentValue = currentFrame.getStack(currentFrame.getStackSize() - 1);
break;
}
case DUP: {
currentValue = currentFrame.getStack(currentFrame.getStackSize() - 1);
break;
}
case PUTSTATIC: {
currentValue = currentFrame.getStack(currentFrame.getStackSize() - 1);
break;
}
case SWAP: {
currentValue = currentFrame.getStack(currentFrame.getStackSize() - 1);
break;
}
default: {
oops("Unexpected opcode {}", now.getOpcode());
return null;
}
}
if (currentValue.insns.size() != 1) {
oops("Expected 1 source insn, found {}", TransformerHelper.insnsToString(currentValue.insns));
return null;
}
return getSource(methodNode, frames, currentValue.insns.iterator().next(), wants);
}
示例2: getLocalReplacementsInc
import org.objectweb.asm.tree.analysis.Frame; //导入方法依赖的package包/类
private Map<String, InsnList> getLocalReplacementsInc(MethodNode mn, String desc,
IincInsnNode node, Frame frame) {
Map<String, InsnList> replacements = new HashMap<String, InsnList>();
int otherNum = -1;
otherNum = node.var;
int currentId = mn.instructions.indexOf(node);
for (Object v : mn.localVariables) {
LocalVariableNode localVar = (LocalVariableNode) v;
int startId = mn.instructions.indexOf(localVar.start);
int endId = mn.instructions.indexOf(localVar.end);
logger.info("Checking local variable " + localVar.name + " of type "
+ localVar.desc + " at index " + localVar.index);
if (!localVar.desc.equals(desc))
logger.info("- Types do not match: " + localVar.name);
if (localVar.index == otherNum)
logger.info("- Replacement = original " + localVar.name);
if (currentId < startId)
logger.info("- Out of scope (start) " + localVar.name);
if (currentId > endId)
logger.info("- Out of scope (end) " + localVar.name);
BasicValue newValue = (BasicValue) frame.getLocal(localVar.index);
if (newValue == BasicValue.UNINITIALIZED_VALUE)
logger.info("- Not initialized");
if (localVar.desc.equals(desc) && localVar.index != otherNum
&& currentId >= startId && currentId <= endId
&& newValue != BasicValue.UNINITIALIZED_VALUE) {
logger.info("Adding local variable " + localVar.name + " of type "
+ localVar.desc + " at index " + localVar.index);
InsnList list = new InsnList();
list.add(new IincInsnNode(localVar.index, node.incr));
replacements.put(localVar.name, list);
}
}
return replacements;
}
示例3: getLocalReplacements
import org.objectweb.asm.tree.analysis.Frame; //导入方法依赖的package包/类
private Map<String, InsnList> getLocalReplacements(MethodNode mn, String desc,
AbstractInsnNode node, Frame frame) {
Map<String, InsnList> replacements = new HashMap<String, InsnList>();
//if (desc.equals("I"))
// return replacements;
int otherNum = -1;
if (node instanceof VarInsnNode) {
VarInsnNode vNode = (VarInsnNode) node;
otherNum = vNode.var;
}
if (otherNum == -1)
return replacements;
int currentId = mn.instructions.indexOf(node);
logger.info("Looking for replacements at position " + currentId + " of variable "
+ otherNum + " of type " + desc);
// return replacements;
for (Object v : mn.localVariables) {
LocalVariableNode localVar = (LocalVariableNode) v;
int startId = mn.instructions.indexOf(localVar.start);
int endId = mn.instructions.indexOf(localVar.end);
logger.info("Checking local variable " + localVar.name + " of type "
+ localVar.desc + " at index " + localVar.index);
if (!localVar.desc.equals(desc))
logger.info("- Types do not match");
if (localVar.index == otherNum)
logger.info("- Replacement = original");
if (currentId < startId)
logger.info("- Out of scope (start)");
if (currentId > endId)
logger.info("- Out of scope (end)");
BasicValue newValue = (BasicValue) frame.getLocal(localVar.index);
if (newValue == BasicValue.UNINITIALIZED_VALUE)
logger.info("- Not initialized");
if (localVar.desc.equals(desc) && localVar.index != otherNum
&& currentId >= startId && currentId <= endId
&& newValue != BasicValue.UNINITIALIZED_VALUE) {
logger.info("Adding local variable " + localVar.name + " of type "
+ localVar.desc + " at index " + localVar.index + ", " + startId
+ "-" + endId + ", " + currentId);
InsnList list = new InsnList();
if (node.getOpcode() == Opcodes.GETFIELD) {
list.add(new InsnNode(Opcodes.POP)); // Remove field owner from stack
}
list.add(new VarInsnNode(getLoadOpcode(localVar), localVar.index));
replacements.put(localVar.name, list);
}
}
return replacements;
}
示例4: computeSizes
import org.objectweb.asm.tree.analysis.Frame; //导入方法依赖的package包/类
/**
* Compute sizes required for the storage arrays that will contain the local variables table at this frame.
* @param frame frame to compute for
* @return size required by each storage array
* @throws NullPointerException if any argument is {@code null}
*/
public static StorageSizes computeSizes(Frame<BasicValue> frame) {
Validate.notNull(frame);
// Count size required for each storage array
int intsSize = 0;
int longsSize = 0;
int floatsSize = 0;
int doublesSize = 0;
int objectsSize = 0;
for (int i = 0; i < frame.getLocals(); i++) {
BasicValue basicValue = frame.getLocal(i);
Type type = basicValue.getType();
// If type == null, basicValue is pointing to uninitialized var -- basicValue.toString() will return '.'. This means that this
// slot contains nothing to save. So, skip this slot if we encounter it.
if (type == null) {
continue;
}
// If type is 'Lnull;', this means that the slot has been assigned null and that "there has been no merge yet that would 'raise'
// the type toward some class or interface type" (from ASM mailing list). We know this slot will always contain null at this
// point in the code so we can avoid saving it. When we load it back up, we can simply push a null in to that slot, thereby
// keeping the same 'Lnull;' type.
if ("Lnull;".equals(type.getDescriptor())) {
continue;
}
switch (type.getSort()) {
case Type.BOOLEAN:
case Type.BYTE:
case Type.SHORT:
case Type.CHAR:
case Type.INT:
intsSize++;
break;
case Type.FLOAT:
floatsSize++;
break;
case Type.LONG:
longsSize++;
break;
case Type.DOUBLE:
doublesSize++;
break;
case Type.ARRAY:
case Type.OBJECT:
objectsSize++;
break;
case Type.METHOD:
case Type.VOID:
default:
throw new IllegalStateException();
}
}
return new StorageSizes(intsSize, longsSize, floatsSize, doublesSize, objectsSize);
}