01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.object.bytecode;
06:
07: import com.tc.asm.MethodAdapter;
08: import com.tc.asm.MethodVisitor;
09: import com.tc.asm.Opcodes;
10:
11: /**
12: * Method adaptor that keeps track of the maximum store index that is used for a local variable.
13: */
14: public class MaxLocalVarStoreDetectingMethodAdapter extends
15: MethodAdapter implements Opcodes {
16:
17: private int max_var_store = 0;
18:
19: public MaxLocalVarStoreDetectingMethodAdapter(MethodVisitor mv) {
20: super (mv);
21: }
22:
23: public void visitVarInsn(int opcode, int var) {
24: // detect the maximum position at which local variables are already
25: // stored in the method, this will be used during the instrumentation
26: // to make sure that no current used local variables are overwritten
27: if (ISTORE == opcode || LSTORE == opcode || FSTORE == opcode
28: || DSTORE == opcode || ASTORE == opcode) {
29: if (var > max_var_store) {
30: max_var_store = var;
31: }
32: }
33:
34: super .visitVarInsn(opcode, var);
35: }
36:
37: /**
38: * Returns the current maximum local variable store index.
39: */
40: public int getMaxLocalVarStore() {
41: return max_var_store;
42: }
43: }
|