OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_SNAPSHOT_SERIALIZER_H_ | 5 #ifndef V8_SNAPSHOT_SERIALIZER_H_ |
6 #define V8_SNAPSHOT_SERIALIZER_H_ | 6 #define V8_SNAPSHOT_SERIALIZER_H_ |
7 | 7 |
8 #include "src/isolate.h" | 8 #include "src/isolate.h" |
9 #include "src/log.h" | 9 #include "src/log.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 void CodeDisableOptEvent(AbstractCode* code, | 31 void CodeDisableOptEvent(AbstractCode* code, |
32 SharedFunctionInfo* shared) override {} | 32 SharedFunctionInfo* shared) override {} |
33 | 33 |
34 const char* Lookup(Address address) { | 34 const char* Lookup(Address address) { |
35 return address_to_name_map_.Lookup(address); | 35 return address_to_name_map_.Lookup(address); |
36 } | 36 } |
37 | 37 |
38 private: | 38 private: |
39 class NameMap { | 39 class NameMap { |
40 public: | 40 public: |
41 NameMap() : impl_(HashMap::PointersMatch) {} | 41 NameMap() : impl_(base::HashMap::PointersMatch) {} |
42 | 42 |
43 ~NameMap() { | 43 ~NameMap() { |
44 for (HashMap::Entry* p = impl_.Start(); p != NULL; p = impl_.Next(p)) { | 44 for (base::HashMap::Entry* p = impl_.Start(); p != NULL; |
| 45 p = impl_.Next(p)) { |
45 DeleteArray(static_cast<const char*>(p->value)); | 46 DeleteArray(static_cast<const char*>(p->value)); |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 void Insert(Address code_address, const char* name, int name_size) { | 50 void Insert(Address code_address, const char* name, int name_size) { |
50 HashMap::Entry* entry = FindOrCreateEntry(code_address); | 51 base::HashMap::Entry* entry = FindOrCreateEntry(code_address); |
51 if (entry->value == NULL) { | 52 if (entry->value == NULL) { |
52 entry->value = CopyName(name, name_size); | 53 entry->value = CopyName(name, name_size); |
53 } | 54 } |
54 } | 55 } |
55 | 56 |
56 const char* Lookup(Address code_address) { | 57 const char* Lookup(Address code_address) { |
57 HashMap::Entry* entry = FindEntry(code_address); | 58 base::HashMap::Entry* entry = FindEntry(code_address); |
58 return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL; | 59 return (entry != NULL) ? static_cast<const char*>(entry->value) : NULL; |
59 } | 60 } |
60 | 61 |
61 void Remove(Address code_address) { | 62 void Remove(Address code_address) { |
62 HashMap::Entry* entry = FindEntry(code_address); | 63 base::HashMap::Entry* entry = FindEntry(code_address); |
63 if (entry != NULL) { | 64 if (entry != NULL) { |
64 DeleteArray(static_cast<char*>(entry->value)); | 65 DeleteArray(static_cast<char*>(entry->value)); |
65 RemoveEntry(entry); | 66 RemoveEntry(entry); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
69 void Move(Address from, Address to) { | 70 void Move(Address from, Address to) { |
70 if (from == to) return; | 71 if (from == to) return; |
71 HashMap::Entry* from_entry = FindEntry(from); | 72 base::HashMap::Entry* from_entry = FindEntry(from); |
72 DCHECK(from_entry != NULL); | 73 DCHECK(from_entry != NULL); |
73 void* value = from_entry->value; | 74 void* value = from_entry->value; |
74 RemoveEntry(from_entry); | 75 RemoveEntry(from_entry); |
75 HashMap::Entry* to_entry = FindOrCreateEntry(to); | 76 base::HashMap::Entry* to_entry = FindOrCreateEntry(to); |
76 DCHECK(to_entry->value == NULL); | 77 DCHECK(to_entry->value == NULL); |
77 to_entry->value = value; | 78 to_entry->value = value; |
78 } | 79 } |
79 | 80 |
80 private: | 81 private: |
81 static char* CopyName(const char* name, int name_size) { | 82 static char* CopyName(const char* name, int name_size) { |
82 char* result = NewArray<char>(name_size + 1); | 83 char* result = NewArray<char>(name_size + 1); |
83 for (int i = 0; i < name_size; ++i) { | 84 for (int i = 0; i < name_size; ++i) { |
84 char c = name[i]; | 85 char c = name[i]; |
85 if (c == '\0') c = ' '; | 86 if (c == '\0') c = ' '; |
86 result[i] = c; | 87 result[i] = c; |
87 } | 88 } |
88 result[name_size] = '\0'; | 89 result[name_size] = '\0'; |
89 return result; | 90 return result; |
90 } | 91 } |
91 | 92 |
92 HashMap::Entry* FindOrCreateEntry(Address code_address) { | 93 base::HashMap::Entry* FindOrCreateEntry(Address code_address) { |
93 return impl_.LookupOrInsert(code_address, | 94 return impl_.LookupOrInsert(code_address, |
94 ComputePointerHash(code_address)); | 95 ComputePointerHash(code_address)); |
95 } | 96 } |
96 | 97 |
97 HashMap::Entry* FindEntry(Address code_address) { | 98 base::HashMap::Entry* FindEntry(Address code_address) { |
98 return impl_.Lookup(code_address, ComputePointerHash(code_address)); | 99 return impl_.Lookup(code_address, ComputePointerHash(code_address)); |
99 } | 100 } |
100 | 101 |
101 void RemoveEntry(HashMap::Entry* entry) { | 102 void RemoveEntry(base::HashMap::Entry* entry) { |
102 impl_.Remove(entry->key, entry->hash); | 103 impl_.Remove(entry->key, entry->hash); |
103 } | 104 } |
104 | 105 |
105 HashMap impl_; | 106 base::HashMap impl_; |
106 | 107 |
107 DISALLOW_COPY_AND_ASSIGN(NameMap); | 108 DISALLOW_COPY_AND_ASSIGN(NameMap); |
108 }; | 109 }; |
109 | 110 |
110 void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*, | 111 void LogRecordedBuffer(AbstractCode* code, SharedFunctionInfo*, |
111 const char* name, int length) override { | 112 const char* name, int length) override { |
112 address_to_name_map_.Insert(code->address(), name, length); | 113 address_to_name_map_.Insert(code->address(), name, length); |
113 } | 114 } |
114 | 115 |
115 NameMap address_to_name_map_; | 116 NameMap address_to_name_map_; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 SnapshotByteSink* sink_; | 316 SnapshotByteSink* sink_; |
316 int reference_representation_; | 317 int reference_representation_; |
317 int bytes_processed_so_far_; | 318 int bytes_processed_so_far_; |
318 bool code_has_been_output_; | 319 bool code_has_been_output_; |
319 }; | 320 }; |
320 | 321 |
321 } // namespace internal | 322 } // namespace internal |
322 } // namespace v8 | 323 } // namespace v8 |
323 | 324 |
324 #endif // V8_SNAPSHOT_SERIALIZER_H_ | 325 #endif // V8_SNAPSHOT_SERIALIZER_H_ |
OLD | NEW |