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) | 11 #if defined(DEBUG) && defined(V8_OS_LINUX) && !defined(V8_OS_ANDROID) |
12 #define SYMBOLIZE_FUNCTION | 12 #define SYMBOLIZE_FUNCTION |
13 #include <execinfo.h> | 13 #include <execinfo.h> |
14 #endif // DEBUG && V8_OS_LINUX && !V8_OS_ANDROID | 14 #endif // DEBUG && V8_OS_LINUX && !V8_OS_ANDROID |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 namespace internal { | 17 namespace internal { |
18 | 18 |
19 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) { | 19 ExternalReferenceEncoder::ExternalReferenceEncoder(Isolate* isolate) { |
20 map_ = isolate->external_reference_map(); | 20 map_ = isolate->external_reference_map(); |
21 if (map_ != NULL) return; | 21 if (map_ != nullptr) return; |
22 map_ = new base::HashMap(); | 22 map_ = new AddressToIndexHashMap(); |
23 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); | 23 ExternalReferenceTable* table = ExternalReferenceTable::instance(isolate); |
24 for (int i = 0; i < table->size(); ++i) { | 24 for (uint32_t i = 0; i < table->size(); ++i) { |
25 Address addr = table->address(i); | 25 Address addr = table->address(i); |
26 if (addr == ExternalReferenceTable::NotAvailable()) continue; | |
27 // We expect no duplicate external references entries in the table. | 26 // We expect no duplicate external references entries in the table. |
28 // AccessorRefTable getter may have duplicates, indicated by an empty string | 27 // AccessorRefTable getter may have duplicates, indicated by an empty string |
29 // as name. | 28 // as name. |
30 DCHECK(table->name(i)[0] == '\0' || | 29 DCHECK(table->name(i)[0] == '\0' || !map_->Has(addr)); |
31 map_->Lookup(addr, Hash(addr)) == nullptr); | 30 map_->Set(addr, i); |
32 map_->LookupOrInsert(addr, Hash(addr))->value = reinterpret_cast<void*>(i); | 31 DCHECK(map_->Has(addr)); |
33 } | 32 } |
34 isolate->set_external_reference_map(map_); | 33 isolate->set_external_reference_map(map_); |
35 } | 34 } |
36 | 35 |
37 uint32_t ExternalReferenceEncoder::Encode(Address address) const { | 36 uint32_t ExternalReferenceEncoder::Encode(Address address) const { |
38 DCHECK_NOT_NULL(address); | 37 if (!map_->Has(address)) { |
39 base::HashMap::Entry* entry = | |
40 const_cast<base::HashMap*>(map_)->Lookup(address, Hash(address)); | |
41 if (entry == nullptr) { | |
42 void* function_addr = address; | 38 void* function_addr = address; |
43 v8::base::OS::PrintError("Unknown external reference %p.\n", function_addr); | 39 v8::base::OS::PrintError("Unknown external reference %p.\n", function_addr); |
44 #ifdef SYMBOLIZE_FUNCTION | 40 #ifdef SYMBOLIZE_FUNCTION |
45 v8::base::OS::PrintError("%s\n", backtrace_symbols(&function_addr, 1)[0]); | 41 v8::base::OS::PrintError("%s\n", backtrace_symbols(&function_addr, 1)[0]); |
46 #endif // SYMBOLIZE_FUNCTION | 42 #endif // SYMBOLIZE_FUNCTION |
47 v8::base::OS::Abort(); | 43 v8::base::OS::Abort(); |
48 } | 44 } |
49 return static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); | 45 return map_->Get(address); |
50 } | 46 } |
51 | 47 |
52 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate, | 48 const char* ExternalReferenceEncoder::NameOfAddress(Isolate* isolate, |
53 Address address) const { | 49 Address address) const { |
54 base::HashMap::Entry* entry = | 50 if (!map_->Has(address)) return "<unknown>"; |
55 const_cast<base::HashMap*>(map_)->Lookup(address, Hash(address)); | 51 return ExternalReferenceTable::instance(isolate)->name(map_->Get(address)); |
56 if (entry == NULL) return "<unknown>"; | |
57 uint32_t i = static_cast<uint32_t>(reinterpret_cast<intptr_t>(entry->value)); | |
58 return ExternalReferenceTable::instance(isolate)->name(i); | |
59 } | 52 } |
60 | 53 |
61 void SerializedData::AllocateData(int size) { | 54 void SerializedData::AllocateData(int size) { |
62 DCHECK(!owns_data_); | 55 DCHECK(!owns_data_); |
63 data_ = NewArray<byte>(size); | 56 data_ = NewArray<byte>(size); |
64 size_ = size; | 57 size_ = size; |
65 owns_data_ = true; | 58 owns_data_ = true; |
66 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data_), kPointerAlignment)); | 59 DCHECK(IsAligned(reinterpret_cast<intptr_t>(data_), kPointerAlignment)); |
67 } | 60 } |
68 | 61 |
(...skipping 14 matching lines...) Expand all Loading... |
83 if (cache->at(i)->IsUndefined(isolate)) break; | 76 if (cache->at(i)->IsUndefined(isolate)) break; |
84 } | 77 } |
85 } | 78 } |
86 | 79 |
87 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { | 80 bool SerializerDeserializer::CanBeDeferred(HeapObject* o) { |
88 return !o->IsString() && !o->IsScript(); | 81 return !o->IsString() && !o->IsScript(); |
89 } | 82 } |
90 | 83 |
91 } // namespace internal | 84 } // namespace internal |
92 } // namespace v8 | 85 } // namespace v8 |
OLD | NEW |