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

Side by Side Diff: src/scopeinfo.cc

Issue 8221004: Move declaration of SerializedScopeInfo from variables.h to objects.h (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 function_name_ = proxy->name(); 131 function_name_ = proxy->name();
132 // Note that we must not find the function name in the context slot 132 // Note that we must not find the function name in the context slot
133 // list - instead it must be handled separately in the 133 // list - instead it must be handled separately in the
134 // Contexts::Lookup() function. Thus record an empty symbol here so we 134 // Contexts::Lookup() function. Thus record an empty symbol here so we
135 // get the correct number of context slots. 135 // get the correct number of context slots.
136 ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS == 136 ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS ==
137 context_slots_.length()); 137 context_slots_.length());
138 ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS == 138 ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS ==
139 context_modes_.length()); 139 context_modes_.length());
140 context_slots_.Add(FACTORY->empty_symbol()); 140 context_slots_.Add(FACTORY->empty_symbol());
141 context_modes_.Add(Variable::INTERNAL); 141 context_modes_.Add(INTERNAL);
142 } 142 }
143 } 143 }
144 } 144 }
145 145
146 146
147 // Encoding format in a FixedArray object: 147 // Encoding format in a FixedArray object:
148 // 148 //
149 // - function name 149 // - function name
150 // 150 //
151 // - calls eval boolean flag 151 // - calls eval boolean flag
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 p = ReadSymbol(p, &s); 209 p = ReadSymbol(p, &s);
210 list->Add(s); 210 list->Add(s);
211 } 211 }
212 return p; 212 return p;
213 } 213 }
214 214
215 215
216 template <class Allocator> 216 template <class Allocator>
217 static Object** ReadList(Object** p, 217 static Object** ReadList(Object** p,
218 List<Handle<String>, Allocator>* list, 218 List<Handle<String>, Allocator>* list,
219 List<Variable::Mode, Allocator>* modes) { 219 List<VariableMode, Allocator>* modes) {
220 ASSERT(list->is_empty()); 220 ASSERT(list->is_empty());
221 int n; 221 int n;
222 p = ReadInt(p, &n); 222 p = ReadInt(p, &n);
223 while (n-- > 0) { 223 while (n-- > 0) {
224 Handle<String> s; 224 Handle<String> s;
225 int m; 225 int m;
226 p = ReadSymbol(p, &s); 226 p = ReadSymbol(p, &s);
227 p = ReadInt(p, &m); 227 p = ReadInt(p, &m);
228 list->Add(s); 228 list->Add(s);
229 modes->Add(static_cast<Variable::Mode>(m)); 229 modes->Add(static_cast<VariableMode>(m));
230 } 230 }
231 return p; 231 return p;
232 } 232 }
233 233
234 234
235 template<class Allocator> 235 template<class Allocator>
236 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) 236 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data)
237 : function_name_(FACTORY->empty_symbol()), 237 : function_name_(FACTORY->empty_symbol()),
238 parameters_(4), 238 parameters_(4),
239 stack_slots_(8), 239 stack_slots_(8),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 for (int i = 0; i < n; i++) { 278 for (int i = 0; i < n; i++) {
279 p = WriteSymbol(p, list->at(i)); 279 p = WriteSymbol(p, list->at(i));
280 } 280 }
281 return p; 281 return p;
282 } 282 }
283 283
284 284
285 template <class Allocator> 285 template <class Allocator>
286 static Object** WriteList(Object** p, 286 static Object** WriteList(Object** p,
287 List<Handle<String>, Allocator>* list, 287 List<Handle<String>, Allocator>* list,
288 List<Variable::Mode, Allocator>* modes) { 288 List<VariableMode, Allocator>* modes) {
289 const int n = list->length(); 289 const int n = list->length();
290 p = WriteInt(p, n); 290 p = WriteInt(p, n);
291 for (int i = 0; i < n; i++) { 291 for (int i = 0; i < n; i++) {
292 p = WriteSymbol(p, list->at(i)); 292 p = WriteSymbol(p, list->at(i));
293 p = WriteInt(p, modes->at(i)); 293 p = WriteInt(p, modes->at(i));
294 } 294 }
295 return p; 295 return p;
296 } 296 }
297 297
298 298
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 Object** p = p0; 449 Object** p = p0;
450 Object** end = p0 + number_of_stack_slots; 450 Object** end = p0 + number_of_stack_slots;
451 while (p != end) { 451 while (p != end) {
452 if (*p == name) return static_cast<int>(p - p0); 452 if (*p == name) return static_cast<int>(p - p0);
453 p++; 453 p++;
454 } 454 }
455 } 455 }
456 return -1; 456 return -1;
457 } 457 }
458 458
459 int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { 459 int SerializedScopeInfo::ContextSlotIndex(String* name, VariableMode* mode) {
460 ASSERT(name->IsSymbol()); 460 ASSERT(name->IsSymbol());
461 Isolate* isolate = GetIsolate(); 461 Isolate* isolate = GetIsolate();
462 int result = isolate->context_slot_cache()->Lookup(this, name, mode); 462 int result = isolate->context_slot_cache()->Lookup(this, name, mode);
463 if (result != ContextSlotCache::kNotFound) return result; 463 if (result != ContextSlotCache::kNotFound) return result;
464 if (length() > 0) { 464 if (length() > 0) {
465 // Slots start after length entry. 465 // Slots start after length entry.
466 Object** p0 = ContextEntriesAddr(); 466 Object** p0 = ContextEntriesAddr();
467 int number_of_context_slots; 467 int number_of_context_slots;
468 p0 = ReadInt(p0, &number_of_context_slots); 468 p0 = ReadInt(p0, &number_of_context_slots);
469 Object** p = p0; 469 Object** p = p0;
470 Object** end = p0 + number_of_context_slots * 2; 470 Object** end = p0 + number_of_context_slots * 2;
471 while (p != end) { 471 while (p != end) {
472 if (*p == name) { 472 if (*p == name) {
473 ASSERT(((p - p0) & 1) == 0); 473 ASSERT(((p - p0) & 1) == 0);
474 int v; 474 int v;
475 ReadInt(p + 1, &v); 475 ReadInt(p + 1, &v);
476 Variable::Mode mode_value = static_cast<Variable::Mode>(v); 476 VariableMode mode_value = static_cast<VariableMode>(v);
477 if (mode != NULL) *mode = mode_value; 477 if (mode != NULL) *mode = mode_value;
478 result = static_cast<int>((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; 478 result = static_cast<int>((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS;
479 isolate->context_slot_cache()->Update(this, name, mode_value, result); 479 isolate->context_slot_cache()->Update(this, name, mode_value, result);
480 return result; 480 return result;
481 } 481 }
482 p += 2; 482 p += 2;
483 } 483 }
484 } 484 }
485 isolate->context_slot_cache()->Update(this, name, Variable::INTERNAL, -1); 485 isolate->context_slot_cache()->Update(this, name, INTERNAL, -1);
486 return -1; 486 return -1;
487 } 487 }
488 488
489 489
490 int SerializedScopeInfo::ParameterIndex(String* name) { 490 int SerializedScopeInfo::ParameterIndex(String* name) {
491 ASSERT(name->IsSymbol()); 491 ASSERT(name->IsSymbol());
492 if (length() > 0) { 492 if (length() > 0) {
493 // We must read parameters from the end since for 493 // We must read parameters from the end since for
494 // multiply declared parameters the value of the 494 // multiply declared parameters the value of the
495 // last declaration of that parameter is used 495 // last declaration of that parameter is used
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 int ContextSlotCache::Hash(Object* data, String* name) { 533 int ContextSlotCache::Hash(Object* data, String* name) {
534 // Uses only lower 32 bits if pointers are larger. 534 // Uses only lower 32 bits if pointers are larger.
535 uintptr_t addr_hash = 535 uintptr_t addr_hash =
536 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(data)) >> 2; 536 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(data)) >> 2;
537 return static_cast<int>((addr_hash ^ name->Hash()) % kLength); 537 return static_cast<int>((addr_hash ^ name->Hash()) % kLength);
538 } 538 }
539 539
540 540
541 int ContextSlotCache::Lookup(Object* data, 541 int ContextSlotCache::Lookup(Object* data,
542 String* name, 542 String* name,
543 Variable::Mode* mode) { 543 VariableMode* mode) {
544 int index = Hash(data, name); 544 int index = Hash(data, name);
545 Key& key = keys_[index]; 545 Key& key = keys_[index];
546 if ((key.data == data) && key.name->Equals(name)) { 546 if ((key.data == data) && key.name->Equals(name)) {
547 Value result(values_[index]); 547 Value result(values_[index]);
548 if (mode != NULL) *mode = result.mode(); 548 if (mode != NULL) *mode = result.mode();
549 return result.index() + kNotFound; 549 return result.index() + kNotFound;
550 } 550 }
551 return kNotFound; 551 return kNotFound;
552 } 552 }
553 553
554 554
555 void ContextSlotCache::Update(Object* data, 555 void ContextSlotCache::Update(Object* data,
556 String* name, 556 String* name,
557 Variable::Mode mode, 557 VariableMode mode,
558 int slot_index) { 558 int slot_index) {
559 String* symbol; 559 String* symbol;
560 ASSERT(slot_index > kNotFound); 560 ASSERT(slot_index > kNotFound);
561 if (HEAP->LookupSymbolIfExists(name, &symbol)) { 561 if (HEAP->LookupSymbolIfExists(name, &symbol)) {
562 int index = Hash(data, symbol); 562 int index = Hash(data, symbol);
563 Key& key = keys_[index]; 563 Key& key = keys_[index];
564 key.data = data; 564 key.data = data;
565 key.name = symbol; 565 key.name = symbol;
566 // Please note value only takes a uint as index. 566 // Please note value only takes a uint as index.
567 values_[index] = Value(mode, slot_index - kNotFound).raw(); 567 values_[index] = Value(mode, slot_index - kNotFound).raw();
568 #ifdef DEBUG 568 #ifdef DEBUG
569 ValidateEntry(data, name, mode, slot_index); 569 ValidateEntry(data, name, mode, slot_index);
570 #endif 570 #endif
571 } 571 }
572 } 572 }
573 573
574 574
575 void ContextSlotCache::Clear() { 575 void ContextSlotCache::Clear() {
576 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; 576 for (int index = 0; index < kLength; index++) keys_[index].data = NULL;
577 } 577 }
578 578
579 579
580 #ifdef DEBUG 580 #ifdef DEBUG
581 581
582 void ContextSlotCache::ValidateEntry(Object* data, 582 void ContextSlotCache::ValidateEntry(Object* data,
583 String* name, 583 String* name,
584 Variable::Mode mode, 584 VariableMode mode,
585 int slot_index) { 585 int slot_index) {
586 String* symbol; 586 String* symbol;
587 if (HEAP->LookupSymbolIfExists(name, &symbol)) { 587 if (HEAP->LookupSymbolIfExists(name, &symbol)) {
588 int index = Hash(data, name); 588 int index = Hash(data, name);
589 Key& key = keys_[index]; 589 Key& key = keys_[index];
590 ASSERT(key.data == data); 590 ASSERT(key.data == data);
591 ASSERT(key.name->Equals(name)); 591 ASSERT(key.name->Equals(name));
592 Value result(values_[index]); 592 Value result(values_[index]);
593 ASSERT(result.mode() == mode); 593 ASSERT(result.mode() == mode);
594 ASSERT(result.index() + kNotFound == slot_index); 594 ASSERT(result.index() + kNotFound == slot_index);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 632 }
633 #endif // DEBUG 633 #endif // DEBUG
634 634
635 635
636 // Make sure the classes get instantiated by the template system. 636 // Make sure the classes get instantiated by the template system.
637 template class ScopeInfo<FreeStoreAllocationPolicy>; 637 template class ScopeInfo<FreeStoreAllocationPolicy>;
638 template class ScopeInfo<PreallocatedStorage>; 638 template class ScopeInfo<PreallocatedStorage>;
639 template class ScopeInfo<ZoneListAllocationPolicy>; 639 template class ScopeInfo<ZoneListAllocationPolicy>;
640 640
641 } } // namespace v8::internal 641 } } // namespace v8::internal
OLDNEW
« src/parser.cc ('K') | « src/scopeinfo.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698