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 3 // found in the LICENSE file. 4 5 #include "src/external-reference-table.h" 6 7 #include "src/accessors.h" 8 #include "src/assembler.h" 9 #include "src/counters.h" 10 #include "src/deoptimizer.h" 11 #include "src/ic/stub-cache.h" 12 13 namespace v8 { 14 namespace internal { 15 16 ExternalReferenceTable* ExternalReferenceTable::instance(Isolate* isolate) { 17 ExternalReferenceTable* external_reference_table = 18 isolate->external_reference_table(); 19 if (external_reference_table == NULL) { 20 external_reference_table = new ExternalReferenceTable(isolate); 21 isolate->set_external_reference_table(external_reference_table); 22 } 23 return external_reference_table; 24 } 25 26 ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) { 27 // Miscellaneous 28 Add(ExternalReference::roots_array_start(isolate).address(), 29 "Heap::roots_array_start()"); 30 Add(ExternalReference::address_of_stack_limit(isolate).address(), 31 "StackGuard::address_of_jslimit()"); 32 Add(ExternalReference::address_of_real_stack_limit(isolate).address(), 33 "StackGuard::address_of_real_jslimit()"); 34 Add(ExternalReference::new_space_allocation_limit_address(isolate).address(), 35 "Heap::NewSpaceAllocationLimitAddress()"); 36 Add(ExternalReference::new_space_allocation_top_address(isolate).address(), 37 "Heap::NewSpaceAllocationTopAddress()"); 38 Add(ExternalReference::mod_two_doubles_operation(isolate).address(), 39 "mod_two_doubles"); 40 // Keyed lookup cache. 41 Add(ExternalReference::keyed_lookup_cache_keys(isolate).address(), 42 "KeyedLookupCache::keys()"); 43 Add(ExternalReference::keyed_lookup_cache_field_offsets(isolate).address(), 44 "KeyedLookupCache::field_offsets()"); 45 Add(ExternalReference::handle_scope_next_address(isolate).address(), 46 "HandleScope::next"); 47 Add(ExternalReference::handle_scope_limit_address(isolate).address(), 48 "HandleScope::limit"); 49 Add(ExternalReference::handle_scope_level_address(isolate).address(), 50 "HandleScope::level"); 51 Add(ExternalReference::new_deoptimizer_function(isolate).address(), 52 "Deoptimizer::New()"); 53 Add(ExternalReference::compute_output_frames_function(isolate).address(), 54 "Deoptimizer::ComputeOutputFrames()"); 55 Add(ExternalReference::address_of_min_int().address(), 56 "LDoubleConstant::min_int"); 57 Add(ExternalReference::address_of_one_half().address(), 58 "LDoubleConstant::one_half"); 59 Add(ExternalReference::isolate_address(isolate).address(), "isolate"); 60 Add(ExternalReference::interpreter_dispatch_table_address(isolate).address(), 61 "Interpreter::dispatch_table_address"); 62 Add(ExternalReference::interpreter_dispatch_counters(isolate).address(), 63 "Interpreter::interpreter_dispatch_counters"); 64 Add(ExternalReference::address_of_negative_infinity().address(), 65 "LDoubleConstant::negative_infinity"); 66 Add(ExternalReference::power_double_double_function(isolate).address(), 67 "power_double_double_function"); 68 Add(ExternalReference::power_double_int_function(isolate).address(), 69 "power_double_int_function"); 70 Add(ExternalReference::ieee754_atan_function(isolate).address(), 71 "base::ieee754::atan"); 72 Add(ExternalReference::ieee754_atan2_function(isolate).address(), 73 "base::ieee754::atan2"); 74 Add(ExternalReference::ieee754_atanh_function(isolate).address(), 75 "base::ieee754::atanh"); 76 Add(ExternalReference::ieee754_cbrt_function(isolate).address(), 77 "base::ieee754::cbrt"); 78 Add(ExternalReference::ieee754_cos_function(isolate).address(), 79 "base::ieee754::cos"); 80 Add(ExternalReference::ieee754_exp_function(isolate).address(), 81 "base::ieee754::exp"); 82 Add(ExternalReference::ieee754_expm1_function(isolate).address(), 83 "base::ieee754::expm1"); 84 Add(ExternalReference::ieee754_log_function(isolate).address(), 85 "base::ieee754::log"); 86 Add(ExternalReference::ieee754_log1p_function(isolate).address(), 87 "base::ieee754::log1p"); 88 Add(ExternalReference::ieee754_log10_function(isolate).address(), 89 "base::ieee754::log10"); 90 Add(ExternalReference::ieee754_log2_function(isolate).address(), 91 "base::ieee754::log2"); 92 Add(ExternalReference::ieee754_sin_function(isolate).address(), 93 "base::ieee754::sin"); 94 Add(ExternalReference::ieee754_tan_function(isolate).address(), 95 "base::ieee754::tan"); 96 Add(ExternalReference::store_buffer_top(isolate).address(), 97 "store_buffer_top"); 98 Add(ExternalReference::address_of_the_hole_nan().address(), "the_hole_nan"); 99 Add(ExternalReference::get_date_field_function(isolate).address(), 100 "JSDate::GetField"); 101 Add(ExternalReference::date_cache_stamp(isolate).address(), 102 "date_cache_stamp"); 103 Add(ExternalReference::address_of_pending_message_obj(isolate).address(), 104 "address_of_pending_message_obj"); 105 Add(ExternalReference::get_make_code_young_function(isolate).address(), 106 "Code::MakeCodeYoung"); 107 Add(ExternalReference::cpu_features().address(), "cpu_features"); 108 Add(ExternalReference::old_space_allocation_top_address(isolate).address(), 109 "Heap::OldSpaceAllocationTopAddress"); 110 Add(ExternalReference::old_space_allocation_limit_address(isolate).address(), 111 "Heap::OldSpaceAllocationLimitAddress"); 112 Add(ExternalReference::allocation_sites_list_address(isolate).address(), 113 "Heap::allocation_sites_list_address()"); 114 Add(ExternalReference::address_of_uint32_bias().address(), "uint32_bias"); 115 Add(ExternalReference::get_mark_code_as_executed_function(isolate).address(), 116 "Code::MarkCodeAsExecuted"); 117 Add(ExternalReference::is_profiling_address(isolate).address(), 118 "Isolate::is_profiling"); 119 Add(ExternalReference::scheduled_exception_address(isolate).address(), 120 "Isolate::scheduled_exception"); 121 Add(ExternalReference::invoke_function_callback(isolate).address(), 122 "InvokeFunctionCallback"); 123 Add(ExternalReference::invoke_accessor_getter_callback(isolate).address(), 124 "InvokeAccessorGetterCallback"); 125 Add(ExternalReference::wasm_f32_trunc(isolate).address(), 126 "wasm::f32_trunc_wrapper"); 127 Add(ExternalReference::wasm_f32_floor(isolate).address(), 128 "wasm::f32_floor_wrapper"); 129 Add(ExternalReference::wasm_f32_ceil(isolate).address(), 130 "wasm::f32_ceil_wrapper"); 131 Add(ExternalReference::wasm_f32_nearest_int(isolate).address(), 132 "wasm::f32_nearest_int_wrapper"); 133 Add(ExternalReference::wasm_f64_trunc(isolate).address(), 134 "wasm::f64_trunc_wrapper"); 135 Add(ExternalReference::wasm_f64_floor(isolate).address(), 136 "wasm::f64_floor_wrapper"); 137 Add(ExternalReference::wasm_f64_ceil(isolate).address(), 138 "wasm::f64_ceil_wrapper"); 139 Add(ExternalReference::wasm_f64_nearest_int(isolate).address(), 140 "wasm::f64_nearest_int_wrapper"); 141 Add(ExternalReference::wasm_int64_to_float32(isolate).address(), 142 "wasm::int64_to_float32_wrapper"); 143 Add(ExternalReference::wasm_uint64_to_float32(isolate).address(), 144 "wasm::uint64_to_float32_wrapper"); 145 Add(ExternalReference::wasm_int64_to_float64(isolate).address(), 146 "wasm::int64_to_float64_wrapper"); 147 Add(ExternalReference::wasm_uint64_to_float64(isolate).address(), 148 "wasm::uint64_to_float64_wrapper"); 149 Add(ExternalReference::wasm_float32_to_int64(isolate).address(), 150 "wasm::float32_to_int64_wrapper"); 151 Add(ExternalReference::wasm_float32_to_uint64(isolate).address(), 152 "wasm::float32_to_uint64_wrapper"); 153 Add(ExternalReference::wasm_float64_to_int64(isolate).address(), 154 "wasm::float64_to_int64_wrapper"); 155 Add(ExternalReference::wasm_float64_to_uint64(isolate).address(), 156 "wasm::float64_to_uint64_wrapper"); 157 Add(ExternalReference::wasm_int64_div(isolate).address(), "wasm::int64_div"); 158 Add(ExternalReference::wasm_int64_mod(isolate).address(), "wasm::int64_mod"); 159 Add(ExternalReference::wasm_uint64_div(isolate).address(), 160 "wasm::uint64_div"); 161 Add(ExternalReference::wasm_uint64_mod(isolate).address(), 162 "wasm::uint64_mod"); 163 Add(ExternalReference::wasm_word32_ctz(isolate).address(), 164 "wasm::word32_ctz"); 165 Add(ExternalReference::wasm_word64_ctz(isolate).address(), 166 "wasm::word64_ctz"); 167 Add(ExternalReference::wasm_word32_popcnt(isolate).address(), 168 "wasm::word32_popcnt"); 169 Add(ExternalReference::wasm_word64_popcnt(isolate).address(), 170 "wasm::word64_popcnt"); 171 Add(ExternalReference::f64_acos_wrapper_function(isolate).address(), 172 "f64_acos_wrapper"); 173 Add(ExternalReference::f64_asin_wrapper_function(isolate).address(), 174 "f64_asin_wrapper"); 175 Add(ExternalReference::f64_pow_wrapper_function(isolate).address(), 176 "f64_pow_wrapper"); 177 Add(ExternalReference::f64_mod_wrapper_function(isolate).address(), 178 "f64_mod_wrapper"); 179 Add(ExternalReference::log_enter_external_function(isolate).address(), 180 "Logger::EnterExternal"); 181 Add(ExternalReference::log_leave_external_function(isolate).address(), 182 "Logger::LeaveExternal"); 183 Add(ExternalReference::address_of_minus_one_half().address(), 184 "double_constants.minus_one_half"); 185 Add(ExternalReference::stress_deopt_count(isolate).address(), 186 "Isolate::stress_deopt_count_address()"); 187 Add(ExternalReference::virtual_handler_register(isolate).address(), 188 "Isolate::virtual_handler_register()"); 189 Add(ExternalReference::virtual_slot_register(isolate).address(), 190 "Isolate::virtual_slot_register()"); 191 Add(ExternalReference::runtime_function_table_address(isolate).address(), 192 "Runtime::runtime_function_table_address()"); 193 Add(ExternalReference::is_tail_call_elimination_enabled_address(isolate) 194 .address(), 195 "Isolate::is_tail_call_elimination_enabled_address()"); 196 197 // Debug addresses 198 Add(ExternalReference::debug_after_break_target_address(isolate).address(), 199 "Debug::after_break_target_address()"); 200 Add(ExternalReference::debug_is_active_address(isolate).address(), 201 "Debug::is_active_address()"); 202 Add(ExternalReference::debug_last_step_action_address(isolate).address(), 203 "Debug::step_in_enabled_address()"); 204 Add(ExternalReference::debug_suspended_generator_address(isolate).address(), 205 "Debug::step_suspended_generator_address()"); 206 207 #ifndef V8_INTERPRETED_REGEXP 208 Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(), 209 "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()"); 210 Add(ExternalReference::re_check_stack_guard_state(isolate).address(), 211 "RegExpMacroAssembler*::CheckStackGuardState()"); 212 Add(ExternalReference::re_grow_stack(isolate).address(), 213 "NativeRegExpMacroAssembler::GrowStack()"); 214 Add(ExternalReference::re_word_character_map().address(), 215 "NativeRegExpMacroAssembler::word_character_map"); 216 Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(), 217 "RegExpStack::limit_address()"); 218 Add(ExternalReference::address_of_regexp_stack_memory_address(isolate) 219 .address(), 220 "RegExpStack::memory_address()"); 221 Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), 222 "RegExpStack::memory_size()"); 223 Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), 224 "OffsetsVector::static_offsets_vector"); 225 #endif // V8_INTERPRETED_REGEXP 226 227 // The following populates all of the different type of external references 228 // into the ExternalReferenceTable. 229 // 230 // NOTE: This function was originally 100k of code. It has since been 231 // rewritten to be mostly table driven, as the callback macro style tends to 232 // very easily cause code bloat. Please be careful in the future when adding 233 // new references. 234 235 struct RefTableEntry { 236 uint16_t id; 237 const char* name; 238 }; 239 240 static const RefTableEntry c_builtins[] = { 241 #define DEF_ENTRY_C(name) {Builtins::c_##name, "Builtins::" #name}, 242 BUILTIN_LIST_C(DEF_ENTRY_C) 243 #undef DEF_ENTRY_C 244 }; 245 246 for (unsigned i = 0; i < arraysize(c_builtins); ++i) { 247 ExternalReference ref(static_cast<Builtins::CFunctionId>(c_builtins[i].id), 248 isolate); 249 Add(ref.address(), c_builtins[i].name); 250 } 251 252 static const RefTableEntry builtins[] = { 253 #define DEF_ENTRY_C(name) {Builtins::k##name, "Builtins::" #name}, 254 #define DEF_ENTRY_A(name, i1, i2) {Builtins::k##name, "Builtins::" #name}, 255 BUILTIN_LIST_C(DEF_ENTRY_C) BUILTIN_LIST_A(DEF_ENTRY_A) 256 BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A) 257 #undef DEF_ENTRY_C 258 #undef DEF_ENTRY_A 259 }; 260 261 for (unsigned i = 0; i < arraysize(builtins); ++i) { 262 ExternalReference ref(static_cast<Builtins::Name>(builtins[i].id), isolate); 263 Add(ref.address(), builtins[i].name); 264 } 265 266 static const RefTableEntry runtime_functions[] = { 267 #define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name}, 268 FOR_EACH_INTRINSIC(RUNTIME_ENTRY) 269 #undef RUNTIME_ENTRY 270 }; 271 272 for (unsigned i = 0; i < arraysize(runtime_functions); ++i) { 273 ExternalReference ref( 274 static_cast<Runtime::FunctionId>(runtime_functions[i].id), isolate); 275 Add(ref.address(), runtime_functions[i].name); 276 } 277 278 // Stat counters 279 struct StatsRefTableEntry { 280 StatsCounter* (Counters::*counter)(); 281 const char* name; 282 }; 283 284 static const StatsRefTableEntry stats_ref_table[] = { 285 #define COUNTER_ENTRY(name, caption) {&Counters::name, "Counters::" #name}, 286 STATS_COUNTER_LIST_1(COUNTER_ENTRY) STATS_COUNTER_LIST_2(COUNTER_ENTRY) 287 #undef COUNTER_ENTRY 288 }; 289 290 Counters* counters = isolate->counters(); 291 for (unsigned i = 0; i < arraysize(stats_ref_table); ++i) { 292 // To make sure the indices are not dependent on whether counters are 293 // enabled, use a dummy address as filler. 294 Address address = NotAvailable(); 295 StatsCounter* counter = (counters->*(stats_ref_table[i].counter))(); 296 if (counter->Enabled()) { 297 address = reinterpret_cast<Address>(counter->GetInternalPointer()); 298 } 299 Add(address, stats_ref_table[i].name); 300 } 301 302 // Top addresses 303 static const char* address_names[] = { 304 #define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address", 305 FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) NULL 306 #undef BUILD_NAME_LITERAL 307 }; 308 309 for (int i = 0; i < Isolate::kIsolateAddressCount; ++i) { 310 Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)), 311 address_names[i]); 312 } 313 314 // Accessors 315 struct AccessorRefTable { 316 Address address; 317 const char* name; 318 }; 319 320 static const AccessorRefTable getters[] = { 321 #define ACCESSOR_INFO_DECLARATION(name) \ 322 {FUNCTION_ADDR(&Accessors::name##Getter), "Accessors::" #name "Getter"}, 323 ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) 324 #undef ACCESSOR_INFO_DECLARATION 325 }; 326 static const AccessorRefTable setters[] = { 327 #define ACCESSOR_SETTER_DECLARATION(name) \ 328 {FUNCTION_ADDR(&Accessors::name), "Accessors::" #name}, 329 ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION) 330 #undef ACCESSOR_INFO_DECLARATION 331 }; 332 333 for (unsigned i = 0; i < arraysize(getters); ++i) { 334 Add(getters[i].address, getters[i].name); 335 Add(AccessorInfo::redirect(isolate, getters[i].address, ACCESSOR_GETTER), 336 ""); 337 } 338 339 for (unsigned i = 0; i < arraysize(setters); ++i) { 340 Add(setters[i].address, setters[i].name); 341 } 342 343 StubCache* stub_cache = isolate->stub_cache(); 344 345 // Stub cache tables 346 Add(stub_cache->key_reference(StubCache::kPrimary).address(), 347 "StubCache::primary_->key"); 348 Add(stub_cache->value_reference(StubCache::kPrimary).address(), 349 "StubCache::primary_->value"); 350 Add(stub_cache->map_reference(StubCache::kPrimary).address(), 351 "StubCache::primary_->map"); 352 Add(stub_cache->key_reference(StubCache::kSecondary).address(), 353 "StubCache::secondary_->key"); 354 Add(stub_cache->value_reference(StubCache::kSecondary).address(), 355 "StubCache::secondary_->value"); 356 Add(stub_cache->map_reference(StubCache::kSecondary).address(), 357 "StubCache::secondary_->map"); 358 359 // Runtime entries 360 Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), 361 "HandleScope::DeleteExtensions"); 362 Add(ExternalReference::incremental_marking_record_write_function(isolate) 363 .address(), 364 "IncrementalMarking::RecordWrite"); 365 Add(ExternalReference::incremental_marking_record_write_code_entry_function( 366 isolate) 367 .address(), 368 "IncrementalMarking::RecordWriteOfCodeEntryFromCode"); 369 Add(ExternalReference::store_buffer_overflow_function(isolate).address(), 370 "StoreBuffer::StoreBufferOverflow"); 371 372 // Add a small set of deopt entry addresses to encoder without generating the 373 // deopt table code, which isn't possible at deserialization time. 374 HandleScope scope(isolate); 375 for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { 376 Address address = Deoptimizer::GetDeoptimizationEntry( 377 isolate, entry, Deoptimizer::LAZY, 378 Deoptimizer::CALCULATE_ENTRY_ADDRESS); 379 Add(address, "lazy_deopt"); 380 } 381 382 // Add external references provided by the embedder (a null-terminated array). 383 intptr_t* api_external_references = isolate->api_external_references(); 384 if (api_external_references != nullptr) { 385 while (*api_external_references != 0) { 386 Add(reinterpret_cast<Address>(*api_external_references), "<embedder>"); 387 api_external_references++; 388 } 389 } 390 } 391 392 } // namespace internal 393 } // namespace v8 394