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 import com.tc.aspectwerkz.transform.inlining.compiler.AbstractJoinPointCompiler; 13 14 import java.lang.reflect.Modifier ; 15 16 23 public class FieldSetJoinPointCompiler extends AbstractJoinPointCompiler { 24 25 30 FieldSetJoinPointCompiler(final CompilationInfo.Model model) { 31 super(model); 32 } 33 34 37 protected void createJoinPointSpecificFields() { 38 String [] fieldNames = null; 39 Type fieldType = Type.getType(m_calleeMemberDesc); 41 fieldNames = new String [1]; 42 String fieldName = ARGUMENT_FIELD + 0; 43 fieldNames[0] = fieldName; 44 m_cw.visitField(ACC_PRIVATE, fieldName, fieldType.getDescriptor(), null, null); 45 m_fieldNames = fieldNames; 46 47 m_cw.visitField( 48 ACC_PRIVATE + ACC_STATIC, 49 SIGNATURE_FIELD_NAME, 50 FIELD_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_FIELD_SIGNATURE_METHOD_NAME, 71 NEW_FIELD_SIGNATURE_METHOD_SIGNATURE 72 ); 73 cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE); 74 } 75 76 84 protected void createInlinedJoinPointInvocation(final MethodVisitor cv, final CompilerInput input) { 85 86 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 88 cv.visitVarInsn(ALOAD, 0); 89 } 90 91 loadArgumentMemberFields(cv, input.argStartIndex); 92 93 if (Modifier.isPublic(m_calleeMemberModifiers)) { 95 if (Modifier.isStatic(m_calleeMemberModifiers)) { 96 cv.visitFieldInsn(PUTSTATIC, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 97 } else { 98 cv.visitFieldInsn(PUTFIELD, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 99 } 100 } else { 101 String joinPointName = null; joinPointName = m_calleeMemberName; 103 joinPointName = TransformationUtil.getWrapperMethodName( 104 joinPointName, 105 m_calleeMemberDesc, 106 m_calleeClassName, 107 PUTFIELD_WRAPPER_METHOD_PREFIX 108 ); 109 StringBuffer sig = new StringBuffer (); 110 sig.append('('); 111 sig.append(m_calleeMemberDesc); 112 sig.append(')'); 113 sig.append('V'); 114 if (Modifier.isStatic(m_calleeMemberModifiers)) { 115 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, sig.toString()); 116 } else { 117 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, sig.toString()); 118 } 119 } 120 121 AsmHelper.addDefaultValue(cv, m_argumentTypes[0]); 122 } 123 124 130 protected void createJoinPointInvocation(final MethodVisitor cv) { 131 132 if (!Modifier.isStatic(m_calleeMemberModifiers)) { 134 cv.visitVarInsn(ALOAD, 0); 135 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 136 } 137 138 loadArguments(cv); 139 140 if (Modifier.isPublic(m_calleeMemberModifiers)) { 142 if (Modifier.isStatic(m_calleeMemberModifiers)) { 143 cv.visitFieldInsn(PUTSTATIC, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 144 } else { 145 cv.visitFieldInsn(PUTFIELD, m_calleeClassName, m_calleeMemberName, m_calleeMemberDesc); 146 } 147 } else { 148 String joinPointName = TransformationUtil.getWrapperMethodName( 149 m_calleeMemberName, 150 m_calleeMemberDesc, 151 m_calleeClassName, 152 PUTFIELD_WRAPPER_METHOD_PREFIX 153 ); 154 StringBuffer putFieldWrapperDesc = new StringBuffer (); 155 putFieldWrapperDesc.append('('); 156 putFieldWrapperDesc.append(m_calleeMemberDesc); 157 putFieldWrapperDesc.append(')'); 158 putFieldWrapperDesc.append('V'); 159 if (Modifier.isStatic(m_calleeMemberModifiers)) { 160 cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName, joinPointName, putFieldWrapperDesc.toString()); 161 } else { 162 cv.visitMethodInsn(INVOKEVIRTUAL, m_calleeClassName, joinPointName, putFieldWrapperDesc.toString()); 163 } 164 } 165 166 AsmHelper.addDefaultValue(cv, m_argumentTypes[0]); 167 } 168 169 174 protected Type getJoinPointReturnType() { 175 return Type.getType(m_calleeMemberDesc); 176 } 177 178 183 protected Type[] getJoinPointArgumentTypes() { 184 return new Type[]{Type.getType(m_calleeMemberDesc)}; 185 } 186 187 190 protected void createGetRttiMethod() { 191 MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC, GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE, null, null); 192 193 cv.visitTypeInsn(NEW, FIELD_RTTI_IMPL_CLASS_NAME); 195 cv.visitInsn(DUP); 196 cv.visitFieldInsn(GETSTATIC, m_joinPointClassName, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE); 197 cv.visitVarInsn(ALOAD, 0); 198 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLER_INSTANCE_FIELD_NAME, m_callerClassSignature); 199 cv.visitVarInsn(ALOAD, 0); 200 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, CALLEE_INSTANCE_FIELD_NAME, m_calleeClassSignature); 201 cv.visitMethodInsn( 202 INVOKESPECIAL, FIELD_RTTI_IMPL_CLASS_NAME, INIT_METHOD_NAME, FIELD_RTTI_IMPL_INIT_SIGNATURE 203 ); 204 205 cv.visitInsn(DUP); 207 if (AsmHelper.isPrimitive(m_returnType)) { 208 AsmHelper.prepareWrappingOfPrimitiveType(cv, m_returnType); 209 cv.visitVarInsn(ALOAD, 0); 210 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor()); 211 AsmHelper.wrapPrimitiveType(cv, m_returnType); 212 } else { 213 cv.visitVarInsn(ALOAD, 0); 214 cv.visitFieldInsn(GETFIELD, m_joinPointClassName, RETURN_VALUE_FIELD_NAME, m_returnType.getDescriptor()); 215 } 216 cv.visitMethodInsn( 217 INVOKEVIRTUAL, 218 FIELD_RTTI_IMPL_CLASS_NAME, 219 SET_FIELD_VALUE_METHOD_NAME, 220 SET_FIELD_VALUE_METHOD_SIGNATURE 221 ); 222 223 cv.visitInsn(ARETURN); 224 cv.visitMaxs(0, 0); 225 } 226 227 230 protected void createGetSignatureMethod() { 231 MethodVisitor cv = m_cw.visitMethod( 232 ACC_PUBLIC, 233 GET_SIGNATURE_METHOD_NAME, 234 GET_SIGNATURE_METHOD_SIGNATURE, 235 null, 236 null 237 ); 238 cv.visitFieldInsn( 239 GETSTATIC, m_joinPointClassName, 240 SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE 241 ); 242 cv.visitInsn(ARETURN); 243 cv.visitMaxs(0, 0); 244 } 245 } | Popular Tags |