Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75153 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44252 invoked from network); 30 Jun 2014 20:08:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Jun 2014 20:08:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:65418] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0B/04-19922-8A3C1B35 for ; Mon, 30 Jun 2014 16:08:10 -0400 Received: by mail-vc0-f179.google.com with SMTP id id10so8052111vcb.38 for ; Mon, 30 Jun 2014 13:08:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=X6AVvIWOcnqZhersdqizrdfBs3XbcQecz7pDIrojOLg=; b=juKZbUSh05RfUdS71lkyQa/g+sYuyGnMPZE7IGnCrFu++QmU3HfUE2mFXhHCD2RRAZ UW8qK8BsBgET0mbUQXIRFxWX0QJlDRg51ePcbWIY1LHSG1rMDGpByZgHB8w/bd0t+jz1 pMfaG9/55Xz4flHZAoVfsRQCFkp9GGLzME+oB26QgDIIQ+KZjyXHmtXb2c8J1mtHclxZ lcVn8P0HcpOOJ2R9JR35UerZrkpq+ODO7p7F+jXYd3D32fOre5b6LxySqs4pTBjtYmon 4JvFn1Oh0ZTyJDTqiAYCPgb3l1AQPkM58OrF1jV/9gDfpKwRbaQYHGN99WAIyrntxg49 sw8Q== X-Gm-Message-State: ALoCoQkxqIyVYiyo2NKrhlPew7X+uZNdqEypj+l8pgrWu54fMUOXZ70M+xM0lnRnIoHIyfnTRaQt0BuAFU9c5IlvSYRZu6XOLc3MgRUM4202XTv4yTwoed0Zf0EnRAHk/jPT37XXm1CZ MIME-Version: 1.0 X-Received: by 10.58.12.73 with SMTP id w9mr2104950veb.13.1404158885964; Mon, 30 Jun 2014 13:08:05 -0700 (PDT) Received: by 10.52.111.71 with HTTP; Mon, 30 Jun 2014 13:08:05 -0700 (PDT) In-Reply-To: References: Date: Tue, 1 Jul 2014 00:08:05 +0400 Message-ID: To: Eric Stenson Cc: PHP Internals Content-Type: multipart/alternative; boundary=047d7b4184419b458204fd13374e Subject: Re: [PHP-DEV] Q: How to handle zend_op_array.scope and zend_op_array.prototype in opcode cache? From: dmitry@zend.com (Dmitry Stogov) --047d7b4184419b458204fd13374e Content-Type: text/plain; charset=UTF-8 Hi Eric, On Tue, Jun 24, 2014 at 11:08 PM, Eric Stenson wrote: > PHP Internals folks-- > > I'm working on the opcode cache part of Wincache, and I believe that > Wincache isn't properly handling the scope and prototype fields of the > zend_op_array struct when copying it into shared memory. > > I tried looking at the Zend Opcache code to figure out what The Right > Way(TM) to handle these fields, and I'm curious about how these fields are > used by the Zend engine. > > From what I can tell, Zend Opcache has a per-process HashTable where it > keeps track of which items is has copied into shared memory (xlat_table). > > It looks like the xlat_table is cleared out before each compilation. When > persisting, Zend persists things in the following order: > 1. function_table > 2. class_table > 3. zend_op_array (for the main zend_op_array produced by compile) > > My questions: > * Is there some guarantee that the scope and prototype on the main > zend_op_array exist in the function_table and class_table for the > compilation? > OPcache makes a trick to compile each file completely independent from others, so op_arrays may refer only to classes and functions from the same script or to internal ones. > * Does the scope and prototype fields really matter for the main > zend_op_array? Wincache has been setting them to NULL since day 1, and > everything seems to work just fine... > scope and prototype make sense only for methods. top_level code and regular functions always have them as NULL. > * The xlat_table key is a ulong. Zend Opcache uses the pointer of an > object as the key. On Windows, a ulong is 32 bits. How does this even > work on an x64 Windows box? > #if SIZEOF_SIZE_T <= SIZEOF_LONG /* If sizeof(void*) == sizeof(ulong) we can use zend_hash index functions */ # define accel_xlat_set(old, new) zend_hash_index_update(&ZCG(bind_hash), (ulong)(zend_uintptr_t)(old), &(new), sizeof(void*), NULL) # define accel_xlat_get(old, new) zend_hash_index_find(&ZCG(bind_hash), (ulong)(zend_uintptr_t)(old), (void**)&(new)) #else # define accel_xlat_set(old, new) zend_hash_quick_add(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (ulong)(zend_uintptr_t)(old), (void**)&(new), sizeof(void*), NULL) # define accel_xlat_get(old, new) zend_hash_quick_find(&ZCG(bind_hash), (char*)&(old), sizeof(void*), (ulong)(zend_uintptr_t)(old), (void**)&(new)) #endif So on x64 Windows we use "string" keys. It's less efficient but safe. Thanks. Dmitry. > > Thx! > --E. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7b4184419b458204fd13374e--