jakarta-bcel-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Huntwork <...@huntwork.net>
Subject Re: Query regarding index of local variables
Date Tue, 08 Feb 2005 15:01:16 GMT
First, let me recommend a book to you that you may already know about:
http://java.sun.com/docs/books/vmspec/2nd-edition/html/VMSpecTOC.doc.html

read carefully enough, this book will tell you everything you need to 
know to screw around with class files to your heart's content.

see below.

Koduru, Rajendra Kumar Reddy wrote:
[...]
> 	// code
> 
> 		int i = methodgen.getLocalVariables().length
> 		my_lv1 = i+1;
> 		my_lv2 = i+2;
> 		my_lv =  i+3;
> 
> 	// code
> 
> 	and I used to store using il.append ( new ASTORE ( my_lv2 ) );
> 
> 
> 	 I encountered a problem with this, i.e. the variable i returned
> 22,
> 	 where as the max index is 7.. So there was overlap in the local
> vars and my class file got corrupted

there is no relationship between number of local variables and the first 
free slot.  each LocalVariable describes the type contained in a slot 
over a particular range of instructions.  there are 0 or more 
LocalVariables for each slot.  You should print out the various fields 
in your LocalVariables just to get a feel for what they contain, 
especially the start index, end index and type.

what you want is:

setMaxLocals(); //if you have inserted variables already
int i = methodgen.getMaxLocals();
...

In the project I used to work on (sandmark.cs.arizona.edu), almost every 
occurrence of getLocalVariables was a bug.  That's because the local 
variable table may be incomplete, inaccurate (to some extent), 
obfuscated, or just plain missing (MethodGen.removeLocalVariables() or 
something like that).

> 
> 
> 
> 	 I just wanted to know..why is it like that.. Doesn't each local
> variable have unique index?
> 
> 	 Isnt the length (i that is returned) mean the no of local
> variables in the corresponding method?
> 
> 	However now I tried using 
> 
> 	// code
> 
> 	int max_index = 0;
> 
>      LocalVariableGen[] lv1 = mgen.getLocalVariables();
> 	
>     for(int i = 0; i< lv1.length; i++){
> 
>       if(lv1[i].getIndex() > max_index)
>           max_index = lv1[i].getIndex();
>       }	
> 		
> 		my_lv1 = i+1;
> 		my_lv2 = i+2;
> 		my_lv =  i+3;
> 	
> 	// code
> 
> 	and it works fine..
> 
> 	but I just wanted to clarify it.
> 
> 	Please help me in this regard.
> 
> 
> Thank you
> Reddy
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: bcel-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org


Mime
View raw message