本文整理汇总了Java中jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode类的典型用法代码示例。如果您正苦于以下问题:Java TryCatchBlockNode类的具体用法?Java TryCatchBlockNode怎么用?Java TryCatchBlockNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TryCatchBlockNode类属于jdk.internal.org.objectweb.asm.tree包,在下文中一共展示了TryCatchBlockNode类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitCode
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
/**
* Creates the new instructions, inlining each instantiation of each
* subroutine until the code is fully elaborated.
*/
private void emitCode() {
LinkedList<Instantiation> worklist = new LinkedList<Instantiation>();
// Create an instantiation of the "root" subroutine, which is just the
// main routine
worklist.add(new Instantiation(null, mainSubroutine));
// Emit instantiations of each subroutine we encounter, including the
// main subroutine
InsnList newInstructions = new InsnList();
List<TryCatchBlockNode> newTryCatchBlocks = new ArrayList<TryCatchBlockNode>();
List<LocalVariableNode> newLocalVariables = new ArrayList<LocalVariableNode>();
while (!worklist.isEmpty()) {
Instantiation inst = worklist.removeFirst();
emitSubroutine(inst, worklist, newInstructions, newTryCatchBlocks,
newLocalVariables);
}
instructions = newInstructions;
tryCatchBlocks = newTryCatchBlocks;
localVariables = newLocalVariables;
}
示例2: visitEnd
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
@Override
public void visitEnd() {
// Compares TryCatchBlockNodes by the length of their "try" block.
Comparator<TryCatchBlockNode> comp = new Comparator<TryCatchBlockNode>() {
public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) {
int len1 = blockLength(t1);
int len2 = blockLength(t2);
return len1 - len2;
}
private int blockLength(TryCatchBlockNode block) {
int startidx = instructions.indexOf(block.start);
int endidx = instructions.indexOf(block.end);
return endidx - startidx;
}
};
Collections.sort(tryCatchBlocks, comp);
// Updates the 'target' of each try catch block annotation.
for (int i = 0; i < tryCatchBlocks.size(); ++i) {
tryCatchBlocks.get(i).updateIndex(i);
}
if (mv != null) {
accept(mv);
}
}
示例3: checkNoForName
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的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);
}
}
}
示例4: visitEnd
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
@Override
public void visitEnd() {
// Compares TryCatchBlockNodes by the length of their "try" block.
Comparator<TryCatchBlockNode> comp = new Comparator<TryCatchBlockNode>() {
public int compare(TryCatchBlockNode t1, TryCatchBlockNode t2) {
int len1 = blockLength(t1);
int len2 = blockLength(t2);
return len1 - len2;
}
private int blockLength(TryCatchBlockNode block) {
int startidx = instructions.indexOf(block.start);
int endidx = instructions.indexOf(block.end);
return endidx - startidx;
}
};
Collections.sort(tryCatchBlocks, comp);
if (mv != null) {
accept(mv);
}
}
示例5: emitCode
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
/**
* Creates the new instructions, inlining each instantiation of each
* subroutine until the code is fully elaborated.
*/
private void emitCode() {
LinkedList<Instantiation> worklist = new LinkedList<Instantiation>();
// Create an instantiation of the "root" subroutine, which is just the
// main routine
worklist.add(new Instantiation(null, mainSubroutine));
// Emit instantiations of each subroutine we encounter, including the
// main subroutine
InsnList newInstructions = new InsnList();
List<TryCatchBlockNode> newTryCatchBlocks = new ArrayList<TryCatchBlockNode>();
List<LocalVariableNode> newLocalVariables = new ArrayList<LocalVariableNode>();
while (!worklist.isEmpty()) {
Instantiation inst = worklist.removeFirst();
emitSubroutine(inst,
worklist,
newInstructions,
newTryCatchBlocks,
newLocalVariables);
}
instructions = newInstructions;
tryCatchBlocks = newTryCatchBlocks;
localVariables = newLocalVariables;
}
示例6: canThrowCheckedException
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的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;
}
示例7: suppressBlocks
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的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();
}
}
}
}
}
示例8: checkForName
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的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");
}
}
示例9: markSubroutineWalk
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
/**
* Performs a depth first search walking the normal byte code path starting
* at <code>index</code>, and adding each instruction encountered into the
* subroutine <code>sub</code>. After this walk is complete, iterates over
* the exception handlers to ensure that we also include those byte codes
* which are reachable through an exception that may be thrown during the
* execution of the subroutine. Invoked from <code>markSubroutines()</code>.
*
* @param sub
* the subroutine whose instructions must be computed.
* @param index
* an instruction of this subroutine.
* @param anyvisited
* indexes of the already visited instructions, i.e. marked as
* part of this subroutine or any previously computed subroutine.
*/
private void markSubroutineWalk(final BitSet sub, final int index,
final BitSet anyvisited) {
if (LOGGING) {
log("markSubroutineWalk: sub=" + sub + " index=" + index);
}
// First find those instructions reachable via normal execution
markSubroutineWalkDFS(sub, index, anyvisited);
// Now, make sure we also include any applicable exception handlers
boolean loop = true;
while (loop) {
loop = false;
for (Iterator<TryCatchBlockNode> it = tryCatchBlocks.iterator(); it
.hasNext();) {
TryCatchBlockNode trycatch = it.next();
if (LOGGING) {
// TODO use of default toString().
log("Scanning try/catch " + trycatch);
}
// If the handler has already been processed, skip it.
int handlerindex = instructions.indexOf(trycatch.handler);
if (sub.get(handlerindex)) {
continue;
}
int startindex = instructions.indexOf(trycatch.start);
int endindex = instructions.indexOf(trycatch.end);
int nextbit = sub.nextSetBit(startindex);
if (nextbit != -1 && nextbit < endindex) {
if (LOGGING) {
log("Adding exception handler: " + startindex + '-'
+ endindex + " due to " + nextbit + " handler "
+ handlerindex);
}
markSubroutineWalkDFS(sub, handlerindex, anyvisited);
loop = true;
}
}
}
}
示例10: markSubroutineWalk
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
/**
* Performs a depth first search walking the normal byte code path starting
* at <code>index</code>, and adding each instruction encountered into
* the subroutine <code>sub</code>. After this walk is complete, iterates
* over the exception handlers to ensure that we also include those byte
* codes which are reachable through an exception that may be thrown during
* the execution of the subroutine. Invoked from
* <code>markSubroutines()</code>.
*
* @param sub the subroutine whose instructions must be computed.
* @param index an instruction of this subroutine.
* @param anyvisited indexes of the already visited instructions, i.e.
* marked as part of this subroutine or any previously computed
* subroutine.
*/
private void markSubroutineWalk(
final BitSet sub,
final int index,
final BitSet anyvisited)
{
if (LOGGING) {
log("markSubroutineWalk: sub=" + sub + " index=" + index);
}
// First find those instructions reachable via normal execution
markSubroutineWalkDFS(sub, index, anyvisited);
// Now, make sure we also include any applicable exception handlers
boolean loop = true;
while (loop) {
loop = false;
for (Iterator<TryCatchBlockNode> it = tryCatchBlocks.iterator(); it.hasNext();) {
TryCatchBlockNode trycatch = it.next();
if (LOGGING) {
// TODO use of default toString().
log("Scanning try/catch " + trycatch);
}
// If the handler has already been processed, skip it.
int handlerindex = instructions.indexOf(trycatch.handler);
if (sub.get(handlerindex)) {
continue;
}
int startindex = instructions.indexOf(trycatch.start);
int endindex = instructions.indexOf(trycatch.end);
int nextbit = sub.nextSetBit(startindex);
if (nextbit != -1 && nextbit < endindex) {
if (LOGGING) {
log("Adding exception handler: " + startindex + '-'
+ endindex + " due to " + nextbit + " handler "
+ handlerindex);
}
markSubroutineWalkDFS(sub, handlerindex, anyvisited);
loop = true;
}
}
}
}
示例11: newControlFlowExceptionEdge
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
/**
* Creates a control flow graph edge corresponding to an exception handler.
* The default implementation of this method delegates to
* {@link #newControlFlowExceptionEdge(int, int)
* newControlFlowExceptionEdge(int, int)}. It can be overridden in order to
* construct the control flow graph of a method (this method is called by
* the {@link #analyze analyze} method during its visit of the method's
* code).
*
* @param insn an instruction index.
* @param tcb TryCatchBlockNode corresponding to this edge.
* @return true if this edge must be considered in the data flow analysis
* performed by this analyzer, or false otherwise. The default
* implementation of this method delegates to
* {@link #newControlFlowExceptionEdge(int, int)
* newControlFlowExceptionEdge(int, int)}.
*/
protected boolean newControlFlowExceptionEdge(
final int insn,
final TryCatchBlockNode tcb)
{
return newControlFlowExceptionEdge(insn, insns.indexOf(tcb.handler));
}
示例12: getHandlers
import jdk.internal.org.objectweb.asm.tree.TryCatchBlockNode; //导入依赖的package包/类
/**
* Returns the exception handlers for the given instruction.
*
* @param insn
* the index of an instruction of the last recently analyzed
* method.
* @return a list of {@link TryCatchBlockNode} objects.
*/
public List<TryCatchBlockNode> getHandlers(final int insn) {
return handlers[insn];
}