Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:34670 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57297 invoked by uid 1010); 10 Jan 2008 23:46:10 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 57282 invoked from network); 10 Jan 2008 23:46:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Jan 2008 23:46:10 -0000 Authentication-Results: pb1.pair.com header.from=andi@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=andi@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.162 as permitted sender) X-PHP-List-Original-Sender: andi@zend.com X-Host-Fingerprint: 212.25.124.162 mail.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.162] ([212.25.124.162:21236] helo=mx1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C4/F0-51656-14EA6874 for ; Thu, 10 Jan 2008 18:46:10 -0500 Received: from us-ex1.zend.com ([192.168.16.5]) by mx1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 11 Jan 2008 01:46:07 +0200 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Date: Thu, 10 Jan 2008 15:46:03 -0800 Message-ID: <698DE66518E7CA45812BD18E807866CE011C7C78@us-ex1.zend.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question Thread-Index: AchT4ZmYy5CpBNS3T8GcO9WScZ6tFAAAR1mA References: <300A9932AE9C0145A146B5A4E5CCE96901921EDC@sf2pmxb01.thefacebook.com> To: "Kannan Muthukkaruppan" , X-OriginalArrivalTime: 10 Jan 2008 23:46:07.0388 (UTC) FILETIME=[F851BDC0:01C853E2] Subject: RE: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question From: andi@zend.com ("Andi Gutmans") Op arrays are read-only. This is a design goal and is especially important for byte code caches where several processes are looking at the same op array. Therefore setting IS_CONST to is_ref=3D1/refcount=3D2 = we are ensuring that they will not be changed. The copy happens only the first time and afterwards that zval may be used, incremented, etc... Net net, it is intended behavior and very important. Andi > -----Original Message----- > From: Kannan Muthukkaruppan [mailto:Kannan@facebook.com] > Sent: Thursday, January 10, 2008 3:36 PM > To: internals@lists.php.net > Subject: [PHP-DEV] php-5.2.3: zend_opcode.c: pass_two() question >=20 > An example assignment such as: > $x =3D 10; > doesn't seem to get handled as a simple ref-count incrementing > assignment (in zend_assign_to_variable()). Instead, $x ends up getting > a > new "zval" into which a > copy of the RHS (10) is made. >=20 > This seems to be because the zval/znode corresponding to the literal 10 > is an IS_CONST operand of the assignment opcode. And, during the end > of > compilation of a function, the IS_CONST operands in the function's > op_array are patched up as "references" (is_ref is set to 1). >=20 > zend_opcode.c:pass_two() > ... > while (opline < end) { > if (opline->op1.op_type =3D=3D IS_CONST) { > opline->op1.u.constant.is_ref =3D 1; > opline->op1.u.constant.refcount =3D 2; /* Make sure is_ref won't be > reset */ > } > if (opline->op2.op_type =3D=3D IS_CONST) { > opline->op2.u.constant.is_ref =3D 1; > opline->op2.u.constant.refcount =3D 2; > } > ... >=20 > And zend_assign_to_variable(), when it sees the RHS to be a reference > ("is_ref =3D=3D 1") ends up doing a copy rather than a ref-count > incrementing assignment. >=20 > It seems like performance would be better if we didn't mark constant > operands as "references" in pass_two(). But presumably it is required > to > handle some cases that'll otherwise break? I am trying to understand > what those cases are. If someone can shed further light on this issue, > it is much appreciated... >=20 > regards, > Kannan Muthukkaruppan