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

Side by Side Diff: src/runtime/runtime.cc

Issue 2324803002: [Parser] Avoid on-the-fly internalization for natives_syntax. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « src/runtime/runtime.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 // 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/runtime/runtime.h" 5 #include "src/runtime/runtime.h"
6 6
7 #include "src/assembler.h" 7 #include "src/assembler.h"
8 #include "src/base/hashmap.h"
8 #include "src/contexts.h" 9 #include "src/contexts.h"
9 #include "src/handles-inl.h" 10 #include "src/handles-inl.h"
10 #include "src/heap/heap.h" 11 #include "src/heap/heap.h"
11 #include "src/isolate.h" 12 #include "src/isolate.h"
12 #include "src/runtime/runtime-utils.h" 13 #include "src/runtime/runtime-utils.h"
13 14
14 namespace v8 { 15 namespace v8 {
15 namespace internal { 16 namespace internal {
16 17
17 // Header of runtime functions. 18 // Header of runtime functions.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 , 51 ,
51 52
52 static const Runtime::Function kIntrinsicFunctions[] = { 53 static const Runtime::Function kIntrinsicFunctions[] = {
53 FOR_EACH_INTRINSIC(F) 54 FOR_EACH_INTRINSIC(F)
54 FOR_EACH_INTRINSIC(I) 55 FOR_EACH_INTRINSIC(I)
55 }; 56 };
56 57
57 #undef I 58 #undef I
58 #undef F 59 #undef F
59 60
61 namespace {
60 62
61 void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate, 63 V8_DECLARE_ONCE(initialize_function_name_map_once);
62 Handle<NameDictionary> dict) { 64 static const base::HashMap* kRuntimeFunctionNameMap;
63 DCHECK(dict->NumberOfElements() == 0); 65
64 HandleScope scope(isolate); 66 struct IntrinsicFunctionIdentifier {
65 for (int i = 0; i < kNumFunctions; ++i) { 67 IntrinsicFunctionIdentifier(const unsigned char* data, const int length)
66 const char* name = kIntrinsicFunctions[i].name; 68 : data_(data), length_(length) {}
67 if (name == NULL) continue; 69
68 Handle<NameDictionary> new_dict = NameDictionary::Add( 70 static bool Match(void* key1, void* key2) {
69 dict, isolate->factory()->InternalizeUtf8String(name), 71 const IntrinsicFunctionIdentifier* lhs =
70 Handle<Smi>(Smi::FromInt(i), isolate), PropertyDetails::Empty()); 72 static_cast<IntrinsicFunctionIdentifier*>(key1);
71 // The dictionary does not need to grow. 73 const IntrinsicFunctionIdentifier* rhs =
72 CHECK(new_dict.is_identical_to(dict)); 74 static_cast<IntrinsicFunctionIdentifier*>(key2);
75 if (lhs->length_ != rhs->length_) return false;
76 return CompareCharsUnsigned(reinterpret_cast<const uint8_t*>(lhs->data_),
77 reinterpret_cast<const uint8_t*>(rhs->data_),
78 rhs->length_) == 0;
73 } 79 }
80
81 uint32_t Hash() {
82 return StringHasher::HashSequentialString<uint8_t>(
83 data_, length_, v8::internal::kZeroHashSeed);
84 }
85
86 const unsigned char* data_;
87 const int length_;
88 };
89
90 void InitializeIntrinsicFunctionNames() {
91 base::HashMap* function_name_map =
92 new base::HashMap(IntrinsicFunctionIdentifier::Match);
93 for (size_t i = 0; i < arraysize(kIntrinsicFunctions); ++i) {
94 const Runtime::Function* function = &kIntrinsicFunctions[i];
95 IntrinsicFunctionIdentifier* identifier = new IntrinsicFunctionIdentifier(
96 reinterpret_cast<const unsigned char*>(function->name),
97 static_cast<int>(strlen(function->name)));
98 base::HashMap::Entry* entry =
99 function_name_map->InsertNew(identifier, identifier->Hash());
100 entry->value = const_cast<Runtime::Function*>(function);
101 }
102 kRuntimeFunctionNameMap = function_name_map;
74 } 103 }
75 104
105 } // namespace
76 106
77 const Runtime::Function* Runtime::FunctionForName(Handle<String> name) { 107 const Runtime::Function* Runtime::FunctionForName(const unsigned char* name,
78 Heap* heap = name->GetHeap(); 108 int length) {
79 int entry = heap->intrinsic_function_names()->FindEntry(name); 109 base::CallOnce(&initialize_function_name_map_once,
80 if (entry != kNotFound) { 110 &InitializeIntrinsicFunctionNames);
81 Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry); 111 IntrinsicFunctionIdentifier identifier(name, length);
82 int function_index = Smi::cast(smi_index)->value(); 112 base::HashMap::Entry* entry =
83 return &(kIntrinsicFunctions[function_index]); 113 kRuntimeFunctionNameMap->Lookup(&identifier, identifier.Hash());
114 if (entry) {
115 return reinterpret_cast<Function*>(entry->value);
84 } 116 }
85 return NULL; 117 return NULL;
86 } 118 }
87 119
88 120
89 const Runtime::Function* Runtime::FunctionForEntry(Address entry) { 121 const Runtime::Function* Runtime::FunctionForEntry(Address entry) {
90 for (size_t i = 0; i < arraysize(kIntrinsicFunctions); ++i) { 122 for (size_t i = 0; i < arraysize(kIntrinsicFunctions); ++i) {
91 if (entry == kIntrinsicFunctions[i].entry) { 123 if (entry == kIntrinsicFunctions[i].entry) {
92 return &(kIntrinsicFunctions[i]); 124 return &(kIntrinsicFunctions[i]);
93 } 125 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 158 }
127 159
128 160
129 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) { 161 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) {
130 return os << Runtime::FunctionForId(id)->name; 162 return os << Runtime::FunctionForId(id)->name;
131 } 163 }
132 164
133 165
134 } // namespace internal 166 } // namespace internal
135 } // namespace v8 167 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698