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 FieldGetJoinPointCompiler extends AbstractJoinPointCompiler { 26 27 32 FieldGetJoinPointCompiler(final CompilationInfo.Model model) { 33 super(model); 34 } 35 36 39 protected void createJoinPointSpecificFields() { 40 String [] fieldNames = null; 41 Type fieldType = Type.getType(m_calleeMemberDesc); 43 fieldNames = new String [1]; 44 String fieldName = ARGUMENT_FIELD + 0; 45 fieldNames[0] = fieldName; 46 m_cw.visitField(ACC_PRIVATE, fieldName, fieldType.getDescriptor(), null, null); 47 m_fieldNames = fieldNames; 48 49 m_cw.visitField( 50 ACC_PRIVATE + ACC_STATIC, 51 SIGNATURE_FIELD_NAME, 52 FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE, 53 null, 54 null 55 ); 56 } 57 58 65 protected void createSignature(final CodeVisitor cv) { 66 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME, CLASS_CLASS_SIGNATURE); 67 cv.visitLdcInsn(new Integer (m_joinPointHash)); 68 69 cv.visitMethodInsn( 70 INVOKESTATIC, 71 SIGNATURE_FACTORY_CLASS, 72 NEW_FIELD_SIGNATURE_METHOD_NAME, 73 NEW_FIELD_SIGNATURE_METHOD_SIGNATURE 74 ); 75 cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE); 76 } 77 78 86 protected void createInlinedJoinPointInvocation(final CodeVisitor cv, final boolean isOptimizedJoinPoint, 87 final int argStartIndex, final int joinPointIndex) { 88 89 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 91 cv.visitVarInsn(ALOAD, 0); 92 } 93 94 if (Modifier.isPublic(m_calleeMemberModifiers)) { 96 if (Modifier.isStatic(m_calleeMemberModifiers)) { 97 cv.visitFieldInsn(GETSTATIC, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 98 } else { 99 cv.visitFieldInsn(GETFIELD, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 100 } 101 } else { 102 String joinPointName = TransformationUtil.getWrapperMethodName( 104 m_calleeMemberName, 105 m_calleeMemberDesc, 106 m_calleeClassName, 107 GETFIELD_WRAPPER_METHOD_PREFIX 108 ); 109 StringBuffer getFieldWrapperDesc = new StringBuffer (); 110 getFieldWrapperDesc.append('('); 111 getFieldWrapperDesc.append(')'); 112 getFieldWrapperDesc.append(m_calleeMemberDesc); 113 if (Modifier.isStatic(m_calleeMemberModifiers)) { 114 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 115 } else { 116 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 117 } 118 } 119 } 120 121 127 protected void createJoinPointInvocation(final CodeVisitor cv) { 128 129 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 131 cv.visitVarInsn(ALOAD, 0); 132 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 133 } 134 135 if (Modifier.isPublic(m_calleeMemberModifiers)) { 137 if (Modifier.isStatic(m_calleeMemberModifiers)) { 138 cv.visitFieldInsn(GETSTATIC, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 139 } else { 140 cv.visitFieldInsn(GETFIELD, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 141 } 142 } else { 143 String joinPointName = TransformationUtil.getWrapperMethodName( 144 m_calleeMemberName, 145 m_calleeMemberDesc, 146 m_calleeClassName, 147 GETFIELD_WRAPPER_METHOD_PREFIX 148 ); 149 StringBuffer getFieldWrapperDesc = new StringBuffer (); 150 getFieldWrapperDesc.append('('); 151 getFieldWrapperDesc.append(')'); 152 getFieldWrapperDesc.append(m_calleeMemberDesc); 153 if (Modifier.isStatic(m_calleeMemberModifiers)) { 154 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 155 } else { 156 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 157 } 158 } 159 } 160 161 166 protected Type getJoinPointReturnType() { 167 return Type.getType(m_calleeMemberDesc); 168 } 169 170 175 protected Type[] getJoinPointArgumentTypes() { 176 return new Type[]{Type.getType(m_calleeMemberDesc)}; 177 } 178 179 182 protected void createGetRttiMethod() { 183 CodeVisitor cv = m_cw.visitMethod(ACC_PUBLIC, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE, null, null); 184 185 cv.visitTypeInsn(NEW, FIELD_RTTI_IMPL_CLASS_NAME); 187 cv.visitInsn(DUP); 188 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE); 189 cv.visitVarInsn(ALOAD, 0); 190 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLER_INSTANCE_FIELD_NAME, m_callerClassSignature); 191 cv.visitVarInsn(ALOAD, 0); 192 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 193 cv.visitMethodInsn( 194 INVOKESPECIAL, FIELD_RTTI_IMPL_CLASS_NAME, INIT_METHOD_NAME, FIELD_RTTI_IMPL_INIT_SIGNATURE 195 ); 196 197 cv.visitInsn(DUP); 199 if (AsmHelper.isPrimitive(m_returnType)) { 200 AsmHelper.prepareWrappingOfPrimitiveType(cv, m_returnType); 201 cv.visitVarInsn(ALOAD, 0); 202 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor()); 203 AsmHelper.wrapPrimitiveType(cv, m_returnType); 204 } else { 205 cv.visitVarInsn(ALOAD, 0); 206 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor()); 207 } 208 cv.visitMethodInsn( 209 INVOKEVIRTUAL, 210 FIELD_RTTI_IMPL_CLASS_NAME, 211 SET_FIELD_VALUE_METHOD_NAME, 212 SET_FIELD_VALUE_METHOD_SIGNATURE 213 ); 214 215 cv.visitInsn(ARETURN); 216 cv.visitMaxs(0, 0); 217 } 218 219 222 protected void createGetSignatureMethod() { 223 CodeVisitor cv = m_cw.visitMethod( 224 ACC_PUBLIC, 225 GET_SIGNATURE_METHOD_NAME, 226 GET_SIGNATURE_METHOD_SIGNATURE, 227 null, 228 null 229 ); 230 cv.visitFieldInsn( 231 GETSTATIC, m_joinPointClassName, 232 SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE 233 ); 234 cv.visitInsn(ARETURN); 235 cv.visitMaxs(0, 0); 236 } 237 } | Popular Tags |