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 int x = (s != NULL ? s->index() : 0); | 43 int x = (s != NULL ? s->index() : 0); |
44 int y = (t != NULL ? t->index() : 0); | 44 int y = (t != NULL ? t->index() : 0); |
45 // Consider sorting them according to type as well? | 45 // Consider sorting them according to type as well? |
46 return x - y; | 46 return x - y; |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 template<class Allocator> | 50 template<class Allocator> |
51 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) | 51 ScopeInfo<Allocator>::ScopeInfo(Scope* scope) |
52 : function_name_(Factory::empty_symbol()), | 52 : function_name_(Factory::empty_symbol()), |
53 supports_eval_(scope->SupportsEval()), | |
54 parameters_(scope->num_parameters()), | 53 parameters_(scope->num_parameters()), |
55 stack_slots_(scope->num_stack_slots()), | 54 stack_slots_(scope->num_stack_slots()), |
56 context_slots_(scope->num_heap_slots()), | 55 context_slots_(scope->num_heap_slots()), |
57 context_modes_(scope->num_heap_slots()) { | 56 context_modes_(scope->num_heap_slots()) { |
58 // Add parameters. | 57 // Add parameters. |
59 for (int i = 0; i < scope->num_parameters(); i++) { | 58 for (int i = 0; i < scope->num_parameters(); i++) { |
60 ASSERT(parameters_.length() == i); | 59 ASSERT(parameters_.length() == i); |
61 parameters_.Add(scope->parameter(i)->name()); | 60 parameters_.Add(scope->parameter(i)->name()); |
62 } | 61 } |
63 | 62 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 context_slots_.Add(Factory::empty_symbol()); | 143 context_slots_.Add(Factory::empty_symbol()); |
145 context_modes_.Add(Variable::INTERNAL); | 144 context_modes_.Add(Variable::INTERNAL); |
146 } | 145 } |
147 } | 146 } |
148 } | 147 } |
149 | 148 |
150 | 149 |
151 // Encoding format in the Code object: | 150 // Encoding format in the Code object: |
152 // | 151 // |
153 // - function name | 152 // - function name |
154 // - supports eval info | |
155 // | 153 // |
156 // - number of variables in the context object (smi) (= function context | 154 // - number of variables in the context object (smi) (= function context |
157 // slot index + 1) | 155 // slot index + 1) |
158 // - list of pairs (name, Var mode) of context-allocated variables (starting | 156 // - list of pairs (name, Var mode) of context-allocated variables (starting |
159 // with context slot 0) | 157 // with context slot 0) |
160 // - NULL (sentinel) | 158 // - NULL (sentinel) |
161 // | 159 // |
162 // - number of parameters (smi) | 160 // - number of parameters (smi) |
163 // - list of parameter names (starting with parameter 0 first) | 161 // - list of parameter names (starting with parameter 0 first) |
164 // - NULL (sentinel) | 162 // - NULL (sentinel) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 list->Add(s); | 238 list->Add(s); |
241 modes->Add(static_cast<Variable::Mode>(m)); | 239 modes->Add(static_cast<Variable::Mode>(m)); |
242 } | 240 } |
243 return ReadSentinel(p); | 241 return ReadSentinel(p); |
244 } | 242 } |
245 | 243 |
246 | 244 |
247 template<class Allocator> | 245 template<class Allocator> |
248 ScopeInfo<Allocator>::ScopeInfo(Code* code) | 246 ScopeInfo<Allocator>::ScopeInfo(Code* code) |
249 : function_name_(Factory::empty_symbol()), | 247 : function_name_(Factory::empty_symbol()), |
250 supports_eval_(false), | |
251 parameters_(4), | 248 parameters_(4), |
252 stack_slots_(8), | 249 stack_slots_(8), |
253 context_slots_(8), | 250 context_slots_(8), |
254 context_modes_(8) { | 251 context_modes_(8) { |
255 if (code == NULL || code->sinfo_size() == 0) return; | 252 if (code == NULL || code->sinfo_size() == 0) return; |
256 | 253 |
257 Object** p0 = &Memory::Object_at(code->sinfo_start()); | 254 Object** p0 = &Memory::Object_at(code->sinfo_start()); |
258 Object** p = p0; | 255 Object** p = p0; |
259 p = ReadSymbol(p, &function_name_); | 256 p = ReadSymbol(p, &function_name_); |
260 p = ReadBool(p, &supports_eval_); | |
261 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 257 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
262 p = ReadList<Allocator>(p, ¶meters_); | 258 p = ReadList<Allocator>(p, ¶meters_); |
263 p = ReadList<Allocator>(p, &stack_slots_); | 259 p = ReadList<Allocator>(p, &stack_slots_); |
264 ASSERT((p - p0) * kPointerSize == code->sinfo_size()); | 260 ASSERT((p - p0) * kPointerSize == code->sinfo_size()); |
265 } | 261 } |
266 | 262 |
267 | 263 |
268 static inline Object** WriteInt(Object** p, int x) { | 264 static inline Object** WriteInt(Object** p, int x) { |
269 *p++ = Smi::FromInt(x); | 265 *p++ = Smi::FromInt(x); |
270 return p; | 266 return p; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 for (int i = 0; i < n; i++) { | 299 for (int i = 0; i < n; i++) { |
304 p = WriteSymbol(p, list->at(i)); | 300 p = WriteSymbol(p, list->at(i)); |
305 p = WriteInt(p, modes->at(i)); | 301 p = WriteInt(p, modes->at(i)); |
306 } | 302 } |
307 return WriteSentinel(p); | 303 return WriteSentinel(p); |
308 } | 304 } |
309 | 305 |
310 | 306 |
311 template<class Allocator> | 307 template<class Allocator> |
312 int ScopeInfo<Allocator>::Serialize(Code* code) { | 308 int ScopeInfo<Allocator>::Serialize(Code* code) { |
313 // function name, supports eval, length & sentinel for 3 tables: | 309 // function name, length & sentinel for 3 tables: |
314 const int extra_slots = 1 + 1 + 2 * 3; | 310 const int extra_slots = 1 + 2 * 3; |
315 int size = (extra_slots + | 311 int size = (extra_slots + |
316 context_slots_.length() * 2 + | 312 context_slots_.length() * 2 + |
317 parameters_.length() + | 313 parameters_.length() + |
318 stack_slots_.length()) * kPointerSize; | 314 stack_slots_.length()) * kPointerSize; |
319 | 315 |
320 if (code != NULL) { | 316 if (code != NULL) { |
321 CHECK(code->sinfo_size() == size); | 317 CHECK(code->sinfo_size() == size); |
322 Object** p0 = &Memory::Object_at(code->sinfo_start()); | 318 Object** p0 = &Memory::Object_at(code->sinfo_start()); |
323 Object** p = p0; | 319 Object** p = p0; |
324 p = WriteSymbol(p, function_name_); | 320 p = WriteSymbol(p, function_name_); |
325 p = WriteInt(p, supports_eval_); | |
326 p = WriteList(p, &context_slots_, &context_modes_); | 321 p = WriteList(p, &context_slots_, &context_modes_); |
327 p = WriteList(p, ¶meters_); | 322 p = WriteList(p, ¶meters_); |
328 p = WriteList(p, &stack_slots_); | 323 p = WriteList(p, &stack_slots_); |
329 ASSERT((p - p0) * kPointerSize == size); | 324 ASSERT((p - p0) * kPointerSize == size); |
330 } | 325 } |
331 | 326 |
332 return size; | 327 return size; |
333 } | 328 } |
334 | 329 |
335 | 330 |
336 template<class Allocator> | 331 template<class Allocator> |
337 void ScopeInfo<Allocator>::IterateScopeInfo(Code* code, ObjectVisitor* v) { | 332 void ScopeInfo<Allocator>::IterateScopeInfo(Code* code, ObjectVisitor* v) { |
338 Object** start = &Memory::Object_at(code->sinfo_start()); | 333 Object** start = &Memory::Object_at(code->sinfo_start()); |
339 Object** end = &Memory::Object_at(code->sinfo_start() + code->sinfo_size()); | 334 Object** end = &Memory::Object_at(code->sinfo_start() + code->sinfo_size()); |
340 v->VisitPointers(start, end); | 335 v->VisitPointers(start, end); |
341 } | 336 } |
342 | 337 |
343 | 338 |
344 static Object** ContextEntriesAddr(Code* code) { | 339 static Object** ContextEntriesAddr(Code* code) { |
345 ASSERT(code->sinfo_size() > 0); | 340 ASSERT(code->sinfo_size() > 0); |
346 // +2 for function name, supports eval: | 341 // +1 for function name: |
347 return &Memory::Object_at(code->sinfo_start()) + 2; | 342 return &Memory::Object_at(code->sinfo_start()) + 1; |
348 } | 343 } |
349 | 344 |
350 | 345 |
351 static Object** ParameterEntriesAddr(Code* code) { | 346 static Object** ParameterEntriesAddr(Code* code) { |
352 ASSERT(code->sinfo_size() > 0); | 347 ASSERT(code->sinfo_size() > 0); |
353 Object** p = ContextEntriesAddr(code); | 348 Object** p = ContextEntriesAddr(code); |
354 int n; // number of context slots; | 349 int n; // number of context slots; |
355 p = ReadInt(p, &n); | 350 p = ReadInt(p, &n); |
356 return p + n*2 + 1; // *2 for pairs, +1 for sentinel | 351 return p + n*2 + 1; // *2 for pairs, +1 for sentinel |
357 } | 352 } |
358 | 353 |
359 | 354 |
360 static Object** StackSlotEntriesAddr(Code* code) { | 355 static Object** StackSlotEntriesAddr(Code* code) { |
361 ASSERT(code->sinfo_size() > 0); | 356 ASSERT(code->sinfo_size() > 0); |
362 Object** p = ParameterEntriesAddr(code); | 357 Object** p = ParameterEntriesAddr(code); |
363 int n; // number of parameter slots; | 358 int n; // number of parameter slots; |
364 p = ReadInt(p, &n); | 359 p = ReadInt(p, &n); |
365 return p + n + 1; // +1 for sentinel | 360 return p + n + 1; // +1 for sentinel |
366 } | 361 } |
367 | 362 |
368 | 363 |
369 template<class Allocator> | 364 template<class Allocator> |
370 bool ScopeInfo<Allocator>::SupportsEval(Code* code) { | |
371 bool result = false; | |
372 if (code->sinfo_size() > 0) { | |
373 ReadBool(&Memory::Object_at(code->sinfo_start()) + 1, &result); | |
374 } | |
375 #ifdef DEBUG | |
376 { ScopeInfo info(code); | |
377 ASSERT(result == info.supports_eval_); | |
378 } | |
379 #endif | |
380 return result; | |
381 } | |
382 | |
383 | |
384 template<class Allocator> | |
385 int ScopeInfo<Allocator>::NumberOfStackSlots(Code* code) { | 365 int ScopeInfo<Allocator>::NumberOfStackSlots(Code* code) { |
386 if (code->sinfo_size() > 0) { | 366 if (code->sinfo_size() > 0) { |
387 Object** p = StackSlotEntriesAddr(code); | 367 Object** p = StackSlotEntriesAddr(code); |
388 int n; // number of stack slots; | 368 int n; // number of stack slots; |
389 ReadInt(p, &n); | 369 ReadInt(p, &n); |
390 return n; | 370 return n; |
391 } | 371 } |
392 return 0; | 372 return 0; |
393 } | 373 } |
394 | 374 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 | 524 |
545 template<class Allocator> | 525 template<class Allocator> |
546 void ScopeInfo<Allocator>::Print() { | 526 void ScopeInfo<Allocator>::Print() { |
547 PrintF("ScopeInfo "); | 527 PrintF("ScopeInfo "); |
548 if (function_name_->length() > 0) | 528 if (function_name_->length() > 0) |
549 function_name_->ShortPrint(); | 529 function_name_->ShortPrint(); |
550 else | 530 else |
551 PrintF("/* no function name */"); | 531 PrintF("/* no function name */"); |
552 PrintF("{"); | 532 PrintF("{"); |
553 | 533 |
554 if (supports_eval_) | |
555 PrintF("\n // supports eval\n"); | |
556 | |
557 PrintList<Allocator>("parameters", 0, parameters_); | 534 PrintList<Allocator>("parameters", 0, parameters_); |
558 PrintList<Allocator>("stack slots", 0, stack_slots_); | 535 PrintList<Allocator>("stack slots", 0, stack_slots_); |
559 PrintList<Allocator>("context slots", Context::MIN_CONTEXT_SLOTS, | 536 PrintList<Allocator>("context slots", Context::MIN_CONTEXT_SLOTS, |
560 context_slots_); | 537 context_slots_); |
561 | 538 |
562 PrintF("}\n"); | 539 PrintF("}\n"); |
563 } | 540 } |
564 #endif // DEBUG | 541 #endif // DEBUG |
565 | 542 |
566 | 543 |
567 // Make sure the classes get instantiated by the template system. | 544 // Make sure the classes get instantiated by the template system. |
568 template class ScopeInfo<FreeStoreAllocationPolicy>; | 545 template class ScopeInfo<FreeStoreAllocationPolicy>; |
569 template class ScopeInfo<PreallocatedStorage>; | 546 template class ScopeInfo<PreallocatedStorage>; |
570 | 547 |
571 } } // namespace v8::internal | 548 } } // namespace v8::internal |
OLD | NEW |