PageRenderTime 39ms CodeModel.GetById 15ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/js/src/jspropertycacheinlines.h

http://github.com/zpao/v8monkey
C Header | 122 lines | 55 code | 12 blank | 55 comment | 17 complexity | 4d213dc78eb1e5cb68b9f420109792e7 MD5 | raw file
  1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2 * vim: set ts=8 sw=4 et tw=99:
  3 *
  4 * ***** BEGIN LICENSE BLOCK *****
  5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  6 *
  7 * The contents of this file are subject to the Mozilla Public License Version
  8 * 1.1 (the "License"); you may not use this file except in compliance with
  9 * the License. You may obtain a copy of the License at
 10 * http://www.mozilla.org/MPL/
 11 *
 12 * Software distributed under the License is distributed on an "AS IS" basis,
 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 14 * for the specific language governing rights and limitations under the
 15 * License.
 16 *
 17 * The Original Code is Mozilla Communicator client code, released
 18 * March 31, 1998.
 19 *
 20 * The Initial Developer of the Original Code is
 21 * Mozilla Corporation.
 22 * Portions created by the Initial Developer are Copyright (C) 2010
 23 * the Initial Developer. All Rights Reserved.
 24 *
 25 * Contributor(s):
 26 *   Igor Bukanov <igor@mir2.org>
 27 *
 28 * Alternatively, the contents of this file may be used under the terms of
 29 * either of the GNU General Public License Version 2 or later (the "GPL"),
 30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 31 * in which case the provisions of the GPL or the LGPL are applicable instead
 32 * of those above. If you wish to allow use of your version of this file only
 33 * under the terms of either the GPL or the LGPL, and not to allow others to
 34 * use your version of this file under the terms of the MPL, indicate your
 35 * decision by deleting the provisions above and replace them with the notice
 36 * and other provisions required by the GPL or the LGPL. If you do not delete
 37 * the provisions above, a recipient may use your version of this file under
 38 * the terms of any one of the MPL, the GPL or the LGPL.
 39 *
 40 * ***** END LICENSE BLOCK ***** */
 41
 42#ifndef jspropertycacheinlines_h___
 43#define jspropertycacheinlines_h___
 44
 45#include "jslock.h"
 46#include "jspropertycache.h"
 47#include "jsscope.h"
 48
 49using namespace js;
 50
 51/*
 52 * This method is designed to inline the fast path in js_Interpret, so it makes
 53 * "just-so" restrictions on parameters, e.g. pobj and obj should not be the
 54 * same variable, since for JOF_PROP-mode opcodes, obj must not be changed
 55 * because of a cache miss.
 56 *
 57 * On return, if name is null then obj points to the scope chain element in
 58 * which the property was found, pobj is locked, and entry is valid. If name is
 59 * non-null then no object is locked but entry is still set correctly for use,
 60 * e.g., by PropertyCache::fill and name should be used as the id to find.
 61 *
 62 * We must lock pobj on a hit in order to close races with threads that might
 63 * be deleting a property from its scope, or otherwise invalidating property
 64 * caches (on all threads) by re-generating JSObject::shape().
 65 */
 66JS_ALWAYS_INLINE void
 67PropertyCache::test(JSContext *cx, jsbytecode *pc, JSObject *&obj,
 68                    JSObject *&pobj, PropertyCacheEntry *&entry, PropertyName *&name)
 69{
 70    JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
 71
 72    const Shape *kshape = obj->lastProperty();
 73    entry = &table[hash(pc, kshape)];
 74    PCMETER(pctestentry = entry);
 75    PCMETER(tests++);
 76    JS_ASSERT(&obj != &pobj);
 77    if (entry->kpc == pc && entry->kshape == kshape) {
 78        JSObject *tmp;
 79        pobj = obj;
 80        if (entry->isPrototypePropertyHit() &&
 81            (tmp = pobj->getProto()) != NULL) {
 82            pobj = tmp;
 83        }
 84
 85        if (pobj->lastProperty() == entry->pshape) {
 86            PCMETER(pchits++);
 87            PCMETER(entry->isOwnPropertyHit() || protopchits++);
 88            name = NULL;
 89            return;
 90        }
 91    }
 92    name = fullTest(cx, pc, &obj, &pobj, entry);
 93    if (name)
 94        PCMETER(misses++);
 95}
 96
 97JS_ALWAYS_INLINE bool
 98PropertyCache::testForSet(JSContext *cx, jsbytecode *pc, JSObject *obj,
 99                          PropertyCacheEntry **entryp, JSObject **obj2p, PropertyName **namep)
100{
101    JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
102
103    const Shape *kshape = obj->lastProperty();
104    PropertyCacheEntry *entry = &table[hash(pc, kshape)];
105    *entryp = entry;
106    PCMETER(pctestentry = entry);
107    PCMETER(tests++);
108    PCMETER(settests++);
109    if (entry->kpc == pc && entry->kshape == kshape)
110        return true;
111
112    PropertyName *name = fullTest(cx, pc, &obj, obj2p, entry);
113    JS_ASSERT(name);
114
115    PCMETER(misses++);
116    PCMETER(setmisses++);
117
118    *namep = name;
119    return false;
120}
121
122#endif /* jspropertycacheinlines_h___ */