OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 7964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7975 Object* AsObject() { return string_; } | 7975 Object* AsObject() { return string_; } |
7976 | 7976 |
7977 String* string_; | 7977 String* string_; |
7978 uint32_t hash_; | 7978 uint32_t hash_; |
7979 }; | 7979 }; |
7980 | 7980 |
7981 | 7981 |
7982 // StringSharedKeys are used as keys in the eval cache. | 7982 // StringSharedKeys are used as keys in the eval cache. |
7983 class StringSharedKey : public HashTableKey { | 7983 class StringSharedKey : public HashTableKey { |
7984 public: | 7984 public: |
7985 StringSharedKey(String* source, SharedFunctionInfo* shared) | 7985 StringSharedKey(String* source, |
7986 : source_(source), shared_(shared) { } | 7986 SharedFunctionInfo* shared, |
| 7987 StrictModeFlag strict_mode) |
| 7988 : source_(source), |
| 7989 shared_(shared), |
| 7990 strict_mode_(strict_mode) { } |
7987 | 7991 |
7988 bool IsMatch(Object* other) { | 7992 bool IsMatch(Object* other) { |
7989 if (!other->IsFixedArray()) return false; | 7993 if (!other->IsFixedArray()) return false; |
7990 FixedArray* pair = FixedArray::cast(other); | 7994 FixedArray* pair = FixedArray::cast(other); |
7991 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); | 7995 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); |
7992 if (shared != shared_) return false; | 7996 if (shared != shared_) return false; |
| 7997 StrictModeFlag strict_mode = static_cast<StrictModeFlag>( |
| 7998 Smi::cast(pair->get(2))->value()); |
| 7999 if (strict_mode != strict_mode_) return false; |
7993 String* source = String::cast(pair->get(1)); | 8000 String* source = String::cast(pair->get(1)); |
7994 return source->Equals(source_); | 8001 return source->Equals(source_); |
7995 } | 8002 } |
7996 | 8003 |
7997 static uint32_t StringSharedHashHelper(String* source, | 8004 static uint32_t StringSharedHashHelper(String* source, |
7998 SharedFunctionInfo* shared) { | 8005 SharedFunctionInfo* shared, |
| 8006 StrictModeFlag strict_mode) { |
7999 uint32_t hash = source->Hash(); | 8007 uint32_t hash = source->Hash(); |
8000 if (shared->HasSourceCode()) { | 8008 if (shared->HasSourceCode()) { |
8001 // Instead of using the SharedFunctionInfo pointer in the hash | 8009 // Instead of using the SharedFunctionInfo pointer in the hash |
8002 // code computation, we use a combination of the hash of the | 8010 // code computation, we use a combination of the hash of the |
8003 // script source code and the start and end positions. We do | 8011 // script source code and the start and end positions. We do |
8004 // this to ensure that the cache entries can survive garbage | 8012 // this to ensure that the cache entries can survive garbage |
8005 // collection. | 8013 // collection. |
8006 Script* script = Script::cast(shared->script()); | 8014 Script* script = Script::cast(shared->script()); |
8007 hash ^= String::cast(script->source())->Hash(); | 8015 hash ^= String::cast(script->source())->Hash(); |
| 8016 if (strict_mode == kStrictMode) hash ^= 0x8000; |
8008 hash += shared->start_position(); | 8017 hash += shared->start_position(); |
8009 } | 8018 } |
8010 return hash; | 8019 return hash; |
8011 } | 8020 } |
8012 | 8021 |
8013 uint32_t Hash() { | 8022 uint32_t Hash() { |
8014 return StringSharedHashHelper(source_, shared_); | 8023 return StringSharedHashHelper(source_, shared_, strict_mode_); |
8015 } | 8024 } |
8016 | 8025 |
8017 uint32_t HashForObject(Object* obj) { | 8026 uint32_t HashForObject(Object* obj) { |
8018 FixedArray* pair = FixedArray::cast(obj); | 8027 FixedArray* pair = FixedArray::cast(obj); |
8019 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); | 8028 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); |
8020 String* source = String::cast(pair->get(1)); | 8029 String* source = String::cast(pair->get(1)); |
8021 return StringSharedHashHelper(source, shared); | 8030 StrictModeFlag strict_mode = static_cast<StrictModeFlag>( |
| 8031 Smi::cast(pair->get(2))->value()); |
| 8032 return StringSharedHashHelper(source, shared, strict_mode); |
8022 } | 8033 } |
8023 | 8034 |
8024 MUST_USE_RESULT MaybeObject* AsObject() { | 8035 MUST_USE_RESULT MaybeObject* AsObject() { |
8025 Object* obj; | 8036 Object* obj; |
8026 { MaybeObject* maybe_obj = Heap::AllocateFixedArray(2); | 8037 { MaybeObject* maybe_obj = Heap::AllocateFixedArray(3); |
8027 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 8038 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
8028 } | 8039 } |
8029 FixedArray* pair = FixedArray::cast(obj); | 8040 FixedArray* pair = FixedArray::cast(obj); |
8030 pair->set(0, shared_); | 8041 pair->set(0, shared_); |
8031 pair->set(1, source_); | 8042 pair->set(1, source_); |
| 8043 pair->set(2, Smi::FromInt(strict_mode_)); |
8032 return pair; | 8044 return pair; |
8033 } | 8045 } |
8034 | 8046 |
8035 private: | 8047 private: |
8036 String* source_; | 8048 String* source_; |
8037 SharedFunctionInfo* shared_; | 8049 SharedFunctionInfo* shared_; |
| 8050 StrictModeFlag strict_mode_; |
8038 }; | 8051 }; |
8039 | 8052 |
8040 | 8053 |
8041 // RegExpKey carries the source and flags of a regular expression as key. | 8054 // RegExpKey carries the source and flags of a regular expression as key. |
8042 class RegExpKey : public HashTableKey { | 8055 class RegExpKey : public HashTableKey { |
8043 public: | 8056 public: |
8044 RegExpKey(String* string, JSRegExp::Flags flags) | 8057 RegExpKey(String* string, JSRegExp::Flags flags) |
8045 : string_(string), | 8058 : string_(string), |
8046 flags_(Smi::FromInt(flags.value())) { } | 8059 flags_(Smi::FromInt(flags.value())) { } |
8047 | 8060 |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8986 | 8999 |
8987 | 9000 |
8988 Object* CompilationCacheTable::Lookup(String* src) { | 9001 Object* CompilationCacheTable::Lookup(String* src) { |
8989 StringKey key(src); | 9002 StringKey key(src); |
8990 int entry = FindEntry(&key); | 9003 int entry = FindEntry(&key); |
8991 if (entry == kNotFound) return Heap::undefined_value(); | 9004 if (entry == kNotFound) return Heap::undefined_value(); |
8992 return get(EntryToIndex(entry) + 1); | 9005 return get(EntryToIndex(entry) + 1); |
8993 } | 9006 } |
8994 | 9007 |
8995 | 9008 |
8996 Object* CompilationCacheTable::LookupEval(String* src, Context* context) { | 9009 Object* CompilationCacheTable::LookupEval(String* src, |
8997 StringSharedKey key(src, context->closure()->shared()); | 9010 Context* context, |
| 9011 StrictModeFlag strict_mode) { |
| 9012 StringSharedKey key(src, context->closure()->shared(), strict_mode); |
8998 int entry = FindEntry(&key); | 9013 int entry = FindEntry(&key); |
8999 if (entry == kNotFound) return Heap::undefined_value(); | 9014 if (entry == kNotFound) return Heap::undefined_value(); |
9000 return get(EntryToIndex(entry) + 1); | 9015 return get(EntryToIndex(entry) + 1); |
9001 } | 9016 } |
9002 | 9017 |
9003 | 9018 |
9004 Object* CompilationCacheTable::LookupRegExp(String* src, | 9019 Object* CompilationCacheTable::LookupRegExp(String* src, |
9005 JSRegExp::Flags flags) { | 9020 JSRegExp::Flags flags) { |
9006 RegExpKey key(src, flags); | 9021 RegExpKey key(src, flags); |
9007 int entry = FindEntry(&key); | 9022 int entry = FindEntry(&key); |
(...skipping 14 matching lines...) Expand all Loading... |
9022 int entry = cache->FindInsertionEntry(key.Hash()); | 9037 int entry = cache->FindInsertionEntry(key.Hash()); |
9023 cache->set(EntryToIndex(entry), src); | 9038 cache->set(EntryToIndex(entry), src); |
9024 cache->set(EntryToIndex(entry) + 1, value); | 9039 cache->set(EntryToIndex(entry) + 1, value); |
9025 cache->ElementAdded(); | 9040 cache->ElementAdded(); |
9026 return cache; | 9041 return cache; |
9027 } | 9042 } |
9028 | 9043 |
9029 | 9044 |
9030 MaybeObject* CompilationCacheTable::PutEval(String* src, | 9045 MaybeObject* CompilationCacheTable::PutEval(String* src, |
9031 Context* context, | 9046 Context* context, |
9032 Object* value) { | 9047 SharedFunctionInfo* value) { |
9033 StringSharedKey key(src, context->closure()->shared()); | 9048 StringSharedKey key(src, |
| 9049 context->closure()->shared(), |
| 9050 value->strict_mode() ? kStrictMode : kNonStrictMode); |
9034 Object* obj; | 9051 Object* obj; |
9035 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); | 9052 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); |
9036 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 9053 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
9037 } | 9054 } |
9038 | 9055 |
9039 CompilationCacheTable* cache = | 9056 CompilationCacheTable* cache = |
9040 reinterpret_cast<CompilationCacheTable*>(obj); | 9057 reinterpret_cast<CompilationCacheTable*>(obj); |
9041 int entry = cache->FindInsertionEntry(key.Hash()); | 9058 int entry = cache->FindInsertionEntry(key.Hash()); |
9042 | 9059 |
9043 Object* k; | 9060 Object* k; |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9867 if (break_point_objects()->IsUndefined()) return 0; | 9884 if (break_point_objects()->IsUndefined()) return 0; |
9868 // Single beak point. | 9885 // Single beak point. |
9869 if (!break_point_objects()->IsFixedArray()) return 1; | 9886 if (!break_point_objects()->IsFixedArray()) return 1; |
9870 // Multiple break points. | 9887 // Multiple break points. |
9871 return FixedArray::cast(break_point_objects())->length(); | 9888 return FixedArray::cast(break_point_objects())->length(); |
9872 } | 9889 } |
9873 #endif | 9890 #endif |
9874 | 9891 |
9875 | 9892 |
9876 } } // namespace v8::internal | 9893 } } // namespace v8::internal |
OLD | NEW |