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

Side by Side Diff: src/serialize.cc

Issue 19724007: Logger: introduce abstract interface for CodeEvent listeners. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments addressed. rebaselined. Created 7 years, 4 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
« no previous file with comments | « src/serialize.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 DeleteArray(encodings_[type]); 658 DeleteArray(encodings_[type]);
659 } 659 }
660 DeleteArray(encodings_); 660 DeleteArray(encodings_);
661 } 661 }
662 662
663 663
664 bool Serializer::serialization_enabled_ = false; 664 bool Serializer::serialization_enabled_ = false;
665 bool Serializer::too_late_to_enable_now_ = false; 665 bool Serializer::too_late_to_enable_now_ = false;
666 666
667 667
668 class CodeAddressMap: public CodeEventLogger {
669 public:
670 explicit CodeAddressMap(Isolate* isolate)
671 : isolate_(isolate) {
672 isolate->logger()->addCodeEventListener(this);
673 }
674
675 virtual ~CodeAddressMap() {
676 isolate_->logger()->removeCodeEventListener(this);
677 }
678
679 virtual void CodeMoveEvent(Address from, Address to) {
680 address_to_name_map_.Move(from, to);
681 }
682
683 virtual void CodeDeleteEvent(Address from) {
684 address_to_name_map_.Remove(from);
685 }
686
687 const char* Lookup(Address address) {
688 return address_to_name_map_.Lookup(address);
689 }
690
691 private:
692 class NameMap {
693 public:
694 NameMap() : impl_(&PointerEquals) {}
695
696 ~NameMap() {
697 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) {
698 DeleteArray(static_cast<const char*>(p->value));
699 }
700 }
701
702 void Insert(Address code_address, const char* name, int name_size) {
703 HashMap::Entry* entry = FindOrCreateEntry(code_address);
704 if (entry->value == NULL) {
705 entry->value = CopyName(name, name_size);
706 }
707 }
708
709 const char* Lookup(Address code_address) {
710 HashMap::Entry* entry = FindEntry(code_address);
711 return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL;
712 }
713
714 void Remove(Address code_address) {
715 HashMap::Entry* entry = FindEntry(code_address);
716 if (entry != NULL) {
717 DeleteArray(static_cast<char*>(entry->value));
718 RemoveEntry(entry);
719 }
720 }
721
722 void Move(Address from, Address to) {
723 if (from == to) return;
724 HashMap::Entry* from_entry = FindEntry(from);
725 ASSERT(from_entry != NULL);
726 void* value = from_entry->value;
727 RemoveEntry(from_entry);
728 HashMap::Entry* to_entry = FindOrCreateEntry(to);
729 ASSERT(to_entry->value == NULL);
730 to_entry->value = value;
731 }
732
733 private:
734 static bool PointerEquals(void* lhs, void* rhs) {
735 return lhs == rhs;
736 }
737
738 static char* CopyName(const char* name, int name_size) {
739 char* result = NewArray<char>(name_size + 1);
740 for (int i = 0; i < name_size; ++i) {
741 char c = name[i];
742 if (c == '\0') c = ' ';
743 result[i] = c;
744 }
745 result[name_size] = '\0';
746 return result;
747 }
748
749 HashMap::Entry* FindOrCreateEntry(Address code_address) {
750 return impl_.Lookup(code_address, ComputePointerHash(code_address), true);
751 }
752
753 HashMap::Entry* FindEntry(Address code_address) {
754 return impl_.Lookup(code_address,
755 ComputePointerHash(code_address),
756 false);
757 }
758
759 void RemoveEntry(HashMap::Entry* entry) {
760 impl_.Remove(entry->key, entry->hash);
761 }
762
763 HashMap impl_;
764
765 DISALLOW_COPY_AND_ASSIGN(NameMap);
766 };
767
768 virtual void LogRecordedBuffer(Code* code,
769 SharedFunctionInfo*,
770 const char* name,
771 int length) {
772 address_to_name_map_.Insert(code->address(), name, length);
773 }
774
775 NameMap address_to_name_map_;
776 Isolate* isolate_;
777 };
778
779
780 CodeAddressMap* Serializer::code_address_map_ = NULL;
781
782
783 void Serializer::Enable() {
784 if (!serialization_enabled_) {
785 ASSERT(!too_late_to_enable_now_);
786 }
787 if (serialization_enabled_) return;
788 serialization_enabled_ = true;
789 i::Isolate* isolate = Isolate::Current();
790 isolate->InitializeLoggingAndCounters();
791 code_address_map_ = new CodeAddressMap(isolate);
792 }
793
794
795 void Serializer::Disable() {
796 if (!serialization_enabled_) return;
797 serialization_enabled_ = false;
798 delete code_address_map_;
799 code_address_map_ = NULL;
800 }
801
802
668 Deserializer::Deserializer(SnapshotByteSource* source) 803 Deserializer::Deserializer(SnapshotByteSource* source)
669 : isolate_(NULL), 804 : isolate_(NULL),
670 source_(source), 805 source_(source),
671 external_reference_decoder_(NULL) { 806 external_reference_decoder_(NULL) {
672 for (int i = 0; i < LAST_SPACE + 1; i++) { 807 for (int i = 0; i < LAST_SPACE + 1; i++) {
673 reservations_[i] = kUninitializedReservation; 808 reservations_[i] = kUninitializedReservation;
674 } 809 }
675 } 810 }
676 811
677 812
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 1586
1452 1587
1453 void Serializer::ObjectSerializer::Serialize() { 1588 void Serializer::ObjectSerializer::Serialize() {
1454 int space = Serializer::SpaceOfObject(object_); 1589 int space = Serializer::SpaceOfObject(object_);
1455 int size = object_->Size(); 1590 int size = object_->Size();
1456 1591
1457 sink_->Put(kNewObject + reference_representation_ + space, 1592 sink_->Put(kNewObject + reference_representation_ + space,
1458 "ObjectSerialization"); 1593 "ObjectSerialization");
1459 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words"); 1594 sink_->PutInt(size >> kObjectAlignmentBits, "Size in words");
1460 1595
1461 LOG(i::Isolate::Current(), 1596 ASSERT(code_address_map_);
1597 const char* code_name = code_address_map_->Lookup(object_->address());
1598 LOG(serializer_->isolate_,
1599 CodeNameEvent(object_->address(), sink_->Position(), code_name));
1600 LOG(serializer_->isolate_,
1462 SnapshotPositionEvent(object_->address(), sink_->Position())); 1601 SnapshotPositionEvent(object_->address(), sink_->Position()));
1463 1602
1464 // Mark this object as already serialized. 1603 // Mark this object as already serialized.
1465 int offset = serializer_->Allocate(space, size); 1604 int offset = serializer_->Allocate(space, size);
1466 serializer_->address_mapper()->AddMapping(object_, offset); 1605 serializer_->address_mapper()->AddMapping(object_, offset);
1467 1606
1468 // Serialize the map (first word of the object). 1607 // Serialize the map (first word of the object).
1469 serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0); 1608 serializer_->SerializeObject(object_->map(), kPlain, kStartOfObject, 0);
1470 1609
1471 // Serialize the rest of the object. 1610 // Serialize the rest of the object.
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 1856
1718 bool SnapshotByteSource::AtEOF() { 1857 bool SnapshotByteSource::AtEOF() {
1719 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false; 1858 if (0u + length_ - position_ > 2 * sizeof(uint32_t)) return false;
1720 for (int x = position_; x < length_; x++) { 1859 for (int x = position_; x < length_; x++) {
1721 if (data_[x] != SerializerDeserializer::nop()) return false; 1860 if (data_[x] != SerializerDeserializer::nop()) return false;
1722 } 1861 }
1723 return true; 1862 return true;
1724 } 1863 }
1725 1864
1726 } } // namespace v8::internal 1865 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698