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, SharedFunctionInfo* shared, bool strict) |
7986 : source_(source), shared_(shared) { } | 7986 : source_(source), shared_(shared), strict_(strict) { } |
7987 | 7987 |
7988 bool IsMatch(Object* other) { | 7988 bool IsMatch(Object* other) { |
7989 if (!other->IsFixedArray()) return false; | 7989 if (!other->IsFixedArray()) return false; |
7990 FixedArray* pair = FixedArray::cast(other); | 7990 FixedArray* pair = FixedArray::cast(other); |
7991 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); | 7991 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); |
7992 if (shared != shared_) return false; | 7992 if (shared != shared_) return false; |
7993 bool strict = Smi::cast(pair->get(2))->value() != 0; | |
Lasse Reichstein
2011/02/03 12:36:01
Do you need to store the strictness in a separate
Martin Maly
2011/02/04 01:02:34
I believe I do need to store the strict flag. The
| |
7994 if (strict != strict_) return false; | |
7993 String* source = String::cast(pair->get(1)); | 7995 String* source = String::cast(pair->get(1)); |
7994 return source->Equals(source_); | 7996 return source->Equals(source_); |
7995 } | 7997 } |
7996 | 7998 |
7997 static uint32_t StringSharedHashHelper(String* source, | 7999 static uint32_t StringSharedHashHelper(String* source, |
7998 SharedFunctionInfo* shared) { | 8000 SharedFunctionInfo* shared, |
8001 bool strict) { | |
7999 uint32_t hash = source->Hash(); | 8002 uint32_t hash = source->Hash(); |
8000 if (shared->HasSourceCode()) { | 8003 if (shared->HasSourceCode()) { |
8001 // Instead of using the SharedFunctionInfo pointer in the hash | 8004 // Instead of using the SharedFunctionInfo pointer in the hash |
8002 // code computation, we use a combination of the hash of the | 8005 // code computation, we use a combination of the hash of the |
8003 // script source code and the start and end positions. We do | 8006 // script source code and the start and end positions. We do |
8004 // this to ensure that the cache entries can survive garbage | 8007 // this to ensure that the cache entries can survive garbage |
8005 // collection. | 8008 // collection. |
8006 Script* script = Script::cast(shared->script()); | 8009 Script* script = Script::cast(shared->script()); |
8007 hash ^= String::cast(script->source())->Hash(); | 8010 hash ^= String::cast(script->source())->Hash(); |
8011 hash ^= strict ? 0x8000 : 0x800; | |
Martin Maly
2011/02/02 23:56:22
Just a guess, there may be better (or more V8 code
Lasse Reichstein
2011/02/03 12:36:01
I don't think it matters what you do for strict-mo
Martin Maly
2011/02/04 01:02:34
Done.
| |
8008 hash += shared->start_position(); | 8012 hash += shared->start_position(); |
8009 } | 8013 } |
8010 return hash; | 8014 return hash; |
8011 } | 8015 } |
8012 | 8016 |
8013 uint32_t Hash() { | 8017 uint32_t Hash() { |
8014 return StringSharedHashHelper(source_, shared_); | 8018 return StringSharedHashHelper(source_, shared_, strict_); |
8015 } | 8019 } |
8016 | 8020 |
8017 uint32_t HashForObject(Object* obj) { | 8021 uint32_t HashForObject(Object* obj) { |
8018 FixedArray* pair = FixedArray::cast(obj); | 8022 FixedArray* pair = FixedArray::cast(obj); |
8019 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); | 8023 SharedFunctionInfo* shared = SharedFunctionInfo::cast(pair->get(0)); |
8020 String* source = String::cast(pair->get(1)); | 8024 String* source = String::cast(pair->get(1)); |
8021 return StringSharedHashHelper(source, shared); | 8025 bool strict = Smi::cast(pair->get(2))->value() != 0; |
8026 return StringSharedHashHelper(source, shared, strict); | |
8022 } | 8027 } |
8023 | 8028 |
8024 MUST_USE_RESULT MaybeObject* AsObject() { | 8029 MUST_USE_RESULT MaybeObject* AsObject() { |
8025 Object* obj; | 8030 Object* obj; |
8026 { MaybeObject* maybe_obj = Heap::AllocateFixedArray(2); | 8031 { MaybeObject* maybe_obj = Heap::AllocateFixedArray(3); |
8027 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 8032 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
8028 } | 8033 } |
8029 FixedArray* pair = FixedArray::cast(obj); | 8034 FixedArray* pair = FixedArray::cast(obj); |
8030 pair->set(0, shared_); | 8035 pair->set(0, shared_); |
8031 pair->set(1, source_); | 8036 pair->set(1, source_); |
8037 pair->set(2, Smi::FromInt(strict_ ? 1 : 0)); | |
8032 return pair; | 8038 return pair; |
8033 } | 8039 } |
8034 | 8040 |
8035 private: | 8041 private: |
8036 String* source_; | 8042 String* source_; |
8037 SharedFunctionInfo* shared_; | 8043 SharedFunctionInfo* shared_; |
8044 bool strict_; | |
8038 }; | 8045 }; |
8039 | 8046 |
8040 | 8047 |
8041 // RegExpKey carries the source and flags of a regular expression as key. | 8048 // RegExpKey carries the source and flags of a regular expression as key. |
8042 class RegExpKey : public HashTableKey { | 8049 class RegExpKey : public HashTableKey { |
8043 public: | 8050 public: |
8044 RegExpKey(String* string, JSRegExp::Flags flags) | 8051 RegExpKey(String* string, JSRegExp::Flags flags) |
8045 : string_(string), | 8052 : string_(string), |
8046 flags_(Smi::FromInt(flags.value())) { } | 8053 flags_(Smi::FromInt(flags.value())) { } |
8047 | 8054 |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8986 | 8993 |
8987 | 8994 |
8988 Object* CompilationCacheTable::Lookup(String* src) { | 8995 Object* CompilationCacheTable::Lookup(String* src) { |
8989 StringKey key(src); | 8996 StringKey key(src); |
8990 int entry = FindEntry(&key); | 8997 int entry = FindEntry(&key); |
8991 if (entry == kNotFound) return Heap::undefined_value(); | 8998 if (entry == kNotFound) return Heap::undefined_value(); |
8992 return get(EntryToIndex(entry) + 1); | 8999 return get(EntryToIndex(entry) + 1); |
8993 } | 9000 } |
8994 | 9001 |
8995 | 9002 |
8996 Object* CompilationCacheTable::LookupEval(String* src, Context* context) { | 9003 Object* CompilationCacheTable::LookupEval(String* src, |
8997 StringSharedKey key(src, context->closure()->shared()); | 9004 Context* context, |
9005 bool is_strict) { | |
9006 StringSharedKey key(src, context->closure()->shared(), is_strict); | |
Martin Maly
2011/02/02 23:56:22
It seems weird that this function hashes by:
conte
Lasse Reichstein
2011/02/03 12:36:01
I'm not sure I understand the question.
You can ha
Martin Maly
2011/02/04 01:02:34
Makes sense, thanks for the explanation.
| |
8998 int entry = FindEntry(&key); | 9007 int entry = FindEntry(&key); |
8999 if (entry == kNotFound) return Heap::undefined_value(); | 9008 if (entry == kNotFound) return Heap::undefined_value(); |
9000 return get(EntryToIndex(entry) + 1); | 9009 return get(EntryToIndex(entry) + 1); |
9001 } | 9010 } |
9002 | 9011 |
9003 | 9012 |
9004 Object* CompilationCacheTable::LookupRegExp(String* src, | 9013 Object* CompilationCacheTable::LookupRegExp(String* src, |
9005 JSRegExp::Flags flags) { | 9014 JSRegExp::Flags flags) { |
9006 RegExpKey key(src, flags); | 9015 RegExpKey key(src, flags); |
9007 int entry = FindEntry(&key); | 9016 int entry = FindEntry(&key); |
(...skipping 14 matching lines...) Expand all Loading... | |
9022 int entry = cache->FindInsertionEntry(key.Hash()); | 9031 int entry = cache->FindInsertionEntry(key.Hash()); |
9023 cache->set(EntryToIndex(entry), src); | 9032 cache->set(EntryToIndex(entry), src); |
9024 cache->set(EntryToIndex(entry) + 1, value); | 9033 cache->set(EntryToIndex(entry) + 1, value); |
9025 cache->ElementAdded(); | 9034 cache->ElementAdded(); |
9026 return cache; | 9035 return cache; |
9027 } | 9036 } |
9028 | 9037 |
9029 | 9038 |
9030 MaybeObject* CompilationCacheTable::PutEval(String* src, | 9039 MaybeObject* CompilationCacheTable::PutEval(String* src, |
9031 Context* context, | 9040 Context* context, |
9032 Object* value) { | 9041 SharedFunctionInfo* value) { |
9033 StringSharedKey key(src, context->closure()->shared()); | 9042 StringSharedKey key(src, |
9043 context->closure()->shared(), | |
9044 value->strict_mode()); | |
9034 Object* obj; | 9045 Object* obj; |
9035 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); | 9046 { MaybeObject* maybe_obj = EnsureCapacity(1, &key); |
9036 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 9047 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
9037 } | 9048 } |
9038 | 9049 |
9039 CompilationCacheTable* cache = | 9050 CompilationCacheTable* cache = |
9040 reinterpret_cast<CompilationCacheTable*>(obj); | 9051 reinterpret_cast<CompilationCacheTable*>(obj); |
9041 int entry = cache->FindInsertionEntry(key.Hash()); | 9052 int entry = cache->FindInsertionEntry(key.Hash()); |
9042 | 9053 |
9043 Object* k; | 9054 Object* k; |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9867 if (break_point_objects()->IsUndefined()) return 0; | 9878 if (break_point_objects()->IsUndefined()) return 0; |
9868 // Single beak point. | 9879 // Single beak point. |
9869 if (!break_point_objects()->IsFixedArray()) return 1; | 9880 if (!break_point_objects()->IsFixedArray()) return 1; |
9870 // Multiple break points. | 9881 // Multiple break points. |
9871 return FixedArray::cast(break_point_objects())->length(); | 9882 return FixedArray::cast(break_point_objects())->length(); |
9872 } | 9883 } |
9873 #endif | 9884 #endif |
9874 | 9885 |
9875 | 9886 |
9876 } } // namespace v8::internal | 9887 } } // namespace v8::internal |
OLD | NEW |