本文整理汇总了Java中jdk.internal.org.objectweb.asm.tree.MethodNode类的典型用法代码示例。如果您正苦于以下问题:Java MethodNode类的具体用法?Java MethodNode怎么用?Java MethodNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodNode类属于jdk.internal.org.objectweb.asm.tree包,在下文中一共展示了MethodNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkNoForName
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
private static void checkNoForName(MethodNode m) throws Exception {
Iterator<AbstractInsnNode> it = m.instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode n = it.next();
if (n instanceof MethodInsnNode) {
MethodInsnNode met = (MethodInsnNode) n;
if (met.name.equals("forName")
&& met.owner.equals("java/lang/Class")
&& met.desc.equals("(Ljava/lang/String;)Ljava/lang/Class;")) {
throw new Exception("forName not removed in " + m.name);
}
}
}
for (TryCatchBlockNode tcb : m.tryCatchBlocks) {
if (tcb.type.equals(ClassNotFoundException.class.getName().replaceAll("\\.", "/"))) {
throw new Exception("ClassNotFoundException Block not removed for " + m.name);
}
}
}
示例2: verify
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
/**
* Checks a given class.
*
* @param cr
* a <code>ClassReader</code> that contains bytecode for the
* analysis.
* @param loader
* a <code>ClassLoader</code> which will be used to load
* referenced classes. This is useful if you are verifiying
* multiple interdependent classes.
* @param dump
* true if bytecode should be printed out not only when errors
* are found.
* @param pw
* write where results going to be printed
*/
public static void verify(final ClassReader cr, final ClassLoader loader,
final boolean dump, final PrintWriter pw) {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
Type syperType = cn.superName == null ? null : Type
.getObjectType(cn.superName);
List<MethodNode> methods = cn.methods;
List<Type> interfaces = new ArrayList<Type>();
for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
interfaces.add(Type.getObjectType(i.next()));
}
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = methods.get(i);
SimpleVerifier verifier = new SimpleVerifier(
Type.getObjectType(cn.name), syperType, interfaces,
(cn.access & Opcodes.ACC_INTERFACE) != 0);
Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
if (loader != null) {
verifier.setClassLoader(loader);
}
try {
a.analyze(cn.name, method);
if (!dump) {
continue;
}
} catch (Exception e) {
e.printStackTrace(pw);
}
printAnalyzerResult(method, a, pw);
}
pw.flush();
}
示例3: printAnalyzerResult
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a,
final PrintWriter pw) {
Frame<BasicValue>[] frames = a.getFrames();
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
pw.println(method.name + method.desc);
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
StringBuilder sb = new StringBuilder();
Frame<BasicValue> f = frames[j];
if (f == null) {
sb.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
sb.append(getShortName(f.getLocal(k).toString()))
.append(' ');
}
sb.append(" : ");
for (int k = 0; k < f.getStackSize(); ++k) {
sb.append(getShortName(f.getStack(k).toString()))
.append(' ');
}
}
while (sb.length() < method.maxStack + method.maxLocals + 1) {
sb.append(' ');
}
pw.print(Integer.toString(j + 100000).substring(1));
pw.print(" " + sb + " : " + t.text.get(t.text.size() - 1));
}
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
method.tryCatchBlocks.get(j).accept(mv);
pw.print(" " + t.text.get(t.text.size() - 1));
}
pw.println();
}
示例4: CheckMethodAdapter
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
/**
* Constructs a new {@link CheckMethodAdapter} object. This method adapter
* will perform basic data flow checks. For instance in a method whose
* signature is <tt>void m ()</tt>, the invalid instruction IRETURN, or the
* invalid sequence IADD L2I will be detected.
*
* @param access
* the method's access flags.
* @param name
* the method's name.
* @param desc
* the method's descriptor (see {@link Type Type}).
* @param cmv
* the method visitor to which this adapter must delegate calls.
* @param labels
* a map of already visited labels (in other methods).
*/
public CheckMethodAdapter(final int access, final String name,
final String desc, final MethodVisitor cmv,
final Map<Label, Integer> labels) {
this(new MethodNode(Opcodes.ASM5, access, name, desc, null, null) {
@Override
public void visitEnd() {
Analyzer<BasicValue> a = new Analyzer<BasicValue>(
new BasicVerifier());
try {
a.analyze("dummy", this);
} catch (Exception e) {
if (e instanceof IndexOutOfBoundsException
&& maxLocals == 0 && maxStack == 0) {
throw new RuntimeException(
"Data flow checking option requires valid, non zero maxLocals and maxStack values.");
}
e.printStackTrace();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw, true);
CheckClassAdapter.printAnalyzerResult(this, a, pw);
pw.close();
throw new RuntimeException(e.getMessage() + ' '
+ sw.toString());
}
accept(cmv);
}
}, labels);
this.access = access;
}
示例5: resolve
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
@Override
public ClassReader resolve(ClassNode cn, MethodNode mn, String type) {
int classIndex = cn.name.lastIndexOf("/");
String callerPkg = classIndex == -1 ? ""
: cn.name.substring(0, classIndex);
int typeClassIndex = type.lastIndexOf("/");
String pkg = typeClassIndex == - 1 ? ""
: type.substring(0, typeClassIndex);
ClassReader reader = null;
if (packages.contains(pkg) || pkg.equals(callerPkg)) {
ClassReader r = pools.getGlobalPool().getClassReader(type);
if (r != null) {
// if not private
if ((r.getAccess() & Opcodes.ACC_PRIVATE)
!= Opcodes.ACC_PRIVATE) {
// public
if (((r.getAccess() & Opcodes.ACC_PUBLIC)
== Opcodes.ACC_PUBLIC)) {
reader = r;
} else if (pkg.equals(callerPkg)) {
reader = r;
}
}
}
}
return reader;
}
示例6: optimize
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
@Override
public boolean optimize(Consumer<String> logger, AsmPools pools,
AsmModulePool modulePool,
ClassNode cn, MethodNode m, TypeResolver resolver) throws Exception {
this.logger = logger;
Data data = ReflectionOptimizer.replaceWithClassConstant(cn, m, createResolver(resolver));
instructionsRemoved += data.removedInstructions();
numRemovedHandlers += data.removedHandlers().size();
for (Entry<String, Set<Block>> entry : data.removedHandlers().entrySet()) {
logRemoval(cn.name + "." + m.name + "removed block for " + entry.getKey()
+ " : " + entry.getValue());
}
return data.removedInstructions() > 0;
}
示例7: createResolver
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
public TypeResolver createResolver(TypeResolver resolver) {
return (ClassNode cn, MethodNode mn, String type) -> {
ClassReader reader = resolver.resolve(cn, mn, type);
if (reader == null) {
logNotReplaced(type);
} else {
logReplaced(type);
}
return reader;
};
}
示例8: canThrowCheckedException
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
public static boolean canThrowCheckedException(ReflectionOptimizer.TypeResolver cch,
ClassNode classNode, MethodNode m, TryCatchBlockNode bn) throws Exception {
int istart = m.instructions.indexOf(bn.start);
int iend = m.instructions.indexOf(bn.end);
for (int i = istart; i < iend - 1; i++) {
AbstractInsnNode instr = m.instructions.get(i);
if (instr instanceof MethodInsnNode) {
MethodInsnNode meth = (MethodInsnNode) instr;
ClassReader reader = cch.resolve(classNode, m, meth.owner);
if (reader != null) {
ClassNode cn = new ClassNode();
reader.accept(cn, ClassReader.EXPAND_FRAMES);
for (MethodNode method : cn.methods) {
if (method.name.equals(meth.name)) {
for (String e : method.exceptions) {
if (e.equals(bn.type)) {
return true;
}
}
}
}
} else {
return true;
}
}
}
return false;
}
示例9: suppressBlocks
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
public static void suppressBlocks(MethodNode m, Set<ControlFlow.Block> toRemove) throws Exception {
m.instructions.resetLabels();
Iterator<AbstractInsnNode> it = m.instructions.iterator();
while (it.hasNext()) {
AbstractInsnNode n = it.next();
Iterator<TryCatchBlockNode> handlers = m.tryCatchBlocks.iterator();
boolean cont = false;
// Do not delete instructions that are end of other try block.
while (handlers.hasNext()) {
TryCatchBlockNode handler = handlers.next();
if (handler.end == n) {
cont = true;
}
}
if (cont) {
continue;
}
for (ControlFlow.Block b : toRemove) {
for (ControlFlow.InstructionNode ins : b.getInstructions()) {
if (ins.getInstr() == n) {
it.remove();
}
}
}
}
}
示例10: visit
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
@Override
public void visit(AsmPools pools) {
called = true;
for (AsmModulePool p : pools.getModulePools()) {
p.visitClassReaders((reader) -> {
ClassNode cn = new ClassNode();
if ((reader.getAccess() & Opcodes.ACC_INTERFACE) == 0) {
reader.accept(cn, ClassReader.EXPAND_FRAMES);
for (MethodNode m : cn.methods) {
if ((m.access & Opcodes.ACC_ABSTRACT) == 0
&& (m.access & Opcodes.ACC_NATIVE) == 0) {
numMethods += 1;
try {
ControlFlow f
= ControlFlow.createControlFlow(cn.name, m);
for (Block b : f.getBlocks()) {
numBlocks += 1;
f.getClosure(b);
}
} catch (Throwable ex) {
//ex.printStackTrace();
throw new RuntimeException("Exception in "
+ cn.name + "." + m.name, ex);
}
}
}
}
return null;
});
}
}
示例11: checkForName
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
private static void checkForName(MethodNode m) throws Exception {
Iterator<AbstractInsnNode> it = m.instructions.iterator();
boolean found = false;
while (it.hasNext()) {
AbstractInsnNode n = it.next();
if (n instanceof MethodInsnNode) {
MethodInsnNode met = (MethodInsnNode) n;
if (met.name.equals("forName")
&& met.owner.equals("java/lang/Class")
&& met.desc.equals("(Ljava/lang/String;)Ljava/lang/Class;")) {
found = true;
break;
}
}
}
if (!found) {
throw new Exception("forName removed but shouldn't have");
}
found = false;
for (TryCatchBlockNode tcb : m.tryCatchBlocks) {
if (tcb.type.equals(ClassNotFoundException.class.getName().replaceAll("\\.", "/"))) {
found = true;
break;
}
}
if (!found) {
throw new Exception("tryCatchBlocks removed but shouldn't have");
}
}
示例12: canRun
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
@Override
protected boolean canRun(ClassNode node) {
if(node.access == (Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_SUPER))
{
int cnFields = 0;
String cnField = "L" + classnames.get("CacheableNode") + ";";
List<FieldNode> fieldNodes = node.fields;
for(FieldNode fieldNode : fieldNodes)
{
if(fieldNode.desc.equals(cnField))
cnFields++;
}
if(cnFields > 0)
{
List<MethodNode> methodNodes = node.methods;
int cnMethods = 0;
for(MethodNode methodNode : methodNodes)
{
if(methodNode.desc.contains(cnField))
cnMethods++;
}
return cnMethods > 10;
}
}
return false;
}
示例13: find
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
public static List<AbstractInsnNode> find(ClassNode cn, Mask... masks) {
for (MethodNode mn : cn.methods) {
for (AbstractInsnNode ain : mn.instructions.toArray()) {
List<AbstractInsnNode> result = next(ain, masks);
if (result != null) return result;
}
}
return null;
}
示例14: findAll
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
public static List<List<AbstractInsnNode>> findAll(ClassNode cn, Mask... masks) {
List<List<AbstractInsnNode>> all = new ArrayList<>();
for (MethodNode mn : cn.methods) {
for (AbstractInsnNode ain : mn.instructions.toArray()) {
List<AbstractInsnNode> result = next(ain, masks);
if (result != null) all.add(result);
}
}
return all.isEmpty() ? null : all;
}
示例15: printAnalyzerResult
import jdk.internal.org.objectweb.asm.tree.MethodNode; //导入依赖的package包/类
static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a,
final PrintWriter pw) {
Frame<BasicValue>[] frames = a.getFrames();
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
pw.println(method.name + method.desc);
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
StringBuffer s = new StringBuffer();
Frame<BasicValue> f = frames[j];
if (f == null) {
s.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
s.append(getShortName(f.getLocal(k).toString()))
.append(' ');
}
s.append(" : ");
for (int k = 0; k < f.getStackSize(); ++k) {
s.append(getShortName(f.getStack(k).toString()))
.append(' ');
}
}
while (s.length() < method.maxStack + method.maxLocals + 1) {
s.append(' ');
}
pw.print(Integer.toString(j + 100000).substring(1));
pw.print(" " + s + " : " + t.text.get(t.text.size() - 1));
}
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
method.tryCatchBlocks.get(j).accept(mv);
pw.print(" " + t.text.get(t.text.size() - 1));
}
pw.println();
}