Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] AspectJ vs PostSharp?

While learning AspectJ I am constantly comparing it against PostSharp - the
aspect framework I used in .NET. Let me give a very brief and somewhat
simplified overview of how PostSharp works (just in case). This way it would
be easier for me to ask the question.

1. .NET code is compiled as usual and produces dll or exe.
2. A dedicated PostSharp msbuild task kicks in, which reads the dll or exe
produced in (1), parses the MSIL byte code to create the byte code object
model.
3. Registered user aspects are invoked. PostSharp.Core exposes the MSIL byte
code object model through a dedicated API, which lets the aspect to
manipulate the model as it pleases (including, but not limited to, creating
new methods and filling in the method instructions). Implementing
crosscutting concerns is done by registering advices with the interesting
join points (similar to those of AspectJ).
4. Next, the PostSharp.Core engine travels the object model to create the
corresponding .il file. During the traversal it invokes the advices
registered by the aspects in (3).
5. Finally, MSIL assembler is called to compile the .il file from (4) into
the respective dll or exe.

This is roughly how the low level PostSharp.Core engine works. It is low
level, because the advice is responsible to inject the MSIL byte code,
meaning the advice author must be comfortable with the MSIL byte code
language. 

(As a side note, PostSharp comes with a higher level API, called
PostSharp.Laos, but in order to have efficient logging, I had to work at the
PostSharp.Core level)

Anyway, I am nearing the punchline of my question. The aspect code (written
in C# in my case) is invoked during the compilation of the subject project
and has a complete access to all the metadata of that project. Everything
available to the compiler is made available to the aspect code through the
PostSharp.Core API.

It so seems to me, that AspectJ compares to PostSharp.Core as the C++
compares to the assembly language. Coding in AspectJ creates a code to be
run during the compilation, but that code is specified declaratively using
special high level syntax. 

I dare to guess that under the hood, AspectJ contains a logic similar to
that of PostSharp.Core. There should be an object model describing the JVM
byte code, should it? Assuming I am right, is it possible to take advantage
of that model to extend the capabilities exposed through the current high
level declarative AspectJ language? Like having a door into the low level
AspectJ API, much like PostSharp.Core does.

--
View this message in context: http://aspectj.2085585.n4.nabble.com/AspectJ-vs-PostSharp-tp4196604p4196604.html
Sent from the AspectJ - users mailing list archive at Nabble.com.


Back to the top