final IndexTuple[] aroundAdvices,
final IndexTuple[] beforeAdvices,
final IndexTuple[] afterAdvices,
final System system) {
CodeVisitor cv =
cw.visitMethod(
Constants.ACC_PUBLIC, INIT_METHOD_NAME, JIT_JOIN_POINT_INIT_METHOD_SIGNATURE, null, null
);
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitVarInsn(Constants.ALOAD, 1);
cv.visitVarInsn(Constants.ILOAD, 2);
cv.visitVarInsn(Constants.ALOAD, 3);
cv.visitVarInsn(Constants.ALOAD, 6);
cv.visitInsn(Constants.ACONST_NULL);
cv.visitInsn(Constants.ACONST_NULL);
cv.visitInsn(Constants.ACONST_NULL);
cv.visitMethodInsn(
Constants.INVOKESPECIAL, JOIN_POINT_BASE_CLASS_NAME,
INIT_METHOD_NAME, JOIN_POINT_BASE_INIT_METHOD_SIGNATURE
);
// init the stack frame field
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitInsn(Constants.ICONST_M1);
cv.visitFieldInsn(Constants.PUTFIELD, className, STACKFRAME_FIELD_NAME, I);
// init the signature field
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitVarInsn(Constants.ALOAD, 4);
switch (joinPointType) {
case JoinPointType.METHOD_EXECUTION:
case JoinPointType.METHOD_CALL:
cv.visitTypeInsn(Constants.CHECKCAST, METHOD_SIGNATURE_IMPL_CLASS_NAME);
cv.visitFieldInsn(
Constants.PUTFIELD, className, SIGNATURE_FIELD_NAME, METHOD_SIGNATURE_IMPL_CLASS_SIGNATURE
);
break;
case JoinPointType.CONSTRUCTOR_CALL:
case JoinPointType.CONSTRUCTOR_EXECUTION:
cv.visitTypeInsn(Constants.CHECKCAST, CONSTRUCTOR_SIGNATURE_IMPL_CLASS_NAME);
cv.visitFieldInsn(
Constants.PUTFIELD, className, SIGNATURE_FIELD_NAME,
CONSTRUCTOR_SIGNATURE_IMPL_CLASS_SIGNATURE
);
break;
case JoinPointType.FIELD_SET:
case JoinPointType.FIELD_GET:
cv.visitTypeInsn(Constants.CHECKCAST, FIELD_SIGNATURE_IMPL_CLASS_NAME);
cv.visitFieldInsn(
Constants.PUTFIELD, className, SIGNATURE_FIELD_NAME, FIELD_SIGNATURE_IMPL_CLASS_SIGNATURE
);
break;
case JoinPointType.HANDLER:
throw new UnsupportedOperationException("handler is not support yet");
case JoinPointType.STATIC_INITALIZATION:
throw new UnsupportedOperationException("static initialization is not support yet");
}
// init the rtti field
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitVarInsn(Constants.ALOAD, 5);
switch (joinPointType) {
case JoinPointType.METHOD_EXECUTION:
case JoinPointType.METHOD_CALL:
cv.visitTypeInsn(Constants.CHECKCAST, METHOD_RTTI_IMPL_CLASS_NAME);
cv.visitFieldInsn(Constants.PUTFIELD, className, RTTI_FIELD_NAME, METHOD_RTTI_IMPL_CLASS_SIGNATURE);
break;
case JoinPointType.CONSTRUCTOR_CALL:
case JoinPointType.CONSTRUCTOR_EXECUTION:
cv.visitTypeInsn(Constants.CHECKCAST, CONSTRUCTOR_RTTI_IMPL_CLASS_NAME);
cv.visitFieldInsn(
Constants.PUTFIELD, className, RTTI_FIELD_NAME,
CONSTRUCTOR_RTTI_IMPL_CLASS_SIGNATURE
);
break;
case JoinPointType.FIELD_SET:
case JoinPointType.FIELD_GET:
cv.visitTypeInsn(Constants.CHECKCAST, FIELD_RTTI_IMPL_CLASS_NAME);
cv.visitFieldInsn(Constants.PUTFIELD, className, RTTI_FIELD_NAME, FIELD_RTTI_IMPL_CLASS_SIGNATURE);
break;
case JoinPointType.HANDLER:
throw new UnsupportedOperationException("handler is not support yet");
case JoinPointType.STATIC_INITALIZATION:
throw new UnsupportedOperationException("static initialization is not support yet");
}
// init the system field
cv.visitVarInsn(Constants.ALOAD, 0);
cv.visitVarInsn(Constants.ALOAD, 1);
cv.visitMethodInsn(
Constants.INVOKESTATIC, SYSTEM_LOADER_CLASS_NAME, GET_SYSTEM_METHOD_NAME,
GET_SYSTEM_METHOD_NAME_SIGNATURE
);
cv.visitFieldInsn(Constants.PUTFIELD, className, SYSTEM_FIELD_NAME, SYSTEM_CLASS_SIGNATURE);
// init the aspect fields
for (int i = 0; i < aroundAdvices.length; i++) {
if (initAspectField(system, aroundAdvices[i], cw, AROUND_ADVICE_FIELD_PREFIX + i, cv, className)) {
return true;
}
}
for (int i = 0; i < beforeAdvices.length; i++) {
if (initAspectField(system, beforeAdvices[i], cw, BEFORE_ADVICE_FIELD_PREFIX + i, cv, className)) {
return true;
}
}
for (int i = 0; i < afterAdvices.length; i++) {
if (initAspectField(system, afterAdvices[i], cw, AFTER_ADVICE_FIELD_PREFIX + i, cv, className)) {
return true;
}
}
cv.visitInsn(Constants.RETURN);
cv.visitMaxs(0, 0);
return false;
}