Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: src/ast/context-slot-cache.cc

Issue 2287783003: Revert of Always deserialize scope infos for parsing (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/context-slot-cache.h ('k') | src/ast/scopeinfo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/ast/context-slot-cache.h"
6
7 #include <stdlib.h>
8
9 #include "src/ast/scopes.h"
10 #include "src/bootstrapper.h"
11
12 namespace v8 {
13 namespace internal {
14
15 int ContextSlotCache::Hash(Object* data, String* name) {
16 // Uses only lower 32 bits if pointers are larger.
17 uintptr_t addr_hash =
18 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(data)) >> 2;
19 return static_cast<int>((addr_hash ^ name->Hash()) % kLength);
20 }
21
22 int ContextSlotCache::Lookup(Object* data, String* name, VariableMode* mode,
23 InitializationFlag* init_flag,
24 MaybeAssignedFlag* maybe_assigned_flag) {
25 int index = Hash(data, name);
26 Key& key = keys_[index];
27 if ((key.data == data) && key.name->Equals(name)) {
28 Value result(values_[index]);
29 if (mode != nullptr) *mode = result.mode();
30 if (init_flag != nullptr) *init_flag = result.initialization_flag();
31 if (maybe_assigned_flag != nullptr)
32 *maybe_assigned_flag = result.maybe_assigned_flag();
33 return result.index() + kNotFound;
34 }
35 return kNotFound;
36 }
37
38 void ContextSlotCache::Update(Handle<Object> data, Handle<String> name,
39 VariableMode mode, InitializationFlag init_flag,
40 MaybeAssignedFlag maybe_assigned_flag,
41 int slot_index) {
42 DisallowHeapAllocation no_gc;
43 Handle<String> internalized_name;
44 DCHECK(slot_index > kNotFound);
45 if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name)
46 .ToHandle(&internalized_name)) {
47 int index = Hash(*data, *internalized_name);
48 Key& key = keys_[index];
49 key.data = *data;
50 key.name = *internalized_name;
51 // Please note value only takes a uint as index.
52 values_[index] =
53 Value(mode, init_flag, maybe_assigned_flag, slot_index - kNotFound)
54 .raw();
55 #ifdef DEBUG
56 ValidateEntry(data, name, mode, init_flag, maybe_assigned_flag, slot_index);
57 #endif
58 }
59 }
60
61 void ContextSlotCache::Clear() {
62 for (int index = 0; index < kLength; index++) keys_[index].data = nullptr;
63 }
64
65 #ifdef DEBUG
66
67 void ContextSlotCache::ValidateEntry(Handle<Object> data, Handle<String> name,
68 VariableMode mode,
69 InitializationFlag init_flag,
70 MaybeAssignedFlag maybe_assigned_flag,
71 int slot_index) {
72 DisallowHeapAllocation no_gc;
73 Handle<String> internalized_name;
74 if (StringTable::InternalizeStringIfExists(name->GetIsolate(), name)
75 .ToHandle(&internalized_name)) {
76 int index = Hash(*data, *name);
77 Key& key = keys_[index];
78 DCHECK(key.data == *data);
79 DCHECK(key.name->Equals(*name));
80 Value result(values_[index]);
81 DCHECK(result.mode() == mode);
82 DCHECK(result.initialization_flag() == init_flag);
83 DCHECK(result.maybe_assigned_flag() == maybe_assigned_flag);
84 DCHECK(result.index() + kNotFound == slot_index);
85 }
86 }
87
88 #endif // DEBUG
89
90 } // namespace internal
91 } // namespace v8
OLDNEW
« no previous file with comments | « src/ast/context-slot-cache.h ('k') | src/ast/scopeinfo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698