Return-Path: Delivered-To: apmail-jakarta-bcel-user-archive@www.apache.org Received: (qmail 23498 invoked from network); 9 Feb 2005 11:03:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 9 Feb 2005 11:03:31 -0000 Received: (qmail 52409 invoked by uid 500); 9 Feb 2005 11:03:31 -0000 Delivered-To: apmail-jakarta-bcel-user-archive@jakarta.apache.org Received: (qmail 52203 invoked by uid 500); 9 Feb 2005 11:03:29 -0000 Mailing-List: contact bcel-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "BCEL Users List" Reply-To: "BCEL Users List" Delivered-To: mailing list bcel-user@jakarta.apache.org Received: (qmail 52189 invoked by uid 99); 9 Feb 2005 11:03:29 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: domain of rajendra.kumar.reddy.koduru@sap.com designates 155.56.68.140 as permitted sender) Received: from smtpde03.sap-ag.de (HELO smtpde03.sap-ag.de) (155.56.68.140) by apache.org (qpsmtpd/0.28) with ESMTP; Wed, 09 Feb 2005 03:03:28 -0800 Received: from sap-ag.de (smtpde03) by smtpde03.sap-ag.de (out) with ESMTP id MAA08981 for ; Wed, 9 Feb 2005 12:03:24 +0100 (MEZ) content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6603.0 Subject: RE: Query regarding index of local variables Date: Wed, 9 Feb 2005 12:03:24 +0100 Message-ID: <73DFF891F8024B48AD56B594C4C5038A6BDAD4@dewdfe23.wdf.sap.corp> Thread-Topic: Query regarding index of local variables Thread-Index: AcUN/LbpQcZl08i2S6y9oOoHRiOVlwAmMj0A From: "Koduru, Rajendra Kumar Reddy" To: "BCEL Users List" X-OriginalArrivalTime: 09 Feb 2005 11:03:24.0821 (UTC) FILETIME=[F9C46C50:01C50E96] X-SAP: out X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi Andrew,=20 I have gone thru this concept of assigning a slot to local variables by observing the local variable tables of the class files, yep each slot is being taken by many local var. so I used getMaxLocals() and it worked fine (removed my own way of fidning max index, which sometimes is causing an error due to incomplete lv table). Please find a comment inline regarding the comment made by you "stack height mismatch verification error". =09 =20 >Koduru, Rajendra Kumar Reddy wrote: >> Hi Andrew >>=20 >> Thank you for recommending me the VM spec... > >Reading the VM spec is not as stupid an idea as it might=20 >sound. I'm not=20 >aware of any more concise or helpful reference for bytecode=20 >manipulators. Can anyone suggest a better one? > >>=20 >> But my prob is a little different, > >It seems that your problem can be summarized as, "How do i=20 >choose a free=20 >slot?" That's the question i answered in my previous email. =20 >see below=20 >for further explanation. > >>=20 >> as you have said I can add local variables using=20 >>=20 >> LocalVar var =3D localvargen.addLocalvar() >> int index =3D var.getIndex(); >> llcalvargen.setstart( ilist.append ( new ASTORE ( index ) ) ) >> . >> . >> .=20 >> =20 >> as many as required >>=20 >> and at the calling setMaxLocals(); >>=20 >> That is OK. > >none of this is actually required. the local variable table=20 >is just for=20 >debugging purposes, and as i said before, may be inaccurate,=20 >incomplete,=20 >obfuscated, or missing. feel free to ignore LocalVar objects=20 >completely=20 >and just choose some slots yourself and use them. > >The usual way of choosing slots, as far as I'm aware, is to call=20 >getMaxLocals: > >MethodGen mg =3D ... >int freeSlot =3D mg.getMaxLocals(); >int freeSlot2 =3D freeSlot + 1; >mg.getInstructionList().append(new ASTORE(freeSlot)); >... > >>=20 >> but now consider a scenario like this >> =09 >> public int getI(){ >> return 2; >> } >>=20 >> Now I am trying to insert try-finally to this method by >> instrumenting in bytecode=20 >>=20 >> which should look like =20 >>=20 >> public int getI(){ >> try{ >> return 2; >> }finally {=20 >> System.out.println("sample"); >> } >> =09 >> }=09 >>=20 >> To create this, I should create a empty catch block which throws >> the exception that is not handled and redirect all the calls=20 >to finally >> before the=20 >> return statement >>=20 >> now comes the problem with local variables. >>=20 >>=20 >> I will get the instructionlist >> I will find the instance of return, and insert a JSR instr >> before this return and redirect all the branches > >btw, when you get past your other problems, it seems like you=20 >might have=20 >a stack height mismatch verification error at your subroutine. ask=20 >about that if it happens. if i'm right, it'll happen in any non-void=20 >method you instrument. Andrew, I did not get that type of error, however could you please let me know , why were you expecting this?? in non void methods, I was using=20 1. new ASTORE(x) // storing the result 2. jsr call // calling jsr 3. new ALOAD(x) // loading back the result 4. return // returning the result and all the branches were reidrected to 1 (i.e store statement) in case of non void methods so could you please let me know , why were you expecting an error?? So that I could rectify it am I right in doing like this??? However just to mention, I was also using methodgen.setMaxStack before returning the isntrumented method > >> Next step is creation of catch block, where I have a problem >> here I should store the exception, make a jsr >> call, load the exception which I stored before and rethrow it >>=20 >> so I use ilist.append ( new ASTORE ( ? ) ) >> ilist.append ( new JSR() ); >> ilist.load ( new ALOAD ( ? ) ) >> =09 >> so what should I use in the place of "?" (2,3,4......) > >i suggest mg.getMaxLocals() > >>=20 >> same while creating finally block, I should store the return >> address >> =09 >> ilist.append ( new ASTORE ( ?? ) ) >> // performs the instrumentation of system.out..... >> ret ??=20 >> =09 >> so what should I use in place of "?" (2,3,4......) > >i suggest mg.getMaxLocals() + 1 > >>=20 >> so what I am doing is=20 >> =09 >> getting the max_index (maximum index) available in the >> localvargen=20 >> and assigning max_index+1 to the first ? >> and assigning max_index+2 to the second ?? >>=20 >> am I wrong in doing like these????? > >If the local variable table were complete and accurate, this method=20 >would be correct, but you should not assume that. =20 >getMaxLocals() always=20 >returns a free slot (assuming you call setMaxLocals()=20 >appropriately) and=20 >frees you from writing your own code to find max_index. > >>=20 >> is there some other efficient way for doing this??? > >getMaxLocals() > >>=20 >> Please help me in this regard. >>=20 >> Thank you >> Reddy >> =09 > >--------------------------------------------------------------------- >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