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 #include "src/snapshot/serializer-common.h" | 5 #include "src/snapshot/serializer-common.h" |
6 | 6 |
7 #include "src/external-reference-table.h" | 7 #include "src/external-reference-table.h" |
8 #include "src/ic/stub-cache.h" | 8 #include "src/ic/stub-cache.h" |
9 #include "src/list-inl.h" | 9 #include "src/list-inl.h" |
10 | 10 |
| 11 #if defined(DEBUG) && defined(V8_OS_LINUX) && !defined(V8_OS_ANDROID) |
| 12 #define SYMBOLIZE_FUNCTION |
| 13 #include <execinfo.h> |
| 14 #endif // DEBUG && V8_OS_LINUX && !V8_OS_ANDROID |
| 15 |
11 namespace v8 { | 16 namespace v8 { |
12 namespace internal { | 17 namespace internal { |
13 | 18 |
14 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) { | 19 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) { |
15 map_ = isolate->external_reference_map(); | 20 map_ = isolate->external_reference_map(); |
16 #ifdef DEBUG | |
17 table_ = ExternalReferenceTable::instance(isolate); | |
18 #endif // DEBUG | |
19 if (map_ != nullptr) return; | 21 if (map_ != nullptr) return; |
20 map_ = new AddressToIndexHashMap(); | 22 map_ = new AddressToIndexHashMap(); |
21 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); | 23 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); |
22 for (uint32_t i = 0; i < table->size(); ++i) { | 24 for (uint32_t i = 0; i < table->size(); ++i) { |
23 Address addr = table->address(i); | 25 Address addr = table->address(i); |
24 DCHECK(map_->Get(addr).IsNothing() || | 26 // We expect no duplicate external references entries in the table. |
25 strncmp(table->name(i), "Redirect to ", 12) == 0); | 27 // AccessorRefTable getter may have duplicates, indicated by an empty string |
| 28 // as name. |
| 29 DCHECK(table->name(i)[0] == '\0' || map_->Get(addr).IsNothing()); |
26 map_->Set(addr, i); | 30 map_->Set(addr, i); |
27 DCHECK(map_->Get(addr).IsJust()); | 31 DCHECK(map_->Get(addr).IsJust()); |
28 } | 32 } |
29 isolate->set_external_reference_map(map_); | 33 isolate->set_external_reference_map(map_); |
30 } | 34 } |
31 | 35 |
32 uint32_t ExternalReferenceEncoder::Encode(Address address) const { | 36 uint32_t ExternalReferenceEncoder::Encode(Address address) const { |
33 Maybe<uint32_t> maybe_index = map_->Get(address); | 37 Maybe<uint32_t> maybe_index = map_->Get(address); |
34 if (maybe_index.IsNothing()) { | 38 if (maybe_index.IsNothing()) { |
35 void* addr = address; | 39 void* function_addr = address; |
36 v8::base::OS::PrintError("Unknown external reference %p.\n", addr); | 40 v8::base::OS::PrintError("Unknown external reference %p.\n", function_addr); |
37 v8::base::OS::PrintError("%s", ExternalReferenceTable::ResolveSymbol(addr)); | 41 #ifdef SYMBOLIZE_FUNCTION |
| 42 v8::base::OS::PrintError("%s\n", backtrace_symbols(&function_addr, 1)[0]); |
| 43 #endif // SYMBOLIZE_FUNCTION |
38 v8::base::OS::Abort(); | 44 v8::base::OS::Abort(); |
39 } | 45 } |
40 #ifdef DEBUG | |
41 table_->increment_count(maybe_index.FromJust()); | |
42 #endif // DEBUG | |
43 return maybe_index.FromJust(); | 46 return maybe_index.FromJust(); |
44 } | 47 } |
45 | 48 |
46 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate, | 49 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate, |
47 Address address) const { | 50 Address address) const { |
48 Maybe<uint32_t> maybe_index = map_->Get(address); | 51 Maybe<uint32_t> maybe_index = map_->Get(address); |
49 if (maybe_index.IsNothing()) return "<unknown>"; | 52 if (maybe_index.IsNothing()) return "<unknown>"; |
50 return ExternalReferenceTable::instance(isolate)->name( | 53 return ExternalReferenceTable::instance(isolate)->name( |
51 maybe_index.FromJust()); | 54 maybe_index.FromJust()); |
52 } | 55 } |
(...skipping 23 matching lines...) Expand all Loading... |
76 if (cache->at(i)->IsUndefined(isolate)) break; | 79 if (cache->at(i)->IsUndefined(isolate)) break; |
77 } | 80 } |
78 } | 81 } |
79 | 82 |
80 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { | 83 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { |
81 return !o->IsString() && !o->IsScript(); | 84 return !o->IsString() && !o->IsScript(); |
82 } | 85 } |
83 | 86 |
84 } // namespace internal | 87 } // namespace internal |
85 } // namespace v8 | 88 } // namespace v8 |
OLD | NEW |