OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 23 matching lines...) Expand all Loading... | |
34 | 34 |
35 static bool Match(void* key1, void* key2) { | 35 static bool Match(void* key1, void* key2) { |
36 String* name1 = *static_cast<String**>(key1); | 36 String* name1 = *static_cast<String**>(key1); |
37 String* name2 = *static_cast<String**>(key2); | 37 String* name2 = *static_cast<String**>(key2); |
38 ASSERT(name1->IsSymbol()); | 38 ASSERT(name1->IsSymbol()); |
39 ASSERT(name2->IsSymbol()); | 39 ASSERT(name2->IsSymbol()); |
40 return name1 == name2; | 40 return name1 == name2; |
41 } | 41 } |
42 | 42 |
43 | 43 |
44 Interface* Interface::Lookup(Handle<String> name) { | 44 Interface* Interface::Lookup(Handle<String> name, Zone* zone) { |
45 ASSERT(IsModule()); | 45 ASSERT(IsModule()); |
46 ZoneHashMap* map = Chase()->exports_; | 46 ZoneHashMap* map = Chase()->exports_; |
47 if (map == NULL) return NULL; | 47 if (map == NULL) return NULL; |
48 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false); | 48 ZoneAllocationPolicy allocator(zone); |
49 ZoneHashMap::Entry* p = map->Lookup(name.location(), name->Hash(), false, | |
50 allocator); | |
49 if (p == NULL) return NULL; | 51 if (p == NULL) return NULL; |
50 ASSERT(*static_cast<String**>(p->key) == *name); | 52 ASSERT(*static_cast<String**>(p->key) == *name); |
51 ASSERT(p->value != NULL); | 53 ASSERT(p->value != NULL); |
52 return static_cast<Interface*>(p->value); | 54 return static_cast<Interface*>(p->value); |
53 } | 55 } |
54 | 56 |
55 | 57 |
56 #ifdef DEBUG | 58 #ifdef DEBUG |
57 // Current nesting depth for debug output. | 59 // Current nesting depth for debug output. |
58 class Nesting { | 60 class Nesting { |
59 public: | 61 public: |
60 Nesting() { current_ += 2; } | 62 Nesting() { current_ += 2; } |
61 ~Nesting() { current_ -= 2; } | 63 ~Nesting() { current_ -= 2; } |
62 static int current() { return current_; } | 64 static int current() { return current_; } |
63 private: | 65 private: |
64 static int current_; | 66 static int current_; |
65 }; | 67 }; |
66 | 68 |
67 int Nesting::current_ = 0; | 69 int Nesting::current_ = 0; |
68 #endif | 70 #endif |
69 | 71 |
70 | 72 |
71 void Interface::DoAdd( | 73 void Interface::DoAdd( |
72 void* name, uint32_t hash, Interface* interface, bool* ok) { | 74 void* name, uint32_t hash, Interface* interface, bool* ok, Zone* zone) { |
73 MakeModule(ok); | 75 MakeModule(ok); |
74 if (!*ok) return; | 76 if (!*ok) return; |
75 | 77 |
76 #ifdef DEBUG | 78 #ifdef DEBUG |
77 if (FLAG_print_interface_details) { | 79 if (FLAG_print_interface_details) { |
78 PrintF("%*s# Adding...\n", Nesting::current(), ""); | 80 PrintF("%*s# Adding...\n", Nesting::current(), ""); |
79 PrintF("%*sthis = ", Nesting::current(), ""); | 81 PrintF("%*sthis = ", Nesting::current(), ""); |
80 this->Print(Nesting::current()); | 82 this->Print(Nesting::current()); |
81 PrintF("%*s%s : ", Nesting::current(), "", | 83 PrintF("%*s%s : ", Nesting::current(), "", |
82 (*static_cast<String**>(name))->ToAsciiArray()); | 84 (*static_cast<String**>(name))->ToAsciiArray()); |
83 interface->Print(Nesting::current()); | 85 interface->Print(Nesting::current()); |
84 } | 86 } |
85 #endif | 87 #endif |
86 | 88 |
87 ZoneHashMap** map = &Chase()->exports_; | 89 ZoneHashMap** map = &Chase()->exports_; |
88 if (*map == NULL) *map = new ZoneHashMap(Match, 8); | 90 ZoneAllocationPolicy allocator(zone); |
89 | 91 |
90 ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen()); | 92 if (*map == NULL) |
93 *map = new ZoneHashMap(Match, 8, allocator); | |
danno
2012/06/05 13:42:35
Constant for default argument
sanjoy
2012/06/05 14:21:39
Fixed.
| |
94 | |
95 ZoneHashMap::Entry* p = (*map)->Lookup(name, hash, !IsFrozen(), allocator); | |
91 if (p == NULL) { | 96 if (p == NULL) { |
92 // This didn't have name but was frozen already, that's an error. | 97 // This didn't have name but was frozen already, that's an error. |
93 *ok = false; | 98 *ok = false; |
94 } else if (p->value == NULL) { | 99 } else if (p->value == NULL) { |
95 p->value = interface; | 100 p->value = interface; |
96 } else { | 101 } else { |
97 #ifdef DEBUG | 102 #ifdef DEBUG |
98 Nesting nested; | 103 Nesting nested; |
99 #endif | 104 #endif |
100 static_cast<Interface*>(p->value)->Unify(interface, ok); | 105 static_cast<Interface*>(p->value)->Unify(interface, ok, zone); |
101 } | 106 } |
102 | 107 |
103 #ifdef DEBUG | 108 #ifdef DEBUG |
104 if (FLAG_print_interface_details) { | 109 if (FLAG_print_interface_details) { |
105 PrintF("%*sthis' = ", Nesting::current(), ""); | 110 PrintF("%*sthis' = ", Nesting::current(), ""); |
106 this->Print(Nesting::current()); | 111 this->Print(Nesting::current()); |
107 PrintF("%*s# Added.\n", Nesting::current(), ""); | 112 PrintF("%*s# Added.\n", Nesting::current(), ""); |
108 } | 113 } |
109 #endif | 114 #endif |
110 } | 115 } |
111 | 116 |
112 | 117 |
113 void Interface::Unify(Interface* that, bool* ok) { | 118 void Interface::Unify(Interface* that, bool* ok, Zone* zone) { |
114 if (this->forward_) return this->Chase()->Unify(that, ok); | 119 if (this->forward_) return this->Chase()->Unify(that, ok, zone); |
115 if (that->forward_) return this->Unify(that->Chase(), ok); | 120 if (that->forward_) return this->Unify(that->Chase(), ok, zone); |
116 ASSERT(this->forward_ == NULL); | 121 ASSERT(this->forward_ == NULL); |
117 ASSERT(that->forward_ == NULL); | 122 ASSERT(that->forward_ == NULL); |
118 | 123 |
119 *ok = true; | 124 *ok = true; |
120 if (this == that) return; | 125 if (this == that) return; |
121 if (this->IsValue()) return that->MakeValue(ok); | 126 if (this->IsValue()) return that->MakeValue(ok); |
122 if (that->IsValue()) return this->MakeValue(ok); | 127 if (that->IsValue()) return this->MakeValue(ok); |
123 | 128 |
124 #ifdef DEBUG | 129 #ifdef DEBUG |
125 if (FLAG_print_interface_details) { | 130 if (FLAG_print_interface_details) { |
126 PrintF("%*s# Unifying...\n", Nesting::current(), ""); | 131 PrintF("%*s# Unifying...\n", Nesting::current(), ""); |
127 PrintF("%*sthis = ", Nesting::current(), ""); | 132 PrintF("%*sthis = ", Nesting::current(), ""); |
128 this->Print(Nesting::current()); | 133 this->Print(Nesting::current()); |
129 PrintF("%*sthat = ", Nesting::current(), ""); | 134 PrintF("%*sthat = ", Nesting::current(), ""); |
130 that->Print(Nesting::current()); | 135 that->Print(Nesting::current()); |
131 } | 136 } |
132 #endif | 137 #endif |
133 | 138 |
134 // Merge the smaller interface into the larger, for performance. | 139 // Merge the smaller interface into the larger, for performance. |
135 if (this->exports_ != NULL && (that->exports_ == NULL || | 140 if (this->exports_ != NULL && (that->exports_ == NULL || |
136 this->exports_->occupancy() >= that->exports_->occupancy())) { | 141 this->exports_->occupancy() >= that->exports_->occupancy())) { |
137 this->DoUnify(that, ok); | 142 this->DoUnify(that, ok, zone); |
138 } else { | 143 } else { |
139 that->DoUnify(this, ok); | 144 that->DoUnify(this, ok, zone); |
140 } | 145 } |
141 | 146 |
142 #ifdef DEBUG | 147 #ifdef DEBUG |
143 if (FLAG_print_interface_details) { | 148 if (FLAG_print_interface_details) { |
144 PrintF("%*sthis' = ", Nesting::current(), ""); | 149 PrintF("%*sthis' = ", Nesting::current(), ""); |
145 this->Print(Nesting::current()); | 150 this->Print(Nesting::current()); |
146 PrintF("%*sthat' = ", Nesting::current(), ""); | 151 PrintF("%*sthat' = ", Nesting::current(), ""); |
147 that->Print(Nesting::current()); | 152 that->Print(Nesting::current()); |
148 PrintF("%*s# Unified.\n", Nesting::current(), ""); | 153 PrintF("%*s# Unified.\n", Nesting::current(), ""); |
149 } | 154 } |
150 #endif | 155 #endif |
151 } | 156 } |
152 | 157 |
153 | 158 |
154 void Interface::DoUnify(Interface* that, bool* ok) { | 159 void Interface::DoUnify(Interface* that, bool* ok, Zone* zone) { |
155 ASSERT(this->forward_ == NULL); | 160 ASSERT(this->forward_ == NULL); |
156 ASSERT(that->forward_ == NULL); | 161 ASSERT(that->forward_ == NULL); |
157 ASSERT(!this->IsValue()); | 162 ASSERT(!this->IsValue()); |
158 ASSERT(!that->IsValue()); | 163 ASSERT(!that->IsValue()); |
159 ASSERT(*ok); | 164 ASSERT(*ok); |
160 | 165 |
161 #ifdef DEBUG | 166 #ifdef DEBUG |
162 Nesting nested; | 167 Nesting nested; |
163 #endif | 168 #endif |
164 | 169 |
165 // Try to merge all members from that into this. | 170 // Try to merge all members from that into this. |
166 ZoneHashMap* map = that->exports_; | 171 ZoneHashMap* map = that->exports_; |
167 if (map != NULL) { | 172 if (map != NULL) { |
168 for (ZoneHashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) { | 173 for (ZoneHashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) { |
169 this->DoAdd(p->key, p->hash, static_cast<Interface*>(p->value), ok); | 174 this->DoAdd(p->key, p->hash, static_cast<Interface*>(p->value), ok, zone); |
170 if (!*ok) return; | 175 if (!*ok) return; |
171 } | 176 } |
172 } | 177 } |
173 | 178 |
174 // If the new interface is larger than that's, then there were members in | 179 // If the new interface is larger than that's, then there were members in |
175 // 'this' which 'that' didn't have. If 'that' was frozen that is an error. | 180 // 'this' which 'that' didn't have. If 'that' was frozen that is an error. |
176 int this_size = this->exports_ == NULL ? 0 : this->exports_->occupancy(); | 181 int this_size = this->exports_ == NULL ? 0 : this->exports_->occupancy(); |
177 int that_size = map == NULL ? 0 : map->occupancy(); | 182 int that_size = map == NULL ? 0 : map->occupancy(); |
178 if (that->IsFrozen() && this_size > that_size) { | 183 if (that->IsFrozen() && this_size > that_size) { |
179 *ok = false; | 184 *ok = false; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); | 231 PrintF("%*s%s : ", n0 + 2, "", name->ToAsciiArray()); |
227 interface->Print(n0 + 2); | 232 interface->Print(n0 + 2); |
228 } | 233 } |
229 PrintF("%*s}\n", n0, ""); | 234 PrintF("%*s}\n", n0, ""); |
230 } | 235 } |
231 } | 236 } |
232 } | 237 } |
233 #endif | 238 #endif |
234 | 239 |
235 } } // namespace v8::internal | 240 } } // namespace v8::internal |
OLD | NEW |