Example:
// Method to analyze
public Object doSomething(int x) {
Number n;
if (x < 5) {
n = new Double(0);
} else {
n = new Long(0);
}
return n;
}
// Which compiles to:
// 0: iload_1
// 1: iconst_5
// 2: if_icmpge 17
// 5: new #18; //class java/lang/Double
// 8: dup
// 9: dconst_0
// 10: invokespecial #44; //Method java/lang/Double."<init>":(D)V
// 13: astore_2
// 14: goto 26
// 17: new #16; //class java/lang/Long
// 20: dup
// 21: lconst_1
// 22: invokespecial #47; //Method java/lang/Long."<init>":(J)V
// 25: astore_2
// 26: aload_2
// 27: areturn
public void analyzeIt(CtClass clazz, MethodInfo method) {
Analyzer analyzer = new Analyzer();
Frame[] frames = analyzer.analyze(clazz, method);
frames[0].getLocal(0).getCtClass(); // returns clazz;
frames[0].getLocal(1).getCtClass(); // returns java.lang.String
frames[1].peek(); // returns Type.INTEGER
frames[27].peek().getCtClass(); // returns java.lang.Number
}
FramePrinter
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| private CtClass | |
| private Analyzer. | |
| private Frame[] | |
| private final SubroutineScanner | |
| private Subroutine[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Frame[] | Returns: an array, indexed by instruction position, of the starting frame state, or null if this method doesn't have codethe declaring class of the method clazz, MethodInfo the method to analyze method)Performs data-flow analysis on a method and returns an array, indexed by instruction position, containing the starting frame state of all reachable instructions. |
| public Frame[] | Returns: an array, indexed by instruction position, of the starting frame state, or null if this method doesn't have codethe method to analyze method)Performs data-flow analysis on a method and returns an array, indexed by instruction position, containing the starting frame state of all reachable instructions. |
| private void | |
| private Analyzer. | |
| private Frame | |
| private int | |
| private int | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private void | |
| private Type |
| clazz | back to summary |
|---|---|
| private CtClass clazz | |
| exceptions | back to summary |
|---|---|
| private Analyzer. | |
| frames | back to summary |
|---|---|
| private Frame[] frames | |
| scanner | back to summary |
|---|---|
| private final SubroutineScanner scanner | |
| subroutines | back to summary |
|---|---|
| private Subroutine[] subroutines | |
| Analyzer | back to summary |
|---|---|
| public Analyzer() | |
| analyze | back to summary |
|---|---|
| public Frame[] analyze(CtClass clazz, MethodInfo method) throws BadBytecode Performs data-flow analysis on a method and returns an array, indexed by instruction position, containing the starting frame state of all reachable instructions. Non-reachable code, and illegal code offsets are represented as a null in the frame state array. This can be used to detect dead code. If the method does not contain code (it is either native or abstract), null is returned.
| |
| analyze | back to summary |
|---|---|
| public Frame[] analyze(CtMethod method) throws BadBytecode Performs data-flow analysis on a method and returns an array, indexed by instruction position, containing the starting frame state of all reachable instructions. Non-reachable code, and illegal code offsets are represented as a null in the frame state array. This can be used to detect dead code. If the method does not contain code (it is either native or abstract), null is returned.
| |
| analyzeNextEntry | back to summary |
|---|---|
| private void analyzeNextEntry(MethodInfo method, CodeIterator iter, IntQueue queue, Executor executor) throws BadBytecode | |
| buildExceptionInfo | back to summary |
|---|---|
| private Analyzer. | |
| firstFrame | back to summary |
|---|---|
| private Frame firstFrame(MethodInfo method, int maxLocals, int maxStack) | |
| getNext | back to summary |
|---|---|
| private int getNext(CodeIterator iter, int of, int restore) throws BadBytecode | |
| lookAhead | back to summary |
|---|---|
| private int lookAhead(CodeIterator iter, int pos) throws BadBytecode | |
| merge | back to summary |
|---|---|
| private void merge(IntQueue queue, Frame frame, int target) | |
| mergeExceptionHandlers | back to summary |
|---|---|
| private void mergeExceptionHandlers(IntQueue queue, MethodInfo method, int pos, Frame frame) | |
| mergeJsr | back to summary |
|---|---|
| private void mergeJsr(IntQueue queue, Frame frame, Subroutine sub, int pos, int next) throws BadBytecode | |
| mergeLookupSwitch | back to summary |
|---|---|
| private void mergeLookupSwitch(IntQueue queue, int pos, CodeIterator iter, Frame frame) throws BadBytecode | |
| mergeRet | back to summary |
|---|---|
| private void mergeRet(IntQueue queue, CodeIterator iter, int pos, Frame frame, Subroutine subroutine) throws BadBytecode | |
| mergeTableSwitch | back to summary |
|---|---|
| private void mergeTableSwitch(IntQueue queue, int pos, CodeIterator iter, Frame frame) throws BadBytecode | |
| zeroExtend | back to summary |
|---|---|
| private Type zeroExtend(Type type) | |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private int | |
| private int | |
| private Type |
| Access | Constructor and Description |
|---|---|
| private |
| end | back to summary |
|---|---|
| private int end | |
| handler | back to summary |
|---|---|
| private int handler | |
| start | back to summary |
|---|---|
| private int start | |
| type | back to summary |
|---|---|
| private Type type | |
| ExceptionInfo | back to summary |
|---|---|
| private ExceptionInfo(int start, int end, int handler, Type type) | |