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/external-reference-table.h" | 5 #include "src/external-reference-table.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
| 9 #include "src/builtins/builtins.h" |
9 #include "src/counters.h" | 10 #include "src/counters.h" |
10 #include "src/deoptimizer.h" | 11 #include "src/deoptimizer.h" |
11 #include "src/ic/stub-cache.h" | 12 #include "src/ic/stub-cache.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
| 17 // Forward declarations for C++ builtins. |
| 18 #define FORWARD_DECLARE(Name) \ |
| 19 Object* Builtin_##Name(int argc, Object** args, Isolate* isolate); |
| 20 BUILTIN_LIST_C(FORWARD_DECLARE) |
| 21 #undef FORWARD_DECLARE |
| 22 |
16 ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) { | 23 ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) { |
17 ExternalReferenceTable* external_reference_table = | 24 ExternalReferenceTable* external_reference_table = |
18 isolate->external_reference_table(); | 25 isolate->external_reference_table(); |
19 if (external_reference_table == NULL) { | 26 if (external_reference_table == NULL) { |
20 external_reference_table = new ExternalReferenceTable(isolate); | 27 external_reference_table = new ExternalReferenceTable(isolate); |
21 isolate->set_external_reference_table(external_reference_table); | 28 isolate->set_external_reference_table(external_reference_table); |
22 } | 29 } |
23 return external_reference_table; | 30 return external_reference_table; |
24 } | 31 } |
25 | 32 |
26 ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) { | 33 ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) { |
| 34 AddReferences(isolate); |
| 35 AddBuiltins(isolate); |
| 36 AddRuntimeFunctions(isolate); |
| 37 AddStatCounters(isolate); |
| 38 AddIsolateAddresses(isolate); |
| 39 AddAccessors(isolate); |
| 40 AddStubCache(isolate); |
| 41 AddDeoptEntries(isolate); |
| 42 AddApiReferences(isolate); |
| 43 } |
| 44 |
| 45 void ExternalReferenceTable::AddReferences(Isolate* isolate) { |
27 // Miscellaneous | 46 // Miscellaneous |
28 Add(ExternalReference::roots_array_start(isolate).address(), | 47 Add(ExternalReference::roots_array_start(isolate).address(), |
29 "Heap::roots_array_start()"); | 48 "Heap::roots_array_start()"); |
30 Add(ExternalReference::address_of_stack_limit(isolate).address(), | 49 Add(ExternalReference::address_of_stack_limit(isolate).address(), |
31 "StackGuard::address_of_jslimit()"); | 50 "StackGuard::address_of_jslimit()"); |
32 Add(ExternalReference::address_of_real_stack_limit(isolate).address(), | 51 Add(ExternalReference::address_of_real_stack_limit(isolate).address(), |
33 "StackGuard::address_of_real_jslimit()"); | 52 "StackGuard::address_of_real_jslimit()"); |
34 Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), | 53 Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), |
35 "Heap::NewSpaceAllocationLimitAddress()"); | 54 "Heap::NewSpaceAllocationLimitAddress()"); |
36 Add(ExternalReference::new_space_allocation_top_address(isolate).address(), | 55 Add(ExternalReference::new_space_allocation_top_address(isolate).address(), |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 "RegExpStack::limit_address()"); | 246 "RegExpStack::limit_address()"); |
228 Add(ExternalReference::address_of_regexp_stack_memory_address(isolate) | 247 Add(ExternalReference::address_of_regexp_stack_memory_address(isolate) |
229 .address(), | 248 .address(), |
230 "RegExpStack::memory_address()"); | 249 "RegExpStack::memory_address()"); |
231 Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), | 250 Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), |
232 "RegExpStack::memory_size()"); | 251 "RegExpStack::memory_size()"); |
233 Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), | 252 Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), |
234 "OffsetsVector::static_offsets_vector"); | 253 "OffsetsVector::static_offsets_vector"); |
235 #endif // V8_INTERPRETED_REGEXP | 254 #endif // V8_INTERPRETED_REGEXP |
236 | 255 |
237 // The following populates all of the different type of external references | 256 // Runtime entries |
238 // into the ExternalReferenceTable. | 257 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), |
239 // | 258 "HandleScope::DeleteExtensions"); |
240 // NOTE: This function was originally 100k of code. It has since been | 259 Add(ExternalReference::incremental_marking_record_write_function(isolate) |
241 // rewritten to be mostly table driven, as the callback macro style tends to | 260 .address(), |
242 // very easily cause code bloat. Please be careful in the future when adding | 261 "IncrementalMarking::RecordWrite"); |
243 // new references. | 262 Add(ExternalReference::incremental_marking_record_write_code_entry_function( |
| 263 isolate) |
| 264 .address(), |
| 265 "IncrementalMarking::RecordWriteOfCodeEntryFromCode"); |
| 266 Add(ExternalReference::store_buffer_overflow_function(isolate).address(), |
| 267 "StoreBuffer::StoreBufferOverflow"); |
| 268 } |
244 | 269 |
245 struct RefTableEntry { | 270 void ExternalReferenceTable::AddBuiltins(Isolate* isolate) { |
246 uint16_t id; | 271 struct CBuiltinEntry { |
| 272 Address address; |
| 273 const char* name; |
| 274 }; |
| 275 static const CBuiltinEntry c_builtins[] = { |
| 276 #define DEF_ENTRY(Name, ...) {FUNCTION_ADDR(&Builtin_##Name), "Builtin_" #Name}, |
| 277 BUILTIN_LIST_C(DEF_ENTRY) |
| 278 #undef DEF_ENTRY |
| 279 }; |
| 280 for (unsigned i = 0; i < arraysize(c_builtins); ++i) { |
| 281 Add(ExternalReference(c_builtins[i].address, isolate).address(), |
| 282 c_builtins[i].name); |
| 283 } |
| 284 |
| 285 struct BuiltinEntry { |
| 286 Builtins::Name id; |
| 287 const char* name; |
| 288 }; |
| 289 static const BuiltinEntry builtins[] = { |
| 290 #define DEF_ENTRY(Name, ...) {Builtins::k##Name, "Builtin_" #Name}, |
| 291 BUILTIN_LIST_C(DEF_ENTRY) BUILTIN_LIST_A(DEF_ENTRY) |
| 292 #undef DEF_ENTRY |
| 293 }; |
| 294 for (unsigned i = 0; i < arraysize(builtins); ++i) { |
| 295 Add(isolate->builtins()->builtin_address(builtins[i].id), builtins[i].name); |
| 296 } |
| 297 } |
| 298 |
| 299 void ExternalReferenceTable::AddRuntimeFunctions(Isolate* isolate) { |
| 300 struct RuntimeEntry { |
| 301 Runtime::FunctionId id; |
247 const char* name; | 302 const char* name; |
248 }; | 303 }; |
249 | 304 |
250 static const RefTableEntry c_builtins[] = { | 305 static const RuntimeEntry runtime_functions[] = { |
251 #define DEF_ENTRY(name) {Builtins::c_##name, "Builtins::" #name}, | |
252 BUILTIN_LIST_C(DEF_ENTRY) | |
253 #undef DEF_ENTRY | |
254 }; | |
255 | |
256 for (unsigned i = 0; i < arraysize(c_builtins); ++i) { | |
257 ExternalReference ref(static_cast<Builtins::CFunctionId>(c_builtins[i].id), | |
258 isolate); | |
259 Add(ref.address(), c_builtins[i].name); | |
260 } | |
261 | |
262 static const RefTableEntry builtins[] = { | |
263 #define DEF_ENTRY(name, ...) {Builtins::k##name, "Builtins::" #name}, | |
264 BUILTIN_LIST_C(DEF_ENTRY) BUILTIN_LIST_A(DEF_ENTRY) | |
265 #undef DEF_ENTRY | |
266 }; | |
267 | |
268 for (unsigned i = 0; i < arraysize(builtins); ++i) { | |
269 ExternalReference ref(static_cast<Builtins::Name>(builtins[i].id), isolate); | |
270 Add(ref.address(), builtins[i].name); | |
271 } | |
272 | |
273 static const RefTableEntry runtime_functions[] = { | |
274 #define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name}, | 306 #define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name}, |
275 FOR_EACH_INTRINSIC(RUNTIME_ENTRY) | 307 FOR_EACH_INTRINSIC(RUNTIME_ENTRY) |
276 #undef RUNTIME_ENTRY | 308 #undef RUNTIME_ENTRY |
277 }; | 309 }; |
278 | 310 |
279 for (unsigned i = 0; i < arraysize(runtime_functions); ++i) { | 311 for (unsigned i = 0; i < arraysize(runtime_functions); ++i) { |
280 ExternalReference ref( | 312 ExternalReference ref(runtime_functions[i].id, isolate); |
281 static_cast<Runtime::FunctionId>(runtime_functions[i].id), isolate); | |
282 Add(ref.address(), runtime_functions[i].name); | 313 Add(ref.address(), runtime_functions[i].name); |
283 } | 314 } |
| 315 } |
284 | 316 |
| 317 void ExternalReferenceTable::AddStatCounters(Isolate* isolate) { |
285 // Stat counters | 318 // Stat counters |
286 struct StatsRefTableEntry { | 319 struct StatsRefTableEntry { |
287 StatsCounter* (Counters::*counter)(); | 320 StatsCounter* (Counters::*counter)(); |
288 const char* name; | 321 const char* name; |
289 }; | 322 }; |
290 | 323 |
291 static const StatsRefTableEntry stats_ref_table[] = { | 324 static const StatsRefTableEntry stats_ref_table[] = { |
292 #define COUNTER_ENTRY(name, caption) {&Counters::name, "Counters::" #name}, | 325 #define COUNTER_ENTRY(name, caption) {&Counters::name, "Counters::" #name}, |
293 STATS_COUNTER_LIST_1(COUNTER_ENTRY) STATS_COUNTER_LIST_2(COUNTER_ENTRY) | 326 STATS_COUNTER_LIST_1(COUNTER_ENTRY) STATS_COUNTER_LIST_2(COUNTER_ENTRY) |
294 #undef COUNTER_ENTRY | 327 #undef COUNTER_ENTRY |
295 }; | 328 }; |
296 | 329 |
297 Counters* counters = isolate->counters(); | 330 Counters* counters = isolate->counters(); |
298 for (unsigned i = 0; i < arraysize(stats_ref_table); ++i) { | 331 for (unsigned i = 0; i < arraysize(stats_ref_table); ++i) { |
299 // To make sure the indices are not dependent on whether counters are | 332 // To make sure the indices are not dependent on whether counters are |
300 // enabled, use a dummy address as filler. | 333 // enabled, use a dummy address as filler. |
301 Address address = NotAvailable(); | 334 Address address = NotAvailable(); |
302 StatsCounter* counter = (counters->*(stats_ref_table[i].counter))(); | 335 StatsCounter* counter = (counters->*(stats_ref_table[i].counter))(); |
303 if (counter->Enabled()) { | 336 if (counter->Enabled()) { |
304 address = reinterpret_cast<Address>(counter->GetInternalPointer()); | 337 address = reinterpret_cast<Address>(counter->GetInternalPointer()); |
305 } | 338 } |
306 Add(address, stats_ref_table[i].name); | 339 Add(address, stats_ref_table[i].name); |
307 } | 340 } |
| 341 } |
308 | 342 |
| 343 void ExternalReferenceTable::AddIsolateAddresses(Isolate* isolate) { |
309 // Top addresses | 344 // Top addresses |
310 static const char* address_names[] = { | 345 static const char* address_names[] = { |
311 #define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address", | 346 #define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address", |
312 FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) NULL | 347 FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) NULL |
313 #undef BUILD_NAME_LITERAL | 348 #undef BUILD_NAME_LITERAL |
314 }; | 349 }; |
315 | 350 |
316 for (int i = 0; i < Isolate::kIsolateAddressCount; ++i) { | 351 for (int i = 0; i < Isolate::kIsolateAddressCount; ++i) { |
317 Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)), | 352 Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)), |
318 address_names[i]); | 353 address_names[i]); |
319 } | 354 } |
| 355 } |
320 | 356 |
| 357 void ExternalReferenceTable::AddAccessors(Isolate* isolate) { |
321 // Accessors | 358 // Accessors |
322 struct AccessorRefTable { | 359 struct AccessorRefTable { |
323 Address address; | 360 Address address; |
324 const char* name; | 361 const char* name; |
325 }; | 362 }; |
326 | 363 |
327 static const AccessorRefTable getters[] = { | 364 static const AccessorRefTable getters[] = { |
328 #define ACCESSOR_INFO_DECLARATION(name) \ | 365 #define ACCESSOR_INFO_DECLARATION(name) \ |
329 {FUNCTION_ADDR(&Accessors::name##Getter), "Accessors::" #name "Getter"}, | 366 {FUNCTION_ADDR(&Accessors::name##Getter), "Accessors::" #name "Getter"}, |
330 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) | 367 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) |
331 #undef ACCESSOR_INFO_DECLARATION | 368 #undef ACCESSOR_INFO_DECLARATION |
332 }; | 369 }; |
333 static const AccessorRefTable setters[] = { | 370 static const AccessorRefTable setters[] = { |
334 #define ACCESSOR_SETTER_DECLARATION(name) \ | 371 #define ACCESSOR_SETTER_DECLARATION(name) \ |
335 {FUNCTION_ADDR(&Accessors::name), "Accessors::" #name}, | 372 {FUNCTION_ADDR(&Accessors::name), "Accessors::" #name}, |
336 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION) | 373 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION) |
337 #undef ACCESSOR_INFO_DECLARATION | 374 #undef ACCESSOR_INFO_DECLARATION |
338 }; | 375 }; |
339 | 376 |
340 for (unsigned i = 0; i < arraysize(getters); ++i) { | 377 for (unsigned i = 0; i < arraysize(getters); ++i) { |
341 Add(getters[i].address, getters[i].name); | 378 Add(getters[i].address, getters[i].name); |
342 Add(AccessorInfo::redirect(isolate, getters[i].address, ACCESSOR_GETTER), | 379 Add(AccessorInfo::redirect(isolate, getters[i].address, ACCESSOR_GETTER), |
343 ""); | 380 ""); |
344 } | 381 } |
345 | 382 |
346 for (unsigned i = 0; i < arraysize(setters); ++i) { | 383 for (unsigned i = 0; i < arraysize(setters); ++i) { |
347 Add(setters[i].address, setters[i].name); | 384 Add(setters[i].address, setters[i].name); |
348 } | 385 } |
| 386 } |
349 | 387 |
| 388 void ExternalReferenceTable::AddStubCache(Isolate* isolate) { |
350 StubCache* load_stub_cache = isolate->load_stub_cache(); | 389 StubCache* load_stub_cache = isolate->load_stub_cache(); |
351 | 390 |
352 // Stub cache tables | 391 // Stub cache tables |
353 Add(load_stub_cache->key_reference(StubCache::kPrimary).address(), | 392 Add(load_stub_cache->key_reference(StubCache::kPrimary).address(), |
354 "Load StubCache::primary_->key"); | 393 "Load StubCache::primary_->key"); |
355 Add(load_stub_cache->value_reference(StubCache::kPrimary).address(), | 394 Add(load_stub_cache->value_reference(StubCache::kPrimary).address(), |
356 "Load StubCache::primary_->value"); | 395 "Load StubCache::primary_->value"); |
357 Add(load_stub_cache->map_reference(StubCache::kPrimary).address(), | 396 Add(load_stub_cache->map_reference(StubCache::kPrimary).address(), |
358 "Load StubCache::primary_->map"); | 397 "Load StubCache::primary_->map"); |
359 Add(load_stub_cache->key_reference(StubCache::kSecondary).address(), | 398 Add(load_stub_cache->key_reference(StubCache::kSecondary).address(), |
(...skipping 11 matching lines...) Expand all Loading... |
371 Add(store_stub_cache->value_reference(StubCache::kPrimary).address(), | 410 Add(store_stub_cache->value_reference(StubCache::kPrimary).address(), |
372 "Store StubCache::primary_->value"); | 411 "Store StubCache::primary_->value"); |
373 Add(store_stub_cache->map_reference(StubCache::kPrimary).address(), | 412 Add(store_stub_cache->map_reference(StubCache::kPrimary).address(), |
374 "Store StubCache::primary_->map"); | 413 "Store StubCache::primary_->map"); |
375 Add(store_stub_cache->key_reference(StubCache::kSecondary).address(), | 414 Add(store_stub_cache->key_reference(StubCache::kSecondary).address(), |
376 "Store StubCache::secondary_->key"); | 415 "Store StubCache::secondary_->key"); |
377 Add(store_stub_cache->value_reference(StubCache::kSecondary).address(), | 416 Add(store_stub_cache->value_reference(StubCache::kSecondary).address(), |
378 "Store StubCache::secondary_->value"); | 417 "Store StubCache::secondary_->value"); |
379 Add(store_stub_cache->map_reference(StubCache::kSecondary).address(), | 418 Add(store_stub_cache->map_reference(StubCache::kSecondary).address(), |
380 "Store StubCache::secondary_->map"); | 419 "Store StubCache::secondary_->map"); |
| 420 } |
381 | 421 |
382 // Runtime entries | 422 void ExternalReferenceTable::AddDeoptEntries(Isolate* isolate) { |
383 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), | 423 // Add a small set of deopt entry addresses to encoder without generating |
384 "HandleScope::DeleteExtensions"); | 424 // the |
385 Add(ExternalReference::incremental_marking_record_write_function(isolate) | |
386 .address(), | |
387 "IncrementalMarking::RecordWrite"); | |
388 Add(ExternalReference::incremental_marking_record_write_code_entry_function( | |
389 isolate) | |
390 .address(), | |
391 "IncrementalMarking::RecordWriteOfCodeEntryFromCode"); | |
392 Add(ExternalReference::store_buffer_overflow_function(isolate).address(), | |
393 "StoreBuffer::StoreBufferOverflow"); | |
394 | |
395 // Add a small set of deopt entry addresses to encoder without generating the | |
396 // deopt table code, which isn't possible at deserialization time. | 425 // deopt table code, which isn't possible at deserialization time. |
397 HandleScope scope(isolate); | 426 HandleScope scope(isolate); |
398 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { | 427 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { |
399 Address address = Deoptimizer::GetDeoptimizationEntry( | 428 Address address = Deoptimizer::GetDeoptimizationEntry( |
400 isolate, entry, Deoptimizer::LAZY, | 429 isolate, entry, Deoptimizer::LAZY, |
401 Deoptimizer::CALCULATE_ENTRY_ADDRESS); | 430 Deoptimizer::CALCULATE_ENTRY_ADDRESS); |
402 Add(address, "lazy_deopt"); | 431 Add(address, "lazy_deopt"); |
403 } | 432 } |
| 433 } |
404 | 434 |
405 // Add external references provided by the embedder (a null-terminated array). | 435 void ExternalReferenceTable::AddApiReferences(Isolate* isolate) { |
| 436 // Add external references provided by the embedder (a null-terminated |
| 437 // array). |
406 intptr_t* api_external_references = isolate->api_external_references(); | 438 intptr_t* api_external_references = isolate->api_external_references(); |
407 if (api_external_references != nullptr) { | 439 if (api_external_references != nullptr) { |
408 while (*api_external_references != 0) { | 440 while (*api_external_references != 0) { |
409 Add(reinterpret_cast<Address>(*api_external_references), "<embedder>"); | 441 Add(reinterpret_cast<Address>(*api_external_references), "<embedder>"); |
410 api_external_references++; | 442 api_external_references++; |
411 } | 443 } |
412 } | 444 } |
413 } | 445 } |
414 | 446 |
415 } // namespace internal | 447 } // namespace internal |
416 } // namespace v8 | 448 } // namespace v8 |
OLD | NEW |