OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 // and which may have a NULL slot... - find a better solution... | 43 // and which may have a NULL slot... - find a better solution... |
44 int x = (s != NULL ? s->index() : 0); | 44 int x = (s != NULL ? s->index() : 0); |
45 int y = (t != NULL ? t->index() : 0); | 45 int y = (t != NULL ? t->index() : 0); |
46 // Consider sorting them according to type as well? | 46 // Consider sorting them according to type as well? |
47 return x - y; | 47 return x - y; |
48 } | 48 } |
49 | 49 |
50 | 50 |
51 template<class Allocator> | 51 template<class Allocator> |
52 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) | 52 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) |
53 : function_name_(Factory::empty_symbol()), | 53 : function_name_(FACTORY->empty_symbol()), |
54 calls_eval_(scope->calls_eval()), | 54 calls_eval_(scope->calls_eval()), |
55 parameters_(scope->num_parameters()), | 55 parameters_(scope->num_parameters()), |
56 stack_slots_(scope->num_stack_slots()), | 56 stack_slots_(scope->num_stack_slots()), |
57 context_slots_(scope->num_heap_slots()), | 57 context_slots_(scope->num_heap_slots()), |
58 context_modes_(scope->num_heap_slots()) { | 58 context_modes_(scope->num_heap_slots()) { |
59 // Add parameters. | 59 // Add parameters. |
60 for (int i = 0; i < scope->num_parameters(); i++) { | 60 for (int i = 0; i < scope->num_parameters(); i++) { |
61 ASSERT(parameters_.length() == i); | 61 ASSERT(parameters_.length() == i); |
62 parameters_.Add(scope->parameter(i)->name()); | 62 parameters_.Add(scope->parameter(i)->name()); |
63 } | 63 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 var->AsSlot()->type() == Slot::CONTEXT) { | 134 var->AsSlot()->type() == Slot::CONTEXT) { |
135 function_name_ = var->name(); | 135 function_name_ = var->name(); |
136 // Note that we must not find the function name in the context slot | 136 // Note that we must not find the function name in the context slot |
137 // list - instead it must be handled separately in the | 137 // list - instead it must be handled separately in the |
138 // Contexts::Lookup() function. Thus record an empty symbol here so we | 138 // Contexts::Lookup() function. Thus record an empty symbol here so we |
139 // get the correct number of context slots. | 139 // get the correct number of context slots. |
140 ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == | 140 ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == |
141 context_slots_.length()); | 141 context_slots_.length()); |
142 ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == | 142 ASSERT(var->AsSlot()->index() - Context::MIN_CONTEXT_SLOTS == |
143 context_modes_.length()); | 143 context_modes_.length()); |
144 context_slots_.Add(Factory::empty_symbol()); | 144 context_slots_.Add(FACTORY->empty_symbol()); |
145 context_modes_.Add(Variable::INTERNAL); | 145 context_modes_.Add(Variable::INTERNAL); |
146 } | 146 } |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 // Encoding format in a FixedArray object: | 151 // Encoding format in a FixedArray object: |
152 // | 152 // |
153 // - function name | 153 // - function name |
154 // | 154 // |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 p = ReadInt(p, &m); | 231 p = ReadInt(p, &m); |
232 list->Add(s); | 232 list->Add(s); |
233 modes->Add(static_cast<Variable::Mode>(m)); | 233 modes->Add(static_cast<Variable::Mode>(m)); |
234 } | 234 } |
235 return p; | 235 return p; |
236 } | 236 } |
237 | 237 |
238 | 238 |
239 template<class Allocator> | 239 template<class Allocator> |
240 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) | 240 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) |
241 : function_name_(Factory::empty_symbol()), | 241 : function_name_(FACTORY->empty_symbol()), |
242 parameters_(4), | 242 parameters_(4), |
243 stack_slots_(8), | 243 stack_slots_(8), |
244 context_slots_(8), | 244 context_slots_(8), |
245 context_modes_(8) { | 245 context_modes_(8) { |
246 if (data->length() > 0) { | 246 if (data->length() > 0) { |
247 Object** p0 = data->data_start(); | 247 Object** p0 = data->data_start(); |
248 Object** p = p0; | 248 Object** p = p0; |
249 p = ReadSymbol(p, &function_name_); | 249 p = ReadSymbol(p, &function_name_); |
250 p = ReadBool(p, &calls_eval_); | 250 p = ReadBool(p, &calls_eval_); |
251 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 251 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 template<class Allocator> | 302 template<class Allocator> |
303 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { | 303 Handle<SerializedScopeInfo> ScopeInfo<Allocator>::Serialize() { |
304 // function name, calls eval, length for 3 tables: | 304 // function name, calls eval, length for 3 tables: |
305 const int extra_slots = 1 + 1 + 3; | 305 const int extra_slots = 1 + 1 + 3; |
306 int length = extra_slots + | 306 int length = extra_slots + |
307 context_slots_.length() * 2 + | 307 context_slots_.length() * 2 + |
308 parameters_.length() + | 308 parameters_.length() + |
309 stack_slots_.length(); | 309 stack_slots_.length(); |
310 | 310 |
311 Handle<SerializedScopeInfo> data( | 311 Handle<SerializedScopeInfo> data( |
312 SerializedScopeInfo::cast(*Factory::NewFixedArray(length, TENURED))); | 312 SerializedScopeInfo::cast(*FACTORY->NewFixedArray(length, TENURED))); |
313 AssertNoAllocation nogc; | 313 AssertNoAllocation nogc; |
314 | 314 |
315 Object** p0 = data->data_start(); | 315 Object** p0 = data->data_start(); |
316 Object** p = p0; | 316 Object** p = p0; |
317 p = WriteSymbol(p, function_name_); | 317 p = WriteSymbol(p, function_name_); |
318 p = WriteBool(p, calls_eval_); | 318 p = WriteBool(p, calls_eval_); |
319 p = WriteList(p, &context_slots_, &context_modes_); | 319 p = WriteList(p, &context_slots_, &context_modes_); |
320 p = WriteList(p, ¶meters_); | 320 p = WriteList(p, ¶meters_); |
321 p = WriteList(p, &stack_slots_); | 321 p = WriteList(p, &stack_slots_); |
322 ASSERT((p - p0) == length); | 322 ASSERT((p - p0) == length); |
(...skipping 27 matching lines...) Expand all Loading... |
350 } | 350 } |
351 | 351 |
352 | 352 |
353 Handle<SerializedScopeInfo> SerializedScopeInfo::Create(Scope* scope) { | 353 Handle<SerializedScopeInfo> SerializedScopeInfo::Create(Scope* scope) { |
354 ScopeInfo<ZoneListAllocationPolicy> sinfo(scope); | 354 ScopeInfo<ZoneListAllocationPolicy> sinfo(scope); |
355 return sinfo.Serialize(); | 355 return sinfo.Serialize(); |
356 } | 356 } |
357 | 357 |
358 | 358 |
359 SerializedScopeInfo* SerializedScopeInfo::Empty() { | 359 SerializedScopeInfo* SerializedScopeInfo::Empty() { |
360 return reinterpret_cast<SerializedScopeInfo*>(Heap::empty_fixed_array()); | 360 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); |
361 } | 361 } |
362 | 362 |
363 | 363 |
364 Object** SerializedScopeInfo::ContextEntriesAddr() { | 364 Object** SerializedScopeInfo::ContextEntriesAddr() { |
365 ASSERT(length() > 0); | 365 ASSERT(length() > 0); |
366 return data_start() + 2; // +2 for function name and calls eval. | 366 return data_start() + 2; // +2 for function name and calls eval. |
367 } | 367 } |
368 | 368 |
369 | 369 |
370 Object** SerializedScopeInfo::ParameterEntriesAddr() { | 370 Object** SerializedScopeInfo::ParameterEntriesAddr() { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 while (p != end) { | 441 while (p != end) { |
442 if (*p == name) return static_cast<int>(p - p0); | 442 if (*p == name) return static_cast<int>(p - p0); |
443 p++; | 443 p++; |
444 } | 444 } |
445 } | 445 } |
446 return -1; | 446 return -1; |
447 } | 447 } |
448 | 448 |
449 int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { | 449 int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { |
450 ASSERT(name->IsSymbol()); | 450 ASSERT(name->IsSymbol()); |
451 int result = ContextSlotCache::Lookup(this, name, mode); | 451 Isolate* isolate = GetIsolate(); |
| 452 int result = isolate->context_slot_cache()->Lookup(this, name, mode); |
452 if (result != ContextSlotCache::kNotFound) return result; | 453 if (result != ContextSlotCache::kNotFound) return result; |
453 if (length() > 0) { | 454 if (length() > 0) { |
454 // Slots start after length entry. | 455 // Slots start after length entry. |
455 Object** p0 = ContextEntriesAddr(); | 456 Object** p0 = ContextEntriesAddr(); |
456 int number_of_context_slots; | 457 int number_of_context_slots; |
457 p0 = ReadInt(p0, &number_of_context_slots); | 458 p0 = ReadInt(p0, &number_of_context_slots); |
458 Object** p = p0; | 459 Object** p = p0; |
459 Object** end = p0 + number_of_context_slots * 2; | 460 Object** end = p0 + number_of_context_slots * 2; |
460 while (p != end) { | 461 while (p != end) { |
461 if (*p == name) { | 462 if (*p == name) { |
462 ASSERT(((p - p0) & 1) == 0); | 463 ASSERT(((p - p0) & 1) == 0); |
463 int v; | 464 int v; |
464 ReadInt(p + 1, &v); | 465 ReadInt(p + 1, &v); |
465 Variable::Mode mode_value = static_cast<Variable::Mode>(v); | 466 Variable::Mode mode_value = static_cast<Variable::Mode>(v); |
466 if (mode != NULL) *mode = mode_value; | 467 if (mode != NULL) *mode = mode_value; |
467 result = static_cast<int>((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; | 468 result = static_cast<int>((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; |
468 ContextSlotCache::Update(this, name, mode_value, result); | 469 isolate->context_slot_cache()->Update(this, name, mode_value, result); |
469 return result; | 470 return result; |
470 } | 471 } |
471 p += 2; | 472 p += 2; |
472 } | 473 } |
473 } | 474 } |
474 ContextSlotCache::Update(this, name, Variable::INTERNAL, -1); | 475 isolate->context_slot_cache()->Update(this, name, Variable::INTERNAL, -1); |
475 return -1; | 476 return -1; |
476 } | 477 } |
477 | 478 |
478 | 479 |
479 int SerializedScopeInfo::ParameterIndex(String* name) { | 480 int SerializedScopeInfo::ParameterIndex(String* name) { |
480 ASSERT(name->IsSymbol()); | 481 ASSERT(name->IsSymbol()); |
481 if (length() > 0) { | 482 if (length() > 0) { |
482 // We must read parameters from the end since for | 483 // We must read parameters from the end since for |
483 // multiply declared parameters the value of the | 484 // multiply declared parameters the value of the |
484 // last declaration of that parameter is used | 485 // last declaration of that parameter is used |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 return kNotFound; | 541 return kNotFound; |
541 } | 542 } |
542 | 543 |
543 | 544 |
544 void ContextSlotCache::Update(Object* data, | 545 void ContextSlotCache::Update(Object* data, |
545 String* name, | 546 String* name, |
546 Variable::Mode mode, | 547 Variable::Mode mode, |
547 int slot_index) { | 548 int slot_index) { |
548 String* symbol; | 549 String* symbol; |
549 ASSERT(slot_index > kNotFound); | 550 ASSERT(slot_index > kNotFound); |
550 if (Heap::LookupSymbolIfExists(name, &symbol)) { | 551 if (HEAP->LookupSymbolIfExists(name, &symbol)) { |
551 int index = Hash(data, symbol); | 552 int index = Hash(data, symbol); |
552 Key& key = keys_[index]; | 553 Key& key = keys_[index]; |
553 key.data = data; | 554 key.data = data; |
554 key.name = symbol; | 555 key.name = symbol; |
555 // Please note value only takes a uint as index. | 556 // Please note value only takes a uint as index. |
556 values_[index] = Value(mode, slot_index - kNotFound).raw(); | 557 values_[index] = Value(mode, slot_index - kNotFound).raw(); |
557 #ifdef DEBUG | 558 #ifdef DEBUG |
558 ValidateEntry(data, name, mode, slot_index); | 559 ValidateEntry(data, name, mode, slot_index); |
559 #endif | 560 #endif |
560 } | 561 } |
561 } | 562 } |
562 | 563 |
563 | 564 |
564 void ContextSlotCache::Clear() { | 565 void ContextSlotCache::Clear() { |
565 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; | 566 for (int index = 0; index < kLength; index++) keys_[index].data = NULL; |
566 } | 567 } |
567 | 568 |
568 | 569 |
569 ContextSlotCache::Key ContextSlotCache::keys_[ContextSlotCache::kLength]; | |
570 | |
571 | |
572 uint32_t ContextSlotCache::values_[ContextSlotCache::kLength]; | |
573 | |
574 | |
575 #ifdef DEBUG | 570 #ifdef DEBUG |
576 | 571 |
577 void ContextSlotCache::ValidateEntry(Object* data, | 572 void ContextSlotCache::ValidateEntry(Object* data, |
578 String* name, | 573 String* name, |
579 Variable::Mode mode, | 574 Variable::Mode mode, |
580 int slot_index) { | 575 int slot_index) { |
581 String* symbol; | 576 String* symbol; |
582 if (Heap::LookupSymbolIfExists(name, &symbol)) { | 577 if (HEAP->LookupSymbolIfExists(name, &symbol)) { |
583 int index = Hash(data, name); | 578 int index = Hash(data, name); |
584 Key& key = keys_[index]; | 579 Key& key = keys_[index]; |
585 ASSERT(key.data == data); | 580 ASSERT(key.data == data); |
586 ASSERT(key.name->Equals(name)); | 581 ASSERT(key.name->Equals(name)); |
587 Value result(values_[index]); | 582 Value result(values_[index]); |
588 ASSERT(result.mode() == mode); | 583 ASSERT(result.mode() == mode); |
589 ASSERT(result.index() + kNotFound == slot_index); | 584 ASSERT(result.index() + kNotFound == slot_index); |
590 } | 585 } |
591 } | 586 } |
592 | 587 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 } | 622 } |
628 #endif // DEBUG | 623 #endif // DEBUG |
629 | 624 |
630 | 625 |
631 // Make sure the classes get instantiated by the template system. | 626 // Make sure the classes get instantiated by the template system. |
632 template class ScopeInfo<FreeStoreAllocationPolicy>; | 627 template class ScopeInfo<FreeStoreAllocationPolicy>; |
633 template class ScopeInfo<PreallocatedStorage>; | 628 template class ScopeInfo<PreallocatedStorage>; |
634 template class ScopeInfo<ZoneListAllocationPolicy>; | 629 template class ScopeInfo<ZoneListAllocationPolicy>; |
635 | 630 |
636 } } // namespace v8::internal | 631 } } // namespace v8::internal |
OLD | NEW |