001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
003: */
004: package com.tc.aspectwerkz.transform.inlining.compiler;
005:
006: import com.tc.asm.MethodVisitor;
007: import com.tc.asm.Type;
008:
009: import com.tc.aspectwerkz.transform.TransformationUtil;
010:
011: /**
012: * A compiler that compiles/generates a class that represents a specific join
013: * point, a class which invokes the advices and the target join point
014: * statically.
015: *
016: * @author <a href="mailto:the_mindstorm@evolva.ro">Alex Popescu </a>
017: */
018: public class StaticInitializationJoinPointCompiler extends
019: AbstractJoinPointCompiler {
020: private static final Type[] ARG_TYPES = new Type[0];
021:
022: /**
023: * Creates a new join point compiler instance.
024: *
025: * @param model
026: */
027: StaticInitializationJoinPointCompiler(
028: final CompilationInfo.Model model) {
029: super (model);
030: }
031:
032: /**
033: * Creates join point specific fields.
034: */
035: protected void createJoinPointSpecificFields() {
036: m_fieldNames = new String[0];
037:
038: m_cw.visitField(ACC_PRIVATE + ACC_STATIC, SIGNATURE_FIELD_NAME,
039: STATICINITIALIZATION_SIGNATURE_IMPL_CLASS_SIGNATURE,
040: null, null);
041: }
042:
043: /**
044: * Creates the signature for the join point.
045: *
046: * @param cv
047: */
048: protected void createSignature(final MethodVisitor cv) {
049: cv.visitFieldInsn(GETSTATIC, m_joinPointClassName,
050: TARGET_CLASS_FIELD_NAME_IN_JP, CLASS_CLASS_SIGNATURE);
051: cv.visitMethodInsn(INVOKESTATIC, SIGNATURE_FACTORY_CLASS,
052: NEW_STATICINITIALIZATION_SIGNATURE_METHOD_NAME,
053: NEW_STATICINITIALIZATION_SIGNATURE_METHOD_SIGNATURE);
054: cv.visitFieldInsn(PUTSTATIC, m_joinPointClassName,
055: SIGNATURE_FIELD_NAME,
056: STATICINITIALIZATION_SIGNATURE_IMPL_CLASS_SIGNATURE);
057: }
058:
059: /**
060: * Optimized implementation that does not retrieve the parameters from the
061: * join point instance but is passed directly to the method from the input
062: * parameters in the 'invoke' method. Can only be used if no around advice
063: * exists.
064: *
065: * @param cv
066: * @param input
067: */
068: protected void createInlinedJoinPointInvocation(
069: final MethodVisitor cv, final CompilerInput input) {
070: String joinPointName = TransformationUtil
071: .getPrefixedOriginalClinitName(m_calleeClassName);
072:
073: cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName,
074: joinPointName, m_calleeMemberDesc);
075: }
076:
077: /**
078: * Creates a call to the target join point, the parameter(s) to the join
079: * point are retrieved from the invocation local join point instance.
080: *
081: * @param cv
082: */
083: protected void createJoinPointInvocation(final MethodVisitor cv) {
084:
085: // load the target instance member field unless calleeMember is static
086: String joinPointName = TransformationUtil
087: .getPrefixedOriginalClinitName(m_calleeClassName);
088: cv.visitMethodInsn(INVOKESTATIC, m_calleeClassName,
089: joinPointName, m_calleeMemberDesc);
090: }
091:
092: /**
093: * Returns the join points return type.
094: *
095: * @return
096: */
097: protected Type getJoinPointReturnType() {
098: return Type.VOID_TYPE;
099: }
100:
101: /**
102: * Returns the join points argument type(s).
103: *
104: * @return
105: */
106: protected Type[] getJoinPointArgumentTypes() {
107: return ARG_TYPES;
108: }
109:
110: /**
111: * Creates the getRtti method
112: */
113: protected void createGetRttiMethod() {
114: MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC,
115: GET_RTTI_METHOD_NAME, GET_RTTI_METHOD_SIGNATURE, null,
116: null);
117:
118: // new StaticInitializationRttiImpl
119: cv
120: .visitTypeInsn(NEW,
121: STATICINITIALIZATION_RTTI_IMPL_CLASS_NAME);
122: cv.visitInsn(DUP);
123: cv.visitFieldInsn(GETSTATIC, m_joinPointClassName,
124: SIGNATURE_FIELD_NAME,
125: STATICINITIALIZATION_SIGNATURE_IMPL_CLASS_SIGNATURE);
126: cv.visitMethodInsn(INVOKESPECIAL,
127: STATICINITIALIZATION_RTTI_IMPL_CLASS_NAME,
128: INIT_METHOD_NAME,
129: STATICINITIALIZATION_RTTI_IMPL_INIT_SIGNATURE);
130:
131: cv.visitInsn(ARETURN);
132: cv.visitMaxs(0, 0);
133: }
134:
135: /**
136: * Creates the getSignature method.
137: */
138: protected void createGetSignatureMethod() {
139: MethodVisitor cv = m_cw.visitMethod(ACC_PUBLIC,
140: GET_SIGNATURE_METHOD_NAME,
141: GET_SIGNATURE_METHOD_SIGNATURE, null, null);
142:
143: cv.visitFieldInsn(GETSTATIC, m_joinPointClassName,
144: SIGNATURE_FIELD_NAME,
145: STATICINITIALIZATION_SIGNATURE_IMPL_CLASS_SIGNATURE);
146: cv.visitInsn(ARETURN);
147: cv.visitMaxs(0, 0);
148: }
149: }
|