Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 66920 invoked from network); 13 Dec 2005 20:30:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 13 Dec 2005 20:30:09 -0000 Received: (qmail 91941 invoked by uid 500); 13 Dec 2005 20:30:07 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 91908 invoked by uid 500); 13 Dec 2005 20:30:07 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 91899 invoked by uid 99); 13 Dec 2005 20:30:07 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Dec 2005 12:30:07 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [32.97.182.141] (HELO e1.ny.us.ibm.com) (32.97.182.141) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Dec 2005 12:30:06 -0800 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e1.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id jBDKTiBe002334 for ; Tue, 13 Dec 2005 15:29:45 -0500 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay04.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id jBDKTjKn102694 for ; Tue, 13 Dec 2005 15:29:45 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.12.11/8.13.3) with ESMTP id jBDKTijp002422 for ; Tue, 13 Dec 2005 15:29:44 -0500 Received: from [127.0.0.1] (sig-9-48-111-99.mts.ibm.com [9.48.111.99]) by d01av02.pok.ibm.com (8.12.11/8.12.11) with ESMTP id jBDKTgVH002280 for ; Tue, 13 Dec 2005 15:29:43 -0500 Message-ID: <439F2F36.1040205@debrunners.com> Date: Tue, 13 Dec 2005 12:29:42 -0800 From: Daniel John Debrunner User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.3) Gecko/20040910 X-Accept-Language: en-us, en, de MIME-Version: 1.0 To: derby-dev@db.apache.org Subject: Re: Question about MethodBuilder.pushThis() References: <439F2552.6070106@sbcglobal.net> In-Reply-To: <439F2552.6070106@sbcglobal.net> X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Kathey Marsden wrote: > I have a few newbie questions about MethodBuilder and BaseActivation > and ClassBuilder > > If I look at this code in ExpressionClassBuilder: > > void pushPVSReference(MethodBuilder mb) > { > mb.pushThis(); > mb.getField(ClassName.BaseActivation, "pvs", > ClassName.ParameterValueSet); > } > > it would seem that pushThis() pushes an instance of BaseActivation > onto the stack. How exactly does that happen? > In BCMethod pushThis seems to push a ClassBuilder. I don't see how > BaseActivation gets there. I'm not sure what you are seeing in BCMethod.pushThis(). The first line is: myCode.addInstr(VMOpcode.ALOAD_0); This adds the instruction ALOAD_0 which is the instruction that will push 'this' onto the operand stack. The second line is: growStack(1, cb.classType); This is code that in the byte code builder maintains track of the types of the operands that are on the operand stack. Pushing 'this' onto the operand stack will put a reference of type X, where X is the name of the generated class, e.g. org.apache.derby.exe.ac435340402342342. Here 'cb.classType' represents the class name of the generated class. Thus pushThis() pushes a Java reference corresponding to 'this' and it will be of type org.apache.derby.exe.ac435340402342342 (as an example name). Now at the language level, e.g. pushPVSReference, it is known that the generated class is a sub-class of BaseActivation, since the language layer declared/created the generated class using BaseActivation as its super-class. > mb.getField(ClassName.BaseActivation, "pvs", > ClassName.ParameterValueSet); Now the first argument to getField here is the *declared* class of the field. If the argument is null, then the declared class of the field is taken from the type of the operand on the stack. In this case the pvs field is declared in BaseActivation, so the jvm class format requires that the description of the field is its declared type, thus BaseActivation is needed. Basically the use of ClassName.BaseActivation here is an "up cast". In Java language it's: ((BaseActivation) this).pvs; If you were writing Java code, then you would just use: this.pvs but the Java compiler would perform the resolution of the field and generate code that represents: ((BaseActivation) this).pvs. The Derby byte code compiler does not perform field or method resolution like the Java compiler, it expects the caller (the language layer) to provide correct field and method descriptors. Hope this helps, Dan.