| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/profile-generator-inl.h" | 7 #include "src/profile-generator-inl.h" |
| 8 | 8 |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/debug.h" | 10 #include "src/debug.h" |
| 11 #include "src/deoptimizer.h" | 11 #include "src/deoptimizer.h" |
| 12 #include "src/global-handles.h" | 12 #include "src/global-handles.h" |
| 13 #include "src/sampler.h" | 13 #include "src/sampler.h" |
| 14 #include "src/scopeinfo.h" | 14 #include "src/scopeinfo.h" |
| 15 #include "src/unicode.h" | 15 #include "src/unicode.h" |
| 16 | 16 |
| 17 namespace v8 { | 17 namespace v8 { |
| 18 namespace internal { | 18 namespace internal { |
| 19 | 19 |
| 20 | 20 |
| 21 bool StringsStorage::StringsMatch(void* key1, void* key2) { | |
| 22 return strcmp(reinterpret_cast<char*>(key1), | |
| 23 reinterpret_cast<char*>(key2)) == 0; | |
| 24 } | |
| 25 | |
| 26 | |
| 27 StringsStorage::StringsStorage(Heap* heap) | |
| 28 : hash_seed_(heap->HashSeed()), names_(StringsMatch) { | |
| 29 } | |
| 30 | |
| 31 | |
| 32 StringsStorage::~StringsStorage() { | |
| 33 for (HashMap::Entry* p = names_.Start(); | |
| 34 p != NULL; | |
| 35 p = names_.Next(p)) { | |
| 36 DeleteArray(reinterpret_cast<const char*>(p->value)); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 | |
| 41 const char* StringsStorage::GetCopy(const char* src) { | |
| 42 int len = static_cast<int>(strlen(src)); | |
| 43 HashMap::Entry* entry = GetEntry(src, len); | |
| 44 if (entry->value == NULL) { | |
| 45 Vector<char> dst = Vector<char>::New(len + 1); | |
| 46 StrNCpy(dst, src, len); | |
| 47 dst[len] = '\0'; | |
| 48 entry->key = dst.start(); | |
| 49 entry->value = entry->key; | |
| 50 } | |
| 51 return reinterpret_cast<const char*>(entry->value); | |
| 52 } | |
| 53 | |
| 54 | |
| 55 const char* StringsStorage::GetFormatted(const char* format, ...) { | |
| 56 va_list args; | |
| 57 va_start(args, format); | |
| 58 const char* result = GetVFormatted(format, args); | |
| 59 va_end(args); | |
| 60 return result; | |
| 61 } | |
| 62 | |
| 63 | |
| 64 const char* StringsStorage::AddOrDisposeString(char* str, int len) { | |
| 65 HashMap::Entry* entry = GetEntry(str, len); | |
| 66 if (entry->value == NULL) { | |
| 67 // New entry added. | |
| 68 entry->key = str; | |
| 69 entry->value = str; | |
| 70 } else { | |
| 71 DeleteArray(str); | |
| 72 } | |
| 73 return reinterpret_cast<const char*>(entry->value); | |
| 74 } | |
| 75 | |
| 76 | |
| 77 const char* StringsStorage::GetVFormatted(const char* format, va_list args) { | |
| 78 Vector<char> str = Vector<char>::New(1024); | |
| 79 int len = VSNPrintF(str, format, args); | |
| 80 if (len == -1) { | |
| 81 DeleteArray(str.start()); | |
| 82 return GetCopy(format); | |
| 83 } | |
| 84 return AddOrDisposeString(str.start(), len); | |
| 85 } | |
| 86 | |
| 87 | |
| 88 const char* StringsStorage::GetName(Name* name) { | |
| 89 if (name->IsString()) { | |
| 90 String* str = String::cast(name); | |
| 91 int length = Min(kMaxNameSize, str->length()); | |
| 92 int actual_length = 0; | |
| 93 SmartArrayPointer<char> data = | |
| 94 str->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL, 0, length, | |
| 95 &actual_length); | |
| 96 return AddOrDisposeString(data.Detach(), actual_length); | |
| 97 } else if (name->IsSymbol()) { | |
| 98 return "<symbol>"; | |
| 99 } | |
| 100 return ""; | |
| 101 } | |
| 102 | |
| 103 | |
| 104 const char* StringsStorage::GetName(int index) { | |
| 105 return GetFormatted("%d", index); | |
| 106 } | |
| 107 | |
| 108 | |
| 109 const char* StringsStorage::GetFunctionName(Name* name) { | |
| 110 return GetName(name); | |
| 111 } | |
| 112 | |
| 113 | |
| 114 const char* StringsStorage::GetFunctionName(const char* name) { | |
| 115 return GetCopy(name); | |
| 116 } | |
| 117 | |
| 118 | |
| 119 size_t StringsStorage::GetUsedMemorySize() const { | |
| 120 size_t size = sizeof(*this); | |
| 121 size += sizeof(HashMap::Entry) * names_.capacity(); | |
| 122 for (HashMap::Entry* p = names_.Start(); p != NULL; p = names_.Next(p)) { | |
| 123 size += strlen(reinterpret_cast<const char*>(p->value)) + 1; | |
| 124 } | |
| 125 return size; | |
| 126 } | |
| 127 | |
| 128 | |
| 129 HashMap::Entry* StringsStorage::GetEntry(const char* str, int len) { | |
| 130 uint32_t hash = StringHasher::HashSequentialString(str, len, hash_seed_); | |
| 131 return names_.Lookup(const_cast<char*>(str), hash, true); | |
| 132 } | |
| 133 | |
| 134 | |
| 135 JITLineInfoTable::JITLineInfoTable() {} | 21 JITLineInfoTable::JITLineInfoTable() {} |
| 136 | 22 |
| 137 | 23 |
| 138 JITLineInfoTable::~JITLineInfoTable() {} | 24 JITLineInfoTable::~JITLineInfoTable() {} |
| 139 | 25 |
| 140 | 26 |
| 141 void JITLineInfoTable::SetPosition(int pc_offset, int line) { | 27 void JITLineInfoTable::SetPosition(int pc_offset, int line) { |
| 142 DCHECK(pc_offset >= 0); | 28 DCHECK(pc_offset >= 0); |
| 143 DCHECK(line > 0); // The 1-based number of the source line. | 29 DCHECK(line > 0); // The 1-based number of the source line. |
| 144 if (GetSourceLineNumber(pc_offset) != line) { | 30 if (GetSourceLineNumber(pc_offset) != line) { |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 case OTHER: | 650 case OTHER: |
| 765 case EXTERNAL: | 651 case EXTERNAL: |
| 766 return program_entry_; | 652 return program_entry_; |
| 767 case IDLE: | 653 case IDLE: |
| 768 return idle_entry_; | 654 return idle_entry_; |
| 769 default: return NULL; | 655 default: return NULL; |
| 770 } | 656 } |
| 771 } | 657 } |
| 772 | 658 |
| 773 } } // namespace v8::internal | 659 } } // namespace v8::internal |
| OLD | NEW |