com.tc.object.bytecode.rwsync
Class LockingClassAdapter

java.lang.Object
  extended by com.tc.asm.ClassAdapter
      extended by com.tc.object.bytecode.rwsync.LockingClassAdapter
All Implemented Interfaces:
ClassVisitor, Opcodes

public abstract class LockingClassAdapter
extends ClassAdapter
implements Opcodes

A base for class adapters that wrap methods inside read or write locks. Creates and initializes the lock fields, and defines a table-based approach to specifying locking strategy.


Field Summary
protected static MethodStrategy INIT_STRATEGY
           
protected static MethodStrategy NOLOCK_STRATEGY
           
protected static MethodStrategy READLOCK_STRATEGY
           
protected static MethodStrategy WRITELOCK_STRATEGY
           
 
Fields inherited from class com.tc.asm.ClassAdapter
cv
 
Fields inherited from interface com.tc.asm.Opcodes
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEDYNAMIC_OWNER, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7
 
Constructor Summary
LockingClassAdapter(ClassVisitor cv)
           
 
Method Summary
protected  void addLockFields()
          Helper function to add the necessary lock fields to a class.
protected abstract  java.util.Map<MethodId,MethodStrategy> getLockingStrategy()
           
protected abstract  java.lang.String getOuterDesc()
           
protected abstract  java.lang.String getOuterType()
           
protected abstract  java.lang.String getOwnerType()
           
protected abstract  java.lang.String getOwnerTypeDots()
           
 MethodVisitor visitMethod(int access, java.lang.String name, java.lang.String desc, java.lang.String signature, java.lang.String[] exceptions)
          Modify existing methods and create new wrapped methods.
 
Methods inherited from class com.tc.asm.ClassAdapter
visit, visitAnnotation, visitAttribute, visitEnd, visitField, visitInnerClass, visitOuterClass, visitSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INIT_STRATEGY

protected static final MethodStrategy INIT_STRATEGY

NOLOCK_STRATEGY

protected static final MethodStrategy NOLOCK_STRATEGY

READLOCK_STRATEGY

protected static final MethodStrategy READLOCK_STRATEGY

WRITELOCK_STRATEGY

protected static final MethodStrategy WRITELOCK_STRATEGY
Constructor Detail

LockingClassAdapter

public LockingClassAdapter(ClassVisitor cv)
Method Detail

getOwnerType

protected abstract java.lang.String getOwnerType()
Returns:
the slash and dollar delimited name of the type being instrumented, e.g., "org/hibernate/collection/AbstractPersistentCollection$IteratorProxy"

getOwnerTypeDots

protected abstract java.lang.String getOwnerTypeDots()
Returns:
the human-friendly name of the type being instrumented, e.g., "org.hibernate.collection.AbstractPersistentCollection.IteratorProxy"

getOuterType

protected abstract java.lang.String getOuterType()
Returns:
the slash-delimited name of the outer type, if the owner type (the type being instrumented) is an inner type; or null, if the owner type is a top-level type. For example, "org/hibernate/collection/AbstractPersistentCollection".

getOuterDesc

protected abstract java.lang.String getOuterDesc()
Returns:
the type descriptor of the outer type, if the owner type (the type being instrumented) is an inner type; or null, if the owner type is a top-level type. For example, "Lorg/hibernate/collection/AbstractPersistentCollection;".

getLockingStrategy

protected abstract java.util.Map<MethodId,MethodStrategy> getLockingStrategy()
Returns:
a read-only map of method identifier to locking technique.

visitMethod

public MethodVisitor visitMethod(int access,
                                 java.lang.String name,
                                 java.lang.String desc,
                                 java.lang.String signature,
                                 java.lang.String[] exceptions)
Modify existing methods and create new wrapped methods.

Specified by:
visitMethod in interface ClassVisitor
Overrides:
visitMethod in class ClassAdapter
Parameters:
access - the method's access flags (see Opcodes). This parameter also indicates if the method is synthetic and/or deprecated.
name - the method's name.
desc - the method's descriptor (see Type).
signature - the method's signature. May be null if the method parameters, return type and exceptions do not use generic types.
exceptions - the internal names of the method's exception classes (see getInternalName). May be null.
Returns:
an object to visit the byte code of the method, or null if this class visitor is not interested in visiting the code of this method.

addLockFields

protected void addLockFields()
Helper function to add the necessary lock fields to a class. This should be called from ClassVisitor.visitEnd() of the class adapter that is instrumenting the base class of a hierarchy. That is, if B extends A, and methods in A and B are both being locked, this should be called from A's class adapter. Don't call it from B's adapter, or you'll be using different locks for the A and B methods on the same object!

Class adapters which call this method should also map constructor methods to the InitMethodStrategy strategy to initialize the fields.

Parameters:
cv - can be the originating ClassVisitor or its delegate, it doesn't matter
See Also:
InitMethodStrategy


Copyright © 2010 Terracotta, Inc.. All Rights Reserved.