Normand Briere
2018-07-07 09ddd38fd4a8a7100c834a5e976f4796fae53541
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
 * JStackAlloc (c) 2008 Martin Dvorak <jezek2@advel.cz>
 *
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from
 * the use of this software.
 * 
 * Permission is granted to anyone to use this software for any purpose, 
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 * 
 * 1. The origin of this software must not be misrepresented; you must not
 *    claim that you wrote the original software. If you use this software
 *    in a product, an acknowledgment in the product documentation would be
 *    appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 *    misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */
 
package cz.advel.stack.instrument;
 
import org.objectweb.asm.*;
 
/**
 *
 * @author jezek2
 */
class CheckMethod implements MethodVisitor {
 
   private Instrumenter instr;
 
   public CheckMethod(Instrumenter instr) {
       this.instr = instr;
   }
 
   public AnnotationVisitor visitAnnotationDefault() {
       return CheckClass.EMPTY_VISITOR;
   }
 
   public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
       return CheckClass.EMPTY_VISITOR;
   }
 
   public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) {
       return CheckClass.EMPTY_VISITOR;
   }
 
   public void visitAttribute(Attribute attr) {
   }
 
   public void visitCode() {
   }
 
   public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) {
   }
 
   public void visitInsn(int opcode) {
   }
 
   public void visitIntInsn(int opcode, int operand) {
   }
 
   public void visitVarInsn(int opcode, int var) {
   }
 
   public void visitTypeInsn(int opcode, String desc) {
   }
 
   public void visitFieldInsn(int opcode, String owner, String name, String desc) {
   }
 
   public void visitMethodInsn(int opcode, String owner, String name, String desc) {
       // check for already instrumented code to obtain list of used stack types:
       if (opcode == Opcodes.INVOKEVIRTUAL && owner.equals(instr.getStackInternalName())) {
           if (name.startsWith("get")) {
               String type = Type.getReturnType(desc).getInternalName();
               instr.addStackType(type);
           }
       }
       
       // check if we need to instrument this method:
       if (opcode == Opcodes.INVOKESTATIC && owner.equals(Instrumenter.STACK_NAME)) {
           if (name.equals("alloc") || name.equals("libraryCleanCurrentThread")) {
               instr.addInstrumentMethod();
           }
       }
   }
 
   public void visitJumpInsn(int opcode, Label label) {
   }
 
   public void visitLabel(Label label) {
   }
 
   public void visitLdcInsn(Object cst) {
   }
 
   public void visitIincInsn(int var, int increment) {
   }
 
   public void visitTableSwitchInsn(int min, int max, Label dflt, Label[] labels) {
   }
 
   public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
   }
 
   public void visitMultiANewArrayInsn(String desc, int dims) {
   }
 
   public void visitTryCatchBlock(Label start, Label end, Label handler, String type) {
   }
 
   public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
   }
 
   public void visitLineNumber(int line, Label start) {
   }
 
   public void visitMaxs(int maxStack, int maxLocals) {
   }
 
   public void visitEnd() {
   }
   
}