| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // We may have rewritten parameters (that are in the arguments object) | 44 // We may have rewritten parameters (that are in the arguments object) |
| 45 // and which may have a NULL slot... - find a better solution... | 45 // and which may have a NULL slot... - find a better solution... |
| 46 int x = (s != NULL ? s->index() : 0); | 46 int x = (s != NULL ? s->index() : 0); |
| 47 int y = (t != NULL ? t->index() : 0); | 47 int y = (t != NULL ? t->index() : 0); |
| 48 // Consider sorting them according to type as well? | 48 // Consider sorting them according to type as well? |
| 49 return x - y; | 49 return x - y; |
| 50 } | 50 } |
| 51 | 51 |
| 52 | 52 |
| 53 template<class Allocator> | 53 template<class Allocator> |
| 54 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) | 54 ScopeInfo<Allocator>::ScopeInfo(Scope* scope, const Allocator& allocator) |
| 55 : function_name_(FACTORY->empty_symbol()), | 55 : function_name_(FACTORY->empty_symbol()), |
| 56 calls_eval_(scope->calls_eval()), | 56 calls_eval_(scope->calls_eval()), |
| 57 is_strict_mode_(scope->is_strict_mode()), | 57 is_strict_mode_(scope->is_strict_mode()), |
| 58 parameters_(scope->num_parameters()), | 58 parameters_(scope->num_parameters(), allocator), |
| 59 stack_slots_(scope->num_stack_slots()), | 59 stack_slots_(scope->num_stack_slots(), allocator), |
| 60 context_slots_(scope->num_heap_slots()), | 60 context_slots_(scope->num_heap_slots(), allocator), |
| 61 context_modes_(scope->num_heap_slots()) { | 61 context_modes_(scope->num_heap_slots(), allocator) { |
| 62 // Add parameters. | 62 // Add parameters. |
| 63 for (int i = 0; i < scope->num_parameters(); i++) { | 63 for (int i = 0; i < scope->num_parameters(); i++) { |
| 64 ASSERT(parameters_.length() == i); | 64 ASSERT(parameters_.length() == i); |
| 65 parameters_.Add(scope->parameter(i)->name()); | 65 parameters_.Add(scope->parameter(i)->name()); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // Add stack locals and collect heap locals. | 68 // Add stack locals and collect heap locals. |
| 69 // We are assuming that the locals' slots are allocated in | 69 // We are assuming that the locals' slots are allocated in |
| 70 // increasing order, so we can simply add them to the | 70 // increasing order, so we can simply add them to the |
| 71 // ScopeInfo lists. However, due to usage analysis, this is | 71 // ScopeInfo lists. However, due to usage analysis, this is |
| 72 // not true for context-allocated locals: Some of them | 72 // not true for context-allocated locals: Some of them |
| 73 // may be parameters which are allocated before the | 73 // may be parameters which are allocated before the |
| 74 // non-parameter locals. When the non-parameter locals are | 74 // non-parameter locals. When the non-parameter locals are |
| 75 // sorted according to usage, the allocated slot indices may | 75 // sorted according to usage, the allocated slot indices may |
| 76 // not be in increasing order with the variable list anymore. | 76 // not be in increasing order with the variable list anymore. |
| 77 // Thus, we first collect the context-allocated locals, and then | 77 // Thus, we first collect the context-allocated locals, and then |
| 78 // sort them by context slot index before adding them to the | 78 // sort them by context slot index before adding them to the |
| 79 // ScopeInfo list. | 79 // ScopeInfo list. |
| 80 List<Variable*, Allocator> locals(32); // 32 is a wild guess | 80 List<Variable*, Allocator> locals(32, allocator); // 32 is a wild guess |
| 81 ASSERT(locals.is_empty()); | 81 ASSERT(locals.is_empty()); |
| 82 scope->CollectUsedVariables(&locals); | 82 scope->CollectUsedVariables(&locals); |
| 83 locals.Sort(&CompareLocal); | 83 locals.Sort(&CompareLocal); |
| 84 | 84 |
| 85 List<Variable*, Allocator> heap_locals(locals.length()); | 85 List<Variable*, Allocator> heap_locals(locals.length(), allocator); |
| 86 for (int i = 0; i < locals.length(); i++) { | 86 for (int i = 0; i < locals.length(); i++) { |
| 87 Variable* var = locals[i]; | 87 Variable* var = locals[i]; |
| 88 if (var->is_used()) { | 88 if (var->is_used()) { |
| 89 Slot* slot = var->AsSlot(); | 89 Slot* slot = var->AsSlot(); |
| 90 if (slot != NULL) { | 90 if (slot != NULL) { |
| 91 switch (slot->type()) { | 91 switch (slot->type()) { |
| 92 case Slot::PARAMETER: | 92 case Slot::PARAMETER: |
| 93 // explicitly added to parameters_ above - ignore | 93 // explicitly added to parameters_ above - ignore |
| 94 break; | 94 break; |
| 95 | 95 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 p = ReadSymbol(p, &s); | 233 p = ReadSymbol(p, &s); |
| 234 p = ReadInt(p, &m); | 234 p = ReadInt(p, &m); |
| 235 list->Add(s); | 235 list->Add(s); |
| 236 modes->Add(static_cast<Variable::Mode>(m)); | 236 modes->Add(static_cast<Variable::Mode>(m)); |
| 237 } | 237 } |
| 238 return p; | 238 return p; |
| 239 } | 239 } |
| 240 | 240 |
| 241 | 241 |
| 242 template<class Allocator> | 242 template<class Allocator> |
| 243 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data) | 243 ScopeInfo<Allocator>::ScopeInfo(SerializedScopeInfo* data, |
| 244 const Allocator& allocator) |
| 244 : function_name_(FACTORY->empty_symbol()), | 245 : function_name_(FACTORY->empty_symbol()), |
| 245 parameters_(4), | 246 parameters_(4, allocator), |
| 246 stack_slots_(8), | 247 stack_slots_(8, allocator), |
| 247 context_slots_(8), | 248 context_slots_(8, allocator), |
| 248 context_modes_(8) { | 249 context_modes_(8, allocator) { |
| 249 if (data->length() > 0) { | 250 if (data->length() > 0) { |
| 250 Object** p0 = data->data_start(); | 251 Object** p0 = data->data_start(); |
| 251 Object** p = p0; | 252 Object** p = p0; |
| 252 p = ReadSymbol(p, &function_name_); | 253 p = ReadSymbol(p, &function_name_); |
| 253 p = ReadBool(p, &calls_eval_); | 254 p = ReadBool(p, &calls_eval_); |
| 254 p = ReadBool(p, &is_strict_mode_); | 255 p = ReadBool(p, &is_strict_mode_); |
| 255 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 256 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
| 256 p = ReadList<Allocator>(p, ¶meters_); | 257 p = ReadList<Allocator>(p, ¶meters_); |
| 257 p = ReadList<Allocator>(p, &stack_slots_); | 258 p = ReadList<Allocator>(p, &stack_slots_); |
| 258 ASSERT((p - p0) == FixedArray::cast(data)->length()); | 259 ASSERT((p - p0) == FixedArray::cast(data)->length()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 int number_of_locals = number_of_stack_slots(); | 350 int number_of_locals = number_of_stack_slots(); |
| 350 if (number_of_context_slots() > 0) { | 351 if (number_of_context_slots() > 0) { |
| 351 ASSERT(number_of_context_slots() >= Context::MIN_CONTEXT_SLOTS); | 352 ASSERT(number_of_context_slots() >= Context::MIN_CONTEXT_SLOTS); |
| 352 number_of_locals += number_of_context_slots() - Context::MIN_CONTEXT_SLOTS; | 353 number_of_locals += number_of_context_slots() - Context::MIN_CONTEXT_SLOTS; |
| 353 } | 354 } |
| 354 return number_of_locals; | 355 return number_of_locals; |
| 355 } | 356 } |
| 356 | 357 |
| 357 | 358 |
| 358 Handle<SerializedScopeInfo> SerializedScopeInfo::Create(Scope* scope) { | 359 Handle<SerializedScopeInfo> SerializedScopeInfo::Create(Scope* scope) { |
| 359 ScopeInfo<ZoneListAllocationPolicy> sinfo(scope); | 360 ScopeInfo<ZoneListAllocator> sinfo(scope, ZoneListAllocator(ZONE)); |
| 360 return sinfo.Serialize(); | 361 return sinfo.Serialize(); |
| 361 } | 362 } |
| 362 | 363 |
| 363 | 364 |
| 364 SerializedScopeInfo* SerializedScopeInfo::Empty() { | 365 SerializedScopeInfo* SerializedScopeInfo::Empty() { |
| 365 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); | 366 return reinterpret_cast<SerializedScopeInfo*>(HEAP->empty_fixed_array()); |
| 366 } | 367 } |
| 367 | 368 |
| 368 | 369 |
| 369 Object** SerializedScopeInfo::ContextEntriesAddr() { | 370 Object** SerializedScopeInfo::ContextEntriesAddr() { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 PrintList<Allocator>("stack slots", 0, stack_slots_); | 635 PrintList<Allocator>("stack slots", 0, stack_slots_); |
| 635 PrintList<Allocator>("context slots", Context::MIN_CONTEXT_SLOTS, | 636 PrintList<Allocator>("context slots", Context::MIN_CONTEXT_SLOTS, |
| 636 context_slots_); | 637 context_slots_); |
| 637 | 638 |
| 638 PrintF("}\n"); | 639 PrintF("}\n"); |
| 639 } | 640 } |
| 640 #endif // DEBUG | 641 #endif // DEBUG |
| 641 | 642 |
| 642 | 643 |
| 643 // Make sure the classes get instantiated by the template system. | 644 // Make sure the classes get instantiated by the template system. |
| 644 template class ScopeInfo<FreeStoreAllocationPolicy>; | 645 template class ScopeInfo<FreeStoreAllocator>; |
| 645 template class ScopeInfo<PreallocatedStorage>; | 646 template class ScopeInfo<PreallocatedStorageAllocator>; |
| 646 template class ScopeInfo<ZoneListAllocationPolicy>; | 647 template class ScopeInfo<ZoneListAllocator>; |
| 647 | 648 |
| 648 } } // namespace v8::internal | 649 } } // namespace v8::internal |
| OLD | NEW |