Return-Path: Delivered-To: apmail-jakarta-bcel-user-archive@www.apache.org Received: (qmail 8588 invoked from network); 8 Feb 2005 16:39:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 8 Feb 2005 16:39:02 -0000 Received: (qmail 28038 invoked by uid 500); 8 Feb 2005 16:39:01 -0000 Delivered-To: apmail-jakarta-bcel-user-archive@jakarta.apache.org Received: (qmail 28014 invoked by uid 500); 8 Feb 2005 16:39:01 -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 28000 invoked by uid 99); 8 Feb 2005 16:39:00 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from relay02.pair.com (HELO relay02.pair.com) (209.68.5.16) by apache.org (qpsmtpd/0.28) with SMTP; Tue, 08 Feb 2005 08:38:59 -0800 Received: (qmail 27474 invoked from network); 8 Feb 2005 16:38:57 -0000 Received: from unknown (HELO r1.ash.huntwork.net) (unknown) by unknown with SMTP; 8 Feb 2005 16:38:57 -0000 X-pair-Authenticated: 68.63.196.107 Received: from [209.203.91.199] (209-203-91-199.gen.twtelecom.net [209.203.91.199]) (authenticated bits=0) by r1.ash.huntwork.net (8.12.8/8.12.8) with ESMTP id j18GctpN018228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 8 Feb 2005 09:38:56 -0700 Message-ID: <4208EB29.3080801@huntwork.net> Date: Tue, 08 Feb 2005 09:39:05 -0700 From: Andrew Huntwork User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: BCEL Users List Subject: Re: Query regarding index of local variables References: <73DFF891F8024B48AD56B594C4C5038A6BDAD3@dewdfe23.wdf.sap.corp> In-Reply-To: <73DFF891F8024B48AD56B594C4C5038A6BDAD3@dewdfe23.wdf.sap.corp> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Koduru, Rajendra Kumar Reddy wrote: > Hi Andrew > > Thank you for recommending me the VM spec... Reading the VM spec is not as stupid an idea as it might sound. I'm not aware of any more concise or helpful reference for bytecode manipulators. Can anyone suggest a better one? > > But my prob is a little different, It seems that your problem can be summarized as, "How do i choose a free slot?" That's the question i answered in my previous email. see below for further explanation. > > as you have said I can add local variables using > > LocalVar var = localvargen.addLocalvar() > int index = var.getIndex(); > llcalvargen.setstart( ilist.append ( new ASTORE ( index ) ) ) > . > . > . > > as many as required > > and at the calling setMaxLocals(); > > That is OK. none of this is actually required. the local variable table is just for debugging purposes, and as i said before, may be inaccurate, incomplete, obfuscated, or missing. feel free to ignore LocalVar objects completely and just choose some slots yourself and use them. The usual way of choosing slots, as far as I'm aware, is to call getMaxLocals: MethodGen mg = ... int freeSlot = mg.getMaxLocals(); int freeSlot2 = freeSlot + 1; mg.getInstructionList().append(new ASTORE(freeSlot)); ... > > but now consider a scenario like this > > public int getI(){ > return 2; > } > > Now I am trying to insert try-finally to this method by > instrumenting in bytecode > > which should look like > > public int getI(){ > try{ > return 2; > }finally { > System.out.println("sample"); > } > > } > > To create this, I should create a empty catch block which throws > the exception that is not handled and redirect all the calls to finally > before the > return statement > > now comes the problem with local variables. > > > 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 might have a stack height mismatch verification error at your subroutine. ask about that if it happens. if i'm right, it'll happen in any non-void method you instrument. > 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 > > so I use ilist.append ( new ASTORE ( ? ) ) > ilist.append ( new JSR() ); > ilist.load ( new ALOAD ( ? ) ) > > so what should I use in the place of "?" (2,3,4......) i suggest mg.getMaxLocals() > > same while creating finally block, I should store the return > address > > ilist.append ( new ASTORE ( ?? ) ) > // performs the instrumentation of system.out..... > ret ?? > > so what should I use in place of "?" (2,3,4......) i suggest mg.getMaxLocals() + 1 > > so what I am doing is > > getting the max_index (maximum index) available in the > localvargen > and assigning max_index+1 to the first ? > and assigning max_index+2 to the second ?? > > am I wrong in doing like these????? If the local variable table were complete and accurate, this method would be correct, but you should not assume that. getMaxLocals() always returns a free slot (assuming you call setMaxLocals() appropriately) and frees you from writing your own code to find max_index. > > is there some other efficient way for doing this??? getMaxLocals() > > 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