blob: 17cd56be8064b1eb518e2ee2e92118eeda9ccbfb [file] [log] [blame]
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001// Copyright (c) 1994-2006 Sun Microsystems Inc.
Steve Blocka7e24c12009-10-30 11:49:00 +00002// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010033// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000034
Ben Murdochb8a8cc12014-11-26 15:28:44 +000035#include "src/assembler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000036
Ben Murdoch097c5b22016-05-18 11:27:45 +010037#include <math.h>
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038#include <cmath>
39#include "src/api.h"
40#include "src/base/cpu.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040041#include "src/base/functional.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000042#include "src/base/lazy-instance.h"
43#include "src/base/platform/platform.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000044#include "src/base/utils/random-number-generator.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000045#include "src/builtins.h"
46#include "src/codegen.h"
47#include "src/counters.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000048#include "src/debug/debug.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049#include "src/deoptimizer.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050#include "src/disassembler.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051#include "src/execution.h"
52#include "src/ic/ic.h"
53#include "src/ic/stub-cache.h"
Ben Murdoch097c5b22016-05-18 11:27:45 +010054#include "src/interpreter/interpreter.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000055#include "src/ostreams.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056#include "src/profiler/cpu-profiler.h"
57#include "src/regexp/jsregexp.h"
58#include "src/regexp/regexp-macro-assembler.h"
59#include "src/regexp/regexp-stack.h"
60#include "src/register-configuration.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040061#include "src/runtime/runtime.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000062#include "src/simulator.h" // For flushing instruction cache.
Ben Murdochda12d292016-06-02 14:46:10 +010063#include "src/snapshot/serializer-common.h"
64#include "src/wasm/wasm-external-refs.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +010065
66#if V8_TARGET_ARCH_IA32
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067#include "src/ia32/assembler-ia32-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010068#elif V8_TARGET_ARCH_X64
Ben Murdochb8a8cc12014-11-26 15:28:44 +000069#include "src/x64/assembler-x64-inl.h" // NOLINT
70#elif V8_TARGET_ARCH_ARM64
71#include "src/arm64/assembler-arm64-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010072#elif V8_TARGET_ARCH_ARM
Ben Murdochb8a8cc12014-11-26 15:28:44 +000073#include "src/arm/assembler-arm-inl.h" // NOLINT
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000074#elif V8_TARGET_ARCH_PPC
75#include "src/ppc/assembler-ppc-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010076#elif V8_TARGET_ARCH_MIPS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077#include "src/mips/assembler-mips-inl.h" // NOLINT
78#elif V8_TARGET_ARCH_MIPS64
79#include "src/mips64/assembler-mips64-inl.h" // NOLINT
Ben Murdochda12d292016-06-02 14:46:10 +010080#elif V8_TARGET_ARCH_S390
81#include "src/s390/assembler-s390-inl.h" // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082#elif V8_TARGET_ARCH_X87
83#include "src/x87/assembler-x87-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010084#else
85#error "Unknown architecture."
86#endif
87
Steve Blocka7e24c12009-10-30 11:49:00 +000088// Include native regexp-macro-assembler.
Steve Block6ded16b2010-05-10 14:33:55 +010089#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000090#if V8_TARGET_ARCH_IA32
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000091#include "src/regexp/ia32/regexp-macro-assembler-ia32.h" // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +000092#elif V8_TARGET_ARCH_X64
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000093#include "src/regexp/x64/regexp-macro-assembler-x64.h" // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +000094#elif V8_TARGET_ARCH_ARM64
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000095#include "src/regexp/arm64/regexp-macro-assembler-arm64.h" // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +000096#elif V8_TARGET_ARCH_ARM
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000097#include "src/regexp/arm/regexp-macro-assembler-arm.h" // NOLINT
98#elif V8_TARGET_ARCH_PPC
99#include "src/regexp/ppc/regexp-macro-assembler-ppc.h" // NOLINT
Steve Block44f0eee2011-05-26 01:26:41 +0100100#elif V8_TARGET_ARCH_MIPS
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000101#include "src/regexp/mips/regexp-macro-assembler-mips.h" // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000102#elif V8_TARGET_ARCH_MIPS64
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000103#include "src/regexp/mips64/regexp-macro-assembler-mips64.h" // NOLINT
Ben Murdochda12d292016-06-02 14:46:10 +0100104#elif V8_TARGET_ARCH_S390
105#include "src/regexp/s390/regexp-macro-assembler-s390.h" // NOLINT
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000106#elif V8_TARGET_ARCH_X87
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000107#include "src/regexp/x87/regexp-macro-assembler-x87.h" // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000108#else // Unknown architecture.
109#error "Unknown architecture."
110#endif // Target architecture.
Steve Block6ded16b2010-05-10 14:33:55 +0100111#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000112
113namespace v8 {
114namespace internal {
115
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100116// -----------------------------------------------------------------------------
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000117// Common register code.
118
119const char* Register::ToString() {
120 // This is the mapping of allocation indices to registers.
121 DCHECK(reg_code >= 0 && reg_code < kNumRegisters);
122 return RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
123 ->GetGeneralRegisterName(reg_code);
124}
125
126
127bool Register::IsAllocatable() const {
128 return ((1 << reg_code) &
129 RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
130 ->allocatable_general_codes_mask()) != 0;
131}
132
133
134const char* DoubleRegister::ToString() {
135 // This is the mapping of allocation indices to registers.
136 DCHECK(reg_code >= 0 && reg_code < kMaxNumRegisters);
137 return RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
138 ->GetDoubleRegisterName(reg_code);
139}
140
141
142bool DoubleRegister::IsAllocatable() const {
143 return ((1 << reg_code) &
144 RegisterConfiguration::ArchDefault(RegisterConfiguration::CRANKSHAFT)
145 ->allocatable_double_codes_mask()) != 0;
146}
147
148
149// -----------------------------------------------------------------------------
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100150// Common double constants.
Steve Blocka7e24c12009-10-30 11:49:00 +0000151
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100152struct DoubleConstant BASE_EMBEDDED {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000153double min_int;
154double one_half;
155double minus_one_half;
156double negative_infinity;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000157double the_hole_nan;
158double uint32_bias;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100159};
160
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000161static DoubleConstant double_constants;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100162
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000163const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100164
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000165static bool math_exp_data_initialized = false;
166static base::Mutex* math_exp_data_mutex = NULL;
167static double* math_exp_constants_array = NULL;
168static double* math_exp_log_table_array = NULL;
169
Steve Blocka7e24c12009-10-30 11:49:00 +0000170// -----------------------------------------------------------------------------
Steve Block053d10c2011-06-13 19:13:29 +0100171// Implementation of AssemblerBase
172
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size)
Steve Block053d10c2011-06-13 19:13:29 +0100174 : isolate_(isolate),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000175 jit_cookie_(0),
176 enabled_cpu_features_(0),
177 emit_debug_code_(FLAG_debug_code),
178 predictable_code_size_(false),
179 // We may use the assembler without an isolate.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400180 serializer_enabled_(isolate && isolate->serializer_enabled()),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000181 constant_pool_available_(false) {
182 DCHECK_NOT_NULL(isolate);
183 if (FLAG_mask_constants_with_cookie) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000184 jit_cookie_ = isolate->random_number_generator()->NextInt();
Steve Block053d10c2011-06-13 19:13:29 +0100185 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000186 own_buffer_ = buffer == NULL;
187 if (buffer_size == 0) buffer_size = kMinimalBufferSize;
188 DCHECK(buffer_size > 0);
189 if (own_buffer_) buffer = NewArray<byte>(buffer_size);
190 buffer_ = static_cast<byte*>(buffer);
191 buffer_size_ = buffer_size;
192
193 pc_ = buffer_;
Steve Block053d10c2011-06-13 19:13:29 +0100194}
195
196
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000197AssemblerBase::~AssemblerBase() {
198 if (own_buffer_) DeleteArray(buffer_);
199}
200
201
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000202void AssemblerBase::FlushICache(Isolate* isolate, void* start, size_t size) {
203 if (size == 0) return;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000204
205#if defined(USE_SIMULATOR)
206 Simulator::FlushICache(isolate->simulator_i_cache(), start, size);
207#else
208 CpuFeatures::FlushICache(start, size);
209#endif // USE_SIMULATOR
210}
211
212
213void AssemblerBase::Print() {
214 OFStream os(stdout);
215 v8::internal::Disassembler::Decode(isolate(), &os, buffer_, pc_, nullptr);
216}
217
218
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000219// -----------------------------------------------------------------------------
220// Implementation of PredictableCodeSizeScope
221
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000222PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler)
223 : PredictableCodeSizeScope(assembler, -1) {}
224
225
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000226PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler,
227 int expected_size)
228 : assembler_(assembler),
229 expected_size_(expected_size),
230 start_offset_(assembler->pc_offset()),
231 old_value_(assembler->predictable_code_size()) {
232 assembler_->set_predictable_code_size(true);
233}
234
235
236PredictableCodeSizeScope::~PredictableCodeSizeScope() {
237 // TODO(svenpanne) Remove the 'if' when everything works.
238 if (expected_size_ >= 0) {
239 CHECK_EQ(expected_size_, assembler_->pc_offset() - start_offset_);
240 }
241 assembler_->set_predictable_code_size(old_value_);
242}
243
244
245// -----------------------------------------------------------------------------
246// Implementation of CpuFeatureScope
247
248#ifdef DEBUG
249CpuFeatureScope::CpuFeatureScope(AssemblerBase* assembler, CpuFeature f)
250 : assembler_(assembler) {
251 DCHECK(CpuFeatures::IsSupported(f));
252 old_enabled_ = assembler_->enabled_cpu_features();
253 uint64_t mask = static_cast<uint64_t>(1) << f;
254 // TODO(svenpanne) This special case below doesn't belong here!
255#if V8_TARGET_ARCH_ARM
256 // ARMv7 is implied by VFP3.
257 if (f == VFP3) {
258 mask |= static_cast<uint64_t>(1) << ARMv7;
259 }
260#endif
261 assembler_->set_enabled_cpu_features(old_enabled_ | mask);
262}
263
264
265CpuFeatureScope::~CpuFeatureScope() {
266 assembler_->set_enabled_cpu_features(old_enabled_);
267}
268#endif
269
270
271bool CpuFeatures::initialized_ = false;
272unsigned CpuFeatures::supported_ = 0;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100273unsigned CpuFeatures::icache_line_size_ = 0;
274unsigned CpuFeatures::dcache_line_size_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000275
Steve Block053d10c2011-06-13 19:13:29 +0100276// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000277// Implementation of Label
278
279int Label::pos() const {
280 if (pos_ < 0) return -pos_ - 1;
281 if (pos_ > 0) return pos_ - 1;
282 UNREACHABLE();
283 return 0;
284}
285
286
287// -----------------------------------------------------------------------------
288// Implementation of RelocInfoWriter and RelocIterator
289//
Ben Murdoch257744e2011-11-30 15:57:28 +0000290// Relocation information is written backwards in memory, from high addresses
291// towards low addresses, byte by byte. Therefore, in the encodings listed
292// below, the first byte listed it at the highest address, and successive
293// bytes in the record are at progressively lower addresses.
294//
Steve Blocka7e24c12009-10-30 11:49:00 +0000295// Encoding
296//
297// The most common modes are given single-byte encodings. Also, it is
298// easy to identify the type of reloc info and skip unwanted modes in
299// an iteration.
300//
Ben Murdoch257744e2011-11-30 15:57:28 +0000301// The encoding relies on the fact that there are fewer than 14
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000302// different relocation modes using standard non-compact encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000303//
Ben Murdoch257744e2011-11-30 15:57:28 +0000304// The first byte of a relocation record has a tag in its low 2 bits:
305// Here are the record schemes, depending on the low tag and optional higher
306// tags.
Steve Blocka7e24c12009-10-30 11:49:00 +0000307//
Ben Murdoch257744e2011-11-30 15:57:28 +0000308// Low tag:
309// 00: embedded_object: [6-bit pc delta] 00
Steve Blocka7e24c12009-10-30 11:49:00 +0000310//
Ben Murdoch257744e2011-11-30 15:57:28 +0000311// 01: code_target: [6-bit pc delta] 01
Steve Blocka7e24c12009-10-30 11:49:00 +0000312//
Ben Murdoch257744e2011-11-30 15:57:28 +0000313// 10: short_data_record: [6-bit pc delta] 10 followed by
314// [6-bit data delta] [2-bit data type tag]
Steve Blocka7e24c12009-10-30 11:49:00 +0000315//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000316// 11: long_record [6 bit reloc mode] 11
317// followed by pc delta
318// followed by optional data depending on type.
Steve Blocka7e24c12009-10-30 11:49:00 +0000319//
Ben Murdoch257744e2011-11-30 15:57:28 +0000320// 2-bit data type tags, used in short_data_record and data_jump long_record:
321// code_target_with_id: 00
322// position: 01
323// statement_position: 10
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000324// deopt_reason: 11
Steve Blocka7e24c12009-10-30 11:49:00 +0000325//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000326// If a pc delta exceeds 6 bits, it is split into a remainder that fits into
327// 6 bits and a part that does not. The latter is encoded as a long record
328// with PC_JUMP as pseudo reloc info mode. The former is encoded as part of
329// the following record in the usual way. The long pc jump record has variable
330// length:
331// pc-jump: [PC_JUMP] 11
Ben Murdoch257744e2011-11-30 15:57:28 +0000332// [7 bits data] 0
333// ...
334// [7 bits data] 1
335// (Bits 6..31 of pc delta, with leading zeroes
336// dropped, and last non-zero chunk tagged with 1.)
337
Steve Blocka7e24c12009-10-30 11:49:00 +0000338const int kTagBits = 2;
339const int kTagMask = (1 << kTagBits) - 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000340const int kLongTagBits = 6;
341const int kShortDataTypeTagBits = 2;
342const int kShortDataBits = kBitsPerByte - kShortDataTypeTagBits;
Steve Blocka7e24c12009-10-30 11:49:00 +0000343
344const int kEmbeddedObjectTag = 0;
345const int kCodeTargetTag = 1;
Ben Murdoch257744e2011-11-30 15:57:28 +0000346const int kLocatableTag = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000347const int kDefaultTag = 3;
348
Steve Blocka7e24c12009-10-30 11:49:00 +0000349const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
350const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100351const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000352
Steve Blocka7e24c12009-10-30 11:49:00 +0000353const int kChunkBits = 7;
354const int kChunkMask = (1 << kChunkBits) - 1;
355const int kLastChunkTagBits = 1;
356const int kLastChunkTagMask = 1;
357const int kLastChunkTag = 1;
358
Ben Murdoch257744e2011-11-30 15:57:28 +0000359const int kCodeWithIdTag = 0;
360const int kNonstatementPositionTag = 1;
361const int kStatementPositionTag = 2;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000362const int kDeoptReasonTag = 3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000363
Steve Blocka7e24c12009-10-30 11:49:00 +0000364
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000365uint32_t RelocInfoWriter::WriteLongPCJump(uint32_t pc_delta) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000366 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
367 // Otherwise write a variable length PC jump for the bits that do
368 // not fit in the kSmallPCDeltaBits bits.
369 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000370 WriteMode(RelocInfo::PC_JUMP);
Steve Blocka7e24c12009-10-30 11:49:00 +0000371 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000372 DCHECK(pc_jump > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000373 // Write kChunkBits size chunks of the pc_jump.
374 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
375 byte b = pc_jump & kChunkMask;
376 *--pos_ = b << kLastChunkTagBits;
377 }
378 // Tag the last chunk so it can be identified.
379 *pos_ = *pos_ | kLastChunkTag;
380 // Return the remaining kSmallPCDeltaBits of the pc_delta.
381 return pc_delta & kSmallPCDeltaMask;
382}
383
384
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385void RelocInfoWriter::WriteShortTaggedPC(uint32_t pc_delta, int tag) {
386 // Write a byte of tagged pc-delta, possibly preceded by an explicit pc-jump.
387 pc_delta = WriteLongPCJump(pc_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000388 *--pos_ = pc_delta << kTagBits | tag;
389}
390
391
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000392void RelocInfoWriter::WriteShortTaggedData(intptr_t data_delta, int tag) {
393 *--pos_ = static_cast<byte>(data_delta << kShortDataTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000394}
395
396
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000397void RelocInfoWriter::WriteMode(RelocInfo::Mode rmode) {
398 STATIC_ASSERT(RelocInfo::NUMBER_OF_MODES <= (1 << kLongTagBits));
399 *--pos_ = static_cast<int>((rmode << kTagBits) | kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000400}
401
402
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000403void RelocInfoWriter::WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000404 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000405 pc_delta = WriteLongPCJump(pc_delta);
406 WriteMode(rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000407 *--pos_ = pc_delta;
408}
409
410
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000411void RelocInfoWriter::WriteIntData(int number) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000412 for (int i = 0; i < kIntSize; i++) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000413 *--pos_ = static_cast<byte>(number);
Ben Murdoch257744e2011-11-30 15:57:28 +0000414 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000415 number = number >> kBitsPerByte;
Ben Murdoch257744e2011-11-30 15:57:28 +0000416 }
417}
418
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000419
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000420void RelocInfoWriter::WriteData(intptr_t data_delta) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000421 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000422 *--pos_ = static_cast<byte>(data_delta);
Ben Murdoch257744e2011-11-30 15:57:28 +0000423 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Steve Blocka7e24c12009-10-30 11:49:00 +0000424 data_delta = data_delta >> kBitsPerByte;
425 }
426}
427
428
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000429void RelocInfoWriter::WritePosition(int pc_delta, int pos_delta,
430 RelocInfo::Mode rmode) {
431 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag
432 : kStatementPositionTag;
433 // Check if delta is small enough to fit in a tagged byte.
434 if (is_intn(pos_delta, kShortDataBits)) {
435 WriteShortTaggedPC(pc_delta, kLocatableTag);
436 WriteShortTaggedData(pos_delta, pos_type_tag);
437 } else {
438 // Otherwise, use costly encoding.
439 WriteModeAndPC(pc_delta, rmode);
440 WriteIntData(pos_delta);
441 }
442}
443
444
445void RelocInfoWriter::FlushPosition() {
446 if (!next_position_candidate_flushed_) {
447 WritePosition(next_position_candidate_pc_delta_,
448 next_position_candidate_pos_delta_, RelocInfo::POSITION);
449 next_position_candidate_pos_delta_ = 0;
450 next_position_candidate_pc_delta_ = 0;
451 next_position_candidate_flushed_ = true;
452 }
453}
454
455
Steve Blocka7e24c12009-10-30 11:49:00 +0000456void RelocInfoWriter::Write(const RelocInfo* rinfo) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000457 RelocInfo::Mode rmode = rinfo->rmode();
458 if (rmode != RelocInfo::POSITION) {
459 FlushPosition();
460 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000461#ifdef DEBUG
462 byte* begin_pos = pos_;
463#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000464 DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES);
465 DCHECK(rinfo->pc() - last_pc_ >= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000466 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000467 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000468
469 // The two most common modes are given small tags, and usually fit in a byte.
470 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000471 WriteShortTaggedPC(pc_delta, kEmbeddedObjectTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000472 } else if (rmode == RelocInfo::CODE_TARGET) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000473 WriteShortTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000474 DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Ben Murdoch257744e2011-11-30 15:57:28 +0000475 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
476 // Use signed delta-encoding for id.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000477 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data());
Ben Murdoch257744e2011-11-30 15:57:28 +0000478 int id_delta = static_cast<int>(rinfo->data()) - last_id_;
479 // Check if delta is small enough to fit in a tagged byte.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000480 if (is_intn(id_delta, kShortDataBits)) {
481 WriteShortTaggedPC(pc_delta, kLocatableTag);
482 WriteShortTaggedData(id_delta, kCodeWithIdTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000483 } else {
484 // Otherwise, use costly encoding.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000485 WriteModeAndPC(pc_delta, rmode);
486 WriteIntData(id_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000488 last_id_ = static_cast<int>(rinfo->data());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000489 } else if (rmode == RelocInfo::DEOPT_REASON) {
490 DCHECK(rinfo->data() < (1 << kShortDataBits));
491 WriteShortTaggedPC(pc_delta, kLocatableTag);
492 WriteShortTaggedData(rinfo->data(), kDeoptReasonTag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000493 } else if (RelocInfo::IsPosition(rmode)) {
494 // Use signed delta-encoding for position.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000495 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data());
Ben Murdoch257744e2011-11-30 15:57:28 +0000496 int pos_delta = static_cast<int>(rinfo->data()) - last_position_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000497 if (rmode == RelocInfo::STATEMENT_POSITION) {
498 WritePosition(pc_delta, pos_delta, rmode);
Ben Murdoch257744e2011-11-30 15:57:28 +0000499 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000500 DCHECK_EQ(rmode, RelocInfo::POSITION);
501 if (pc_delta != 0 || last_mode_ != RelocInfo::POSITION) {
502 FlushPosition();
503 next_position_candidate_pc_delta_ = pc_delta;
504 next_position_candidate_pos_delta_ = pos_delta;
505 } else {
506 next_position_candidate_pos_delta_ += pos_delta;
507 }
508 next_position_candidate_flushed_ = false;
Ben Murdoch257744e2011-11-30 15:57:28 +0000509 }
510 last_position_ = static_cast<int>(rinfo->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000511 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512 WriteModeAndPC(pc_delta, rmode);
513 if (RelocInfo::IsComment(rmode)) {
514 WriteData(rinfo->data());
515 } else if (RelocInfo::IsConstPool(rmode) ||
Ben Murdochc5610432016-08-08 18:44:38 +0100516 RelocInfo::IsVeneerPool(rmode) ||
517 RelocInfo::IsDeoptId(rmode)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000518 WriteIntData(static_cast<int>(rinfo->data()));
519 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000520 }
521 last_pc_ = rinfo->pc();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000522 last_mode_ = rmode;
Steve Blocka7e24c12009-10-30 11:49:00 +0000523#ifdef DEBUG
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000524 DCHECK(begin_pos - pos_ <= kMaxSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000525#endif
526}
527
528
529inline int RelocIterator::AdvanceGetTag() {
530 return *--pos_ & kTagMask;
531}
532
533
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000534inline RelocInfo::Mode RelocIterator::GetMode() {
535 return static_cast<RelocInfo::Mode>((*pos_ >> kTagBits) &
536 ((1 << kLongTagBits) - 1));
Steve Blocka7e24c12009-10-30 11:49:00 +0000537}
538
539
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000540inline void RelocIterator::ReadShortTaggedPC() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000541 rinfo_.pc_ += *pos_ >> kTagBits;
542}
543
544
545inline void RelocIterator::AdvanceReadPC() {
546 rinfo_.pc_ += *--pos_;
547}
548
549
Ben Murdoch257744e2011-11-30 15:57:28 +0000550void RelocIterator::AdvanceReadId() {
551 int x = 0;
552 for (int i = 0; i < kIntSize; i++) {
553 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
554 }
555 last_id_ += x;
556 rinfo_.data_ = last_id_;
557}
558
559
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000560void RelocIterator::AdvanceReadInt() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000561 int x = 0;
562 for (int i = 0; i < kIntSize; i++) {
563 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
564 }
565 rinfo_.data_ = x;
566}
567
568
Ben Murdoch257744e2011-11-30 15:57:28 +0000569void RelocIterator::AdvanceReadPosition() {
570 int x = 0;
571 for (int i = 0; i < kIntSize; i++) {
572 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
573 }
574 last_position_ += x;
575 rinfo_.data_ = last_position_;
576}
577
578
Steve Blocka7e24c12009-10-30 11:49:00 +0000579void RelocIterator::AdvanceReadData() {
580 intptr_t x = 0;
581 for (int i = 0; i < kIntptrSize; i++) {
582 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
583 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000584 rinfo_.data_ = x;
Steve Blocka7e24c12009-10-30 11:49:00 +0000585}
586
587
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000588void RelocIterator::AdvanceReadLongPCJump() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000589 // Read the 32-kSmallPCDeltaBits most significant bits of the
590 // pc jump in kChunkBits bit chunks and shift them into place.
591 // Stop when the last chunk is encountered.
592 uint32_t pc_jump = 0;
593 for (int i = 0; i < kIntSize; i++) {
594 byte pc_jump_part = *--pos_;
595 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
596 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
597 }
598 // The least significant kSmallPCDeltaBits bits will be added
599 // later.
600 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
601}
602
603
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000604inline int RelocIterator::GetShortDataTypeTag() {
605 return *pos_ & ((1 << kShortDataTypeTagBits) - 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000606}
607
608
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000609inline void RelocIterator::ReadShortTaggedId() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000610 int8_t signed_b = *pos_;
611 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000612 last_id_ += signed_b >> kShortDataTypeTagBits;
Ben Murdoch257744e2011-11-30 15:57:28 +0000613 rinfo_.data_ = last_id_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000614}
615
616
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000617inline void RelocIterator::ReadShortTaggedPosition() {
Ben Murdoch257744e2011-11-30 15:57:28 +0000618 int8_t signed_b = *pos_;
619 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000620 last_position_ += signed_b >> kShortDataTypeTagBits;
Ben Murdoch257744e2011-11-30 15:57:28 +0000621 rinfo_.data_ = last_position_;
622}
623
624
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000625inline void RelocIterator::ReadShortTaggedData() {
626 uint8_t unsigned_b = *pos_;
627 rinfo_.data_ = unsigned_b >> kTagBits;
628}
629
630
Ben Murdoch257744e2011-11-30 15:57:28 +0000631static inline RelocInfo::Mode GetPositionModeFromTag(int tag) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000632 DCHECK(tag == kNonstatementPositionTag ||
Ben Murdoch257744e2011-11-30 15:57:28 +0000633 tag == kStatementPositionTag);
634 return (tag == kNonstatementPositionTag) ?
635 RelocInfo::POSITION :
636 RelocInfo::STATEMENT_POSITION;
Steve Blocka7e24c12009-10-30 11:49:00 +0000637}
638
639
640void RelocIterator::next() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000641 DCHECK(!done());
Steve Blocka7e24c12009-10-30 11:49:00 +0000642 // Basically, do the opposite of RelocInfoWriter::Write.
643 // Reading of data is as far as possible avoided for unwanted modes,
644 // but we must always update the pc.
645 //
646 // We exit this loop by returning when we find a mode we want.
647 while (pos_ > end_) {
648 int tag = AdvanceGetTag();
649 if (tag == kEmbeddedObjectTag) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000650 ReadShortTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000651 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
652 } else if (tag == kCodeTargetTag) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000653 ReadShortTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000654 if (SetMode(RelocInfo::CODE_TARGET)) return;
Ben Murdoch257744e2011-11-30 15:57:28 +0000655 } else if (tag == kLocatableTag) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000656 ReadShortTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000657 Advance();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000658 int data_type_tag = GetShortDataTypeTag();
659 if (data_type_tag == kCodeWithIdTag) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000660 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000661 ReadShortTaggedId();
662 return;
663 }
664 } else if (data_type_tag == kDeoptReasonTag) {
665 if (SetMode(RelocInfo::DEOPT_REASON)) {
666 ReadShortTaggedData();
Ben Murdoch257744e2011-11-30 15:57:28 +0000667 return;
668 }
669 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000670 DCHECK(data_type_tag == kNonstatementPositionTag ||
671 data_type_tag == kStatementPositionTag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000672 if (mode_mask_ & RelocInfo::kPositionMask) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000673 // Always update the position if we are interested in either
674 // statement positions or non-statement positions.
675 ReadShortTaggedPosition();
676 if (SetMode(GetPositionModeFromTag(data_type_tag))) return;
Ben Murdoch257744e2011-11-30 15:57:28 +0000677 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000678 }
679 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000680 DCHECK(tag == kDefaultTag);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000681 RelocInfo::Mode rmode = GetMode();
682 if (rmode == RelocInfo::PC_JUMP) {
683 AdvanceReadLongPCJump();
684 } else {
685 AdvanceReadPC();
686 if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
687 if (SetMode(rmode)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000688 AdvanceReadId();
689 return;
690 }
691 Advance(kIntSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000692 } else if (RelocInfo::IsComment(rmode)) {
693 if (SetMode(rmode)) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000694 AdvanceReadData();
695 return;
696 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000697 Advance(kIntptrSize);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000698 } else if (RelocInfo::IsPosition(rmode)) {
699 if (mode_mask_ & RelocInfo::kPositionMask) {
700 // Always update the position if we are interested in either
701 // statement positions or non-statement positions.
702 AdvanceReadPosition();
703 if (SetMode(rmode)) return;
704 } else {
705 Advance(kIntSize);
706 }
707 } else if (RelocInfo::IsConstPool(rmode) ||
Ben Murdochc5610432016-08-08 18:44:38 +0100708 RelocInfo::IsVeneerPool(rmode) ||
709 RelocInfo::IsDeoptId(rmode)) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000710 if (SetMode(rmode)) {
711 AdvanceReadInt();
712 return;
713 }
714 Advance(kIntSize);
715 } else if (SetMode(static_cast<RelocInfo::Mode>(rmode))) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000716 return;
717 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000718 }
719 }
720 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000721 if (code_age_sequence_ != NULL) {
722 byte* old_code_age_sequence = code_age_sequence_;
723 code_age_sequence_ = NULL;
724 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) {
725 rinfo_.data_ = 0;
726 rinfo_.pc_ = old_code_age_sequence;
727 return;
728 }
729 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000730 done_ = true;
731}
732
733
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000734RelocIterator::RelocIterator(Code* code, int mode_mask)
735 : rinfo_(code->map()->GetIsolate()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100736 rinfo_.host_ = code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000737 rinfo_.pc_ = code->instruction_start();
738 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100739 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000740 pos_ = code->relocation_start() + code->relocation_size();
741 end_ = code->relocation_start();
742 done_ = false;
743 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000744 last_id_ = 0;
745 last_position_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000746 byte* sequence = code->FindCodeAgeSequence();
747 // We get the isolate from the map, because at serialization time
748 // the code pointer has been cloned and isn't really in heap space.
749 Isolate* isolate = code->map()->GetIsolate();
750 if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) {
751 code_age_sequence_ = sequence;
752 } else {
753 code_age_sequence_ = NULL;
754 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000755 if (mode_mask_ == 0) pos_ = end_;
756 next();
757}
758
759
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000760RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask)
761 : rinfo_(desc.origin->isolate()) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000762 rinfo_.pc_ = desc.buffer;
763 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100764 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000765 pos_ = desc.buffer + desc.buffer_size;
766 end_ = pos_ - desc.reloc_size;
767 done_ = false;
768 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000769 last_id_ = 0;
770 last_position_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000771 code_age_sequence_ = NULL;
Steve Blocka7e24c12009-10-30 11:49:00 +0000772 if (mode_mask_ == 0) pos_ = end_;
773 next();
774}
775
776
777// -----------------------------------------------------------------------------
778// Implementation of RelocInfo
779
Ben Murdoch097c5b22016-05-18 11:27:45 +0100780bool RelocInfo::IsPatchedDebugBreakSlotSequence() {
781 return DebugCodegen::DebugBreakSlotIsPatched(pc_);
782}
Steve Blocka7e24c12009-10-30 11:49:00 +0000783
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000784#ifdef DEBUG
785bool RelocInfo::RequiresRelocation(const CodeDesc& desc) {
786 // Ensure there are no code targets or embedded objects present in the
787 // deoptimization entries, they would require relocation after code
788 // generation.
789 int mode_mask = RelocInfo::kCodeTargetMask |
790 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
791 RelocInfo::ModeMask(RelocInfo::CELL) |
792 RelocInfo::kApplyMask;
793 RelocIterator it(desc, mode_mask);
794 return !it.done();
795}
796#endif
797
798
Steve Blocka7e24c12009-10-30 11:49:00 +0000799#ifdef ENABLE_DISASSEMBLER
800const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
801 switch (rmode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000802 case NONE32:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000803 return "no reloc 32";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000804 case NONE64:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000805 return "no reloc 64";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000806 case EMBEDDED_OBJECT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000807 return "embedded object";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000808 case DEBUGGER_STATEMENT:
809 return "debugger statement";
810 case CODE_TARGET:
Steve Blocka7e24c12009-10-30 11:49:00 +0000811 return "code target";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000812 case CODE_TARGET_WITH_ID:
Ben Murdoch257744e2011-11-30 15:57:28 +0000813 return "code target with id";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000814 case CELL:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000815 return "property cell";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000816 case RUNTIME_ENTRY:
Steve Blocka7e24c12009-10-30 11:49:00 +0000817 return "runtime entry";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000818 case COMMENT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000819 return "comment";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000820 case POSITION:
Steve Blocka7e24c12009-10-30 11:49:00 +0000821 return "position";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000822 case STATEMENT_POSITION:
Steve Blocka7e24c12009-10-30 11:49:00 +0000823 return "statement position";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000824 case EXTERNAL_REFERENCE:
Steve Blocka7e24c12009-10-30 11:49:00 +0000825 return "external reference";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000826 case INTERNAL_REFERENCE:
Steve Blocka7e24c12009-10-30 11:49:00 +0000827 return "internal reference";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000828 case INTERNAL_REFERENCE_ENCODED:
829 return "encoded internal reference";
830 case DEOPT_REASON:
831 return "deopt reason";
Ben Murdochc5610432016-08-08 18:44:38 +0100832 case DEOPT_ID:
833 return "deopt index";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000834 case CONST_POOL:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000835 return "constant pool";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000836 case VENEER_POOL:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000837 return "veneer pool";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000838 case DEBUG_BREAK_SLOT_AT_POSITION:
839 return "debug break slot at position";
840 case DEBUG_BREAK_SLOT_AT_RETURN:
841 return "debug break slot at return";
842 case DEBUG_BREAK_SLOT_AT_CALL:
843 return "debug break slot at call";
Ben Murdochda12d292016-06-02 14:46:10 +0100844 case DEBUG_BREAK_SLOT_AT_TAIL_CALL:
845 return "debug break slot at tail call";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000846 case CODE_AGE_SEQUENCE:
847 return "code age sequence";
848 case GENERATOR_CONTINUATION:
849 return "generator continuation";
Ben Murdochda12d292016-06-02 14:46:10 +0100850 case WASM_MEMORY_REFERENCE:
851 return "wasm memory reference";
Ben Murdochc5610432016-08-08 18:44:38 +0100852 case WASM_MEMORY_SIZE_REFERENCE:
853 return "wasm memory size reference";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000854 case NUMBER_OF_MODES:
855 case PC_JUMP:
Steve Blocka7e24c12009-10-30 11:49:00 +0000856 UNREACHABLE();
857 return "number_of_modes";
858 }
859 return "unknown relocation type";
860}
861
862
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400863void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT
864 os << static_cast<const void*>(pc_) << " " << RelocModeName(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000865 if (IsComment(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000866 os << " (" << reinterpret_cast<char*>(data_) << ")";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000867 } else if (rmode_ == DEOPT_REASON) {
868 os << " (" << Deoptimizer::GetDeoptReason(
869 static_cast<Deoptimizer::DeoptReason>(data_)) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000870 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000871 os << " (" << Brief(target_object()) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000872 } else if (rmode_ == EXTERNAL_REFERENCE) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000873 ExternalReferenceEncoder ref_encoder(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000874 os << " ("
875 << ref_encoder.NameOfAddress(isolate, target_external_reference())
876 << ") (" << static_cast<const void*>(target_external_reference())
877 << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000878 } else if (IsCodeTarget(rmode_)) {
879 Code* code = Code::GetCodeFromTargetAddress(target_address());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400880 os << " (" << Code::Kind2String(code->kind()) << ") ("
881 << static_cast<const void*>(target_address()) << ")";
Ben Murdoch257744e2011-11-30 15:57:28 +0000882 if (rmode_ == CODE_TARGET_WITH_ID) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000883 os << " (id=" << static_cast<int>(data_) << ")";
Ben Murdoch257744e2011-11-30 15:57:28 +0000884 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000885 } else if (IsPosition(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000886 os << " (" << data() << ")";
887 } else if (IsRuntimeEntry(rmode_) &&
888 isolate->deoptimizer_data() != NULL) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100889 // Depotimization bailouts are stored as runtime entries.
890 int id = Deoptimizer::GetDeoptimizationId(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000891 isolate, target_address(), Deoptimizer::EAGER);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100892 if (id != Deoptimizer::kNotDeoptimizationEntry) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000893 os << " (deoptimization bailout " << id << ")";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100894 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000895 } else if (IsConstPool(rmode_)) {
896 os << " (size " << static_cast<int>(data_) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000897 }
898
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000899 os << "\n";
Steve Blocka7e24c12009-10-30 11:49:00 +0000900}
901#endif // ENABLE_DISASSEMBLER
902
903
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000904#ifdef VERIFY_HEAP
905void RelocInfo::Verify(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000906 switch (rmode_) {
907 case EMBEDDED_OBJECT:
908 Object::VerifyPointer(target_object());
909 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000910 case CELL:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100911 Object::VerifyPointer(target_cell());
912 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000913 case DEBUGGER_STATEMENT:
Ben Murdoch257744e2011-11-30 15:57:28 +0000914 case CODE_TARGET_WITH_ID:
Steve Blocka7e24c12009-10-30 11:49:00 +0000915 case CODE_TARGET: {
916 // convert inline target address to code object
917 Address addr = target_address();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000918 CHECK(addr != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000919 // Check that we can find the right code object.
920 Code* code = Code::GetCodeFromTargetAddress(addr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000921 Object* found = isolate->FindCodeObject(addr);
922 CHECK(found->IsCode());
923 CHECK(code->address() == HeapObject::cast(found)->address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000924 break;
925 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000926 case INTERNAL_REFERENCE:
927 case INTERNAL_REFERENCE_ENCODED: {
928 Address target = target_internal_reference();
929 Address pc = target_internal_reference_address();
930 Code* code = Code::cast(isolate->FindCodeObject(pc));
931 CHECK(target >= code->instruction_start());
932 CHECK(target <= code->instruction_end());
933 break;
934 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000935 case RUNTIME_ENTRY:
Steve Blocka7e24c12009-10-30 11:49:00 +0000936 case COMMENT:
937 case POSITION:
938 case STATEMENT_POSITION:
939 case EXTERNAL_REFERENCE:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000940 case DEOPT_REASON:
Ben Murdochc5610432016-08-08 18:44:38 +0100941 case DEOPT_ID:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000942 case CONST_POOL:
943 case VENEER_POOL:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 case DEBUG_BREAK_SLOT_AT_POSITION:
945 case DEBUG_BREAK_SLOT_AT_RETURN:
946 case DEBUG_BREAK_SLOT_AT_CALL:
Ben Murdochda12d292016-06-02 14:46:10 +0100947 case DEBUG_BREAK_SLOT_AT_TAIL_CALL:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000948 case GENERATOR_CONTINUATION:
Ben Murdochda12d292016-06-02 14:46:10 +0100949 case WASM_MEMORY_REFERENCE:
Ben Murdochc5610432016-08-08 18:44:38 +0100950 case WASM_MEMORY_SIZE_REFERENCE:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000951 case NONE32:
952 case NONE64:
Steve Blocka7e24c12009-10-30 11:49:00 +0000953 break;
954 case NUMBER_OF_MODES:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000955 case PC_JUMP:
Steve Blocka7e24c12009-10-30 11:49:00 +0000956 UNREACHABLE();
957 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000958 case CODE_AGE_SEQUENCE:
959 DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode());
960 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000961 }
962}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000963#endif // VERIFY_HEAP
Steve Blocka7e24c12009-10-30 11:49:00 +0000964
965
Steve Blocka7e24c12009-10-30 11:49:00 +0000966// Implementation of ExternalReference
967
Ben Murdoch097c5b22016-05-18 11:27:45 +0100968static ExternalReference::Type BuiltinCallTypeForResultSize(int result_size) {
969 switch (result_size) {
970 case 1:
971 return ExternalReference::BUILTIN_CALL;
972 case 2:
973 return ExternalReference::BUILTIN_CALL_PAIR;
974 case 3:
975 return ExternalReference::BUILTIN_CALL_TRIPLE;
976 }
977 UNREACHABLE();
978 return ExternalReference::BUILTIN_CALL;
979}
980
981
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000982void ExternalReference::SetUp() {
983 double_constants.min_int = kMinInt;
984 double_constants.one_half = 0.5;
985 double_constants.minus_one_half = -0.5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000986 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64);
987 double_constants.negative_infinity = -V8_INFINITY;
988 double_constants.uint32_bias =
989 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1;
990
991 math_exp_data_mutex = new base::Mutex();
992}
993
994
995void ExternalReference::InitializeMathExpData() {
996 // Early return?
997 if (math_exp_data_initialized) return;
998
999 base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex);
1000 if (!math_exp_data_initialized) {
1001 // If this is changed, generated code must be adapted too.
1002 const int kTableSizeBits = 11;
1003 const int kTableSize = 1 << kTableSizeBits;
1004 const double kTableSizeDouble = static_cast<double>(kTableSize);
1005
1006 math_exp_constants_array = new double[9];
1007 // Input values smaller than this always return 0.
1008 math_exp_constants_array[0] = -708.39641853226408;
1009 // Input values larger than this always return +Infinity.
1010 math_exp_constants_array[1] = 709.78271289338397;
1011 math_exp_constants_array[2] = V8_INFINITY;
1012 // The rest is black magic. Do not attempt to understand it. It is
1013 // loosely based on the "expd" function published at:
1014 // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html
1015 const double constant3 = (1 << kTableSizeBits) / std::log(2.0);
1016 math_exp_constants_array[3] = constant3;
1017 math_exp_constants_array[4] =
1018 static_cast<double>(static_cast<int64_t>(3) << 51);
1019 math_exp_constants_array[5] = 1 / constant3;
1020 math_exp_constants_array[6] = 3.0000000027955394;
1021 math_exp_constants_array[7] = 0.16666666685227835;
1022 math_exp_constants_array[8] = 1;
1023
1024 math_exp_log_table_array = new double[kTableSize];
1025 for (int i = 0; i < kTableSize; i++) {
1026 double value = std::pow(2, i / kTableSizeDouble);
1027 uint64_t bits = bit_cast<uint64_t, double>(value);
1028 bits &= (static_cast<uint64_t>(1) << 52) - 1;
1029 double mantissa = bit_cast<double, uint64_t>(bits);
1030 math_exp_log_table_array[i] = mantissa;
1031 }
1032
1033 math_exp_data_initialized = true;
1034 }
1035}
1036
1037
1038void ExternalReference::TearDownMathExpData() {
1039 delete[] math_exp_constants_array;
1040 math_exp_constants_array = NULL;
1041 delete[] math_exp_log_table_array;
1042 math_exp_log_table_array = NULL;
1043 delete math_exp_data_mutex;
1044 math_exp_data_mutex = NULL;
1045}
1046
1047
Steve Block44f0eee2011-05-26 01:26:41 +01001048ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
1049 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001050
1051
Steve Block1e0659c2011-05-24 12:43:12 +01001052ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001053 ApiFunction* fun,
1054 Type type = ExternalReference::BUILTIN_CALL,
1055 Isolate* isolate = NULL)
1056 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +00001057
1058
Steve Block44f0eee2011-05-26 01:26:41 +01001059ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
1060 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001061
1062
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001063ExternalReference::ExternalReference(Runtime::FunctionId id, Isolate* isolate)
Ben Murdoch097c5b22016-05-18 11:27:45 +01001064 : ExternalReference(Runtime::FunctionForId(id), isolate) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001065
1066
Steve Block44f0eee2011-05-26 01:26:41 +01001067ExternalReference::ExternalReference(const Runtime::Function* f,
1068 Isolate* isolate)
Ben Murdoch097c5b22016-05-18 11:27:45 +01001069 : address_(Redirect(isolate, f->entry,
1070 BuiltinCallTypeForResultSize(f->result_size))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001071
1072
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001073ExternalReference ExternalReference::isolate_address(Isolate* isolate) {
1074 return ExternalReference(isolate);
Steve Block44f0eee2011-05-26 01:26:41 +01001075}
1076
Ben Murdoch097c5b22016-05-18 11:27:45 +01001077ExternalReference ExternalReference::interpreter_dispatch_table_address(
1078 Isolate* isolate) {
1079 return ExternalReference(isolate->interpreter()->dispatch_table_address());
1080}
Steve Block44f0eee2011-05-26 01:26:41 +01001081
Ben Murdochc5610432016-08-08 18:44:38 +01001082ExternalReference ExternalReference::interpreter_dispatch_counters(
1083 Isolate* isolate) {
1084 return ExternalReference(
1085 isolate->interpreter()->bytecode_dispatch_counters_table());
1086}
1087
Steve Blocka7e24c12009-10-30 11:49:00 +00001088ExternalReference::ExternalReference(StatsCounter* counter)
1089 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
1090
1091
Steve Block44f0eee2011-05-26 01:26:41 +01001092ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
1093 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001094
1095
1096ExternalReference::ExternalReference(const SCTableReference& table_ref)
1097 : address_(table_ref.address()) {}
1098
1099
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001100ExternalReference ExternalReference::
1101 incremental_marking_record_write_function(Isolate* isolate) {
1102 return ExternalReference(Redirect(
1103 isolate,
1104 FUNCTION_ADDR(IncrementalMarking::RecordWriteFromCode)));
1105}
1106
Ben Murdoch097c5b22016-05-18 11:27:45 +01001107ExternalReference
1108ExternalReference::incremental_marking_record_write_code_entry_function(
1109 Isolate* isolate) {
1110 return ExternalReference(Redirect(
1111 isolate,
1112 FUNCTION_ADDR(IncrementalMarking::RecordWriteOfCodeEntryFromCode)));
1113}
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001114
Ben Murdoch097c5b22016-05-18 11:27:45 +01001115ExternalReference ExternalReference::store_buffer_overflow_function(
1116 Isolate* isolate) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001117 return ExternalReference(Redirect(
1118 isolate,
1119 FUNCTION_ADDR(StoreBuffer::StoreBufferOverflow)));
1120}
1121
1122
Steve Block44f0eee2011-05-26 01:26:41 +01001123ExternalReference ExternalReference::delete_handle_scope_extensions(
1124 Isolate* isolate) {
1125 return ExternalReference(Redirect(
1126 isolate,
1127 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -07001128}
1129
1130
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001131ExternalReference ExternalReference::get_date_field_function(
1132 Isolate* isolate) {
1133 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(JSDate::GetField)));
1134}
1135
1136
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001137ExternalReference ExternalReference::get_make_code_young_function(
1138 Isolate* isolate) {
1139 return ExternalReference(Redirect(
1140 isolate, FUNCTION_ADDR(Code::MakeCodeAgeSequenceYoung)));
1141}
1142
1143
1144ExternalReference ExternalReference::get_mark_code_as_executed_function(
1145 Isolate* isolate) {
1146 return ExternalReference(Redirect(
1147 isolate, FUNCTION_ADDR(Code::MarkCodeAsExecuted)));
1148}
1149
1150
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001151ExternalReference ExternalReference::date_cache_stamp(Isolate* isolate) {
1152 return ExternalReference(isolate->date_cache()->stamp_address());
1153}
1154
1155
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001156ExternalReference ExternalReference::stress_deopt_count(Isolate* isolate) {
1157 return ExternalReference(isolate->stress_deopt_count_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001158}
1159
1160
Steve Block44f0eee2011-05-26 01:26:41 +01001161ExternalReference ExternalReference::new_deoptimizer_function(
1162 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001163 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001164 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001165}
1166
1167
Steve Block44f0eee2011-05-26 01:26:41 +01001168ExternalReference ExternalReference::compute_output_frames_function(
1169 Isolate* isolate) {
1170 return ExternalReference(
1171 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001172}
1173
Ben Murdochda12d292016-06-02 14:46:10 +01001174ExternalReference ExternalReference::wasm_f32_trunc(Isolate* isolate) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001175 return ExternalReference(
Ben Murdochda12d292016-06-02 14:46:10 +01001176 Redirect(isolate, FUNCTION_ADDR(wasm::f32_trunc_wrapper)));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001177}
Ben Murdochda12d292016-06-02 14:46:10 +01001178ExternalReference ExternalReference::wasm_f32_floor(Isolate* isolate) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001179 return ExternalReference(
Ben Murdochda12d292016-06-02 14:46:10 +01001180 Redirect(isolate, FUNCTION_ADDR(wasm::f32_floor_wrapper)));
1181}
1182ExternalReference ExternalReference::wasm_f32_ceil(Isolate* isolate) {
1183 return ExternalReference(
1184 Redirect(isolate, FUNCTION_ADDR(wasm::f32_ceil_wrapper)));
1185}
1186ExternalReference ExternalReference::wasm_f32_nearest_int(Isolate* isolate) {
1187 return ExternalReference(
1188 Redirect(isolate, FUNCTION_ADDR(wasm::f32_nearest_int_wrapper)));
1189}
1190
1191ExternalReference ExternalReference::wasm_f64_trunc(Isolate* isolate) {
1192 return ExternalReference(
1193 Redirect(isolate, FUNCTION_ADDR(wasm::f64_trunc_wrapper)));
1194}
1195
1196ExternalReference ExternalReference::wasm_f64_floor(Isolate* isolate) {
1197 return ExternalReference(
1198 Redirect(isolate, FUNCTION_ADDR(wasm::f64_floor_wrapper)));
1199}
1200
1201ExternalReference ExternalReference::wasm_f64_ceil(Isolate* isolate) {
1202 return ExternalReference(
1203 Redirect(isolate, FUNCTION_ADDR(wasm::f64_ceil_wrapper)));
1204}
1205
1206ExternalReference ExternalReference::wasm_f64_nearest_int(Isolate* isolate) {
1207 return ExternalReference(
1208 Redirect(isolate, FUNCTION_ADDR(wasm::f64_nearest_int_wrapper)));
1209}
1210
1211ExternalReference ExternalReference::wasm_int64_to_float32(Isolate* isolate) {
1212 return ExternalReference(
1213 Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float32_wrapper)));
1214}
1215
1216ExternalReference ExternalReference::wasm_uint64_to_float32(Isolate* isolate) {
1217 return ExternalReference(
1218 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float32_wrapper)));
1219}
1220
1221ExternalReference ExternalReference::wasm_int64_to_float64(Isolate* isolate) {
1222 return ExternalReference(
1223 Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float64_wrapper)));
1224}
1225
1226ExternalReference ExternalReference::wasm_uint64_to_float64(Isolate* isolate) {
1227 return ExternalReference(
1228 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float64_wrapper)));
1229}
1230
1231ExternalReference ExternalReference::wasm_float32_to_int64(Isolate* isolate) {
1232 return ExternalReference(
1233 Redirect(isolate, FUNCTION_ADDR(wasm::float32_to_int64_wrapper)));
1234}
1235
1236ExternalReference ExternalReference::wasm_float32_to_uint64(Isolate* isolate) {
1237 return ExternalReference(
1238 Redirect(isolate, FUNCTION_ADDR(wasm::float32_to_uint64_wrapper)));
1239}
1240
1241ExternalReference ExternalReference::wasm_float64_to_int64(Isolate* isolate) {
1242 return ExternalReference(
1243 Redirect(isolate, FUNCTION_ADDR(wasm::float64_to_int64_wrapper)));
1244}
1245
1246ExternalReference ExternalReference::wasm_float64_to_uint64(Isolate* isolate) {
1247 return ExternalReference(
1248 Redirect(isolate, FUNCTION_ADDR(wasm::float64_to_uint64_wrapper)));
1249}
1250
1251ExternalReference ExternalReference::wasm_int64_div(Isolate* isolate) {
1252 return ExternalReference(
1253 Redirect(isolate, FUNCTION_ADDR(wasm::int64_div_wrapper)));
1254}
1255
1256ExternalReference ExternalReference::wasm_int64_mod(Isolate* isolate) {
1257 return ExternalReference(
1258 Redirect(isolate, FUNCTION_ADDR(wasm::int64_mod_wrapper)));
1259}
1260
1261ExternalReference ExternalReference::wasm_uint64_div(Isolate* isolate) {
1262 return ExternalReference(
1263 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_div_wrapper)));
1264}
1265
1266ExternalReference ExternalReference::wasm_uint64_mod(Isolate* isolate) {
1267 return ExternalReference(
1268 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_mod_wrapper)));
1269}
1270
Ben Murdochc5610432016-08-08 18:44:38 +01001271ExternalReference ExternalReference::wasm_word32_ctz(Isolate* isolate) {
1272 return ExternalReference(
1273 Redirect(isolate, FUNCTION_ADDR(wasm::word32_ctz_wrapper)));
1274}
1275
1276ExternalReference ExternalReference::wasm_word64_ctz(Isolate* isolate) {
1277 return ExternalReference(
1278 Redirect(isolate, FUNCTION_ADDR(wasm::word64_ctz_wrapper)));
1279}
1280
1281ExternalReference ExternalReference::wasm_word32_popcnt(Isolate* isolate) {
1282 return ExternalReference(
1283 Redirect(isolate, FUNCTION_ADDR(wasm::word32_popcnt_wrapper)));
1284}
1285
1286ExternalReference ExternalReference::wasm_word64_popcnt(Isolate* isolate) {
1287 return ExternalReference(
1288 Redirect(isolate, FUNCTION_ADDR(wasm::word64_popcnt_wrapper)));
1289}
1290
Ben Murdochda12d292016-06-02 14:46:10 +01001291static void f64_acos_wrapper(double* param) { *param = std::acos(*param); }
1292
1293ExternalReference ExternalReference::f64_acos_wrapper_function(
1294 Isolate* isolate) {
1295 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_acos_wrapper)));
1296}
1297
1298static void f64_asin_wrapper(double* param) { *param = std::asin(*param); }
1299
1300ExternalReference ExternalReference::f64_asin_wrapper_function(
1301 Isolate* isolate) {
1302 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_asin_wrapper)));
1303}
1304
1305static void f64_atan_wrapper(double* param) { *param = std::atan(*param); }
1306
1307ExternalReference ExternalReference::f64_atan_wrapper_function(
1308 Isolate* isolate) {
1309 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_atan_wrapper)));
1310}
1311
1312static void f64_cos_wrapper(double* param) { *param = std::cos(*param); }
1313
1314ExternalReference ExternalReference::f64_cos_wrapper_function(
1315 Isolate* isolate) {
1316 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_cos_wrapper)));
1317}
1318
1319static void f64_sin_wrapper(double* param) { *param = std::sin(*param); }
1320
1321ExternalReference ExternalReference::f64_sin_wrapper_function(
1322 Isolate* isolate) {
1323 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_sin_wrapper)));
1324}
1325
1326static void f64_tan_wrapper(double* param) { *param = std::tan(*param); }
1327
1328ExternalReference ExternalReference::f64_tan_wrapper_function(
1329 Isolate* isolate) {
1330 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper)));
1331}
1332
1333static void f64_exp_wrapper(double* param) { *param = std::exp(*param); }
1334
1335ExternalReference ExternalReference::f64_exp_wrapper_function(
1336 Isolate* isolate) {
1337 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper)));
1338}
1339
1340static void f64_log_wrapper(double* param) { *param = std::log(*param); }
1341
1342ExternalReference ExternalReference::f64_log_wrapper_function(
1343 Isolate* isolate) {
1344 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_log_wrapper)));
1345}
1346
1347static void f64_pow_wrapper(double* param0, double* param1) {
1348 *param0 = power_double_double(*param0, *param1);
1349}
1350
1351ExternalReference ExternalReference::f64_pow_wrapper_function(
1352 Isolate* isolate) {
1353 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_pow_wrapper)));
1354}
1355
1356static void f64_atan2_wrapper(double* param0, double* param1) {
1357 double x = *param0;
1358 double y = *param1;
1359 // TODO(bradnelson): Find a good place to put this to share
1360 // with the same code in src/runtime/runtime-math.cc
1361 static const double kPiDividedBy4 = 0.78539816339744830962;
1362 if (std::isinf(x) && std::isinf(y)) {
1363 // Make sure that the result in case of two infinite arguments
1364 // is a multiple of Pi / 4. The sign of the result is determined
1365 // by the first argument (x) and the sign of the second argument
1366 // determines the multiplier: one or three.
1367 int multiplier = (x < 0) ? -1 : 1;
1368 if (y < 0) multiplier *= 3;
1369 *param0 = multiplier * kPiDividedBy4;
1370 } else {
1371 *param0 = std::atan2(x, y);
1372 }
1373}
1374
1375ExternalReference ExternalReference::f64_atan2_wrapper_function(
1376 Isolate* isolate) {
1377 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_atan2_wrapper)));
1378}
1379
1380static void f64_mod_wrapper(double* param0, double* param1) {
1381 *param0 = modulo(*param0, *param1);
1382}
1383
1384ExternalReference ExternalReference::f64_mod_wrapper_function(
1385 Isolate* isolate) {
1386 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_mod_wrapper)));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001387}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001388
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001389ExternalReference ExternalReference::log_enter_external_function(
1390 Isolate* isolate) {
1391 return ExternalReference(
1392 Redirect(isolate, FUNCTION_ADDR(Logger::EnterExternal)));
1393}
1394
1395
1396ExternalReference ExternalReference::log_leave_external_function(
1397 Isolate* isolate) {
1398 return ExternalReference(
1399 Redirect(isolate, FUNCTION_ADDR(Logger::LeaveExternal)));
1400}
1401
1402
Steve Block44f0eee2011-05-26 01:26:41 +01001403ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
1404 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001405}
1406
1407
Steve Block44f0eee2011-05-26 01:26:41 +01001408ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
1409 Isolate* isolate) {
1410 return ExternalReference(
1411 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001412}
1413
1414
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001415ExternalReference ExternalReference::roots_array_start(Isolate* isolate) {
1416 return ExternalReference(isolate->heap()->roots_array_start());
Steve Blocka7e24c12009-10-30 11:49:00 +00001417}
1418
1419
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001420ExternalReference ExternalReference::allocation_sites_list_address(
1421 Isolate* isolate) {
1422 return ExternalReference(isolate->heap()->allocation_sites_list_address());
1423}
1424
1425
Steve Block44f0eee2011-05-26 01:26:41 +01001426ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
1427 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +00001428}
1429
1430
Steve Block44f0eee2011-05-26 01:26:41 +01001431ExternalReference ExternalReference::address_of_real_stack_limit(
1432 Isolate* isolate) {
1433 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +00001434}
1435
1436
Steve Block44f0eee2011-05-26 01:26:41 +01001437ExternalReference ExternalReference::address_of_regexp_stack_limit(
1438 Isolate* isolate) {
1439 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001440}
1441
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001442ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001443 return ExternalReference(isolate->heap()->store_buffer_top_address());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001444}
1445
1446
Steve Block44f0eee2011-05-26 01:26:41 +01001447ExternalReference ExternalReference::new_space_allocation_top_address(
1448 Isolate* isolate) {
1449 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +00001450}
1451
1452
Steve Block44f0eee2011-05-26 01:26:41 +01001453ExternalReference ExternalReference::new_space_allocation_limit_address(
1454 Isolate* isolate) {
1455 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +00001456}
1457
Steve Blockd0582a62009-12-15 09:54:21 +00001458
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001459ExternalReference ExternalReference::old_space_allocation_top_address(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001460 Isolate* isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001461 return ExternalReference(isolate->heap()->OldSpaceAllocationTopAddress());
Steve Blockd0582a62009-12-15 09:54:21 +00001462}
1463
1464
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001465ExternalReference ExternalReference::old_space_allocation_limit_address(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001466 Isolate* isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001467 return ExternalReference(isolate->heap()->OldSpaceAllocationLimitAddress());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001468}
1469
1470
1471ExternalReference ExternalReference::handle_scope_level_address(
1472 Isolate* isolate) {
1473 return ExternalReference(HandleScope::current_level_address(isolate));
1474}
1475
1476
1477ExternalReference ExternalReference::handle_scope_next_address(
1478 Isolate* isolate) {
1479 return ExternalReference(HandleScope::current_next_address(isolate));
1480}
1481
1482
1483ExternalReference ExternalReference::handle_scope_limit_address(
1484 Isolate* isolate) {
1485 return ExternalReference(HandleScope::current_limit_address(isolate));
Steve Blockd0582a62009-12-15 09:54:21 +00001486}
1487
1488
Steve Block44f0eee2011-05-26 01:26:41 +01001489ExternalReference ExternalReference::scheduled_exception_address(
1490 Isolate* isolate) {
1491 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +00001492}
1493
1494
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001495ExternalReference ExternalReference::address_of_pending_message_obj(
1496 Isolate* isolate) {
1497 return ExternalReference(isolate->pending_message_obj_address());
1498}
1499
1500
Ben Murdochb0fe1622011-05-05 13:52:32 +01001501ExternalReference ExternalReference::address_of_min_int() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001502 return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001503}
1504
1505
1506ExternalReference ExternalReference::address_of_one_half() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001507 return ExternalReference(reinterpret_cast<void*>(&double_constants.one_half));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001508}
1509
1510
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001511ExternalReference ExternalReference::address_of_minus_one_half() {
1512 return ExternalReference(
1513 reinterpret_cast<void*>(&double_constants.minus_one_half));
Ben Murdoch257744e2011-11-30 15:57:28 +00001514}
1515
1516
Ben Murdochb0fe1622011-05-05 13:52:32 +01001517ExternalReference ExternalReference::address_of_negative_infinity() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001518 return ExternalReference(
1519 reinterpret_cast<void*>(&double_constants.negative_infinity));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001520}
1521
1522
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001523ExternalReference ExternalReference::address_of_the_hole_nan() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001524 return ExternalReference(
1525 reinterpret_cast<void*>(&double_constants.the_hole_nan));
1526}
1527
1528
1529ExternalReference ExternalReference::address_of_uint32_bias() {
1530 return ExternalReference(
1531 reinterpret_cast<void*>(&double_constants.uint32_bias));
1532}
1533
1534
1535ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) {
1536 return ExternalReference(isolate->cpu_profiler()->is_profiling_address());
1537}
1538
1539
1540ExternalReference ExternalReference::invoke_function_callback(
1541 Isolate* isolate) {
1542 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
1543 ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
1544 ApiFunction thunk_fun(thunk_address);
1545 return ExternalReference(&thunk_fun, thunk_type, isolate);
1546}
1547
1548
1549ExternalReference ExternalReference::invoke_accessor_getter_callback(
1550 Isolate* isolate) {
1551 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
1552 ExternalReference::Type thunk_type =
1553 ExternalReference::PROFILING_GETTER_CALL;
1554 ApiFunction thunk_fun(thunk_address);
1555 return ExternalReference(&thunk_fun, thunk_type, isolate);
Steve Block44f0eee2011-05-26 01:26:41 +01001556}
1557
1558
Steve Block6ded16b2010-05-10 14:33:55 +01001559#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001560
Steve Block44f0eee2011-05-26 01:26:41 +01001561ExternalReference ExternalReference::re_check_stack_guard_state(
1562 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001563 Address function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001564#if V8_TARGET_ARCH_X64
Steve Blocka7e24c12009-10-30 11:49:00 +00001565 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
1566#elif V8_TARGET_ARCH_IA32
1567 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001568#elif V8_TARGET_ARCH_ARM64
1569 function = FUNCTION_ADDR(RegExpMacroAssemblerARM64::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +00001570#elif V8_TARGET_ARCH_ARM
1571 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001572#elif V8_TARGET_ARCH_PPC
1573 function = FUNCTION_ADDR(RegExpMacroAssemblerPPC::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +01001574#elif V8_TARGET_ARCH_MIPS
1575 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001576#elif V8_TARGET_ARCH_MIPS64
1577 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Ben Murdochda12d292016-06-02 14:46:10 +01001578#elif V8_TARGET_ARCH_S390
1579 function = FUNCTION_ADDR(RegExpMacroAssemblerS390::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001580#elif V8_TARGET_ARCH_X87
1581 function = FUNCTION_ADDR(RegExpMacroAssemblerX87::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +00001582#else
Leon Clarke4515c472010-02-03 11:58:03 +00001583 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +00001584#endif
Steve Block44f0eee2011-05-26 01:26:41 +01001585 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +00001586}
1587
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001588
Steve Block44f0eee2011-05-26 01:26:41 +01001589ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001590 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001591 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001592}
1593
Steve Block44f0eee2011-05-26 01:26:41 +01001594ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
1595 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001596 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +01001597 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +00001598 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
1599}
1600
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001601
Leon Clarkee46be812010-01-19 14:06:41 +00001602ExternalReference ExternalReference::re_word_character_map() {
1603 return ExternalReference(
1604 NativeRegExpMacroAssembler::word_character_map_address());
1605}
1606
Steve Block44f0eee2011-05-26 01:26:41 +01001607ExternalReference ExternalReference::address_of_static_offsets_vector(
1608 Isolate* isolate) {
1609 return ExternalReference(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001610 reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector()));
Leon Clarkee46be812010-01-19 14:06:41 +00001611}
1612
Steve Block44f0eee2011-05-26 01:26:41 +01001613ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
1614 Isolate* isolate) {
1615 return ExternalReference(
1616 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +00001617}
1618
Steve Block44f0eee2011-05-26 01:26:41 +01001619ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
1620 Isolate* isolate) {
1621 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +00001622}
1623
Steve Block6ded16b2010-05-10 14:33:55 +01001624#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001625
1626
Steve Block44f0eee2011-05-26 01:26:41 +01001627ExternalReference ExternalReference::math_log_double_function(
1628 Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001629 typedef double (*d2d)(double x);
Steve Block44f0eee2011-05-26 01:26:41 +01001630 return ExternalReference(Redirect(isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001631 FUNCTION_ADDR(static_cast<d2d>(std::log)),
Ben Murdoch257744e2011-11-30 15:57:28 +00001632 BUILTIN_FP_CALL));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001633}
1634
1635
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001636ExternalReference ExternalReference::math_exp_constants(int constant_index) {
1637 DCHECK(math_exp_data_initialized);
1638 return ExternalReference(
1639 reinterpret_cast<void*>(math_exp_constants_array + constant_index));
1640}
1641
1642
1643ExternalReference ExternalReference::math_exp_log_table() {
1644 DCHECK(math_exp_data_initialized);
1645 return ExternalReference(reinterpret_cast<void*>(math_exp_log_table_array));
1646}
1647
1648
1649ExternalReference ExternalReference::page_flags(Page* page) {
1650 return ExternalReference(reinterpret_cast<Address>(page) +
1651 MemoryChunk::kFlagsOffset);
1652}
1653
1654
1655ExternalReference ExternalReference::ForDeoptEntry(Address entry) {
1656 return ExternalReference(entry);
1657}
1658
1659
1660ExternalReference ExternalReference::cpu_features() {
1661 DCHECK(CpuFeatures::initialized_);
1662 return ExternalReference(&CpuFeatures::supported_);
1663}
1664
Ben Murdochda12d292016-06-02 14:46:10 +01001665ExternalReference ExternalReference::is_tail_call_elimination_enabled_address(
1666 Isolate* isolate) {
1667 return ExternalReference(isolate->is_tail_call_elimination_enabled_address());
1668}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001669
1670ExternalReference ExternalReference::debug_is_active_address(
1671 Isolate* isolate) {
1672 return ExternalReference(isolate->debug()->is_active_address());
1673}
1674
1675
1676ExternalReference ExternalReference::debug_after_break_target_address(
1677 Isolate* isolate) {
1678 return ExternalReference(isolate->debug()->after_break_target_address());
1679}
1680
1681
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001682ExternalReference ExternalReference::virtual_handler_register(
1683 Isolate* isolate) {
1684 return ExternalReference(isolate->virtual_handler_register_address());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001685}
1686
1687
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001688ExternalReference ExternalReference::virtual_slot_register(Isolate* isolate) {
1689 return ExternalReference(isolate->virtual_slot_register_address());
1690}
1691
1692
1693ExternalReference ExternalReference::runtime_function_table_address(
1694 Isolate* isolate) {
1695 return ExternalReference(
1696 const_cast<Runtime::Function*>(Runtime::RuntimeFunctionTable(isolate)));
1697}
1698
1699
1700double power_helper(Isolate* isolate, double x, double y) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001701 int y_int = static_cast<int>(y);
1702 if (y == y_int) {
1703 return power_double_int(x, y_int); // Returns 1 if exponent is 0.
1704 }
1705 if (y == 0.5) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001706 lazily_initialize_fast_sqrt(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001707 return (std::isinf(x)) ? V8_INFINITY
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001708 : fast_sqrt(x + 0.0, isolate); // Convert -0 to +0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001709 }
1710 if (y == -0.5) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001711 lazily_initialize_fast_sqrt(isolate);
1712 return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0,
1713 isolate); // Convert -0 to +0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001714 }
1715 return power_double_double(x, y);
1716}
1717
1718
Ben Murdochb0fe1622011-05-05 13:52:32 +01001719// Helper function to compute x^y, where y is known to be an
1720// integer. Uses binary decomposition to limit the number of
1721// multiplications; see the discussion in "Hacker's Delight" by Henry
1722// S. Warren, Jr., figure 11-6, page 213.
1723double power_double_int(double x, int y) {
1724 double m = (y < 0) ? 1 / x : x;
1725 unsigned n = (y < 0) ? -y : y;
1726 double p = 1;
1727 while (n != 0) {
1728 if ((n & 1) != 0) p *= m;
1729 m *= m;
1730 if ((n & 2) != 0) p *= m;
1731 m *= m;
1732 n >>= 2;
1733 }
1734 return p;
1735}
1736
1737
1738double power_double_double(double x, double y) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001739 // The checks for special cases can be dropped in ia32 because it has already
1740 // been done in generated code before bailing out here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001741 if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001742 return std::numeric_limits<double>::quiet_NaN();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001743 }
Ben Murdochda12d292016-06-02 14:46:10 +01001744 return Pow(x, y);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001745}
1746
1747
Steve Block44f0eee2011-05-26 01:26:41 +01001748ExternalReference ExternalReference::power_double_double_function(
1749 Isolate* isolate) {
1750 return ExternalReference(Redirect(isolate,
1751 FUNCTION_ADDR(power_double_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001752 BUILTIN_FP_FP_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001753}
1754
1755
Steve Block44f0eee2011-05-26 01:26:41 +01001756ExternalReference ExternalReference::power_double_int_function(
1757 Isolate* isolate) {
1758 return ExternalReference(Redirect(isolate,
1759 FUNCTION_ADDR(power_double_int),
Ben Murdoch257744e2011-11-30 15:57:28 +00001760 BUILTIN_FP_INT_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001761}
1762
1763
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001764ExternalReference ExternalReference::mod_two_doubles_operation(
1765 Isolate* isolate) {
Steve Block44f0eee2011-05-26 01:26:41 +01001766 return ExternalReference(Redirect(isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001767 FUNCTION_ADDR(modulo),
Ben Murdoch257744e2011-11-30 15:57:28 +00001768 BUILTIN_FP_FP_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001769}
1770
1771
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001772ExternalReference ExternalReference::debug_step_in_enabled_address(
1773 Isolate* isolate) {
1774 return ExternalReference(isolate->debug()->step_in_enabled_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001775}
1776
1777
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001778ExternalReference ExternalReference::fixed_typed_array_base_data_offset() {
1779 return ExternalReference(reinterpret_cast<void*>(
1780 FixedTypedArrayBase::kDataOffset - kHeapObjectTag));
Steve Blocka7e24c12009-10-30 11:49:00 +00001781}
Steve Blocka7e24c12009-10-30 11:49:00 +00001782
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001783
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001784bool operator==(ExternalReference lhs, ExternalReference rhs) {
1785 return lhs.address() == rhs.address();
1786}
1787
1788
1789bool operator!=(ExternalReference lhs, ExternalReference rhs) {
1790 return !(lhs == rhs);
1791}
1792
1793
1794size_t hash_value(ExternalReference reference) {
1795 return base::hash<Address>()(reference.address());
1796}
1797
1798
1799std::ostream& operator<<(std::ostream& os, ExternalReference reference) {
1800 os << static_cast<const void*>(reference.address());
1801 const Runtime::Function* fn = Runtime::FunctionForEntry(reference.address());
1802 if (fn) os << "<" << fn->name << ".entry>";
1803 return os;
1804}
1805
Ben Murdochda12d292016-06-02 14:46:10 +01001806void AssemblerPositionsRecorder::RecordPosition(int pos) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001807 DCHECK(pos != RelocInfo::kNoPosition);
1808 DCHECK(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001809 state_.current_position = pos;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001810 LOG_CODE_EVENT(assembler_->isolate(),
1811 CodeLinePosInfoAddPositionEvent(jit_handler_data_,
1812 assembler_->pc_offset(),
1813 pos));
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001814}
1815
Ben Murdochda12d292016-06-02 14:46:10 +01001816void AssemblerPositionsRecorder::RecordStatementPosition(int pos) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001817 DCHECK(pos != RelocInfo::kNoPosition);
1818 DCHECK(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001819 state_.current_statement_position = pos;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001820 LOG_CODE_EVENT(assembler_->isolate(),
1821 CodeLinePosInfoAddStatementPositionEvent(
1822 jit_handler_data_,
1823 assembler_->pc_offset(),
1824 pos));
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001825}
1826
Ben Murdochda12d292016-06-02 14:46:10 +01001827bool AssemblerPositionsRecorder::WriteRecordedPositions() {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001828 bool written = false;
1829
1830 // Write the statement position if it is different from what was written last
1831 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001832 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001833 EnsureSpace ensure_space(assembler_);
1834 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001835 state_.current_statement_position);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001836 state_.written_position = state_.current_statement_position;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001837 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001838 written = true;
1839 }
1840
1841 // Write the position if it is different from what was written last time and
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001842 // also different from the statement position that was just written.
1843 if (state_.current_position != state_.written_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001844 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001845 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1846 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001847 written = true;
1848 }
1849
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001850 // Return whether something was written.
1851 return written;
1852}
1853
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001854
1855ConstantPoolBuilder::ConstantPoolBuilder(int ptr_reach_bits,
1856 int double_reach_bits) {
1857 info_[ConstantPoolEntry::INTPTR].entries.reserve(64);
1858 info_[ConstantPoolEntry::INTPTR].regular_reach_bits = ptr_reach_bits;
1859 info_[ConstantPoolEntry::DOUBLE].regular_reach_bits = double_reach_bits;
1860}
1861
1862
1863ConstantPoolEntry::Access ConstantPoolBuilder::NextAccess(
1864 ConstantPoolEntry::Type type) const {
1865 const PerTypeEntryInfo& info = info_[type];
1866
1867 if (info.overflow()) return ConstantPoolEntry::OVERFLOWED;
1868
1869 int dbl_count = info_[ConstantPoolEntry::DOUBLE].regular_count;
1870 int dbl_offset = dbl_count * kDoubleSize;
1871 int ptr_count = info_[ConstantPoolEntry::INTPTR].regular_count;
1872 int ptr_offset = ptr_count * kPointerSize + dbl_offset;
1873
1874 if (type == ConstantPoolEntry::DOUBLE) {
1875 // Double overflow detection must take into account the reach for both types
1876 int ptr_reach_bits = info_[ConstantPoolEntry::INTPTR].regular_reach_bits;
1877 if (!is_uintn(dbl_offset, info.regular_reach_bits) ||
1878 (ptr_count > 0 &&
1879 !is_uintn(ptr_offset + kDoubleSize - kPointerSize, ptr_reach_bits))) {
1880 return ConstantPoolEntry::OVERFLOWED;
1881 }
1882 } else {
1883 DCHECK(type == ConstantPoolEntry::INTPTR);
1884 if (!is_uintn(ptr_offset, info.regular_reach_bits)) {
1885 return ConstantPoolEntry::OVERFLOWED;
1886 }
1887 }
1888
1889 return ConstantPoolEntry::REGULAR;
1890}
1891
1892
1893ConstantPoolEntry::Access ConstantPoolBuilder::AddEntry(
1894 ConstantPoolEntry& entry, ConstantPoolEntry::Type type) {
1895 DCHECK(!emitted_label_.is_bound());
1896 PerTypeEntryInfo& info = info_[type];
1897 const int entry_size = ConstantPoolEntry::size(type);
1898 bool merged = false;
1899
1900 if (entry.sharing_ok()) {
1901 // Try to merge entries
1902 std::vector<ConstantPoolEntry>::iterator it = info.shared_entries.begin();
1903 int end = static_cast<int>(info.shared_entries.size());
1904 for (int i = 0; i < end; i++, it++) {
1905 if ((entry_size == kPointerSize) ? entry.value() == it->value()
1906 : entry.value64() == it->value64()) {
1907 // Merge with found entry.
1908 entry.set_merged_index(i);
1909 merged = true;
1910 break;
1911 }
1912 }
1913 }
1914
1915 // By definition, merged entries have regular access.
1916 DCHECK(!merged || entry.merged_index() < info.regular_count);
1917 ConstantPoolEntry::Access access =
1918 (merged ? ConstantPoolEntry::REGULAR : NextAccess(type));
1919
1920 // Enforce an upper bound on search time by limiting the search to
1921 // unique sharable entries which fit in the regular section.
1922 if (entry.sharing_ok() && !merged && access == ConstantPoolEntry::REGULAR) {
1923 info.shared_entries.push_back(entry);
1924 } else {
1925 info.entries.push_back(entry);
1926 }
1927
1928 // We're done if we found a match or have already triggered the
1929 // overflow state.
1930 if (merged || info.overflow()) return access;
1931
1932 if (access == ConstantPoolEntry::REGULAR) {
1933 info.regular_count++;
1934 } else {
1935 info.overflow_start = static_cast<int>(info.entries.size()) - 1;
1936 }
1937
1938 return access;
1939}
1940
1941
1942void ConstantPoolBuilder::EmitSharedEntries(Assembler* assm,
1943 ConstantPoolEntry::Type type) {
1944 PerTypeEntryInfo& info = info_[type];
1945 std::vector<ConstantPoolEntry>& shared_entries = info.shared_entries;
1946 const int entry_size = ConstantPoolEntry::size(type);
1947 int base = emitted_label_.pos();
1948 DCHECK(base > 0);
1949 int shared_end = static_cast<int>(shared_entries.size());
1950 std::vector<ConstantPoolEntry>::iterator shared_it = shared_entries.begin();
1951 for (int i = 0; i < shared_end; i++, shared_it++) {
1952 int offset = assm->pc_offset() - base;
1953 shared_it->set_offset(offset); // Save offset for merged entries.
1954 if (entry_size == kPointerSize) {
1955 assm->dp(shared_it->value());
1956 } else {
1957 assm->dq(shared_it->value64());
1958 }
1959 DCHECK(is_uintn(offset, info.regular_reach_bits));
1960
1961 // Patch load sequence with correct offset.
1962 assm->PatchConstantPoolAccessInstruction(shared_it->position(), offset,
1963 ConstantPoolEntry::REGULAR, type);
1964 }
1965}
1966
1967
1968void ConstantPoolBuilder::EmitGroup(Assembler* assm,
1969 ConstantPoolEntry::Access access,
1970 ConstantPoolEntry::Type type) {
1971 PerTypeEntryInfo& info = info_[type];
1972 const bool overflow = info.overflow();
1973 std::vector<ConstantPoolEntry>& entries = info.entries;
1974 std::vector<ConstantPoolEntry>& shared_entries = info.shared_entries;
1975 const int entry_size = ConstantPoolEntry::size(type);
1976 int base = emitted_label_.pos();
1977 DCHECK(base > 0);
1978 int begin;
1979 int end;
1980
1981 if (access == ConstantPoolEntry::REGULAR) {
1982 // Emit any shared entries first
1983 EmitSharedEntries(assm, type);
1984 }
1985
1986 if (access == ConstantPoolEntry::REGULAR) {
1987 begin = 0;
1988 end = overflow ? info.overflow_start : static_cast<int>(entries.size());
1989 } else {
1990 DCHECK(access == ConstantPoolEntry::OVERFLOWED);
1991 if (!overflow) return;
1992 begin = info.overflow_start;
1993 end = static_cast<int>(entries.size());
1994 }
1995
1996 std::vector<ConstantPoolEntry>::iterator it = entries.begin();
1997 if (begin > 0) std::advance(it, begin);
1998 for (int i = begin; i < end; i++, it++) {
1999 // Update constant pool if necessary and get the entry's offset.
2000 int offset;
2001 ConstantPoolEntry::Access entry_access;
2002 if (!it->is_merged()) {
2003 // Emit new entry
2004 offset = assm->pc_offset() - base;
2005 entry_access = access;
2006 if (entry_size == kPointerSize) {
2007 assm->dp(it->value());
2008 } else {
2009 assm->dq(it->value64());
2010 }
2011 } else {
2012 // Retrieve offset from shared entry.
2013 offset = shared_entries[it->merged_index()].offset();
2014 entry_access = ConstantPoolEntry::REGULAR;
2015 }
2016
2017 DCHECK(entry_access == ConstantPoolEntry::OVERFLOWED ||
2018 is_uintn(offset, info.regular_reach_bits));
2019
2020 // Patch load sequence with correct offset.
2021 assm->PatchConstantPoolAccessInstruction(it->position(), offset,
2022 entry_access, type);
2023 }
2024}
2025
2026
2027// Emit and return position of pool. Zero implies no constant pool.
2028int ConstantPoolBuilder::Emit(Assembler* assm) {
2029 bool emitted = emitted_label_.is_bound();
2030 bool empty = IsEmpty();
2031
2032 if (!emitted) {
2033 // Mark start of constant pool. Align if necessary.
2034 if (!empty) assm->DataAlign(kDoubleSize);
2035 assm->bind(&emitted_label_);
2036 if (!empty) {
2037 // Emit in groups based on access and type.
2038 // Emit doubles first for alignment purposes.
2039 EmitGroup(assm, ConstantPoolEntry::REGULAR, ConstantPoolEntry::DOUBLE);
2040 EmitGroup(assm, ConstantPoolEntry::REGULAR, ConstantPoolEntry::INTPTR);
2041 if (info_[ConstantPoolEntry::DOUBLE].overflow()) {
2042 assm->DataAlign(kDoubleSize);
2043 EmitGroup(assm, ConstantPoolEntry::OVERFLOWED,
2044 ConstantPoolEntry::DOUBLE);
2045 }
2046 if (info_[ConstantPoolEntry::INTPTR].overflow()) {
2047 EmitGroup(assm, ConstantPoolEntry::OVERFLOWED,
2048 ConstantPoolEntry::INTPTR);
2049 }
2050 }
2051 }
2052
2053 return !empty ? emitted_label_.pos() : 0;
2054}
2055
2056
2057// Platform specific but identical code for all the platforms.
2058
Ben Murdochc5610432016-08-08 18:44:38 +01002059void Assembler::RecordDeoptReason(const int reason, int raw_position, int id) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002060 if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling()) {
2061 EnsureSpace ensure_space(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002062 RecordRelocInfo(RelocInfo::POSITION, raw_position);
2063 RecordRelocInfo(RelocInfo::DEOPT_REASON, reason);
Ben Murdochc5610432016-08-08 18:44:38 +01002064 RecordRelocInfo(RelocInfo::DEOPT_ID, id);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002065 }
2066}
2067
2068
2069void Assembler::RecordComment(const char* msg) {
2070 if (FLAG_code_comments) {
2071 EnsureSpace ensure_space(this);
2072 RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg));
2073 }
2074}
2075
2076
2077void Assembler::RecordGeneratorContinuation() {
2078 EnsureSpace ensure_space(this);
2079 RecordRelocInfo(RelocInfo::GENERATOR_CONTINUATION);
2080}
2081
2082
2083void Assembler::RecordDebugBreakSlot(RelocInfo::Mode mode) {
2084 EnsureSpace ensure_space(this);
2085 DCHECK(RelocInfo::IsDebugBreakSlot(mode));
2086 RecordRelocInfo(mode);
2087}
2088
2089
2090void Assembler::DataAlign(int m) {
2091 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m));
2092 while ((pc_offset() & (m - 1)) != 0) {
2093 db(0);
2094 }
2095}
2096} // namespace internal
2097} // namespace v8