⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionvisitor.java

📁 该工具也是用于字节码插桩
💻 JAVA
字号:
/* * ConnectionVisitor.java * * Created on July 24, 2001, 8:21 AM * * See LICENSE file for license conditions. */package residue.graph;import org.apache.bcel.generic.*;import java.util.*;/** * * @author  chowells * @version  */public class ConnectionVisitor extends EmptyVisitor{	private boolean shouldConnect;		// InstructionHandle -> Node table	private Map tab;	private InstructionHandle handle;	private int sysExitIndex;	private int runExitIndex;		private Set heads = new HashSet();		public ConnectionVisitor(Map table, ConstantPoolGen cp)	{		tab = table;		sysExitIndex = cp.lookupMethodref("java.lang.System", "exit", "(I)V");		runExitIndex = cp.lookupMethodref("java.lang.Runtime", "exit", "(I)V");	} // ConnectionVisitor		public boolean shouldConnectToNext()	{		return shouldConnect;	} // connectToNext		public void startVisit(InstructionHandle ih)	{		if (ih.getPrev() == null) heads.add(ih);		shouldConnect = true;		handle = ih;		handle.accept(this);	} // startVisit		public Set getHeads()	{		return Collections.unmodifiableSet(heads);	} // getHeads		public void visitJsrInstruction(JsrInstruction ji)	{		// put its target in the set of InstructionHandles		// that begin disconnected components of the flow graph		heads.add(ji.getTarget());	} // visitJsrInstruction		public void visitIfInstruction(IfInstruction ii)	{		Node n = (Node)tab.get(handle);		Node t = (Node)tab.get(ii.getTarget());		n.addEdge(t);	} // visitIfInstruction		public void visitGotoInstruction(GotoInstruction gi)	{		Node n = (Node)tab.get(handle);		Node t = (Node)tab.get(gi.getTarget());		n.addEdge(t);		shouldConnect = false;	} // visitGotoInstruction		public void visitSelect(Select s)	{		Node n = (Node)tab.get(handle);		InstructionHandle [] targets = s.getTargets();		for (int i = 0; i < targets.length; i++)		{			Node t = (Node)tab.get(targets[i]);			n.addEdge(t);		} // for		Node t = (Node)tab.get(s.getTarget());		n.addEdge(t);		shouldConnect = false;	} // visitSelect		public void visitReturnInstruction(ReturnInstruction ri)	{		shouldConnect = false;	} // visitReturnInstruction		public void visitINVOKESTATIC(INVOKESTATIC i)	{		if (i.getIndex() == sysExitIndex)			shouldConnect = false;	} // visitINVOKESTATIC		public void visitINVOKEVIRTUAL(INVOKEVIRTUAL i)	{		if (i.getIndex() == runExitIndex)			shouldConnect = false;	} // visitINVOKEVIRTUAL		public void visitRET(RET r)	{		shouldConnect = false;	} // visitRet		public void visitATHROW(ATHROW th)	{		shouldConnect = false;	} // visitATHROW	} // class ConnectionVisitor

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -