kalyan ram | 2 Jul 2003 23:46
Picon
Favicon

class loading and dynamic instrumentation

Hai
      I have implemented a class loader(not the one
provided with bcel) but in the java programming
language.I am using BCEL api to dynamically intercept
the loading process of class files and put in extra
instrumentation bytecodes.
1.Get the class file
2.Invoke bcel program which does instrumentation
3.turn them into bytes
4.call defineclass.

In the loadclass() function:

    JavaClass jclazz = new
ClassParser(classFilename).parse();

    InstrumentWithBcel insbcel = new
InstrumentWithBcel();		
	insbcel.instrumentClass(jclazz);
       byte raw[] = jclazz.getBytes();
    clas =
defineClass(jclazz.getClassName(),raw,0,raw.length);	

  Is this right way?In the instrumentation,the
bytecode injected is a static method call like
Instrument.invoke();

There are two problems:
1) the program is invoked as:
   java myloader HelloWorld and nothing is getting
(Continue reading)

Shah, Sapan | 8 Jul 2003 08:20

EJB??


is it possible to create EJBs and referencing the same using BCEL?

Thanks and Regards,

Sapan.

Rob Gonzalez | 10 Jul 2003 17:06
Picon

JasminVisitor?

Hi everyone,

I previously used BCEL 4.1 which contained JasminVisitor.  I recently
switched to 5.1, which doesn't seem to have it.  According to the
following thread:

http://www.mail-archive.com/bcel-user%40jakarta.apache.org/msg00089.html

It should be located in the "examples" directory in the source
distribution.  I have downloaded the source distribution
(bcel-5.1-src.tar.gz) and it does not contains examples, nor does it
contain the file "manifest.txt" which ant complains about during build.  
I actually had to "touch manifext.txt" and "mkdir examples" in order for
the build to be successful.

I have copied the JasminVisitor.java from 4.1 and ported it to 5.1 (only
had to change package names) so I have that, but I'm concerned that I may
be using the incorrect source distribution, as it is missing both
"examples" and "manifest.txt".

Thanks,
Rob
Naveen Kuppili | 16 Jul 2003 07:39

Class instrumentation..

Hi,

I have a general question regarding byte code manipulation. I hope
someone can shed some light on this. If I use byte code manipulation to
instrument a class.. would I be violating Wily Tech's patent?

Wily Tech (the makers of Introscope) has a patent (Patent number
6,260,187) which seems to cover pretty much the entire scope of byte
code engineering. Does byte code engineering violate this patent? 

Thanks,
Naveen
Thomas Whitmore | 25 Jul 2003 06:50
Picon

Generating 'control structures' eg if/ then/ else

Hello people,

Using BCEL and interested to get some deeper info/ assistance with generation of method code,
specifically conditional control structures.

What patterns and techniques are people using to generate these, in the simplest and most understandable
way? I'd be interested as to examples and patterns of usage, especially those which are clean and require
no workarounds.

My current approach is to build the structure in essentially backwards; generate 'else' and 'after' code
first so as to get handles to these; insert the 'then' section which must reference 'after'; and finally
insert the conditional which must reference 'else'.

I'm also using separate InstructionLists to build fragments and later combining these into the method
body. Can I use InstructionHandles which reference between lists, at this interim build stage?

---

What I'd *really* like to be doing is building structure in-order; and either inserting instructions into
structural containers, or fixing up forward references as I reach that point. However the API and code do
not look necessarily reliable for creation of branch instruction with null handles.

One thing that springs to mind, if anyone is familiar with graphics APIs, is the distinction between
coordinate lines and the pixels in-between them. A similar dichotomy applies between Instructions and Handles.

If I was talking about an ideal approach for structural generation I'd either be looking for structural
containers which could exist stably while empty, and be later inserted into; or Insertion Point handles
which existed *between* instructions and of which multiple could exist in stable order without having
any actual Instructions separating them.

(Continue reading)

Steve Jones | 25 Jul 2003 10:49
Picon
Picon
Favicon

Re: Generating 'control structures' eg if/ then/ else

Hi,

I generate code using a single instruction list for the method. The generated 
code structure follows the norms outlined in just about any book on compiler 
design.

The "trick" with BCEL is to define branch labels. These are inserted as NOP's 
in the methods instruction list. Branch instructions that you emit have the 
NOP associated with a branch label as the target.

Having generated the method code you then call the removeNOPs() method that 
BCEL provides. This removes all the branch label NOP's and fixes up the 
branches to reference the next instruction after the NOP.

My BCEL code generator uses a visitor pattern to traverse an AST generated by 
my compiler front end. 

I was very tempted to get each method in the visitor to create an instruction 
list for it's own code and to return that to it's parent method. The parent 
would then insert the childs code at the appropriate place in it's 
instruction list. I think this would give a very neat solution. 

At the time I was concerned about the robustness of BCEL. I felt it may have 
short comings and so went for the most conservative solution. 

Now that I'm familiar with BCEL I would use the nested list approach without 
any hesitation.

Cheers Steve,
(Continue reading)

Gary | 28 Jul 2003 22:49
Picon
Favicon

Dynamic Creation of Value Object

Let's say I have the following:

interface IOrder - an order interface
  - getOrderID()
  - setOrderID(String orderID)

interface IBusinessObject - a business object plus
persistence interface
  - insert()
  - update()
  - delete()

class OrderBO implements IOrder, IBusinessObject

What I would like to do is avoid having to code up a
new class for OrderVO (order value object) that
implements just IOrder, providing just getters and
setters (no persistence).

Does someone have code that I could use to do this in
BCEL?  Basically, create a class that implements
IOrder and populate it with the data from a
fully-formed OrderBO?

Thanks, Gary

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
(Continue reading)

Juozas Baliuka | 29 Jul 2003 07:03
Picon

Re: Dynamic Creation of Value Object

Hi,
You can use java.lang.reflect.Proxy (since jdk 1.3) to implement this.
There are a few open source frameworks for this use case too.
 XORM, Voruta uses dynamic code generation for data access and it must be
possible to find more frameworks on SF.
----- Original Message -----
From: "Gary" <glms <at> yahoo.com>
To: <bcel-user <at> jakarta.apache.org>
Sent: Monday, July 28, 2003 10:49 PM
Subject: Dynamic Creation of Value Object

> Let's say I have the following:
>
> interface IOrder - an order interface
>   - getOrderID()
>   - setOrderID(String orderID)
>
> interface IBusinessObject - a business object plus
> persistence interface
>   - insert()
>   - update()
>   - delete()
>
> class OrderBO implements IOrder, IBusinessObject
>
> What I would like to do is avoid having to code up a
> new class for OrderVO (order value object) that
> implements just IOrder, providing just getters and
> setters (no persistence).
>
(Continue reading)

Gary | 29 Jul 2003 16:36
Picon
Favicon

Re: Dynamic Creation of Value Object

I'd rather not use the Proxy support, as it would end
up dragging all sorts of additional classes down to my
client.  I want to just send a pure data transfer
object that has the same interface as the full
business object.

Any ideas/sample code on how I could do this with
BCEL?

Thanks, Gary

--- Juozas Baliuka <baliuka <at> centras.lt> wrote:
> Hi,
> You can use java.lang.reflect.Proxy (since jdk 1.3)
> to implement this.
> There are a few open source frameworks for this use
> case too.
>  XORM, Voruta uses dynamic code generation for data
> access and it must be
> possible to find more frameworks on SF.
> ----- Original Message -----
> From: "Gary" <glms <at> yahoo.com>
> To: <bcel-user <at> jakarta.apache.org>
> Sent: Monday, July 28, 2003 10:49 PM
> Subject: Dynamic Creation of Value Object
> 
> 
> > Let's say I have the following:
> >
> > interface IOrder - an order interface
(Continue reading)

Juozas Baliuka | 29 Jul 2003 18:26
Picon

Re: Dynamic Creation of Value Object


I recommend java.lang.reflect.Proxy for serialization support, if you will
use bcel on server you will need to use it on client too ( to "transport"
class code), it will be problems with security too. You can see cglib for
examples, it generates a lot of stuff at runtime, but java reflection must
be better for this use case.

> I'd rather not use the Proxy support, as it would end
> up dragging all sorts of additional classes down to my
> client.  I want to just send a pure data transfer
> object that has the same interface as the full
> business object.
>
> Any ideas/sample code on how I could do this with
> BCEL?
>
> Thanks, Gary
>
> --- Juozas Baliuka <baliuka <at> centras.lt> wrote:
> > Hi,
> > You can use java.lang.reflect.Proxy (since jdk 1.3)
> > to implement this.
> > There are a few open source frameworks for this use
> > case too.
> >  XORM, Voruta uses dynamic code generation for data
> > access and it must be
> > possible to find more frameworks on SF.
> > ----- Original Message -----
> > From: "Gary" <glms <at> yahoo.com>
> > To: <bcel-user <at> jakarta.apache.org>
(Continue reading)


Gmane