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