Alon Albert | 1 May 2003 18:21

Adding Exception Handler

I am adding an exception handler to existing code. However, the MethodGen class only allows me to add the
handler to the end of the exception table.
This causes a problem since the JVM processes exceptions in order so if my exception is nested within an
existing exception, my new handler will not get called.

I managed to solve this by clearing the exception table (MethodGen.removeExceptionHandlers()) and then adding
my new exception before restoring the old exceptions. However, this isn't a very eficient way of doing this.

I can't even derive from MethodGen to solve this since the exception_vec is declared private rather than
protected.

Am I missing something here or is this an oversight of BCEL?

Bjoern Wuest | 1 May 2003 21:40
Picon

RE: Incompatible argument -> Method signature

Hello

Thanks for all the help. In the first try, I also used the BCELifier but
because of any reason, it didn't work. I slightly modified the "wrapper"
template I wrote and re-BCELified it again and now it seems to work (after
some String-acrobatics :) ).
I will focus on the return type now (which is still missing), run some tests
with various kinds of methods and classes and look what will happen with
nested classes :).

If everything works fine, I will post my code again at the mailing list and
offer for download for some period of time.

Thanks for all the help.
  Bjoern

PS: I appreciate the BCELifier very much since it is an invaluable source
for learning byte-code. I am into byte-code for 6 days now (2 days net-time)
and without BCELifier I would be in the very early beginning.

-----Original Message-----
From: news [mailto:news <at> main.gmane.org] On Behalf Of Berin Loritsch
Sent: Dienstag, 29. April 2003 16:29
To: bcel-user <at> jakarta.apache.org
Subject: Re: Incompatible argument -> Method signature

Bjoern Wuest wrote:
> Hello
> 
> Thanks for the hint. I already tried this but as the 
(Continue reading)

Bjoern Wuest | 2 May 2003 11:10
Picon

Getting JavaClass from class instance

Hello All

I am working on a runtime wrapper for object instances. While I get
everything working with classes available on secondary storage (file
system), I have problems to use the mechanism on wrapper objects created
in memory and now wrapped a second time.
To solve this, I would require a method looking like:

public JavaClass convert(Class MyClassInstance);

Unfortunately, I could not find some similar method. The only think I
found was the ClassLoaderRepository (CLR) of BCEL. However, this
mechanism does not work. The CLR will use the filesystem where the class
is not available since it is purely "in-memory".

Thanks for tips
  Bjoern
Juozas Baliuka | 2 May 2003 17:18
Picon

Re: Getting JavaClass from class instance

I think it is no way to implement this with standard java API or custom
ClassLoder,
classes like java.lang.reflect.Proxy call native methods to define class,
use JNI hooks if possible.

----- Original Message -----
From: "Bjoern Wuest" <bjoern.wuest <at> gmx.net>
To: "'BCEL Users List'" <bcel-user <at> jakarta.apache.org>;
<bjoern.wuest <at> gmx.net>
Sent: Friday, May 02, 2003 11:10 AM
Subject: Getting JavaClass from class instance

> Hello All
>
> I am working on a runtime wrapper for object instances. While I get
> everything working with classes available on secondary storage (file
> system), I have problems to use the mechanism on wrapper objects created
> in memory and now wrapped a second time.
> To solve this, I would require a method looking like:
>
> public JavaClass convert(Class MyClassInstance);
>
> Unfortunately, I could not find some similar method. The only think I
> found was the ClassLoaderRepository (CLR) of BCEL. However, this
> mechanism does not work. The CLR will use the filesystem where the class
> is not available since it is purely "in-memory".
>
> Thanks for tips
>   Bjoern
>
(Continue reading)

Bjoern Wuest | 2 May 2003 17:30
Picon

RE: Getting JavaClass from class instance

Hello All

I oversee a possibility with the ClassLoaderRepository. Now I am able to
get an instance of JavaClass for "in-memory" created objects (classes).
Currently I am fighting with the constructor (telling me something about
wrong arguments) but I am quite sure to fix this problem, too.

Regards
  Bjoern

-----Original Message-----
From: Bjoern Wuest [mailto:bjoern.wuest <at> gmx.net] 
Sent: Freitag, 2. Mai 2003 11:10
To: 'BCEL Users List'; bjoern.wuest <at> gmx.net
Subject: Getting JavaClass from class instance

Hello All

I am working on a runtime wrapper for object instances. While I get
everything working with classes available on secondary storage (file
system), I have problems to use the mechanism on wrapper objects created
in memory and now wrapped a second time.
To solve this, I would require a method looking like:

public JavaClass convert(Class MyClassInstance);

Unfortunately, I could not find some similar method. The only think I
found was the ClassLoaderRepository (CLR) of BCEL. However, this
mechanism does not work. The CLR will use the filesystem where the class
is not available since it is purely "in-memory".
(Continue reading)

Isaac.Goldstein | 8 May 2003 20:16
Favicon

Need help modifying existing class

Hi all.  I'm a newbie to BCEL and I'm trying to figure out how to add
fields and methods to an existing class.  Can anyone show me a small
example.

Thanks.
Bjoern Wuest | 9 May 2003 08:38
Picon

RE: Need help modifying existing class

Hello

As I am not so experienced with BCEL, I did using the 'FieldGen' and
'MethodGen' classes in the 'org.apache.bcel.classfile' package. To use such
this operations, you need an instance of 'JavaClass'.
I tried to learn BCEL using the excellent BCELifier that you can find in
'org.apache.bcel.util'.
Here is a small example on how to use the BCELifier:

try {
	org.apache.bcel.util.ClassLoaderRepository clr = new
org.apache.bcel.util.ClassLoaderRepository(System.class.getClassLoader());
	org.apache.bcel.classfile.JavaClass cls =
clr.loadClass("me.you.AndClass");
	org.apache.bcel.util.BCELifier bf = new
org.apache.bcel.util.BCELifier(cls, System.out);
	bf.start();
} catch (Exception Ex) {
	Ex.printStackTrace();
}

Regards
  Bjoern

-----Original Message-----
From: Isaac.Goldstein <at> ny.frb.org [mailto:Isaac.Goldstein <at> ny.frb.org] 
Sent: Donnerstag, 8. Mai 2003 20:16
To: bcel-user <at> jakarta.apache.org
Subject: Need help modifying existing class

(Continue reading)

Steve Jones | 18 May 2003 14:19
Picon
Picon
Favicon

Adding labels to instruction lists

Hi,

I currently use a NOP instruction as a branch target.  I do a final fixup of 
the code by moving the branch targets to the instruction that follows the NOP 
and then remove the NOP. It works but it's messy.

Can anyone suggest a neat way of inserting code labels into an instruction 
list.  A sort of NOP that produces no opcode.

Cheers, Steve.
Chris Nokleberg | 20 May 2003 01:34
Favicon

Re: Adding labels to instruction lists

Steve Jones wrote:
> Can anyone suggest a neat way of inserting code labels into an instruction 
> list.  A sort of NOP that produces no opcode.

Check out MethodGen.removeNOPs

BCEL will do it for you!

Chris
Nick Hynes | 20 May 2003 02:02

Intra-method dependencies...


Hi all,

I need to build a dependency analyser that is able to work at the method level. Most dependency tracers work
at the package and class level, and are targeted at build tools. I need to identify which methods call other
methods within our product (for smoke testing purposes).

On first sight it appears like a not-too-hard problem to solve. I anticipate simply using the static
constraints part of the package (using the JavaClass, Method and Code objects, and probably the
ConstantsPool). The Code would need to be split into instructions, and then you would need to search for
the invokestatic, invokevirtual, invokespecial and invokeinterface opcodes.

Does this seem like a reasonable implementation?

Am I re-inventing the wheel (has this been done elsewhere/before)?

Would Code.accept( Vistor ) be of use here?

- Nick
 

Gmane