1 4 package com.tc.aspectwerkz.transform.inlining.compiler; 5 6 import com.tc.asm.MethodVisitor; 7 import com.tc.asm.Type; 8 9 10 import com.tc.aspectwerkz.transform.TransformationUtil; 11 import com.tc.aspectwerkz.transform.inlining.AsmHelper; 12 13 import java.lang.reflect.Modifier ; 14 15 22 public class FieldGetJoinPointCompiler extends AbstractJoinPointCompiler { 23 24 29 FieldGetJoinPointCompiler(final CompilationInfo.Model model) { 30 super(model); 31 } 32 33 36 protected void createJoinPointSpecificFields() { 37 String [] fieldNames = null; 38 Type fieldType = Type.getType(m_calleeMemberDesc); 40 fieldNames = new String [1]; 41 String fieldName = ARGUMENT_FIELD + 0; 42 fieldNames[0] = fieldName; 43 m_cw.visitField(ACC_PRIVATE, fieldName, fieldType.getDescriptor(), null, null); 44 m_fieldNames = fieldNames; 45 46 m_cw.visitField( 47 ACC_PRIVATE + ACC_STATIC, 48 SIGNATURE_FIELD_NAME, 49 FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE, 50 null, 51 null 52 ); 53 } 54 55 62 protected void createSignature(final MethodVisitor cv) { 63 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, TARGET_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE); 64 cv.visitLdcInsn(new Integer (m_joinPointHash)); 65 66 cv.visitMethodInsn( 67 INVOKESTATIC, 68 SIGNATURE_FACTORY_CLASS, 69 NEW_FIELD_SIGNATURE_METHOD_NAME, 70 NEW_FIELD_SIGNATURE_METHOD_SIGNATURE 71 ); 72 cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE); 73 } 74 75 83 protected void createInlinedJoinPointInvocation(final MethodVisitor cv, final CompilerInput input) { 84 85 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 87 cv.visitVarInsn(ALOAD, 0); 88 } 89 90 if (Modifier.isPublic(m_calleeMemberModifiers)) { 92 if (Modifier.isStatic(m_calleeMemberModifiers)) { 93 cv.visitFieldInsn(GETSTATIC, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 94 } else { 95 cv.visitFieldInsn(GETFIELD, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 96 } 97 } else { 98 String joinPointName = TransformationUtil.getWrapperMethodName( 100 m_calleeMemberName, 101 m_calleeMemberDesc, 102 m_calleeClassName, 103 GETFIELD_WRAPPER_METHOD_PREFIX 104 ); 105 StringBuffer getFieldWrapperDesc = new StringBuffer (); 106 getFieldWrapperDesc.append('('); 107 getFieldWrapperDesc.append(')'); 108 getFieldWrapperDesc.append(m_calleeMemberDesc); 109 if (Modifier.isStatic(m_calleeMemberModifiers)) { 110 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 111 } else { 112 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 113 } 114 } 115 } 116 117 123 protected void createJoinPointInvocation(final MethodVisitor cv) { 124 125 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 127 cv.visitVarInsn(ALOAD, 0); 128 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 129 } 130 131 if (Modifier.isPublic(m_calleeMemberModifiers)) { 133 if (Modifier.isStatic(m_calleeMemberModifiers)) { 134 cv.visitFieldInsn(GETSTATIC, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 135 } else { 136 cv.visitFieldInsn(GETFIELD, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 137 } 138 } else { 139 String joinPointName = TransformationUtil.getWrapperMethodName( 140 m_calleeMemberName, 141 m_calleeMemberDesc, 142 m_calleeClassName, 143 GETFIELD_WRAPPER_METHOD_PREFIX 144 ); 145 StringBuffer getFieldWrapperDesc = new StringBuffer (); 146 getFieldWrapperDesc.append('('); 147 getFieldWrapperDesc.append(')'); 148 getFieldWrapperDesc.append(m_calleeMemberDesc); 149 if (Modifier.isStatic(m_calleeMemberModifiers)) { 150 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 151 } else { 152 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, getFieldWrapperDesc.toString()); 153 } 154 } 155 } 156 157 162 protected Type getJoinPointReturnType() { 163 return Type.getType(m_calleeMemberDesc); 164 } 165 166 171 protected Type[] getJoinPointArgumentTypes() { 172 return new Type[]{Type.getType(m_calleeMemberDesc)}; 173 } 174 175 178 protected void createGetRttiMethod() { 179 MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE, null, null); 180 181 cv.visitTypeInsn(NEW, FIELD_RTTI_IMPL_CLASS_NAME); 183 cv.visitInsn(DUP); 184 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE); 185 cv.visitVarInsn(ALOAD, 0); 186 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLER_INSTANCE_FIELD_NAME, m_callerClassSignature); 187 cv.visitVarInsn(ALOAD, 0); 188 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 189 cv.visitMethodInsn( 190 INVOKESPECIAL, FIELD_RTTI_IMPL_CLASS_NAME, INIT_METHOD_NAME, FIELD_RTTI_IMPL_INIT_SIGNATURE 191 ); 192 193 cv.visitInsn(DUP); 195 if (AsmHelper.isPrimitive(m_returnType)) { 196 AsmHelper.prepareWrappingOfPrimitiveType(cv, m_returnType); 197 cv.visitVarInsn(ALOAD, 0); 198 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor()); 199 AsmHelper.wrapPrimitiveType(cv, m_returnType); 200 } else { 201 cv.visitVarInsn(ALOAD, 0); 202 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor()); 203 } 204 cv.visitMethodInsn( 205 INVOKEVIRTUAL, 206 FIELD_RTTI_IMPL_CLASS_NAME, 207 SET_FIELD_VALUE_METHOD_NAME, 208 SET_FIELD_VALUE_METHOD_SIGNATURE 209 ); 210 211 cv.visitInsn(ARETURN); 212 cv.visitMaxs(0, 0); 213 } 214 215 218 protected void createGetSignatureMethod() { 219 MethodVisitor cv = m_cw.visitMethod( 220 ACC_PUBLIC, 221 GET_SIGNATURE_METHOD_NAME, 222 GET_SIGNATURE_METHOD_SIGNATURE, 223 null, 224 null 225 ); 226 cv.visitFieldInsn( 227 GETSTATIC, m_joinPointClassName, 228 SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE 229 ); 230 cv.visitInsn(ARETURN); 231 cv.visitMaxs(0, 0); 232 } 233 } | Popular Tags |