Fix code cache lookup for keyed IC's
authorsgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Mar 2010 08:52:31 +0000 (08:52 +0000)
committersgjesse@chromium.org <sgjesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 11 Mar 2010 08:52:31 +0000 (08:52 +0000)
For keyed IC's the name is not necessarily a string.

BUG=http://crbug.com/37853
TEST=test/mjsunit/regress/regress-crbug-37853.js
Review URL: http://codereview.chromium.org/872001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4094 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/ic.cc
src/objects.cc
src/objects.h
test/mjsunit/regress/regress-crbug-37853.js [new file with mode: 0644]

index f82e61e..31154b7 100644 (file)
--- a/src/ic.cc
+++ b/src/ic.cc
@@ -150,7 +150,7 @@ IC::State IC::StateFrom(Code* target, Object* receiver, Object* name) {
   // the receiver map's code cache.  Therefore, if the current target
   // is in the receiver map's code cache, the inline cache failed due
   // to prototype check failure.
-  int index = map->IndexInCodeCache(String::cast(name), target);
+  int index = map->IndexInCodeCache(name, target);
   if (index >= 0) {
     // For keyed load/store, the most likely cause of cache failure is
     // that the key has changed.  We do not distinguish between
index 7f4ab0b..5457678 100644 (file)
@@ -3055,7 +3055,7 @@ Object* Map::FindInCodeCache(String* name, Code::Flags flags) {
 }
 
 
-int Map::IndexInCodeCache(String* name, Code* code) {
+int Map::IndexInCodeCache(Object* name, Code* code) {
   // Get the internal index if a code cache exists.
   if (!code_cache()->IsFixedArray()) {
     return CodeCache::cast(code_cache())->GetIndex(name, code);
@@ -3200,12 +3200,11 @@ Object* CodeCache::LookupNormalTypeCache(String* name, Code::Flags flags) {
 }
 
 
-int CodeCache::GetIndex(String* name, Code* code) {
-  // This is not used for normal load/store/call IC's.
+int CodeCache::GetIndex(Object* name, Code* code) {
   if (code->type() == NORMAL) {
     if (normal_type_cache()->IsUndefined()) return -1;
     CodeCacheHashTable* cache = CodeCacheHashTable::cast(normal_type_cache());
-    return cache->GetIndex(name, code->flags());
+    return cache->GetIndex(String::cast(name), code->flags());
   }
 
   FixedArray* array = default_cache();
@@ -3217,11 +3216,11 @@ int CodeCache::GetIndex(String* name, Code* code) {
 }
 
 
-void CodeCache::RemoveByIndex(String* name, Code* code, int index) {
+void CodeCache::RemoveByIndex(Object* name, Code* code, int index) {
   if (code->type() == NORMAL) {
     ASSERT(!normal_type_cache()->IsUndefined());
     CodeCacheHashTable* cache = CodeCacheHashTable::cast(normal_type_cache());
-    ASSERT(cache->GetIndex(name, code->flags()) == index);
+    ASSERT(cache->GetIndex(String::cast(name), code->flags()) == index);
     cache->RemoveByIndex(index);
   } else {
     FixedArray* array = default_cache();
index 826fcae..2004d50 100644 (file)
@@ -2971,7 +2971,7 @@ class Map: public HeapObject {
 
   // Returns the non-negative index of the code object if it is in the
   // cache and -1 otherwise.
-  int IndexInCodeCache(String* name, Code* code);
+  int IndexInCodeCache(Object* name, Code* code);
 
   // Removes a code object from the code cache at the given index.
   void RemoveFromCodeCache(String* name, Code* code, int index);
@@ -3743,10 +3743,10 @@ class CodeCache: public Struct {
   // code object is not in that cache. This index can be used to later call
   // RemoveByIndex. The cache cannot be modified between a call to GetIndex and
   // RemoveByIndex.
-  int GetIndex(String* name, Code* code);
+  int GetIndex(Object* name, Code* code);
 
   // Remove an object from the cache with the provided internal index.
-  void RemoveByIndex(String* name, Code* code, int index);
+  void RemoveByIndex(Object* name, Code* code, int index);
 
   static inline CodeCache* cast(Object* obj);
 
diff --git a/test/mjsunit/regress/regress-crbug-37853.js b/test/mjsunit/regress/regress-crbug-37853.js
new file mode 100644 (file)
index 0000000..047fbcb
--- /dev/null
@@ -0,0 +1,34 @@
+// Copyright 2009 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// See http://crbug.com/37853
+
+function f(o, k) { return o[k]; }
+a = {'a':1, 1:'a'}
+f(a, 'a')
+f(a, 'a')
+f(a, 1);