1 4 package com.tc.aspectwerkz.transform.inlining.compiler; 5 6 import com.tc.asm.MethodVisitor; 7 import com.tc.asm.Type; 8 9 import com.tc.aspectwerkz.transform.TransformationUtil; 10 11 import java.lang.reflect.Modifier ; 12 13 20 public class ConstructorExecutionJoinPointCompiler extends AbstractJoinPointCompiler { 21 22 27 ConstructorExecutionJoinPointCompiler(final CompilationInfo.Model model) { 28 super(model); 29 } 30 31 34 protected void createJoinPointSpecificFields() { 35 String [] fieldNames = null; 36 Type[] argumentTypes = Type.getArgumentTypes(m_calleeMemberDesc); 38 fieldNames = new String [argumentTypes.length]; 39 for (int i = 0; i < argumentTypes.length; i++) { 40 Type argumentType = argumentTypes[i]; 41 String fieldName = ARGUMENT_FIELD + i; 42 fieldNames[i] = fieldName; 43 m_cw.visitField(ACC_PRIVATE, fieldName, argumentType.getDescriptor(), null, null); 44 } 45 m_fieldNames = fieldNames; 46 47 m_cw.visitField( 48 ACC_PRIVATE + ACC_STATIC, 49 SIGNATURE_FIELD_NAME, 50 CONSTRUCTOR_SIGNATURE_IMPL_CLASS_SIGNATURE, 51 null, 52 null 53 ); 54 } 55 56 63 protected void createSignature(final MethodVisitor cv) { 64 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE); 65 cv.visitLdcInsn(new Integer (m_joinPointHash)); 66 67 cv.visitMethodInsn( 68 INVOKESTATIC, 69 SIGNATURE_FACTORY_CLASS, 70 NEW_CONSTRUCTOR_SIGNATURE_METHOD_NAME, 71 NEW_CONSTRUCTOR_SIGNATURE_METHOD_SIGNATURE 72 ); 73 cv.visitFieldInsn( 74 PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, 75 CONSTRUCTOR_SIGNATURE_IMPL_CLASS_SIGNATURE 76 ); 77 } 78 79 87 protected void createInlinedJoinPointInvocation(final MethodVisitor cv, final CompilerInput input) { 88 89 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 91 cv.visitVarInsn(ALOAD, 0); 92 } 93 94 loadArgumentMemberFields(cv, input.argStartIndex); 95 String bodyName = TransformationUtil.getConstructorBodyMethodName(m_calleeClassName); 96 String bodyDesc = TransformationUtil.getConstructorBodyMethodSignature(m_calleeMemberDesc, m_calleeClassName); 97 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, bodyName, bodyDesc); 98 } 99 100 106 protected void createJoinPointInvocation(final MethodVisitor cv) { 107 108 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 110 cv.visitVarInsn(ALOAD, 0); 111 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 112 } 113 114 loadArguments(cv); 115 String bodyName = TransformationUtil.getConstructorBodyMethodName(m_calleeClassName); 116 String bodyDesc = TransformationUtil.getConstructorBodyMethodSignature(m_calleeMemberDesc, m_calleeClassName); 117 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, bodyName, bodyDesc); 118 } 119 120 125 protected Type getJoinPointReturnType() { 126 return Type.getReturnType(m_calleeMemberDesc); 127 } 128 129 134 protected Type[] getJoinPointArgumentTypes() { 135 return Type.getArgumentTypes(m_calleeMemberDesc); 136 } 137 138 141 protected void createGetRttiMethod() { 142 MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE, null, null); 143 144 cv.visitTypeInsn(NEW, CONSTRUCTOR_RTTI_IMPL_CLASS_NAME); 146 cv.visitInsn(DUP); 147 cv.visitFieldInsn( 148 GETSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, CONSTRUCTOR_SIGNATURE_IMPL_CLASS_SIGNATURE 149 ); 150 cv.visitVarInsn(ALOAD, 0); 151 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLER_INSTANCE_FIELD_NAME, m_callerClassSignature); 152 cv.visitVarInsn(ALOAD, 0); 153 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 154 cv.visitMethodInsn( 155 INVOKESPECIAL, CONSTRUCTOR_RTTI_IMPL_CLASS_NAME, INIT_METHOD_NAME, 156 CONSTRUCTOR_RTTI_IMPL_INIT_SIGNATURE 157 ); 158 159 cv.visitInsn(DUP); 161 createArgumentArrayAt(cv, 1); 162 cv.visitVarInsn(ALOAD, 1); 163 cv.visitMethodInsn( 164 INVOKEVIRTUAL, CONSTRUCTOR_RTTI_IMPL_CLASS_NAME, SET_PARAMETER_VALUES_METHOD_NAME, 165 SET_PARAMETER_VALUES_METHOD_SIGNATURE 166 ); 167 168 cv.visitInsn(ARETURN); 169 cv.visitMaxs(0, 0); 170 } 171 172 175 protected void createGetSignatureMethod() { 176 MethodVisitor cv = m_cw.visitMethod( 177 ACC_PUBLIC, 178 GET_SIGNATURE_METHOD_NAME, 179 GET_SIGNATURE_METHOD_SIGNATURE, 180 null, 181 null 182 ); 183 cv.visitFieldInsn( 184 GETSTATIC, m_joinPointClassName, 185 SIGNATURE_FIELD_NAME, CONSTRUCTOR_SIGNATURE_IMPL_CLASS_SIGNATURE 186 ); 187 cv.visitInsn(ARETURN); 188 cv.visitMaxs(0, 0); 189 } 190 } | Popular Tags |