Tuesday, April 13, 2004

Re: AOP (again)

i had posted some stuff on AOP but got no response. so i thought of posting a blog on the topic.

Yeah sorry about that. I went through the article link you posted before briefly, but didn't really understand it much.

I was sort of confused because what they mention was exactly what attributes are all about - injection of code at runtime, without messing with source code. Keeping a clean separation. So I was wondering what the difference was. Have you figured it out?

aspectj can work on class files. no need for java files. same for javaassist. they make use of reflection to analyse a class and then inject aop code. now i am not sure how this works but i'll go on with what i have understood so far.

Hmm... I dunno how this would work. The class files, just like .NET assemblies, already have bytecode/IL in it. The JIT just converts that to native code. So how and in what form can you add to class files? I would assume that the runtime (JVM/CLR) is the only thing that can inject code. How and when does aspectJ get called?

do attributes in .net (metadata in java) perform the same operation. only that the vm must be knowing the meanings of these attributes compared to the aop compiler incase of aop

Exactly. The VM has to know what to do. Dunno how aspectJ connects at runtime. I dunno of anything related to AOP in .NET... just attributes (if there is a relation).

also does the @Remote attribute in .net, cause an attribute to be included into the code, or does it cause the equivalent IL to be include. simply put, are attributes compile time or runtime. why i am asking is incase there is a custom attribute and the vm does not (by a miracle) get the implementation, does it ignore it. this would be a major runtime problem. also if at runtime wouldn't this slow the VM? somehow i feel the vm does these things, but how without sucking in performance?

I understood attributes to be a way of insterting some extra metadata. In some cases, where the CLR understands those attributes, it acts like a flag. If it sees the flag to be on, it will inject code. Attributes are compile time... but all code is compiled at runtime (JIT compiled) - just more code in injected. I suppose you will have performance degradation, but you can getting so much functionality for free. Plus, when you talk managed code, performance is not the most important concern. In .NET, as I've mentioned before, there is an attribute called "WebMethod" which makes a method a WebService. Imagine the amount of "infrastructure" code that needs to be generated to make it work with SOAP etc...

The custom attributes is just for your own use. You can query that at runtime. You could potentially create another app, which loads up an assembly (class) and reads your custom metadata and does something with it. But the injecting of code (stuff that apparently aspectJ does), that I don't understand. How do they "hook" into the runtime.

which brings me to a second question. what do you think of intellectual property in java/c#. it is very easy to reverse engineer code. if not, simply aop some part. some applns like bcel and javaassist allow to modify bytecode and save the class file or modify the class file at runtime and use it dynamically.

Being a Linux guy, I'm surprised you asked this question ;-) I don' t think it's a huge deal. It is pretty easy to reverse engineer just cause IL is a pretty high level language. But there are code obfuscators out there that will render the code almost unreadable.

Using AOP to modify class files - that's something I'm still a bit skeptical of. I can't understand how they would achieve that. I guess as we get more info on this subject, things will become clearer.

No comments: