blob: a912bb60e4cda0b2e392b8f1a0004cd93ef6caf3 [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;
204 if (CpuFeatures::IsSupported(COHERENT_CACHE)) return;
205
206#if defined(USE_SIMULATOR)
207 Simulator::FlushICache(isolate->simulator_i_cache(), start, size);
208#else
209 CpuFeatures::FlushICache(start, size);
210#endif // USE_SIMULATOR
211}
212
213
214void AssemblerBase::Print() {
215 OFStream os(stdout);
216 v8::internal::Disassembler::Decode(isolate(), &os, buffer_, pc_, nullptr);
217}
218
219
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000220// -----------------------------------------------------------------------------
221// Implementation of PredictableCodeSizeScope
222
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000223PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler)
224 : PredictableCodeSizeScope(assembler, -1) {}
225
226
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000227PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler,
228 int expected_size)
229 : assembler_(assembler),
230 expected_size_(expected_size),
231 start_offset_(assembler->pc_offset()),
232 old_value_(assembler->predictable_code_size()) {
233 assembler_->set_predictable_code_size(true);
234}
235
236
237PredictableCodeSizeScope::~PredictableCodeSizeScope() {
238 // TODO(svenpanne) Remove the 'if' when everything works.
239 if (expected_size_ >= 0) {
240 CHECK_EQ(expected_size_, assembler_->pc_offset() - start_offset_);
241 }
242 assembler_->set_predictable_code_size(old_value_);
243}
244
245
246// -----------------------------------------------------------------------------
247// Implementation of CpuFeatureScope
248
249#ifdef DEBUG
250CpuFeatureScope::CpuFeatureScope(AssemblerBase* assembler, CpuFeature f)
251 : assembler_(assembler) {
252 DCHECK(CpuFeatures::IsSupported(f));
253 old_enabled_ = assembler_->enabled_cpu_features();
254 uint64_t mask = static_cast<uint64_t>(1) << f;
255 // TODO(svenpanne) This special case below doesn't belong here!
256#if V8_TARGET_ARCH_ARM
257 // ARMv7 is implied by VFP3.
258 if (f == VFP3) {
259 mask |= static_cast<uint64_t>(1) << ARMv7;
260 }
261#endif
262 assembler_->set_enabled_cpu_features(old_enabled_ | mask);
263}
264
265
266CpuFeatureScope::~CpuFeatureScope() {
267 assembler_->set_enabled_cpu_features(old_enabled_);
268}
269#endif
270
271
272bool CpuFeatures::initialized_ = false;
273unsigned CpuFeatures::supported_ = 0;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100274unsigned CpuFeatures::icache_line_size_ = 0;
275unsigned CpuFeatures::dcache_line_size_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000276
Steve Block053d10c2011-06-13 19:13:29 +0100277// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000278// Implementation of Label
279
280int Label::pos() const {
281 if (pos_ < 0) return -pos_ - 1;
282 if (pos_ > 0) return pos_ - 1;
283 UNREACHABLE();
284 return 0;
285}
286
287
288// -----------------------------------------------------------------------------
289// Implementation of RelocInfoWriter and RelocIterator
290//
Ben Murdoch257744e2011-11-30 15:57:28 +0000291// Relocation information is written backwards in memory, from high addresses
292// towards low addresses, byte by byte. Therefore, in the encodings listed
293// below, the first byte listed it at the highest address, and successive
294// bytes in the record are at progressively lower addresses.
295//
Steve Blocka7e24c12009-10-30 11:49:00 +0000296// Encoding
297//
298// The most common modes are given single-byte encodings. Also, it is
299// easy to identify the type of reloc info and skip unwanted modes in
300// an iteration.
301//
Ben Murdoch257744e2011-11-30 15:57:28 +0000302// The encoding relies on the fact that there are fewer than 14
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000303// different relocation modes using standard non-compact encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000304//
Ben Murdoch257744e2011-11-30 15:57:28 +0000305// The first byte of a relocation record has a tag in its low 2 bits:
306// Here are the record schemes, depending on the low tag and optional higher
307// tags.
Steve Blocka7e24c12009-10-30 11:49:00 +0000308//
Ben Murdoch257744e2011-11-30 15:57:28 +0000309// Low tag:
310// 00: embedded_object: [6-bit pc delta] 00
Steve Blocka7e24c12009-10-30 11:49:00 +0000311//
Ben Murdoch257744e2011-11-30 15:57:28 +0000312// 01: code_target: [6-bit pc delta] 01
Steve Blocka7e24c12009-10-30 11:49:00 +0000313//
Ben Murdoch257744e2011-11-30 15:57:28 +0000314// 10: short_data_record: [6-bit pc delta] 10 followed by
315// [6-bit data delta] [2-bit data type tag]
Steve Blocka7e24c12009-10-30 11:49:00 +0000316//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000317// 11: long_record [6 bit reloc mode] 11
318// followed by pc delta
319// followed by optional data depending on type.
Steve Blocka7e24c12009-10-30 11:49:00 +0000320//
Ben Murdoch257744e2011-11-30 15:57:28 +0000321// 2-bit data type tags, used in short_data_record and data_jump long_record:
322// code_target_with_id: 00
323// position: 01
324// statement_position: 10
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000325// deopt_reason: 11
Steve Blocka7e24c12009-10-30 11:49:00 +0000326//
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000327// If a pc delta exceeds 6 bits, it is split into a remainder that fits into
328// 6 bits and a part that does not. The latter is encoded as a long record
329// with PC_JUMP as pseudo reloc info mode. The former is encoded as part of
330// the following record in the usual way. The long pc jump record has variable
331// length:
332// pc-jump: [PC_JUMP] 11
Ben Murdoch257744e2011-11-30 15:57:28 +0000333// [7 bits data] 0
334// ...
335// [7 bits data] 1
336// (Bits 6..31 of pc delta, with leading zeroes
337// dropped, and last non-zero chunk tagged with 1.)
338
Steve Blocka7e24c12009-10-30 11:49:00 +0000339const int kTagBits = 2;
340const int kTagMask = (1 << kTagBits) - 1;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000341const int kLongTagBits = 6;
342const int kShortDataTypeTagBits = 2;
343const int kShortDataBits = kBitsPerByte - kShortDataTypeTagBits;
Steve Blocka7e24c12009-10-30 11:49:00 +0000344
345const int kEmbeddedObjectTag = 0;
346const int kCodeTargetTag = 1;
Ben Murdoch257744e2011-11-30 15:57:28 +0000347const int kLocatableTag = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000348const int kDefaultTag = 3;
349
Steve Blocka7e24c12009-10-30 11:49:00 +0000350const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
351const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100352const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000353
Steve Blocka7e24c12009-10-30 11:49:00 +0000354const int kChunkBits = 7;
355const int kChunkMask = (1 << kChunkBits) - 1;
356const int kLastChunkTagBits = 1;
357const int kLastChunkTagMask = 1;
358const int kLastChunkTag = 1;
359
Ben Murdoch257744e2011-11-30 15:57:28 +0000360const int kCodeWithIdTag = 0;
361const int kNonstatementPositionTag = 1;
362const int kStatementPositionTag = 2;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000363const int kDeoptReasonTag = 3;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000364
Steve Blocka7e24c12009-10-30 11:49:00 +0000365
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000366uint32_t RelocInfoWriter::WriteLongPCJump(uint32_t pc_delta) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000367 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
368 // Otherwise write a variable length PC jump for the bits that do
369 // not fit in the kSmallPCDeltaBits bits.
370 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000371 WriteMode(RelocInfo::PC_JUMP);
Steve Blocka7e24c12009-10-30 11:49:00 +0000372 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000373 DCHECK(pc_jump > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000374 // Write kChunkBits size chunks of the pc_jump.
375 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
376 byte b = pc_jump & kChunkMask;
377 *--pos_ = b << kLastChunkTagBits;
378 }
379 // Tag the last chunk so it can be identified.
380 *pos_ = *pos_ | kLastChunkTag;
381 // Return the remaining kSmallPCDeltaBits of the pc_delta.
382 return pc_delta & kSmallPCDeltaMask;
383}
384
385
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000386void RelocInfoWriter::WriteShortTaggedPC(uint32_t pc_delta, int tag) {
387 // Write a byte of tagged pc-delta, possibly preceded by an explicit pc-jump.
388 pc_delta = WriteLongPCJump(pc_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000389 *--pos_ = pc_delta << kTagBits | tag;
390}
391
392
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000393void RelocInfoWriter::WriteShortTaggedData(intptr_t data_delta, int tag) {
394 *--pos_ = static_cast<byte>(data_delta << kShortDataTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000395}
396
397
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000398void RelocInfoWriter::WriteMode(RelocInfo::Mode rmode) {
399 STATIC_ASSERT(RelocInfo::NUMBER_OF_MODES <= (1 << kLongTagBits));
400 *--pos_ = static_cast<int>((rmode << kTagBits) | kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000401}
402
403
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000404void RelocInfoWriter::WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000405 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000406 pc_delta = WriteLongPCJump(pc_delta);
407 WriteMode(rmode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000408 *--pos_ = pc_delta;
409}
410
411
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000412void RelocInfoWriter::WriteIntData(int number) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000413 for (int i = 0; i < kIntSize; i++) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000414 *--pos_ = static_cast<byte>(number);
Ben Murdoch257744e2011-11-30 15:57:28 +0000415 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000416 number = number >> kBitsPerByte;
Ben Murdoch257744e2011-11-30 15:57:28 +0000417 }
418}
419
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000420
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000421void RelocInfoWriter::WriteData(intptr_t data_delta) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000422 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000423 *--pos_ = static_cast<byte>(data_delta);
Ben Murdoch257744e2011-11-30 15:57:28 +0000424 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Steve Blocka7e24c12009-10-30 11:49:00 +0000425 data_delta = data_delta >> kBitsPerByte;
426 }
427}
428
429
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000430void RelocInfoWriter::WritePosition(int pc_delta, int pos_delta,
431 RelocInfo::Mode rmode) {
432 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag
433 : kStatementPositionTag;
434 // Check if delta is small enough to fit in a tagged byte.
435 if (is_intn(pos_delta, kShortDataBits)) {
436 WriteShortTaggedPC(pc_delta, kLocatableTag);
437 WriteShortTaggedData(pos_delta, pos_type_tag);
438 } else {
439 // Otherwise, use costly encoding.
440 WriteModeAndPC(pc_delta, rmode);
441 WriteIntData(pos_delta);
442 }
443}
444
445
446void RelocInfoWriter::FlushPosition() {
447 if (!next_position_candidate_flushed_) {
448 WritePosition(next_position_candidate_pc_delta_,
449 next_position_candidate_pos_delta_, RelocInfo::POSITION);
450 next_position_candidate_pos_delta_ = 0;
451 next_position_candidate_pc_delta_ = 0;
452 next_position_candidate_flushed_ = true;
453 }
454}
455
456
Steve Blocka7e24c12009-10-30 11:49:00 +0000457void RelocInfoWriter::Write(const RelocInfo* rinfo) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000458 RelocInfo::Mode rmode = rinfo->rmode();
459 if (rmode != RelocInfo::POSITION) {
460 FlushPosition();
461 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000462#ifdef DEBUG
463 byte* begin_pos = pos_;
464#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000465 DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES);
466 DCHECK(rinfo->pc() - last_pc_ >= 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000467 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000468 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000469
470 // The two most common modes are given small tags, and usually fit in a byte.
471 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000472 WriteShortTaggedPC(pc_delta, kEmbeddedObjectTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000473 } else if (rmode == RelocInfo::CODE_TARGET) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000474 WriteShortTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000475 DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Ben Murdoch257744e2011-11-30 15:57:28 +0000476 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
477 // Use signed delta-encoding for id.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000478 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data());
Ben Murdoch257744e2011-11-30 15:57:28 +0000479 int id_delta = static_cast<int>(rinfo->data()) - last_id_;
480 // Check if delta is small enough to fit in a tagged byte.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000481 if (is_intn(id_delta, kShortDataBits)) {
482 WriteShortTaggedPC(pc_delta, kLocatableTag);
483 WriteShortTaggedData(id_delta, kCodeWithIdTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000484 } else {
485 // Otherwise, use costly encoding.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000486 WriteModeAndPC(pc_delta, rmode);
487 WriteIntData(id_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000488 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000489 last_id_ = static_cast<int>(rinfo->data());
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490 } else if (rmode == RelocInfo::DEOPT_REASON) {
491 DCHECK(rinfo->data() < (1 << kShortDataBits));
492 WriteShortTaggedPC(pc_delta, kLocatableTag);
493 WriteShortTaggedData(rinfo->data(), kDeoptReasonTag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000494 } else if (RelocInfo::IsPosition(rmode)) {
495 // Use signed delta-encoding for position.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000496 DCHECK_EQ(static_cast<int>(rinfo->data()), rinfo->data());
Ben Murdoch257744e2011-11-30 15:57:28 +0000497 int pos_delta = static_cast<int>(rinfo->data()) - last_position_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000498 if (rmode == RelocInfo::STATEMENT_POSITION) {
499 WritePosition(pc_delta, pos_delta, rmode);
Ben Murdoch257744e2011-11-30 15:57:28 +0000500 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000501 DCHECK_EQ(rmode, RelocInfo::POSITION);
502 if (pc_delta != 0 || last_mode_ != RelocInfo::POSITION) {
503 FlushPosition();
504 next_position_candidate_pc_delta_ = pc_delta;
505 next_position_candidate_pos_delta_ = pos_delta;
506 } else {
507 next_position_candidate_pos_delta_ += pos_delta;
508 }
509 next_position_candidate_flushed_ = false;
Ben Murdoch257744e2011-11-30 15:57:28 +0000510 }
511 last_position_ = static_cast<int>(rinfo->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000512 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000513 WriteModeAndPC(pc_delta, rmode);
514 if (RelocInfo::IsComment(rmode)) {
515 WriteData(rinfo->data());
516 } else if (RelocInfo::IsConstPool(rmode) ||
517 RelocInfo::IsVeneerPool(rmode)) {
518 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) ||
708 RelocInfo::IsVeneerPool(rmode)) {
709 if (SetMode(rmode)) {
710 AdvanceReadInt();
711 return;
712 }
713 Advance(kIntSize);
714 } else if (SetMode(static_cast<RelocInfo::Mode>(rmode))) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000715 return;
716 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000717 }
718 }
719 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000720 if (code_age_sequence_ != NULL) {
721 byte* old_code_age_sequence = code_age_sequence_;
722 code_age_sequence_ = NULL;
723 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) {
724 rinfo_.data_ = 0;
725 rinfo_.pc_ = old_code_age_sequence;
726 return;
727 }
728 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000729 done_ = true;
730}
731
732
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000733RelocIterator::RelocIterator(Code* code, int mode_mask)
734 : rinfo_(code->map()->GetIsolate()) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100735 rinfo_.host_ = code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000736 rinfo_.pc_ = code->instruction_start();
737 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100738 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000739 pos_ = code->relocation_start() + code->relocation_size();
740 end_ = code->relocation_start();
741 done_ = false;
742 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000743 last_id_ = 0;
744 last_position_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000745 byte* sequence = code->FindCodeAgeSequence();
746 // We get the isolate from the map, because at serialization time
747 // the code pointer has been cloned and isn't really in heap space.
748 Isolate* isolate = code->map()->GetIsolate();
749 if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) {
750 code_age_sequence_ = sequence;
751 } else {
752 code_age_sequence_ = NULL;
753 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000754 if (mode_mask_ == 0) pos_ = end_;
755 next();
756}
757
758
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000759RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask)
760 : rinfo_(desc.origin->isolate()) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000761 rinfo_.pc_ = desc.buffer;
762 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100763 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000764 pos_ = desc.buffer + desc.buffer_size;
765 end_ = pos_ - desc.reloc_size;
766 done_ = false;
767 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000768 last_id_ = 0;
769 last_position_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000770 code_age_sequence_ = NULL;
Steve Blocka7e24c12009-10-30 11:49:00 +0000771 if (mode_mask_ == 0) pos_ = end_;
772 next();
773}
774
775
776// -----------------------------------------------------------------------------
777// Implementation of RelocInfo
778
Ben Murdoch097c5b22016-05-18 11:27:45 +0100779bool RelocInfo::IsPatchedDebugBreakSlotSequence() {
780 return DebugCodegen::DebugBreakSlotIsPatched(pc_);
781}
Steve Blocka7e24c12009-10-30 11:49:00 +0000782
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000783#ifdef DEBUG
784bool RelocInfo::RequiresRelocation(const CodeDesc& desc) {
785 // Ensure there are no code targets or embedded objects present in the
786 // deoptimization entries, they would require relocation after code
787 // generation.
788 int mode_mask = RelocInfo::kCodeTargetMask |
789 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
790 RelocInfo::ModeMask(RelocInfo::CELL) |
791 RelocInfo::kApplyMask;
792 RelocIterator it(desc, mode_mask);
793 return !it.done();
794}
795#endif
796
797
Steve Blocka7e24c12009-10-30 11:49:00 +0000798#ifdef ENABLE_DISASSEMBLER
799const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
800 switch (rmode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000801 case NONE32:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000802 return "no reloc 32";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000803 case NONE64:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000804 return "no reloc 64";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000805 case EMBEDDED_OBJECT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000806 return "embedded object";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000807 case DEBUGGER_STATEMENT:
808 return "debugger statement";
809 case CODE_TARGET:
Steve Blocka7e24c12009-10-30 11:49:00 +0000810 return "code target";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000811 case CODE_TARGET_WITH_ID:
Ben Murdoch257744e2011-11-30 15:57:28 +0000812 return "code target with id";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000813 case CELL:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000814 return "property cell";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000815 case RUNTIME_ENTRY:
Steve Blocka7e24c12009-10-30 11:49:00 +0000816 return "runtime entry";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000817 case COMMENT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000818 return "comment";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000819 case POSITION:
Steve Blocka7e24c12009-10-30 11:49:00 +0000820 return "position";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000821 case STATEMENT_POSITION:
Steve Blocka7e24c12009-10-30 11:49:00 +0000822 return "statement position";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000823 case EXTERNAL_REFERENCE:
Steve Blocka7e24c12009-10-30 11:49:00 +0000824 return "external reference";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000825 case INTERNAL_REFERENCE:
Steve Blocka7e24c12009-10-30 11:49:00 +0000826 return "internal reference";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000827 case INTERNAL_REFERENCE_ENCODED:
828 return "encoded internal reference";
829 case DEOPT_REASON:
830 return "deopt reason";
831 case CONST_POOL:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000832 return "constant pool";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000833 case VENEER_POOL:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000834 return "veneer pool";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000835 case DEBUG_BREAK_SLOT_AT_POSITION:
836 return "debug break slot at position";
837 case DEBUG_BREAK_SLOT_AT_RETURN:
838 return "debug break slot at return";
839 case DEBUG_BREAK_SLOT_AT_CALL:
840 return "debug break slot at call";
Ben Murdochda12d292016-06-02 14:46:10 +0100841 case DEBUG_BREAK_SLOT_AT_TAIL_CALL:
842 return "debug break slot at tail call";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000843 case CODE_AGE_SEQUENCE:
844 return "code age sequence";
845 case GENERATOR_CONTINUATION:
846 return "generator continuation";
Ben Murdochda12d292016-06-02 14:46:10 +0100847 case WASM_MEMORY_REFERENCE:
848 return "wasm memory reference";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000849 case NUMBER_OF_MODES:
850 case PC_JUMP:
Steve Blocka7e24c12009-10-30 11:49:00 +0000851 UNREACHABLE();
852 return "number_of_modes";
853 }
854 return "unknown relocation type";
855}
856
857
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400858void RelocInfo::Print(Isolate* isolate, std::ostream& os) { // NOLINT
859 os << static_cast<const void*>(pc_) << " " << RelocModeName(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000860 if (IsComment(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000861 os << " (" << reinterpret_cast<char*>(data_) << ")";
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000862 } else if (rmode_ == DEOPT_REASON) {
863 os << " (" << Deoptimizer::GetDeoptReason(
864 static_cast<Deoptimizer::DeoptReason>(data_)) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000865 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000866 os << " (" << Brief(target_object()) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000867 } else if (rmode_ == EXTERNAL_REFERENCE) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000868 ExternalReferenceEncoder ref_encoder(isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000869 os << " ("
870 << ref_encoder.NameOfAddress(isolate, target_external_reference())
871 << ") (" << static_cast<const void*>(target_external_reference())
872 << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000873 } else if (IsCodeTarget(rmode_)) {
874 Code* code = Code::GetCodeFromTargetAddress(target_address());
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400875 os << " (" << Code::Kind2String(code->kind()) << ") ("
876 << static_cast<const void*>(target_address()) << ")";
Ben Murdoch257744e2011-11-30 15:57:28 +0000877 if (rmode_ == CODE_TARGET_WITH_ID) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000878 os << " (id=" << static_cast<int>(data_) << ")";
Ben Murdoch257744e2011-11-30 15:57:28 +0000879 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000880 } else if (IsPosition(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000881 os << " (" << data() << ")";
882 } else if (IsRuntimeEntry(rmode_) &&
883 isolate->deoptimizer_data() != NULL) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100884 // Depotimization bailouts are stored as runtime entries.
885 int id = Deoptimizer::GetDeoptimizationId(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000886 isolate, target_address(), Deoptimizer::EAGER);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100887 if (id != Deoptimizer::kNotDeoptimizationEntry) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000888 os << " (deoptimization bailout " << id << ")";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100889 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000890 } else if (IsConstPool(rmode_)) {
891 os << " (size " << static_cast<int>(data_) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000892 }
893
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000894 os << "\n";
Steve Blocka7e24c12009-10-30 11:49:00 +0000895}
896#endif // ENABLE_DISASSEMBLER
897
898
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000899#ifdef VERIFY_HEAP
900void RelocInfo::Verify(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000901 switch (rmode_) {
902 case EMBEDDED_OBJECT:
903 Object::VerifyPointer(target_object());
904 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000905 case CELL:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100906 Object::VerifyPointer(target_cell());
907 break;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000908 case DEBUGGER_STATEMENT:
Ben Murdoch257744e2011-11-30 15:57:28 +0000909 case CODE_TARGET_WITH_ID:
Steve Blocka7e24c12009-10-30 11:49:00 +0000910 case CODE_TARGET: {
911 // convert inline target address to code object
912 Address addr = target_address();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000913 CHECK(addr != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000914 // Check that we can find the right code object.
915 Code* code = Code::GetCodeFromTargetAddress(addr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000916 Object* found = isolate->FindCodeObject(addr);
917 CHECK(found->IsCode());
918 CHECK(code->address() == HeapObject::cast(found)->address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000919 break;
920 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000921 case INTERNAL_REFERENCE:
922 case INTERNAL_REFERENCE_ENCODED: {
923 Address target = target_internal_reference();
924 Address pc = target_internal_reference_address();
925 Code* code = Code::cast(isolate->FindCodeObject(pc));
926 CHECK(target >= code->instruction_start());
927 CHECK(target <= code->instruction_end());
928 break;
929 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000930 case RUNTIME_ENTRY:
Steve Blocka7e24c12009-10-30 11:49:00 +0000931 case COMMENT:
932 case POSITION:
933 case STATEMENT_POSITION:
934 case EXTERNAL_REFERENCE:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000935 case DEOPT_REASON:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000936 case CONST_POOL:
937 case VENEER_POOL:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000938 case DEBUG_BREAK_SLOT_AT_POSITION:
939 case DEBUG_BREAK_SLOT_AT_RETURN:
940 case DEBUG_BREAK_SLOT_AT_CALL:
Ben Murdochda12d292016-06-02 14:46:10 +0100941 case DEBUG_BREAK_SLOT_AT_TAIL_CALL:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000942 case GENERATOR_CONTINUATION:
Ben Murdochda12d292016-06-02 14:46:10 +0100943 case WASM_MEMORY_REFERENCE:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000944 case NONE32:
945 case NONE64:
Steve Blocka7e24c12009-10-30 11:49:00 +0000946 break;
947 case NUMBER_OF_MODES:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000948 case PC_JUMP:
Steve Blocka7e24c12009-10-30 11:49:00 +0000949 UNREACHABLE();
950 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000951 case CODE_AGE_SEQUENCE:
952 DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode());
953 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000954 }
955}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000956#endif // VERIFY_HEAP
Steve Blocka7e24c12009-10-30 11:49:00 +0000957
958
Steve Blocka7e24c12009-10-30 11:49:00 +0000959// Implementation of ExternalReference
960
Ben Murdoch097c5b22016-05-18 11:27:45 +0100961static ExternalReference::Type BuiltinCallTypeForResultSize(int result_size) {
962 switch (result_size) {
963 case 1:
964 return ExternalReference::BUILTIN_CALL;
965 case 2:
966 return ExternalReference::BUILTIN_CALL_PAIR;
967 case 3:
968 return ExternalReference::BUILTIN_CALL_TRIPLE;
969 }
970 UNREACHABLE();
971 return ExternalReference::BUILTIN_CALL;
972}
973
974
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000975void ExternalReference::SetUp() {
976 double_constants.min_int = kMinInt;
977 double_constants.one_half = 0.5;
978 double_constants.minus_one_half = -0.5;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000979 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64);
980 double_constants.negative_infinity = -V8_INFINITY;
981 double_constants.uint32_bias =
982 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1;
983
984 math_exp_data_mutex = new base::Mutex();
985}
986
987
988void ExternalReference::InitializeMathExpData() {
989 // Early return?
990 if (math_exp_data_initialized) return;
991
992 base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex);
993 if (!math_exp_data_initialized) {
994 // If this is changed, generated code must be adapted too.
995 const int kTableSizeBits = 11;
996 const int kTableSize = 1 << kTableSizeBits;
997 const double kTableSizeDouble = static_cast<double>(kTableSize);
998
999 math_exp_constants_array = new double[9];
1000 // Input values smaller than this always return 0.
1001 math_exp_constants_array[0] = -708.39641853226408;
1002 // Input values larger than this always return +Infinity.
1003 math_exp_constants_array[1] = 709.78271289338397;
1004 math_exp_constants_array[2] = V8_INFINITY;
1005 // The rest is black magic. Do not attempt to understand it. It is
1006 // loosely based on the "expd" function published at:
1007 // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html
1008 const double constant3 = (1 << kTableSizeBits) / std::log(2.0);
1009 math_exp_constants_array[3] = constant3;
1010 math_exp_constants_array[4] =
1011 static_cast<double>(static_cast<int64_t>(3) << 51);
1012 math_exp_constants_array[5] = 1 / constant3;
1013 math_exp_constants_array[6] = 3.0000000027955394;
1014 math_exp_constants_array[7] = 0.16666666685227835;
1015 math_exp_constants_array[8] = 1;
1016
1017 math_exp_log_table_array = new double[kTableSize];
1018 for (int i = 0; i < kTableSize; i++) {
1019 double value = std::pow(2, i / kTableSizeDouble);
1020 uint64_t bits = bit_cast<uint64_t, double>(value);
1021 bits &= (static_cast<uint64_t>(1) << 52) - 1;
1022 double mantissa = bit_cast<double, uint64_t>(bits);
1023 math_exp_log_table_array[i] = mantissa;
1024 }
1025
1026 math_exp_data_initialized = true;
1027 }
1028}
1029
1030
1031void ExternalReference::TearDownMathExpData() {
1032 delete[] math_exp_constants_array;
1033 math_exp_constants_array = NULL;
1034 delete[] math_exp_log_table_array;
1035 math_exp_log_table_array = NULL;
1036 delete math_exp_data_mutex;
1037 math_exp_data_mutex = NULL;
1038}
1039
1040
Steve Block44f0eee2011-05-26 01:26:41 +01001041ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
1042 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001043
1044
Steve Block1e0659c2011-05-24 12:43:12 +01001045ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001046 ApiFunction* fun,
1047 Type type = ExternalReference::BUILTIN_CALL,
1048 Isolate* isolate = NULL)
1049 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +00001050
1051
Steve Block44f0eee2011-05-26 01:26:41 +01001052ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
1053 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001054
1055
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001056ExternalReference::ExternalReference(Runtime::FunctionId id, Isolate* isolate)
Ben Murdoch097c5b22016-05-18 11:27:45 +01001057 : ExternalReference(Runtime::FunctionForId(id), isolate) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001058
1059
Steve Block44f0eee2011-05-26 01:26:41 +01001060ExternalReference::ExternalReference(const Runtime::Function* f,
1061 Isolate* isolate)
Ben Murdoch097c5b22016-05-18 11:27:45 +01001062 : address_(Redirect(isolate, f->entry,
1063 BuiltinCallTypeForResultSize(f->result_size))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001064
1065
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001066ExternalReference ExternalReference::isolate_address(Isolate* isolate) {
1067 return ExternalReference(isolate);
Steve Block44f0eee2011-05-26 01:26:41 +01001068}
1069
Ben Murdoch097c5b22016-05-18 11:27:45 +01001070ExternalReference ExternalReference::interpreter_dispatch_table_address(
1071 Isolate* isolate) {
1072 return ExternalReference(isolate->interpreter()->dispatch_table_address());
1073}
Steve Block44f0eee2011-05-26 01:26:41 +01001074
Steve Blocka7e24c12009-10-30 11:49:00 +00001075ExternalReference::ExternalReference(StatsCounter* counter)
1076 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
1077
1078
Steve Block44f0eee2011-05-26 01:26:41 +01001079ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
1080 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +00001081
1082
1083ExternalReference::ExternalReference(const SCTableReference& table_ref)
1084 : address_(table_ref.address()) {}
1085
1086
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001087ExternalReference ExternalReference::
1088 incremental_marking_record_write_function(Isolate* isolate) {
1089 return ExternalReference(Redirect(
1090 isolate,
1091 FUNCTION_ADDR(IncrementalMarking::RecordWriteFromCode)));
1092}
1093
Ben Murdoch097c5b22016-05-18 11:27:45 +01001094ExternalReference
1095ExternalReference::incremental_marking_record_write_code_entry_function(
1096 Isolate* isolate) {
1097 return ExternalReference(Redirect(
1098 isolate,
1099 FUNCTION_ADDR(IncrementalMarking::RecordWriteOfCodeEntryFromCode)));
1100}
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001101
Ben Murdoch097c5b22016-05-18 11:27:45 +01001102ExternalReference ExternalReference::store_buffer_overflow_function(
1103 Isolate* isolate) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001104 return ExternalReference(Redirect(
1105 isolate,
1106 FUNCTION_ADDR(StoreBuffer::StoreBufferOverflow)));
1107}
1108
1109
Steve Block44f0eee2011-05-26 01:26:41 +01001110ExternalReference ExternalReference::delete_handle_scope_extensions(
1111 Isolate* isolate) {
1112 return ExternalReference(Redirect(
1113 isolate,
1114 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -07001115}
1116
1117
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001118ExternalReference ExternalReference::get_date_field_function(
1119 Isolate* isolate) {
1120 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(JSDate::GetField)));
1121}
1122
1123
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001124ExternalReference ExternalReference::get_make_code_young_function(
1125 Isolate* isolate) {
1126 return ExternalReference(Redirect(
1127 isolate, FUNCTION_ADDR(Code::MakeCodeAgeSequenceYoung)));
1128}
1129
1130
1131ExternalReference ExternalReference::get_mark_code_as_executed_function(
1132 Isolate* isolate) {
1133 return ExternalReference(Redirect(
1134 isolate, FUNCTION_ADDR(Code::MarkCodeAsExecuted)));
1135}
1136
1137
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001138ExternalReference ExternalReference::date_cache_stamp(Isolate* isolate) {
1139 return ExternalReference(isolate->date_cache()->stamp_address());
1140}
1141
1142
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001143ExternalReference ExternalReference::stress_deopt_count(Isolate* isolate) {
1144 return ExternalReference(isolate->stress_deopt_count_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001145}
1146
1147
Steve Block44f0eee2011-05-26 01:26:41 +01001148ExternalReference ExternalReference::new_deoptimizer_function(
1149 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001150 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001151 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001152}
1153
1154
Steve Block44f0eee2011-05-26 01:26:41 +01001155ExternalReference ExternalReference::compute_output_frames_function(
1156 Isolate* isolate) {
1157 return ExternalReference(
1158 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001159}
1160
Ben Murdochda12d292016-06-02 14:46:10 +01001161ExternalReference ExternalReference::wasm_f32_trunc(Isolate* isolate) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001162 return ExternalReference(
Ben Murdochda12d292016-06-02 14:46:10 +01001163 Redirect(isolate, FUNCTION_ADDR(wasm::f32_trunc_wrapper)));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001164}
Ben Murdochda12d292016-06-02 14:46:10 +01001165ExternalReference ExternalReference::wasm_f32_floor(Isolate* isolate) {
Ben Murdoch097c5b22016-05-18 11:27:45 +01001166 return ExternalReference(
Ben Murdochda12d292016-06-02 14:46:10 +01001167 Redirect(isolate, FUNCTION_ADDR(wasm::f32_floor_wrapper)));
1168}
1169ExternalReference ExternalReference::wasm_f32_ceil(Isolate* isolate) {
1170 return ExternalReference(
1171 Redirect(isolate, FUNCTION_ADDR(wasm::f32_ceil_wrapper)));
1172}
1173ExternalReference ExternalReference::wasm_f32_nearest_int(Isolate* isolate) {
1174 return ExternalReference(
1175 Redirect(isolate, FUNCTION_ADDR(wasm::f32_nearest_int_wrapper)));
1176}
1177
1178ExternalReference ExternalReference::wasm_f64_trunc(Isolate* isolate) {
1179 return ExternalReference(
1180 Redirect(isolate, FUNCTION_ADDR(wasm::f64_trunc_wrapper)));
1181}
1182
1183ExternalReference ExternalReference::wasm_f64_floor(Isolate* isolate) {
1184 return ExternalReference(
1185 Redirect(isolate, FUNCTION_ADDR(wasm::f64_floor_wrapper)));
1186}
1187
1188ExternalReference ExternalReference::wasm_f64_ceil(Isolate* isolate) {
1189 return ExternalReference(
1190 Redirect(isolate, FUNCTION_ADDR(wasm::f64_ceil_wrapper)));
1191}
1192
1193ExternalReference ExternalReference::wasm_f64_nearest_int(Isolate* isolate) {
1194 return ExternalReference(
1195 Redirect(isolate, FUNCTION_ADDR(wasm::f64_nearest_int_wrapper)));
1196}
1197
1198ExternalReference ExternalReference::wasm_int64_to_float32(Isolate* isolate) {
1199 return ExternalReference(
1200 Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float32_wrapper)));
1201}
1202
1203ExternalReference ExternalReference::wasm_uint64_to_float32(Isolate* isolate) {
1204 return ExternalReference(
1205 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float32_wrapper)));
1206}
1207
1208ExternalReference ExternalReference::wasm_int64_to_float64(Isolate* isolate) {
1209 return ExternalReference(
1210 Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float64_wrapper)));
1211}
1212
1213ExternalReference ExternalReference::wasm_uint64_to_float64(Isolate* isolate) {
1214 return ExternalReference(
1215 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float64_wrapper)));
1216}
1217
1218ExternalReference ExternalReference::wasm_float32_to_int64(Isolate* isolate) {
1219 return ExternalReference(
1220 Redirect(isolate, FUNCTION_ADDR(wasm::float32_to_int64_wrapper)));
1221}
1222
1223ExternalReference ExternalReference::wasm_float32_to_uint64(Isolate* isolate) {
1224 return ExternalReference(
1225 Redirect(isolate, FUNCTION_ADDR(wasm::float32_to_uint64_wrapper)));
1226}
1227
1228ExternalReference ExternalReference::wasm_float64_to_int64(Isolate* isolate) {
1229 return ExternalReference(
1230 Redirect(isolate, FUNCTION_ADDR(wasm::float64_to_int64_wrapper)));
1231}
1232
1233ExternalReference ExternalReference::wasm_float64_to_uint64(Isolate* isolate) {
1234 return ExternalReference(
1235 Redirect(isolate, FUNCTION_ADDR(wasm::float64_to_uint64_wrapper)));
1236}
1237
1238ExternalReference ExternalReference::wasm_int64_div(Isolate* isolate) {
1239 return ExternalReference(
1240 Redirect(isolate, FUNCTION_ADDR(wasm::int64_div_wrapper)));
1241}
1242
1243ExternalReference ExternalReference::wasm_int64_mod(Isolate* isolate) {
1244 return ExternalReference(
1245 Redirect(isolate, FUNCTION_ADDR(wasm::int64_mod_wrapper)));
1246}
1247
1248ExternalReference ExternalReference::wasm_uint64_div(Isolate* isolate) {
1249 return ExternalReference(
1250 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_div_wrapper)));
1251}
1252
1253ExternalReference ExternalReference::wasm_uint64_mod(Isolate* isolate) {
1254 return ExternalReference(
1255 Redirect(isolate, FUNCTION_ADDR(wasm::uint64_mod_wrapper)));
1256}
1257
1258static void f64_acos_wrapper(double* param) { *param = std::acos(*param); }
1259
1260ExternalReference ExternalReference::f64_acos_wrapper_function(
1261 Isolate* isolate) {
1262 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_acos_wrapper)));
1263}
1264
1265static void f64_asin_wrapper(double* param) { *param = std::asin(*param); }
1266
1267ExternalReference ExternalReference::f64_asin_wrapper_function(
1268 Isolate* isolate) {
1269 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_asin_wrapper)));
1270}
1271
1272static void f64_atan_wrapper(double* param) { *param = std::atan(*param); }
1273
1274ExternalReference ExternalReference::f64_atan_wrapper_function(
1275 Isolate* isolate) {
1276 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_atan_wrapper)));
1277}
1278
1279static void f64_cos_wrapper(double* param) { *param = std::cos(*param); }
1280
1281ExternalReference ExternalReference::f64_cos_wrapper_function(
1282 Isolate* isolate) {
1283 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_cos_wrapper)));
1284}
1285
1286static void f64_sin_wrapper(double* param) { *param = std::sin(*param); }
1287
1288ExternalReference ExternalReference::f64_sin_wrapper_function(
1289 Isolate* isolate) {
1290 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_sin_wrapper)));
1291}
1292
1293static void f64_tan_wrapper(double* param) { *param = std::tan(*param); }
1294
1295ExternalReference ExternalReference::f64_tan_wrapper_function(
1296 Isolate* isolate) {
1297 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_tan_wrapper)));
1298}
1299
1300static void f64_exp_wrapper(double* param) { *param = std::exp(*param); }
1301
1302ExternalReference ExternalReference::f64_exp_wrapper_function(
1303 Isolate* isolate) {
1304 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_exp_wrapper)));
1305}
1306
1307static void f64_log_wrapper(double* param) { *param = std::log(*param); }
1308
1309ExternalReference ExternalReference::f64_log_wrapper_function(
1310 Isolate* isolate) {
1311 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_log_wrapper)));
1312}
1313
1314static void f64_pow_wrapper(double* param0, double* param1) {
1315 *param0 = power_double_double(*param0, *param1);
1316}
1317
1318ExternalReference ExternalReference::f64_pow_wrapper_function(
1319 Isolate* isolate) {
1320 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_pow_wrapper)));
1321}
1322
1323static void f64_atan2_wrapper(double* param0, double* param1) {
1324 double x = *param0;
1325 double y = *param1;
1326 // TODO(bradnelson): Find a good place to put this to share
1327 // with the same code in src/runtime/runtime-math.cc
1328 static const double kPiDividedBy4 = 0.78539816339744830962;
1329 if (std::isinf(x) && std::isinf(y)) {
1330 // Make sure that the result in case of two infinite arguments
1331 // is a multiple of Pi / 4. The sign of the result is determined
1332 // by the first argument (x) and the sign of the second argument
1333 // determines the multiplier: one or three.
1334 int multiplier = (x < 0) ? -1 : 1;
1335 if (y < 0) multiplier *= 3;
1336 *param0 = multiplier * kPiDividedBy4;
1337 } else {
1338 *param0 = std::atan2(x, y);
1339 }
1340}
1341
1342ExternalReference ExternalReference::f64_atan2_wrapper_function(
1343 Isolate* isolate) {
1344 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_atan2_wrapper)));
1345}
1346
1347static void f64_mod_wrapper(double* param0, double* param1) {
1348 *param0 = modulo(*param0, *param1);
1349}
1350
1351ExternalReference ExternalReference::f64_mod_wrapper_function(
1352 Isolate* isolate) {
1353 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_mod_wrapper)));
Ben Murdoch097c5b22016-05-18 11:27:45 +01001354}
Ben Murdochb0fe1622011-05-05 13:52:32 +01001355
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001356ExternalReference ExternalReference::log_enter_external_function(
1357 Isolate* isolate) {
1358 return ExternalReference(
1359 Redirect(isolate, FUNCTION_ADDR(Logger::EnterExternal)));
1360}
1361
1362
1363ExternalReference ExternalReference::log_leave_external_function(
1364 Isolate* isolate) {
1365 return ExternalReference(
1366 Redirect(isolate, FUNCTION_ADDR(Logger::LeaveExternal)));
1367}
1368
1369
Steve Block44f0eee2011-05-26 01:26:41 +01001370ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
1371 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001372}
1373
1374
Steve Block44f0eee2011-05-26 01:26:41 +01001375ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
1376 Isolate* isolate) {
1377 return ExternalReference(
1378 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001379}
1380
1381
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001382ExternalReference ExternalReference::roots_array_start(Isolate* isolate) {
1383 return ExternalReference(isolate->heap()->roots_array_start());
Steve Blocka7e24c12009-10-30 11:49:00 +00001384}
1385
1386
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001387ExternalReference ExternalReference::allocation_sites_list_address(
1388 Isolate* isolate) {
1389 return ExternalReference(isolate->heap()->allocation_sites_list_address());
1390}
1391
1392
Steve Block44f0eee2011-05-26 01:26:41 +01001393ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
1394 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +00001395}
1396
1397
Steve Block44f0eee2011-05-26 01:26:41 +01001398ExternalReference ExternalReference::address_of_real_stack_limit(
1399 Isolate* isolate) {
1400 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +00001401}
1402
1403
Steve Block44f0eee2011-05-26 01:26:41 +01001404ExternalReference ExternalReference::address_of_regexp_stack_limit(
1405 Isolate* isolate) {
1406 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001407}
1408
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001409ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001410 return ExternalReference(isolate->heap()->store_buffer_top_address());
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001411}
1412
1413
Steve Block44f0eee2011-05-26 01:26:41 +01001414ExternalReference ExternalReference::new_space_allocation_top_address(
1415 Isolate* isolate) {
1416 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +00001417}
1418
1419
Steve Block44f0eee2011-05-26 01:26:41 +01001420ExternalReference ExternalReference::new_space_allocation_limit_address(
1421 Isolate* isolate) {
1422 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +00001423}
1424
Steve Blockd0582a62009-12-15 09:54:21 +00001425
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001426ExternalReference ExternalReference::old_space_allocation_top_address(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001427 Isolate* isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001428 return ExternalReference(isolate->heap()->OldSpaceAllocationTopAddress());
Steve Blockd0582a62009-12-15 09:54:21 +00001429}
1430
1431
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001432ExternalReference ExternalReference::old_space_allocation_limit_address(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001433 Isolate* isolate) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001434 return ExternalReference(isolate->heap()->OldSpaceAllocationLimitAddress());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001435}
1436
1437
1438ExternalReference ExternalReference::handle_scope_level_address(
1439 Isolate* isolate) {
1440 return ExternalReference(HandleScope::current_level_address(isolate));
1441}
1442
1443
1444ExternalReference ExternalReference::handle_scope_next_address(
1445 Isolate* isolate) {
1446 return ExternalReference(HandleScope::current_next_address(isolate));
1447}
1448
1449
1450ExternalReference ExternalReference::handle_scope_limit_address(
1451 Isolate* isolate) {
1452 return ExternalReference(HandleScope::current_limit_address(isolate));
Steve Blockd0582a62009-12-15 09:54:21 +00001453}
1454
1455
Steve Block44f0eee2011-05-26 01:26:41 +01001456ExternalReference ExternalReference::scheduled_exception_address(
1457 Isolate* isolate) {
1458 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +00001459}
1460
1461
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001462ExternalReference ExternalReference::address_of_pending_message_obj(
1463 Isolate* isolate) {
1464 return ExternalReference(isolate->pending_message_obj_address());
1465}
1466
1467
Ben Murdochb0fe1622011-05-05 13:52:32 +01001468ExternalReference ExternalReference::address_of_min_int() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001469 return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001470}
1471
1472
1473ExternalReference ExternalReference::address_of_one_half() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001474 return ExternalReference(reinterpret_cast<void*>(&double_constants.one_half));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001475}
1476
1477
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001478ExternalReference ExternalReference::address_of_minus_one_half() {
1479 return ExternalReference(
1480 reinterpret_cast<void*>(&double_constants.minus_one_half));
Ben Murdoch257744e2011-11-30 15:57:28 +00001481}
1482
1483
Ben Murdochb0fe1622011-05-05 13:52:32 +01001484ExternalReference ExternalReference::address_of_negative_infinity() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001485 return ExternalReference(
1486 reinterpret_cast<void*>(&double_constants.negative_infinity));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001487}
1488
1489
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001490ExternalReference ExternalReference::address_of_the_hole_nan() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001491 return ExternalReference(
1492 reinterpret_cast<void*>(&double_constants.the_hole_nan));
1493}
1494
1495
1496ExternalReference ExternalReference::address_of_uint32_bias() {
1497 return ExternalReference(
1498 reinterpret_cast<void*>(&double_constants.uint32_bias));
1499}
1500
1501
1502ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) {
1503 return ExternalReference(isolate->cpu_profiler()->is_profiling_address());
1504}
1505
1506
1507ExternalReference ExternalReference::invoke_function_callback(
1508 Isolate* isolate) {
1509 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
1510 ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
1511 ApiFunction thunk_fun(thunk_address);
1512 return ExternalReference(&thunk_fun, thunk_type, isolate);
1513}
1514
1515
1516ExternalReference ExternalReference::invoke_accessor_getter_callback(
1517 Isolate* isolate) {
1518 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
1519 ExternalReference::Type thunk_type =
1520 ExternalReference::PROFILING_GETTER_CALL;
1521 ApiFunction thunk_fun(thunk_address);
1522 return ExternalReference(&thunk_fun, thunk_type, isolate);
Steve Block44f0eee2011-05-26 01:26:41 +01001523}
1524
1525
Steve Block6ded16b2010-05-10 14:33:55 +01001526#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001527
Steve Block44f0eee2011-05-26 01:26:41 +01001528ExternalReference ExternalReference::re_check_stack_guard_state(
1529 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001530 Address function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001531#if V8_TARGET_ARCH_X64
Steve Blocka7e24c12009-10-30 11:49:00 +00001532 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
1533#elif V8_TARGET_ARCH_IA32
1534 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001535#elif V8_TARGET_ARCH_ARM64
1536 function = FUNCTION_ADDR(RegExpMacroAssemblerARM64::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +00001537#elif V8_TARGET_ARCH_ARM
1538 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001539#elif V8_TARGET_ARCH_PPC
1540 function = FUNCTION_ADDR(RegExpMacroAssemblerPPC::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +01001541#elif V8_TARGET_ARCH_MIPS
1542 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001543#elif V8_TARGET_ARCH_MIPS64
1544 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Ben Murdochda12d292016-06-02 14:46:10 +01001545#elif V8_TARGET_ARCH_S390
1546 function = FUNCTION_ADDR(RegExpMacroAssemblerS390::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001547#elif V8_TARGET_ARCH_X87
1548 function = FUNCTION_ADDR(RegExpMacroAssemblerX87::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +00001549#else
Leon Clarke4515c472010-02-03 11:58:03 +00001550 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +00001551#endif
Steve Block44f0eee2011-05-26 01:26:41 +01001552 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +00001553}
1554
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001555
Steve Block44f0eee2011-05-26 01:26:41 +01001556ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001557 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001558 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001559}
1560
Steve Block44f0eee2011-05-26 01:26:41 +01001561ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
1562 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001563 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +01001564 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +00001565 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
1566}
1567
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001568
Leon Clarkee46be812010-01-19 14:06:41 +00001569ExternalReference ExternalReference::re_word_character_map() {
1570 return ExternalReference(
1571 NativeRegExpMacroAssembler::word_character_map_address());
1572}
1573
Steve Block44f0eee2011-05-26 01:26:41 +01001574ExternalReference ExternalReference::address_of_static_offsets_vector(
1575 Isolate* isolate) {
1576 return ExternalReference(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001577 reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector()));
Leon Clarkee46be812010-01-19 14:06:41 +00001578}
1579
Steve Block44f0eee2011-05-26 01:26:41 +01001580ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
1581 Isolate* isolate) {
1582 return ExternalReference(
1583 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +00001584}
1585
Steve Block44f0eee2011-05-26 01:26:41 +01001586ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
1587 Isolate* isolate) {
1588 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +00001589}
1590
Steve Block6ded16b2010-05-10 14:33:55 +01001591#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001592
1593
Steve Block44f0eee2011-05-26 01:26:41 +01001594ExternalReference ExternalReference::math_log_double_function(
1595 Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001596 typedef double (*d2d)(double x);
Steve Block44f0eee2011-05-26 01:26:41 +01001597 return ExternalReference(Redirect(isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001598 FUNCTION_ADDR(static_cast<d2d>(std::log)),
Ben Murdoch257744e2011-11-30 15:57:28 +00001599 BUILTIN_FP_CALL));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001600}
1601
1602
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001603ExternalReference ExternalReference::math_exp_constants(int constant_index) {
1604 DCHECK(math_exp_data_initialized);
1605 return ExternalReference(
1606 reinterpret_cast<void*>(math_exp_constants_array + constant_index));
1607}
1608
1609
1610ExternalReference ExternalReference::math_exp_log_table() {
1611 DCHECK(math_exp_data_initialized);
1612 return ExternalReference(reinterpret_cast<void*>(math_exp_log_table_array));
1613}
1614
1615
1616ExternalReference ExternalReference::page_flags(Page* page) {
1617 return ExternalReference(reinterpret_cast<Address>(page) +
1618 MemoryChunk::kFlagsOffset);
1619}
1620
1621
1622ExternalReference ExternalReference::ForDeoptEntry(Address entry) {
1623 return ExternalReference(entry);
1624}
1625
1626
1627ExternalReference ExternalReference::cpu_features() {
1628 DCHECK(CpuFeatures::initialized_);
1629 return ExternalReference(&CpuFeatures::supported_);
1630}
1631
Ben Murdochda12d292016-06-02 14:46:10 +01001632ExternalReference ExternalReference::is_tail_call_elimination_enabled_address(
1633 Isolate* isolate) {
1634 return ExternalReference(isolate->is_tail_call_elimination_enabled_address());
1635}
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001636
1637ExternalReference ExternalReference::debug_is_active_address(
1638 Isolate* isolate) {
1639 return ExternalReference(isolate->debug()->is_active_address());
1640}
1641
1642
1643ExternalReference ExternalReference::debug_after_break_target_address(
1644 Isolate* isolate) {
1645 return ExternalReference(isolate->debug()->after_break_target_address());
1646}
1647
1648
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001649ExternalReference ExternalReference::virtual_handler_register(
1650 Isolate* isolate) {
1651 return ExternalReference(isolate->virtual_handler_register_address());
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001652}
1653
1654
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001655ExternalReference ExternalReference::virtual_slot_register(Isolate* isolate) {
1656 return ExternalReference(isolate->virtual_slot_register_address());
1657}
1658
1659
1660ExternalReference ExternalReference::runtime_function_table_address(
1661 Isolate* isolate) {
1662 return ExternalReference(
1663 const_cast<Runtime::Function*>(Runtime::RuntimeFunctionTable(isolate)));
1664}
1665
1666
1667double power_helper(Isolate* isolate, double x, double y) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001668 int y_int = static_cast<int>(y);
1669 if (y == y_int) {
1670 return power_double_int(x, y_int); // Returns 1 if exponent is 0.
1671 }
1672 if (y == 0.5) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001673 lazily_initialize_fast_sqrt(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001674 return (std::isinf(x)) ? V8_INFINITY
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001675 : fast_sqrt(x + 0.0, isolate); // Convert -0 to +0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001676 }
1677 if (y == -0.5) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001678 lazily_initialize_fast_sqrt(isolate);
1679 return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0,
1680 isolate); // Convert -0 to +0.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001681 }
1682 return power_double_double(x, y);
1683}
1684
1685
Ben Murdochb0fe1622011-05-05 13:52:32 +01001686// Helper function to compute x^y, where y is known to be an
1687// integer. Uses binary decomposition to limit the number of
1688// multiplications; see the discussion in "Hacker's Delight" by Henry
1689// S. Warren, Jr., figure 11-6, page 213.
1690double power_double_int(double x, int y) {
1691 double m = (y < 0) ? 1 / x : x;
1692 unsigned n = (y < 0) ? -y : y;
1693 double p = 1;
1694 while (n != 0) {
1695 if ((n & 1) != 0) p *= m;
1696 m *= m;
1697 if ((n & 2) != 0) p *= m;
1698 m *= m;
1699 n >>= 2;
1700 }
1701 return p;
1702}
1703
1704
1705double power_double_double(double x, double y) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001706 // The checks for special cases can be dropped in ia32 because it has already
1707 // been done in generated code before bailing out here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001708 if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001709 return std::numeric_limits<double>::quiet_NaN();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001710 }
Ben Murdochda12d292016-06-02 14:46:10 +01001711 return Pow(x, y);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001712}
1713
1714
Steve Block44f0eee2011-05-26 01:26:41 +01001715ExternalReference ExternalReference::power_double_double_function(
1716 Isolate* isolate) {
1717 return ExternalReference(Redirect(isolate,
1718 FUNCTION_ADDR(power_double_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001719 BUILTIN_FP_FP_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001720}
1721
1722
Steve Block44f0eee2011-05-26 01:26:41 +01001723ExternalReference ExternalReference::power_double_int_function(
1724 Isolate* isolate) {
1725 return ExternalReference(Redirect(isolate,
1726 FUNCTION_ADDR(power_double_int),
Ben Murdoch257744e2011-11-30 15:57:28 +00001727 BUILTIN_FP_INT_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001728}
1729
1730
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001731ExternalReference ExternalReference::mod_two_doubles_operation(
1732 Isolate* isolate) {
Steve Block44f0eee2011-05-26 01:26:41 +01001733 return ExternalReference(Redirect(isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001734 FUNCTION_ADDR(modulo),
Ben Murdoch257744e2011-11-30 15:57:28 +00001735 BUILTIN_FP_FP_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001736}
1737
1738
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001739ExternalReference ExternalReference::debug_step_in_enabled_address(
1740 Isolate* isolate) {
1741 return ExternalReference(isolate->debug()->step_in_enabled_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001742}
1743
1744
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001745ExternalReference ExternalReference::fixed_typed_array_base_data_offset() {
1746 return ExternalReference(reinterpret_cast<void*>(
1747 FixedTypedArrayBase::kDataOffset - kHeapObjectTag));
Steve Blocka7e24c12009-10-30 11:49:00 +00001748}
Steve Blocka7e24c12009-10-30 11:49:00 +00001749
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001750
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001751bool operator==(ExternalReference lhs, ExternalReference rhs) {
1752 return lhs.address() == rhs.address();
1753}
1754
1755
1756bool operator!=(ExternalReference lhs, ExternalReference rhs) {
1757 return !(lhs == rhs);
1758}
1759
1760
1761size_t hash_value(ExternalReference reference) {
1762 return base::hash<Address>()(reference.address());
1763}
1764
1765
1766std::ostream& operator<<(std::ostream& os, ExternalReference reference) {
1767 os << static_cast<const void*>(reference.address());
1768 const Runtime::Function* fn = Runtime::FunctionForEntry(reference.address());
1769 if (fn) os << "<" << fn->name << ".entry>";
1770 return os;
1771}
1772
Ben Murdochda12d292016-06-02 14:46:10 +01001773void AssemblerPositionsRecorder::RecordPosition(int pos) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001774 DCHECK(pos != RelocInfo::kNoPosition);
1775 DCHECK(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001776 state_.current_position = pos;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001777 LOG_CODE_EVENT(assembler_->isolate(),
1778 CodeLinePosInfoAddPositionEvent(jit_handler_data_,
1779 assembler_->pc_offset(),
1780 pos));
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001781}
1782
Ben Murdochda12d292016-06-02 14:46:10 +01001783void AssemblerPositionsRecorder::RecordStatementPosition(int pos) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001784 DCHECK(pos != RelocInfo::kNoPosition);
1785 DCHECK(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001786 state_.current_statement_position = pos;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001787 LOG_CODE_EVENT(assembler_->isolate(),
1788 CodeLinePosInfoAddStatementPositionEvent(
1789 jit_handler_data_,
1790 assembler_->pc_offset(),
1791 pos));
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001792}
1793
Ben Murdochda12d292016-06-02 14:46:10 +01001794bool AssemblerPositionsRecorder::WriteRecordedPositions() {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001795 bool written = false;
1796
1797 // Write the statement position if it is different from what was written last
1798 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001799 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001800 EnsureSpace ensure_space(assembler_);
1801 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001802 state_.current_statement_position);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001803 state_.written_position = state_.current_statement_position;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001804 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001805 written = true;
1806 }
1807
1808 // Write the position if it is different from what was written last time and
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001809 // also different from the statement position that was just written.
1810 if (state_.current_position != state_.written_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001811 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001812 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1813 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001814 written = true;
1815 }
1816
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001817 // Return whether something was written.
1818 return written;
1819}
1820
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001821
1822ConstantPoolBuilder::ConstantPoolBuilder(int ptr_reach_bits,
1823 int double_reach_bits) {
1824 info_[ConstantPoolEntry::INTPTR].entries.reserve(64);
1825 info_[ConstantPoolEntry::INTPTR].regular_reach_bits = ptr_reach_bits;
1826 info_[ConstantPoolEntry::DOUBLE].regular_reach_bits = double_reach_bits;
1827}
1828
1829
1830ConstantPoolEntry::Access ConstantPoolBuilder::NextAccess(
1831 ConstantPoolEntry::Type type) const {
1832 const PerTypeEntryInfo& info = info_[type];
1833
1834 if (info.overflow()) return ConstantPoolEntry::OVERFLOWED;
1835
1836 int dbl_count = info_[ConstantPoolEntry::DOUBLE].regular_count;
1837 int dbl_offset = dbl_count * kDoubleSize;
1838 int ptr_count = info_[ConstantPoolEntry::INTPTR].regular_count;
1839 int ptr_offset = ptr_count * kPointerSize + dbl_offset;
1840
1841 if (type == ConstantPoolEntry::DOUBLE) {
1842 // Double overflow detection must take into account the reach for both types
1843 int ptr_reach_bits = info_[ConstantPoolEntry::INTPTR].regular_reach_bits;
1844 if (!is_uintn(dbl_offset, info.regular_reach_bits) ||
1845 (ptr_count > 0 &&
1846 !is_uintn(ptr_offset + kDoubleSize - kPointerSize, ptr_reach_bits))) {
1847 return ConstantPoolEntry::OVERFLOWED;
1848 }
1849 } else {
1850 DCHECK(type == ConstantPoolEntry::INTPTR);
1851 if (!is_uintn(ptr_offset, info.regular_reach_bits)) {
1852 return ConstantPoolEntry::OVERFLOWED;
1853 }
1854 }
1855
1856 return ConstantPoolEntry::REGULAR;
1857}
1858
1859
1860ConstantPoolEntry::Access ConstantPoolBuilder::AddEntry(
1861 ConstantPoolEntry& entry, ConstantPoolEntry::Type type) {
1862 DCHECK(!emitted_label_.is_bound());
1863 PerTypeEntryInfo& info = info_[type];
1864 const int entry_size = ConstantPoolEntry::size(type);
1865 bool merged = false;
1866
1867 if (entry.sharing_ok()) {
1868 // Try to merge entries
1869 std::vector<ConstantPoolEntry>::iterator it = info.shared_entries.begin();
1870 int end = static_cast<int>(info.shared_entries.size());
1871 for (int i = 0; i < end; i++, it++) {
1872 if ((entry_size == kPointerSize) ? entry.value() == it->value()
1873 : entry.value64() == it->value64()) {
1874 // Merge with found entry.
1875 entry.set_merged_index(i);
1876 merged = true;
1877 break;
1878 }
1879 }
1880 }
1881
1882 // By definition, merged entries have regular access.
1883 DCHECK(!merged || entry.merged_index() < info.regular_count);
1884 ConstantPoolEntry::Access access =
1885 (merged ? ConstantPoolEntry::REGULAR : NextAccess(type));
1886
1887 // Enforce an upper bound on search time by limiting the search to
1888 // unique sharable entries which fit in the regular section.
1889 if (entry.sharing_ok() && !merged && access == ConstantPoolEntry::REGULAR) {
1890 info.shared_entries.push_back(entry);
1891 } else {
1892 info.entries.push_back(entry);
1893 }
1894
1895 // We're done if we found a match or have already triggered the
1896 // overflow state.
1897 if (merged || info.overflow()) return access;
1898
1899 if (access == ConstantPoolEntry::REGULAR) {
1900 info.regular_count++;
1901 } else {
1902 info.overflow_start = static_cast<int>(info.entries.size()) - 1;
1903 }
1904
1905 return access;
1906}
1907
1908
1909void ConstantPoolBuilder::EmitSharedEntries(Assembler* assm,
1910 ConstantPoolEntry::Type type) {
1911 PerTypeEntryInfo& info = info_[type];
1912 std::vector<ConstantPoolEntry>& shared_entries = info.shared_entries;
1913 const int entry_size = ConstantPoolEntry::size(type);
1914 int base = emitted_label_.pos();
1915 DCHECK(base > 0);
1916 int shared_end = static_cast<int>(shared_entries.size());
1917 std::vector<ConstantPoolEntry>::iterator shared_it = shared_entries.begin();
1918 for (int i = 0; i < shared_end; i++, shared_it++) {
1919 int offset = assm->pc_offset() - base;
1920 shared_it->set_offset(offset); // Save offset for merged entries.
1921 if (entry_size == kPointerSize) {
1922 assm->dp(shared_it->value());
1923 } else {
1924 assm->dq(shared_it->value64());
1925 }
1926 DCHECK(is_uintn(offset, info.regular_reach_bits));
1927
1928 // Patch load sequence with correct offset.
1929 assm->PatchConstantPoolAccessInstruction(shared_it->position(), offset,
1930 ConstantPoolEntry::REGULAR, type);
1931 }
1932}
1933
1934
1935void ConstantPoolBuilder::EmitGroup(Assembler* assm,
1936 ConstantPoolEntry::Access access,
1937 ConstantPoolEntry::Type type) {
1938 PerTypeEntryInfo& info = info_[type];
1939 const bool overflow = info.overflow();
1940 std::vector<ConstantPoolEntry>& entries = info.entries;
1941 std::vector<ConstantPoolEntry>& shared_entries = info.shared_entries;
1942 const int entry_size = ConstantPoolEntry::size(type);
1943 int base = emitted_label_.pos();
1944 DCHECK(base > 0);
1945 int begin;
1946 int end;
1947
1948 if (access == ConstantPoolEntry::REGULAR) {
1949 // Emit any shared entries first
1950 EmitSharedEntries(assm, type);
1951 }
1952
1953 if (access == ConstantPoolEntry::REGULAR) {
1954 begin = 0;
1955 end = overflow ? info.overflow_start : static_cast<int>(entries.size());
1956 } else {
1957 DCHECK(access == ConstantPoolEntry::OVERFLOWED);
1958 if (!overflow) return;
1959 begin = info.overflow_start;
1960 end = static_cast<int>(entries.size());
1961 }
1962
1963 std::vector<ConstantPoolEntry>::iterator it = entries.begin();
1964 if (begin > 0) std::advance(it, begin);
1965 for (int i = begin; i < end; i++, it++) {
1966 // Update constant pool if necessary and get the entry's offset.
1967 int offset;
1968 ConstantPoolEntry::Access entry_access;
1969 if (!it->is_merged()) {
1970 // Emit new entry
1971 offset = assm->pc_offset() - base;
1972 entry_access = access;
1973 if (entry_size == kPointerSize) {
1974 assm->dp(it->value());
1975 } else {
1976 assm->dq(it->value64());
1977 }
1978 } else {
1979 // Retrieve offset from shared entry.
1980 offset = shared_entries[it->merged_index()].offset();
1981 entry_access = ConstantPoolEntry::REGULAR;
1982 }
1983
1984 DCHECK(entry_access == ConstantPoolEntry::OVERFLOWED ||
1985 is_uintn(offset, info.regular_reach_bits));
1986
1987 // Patch load sequence with correct offset.
1988 assm->PatchConstantPoolAccessInstruction(it->position(), offset,
1989 entry_access, type);
1990 }
1991}
1992
1993
1994// Emit and return position of pool. Zero implies no constant pool.
1995int ConstantPoolBuilder::Emit(Assembler* assm) {
1996 bool emitted = emitted_label_.is_bound();
1997 bool empty = IsEmpty();
1998
1999 if (!emitted) {
2000 // Mark start of constant pool. Align if necessary.
2001 if (!empty) assm->DataAlign(kDoubleSize);
2002 assm->bind(&emitted_label_);
2003 if (!empty) {
2004 // Emit in groups based on access and type.
2005 // Emit doubles first for alignment purposes.
2006 EmitGroup(assm, ConstantPoolEntry::REGULAR, ConstantPoolEntry::DOUBLE);
2007 EmitGroup(assm, ConstantPoolEntry::REGULAR, ConstantPoolEntry::INTPTR);
2008 if (info_[ConstantPoolEntry::DOUBLE].overflow()) {
2009 assm->DataAlign(kDoubleSize);
2010 EmitGroup(assm, ConstantPoolEntry::OVERFLOWED,
2011 ConstantPoolEntry::DOUBLE);
2012 }
2013 if (info_[ConstantPoolEntry::INTPTR].overflow()) {
2014 EmitGroup(assm, ConstantPoolEntry::OVERFLOWED,
2015 ConstantPoolEntry::INTPTR);
2016 }
2017 }
2018 }
2019
2020 return !empty ? emitted_label_.pos() : 0;
2021}
2022
2023
2024// Platform specific but identical code for all the platforms.
2025
2026
Ben Murdoch097c5b22016-05-18 11:27:45 +01002027void Assembler::RecordDeoptReason(const int reason, int raw_position) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002028 if (FLAG_trace_deopt || isolate()->cpu_profiler()->is_profiling()) {
2029 EnsureSpace ensure_space(this);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002030 RecordRelocInfo(RelocInfo::POSITION, raw_position);
2031 RecordRelocInfo(RelocInfo::DEOPT_REASON, reason);
2032 }
2033}
2034
2035
2036void Assembler::RecordComment(const char* msg) {
2037 if (FLAG_code_comments) {
2038 EnsureSpace ensure_space(this);
2039 RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg));
2040 }
2041}
2042
2043
2044void Assembler::RecordGeneratorContinuation() {
2045 EnsureSpace ensure_space(this);
2046 RecordRelocInfo(RelocInfo::GENERATOR_CONTINUATION);
2047}
2048
2049
2050void Assembler::RecordDebugBreakSlot(RelocInfo::Mode mode) {
2051 EnsureSpace ensure_space(this);
2052 DCHECK(RelocInfo::IsDebugBreakSlot(mode));
2053 RecordRelocInfo(mode);
2054}
2055
2056
2057void Assembler::DataAlign(int m) {
2058 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m));
2059 while ((pc_offset() & (m - 1)) != 0) {
2060 db(0);
2061 }
2062}
2063} // namespace internal
2064} // namespace v8