1 8 package org.codehaus.aspectwerkz.transform.inlining.compiler; 9 10 import org.objectweb.asm.CodeVisitor; 11 import org.objectweb.asm.Type; 12 13 import org.codehaus.aspectwerkz.transform.TransformationUtil; 14 import org.codehaus.aspectwerkz.transform.inlining.AsmHelper; 15 16 import java.lang.reflect.Modifier ; 17 18 25 public class MethodExecutionJoinPointCompiler extends AbstractJoinPointCompiler { 26 27 32 MethodExecutionJoinPointCompiler(final CompilationInfo.Model model) { 33 super(model); 34 } 35 36 39 protected void createJoinPointSpecificFields() { 40 String [] fieldNames = null; 41 Type[] argumentTypes = Type.getArgumentTypes(m_calleeMemberDesc); 43 fieldNames = new String [argumentTypes.length]; 44 for (int i = 0; i < argumentTypes.length; i++) { 45 Type argumentType = argumentTypes[i]; 46 String fieldName = ARGUMENT_FIELD + i; 47 fieldNames[i] = fieldName; 48 m_cw.visitField(ACC_PRIVATE, fieldName, argumentType.getDescriptor(), null, null); 49 } 50 51 m_fieldNames = fieldNames; 52 53 m_cw.visitField( 54 ACC_PRIVATE + ACC_STATIC, 55 SIGNATURE_FIELD_NAME, 56 METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE, 57 null, 58 null 59 ); 60 } 61 62 69 protected void createSignature(final CodeVisitor cv) { 70 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME, CLASS_CLASS_SIGNATURE); 71 cv.visitLdcInsn(new Integer (m_joinPointHash)); 72 73 cv.visitMethodInsn( 74 INVOKESTATIC, 75 SIGNATURE_FACTORY_CLASS, 76 NEW_METHOD_SIGNATURE_METHOD_NAME, 77 NEW_METHOD_SIGNATURE_METHOD_SIGNATURE 78 ); 79 cv.visitFieldInsn( 80 PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE 81 ); 82 83 } 84 85 93 protected void createInlinedJoinPointInvocation(final CodeVisitor cv, final boolean isOptimizedJoinPoint, 94 final int argStartIndex, final int joinPointIndex) { 95 96 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 98 cv.visitVarInsn(ALOAD, 0); 99 } 100 101 String joinPointName = null; 103 loadArgumentMemberFields(cv, argStartIndex); 104 joinPointName = TransformationUtil.getPrefixedOriginalMethodName( 105 m_calleeMemberName, 106 m_calleeClassName 107 ); 108 if (Modifier.isStatic(m_calleeMemberModifiers)) { 109 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, m_calleeMemberDesc); 110 } else { 111 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, m_calleeMemberDesc); 112 } 113 114 } 115 116 122 protected void createJoinPointInvocation(final CodeVisitor cv) { 123 124 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 126 cv.visitVarInsn(ALOAD, 0); 127 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 128 } 129 130 String joinPointName; 131 loadArguments(cv); 132 joinPointName = TransformationUtil.getPrefixedOriginalMethodName( 133 m_calleeMemberName, 134 m_calleeClassName 135 ); 136 if (Modifier.isStatic(m_calleeMemberModifiers)) { 137 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, m_calleeMemberDesc); 138 } else { 139 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, m_calleeMemberDesc); 140 } 141 } 142 143 148 protected Type getJoinPointReturnType() { 149 return Type.getReturnType(m_calleeMemberDesc); 150 } 151 152 157 protected Type[] getJoinPointArgumentTypes() { 158 return Type.getArgumentTypes(m_calleeMemberDesc); 159 } 160 161 164 protected void createGetRttiMethod() { 165 CodeVisitor cv = m_cw.visitMethod(ACC_PUBLIC, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE, null, null); 166 167 cv.visitTypeInsn(NEW, METHOD_RTTI_IMPL_CLASS_NAME); 169 cv.visitInsn(DUP); 170 cv.visitFieldInsn( 171 GETSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE 172 ); 173 cv.visitVarInsn(ALOAD, 0); 174 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLER_INSTANCE_FIELD_NAME, m_callerClassSignature); 175 cv.visitVarInsn(ALOAD, 0); 176 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 177 cv.visitMethodInsn( 178 INVOKESPECIAL, METHOD_RTTI_IMPL_CLASS_NAME, INIT_METHOD_NAME, METHOD_RTTI_IMPL_INIT_SIGNATURE 179 ); 180 181 cv.visitInsn(DUP); 183 createArgumentArrayAt(cv, 1); 184 cv.visitVarInsn(ALOAD, 1); 185 cv.visitMethodInsn( 186 INVOKEVIRTUAL, METHOD_RTTI_IMPL_CLASS_NAME, SET_PARAMETER_VALUES_METHOD_NAME, 187 SET_PARAMETER_VALUES_METHOD_SIGNATURE 188 ); 189 190 if (m_returnType.getSort() != Type.VOID) { 192 cv.visitInsn(DUP); 193 if (AsmHelper.isPrimitive(m_returnType)) { 194 AsmHelper.prepareWrappingOfPrimitiveType(cv, m_returnType); 195 cv.visitVarInsn(ALOAD, 0); 196 cv.visitFieldInsn( 197 GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor() 198 ); 199 AsmHelper.wrapPrimitiveType(cv, m_returnType); 200 } else { 201 cv.visitVarInsn(ALOAD, 0); 202 cv.visitFieldInsn( 203 GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor() 204 ); 205 } 206 cv.visitMethodInsn( 207 INVOKEVIRTUAL, METHOD_RTTI_IMPL_CLASS_NAME, SET_RETURN_VALUE_METHOD_NAME, 208 SET_RETURN_VALUE_METHOD_SIGNATURE 209 ); 210 } 211 212 cv.visitInsn(ARETURN); 213 cv.visitMaxs(0, 0); 214 } 215 216 219 protected void createGetSignatureMethod() { 220 CodeVisitor cv = m_cw.visitMethod( 221 ACC_PUBLIC, 222 GET_SIGNATURE_METHOD_NAME, 223 GET_SIGNATURE_METHOD_SIGNATURE, 224 null, 225 null 226 ); 227 228 cv.visitFieldInsn( 229 GETSTATIC, m_joinPointClassName, 230 SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE 231 ); 232 cv.visitInsn(ARETURN); 233 cv.visitMaxs(0, 0); 234 } 235 } | Popular Tags |