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

Side by Side Diff: src/scopeinfo.cc

Issue 141038: Implemented a ContextSlotCache for compiled code. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 6 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
« src/scopeinfo.h ('K') | « src/scopeinfo.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // slots start after length entry 418 // slots start after length entry
419 Object** p0 = StackSlotEntriesAddr(code) + 1; 419 Object** p0 = StackSlotEntriesAddr(code) + 1;
420 Object** p = p0; 420 Object** p = p0;
421 while (*p != NULL) { 421 while (*p != NULL) {
422 if (*p == name) return p - p0; 422 if (*p == name) return p - p0;
423 p++; 423 p++;
424 } 424 }
425 } 425 }
426 return -1; 426 return -1;
427 } 427 }
428 428
Mads Ager (chromium) 2009/06/22 08:00:18 Remove extra lines.
429 429
430
431
430 template<class Allocator> 432 template<class Allocator>
431 int ScopeInfo<Allocator>::ContextSlotIndex(Code* code, 433 int ScopeInfo<Allocator>::ContextSlotIndex(Code* code,
432 String* name, 434 String* name,
433 Variable::Mode* mode) { 435 Variable::Mode* mode) {
434 ASSERT(name->IsSymbol()); 436 ASSERT(name->IsSymbol());
437 int result = ContextSlotCache::Lookup(code, name, mode);
438 if (result != ContextSlotCache::kNotFound) return result;
435 if (code->sinfo_size() > 0) { 439 if (code->sinfo_size() > 0) {
436 // Loop below depends on the NULL sentinel after the context slot names. 440 // Loop below depends on the NULL sentinel after the context slot names.
437 ASSERT(NumberOfContextSlots(code) >= Context::MIN_CONTEXT_SLOTS || 441 ASSERT(NumberOfContextSlots(code) >= Context::MIN_CONTEXT_SLOTS ||
438 *(ContextEntriesAddr(code) + 1) == NULL); 442 *(ContextEntriesAddr(code) + 1) == NULL);
443
439 // slots start after length entry 444 // slots start after length entry
440 Object** p0 = ContextEntriesAddr(code) + 1; 445 Object** p0 = ContextEntriesAddr(code) + 1;
441 Object** p = p0; 446 Object** p = p0;
442 // contexts may have no variable slots (in the presence of eval()). 447 // contexts may have no variable slots (in the presence of eval()).
443 while (*p != NULL) { 448 while (*p != NULL) {
444 if (*p == name) { 449 if (*p == name) {
445 ASSERT(((p - p0) & 1) == 0); 450 ASSERT(((p - p0) & 1) == 0);
446 if (mode != NULL) { 451 int v;
447 ReadInt(p + 1, reinterpret_cast<int*>(mode)); 452 ReadInt(p + 1, &v);
448 } 453 Variable::Mode mode_value = static_cast<Variable::Mode>(v);
449 return ((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; 454 if (mode != NULL) *mode = mode_value;
455 result = ((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS;
456 ContextSlotCache::Update(code, name, mode_value, result);
457 return result;
450 } 458 }
451 p += 2; 459 p += 2;
452 } 460 }
453 } 461 }
462 ContextSlotCache::Update(code, name, Variable::INTERNAL, -1);
454 return -1; 463 return -1;
455 } 464 }
456 465
457 466
458 template<class Allocator> 467 template<class Allocator>
459 int ScopeInfo<Allocator>::ParameterIndex(Code* code, String* name) { 468 int ScopeInfo<Allocator>::ParameterIndex(Code* code, String* name) {
460 ASSERT(name->IsSymbol()); 469 ASSERT(name->IsSymbol());
461 if (code->sinfo_size() > 0) { 470 if (code->sinfo_size() > 0) {
462 // We must read parameters from the end since for 471 // We must read parameters from the end since for
463 // multiply declared parameters the value of the 472 // multiply declared parameters the value of the
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 int ScopeInfo<Allocator>::NumberOfLocals() const { 528 int ScopeInfo<Allocator>::NumberOfLocals() const {
520 int number_of_locals = number_of_stack_slots(); 529 int number_of_locals = number_of_stack_slots();
521 if (number_of_context_slots() > 0) { 530 if (number_of_context_slots() > 0) {
522 ASSERT(number_of_context_slots() >= Context::MIN_CONTEXT_SLOTS); 531 ASSERT(number_of_context_slots() >= Context::MIN_CONTEXT_SLOTS);
523 number_of_locals += number_of_context_slots() - Context::MIN_CONTEXT_SLOTS; 532 number_of_locals += number_of_context_slots() - Context::MIN_CONTEXT_SLOTS;
524 } 533 }
525 return number_of_locals; 534 return number_of_locals;
526 } 535 }
527 536
528 537
538 int ContextSlotCache::Hash(Code* code, String* name) {
539 // Uses only lower 32 bits if pointers are larger.
540 uintptr_t addr_hash =
541 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(code)) >> 2;
542 return (addr_hash ^ name->Hash()) % kLength;
543 }
544
545
546 int ContextSlotCache::Lookup(Code* code,
547 String* name,
548 Variable::Mode* mode) {
549 int index = Hash(code, name);
550 Key& key = keys_[index];
551 if ((key.code == code) && key.name->Equals(name)) {
552 Value result(values_[index]);
553 if (mode != NULL) *mode = result.mode();
554 return result.index() + kNotFound;
555 }
556 return kNotFound;
557 }
558
559
560 void ContextSlotCache::Update(Code* code,
561 String* name,
562 Variable::Mode mode,
563 int slot_index) {
564 String* symbol;
565 ASSERT(slot_index > kNotFound);
566 if (Heap::LookupSymbolIfExists(name, &symbol)) {
567 int index = Hash(code, symbol);
568 Key& key = keys_[index];
569 key.code = code;
570 key.name = symbol;
571 // Please note value only takes a uint as index.
572 values_[index] = Value(mode, slot_index - kNotFound).raw();
529 #ifdef DEBUG 573 #ifdef DEBUG
574 Check(code, name, mode, slot_index);
575 #endif
576 }
577 }
578
579
580 void ContextSlotCache::Clear() {
581 for (int index = 0; index < kLength; index++) keys_[index].code = NULL;
582 }
583
584
585 ContextSlotCache::Key ContextSlotCache::keys_[ContextSlotCache::kLength];
586
587
588 uint32_t ContextSlotCache::values_[ContextSlotCache::kLength];
589
590
591 #ifdef DEBUG
592
593 void ContextSlotCache::Check(Code* code,
594 String* name,
595 Variable::Mode mode,
596 int slot_index) {
597 String* symbol;
598 if (Heap::LookupSymbolIfExists(name, &symbol)) {
599 int index = Hash(code, name);
600 Key& key = keys_[index];
601 ASSERT(key.code == code);
602 ASSERT(key.name->Equals(name));
603 Value result(values_[index]);
604 ASSERT(result.mode() == mode);
605 ASSERT(result.index() + kNotFound == slot_index);
606 }
607 }
608
609
530 template <class Allocator> 610 template <class Allocator>
531 static void PrintList(const char* list_name, 611 static void PrintList(const char* list_name,
532 int nof_internal_slots, 612 int nof_internal_slots,
533 List<Handle<String>, Allocator>& list) { 613 List<Handle<String>, Allocator>& list) {
534 if (list.length() > 0) { 614 if (list.length() > 0) {
535 PrintF("\n // %s\n", list_name); 615 PrintF("\n // %s\n", list_name);
536 if (nof_internal_slots > 0) { 616 if (nof_internal_slots > 0) {
537 PrintF(" %2d - %2d [internal slots]\n", 0 , nof_internal_slots - 1); 617 PrintF(" %2d - %2d [internal slots]\n", 0 , nof_internal_slots - 1);
538 } 618 }
539 for (int i = 0; i < list.length(); i++) { 619 for (int i = 0; i < list.length(); i++) {
(...skipping 23 matching lines...) Expand all
563 } 643 }
564 #endif // DEBUG 644 #endif // DEBUG
565 645
566 646
567 // Make sure the classes get instantiated by the template system. 647 // Make sure the classes get instantiated by the template system.
568 template class ScopeInfo<FreeStoreAllocationPolicy>; 648 template class ScopeInfo<FreeStoreAllocationPolicy>;
569 template class ScopeInfo<PreallocatedStorage>; 649 template class ScopeInfo<PreallocatedStorage>;
570 template class ScopeInfo<ZoneListAllocationPolicy>; 650 template class ScopeInfo<ZoneListAllocationPolicy>;
571 651
572 } } // namespace v8::internal 652 } } // namespace v8::internal
OLDNEW
« src/scopeinfo.h ('K') | « src/scopeinfo.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698