/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. #ifndef jspropertycacheinlines_h___
  42. #define jspropertycacheinlines_h___
  43. #include "jslock.h"
  44. #include "jspropertycache.h"
  45. #include "jsscope.h"
  46. using namespace js;
  47. /*
  48. * This method is designed to inline the fast path in js_Interpret, so it makes
  49. * "just-so" restrictions on parameters, e.g. pobj and obj should not be the
  50. * same variable, since for JOF_PROP-mode opcodes, obj must not be changed
  51. * because of a cache miss.
  52. *
  53. * On return, if name is null then obj points to the scope chain element in
  54. * which the property was found, pobj is locked, and entry is valid. If name is
  55. * non-null then no object is locked but entry is still set correctly for use,
  56. * e.g., by PropertyCache::fill and name should be used as the id to find.
  57. *
  58. * We must lock pobj on a hit in order to close races with threads that might
  59. * be deleting a property from its scope, or otherwise invalidating property
  60. * caches (on all threads) by re-generating JSObject::shape().
  61. */
  62. JS_ALWAYS_INLINE void
  63. PropertyCache::test(JSContext *cx, jsbytecode *pc, JSObject *&obj,
  64. JSObject *&pobj, PropertyCacheEntry *&entry, PropertyName *&name)
  65. {
  66. JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
  67. const Shape *kshape = obj->lastProperty();
  68. entry = &table[hash(pc, kshape)];
  69. PCMETER(pctestentry = entry);
  70. PCMETER(tests++);
  71. JS_ASSERT(&obj != &pobj);
  72. if (entry->kpc == pc && entry->kshape == kshape) {
  73. JSObject *tmp;
  74. pobj = obj;
  75. if (entry->isPrototypePropertyHit() &&
  76. (tmp = pobj->getProto()) != NULL) {
  77. pobj = tmp;
  78. }
  79. if (pobj->lastProperty() == entry->pshape) {
  80. PCMETER(pchits++);
  81. PCMETER(entry->isOwnPropertyHit() || protopchits++);
  82. name = NULL;
  83. return;
  84. }
  85. }
  86. name = fullTest(cx, pc, &obj, &pobj, entry);
  87. if (name)
  88. PCMETER(misses++);
  89. }
  90. JS_ALWAYS_INLINE bool
  91. PropertyCache::testForSet(JSContext *cx, jsbytecode *pc, JSObject *obj,
  92. PropertyCacheEntry **entryp, JSObject **obj2p, PropertyName **namep)
  93. {
  94. JS_ASSERT(this == &JS_PROPERTY_CACHE(cx));
  95. const Shape *kshape = obj->lastProperty();
  96. PropertyCacheEntry *entry = &table[hash(pc, kshape)];
  97. *entryp = entry;
  98. PCMETER(pctestentry = entry);
  99. PCMETER(tests++);
  100. PCMETER(settests++);
  101. if (entry->kpc == pc && entry->kshape == kshape)
  102. return true;
  103. PropertyName *name = fullTest(cx, pc, &obj, obj2p, entry);
  104. JS_ASSERT(name);
  105. PCMETER(misses++);
  106. PCMETER(setmisses++);
  107. *namep = name;
  108. return false;
  109. }
  110. #endif /* jspropertycacheinlines_h___ */