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 calls_eval_(scope->calls_eval()), |
53 parameters_(scope->num_parameters()), | 54 parameters_(scope->num_parameters()), |
54 stack_slots_(scope->num_stack_slots()), | 55 stack_slots_(scope->num_stack_slots()), |
55 context_slots_(scope->num_heap_slots()), | 56 context_slots_(scope->num_heap_slots()), |
56 context_modes_(scope->num_heap_slots()) { | 57 context_modes_(scope->num_heap_slots()) { |
57 // Add parameters. | 58 // Add parameters. |
58 for (int i = 0; i < scope->num_parameters(); i++) { | 59 for (int i = 0; i < scope->num_parameters(); i++) { |
59 ASSERT(parameters_.length() == i); | 60 ASSERT(parameters_.length() == i); |
60 parameters_.Add(scope->parameter(i)->name()); | 61 parameters_.Add(scope->parameter(i)->name()); |
61 } | 62 } |
62 | 63 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 : function_name_(Factory::empty_symbol()), | 248 : function_name_(Factory::empty_symbol()), |
248 parameters_(4), | 249 parameters_(4), |
249 stack_slots_(8), | 250 stack_slots_(8), |
250 context_slots_(8), | 251 context_slots_(8), |
251 context_modes_(8) { | 252 context_modes_(8) { |
252 if (code == NULL || code->sinfo_size() == 0) return; | 253 if (code == NULL || code->sinfo_size() == 0) return; |
253 | 254 |
254 Object** p0 = &Memory::Object_at(code->sinfo_start()); | 255 Object** p0 = &Memory::Object_at(code->sinfo_start()); |
255 Object** p = p0; | 256 Object** p = p0; |
256 p = ReadSymbol(p, &function_name_); | 257 p = ReadSymbol(p, &function_name_); |
| 258 p = ReadBool(p, &calls_eval_); |
257 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); | 259 p = ReadList<Allocator>(p, &context_slots_, &context_modes_); |
258 p = ReadList<Allocator>(p, ¶meters_); | 260 p = ReadList<Allocator>(p, ¶meters_); |
259 p = ReadList<Allocator>(p, &stack_slots_); | 261 p = ReadList<Allocator>(p, &stack_slots_); |
260 ASSERT((p - p0) * kPointerSize == code->sinfo_size()); | 262 ASSERT((p - p0) * kPointerSize == code->sinfo_size()); |
261 } | 263 } |
262 | 264 |
263 | 265 |
264 static inline Object** WriteInt(Object** p, int x) { | 266 static inline Object** WriteInt(Object** p, int x) { |
265 *p++ = Smi::FromInt(x); | 267 *p++ = Smi::FromInt(x); |
266 return p; | 268 return p; |
267 } | 269 } |
268 | 270 |
269 | 271 |
| 272 static inline Object** WriteBool(Object** p, bool b) { |
| 273 *p++ = Smi::FromInt(b ? 1 : 0); |
| 274 return p; |
| 275 } |
| 276 |
| 277 |
270 static inline Object** WriteSymbol(Object** p, Handle<String> s) { | 278 static inline Object** WriteSymbol(Object** p, Handle<String> s) { |
271 *p++ = *s; | 279 *p++ = *s; |
272 return p; | 280 return p; |
273 } | 281 } |
274 | 282 |
275 | 283 |
276 static inline Object** WriteSentinel(Object** p) { | 284 static inline Object** WriteSentinel(Object** p) { |
277 *p++ = NULL; | 285 *p++ = NULL; |
278 return p; | 286 return p; |
279 } | 287 } |
(...skipping 19 matching lines...) Expand all Loading... |
299 for (int i = 0; i < n; i++) { | 307 for (int i = 0; i < n; i++) { |
300 p = WriteSymbol(p, list->at(i)); | 308 p = WriteSymbol(p, list->at(i)); |
301 p = WriteInt(p, modes->at(i)); | 309 p = WriteInt(p, modes->at(i)); |
302 } | 310 } |
303 return WriteSentinel(p); | 311 return WriteSentinel(p); |
304 } | 312 } |
305 | 313 |
306 | 314 |
307 template<class Allocator> | 315 template<class Allocator> |
308 int ScopeInfo<Allocator>::Serialize(Code* code) { | 316 int ScopeInfo<Allocator>::Serialize(Code* code) { |
309 // function name, length & sentinel for 3 tables: | 317 // function name, calls eval, length & sentinel for 3 tables: |
310 const int extra_slots = 1 + 2 * 3; | 318 const int extra_slots = 1 + 1 + 2 * 3; |
311 int size = (extra_slots + | 319 int size = (extra_slots + |
312 context_slots_.length() * 2 + | 320 context_slots_.length() * 2 + |
313 parameters_.length() + | 321 parameters_.length() + |
314 stack_slots_.length()) * kPointerSize; | 322 stack_slots_.length()) * kPointerSize; |
315 | 323 |
316 if (code != NULL) { | 324 if (code != NULL) { |
317 CHECK(code->sinfo_size() == size); | 325 CHECK(code->sinfo_size() == size); |
318 Object** p0 = &Memory::Object_at(code->sinfo_start()); | 326 Object** p0 = &Memory::Object_at(code->sinfo_start()); |
319 Object** p = p0; | 327 Object** p = p0; |
320 p = WriteSymbol(p, function_name_); | 328 p = WriteSymbol(p, function_name_); |
| 329 p = WriteBool(p, calls_eval_); |
321 p = WriteList(p, &context_slots_, &context_modes_); | 330 p = WriteList(p, &context_slots_, &context_modes_); |
322 p = WriteList(p, ¶meters_); | 331 p = WriteList(p, ¶meters_); |
323 p = WriteList(p, &stack_slots_); | 332 p = WriteList(p, &stack_slots_); |
324 ASSERT((p - p0) * kPointerSize == size); | 333 ASSERT((p - p0) * kPointerSize == size); |
325 } | 334 } |
326 | 335 |
327 return size; | 336 return size; |
328 } | 337 } |
329 | 338 |
330 | 339 |
331 template<class Allocator> | 340 template<class Allocator> |
332 void ScopeInfo<Allocator>::IterateScopeInfo(Code* code, ObjectVisitor* v) { | 341 void ScopeInfo<Allocator>::IterateScopeInfo(Code* code, ObjectVisitor* v) { |
333 Object** start = &Memory::Object_at(code->sinfo_start()); | 342 Object** start = &Memory::Object_at(code->sinfo_start()); |
334 Object** end = &Memory::Object_at(code->sinfo_start() + code->sinfo_size()); | 343 Object** end = &Memory::Object_at(code->sinfo_start() + code->sinfo_size()); |
335 v->VisitPointers(start, end); | 344 v->VisitPointers(start, end); |
336 } | 345 } |
337 | 346 |
338 | 347 |
339 static Object** ContextEntriesAddr(Code* code) { | 348 static Object** ContextEntriesAddr(Code* code) { |
340 ASSERT(code->sinfo_size() > 0); | 349 ASSERT(code->sinfo_size() > 0); |
341 // +1 for function name: | 350 // +2 for function name and calls eval: |
342 return &Memory::Object_at(code->sinfo_start()) + 1; | 351 return &Memory::Object_at(code->sinfo_start()) + 2; |
343 } | 352 } |
344 | 353 |
345 | 354 |
346 static Object** ParameterEntriesAddr(Code* code) { | 355 static Object** ParameterEntriesAddr(Code* code) { |
347 ASSERT(code->sinfo_size() > 0); | 356 ASSERT(code->sinfo_size() > 0); |
348 Object** p = ContextEntriesAddr(code); | 357 Object** p = ContextEntriesAddr(code); |
349 int n; // number of context slots; | 358 int n; // number of context slots; |
350 p = ReadInt(p, &n); | 359 p = ReadInt(p, &n); |
351 return p + n*2 + 1; // *2 for pairs, +1 for sentinel | 360 return p + n*2 + 1; // *2 for pairs, +1 for sentinel |
352 } | 361 } |
353 | 362 |
354 | 363 |
355 static Object** StackSlotEntriesAddr(Code* code) { | 364 static Object** StackSlotEntriesAddr(Code* code) { |
356 ASSERT(code->sinfo_size() > 0); | 365 ASSERT(code->sinfo_size() > 0); |
357 Object** p = ParameterEntriesAddr(code); | 366 Object** p = ParameterEntriesAddr(code); |
358 int n; // number of parameter slots; | 367 int n; // number of parameter slots; |
359 p = ReadInt(p, &n); | 368 p = ReadInt(p, &n); |
360 return p + n + 1; // +1 for sentinel | 369 return p + n + 1; // +1 for sentinel |
361 } | 370 } |
362 | 371 |
363 | 372 |
364 template<class Allocator> | 373 template<class Allocator> |
| 374 bool ScopeInfo<Allocator>::CallsEval(Code* code) { |
| 375 if (code->sinfo_size() > 0) { |
| 376 // +1 for function name: |
| 377 Object** p = &Memory::Object_at(code->sinfo_start()) + 1; |
| 378 bool calls_eval; |
| 379 p = ReadBool(p, &calls_eval); |
| 380 return calls_eval; |
| 381 } |
| 382 return true; |
| 383 } |
| 384 |
| 385 |
| 386 template<class Allocator> |
365 int ScopeInfo<Allocator>::NumberOfStackSlots(Code* code) { | 387 int ScopeInfo<Allocator>::NumberOfStackSlots(Code* code) { |
366 if (code->sinfo_size() > 0) { | 388 if (code->sinfo_size() > 0) { |
367 Object** p = StackSlotEntriesAddr(code); | 389 Object** p = StackSlotEntriesAddr(code); |
368 int n; // number of stack slots; | 390 int n; // number of stack slots; |
369 ReadInt(p, &n); | 391 ReadInt(p, &n); |
370 return n; | 392 return n; |
371 } | 393 } |
372 return 0; | 394 return 0; |
373 } | 395 } |
374 | 396 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 PrintF("}\n"); | 561 PrintF("}\n"); |
540 } | 562 } |
541 #endif // DEBUG | 563 #endif // DEBUG |
542 | 564 |
543 | 565 |
544 // Make sure the classes get instantiated by the template system. | 566 // Make sure the classes get instantiated by the template system. |
545 template class ScopeInfo<FreeStoreAllocationPolicy>; | 567 template class ScopeInfo<FreeStoreAllocationPolicy>; |
546 template class ScopeInfo<PreallocatedStorage>; | 568 template class ScopeInfo<PreallocatedStorage>; |
547 | 569 |
548 } } // namespace v8::internal | 570 } } // namespace v8::internal |
OLD | NEW |