You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-dev@jakarta.apache.org by Richard Davies <ri...@optevo.com> on 2002/01/19 19:56:32 UTC

Feedback requested: Aspect API for BCEL

  Hi all,
Just before I spent more time on coding this, I wanted some feedback.
Is anyone else currently developing (or in need of) an
aspect-oriented API for BCEL?

 I need something that:
 - Weaves aspects at load time.
 - Has the functionality and feel of aspectj, but implemented as an API. 
(i.e. no compiler)
 - Has designators for control flow logic (which aspectj doesn't yet)
 - Enables me to view where join points are set, (even if they are never 
called!)
 - Does not require any configuration files
 - Is easy to use and set up.
 - Is easy to modify (e.g add new designators)
 - Is well documented (both API and examples)
 - Integrates well with the exisiting BCEL API.
 - Produces code that can be traced in a regular (JPDA) debugger.
 - Is stable :-)

I have looked at aspectJ and JMangler and JAC. I'd really like something 
that
has all of the best features of all of these factored out (with a couple 
of little
things that I specifically need added :-) and made into a simple API.

I already have a design mapped out of how I would like to implement this API
and should have some working code shortly. This is a short code sample that
I am using to give you a feel for what I am doing (terminology has been
borrowed from aspectj):

    public static void main(String[] args) {
       
        //Define the Pointcut: A Pointcut defines zero or more
        //locations in a program, knows as Join Points. This pointcut
        //says that all method calls are Join Points.
        Pointcut pointcut = new Pointcut() {public boolean match(){
            return call("* *(..)");
        }};


        //Define the Advice: The Advice is the code that runs at
        //a Join Point (defined by a Pointcut). As this is
        //Before Advice, the code will be executed just before the
        //Join Point is reached.
        Before before = new Before() {public void advice(){
            System.err.println("Entering " +  getMethod().getName());   
        }};
       
        //Create an Aspect: An aspect is a combination of a Poincut
        //and an Advice. Together, they indicate zero or more
        //points (specified by the Pointcut) in a program where code
        //(written in the Advice) should be inserted or replaced.
        Aspect aspect = new Aspect(before, pointcut);
       
        //Create a ClassSet: A ClassSet is group of classes that
        //can be filtered and iterated over. The ClassPath
        //is an implementation of a ClassSet.
        ClassSet classSet = new ClassPath();
       
        //Filter the ClassSet: Choose a subset of classes to be
        //modified.
        classSet.filter("org.apache.bcel.*");
       
        //Weave the Aspect: Modify the classes in the ClassSet so
        //that the Aspect is applied to them.
        JoinPoint[] joinPoints = aspect.weave(classSet);
       
        //Let's have a look at where all the method calls are:
        for (int i = 0; i < joinPoints.length; i++) {
            System.err.println(joinPoints[i]);
        }
       
        //Initialise the class loader with the ClassSet containing
        //the woven classes and off we go!
        ClassLoader cl = new ClassLoader(classSet);
    }

If nobody is already doing this would you be interested in integrating
my code into the BCEL source tree? I would prefer this API to be
incorporated into BCEL rather than integrated with another project
(or as a standalone project) because:
1. BCEL seems to be the most popular/easy to use bytecode manipulation 
library.
2. It would open up BCEL to a wider audience. Some people are hesitant to
use a library like BCEL because it requires an understanding of the JVM and
bytecode. An aspect API gives people a higher level way of modifying 
bytecode
that does not require as much background knowledge.
3. Even if you do know bytecode and the BCEL API, sometimes some things
would just be easier with a higher level API :-) (Especially because you 
could
trace through your Advice code with a regular debugger!)
4. Having aspects in BCEL would enable developers to mix and match between
a very low level (bytecode mainpulation), low-level (instruction factories)
and mid-level (aspect API) libraries as needed. These APIs can interface
to each other in intelligent ways e.g. Pointcuts could be used to locate
InstructionHandles, thus enabling bytecode to be modified with a lower lovel
API rather than by adding Advice.
5. There are a number of projects that are already or will be doing 
bytecode-
mangling style AOP in the future. It would make sense for these projects to
build upon a common API.
6. When aspectj (the most popular AOP tool) decides to implement load
time aspects, an API that is already in line with aspectj syntax would make
their job easier. While I could submit this code to the aspectj project,
I feel it belongs more with this project as it is more general-purpose and
for other reasons already metioned (such as the end of point 4).
7. People with skills in aspectj would find working with BCEL aspects very
easy to pick up because the terminology and concepts are the same. In
addition, they could hack bytecode at a lower level when needed.
8. It would open AOP to a wider audience.

To sum up, I feel that adding AOP to BCEL could provide a bridge between
AOP and low-level bytecode that would be of benefit to people who find
themselves primarily doing one of these things but need to switch to the 
other
from time to time.

Cheers,
Richard Davies




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by Richard Davies <ri...@optevo.com>.
David Dixon-Peugh wrote:

>
>
> Richard Davies wrote:
>
>> David Dixon-Peugh wrote:
>>
>>> I think an Aspect API for BCEL is a wonderful idea.
>>
>>
>>
>>>
>>>
>>> I'm not sure exactly what is out there for Aspects
>>> in the line you are looking for, but if you need
>>> a good starting point, I've got some code that
>>> provides a good middle ground.
>>>
>>> If you look at Quilt.  (http://sourceforge.net/projects/quilt)
>>> Under the "junit.quilt.cover.generic" package, you can find
>>> code which builds a ControlFlowGraph (using the Jakarta-Graph
>>> package in the Commons Sandbox.)
>>>
>>> Real-soon-now, I hope to have this graph set up so you can
>>> instrument it as you see fit, and generate code straight
>>> off of the graph. 
>>
>>
>>
>> That's cool! One of the things I was thinking of was using BCEL
>> (and AOP API) to scan through the code and find all of the
>> public void test*() methods. Then it would run them automatically.
>> I was looking for something that did test coverage because with
>> that feature plus the above idea, you can do away with test suites.
>> Each time the project is to be tested, simple detect which
>> methods have been modified and then rerun all tests that have
>> these in their flow graph.
>>
>> Is there anything like this around? I'd like to elaborate on that idea
>> (and explain it better/in more detail) but I'm too tired :-)
>>
>> Bye,
>> Richard
>>
>>
>
>
> Actually, I've had something like that in mind for the past couple of
> months.  (Only it would run with JUnit, so the tests don't have to
> be in the code.)

The kind of thing I was thinking of would work with JUnit too:
It's simple to scan through a classpath and check which classes
are JUnit test cases. However, it could be configured to work with
any testing framework: it would simply need a set of rules so it knows
how to identify which classes are test cases, which are test methods,
and which methods do test setup and tear down. These could
be configured externally (and default to JUnit standards).

>
>
> I'm thinking it actually would help a lot in Massive Build systems like
> Gump.  (Or Dante, if I get to build it.)
>
> For example:
>
> Xalan depends on BCEL.
>
> Say that BCEL has a couple of changes in CVS.  Gump currently will
> checkout everything at the end of the day, and try to compile.

It would be nice to do this with CruiseControl perhaps so builds are
done every few minutes or so. This is especially
nice for the Massive Build systems you mention because there would
be (or at least should be) a large number of tests that may need to be
run at each build. Performing test coverage at each build enables you
to calculate a delta which should keep the number of tests run at each
build very small (as well as feeing the devloper of the burden of choosing
which test suite to run).

>
>
> This will definitely kick back any compilation level integration
> issues.
>
> However, what if the behavior of BCEL changes and breaks Xalan?
>
> The Massive Build System, should be able to identify tests in the
> past which exercised the code.  So, not only do the BCEL tests get
> run again, but Xalan tests which depend on the changed BCEL code
> goes as well.

Definitely - provided the Xalan tests were instrumented in the same way
as the BCEL tests, they should also have detected a depedancy on the
changed code.

>
>
> Since the Build System knows that BCEL has changed, it can then
> send the email about the integration failure to both Xalan and
> BCEL.  (I believe right now, it will send it to Xalan, who would
> sit there and scratch their heads as to what is going on. . .)

Hehe - but at least they would know there is a test failure and 
presumably it
would report which tests failed.

Other features that would be testing nice-to-haves:
When there is a test failure, have the state of each object in the stack 
trace
stored. This would mean that each class would have to be instrumented
with an exception handler (that doesn't interfere with any existing 
exception
handlers) that gathers all the fields and arguments and in scope local 
variables
at each point in the stack trace and logs them. One way of capturing 
this state
easily (at least field state) would be to use JSX (sorry - no url but 
search google
for "JSX Java Monash" and you'll find it).
Doing the instrumentation might be a bit fiddly (less so with an Aspect 
API for
BCEL though ;->) but should not cause any performance hit which is cool.

Yet another thing I'd like to try with BCEL or aspects is to do runtime 
analysis of
invariants (like the Daikon tool). A list of invariants and pre and post 
conditions
could be built up during the tests. These invariants could then be generated
as source code files that use the BCEL-Aspect API to enforce the variant
at (produciton) runtime - I figure this would be nicer than directly 
generating bytecode
because the DBC constraints would be human readable. Then, when the code 
is run
(or functional testing is performed), any failure of these "automatic" 
DBC constraints
would indicate a hole in the test suite - i.e. the test suite is 
assuming certain constraints
that are not being adhered to. In this case, either the code should be 
fixed, or the
tests broadened. Of course, none of this should preclude the ability to 
"manually" set
DBC constraints and have those distinguishable from the automatically 
generated ones.

Combining these ideas (test coverage/delta testing + continuous 
integration + state logging +
automatic dbc) could make a nice build process.

What do you think?

Cheers,
Richard.

>
>
> DDP
>
>
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>






--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by David Dixon-Peugh <dp...@mindspring.com>.

Richard Davies wrote:

> David Dixon-Peugh wrote:
> 
>> I think an Aspect API for BCEL is a wonderful idea.
> 
> 
>>
>>
>> I'm not sure exactly what is out there for Aspects
>> in the line you are looking for, but if you need
>> a good starting point, I've got some code that
>> provides a good middle ground.
>>
>> If you look at Quilt.  (http://sourceforge.net/projects/quilt)
>> Under the "junit.quilt.cover.generic" package, you can find
>> code which builds a ControlFlowGraph (using the Jakarta-Graph
>> package in the Commons Sandbox.)
>>
>> Real-soon-now, I hope to have this graph set up so you can
>> instrument it as you see fit, and generate code straight
>> off of the graph. 
> 
> 
> That's cool! One of the things I was thinking of was using BCEL
> (and AOP API) to scan through the code and find all of the
> public void test*() methods. Then it would run them automatically.
> I was looking for something that did test coverage because with
> that feature plus the above idea, you can do away with test suites.
> Each time the project is to be tested, simple detect which
> methods have been modified and then rerun all tests that have
> these in their flow graph.
> 
> Is there anything like this around? I'd like to elaborate on that idea
> (and explain it better/in more detail) but I'm too tired :-)
> 
> Bye,
> Richard
> 
> 


Actually, I've had something like that in mind for the past couple of
months.  (Only it would run with JUnit, so the tests don't have to
be in the code.)

I'm thinking it actually would help a lot in Massive Build systems like
Gump.  (Or Dante, if I get to build it.)

For example:

Xalan depends on BCEL.

Say that BCEL has a couple of changes in CVS.  Gump currently will
checkout everything at the end of the day, and try to compile.

This will definitely kick back any compilation level integration
issues.

However, what if the behavior of BCEL changes and breaks Xalan?

The Massive Build System, should be able to identify tests in the
past which exercised the code.  So, not only do the BCEL tests get
run again, but Xalan tests which depend on the changed BCEL code
goes as well.

Since the Build System knows that BCEL has changed, it can then
send the email about the integration failure to both Xalan and
BCEL.  (I believe right now, it will send it to Xalan, who would
sit there and scratch their heads as to what is going on. . .)

DDP




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by Richard Davies <ri...@optevo.com>.
David Dixon-Peugh wrote:

> I think an Aspect API for BCEL is a wonderful idea.

>
>
> I'm not sure exactly what is out there for Aspects
> in the line you are looking for, but if you need
> a good starting point, I've got some code that
> provides a good middle ground.
>
> If you look at Quilt.  (http://sourceforge.net/projects/quilt)
> Under the "junit.quilt.cover.generic" package, you can find
> code which builds a ControlFlowGraph (using the Jakarta-Graph
> package in the Commons Sandbox.)
>
> Real-soon-now, I hope to have this graph set up so you can
> instrument it as you see fit, and generate code straight
> off of the graph. 

That's cool! One of the things I was thinking of was using BCEL
(and AOP API) to scan through the code and find all of the
public void test*() methods. Then it would run them automatically.
I was looking for something that did test coverage because with
that feature plus the above idea, you can do away with test suites.
Each time the project is to be tested, simple detect which
methods have been modified and then rerun all tests that have
these in their flow graph.

Is there anything like this around? I'd like to elaborate on that idea
(and explain it better/in more detail) but I'm too tired :-)

Bye,
Richard

>
>
> It will solve questions like:
> *  How can I make a Method Exit pointcut?
> *  How can I make an Exception thrown pointcut, when the
>    Exception is never caught?
>
> However, as for being able to step through the generated
> code in a debugger, I don't know how well that could work.

See my reply to Jason for my strategy here.

>
>
> Basically, a ClassFile is associated with one source file.
> Since the Aspect which is added is in a different source
> file, it will be difficult to reconcile them.
>
> Actually, take that back.  If you only weaved calls to the
> Aspect in, and not actual bytecode, then you may be able
> to trace it in a debugger.
>
> Let me know if you need any help.  I'll gladly do what I
> can. 

Cheers, thanks very much.

>
>
> DDP
>
>
> Richard Davies wrote:
>
>>  Hi all,
>> Just before I spent more time on coding this, I wanted some feedback.
>> Is anyone else currently developing (or in need of) an
>> aspect-oriented API for BCEL?
>>
>> I need something that:
>> - Weaves aspects at load time.
>> - Has the functionality and feel of aspectj, but implemented as an 
>> API. (i.e. no compiler)
>> - Has designators for control flow logic (which aspectj doesn't yet)
>> - Enables me to view where join points are set, (even if they are 
>> never called!)
>> - Does not require any configuration files
>> - Is easy to use and set up.
>> - Is easy to modify (e.g add new designators)
>> - Is well documented (both API and examples)
>> - Integrates well with the exisiting BCEL API.
>> - Produces code that can be traced in a regular (JPDA) debugger.
>> - Is stable :-)
>>
>> I have looked at aspectJ and JMangler and JAC. I'd really like 
>> something that
>> has all of the best features of all of these factored out (with a 
>> couple of little
>> things that I specifically need added :-) and made into a simple API.
>>
>> I already have a design mapped out of how I would like to implement 
>> this API
>> and should have some working code shortly. This is a short code 
>> sample that
>> I am using to give you a feel for what I am doing (terminology has been
>> borrowed from aspectj):
>>
>>    public static void main(String[] args) {
>>              //Define the Pointcut: A Pointcut defines zero or more
>>        //locations in a program, knows as Join Points. This pointcut
>>        //says that all method calls are Join Points.
>>        Pointcut pointcut = new Pointcut() {public boolean match(){
>>            return call("* *(..)");
>>        }};
>>
>>
>>        //Define the Advice: The Advice is the code that runs at
>>        //a Join Point (defined by a Pointcut). As this is
>>        //Before Advice, the code will be executed just before the
>>        //Join Point is reached.
>>        Before before = new Before() {public void advice(){
>>            System.err.println("Entering " +  
>> getMethod().getName());          }};
>>              //Create an Aspect: An aspect is a combination of a Poincut
>>        //and an Advice. Together, they indicate zero or more
>>        //points (specified by the Pointcut) in a program where code
>>        //(written in the Advice) should be inserted or replaced.
>>        Aspect aspect = new Aspect(before, pointcut);
>>              //Create a ClassSet: A ClassSet is group of classes that
>>        //can be filtered and iterated over. The ClassPath
>>        //is an implementation of a ClassSet.
>>        ClassSet classSet = new ClassPath();
>>              //Filter the ClassSet: Choose a subset of classes to be
>>        //modified.
>>        classSet.filter("org.apache.bcel.*");
>>              //Weave the Aspect: Modify the classes in the ClassSet so
>>        //that the Aspect is applied to them.
>>        JoinPoint[] joinPoints = aspect.weave(classSet);
>>              //Let's have a look at where all the method calls are:
>>        for (int i = 0; i < joinPoints.length; i++) {
>>            System.err.println(joinPoints[i]);
>>        }
>>              //Initialise the class loader with the ClassSet containing
>>        //the woven classes and off we go!
>>        ClassLoader cl = new ClassLoader(classSet);
>>    }
>>
>> If nobody is already doing this would you be interested in integrating
>> my code into the BCEL source tree? I would prefer this API to be
>> incorporated into BCEL rather than integrated with another project
>> (or as a standalone project) because:
>> 1. BCEL seems to be the most popular/easy to use bytecode 
>> manipulation library.
>> 2. It would open up BCEL to a wider audience. Some people are 
>> hesitant to
>> use a library like BCEL because it requires an understanding of the 
>> JVM and
>> bytecode. An aspect API gives people a higher level way of modifying 
>> bytecode
>> that does not require as much background knowledge.
>> 3. Even if you do know bytecode and the BCEL API, sometimes some things
>> would just be easier with a higher level API :-) (Especially because 
>> you could
>> trace through your Advice code with a regular debugger!)
>> 4. Having aspects in BCEL would enable developers to mix and match 
>> between
>> a very low level (bytecode mainpulation), low-level (instruction 
>> factories)
>> and mid-level (aspect API) libraries as needed. These APIs can interface
>> to each other in intelligent ways e.g. Pointcuts could be used to locate
>> InstructionHandles, thus enabling bytecode to be modified with a 
>> lower lovel
>> API rather than by adding Advice.
>> 5. There are a number of projects that are already or will be doing 
>> bytecode-
>> mangling style AOP in the future. It would make sense for these 
>> projects to
>> build upon a common API.
>> 6. When aspectj (the most popular AOP tool) decides to implement load
>> time aspects, an API that is already in line with aspectj syntax 
>> would make
>> their job easier. While I could submit this code to the aspectj project,
>> I feel it belongs more with this project as it is more 
>> general-purpose and
>> for other reasons already metioned (such as the end of point 4).
>> 7. People with skills in aspectj would find working with BCEL aspects 
>> very
>> easy to pick up because the terminology and concepts are the same. In
>> addition, they could hack bytecode at a lower level when needed.
>> 8. It would open AOP to a wider audience.
>>
>> To sum up, I feel that adding AOP to BCEL could provide a bridge between
>> AOP and low-level bytecode that would be of benefit to people who find
>> themselves primarily doing one of these things but need to switch to 
>> the other
>> from time to time.
>>
>> Cheers,
>> Richard Davies
>>
>>
>>
>>
>> -- 
>> To unsubscribe, e-mail:   
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail: 
>> <ma...@jakarta.apache.org>
>>
>>
>
>
>
> -- 
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>
>





--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by David Dixon-Peugh <dp...@mindspring.com>.
I think an Aspect API for BCEL is a wonderful idea.

I'm not sure exactly what is out there for Aspects
in the line you are looking for, but if you need
a good starting point, I've got some code that
provides a good middle ground.

If you look at Quilt.  (http://sourceforge.net/projects/quilt)
Under the "junit.quilt.cover.generic" package, you can find
code which builds a ControlFlowGraph (using the Jakarta-Graph
package in the Commons Sandbox.)

Real-soon-now, I hope to have this graph set up so you can
instrument it as you see fit, and generate code straight
off of the graph.

It will solve questions like:
*  How can I make a Method Exit pointcut?
*  How can I make an Exception thrown pointcut, when the
    Exception is never caught?

However, as for being able to step through the generated
code in a debugger, I don't know how well that could work.

Basically, a ClassFile is associated with one source file.
Since the Aspect which is added is in a different source
file, it will be difficult to reconcile them.

Actually, take that back.  If you only weaved calls to the
Aspect in, and not actual bytecode, then you may be able
to trace it in a debugger.

Let me know if you need any help.  I'll gladly do what I
can.

DDP


Richard Davies wrote:

>  Hi all,
> Just before I spent more time on coding this, I wanted some feedback.
> Is anyone else currently developing (or in need of) an
> aspect-oriented API for BCEL?
> 
> I need something that:
> - Weaves aspects at load time.
> - Has the functionality and feel of aspectj, but implemented as an API. 
> (i.e. no compiler)
> - Has designators for control flow logic (which aspectj doesn't yet)
> - Enables me to view where join points are set, (even if they are never 
> called!)
> - Does not require any configuration files
> - Is easy to use and set up.
> - Is easy to modify (e.g add new designators)
> - Is well documented (both API and examples)
> - Integrates well with the exisiting BCEL API.
> - Produces code that can be traced in a regular (JPDA) debugger.
> - Is stable :-)
> 
> I have looked at aspectJ and JMangler and JAC. I'd really like something 
> that
> has all of the best features of all of these factored out (with a couple 
> of little
> things that I specifically need added :-) and made into a simple API.
> 
> I already have a design mapped out of how I would like to implement this 
> API
> and should have some working code shortly. This is a short code sample that
> I am using to give you a feel for what I am doing (terminology has been
> borrowed from aspectj):
> 
>    public static void main(String[] args) {
>              //Define the Pointcut: A Pointcut defines zero or more
>        //locations in a program, knows as Join Points. This pointcut
>        //says that all method calls are Join Points.
>        Pointcut pointcut = new Pointcut() {public boolean match(){
>            return call("* *(..)");
>        }};
> 
> 
>        //Define the Advice: The Advice is the code that runs at
>        //a Join Point (defined by a Pointcut). As this is
>        //Before Advice, the code will be executed just before the
>        //Join Point is reached.
>        Before before = new Before() {public void advice(){
>            System.err.println("Entering " +  getMethod().getName());   
>        }};
>              //Create an Aspect: An aspect is a combination of a Poincut
>        //and an Advice. Together, they indicate zero or more
>        //points (specified by the Pointcut) in a program where code
>        //(written in the Advice) should be inserted or replaced.
>        Aspect aspect = new Aspect(before, pointcut);
>              //Create a ClassSet: A ClassSet is group of classes that
>        //can be filtered and iterated over. The ClassPath
>        //is an implementation of a ClassSet.
>        ClassSet classSet = new ClassPath();
>              //Filter the ClassSet: Choose a subset of classes to be
>        //modified.
>        classSet.filter("org.apache.bcel.*");
>              //Weave the Aspect: Modify the classes in the ClassSet so
>        //that the Aspect is applied to them.
>        JoinPoint[] joinPoints = aspect.weave(classSet);
>              //Let's have a look at where all the method calls are:
>        for (int i = 0; i < joinPoints.length; i++) {
>            System.err.println(joinPoints[i]);
>        }
>              //Initialise the class loader with the ClassSet containing
>        //the woven classes and off we go!
>        ClassLoader cl = new ClassLoader(classSet);
>    }
> 
> If nobody is already doing this would you be interested in integrating
> my code into the BCEL source tree? I would prefer this API to be
> incorporated into BCEL rather than integrated with another project
> (or as a standalone project) because:
> 1. BCEL seems to be the most popular/easy to use bytecode manipulation 
> library.
> 2. It would open up BCEL to a wider audience. Some people are hesitant to
> use a library like BCEL because it requires an understanding of the JVM and
> bytecode. An aspect API gives people a higher level way of modifying 
> bytecode
> that does not require as much background knowledge.
> 3. Even if you do know bytecode and the BCEL API, sometimes some things
> would just be easier with a higher level API :-) (Especially because you 
> could
> trace through your Advice code with a regular debugger!)
> 4. Having aspects in BCEL would enable developers to mix and match between
> a very low level (bytecode mainpulation), low-level (instruction factories)
> and mid-level (aspect API) libraries as needed. These APIs can interface
> to each other in intelligent ways e.g. Pointcuts could be used to locate
> InstructionHandles, thus enabling bytecode to be modified with a lower 
> lovel
> API rather than by adding Advice.
> 5. There are a number of projects that are already or will be doing 
> bytecode-
> mangling style AOP in the future. It would make sense for these projects to
> build upon a common API.
> 6. When aspectj (the most popular AOP tool) decides to implement load
> time aspects, an API that is already in line with aspectj syntax would make
> their job easier. While I could submit this code to the aspectj project,
> I feel it belongs more with this project as it is more general-purpose and
> for other reasons already metioned (such as the end of point 4).
> 7. People with skills in aspectj would find working with BCEL aspects very
> easy to pick up because the terminology and concepts are the same. In
> addition, they could hack bytecode at a lower level when needed.
> 8. It would open AOP to a wider audience.
> 
> To sum up, I feel that adding AOP to BCEL could provide a bridge between
> AOP and low-level bytecode that would be of benefit to people who find
> themselves primarily doing one of these things but need to switch to the 
> other
> from time to time.
> 
> Cheers,
> Richard Davies
> 
> 
> 
> 
> -- 
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by Richard Davies <ri...@optevo.com>.
Jason van Zyl wrote:

>On 1/19/02 1:56 PM, "Richard Davies" <ri...@optevo.com> wrote:
>
>>Hi all,
>>Just before I spent more time on coding this, I wanted some feedback.
>>Is anyone else currently developing (or in need of) an
>>aspect-oriented API for BCEL?
>>
>
>Or more accurately an API that employs BCEL to provide give aspects to your
>Java programs. Below I'll just make some comparisons to aspectj as I'm just
>trying to fully understand your request.
>
>>I need something that:
>>- Weaves aspects at load time.
>>
>
>You're not satisfied with the if() pointcut designator. Compile in the
>aspects you need and use the ones you require for a particular case given a
>runtime property?
>
One of the things I'd like to do is be able to pick up all possible 
branch points in code (ifs, switches, loops)
basically anything matching n if* or ?cmp? or *switch opcode as a way of 
checking code coverage.
This isn't a big issue for me though..

>
>
>Why do you need to weave the aspects at load time?
>
The main use I have for aspects is with a system that permits evolution 
of code. New classes can be
received from anywhere on the network and dynamically loaded. I want to 
be able to load  them
without any security or liveness issues. A couple of problems I have 
where aspects can help:
Stopping denial of service attacks: I can use aspects to prevent the 
creation of new threads.
I can also use them to ensure that infinite loops can always be broken 
(or perhaps paused) by the controlling
program. creating of new threads, reflection calls.
In addition I would like to prevent any GUI related classes from being 
loaded.
Due to the nature of the system, all code is received dynamically into 
the container application
as bytecode and needs to have these restrictions placed on it before it 
is executed.

>
>
>>- Has the functionality and feel of aspectj, but implemented as an API.
>>(i.e. no compiler)
>>
>
>So you want to dynamically generate aspect-oriented code, again I'm not
>quite sure I understand why. I chatted with Jim Hugunin, the aspectj team
>member responsible for the compiler, at a recent aspectj workshop and he
>wasn't 100% satisfied with the BCEL API but he might be interested in your
>thoughts for use in ajc?
>
Perhaps, but even if he isn't, it still have value modelling the API on 
aspectj. An API that works in a way
familiar to the aspectj language would be easier to learn/use than one 
that isn't. People could use the aspectj
documentation to help them learn about the API (and vice versa)

>
>
>>- Has designators for control flow logic (which aspectj doesn't yet)
>>
>
>AspectJ has:
>
> cflow(_Pointcut_): Join points in the control flow of the join points
>specified by _Pointcut_.
>
> cflowbelow(_Pointcut_): Join points in the control flow below the join
>points specified by _Pointcut_.
>
Sorry - I was thinking more of loops specifically here again (re the 
point I made earlier about
denial of service attacks).

>
>
>>- Enables me to view where join points are set, (even if they are never
>>called!)
>>
>
>I saw some tools at the above mentioned workshop that provided a very nice
>explorer that allow you to view the relationship between the defined aspects
>the the rest of the code. I can't remember if this tool is released yet, but
>it exists and it looked good.
>
If you could remeber, I'd really like to have a look at it.

>
>
>>- Does not require any configuration files
>>
>
>>- Is easy to use and set up.
>>
>
>>- Is easy to modify (e.g add new designators)
>>
>
>I'm not so sure this is a great idea. I think the aspect team has try to
>provide the smallest number of designators combined with the smallest set of
>operators to provide the necessary flexibility.
>
Sure - I agree with that completely. I meant that design should be 
flexible so that designators can be
changed easily. I am not certain if all designators in aspectj could be 
implemented. Others may be possible
that may only be meaningful in the context of load-time weaving - 
perhaps designators that trigger
when classes are read from the classpath, weaved, loaded, reloade. Who 
knows. I'm not making
assumptions (which I guess was why I thought the designator design 
should be flexible).
On the other hand, maybe it is best leaving these features out until 
they are absolutely proven necessary.
At least if the API was incorporated with BCEL, there is always the 
possibilty of using the
current BCEL API if anything is too much for the aspect-oriented api.

>
>
>>- Is well documented (both API and examples)
>>
>
>Aspectj is getting there!
>
Agreed. In fact, I find the documentation for aspectj the best out of 
all the AOP stuff I have read.
I was commenting more on the load time tools that I have used (JAC, 
JMangler, DJ).

>
>
>>- Integrates well with the exisiting BCEL API.
>>- Produces code that can be traced in a regular (JPDA) debugger.
>>
>
>But if you're generating this dynamically and modifying source on the fly
>how will a normal debugger help? If this is strictly a bytecode API what are
>you going to be looking at? How will you relate what is in the debugger
>output to the source you modified? Again I'm not wholly clear of what your
>intent is here.
>

>
>
>>- Is stable :-)
>>
>
>AspectJ is very stable.
>
Again, this comment was not directed at AspectJ. In fact, everything 
that aspectj does, it does very
well and the team is obviously both very talented and helpful. My 
problem is that at the moment, it
simply doesn't do eveything I want/need (and neither do the other 
products I've looked at - although
in many respects, aspectj is far ahead of them). So being an impatient 
bastard, I thought I'd have a stab
at implementing it myself. ;-> Having said that, I don't want to 
duplicate what someone else is already
doing (I'm even more lazy than I am impatient ..) and I'd prefer it to 
be of use to someone else once I've
done it.

>
> 
>
>>I have looked at aspectJ and JMangler and JAC. I'd really like something
>>that
>>has all of the best features of all of these factored out (with a couple
>>of little
>>things that I specifically need added :-) and made into a simple API.
>>
>
>Have you ever considered trying to lobby the aspectj team to add these
>features that you desire? It is all under the MPL :-)
>
There have been requests for it previously and I have discussed load 
time aspects with them on a recent
thread in the mailing list.
I have but I think it would be simpler for me to implement them as a 
Java API.

>
>
>>I already have a design mapped out of how I would like to implement this API
>>and should have some working code shortly. This is a short code sample that
>>I am using to give you a feel for what I am doing (terminology has been
>>borrowed from aspectj):
>>
>
>[snip]
>
>>If nobody is already doing this would you be interested in integrating
>>my code into the BCEL source tree? I would prefer this API to be
>>incorporated into BCEL rather than integrated with another project
>>(or as a standalone project) because:
>>1. BCEL seems to be the most popular/easy to use bytecode manipulation
>>library.
>>2. It would open up BCEL to a wider audience. Some people are hesitant to
>>use a library like BCEL because it requires an understanding of the JVM and
>>bytecode. An aspect API gives people a higher level way of modifying
>>bytecode
>>that does not require as much background knowledge.
>>
>
>I am definitely in favour of a simpler API.
>
>>3. Even if you do know bytecode and the BCEL API, sometimes some things
>>would just be easier with a higher level API :-) (Especially because you
>>could
>>trace through your Advice code with a regular debugger!)
>>4. Having aspects in BCEL would enable developers to mix and match between
>>a very low level (bytecode mainpulation), low-level (instruction factories)
>>and mid-level (aspect API) libraries as needed. These APIs can interface
>>to each other in intelligent ways e.g. Pointcuts could be used to locate
>>InstructionHandles, thus enabling bytecode to be modified with a lower lovel
>>API rather than by adding Advice.
>>5. There are a number of projects that are already or will be doing
>>bytecode-
>>mangling style AOP in the future. It would make sense for these projects to
>>build upon a common API.
>>6. When aspectj (the most popular AOP tool) decides to implement load
>>time aspects, an API that is already in line with aspectj syntax would make
>>their job easier.
>>
>
>Sure, but maybe blowing these ideas by the aspectj team now might make that
>easier when they do decide to do it. Like I said I'm sure Jim Hugunin would
>be interested.
>
>>While I could submit this code to the aspectj project,
>>I feel it belongs more with this project as it is more general-purpose and
>>for other reasons already metioned (such as the end of point 4).
>>7. People with skills in aspectj would find working with BCEL aspects very
>>easy to pick up because the terminology and concepts are the same. In
>>addition, they could hack bytecode at a lower level when needed.
>>8. It would open AOP to a wider audience.
>>
>>To sum up, I feel that adding AOP to BCEL could provide a bridge between
>>AOP and low-level bytecode that would be of benefit to people who find
>>themselves primarily doing one of these things but need to switch to the
>>other
>>from time to time.
>>
>
>
>While I like the idea of trying to provide a tool that would make it easier
>for the aspectj developers to use BCEL,
>
And for BCEL users to avoid writing bytecode when they don't have to... ;->

> but I'm still honestly confused
>about whether this is strictly a bytecode API or whether you would also be
>providing a grammar in source form that would utilize your API.
>
My design for a Pointcut is like this:
Pointcut(String pattern) where "pattern" follows the same syntax as in 
aspectj. eg.
"* *(..)"
"void set*(int)"
etc...

The Pointcut class looks like:
class Pointcut {
    private JavaClass javaClass;
    private Method method;
    private Instruction instruction;
    //setter/getters etc...
}

A couple of things to note:
The Pointcut could then be used WITHOUT Advice simply as a high-powered 
filter/selector
to access bits of bytecode in aspectj. Even this alone might be a handy API.

Less importantly: The syntax of the "pattern" could be checked a 
weave-time to ensure that
it is syntactically correct. A weave could be done as a part of the 
build process, effectivly
giving you compile time checking of the pattern. Of course, the pattern 
may not be specified
as a constant so that would not be possible - but there again, 
specifying the pattern dynamically
is (yet another :-) thing you could do with an AOP API that you can't do 
with aspectj...


My design for Advice is like this:
abstract class Advice {
   public abstract void advice();
   public Object[] getArgs() {...}
   public Object getThis() {...}
   // other context methods...
}
abstract class After extends Advice {...}
abstract class Around extends Advice {...}
abstract class Before extends Advice {...}
(with a few context methods specific to the type of advice on each 
Advice subclass)

To implement your own advice, extend one of After, Before or Around and 
implement advice().
There are methods that are able to access context information like 
getThis() etc...

As for the nitty-gritty of how the advice was to be inserted, I was 
thinking along these lines:
Aspect aspect = new Aspect(advice, pointcut);
aspect.weave(classSet);
would cause all join points in the classSet to be identified.

So what actually happens at the bytecode level?

I would insert an INVOKESTATIC at each pointcut. The java code that it
is be the equivalent of is:
    Runner.runAdvice(0);
The integer parameter would be inserted as a constant at weave time. It 
serves as an index
to each Advice object. The Advice objects would have registered 
themselves when they
were created with the Runner and been assigned an index.

Eventually, runAdvice() would also need to pass context information as 
parameters too.

As the advice method is simply a regular Java method, it can be traced 
with a debugger.

Another possibility is to rip the bytecode out of advice() and insert it 
at the pointcut. I don't
think this as good an idea though.

> This is what
>I would worry about, I'm a big fan of aspectj so I'm just trying to
>encourage you to talk to them first. They definitely know more about this
>than me ;-)
>
>Nonetheless I am still very interested in your ideas I'm just thing that it
>might be wise to post this message to the aspectj list as well just to get
>some other opinions.
>
>I still have only used BCEL for about 6 months with a little toy compiler,
>Markus is the man you want to talk to. I'm merely curious and trying to
>nudge this proposal in the direction of cooperating with the aspjectj team.
>

I definitely will throw it at the aspectj guys shortly. Just wanted to 
throw it at you guys first to see if there
was any interest at your end first because it seemed to fit better (for 
the reasons above) with BCEL than
with aspectj.

Cheers,
Richard



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by Jason van Zyl <jv...@zenplex.com>.
On 1/19/02 6:53 PM, "Jason van Zyl" <jv...@zenplex.com> wrote:

> On 1/19/02 1:56 PM, "Richard Davies" <ri...@optevo.com> wrote:
> 

I just wanted to apologize for my last post, I shouldn't respond after not
sleeping for two days. I respond again after some sleep.

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Feedback requested: Aspect API for BCEL

Posted by Jason van Zyl <jv...@zenplex.com>.
On 1/19/02 1:56 PM, "Richard Davies" <ri...@optevo.com> wrote:

> Hi all,
> Just before I spent more time on coding this, I wanted some feedback.
> Is anyone else currently developing (or in need of) an
> aspect-oriented API for BCEL?

Or more accurately an API that employs BCEL to provide give aspects to your
Java programs. Below I'll just make some comparisons to aspectj as I'm just
trying to fully understand your request.

> 
> I need something that:
> - Weaves aspects at load time.

You're not satisfied with the if() pointcut designator. Compile in the
aspects you need and use the ones you require for a particular case given a
runtime property?

Why do you need to weave the aspects at load time?

> - Has the functionality and feel of aspectj, but implemented as an API.
> (i.e. no compiler)

So you want to dynamically generate aspect-oriented code, again I'm not
quite sure I understand why. I chatted with Jim Hugunin, the aspectj team
member responsible for the compiler, at a recent aspectj workshop and he
wasn't 100% satisfied with the BCEL API but he might be interested in your
thoughts for use in ajc?

> - Has designators for control flow logic (which aspectj doesn't yet)

AspectJ has:

 cflow(_Pointcut_): Join points in the control flow of the join points
specified by _Pointcut_.

 cflowbelow(_Pointcut_): Join points in the control flow below the join
points specified by _Pointcut_.

> - Enables me to view where join points are set, (even if they are never
> called!)

I saw some tools at the above mentioned workshop that provided a very nice
explorer that allow you to view the relationship between the defined aspects
the the rest of the code. I can't remember if this tool is released yet, but
it exists and it looked good.

> - Does not require any configuration files

> - Is easy to use and set up.

> - Is easy to modify (e.g add new designators)

I'm not so sure this is a great idea. I think the aspect team has try to
provide the smallest number of designators combined with the smallest set of
operators to provide the necessary flexibility.

> - Is well documented (both API and examples)

Aspectj is getting there!

> - Integrates well with the exisiting BCEL API.
> - Produces code that can be traced in a regular (JPDA) debugger.

But if you're generating this dynamically and modifying source on the fly
how will a normal debugger help? If this is strictly a bytecode API what are
you going to be looking at? How will you relate what is in the debugger
output to the source you modified? Again I'm not wholly clear of what your
intent is here.

> - Is stable :-)

AspectJ is very stable.
 
> I have looked at aspectJ and JMangler and JAC. I'd really like something
> that
> has all of the best features of all of these factored out (with a couple
> of little
> things that I specifically need added :-) and made into a simple API.

Have you ever considered trying to lobby the aspectj team to add these
features that you desire? It is all under the MPL :-)

> I already have a design mapped out of how I would like to implement this API
> and should have some working code shortly. This is a short code sample that
> I am using to give you a feel for what I am doing (terminology has been
> borrowed from aspectj):

[snip]

> 
> If nobody is already doing this would you be interested in integrating
> my code into the BCEL source tree? I would prefer this API to be
> incorporated into BCEL rather than integrated with another project
> (or as a standalone project) because:
> 1. BCEL seems to be the most popular/easy to use bytecode manipulation
> library.
> 2. It would open up BCEL to a wider audience. Some people are hesitant to
> use a library like BCEL because it requires an understanding of the JVM and
> bytecode. An aspect API gives people a higher level way of modifying
> bytecode
> that does not require as much background knowledge.

I am definitely in favour of a simpler API.

> 3. Even if you do know bytecode and the BCEL API, sometimes some things
> would just be easier with a higher level API :-) (Especially because you
> could
> trace through your Advice code with a regular debugger!)
> 4. Having aspects in BCEL would enable developers to mix and match between
> a very low level (bytecode mainpulation), low-level (instruction factories)
> and mid-level (aspect API) libraries as needed. These APIs can interface
> to each other in intelligent ways e.g. Pointcuts could be used to locate
> InstructionHandles, thus enabling bytecode to be modified with a lower lovel
> API rather than by adding Advice.
> 5. There are a number of projects that are already or will be doing
> bytecode-
> mangling style AOP in the future. It would make sense for these projects to
> build upon a common API.
> 6. When aspectj (the most popular AOP tool) decides to implement load
> time aspects, an API that is already in line with aspectj syntax would make
> their job easier.

Sure, but maybe blowing these ideas by the aspectj team now might make that
easier when they do decide to do it. Like I said I'm sure Jim Hugunin would
be interested.

> While I could submit this code to the aspectj project,
> I feel it belongs more with this project as it is more general-purpose and
> for other reasons already metioned (such as the end of point 4).
> 7. People with skills in aspectj would find working with BCEL aspects very
> easy to pick up because the terminology and concepts are the same. In
> addition, they could hack bytecode at a lower level when needed.
> 8. It would open AOP to a wider audience.
> 
> To sum up, I feel that adding AOP to BCEL could provide a bridge between
> AOP and low-level bytecode that would be of benefit to people who find
> themselves primarily doing one of these things but need to switch to the
> other
> from time to time.


While I like the idea of trying to provide a tool that would make it easier
for the aspectj developers to use BCEL, but I'm still honestly confused
about whether this is strictly a bytecode API or whether you would also be
providing a grammar in source form that would utilize your API. This is what
I would worry about, I'm a big fan of aspectj so I'm just trying to
encourage you to talk to them first. They definitely know more about this
than me ;-)

Nonetheless I am still very interested in your ideas I'm just thing that it
might be wise to post this message to the aspectj list as well just to get
some other opinions.

I still have only used BCEL for about 6 months with a little toy compiler,
Markus is the man you want to talk to. I'm merely curious and trying to
nudge this proposal in the direction of cooperating with the aspjectj team.

> Cheers,
> Richard Davies
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

-- 

jvz.

Jason van Zyl

http://tambora.zenplex.org
http://jakarta.apache.org/turbine
http://jakarta.apache.org/velocity
http://jakarta.apache.org/alexandria
http://jakarta.apache.org/commons



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>