Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame^] | 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::address_of_negative_infinity().address(), |
| 63 | "LDoubleConstant::negative_infinity"); |
| 64 | Add(ExternalReference::power_double_double_function(isolate).address(), |
| 65 | "power_double_double_function"); |
| 66 | Add(ExternalReference::power_double_int_function(isolate).address(), |
| 67 | "power_double_int_function"); |
| 68 | Add(ExternalReference::math_log_double_function(isolate).address(), |
| 69 | "std::log"); |
| 70 | Add(ExternalReference::store_buffer_top(isolate).address(), |
| 71 | "store_buffer_top"); |
| 72 | Add(ExternalReference::address_of_the_hole_nan().address(), "the_hole_nan"); |
| 73 | Add(ExternalReference::get_date_field_function(isolate).address(), |
| 74 | "JSDate::GetField"); |
| 75 | Add(ExternalReference::date_cache_stamp(isolate).address(), |
| 76 | "date_cache_stamp"); |
| 77 | Add(ExternalReference::address_of_pending_message_obj(isolate).address(), |
| 78 | "address_of_pending_message_obj"); |
| 79 | Add(ExternalReference::get_make_code_young_function(isolate).address(), |
| 80 | "Code::MakeCodeYoung"); |
| 81 | Add(ExternalReference::cpu_features().address(), "cpu_features"); |
| 82 | Add(ExternalReference::old_space_allocation_top_address(isolate).address(), |
| 83 | "Heap::OldSpaceAllocationTopAddress"); |
| 84 | Add(ExternalReference::old_space_allocation_limit_address(isolate).address(), |
| 85 | "Heap::OldSpaceAllocationLimitAddress"); |
| 86 | Add(ExternalReference::allocation_sites_list_address(isolate).address(), |
| 87 | "Heap::allocation_sites_list_address()"); |
| 88 | Add(ExternalReference::address_of_uint32_bias().address(), "uint32_bias"); |
| 89 | Add(ExternalReference::get_mark_code_as_executed_function(isolate).address(), |
| 90 | "Code::MarkCodeAsExecuted"); |
| 91 | Add(ExternalReference::is_profiling_address(isolate).address(), |
| 92 | "CpuProfiler::is_profiling"); |
| 93 | Add(ExternalReference::scheduled_exception_address(isolate).address(), |
| 94 | "Isolate::scheduled_exception"); |
| 95 | Add(ExternalReference::invoke_function_callback(isolate).address(), |
| 96 | "InvokeFunctionCallback"); |
| 97 | Add(ExternalReference::invoke_accessor_getter_callback(isolate).address(), |
| 98 | "InvokeAccessorGetterCallback"); |
| 99 | Add(ExternalReference::wasm_f32_trunc(isolate).address(), |
| 100 | "wasm::f32_trunc_wrapper"); |
| 101 | Add(ExternalReference::wasm_f32_floor(isolate).address(), |
| 102 | "wasm::f32_floor_wrapper"); |
| 103 | Add(ExternalReference::wasm_f32_ceil(isolate).address(), |
| 104 | "wasm::f32_ceil_wrapper"); |
| 105 | Add(ExternalReference::wasm_f32_nearest_int(isolate).address(), |
| 106 | "wasm::f32_nearest_int_wrapper"); |
| 107 | Add(ExternalReference::wasm_f64_trunc(isolate).address(), |
| 108 | "wasm::f64_trunc_wrapper"); |
| 109 | Add(ExternalReference::wasm_f64_floor(isolate).address(), |
| 110 | "wasm::f64_floor_wrapper"); |
| 111 | Add(ExternalReference::wasm_f64_ceil(isolate).address(), |
| 112 | "wasm::f64_ceil_wrapper"); |
| 113 | Add(ExternalReference::wasm_f64_nearest_int(isolate).address(), |
| 114 | "wasm::f64_nearest_int_wrapper"); |
| 115 | Add(ExternalReference::wasm_int64_to_float32(isolate).address(), |
| 116 | "wasm::int64_to_float32_wrapper"); |
| 117 | Add(ExternalReference::wasm_uint64_to_float32(isolate).address(), |
| 118 | "wasm::uint64_to_float32_wrapper"); |
| 119 | Add(ExternalReference::wasm_int64_to_float64(isolate).address(), |
| 120 | "wasm::int64_to_float64_wrapper"); |
| 121 | Add(ExternalReference::wasm_uint64_to_float64(isolate).address(), |
| 122 | "wasm::uint64_to_float64_wrapper"); |
| 123 | Add(ExternalReference::wasm_float32_to_int64(isolate).address(), |
| 124 | "wasm::float32_to_int64_wrapper"); |
| 125 | Add(ExternalReference::wasm_float32_to_uint64(isolate).address(), |
| 126 | "wasm::float32_to_uint64_wrapper"); |
| 127 | Add(ExternalReference::wasm_float64_to_int64(isolate).address(), |
| 128 | "wasm::float64_to_int64_wrapper"); |
| 129 | Add(ExternalReference::wasm_float64_to_uint64(isolate).address(), |
| 130 | "wasm::float64_to_uint64_wrapper"); |
| 131 | Add(ExternalReference::wasm_int64_div(isolate).address(), "wasm::int64_div"); |
| 132 | Add(ExternalReference::wasm_int64_mod(isolate).address(), "wasm::int64_mod"); |
| 133 | Add(ExternalReference::wasm_uint64_div(isolate).address(), |
| 134 | "wasm::uint64_div"); |
| 135 | Add(ExternalReference::wasm_uint64_mod(isolate).address(), |
| 136 | "wasm::uint64_mod"); |
| 137 | Add(ExternalReference::f64_acos_wrapper_function(isolate).address(), |
| 138 | "f64_acos_wrapper"); |
| 139 | Add(ExternalReference::f64_asin_wrapper_function(isolate).address(), |
| 140 | "f64_asin_wrapper"); |
| 141 | Add(ExternalReference::f64_atan_wrapper_function(isolate).address(), |
| 142 | "f64_atan_wrapper"); |
| 143 | Add(ExternalReference::f64_cos_wrapper_function(isolate).address(), |
| 144 | "f64_cos_wrapper"); |
| 145 | Add(ExternalReference::f64_sin_wrapper_function(isolate).address(), |
| 146 | "f64_sin_wrapper"); |
| 147 | Add(ExternalReference::f64_tan_wrapper_function(isolate).address(), |
| 148 | "f64_tan_wrapper"); |
| 149 | Add(ExternalReference::f64_exp_wrapper_function(isolate).address(), |
| 150 | "f64_exp_wrapper"); |
| 151 | Add(ExternalReference::f64_log_wrapper_function(isolate).address(), |
| 152 | "f64_log_wrapper"); |
| 153 | Add(ExternalReference::f64_pow_wrapper_function(isolate).address(), |
| 154 | "f64_pow_wrapper"); |
| 155 | Add(ExternalReference::f64_atan2_wrapper_function(isolate).address(), |
| 156 | "f64_atan2_wrapper"); |
| 157 | Add(ExternalReference::f64_mod_wrapper_function(isolate).address(), |
| 158 | "f64_mod_wrapper"); |
| 159 | Add(ExternalReference::log_enter_external_function(isolate).address(), |
| 160 | "Logger::EnterExternal"); |
| 161 | Add(ExternalReference::log_leave_external_function(isolate).address(), |
| 162 | "Logger::LeaveExternal"); |
| 163 | Add(ExternalReference::address_of_minus_one_half().address(), |
| 164 | "double_constants.minus_one_half"); |
| 165 | Add(ExternalReference::stress_deopt_count(isolate).address(), |
| 166 | "Isolate::stress_deopt_count_address()"); |
| 167 | Add(ExternalReference::virtual_handler_register(isolate).address(), |
| 168 | "Isolate::virtual_handler_register()"); |
| 169 | Add(ExternalReference::virtual_slot_register(isolate).address(), |
| 170 | "Isolate::virtual_slot_register()"); |
| 171 | Add(ExternalReference::runtime_function_table_address(isolate).address(), |
| 172 | "Runtime::runtime_function_table_address()"); |
| 173 | Add(ExternalReference::is_tail_call_elimination_enabled_address(isolate) |
| 174 | .address(), |
| 175 | "Isolate::is_tail_call_elimination_enabled_address()"); |
| 176 | |
| 177 | // Debug addresses |
| 178 | Add(ExternalReference::debug_after_break_target_address(isolate).address(), |
| 179 | "Debug::after_break_target_address()"); |
| 180 | Add(ExternalReference::debug_is_active_address(isolate).address(), |
| 181 | "Debug::is_active_address()"); |
| 182 | Add(ExternalReference::debug_step_in_enabled_address(isolate).address(), |
| 183 | "Debug::step_in_enabled_address()"); |
| 184 | |
| 185 | #ifndef V8_INTERPRETED_REGEXP |
| 186 | Add(ExternalReference::re_case_insensitive_compare_uc16(isolate).address(), |
| 187 | "NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()"); |
| 188 | Add(ExternalReference::re_check_stack_guard_state(isolate).address(), |
| 189 | "RegExpMacroAssembler*::CheckStackGuardState()"); |
| 190 | Add(ExternalReference::re_grow_stack(isolate).address(), |
| 191 | "NativeRegExpMacroAssembler::GrowStack()"); |
| 192 | Add(ExternalReference::re_word_character_map().address(), |
| 193 | "NativeRegExpMacroAssembler::word_character_map"); |
| 194 | Add(ExternalReference::address_of_regexp_stack_limit(isolate).address(), |
| 195 | "RegExpStack::limit_address()"); |
| 196 | Add(ExternalReference::address_of_regexp_stack_memory_address(isolate) |
| 197 | .address(), |
| 198 | "RegExpStack::memory_address()"); |
| 199 | Add(ExternalReference::address_of_regexp_stack_memory_size(isolate).address(), |
| 200 | "RegExpStack::memory_size()"); |
| 201 | Add(ExternalReference::address_of_static_offsets_vector(isolate).address(), |
| 202 | "OffsetsVector::static_offsets_vector"); |
| 203 | #endif // V8_INTERPRETED_REGEXP |
| 204 | |
| 205 | // The following populates all of the different type of external references |
| 206 | // into the ExternalReferenceTable. |
| 207 | // |
| 208 | // NOTE: This function was originally 100k of code. It has since been |
| 209 | // rewritten to be mostly table driven, as the callback macro style tends to |
| 210 | // very easily cause code bloat. Please be careful in the future when adding |
| 211 | // new references. |
| 212 | |
| 213 | struct RefTableEntry { |
| 214 | uint16_t id; |
| 215 | const char* name; |
| 216 | }; |
| 217 | |
| 218 | static const RefTableEntry c_builtins[] = { |
| 219 | #define DEF_ENTRY_C(name, ignored) {Builtins::c_##name, "Builtins::" #name}, |
| 220 | BUILTIN_LIST_C(DEF_ENTRY_C) |
| 221 | #undef DEF_ENTRY_C |
| 222 | }; |
| 223 | |
| 224 | for (unsigned i = 0; i < arraysize(c_builtins); ++i) { |
| 225 | ExternalReference ref(static_cast<Builtins::CFunctionId>(c_builtins[i].id), |
| 226 | isolate); |
| 227 | Add(ref.address(), c_builtins[i].name); |
| 228 | } |
| 229 | |
| 230 | static const RefTableEntry builtins[] = { |
| 231 | #define DEF_ENTRY_C(name, ignored) {Builtins::k##name, "Builtins::" #name}, |
| 232 | #define DEF_ENTRY_A(name, i1, i2, i3) {Builtins::k##name, "Builtins::" #name}, |
| 233 | BUILTIN_LIST_C(DEF_ENTRY_C) BUILTIN_LIST_A(DEF_ENTRY_A) |
| 234 | BUILTIN_LIST_DEBUG_A(DEF_ENTRY_A) |
| 235 | #undef DEF_ENTRY_C |
| 236 | #undef DEF_ENTRY_A |
| 237 | }; |
| 238 | |
| 239 | for (unsigned i = 0; i < arraysize(builtins); ++i) { |
| 240 | ExternalReference ref(static_cast<Builtins::Name>(builtins[i].id), isolate); |
| 241 | Add(ref.address(), builtins[i].name); |
| 242 | } |
| 243 | |
| 244 | static const RefTableEntry runtime_functions[] = { |
| 245 | #define RUNTIME_ENTRY(name, i1, i2) {Runtime::k##name, "Runtime::" #name}, |
| 246 | FOR_EACH_INTRINSIC(RUNTIME_ENTRY) |
| 247 | #undef RUNTIME_ENTRY |
| 248 | }; |
| 249 | |
| 250 | for (unsigned i = 0; i < arraysize(runtime_functions); ++i) { |
| 251 | ExternalReference ref( |
| 252 | static_cast<Runtime::FunctionId>(runtime_functions[i].id), isolate); |
| 253 | Add(ref.address(), runtime_functions[i].name); |
| 254 | } |
| 255 | |
| 256 | // Stat counters |
| 257 | struct StatsRefTableEntry { |
| 258 | StatsCounter* (Counters::*counter)(); |
| 259 | const char* name; |
| 260 | }; |
| 261 | |
| 262 | static const StatsRefTableEntry stats_ref_table[] = { |
| 263 | #define COUNTER_ENTRY(name, caption) {&Counters::name, "Counters::" #name}, |
| 264 | STATS_COUNTER_LIST_1(COUNTER_ENTRY) STATS_COUNTER_LIST_2(COUNTER_ENTRY) |
| 265 | #undef COUNTER_ENTRY |
| 266 | }; |
| 267 | |
| 268 | Counters* counters = isolate->counters(); |
| 269 | for (unsigned i = 0; i < arraysize(stats_ref_table); ++i) { |
| 270 | // To make sure the indices are not dependent on whether counters are |
| 271 | // enabled, use a dummy address as filler. |
| 272 | Address address = NotAvailable(); |
| 273 | StatsCounter* counter = (counters->*(stats_ref_table[i].counter))(); |
| 274 | if (counter->Enabled()) { |
| 275 | address = reinterpret_cast<Address>(counter->GetInternalPointer()); |
| 276 | } |
| 277 | Add(address, stats_ref_table[i].name); |
| 278 | } |
| 279 | |
| 280 | // Top addresses |
| 281 | static const char* address_names[] = { |
| 282 | #define BUILD_NAME_LITERAL(Name, name) "Isolate::" #name "_address", |
| 283 | FOR_EACH_ISOLATE_ADDRESS_NAME(BUILD_NAME_LITERAL) NULL |
| 284 | #undef BUILD_NAME_LITERAL |
| 285 | }; |
| 286 | |
| 287 | for (int i = 0; i < Isolate::kIsolateAddressCount; ++i) { |
| 288 | Add(isolate->get_address_from_id(static_cast<Isolate::AddressId>(i)), |
| 289 | address_names[i]); |
| 290 | } |
| 291 | |
| 292 | // Accessors |
| 293 | struct AccessorRefTable { |
| 294 | Address address; |
| 295 | const char* name; |
| 296 | }; |
| 297 | |
| 298 | static const AccessorRefTable accessors[] = { |
| 299 | #define ACCESSOR_INFO_DECLARATION(name) \ |
| 300 | {FUNCTION_ADDR(&Accessors::name##Getter), "Accessors::" #name "Getter"}, |
| 301 | ACCESSOR_INFO_LIST(ACCESSOR_INFO_DECLARATION) |
| 302 | #undef ACCESSOR_INFO_DECLARATION |
| 303 | #define ACCESSOR_SETTER_DECLARATION(name) \ |
| 304 | {FUNCTION_ADDR(&Accessors::name), "Accessors::" #name}, |
| 305 | ACCESSOR_SETTER_LIST(ACCESSOR_SETTER_DECLARATION) |
| 306 | #undef ACCESSOR_INFO_DECLARATION |
| 307 | }; |
| 308 | |
| 309 | for (unsigned i = 0; i < arraysize(accessors); ++i) { |
| 310 | Add(accessors[i].address, accessors[i].name); |
| 311 | } |
| 312 | |
| 313 | StubCache* stub_cache = isolate->stub_cache(); |
| 314 | |
| 315 | // Stub cache tables |
| 316 | Add(stub_cache->key_reference(StubCache::kPrimary).address(), |
| 317 | "StubCache::primary_->key"); |
| 318 | Add(stub_cache->value_reference(StubCache::kPrimary).address(), |
| 319 | "StubCache::primary_->value"); |
| 320 | Add(stub_cache->map_reference(StubCache::kPrimary).address(), |
| 321 | "StubCache::primary_->map"); |
| 322 | Add(stub_cache->key_reference(StubCache::kSecondary).address(), |
| 323 | "StubCache::secondary_->key"); |
| 324 | Add(stub_cache->value_reference(StubCache::kSecondary).address(), |
| 325 | "StubCache::secondary_->value"); |
| 326 | Add(stub_cache->map_reference(StubCache::kSecondary).address(), |
| 327 | "StubCache::secondary_->map"); |
| 328 | |
| 329 | // Runtime entries |
| 330 | Add(ExternalReference::delete_handle_scope_extensions(isolate).address(), |
| 331 | "HandleScope::DeleteExtensions"); |
| 332 | Add(ExternalReference::incremental_marking_record_write_function(isolate) |
| 333 | .address(), |
| 334 | "IncrementalMarking::RecordWrite"); |
| 335 | Add(ExternalReference::incremental_marking_record_write_code_entry_function( |
| 336 | isolate) |
| 337 | .address(), |
| 338 | "IncrementalMarking::RecordWriteOfCodeEntryFromCode"); |
| 339 | Add(ExternalReference::store_buffer_overflow_function(isolate).address(), |
| 340 | "StoreBuffer::StoreBufferOverflow"); |
| 341 | |
| 342 | // Add a small set of deopt entry addresses to encoder without generating the |
| 343 | // deopt table code, which isn't possible at deserialization time. |
| 344 | HandleScope scope(isolate); |
| 345 | for (int entry = 0; entry < kDeoptTableSerializeEntryCount; ++entry) { |
| 346 | Address address = Deoptimizer::GetDeoptimizationEntry( |
| 347 | isolate, entry, Deoptimizer::LAZY, |
| 348 | Deoptimizer::CALCULATE_ENTRY_ADDRESS); |
| 349 | Add(address, "lazy_deopt"); |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | } // namespace internal |
| 354 | } // namespace v8 |