blob: a70530050ef23102b3335cfd254496e751207446 [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 Murdochb8a8cc12014-11-26 15:28:44 +000037#include <cmath>
38#include "src/api.h"
39#include "src/base/cpu.h"
40#include "src/base/lazy-instance.h"
41#include "src/base/platform/platform.h"
42#include "src/builtins.h"
43#include "src/codegen.h"
44#include "src/counters.h"
45#include "src/cpu-profiler.h"
46#include "src/debug.h"
47#include "src/deoptimizer.h"
48#include "src/execution.h"
49#include "src/ic/ic.h"
50#include "src/ic/stub-cache.h"
51#include "src/isolate-inl.h"
52#include "src/jsregexp.h"
53#include "src/regexp-macro-assembler.h"
54#include "src/regexp-stack.h"
55#include "src/runtime.h"
56#include "src/serialize.h"
57#include "src/token.h"
Ben Murdoch3ef787d2012-04-12 10:51:47 +010058
59#if V8_TARGET_ARCH_IA32
Ben Murdochb8a8cc12014-11-26 15:28:44 +000060#include "src/ia32/assembler-ia32-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010061#elif V8_TARGET_ARCH_X64
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062#include "src/x64/assembler-x64-inl.h" // NOLINT
63#elif V8_TARGET_ARCH_ARM64
64#include "src/arm64/assembler-arm64-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010065#elif V8_TARGET_ARCH_ARM
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066#include "src/arm/assembler-arm-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010067#elif V8_TARGET_ARCH_MIPS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000068#include "src/mips/assembler-mips-inl.h" // NOLINT
69#elif V8_TARGET_ARCH_MIPS64
70#include "src/mips64/assembler-mips64-inl.h" // NOLINT
71#elif V8_TARGET_ARCH_X87
72#include "src/x87/assembler-x87-inl.h" // NOLINT
Ben Murdoch3ef787d2012-04-12 10:51:47 +010073#else
74#error "Unknown architecture."
75#endif
76
Steve Blocka7e24c12009-10-30 11:49:00 +000077// Include native regexp-macro-assembler.
Steve Block6ded16b2010-05-10 14:33:55 +010078#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000079#if V8_TARGET_ARCH_IA32
Ben Murdochb8a8cc12014-11-26 15:28:44 +000080#include "src/ia32/regexp-macro-assembler-ia32.h" // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +000081#elif V8_TARGET_ARCH_X64
Ben Murdochb8a8cc12014-11-26 15:28:44 +000082#include "src/x64/regexp-macro-assembler-x64.h" // NOLINT
83#elif V8_TARGET_ARCH_ARM64
84#include "src/arm64/regexp-macro-assembler-arm64.h" // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +000085#elif V8_TARGET_ARCH_ARM
Ben Murdochb8a8cc12014-11-26 15:28:44 +000086#include "src/arm/regexp-macro-assembler-arm.h" // NOLINT
Steve Block44f0eee2011-05-26 01:26:41 +010087#elif V8_TARGET_ARCH_MIPS
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088#include "src/mips/regexp-macro-assembler-mips.h" // NOLINT
89#elif V8_TARGET_ARCH_MIPS64
90#include "src/mips64/regexp-macro-assembler-mips64.h" // NOLINT
91#elif V8_TARGET_ARCH_X87
92#include "src/x87/regexp-macro-assembler-x87.h" // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +000093#else // Unknown architecture.
94#error "Unknown architecture."
95#endif // Target architecture.
Steve Block6ded16b2010-05-10 14:33:55 +010096#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000097
98namespace v8 {
99namespace internal {
100
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100101// -----------------------------------------------------------------------------
102// Common double constants.
Steve Blocka7e24c12009-10-30 11:49:00 +0000103
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100104struct DoubleConstant BASE_EMBEDDED {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000105double min_int;
106double one_half;
107double minus_one_half;
108double negative_infinity;
109double canonical_non_hole_nan;
110double the_hole_nan;
111double uint32_bias;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100112};
113
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000114static DoubleConstant double_constants;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100115
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000116const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100117
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000118static bool math_exp_data_initialized = false;
119static base::Mutex* math_exp_data_mutex = NULL;
120static double* math_exp_constants_array = NULL;
121static double* math_exp_log_table_array = NULL;
122
Steve Blocka7e24c12009-10-30 11:49:00 +0000123// -----------------------------------------------------------------------------
Steve Block053d10c2011-06-13 19:13:29 +0100124// Implementation of AssemblerBase
125
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000126AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size)
Steve Block053d10c2011-06-13 19:13:29 +0100127 : isolate_(isolate),
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 jit_cookie_(0),
129 enabled_cpu_features_(0),
130 emit_debug_code_(FLAG_debug_code),
131 predictable_code_size_(false),
132 // We may use the assembler without an isolate.
133 serializer_enabled_(isolate && isolate->serializer_enabled()) {
Steve Block053d10c2011-06-13 19:13:29 +0100134 if (FLAG_mask_constants_with_cookie && isolate != NULL) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000135 jit_cookie_ = isolate->random_number_generator()->NextInt();
Steve Block053d10c2011-06-13 19:13:29 +0100136 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000137 own_buffer_ = buffer == NULL;
138 if (buffer_size == 0) buffer_size = kMinimalBufferSize;
139 DCHECK(buffer_size > 0);
140 if (own_buffer_) buffer = NewArray<byte>(buffer_size);
141 buffer_ = static_cast<byte*>(buffer);
142 buffer_size_ = buffer_size;
143
144 pc_ = buffer_;
Steve Block053d10c2011-06-13 19:13:29 +0100145}
146
147
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000148AssemblerBase::~AssemblerBase() {
149 if (own_buffer_) DeleteArray(buffer_);
150}
151
152
153// -----------------------------------------------------------------------------
154// Implementation of PredictableCodeSizeScope
155
156PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler,
157 int expected_size)
158 : assembler_(assembler),
159 expected_size_(expected_size),
160 start_offset_(assembler->pc_offset()),
161 old_value_(assembler->predictable_code_size()) {
162 assembler_->set_predictable_code_size(true);
163}
164
165
166PredictableCodeSizeScope::~PredictableCodeSizeScope() {
167 // TODO(svenpanne) Remove the 'if' when everything works.
168 if (expected_size_ >= 0) {
169 CHECK_EQ(expected_size_, assembler_->pc_offset() - start_offset_);
170 }
171 assembler_->set_predictable_code_size(old_value_);
172}
173
174
175// -----------------------------------------------------------------------------
176// Implementation of CpuFeatureScope
177
178#ifdef DEBUG
179CpuFeatureScope::CpuFeatureScope(AssemblerBase* assembler, CpuFeature f)
180 : assembler_(assembler) {
181 DCHECK(CpuFeatures::IsSupported(f));
182 old_enabled_ = assembler_->enabled_cpu_features();
183 uint64_t mask = static_cast<uint64_t>(1) << f;
184 // TODO(svenpanne) This special case below doesn't belong here!
185#if V8_TARGET_ARCH_ARM
186 // ARMv7 is implied by VFP3.
187 if (f == VFP3) {
188 mask |= static_cast<uint64_t>(1) << ARMv7;
189 }
190#endif
191 assembler_->set_enabled_cpu_features(old_enabled_ | mask);
192}
193
194
195CpuFeatureScope::~CpuFeatureScope() {
196 assembler_->set_enabled_cpu_features(old_enabled_);
197}
198#endif
199
200
201bool CpuFeatures::initialized_ = false;
202unsigned CpuFeatures::supported_ = 0;
203unsigned CpuFeatures::cache_line_size_ = 0;
204
205
Steve Block053d10c2011-06-13 19:13:29 +0100206// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000207// Implementation of Label
208
209int Label::pos() const {
210 if (pos_ < 0) return -pos_ - 1;
211 if (pos_ > 0) return pos_ - 1;
212 UNREACHABLE();
213 return 0;
214}
215
216
217// -----------------------------------------------------------------------------
218// Implementation of RelocInfoWriter and RelocIterator
219//
Ben Murdoch257744e2011-11-30 15:57:28 +0000220// Relocation information is written backwards in memory, from high addresses
221// towards low addresses, byte by byte. Therefore, in the encodings listed
222// below, the first byte listed it at the highest address, and successive
223// bytes in the record are at progressively lower addresses.
224//
Steve Blocka7e24c12009-10-30 11:49:00 +0000225// Encoding
226//
227// The most common modes are given single-byte encodings. Also, it is
228// easy to identify the type of reloc info and skip unwanted modes in
229// an iteration.
230//
Ben Murdoch257744e2011-11-30 15:57:28 +0000231// The encoding relies on the fact that there are fewer than 14
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000232// different relocation modes using standard non-compact encoding.
Steve Blocka7e24c12009-10-30 11:49:00 +0000233//
Ben Murdoch257744e2011-11-30 15:57:28 +0000234// The first byte of a relocation record has a tag in its low 2 bits:
235// Here are the record schemes, depending on the low tag and optional higher
236// tags.
Steve Blocka7e24c12009-10-30 11:49:00 +0000237//
Ben Murdoch257744e2011-11-30 15:57:28 +0000238// Low tag:
239// 00: embedded_object: [6-bit pc delta] 00
Steve Blocka7e24c12009-10-30 11:49:00 +0000240//
Ben Murdoch257744e2011-11-30 15:57:28 +0000241// 01: code_target: [6-bit pc delta] 01
Steve Blocka7e24c12009-10-30 11:49:00 +0000242//
Ben Murdoch257744e2011-11-30 15:57:28 +0000243// 10: short_data_record: [6-bit pc delta] 10 followed by
244// [6-bit data delta] [2-bit data type tag]
Steve Blocka7e24c12009-10-30 11:49:00 +0000245//
Ben Murdoch257744e2011-11-30 15:57:28 +0000246// 11: long_record [2-bit high tag][4 bit middle_tag] 11
247// followed by variable data depending on type.
Steve Blocka7e24c12009-10-30 11:49:00 +0000248//
Ben Murdoch257744e2011-11-30 15:57:28 +0000249// 2-bit data type tags, used in short_data_record and data_jump long_record:
250// code_target_with_id: 00
251// position: 01
252// statement_position: 10
253// comment: 11 (not used in short_data_record)
Steve Blocka7e24c12009-10-30 11:49:00 +0000254//
Ben Murdoch257744e2011-11-30 15:57:28 +0000255// Long record format:
256// 4-bit middle_tag:
257// 0000 - 1100 : Short record for RelocInfo::Mode middle_tag + 2
258// (The middle_tag encodes rmode - RelocInfo::LAST_COMPACT_ENUM,
259// and is between 0000 and 1100)
260// The format is:
261// 00 [4 bit middle_tag] 11 followed by
262// 00 [6 bit pc delta]
Steve Blocka7e24c12009-10-30 11:49:00 +0000263//
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000264// 1101: constant or veneer pool. Used only on ARM and ARM64 for now.
265// The format is: [2-bit sub-type] 1101 11
266// signed int (size of the pool).
267// The 2-bit sub-types are:
268// 00: constant pool
269// 01: veneer pool
Ben Murdoch257744e2011-11-30 15:57:28 +0000270// 1110: long_data_record
271// The format is: [2-bit data_type_tag] 1110 11
272// signed intptr_t, lowest byte written first
273// (except data_type code_target_with_id, which
274// is followed by a signed int, not intptr_t.)
Steve Blocka7e24c12009-10-30 11:49:00 +0000275//
Ben Murdoch257744e2011-11-30 15:57:28 +0000276// 1111: long_pc_jump
277// The format is:
278// pc-jump: 00 1111 11,
279// 00 [6 bits pc delta]
280// or
281// pc-jump (variable length):
282// 01 1111 11,
283// [7 bits data] 0
284// ...
285// [7 bits data] 1
286// (Bits 6..31 of pc delta, with leading zeroes
287// dropped, and last non-zero chunk tagged with 1.)
288
289
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000290#ifdef DEBUG
291const int kMaxStandardNonCompactModes = 14;
292#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000293
294const int kTagBits = 2;
295const int kTagMask = (1 << kTagBits) - 1;
296const int kExtraTagBits = 4;
Ben Murdoch257744e2011-11-30 15:57:28 +0000297const int kLocatableTypeTagBits = 2;
298const int kSmallDataBits = kBitsPerByte - kLocatableTypeTagBits;
Steve Blocka7e24c12009-10-30 11:49:00 +0000299
300const int kEmbeddedObjectTag = 0;
301const int kCodeTargetTag = 1;
Ben Murdoch257744e2011-11-30 15:57:28 +0000302const int kLocatableTag = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000303const int kDefaultTag = 3;
304
Ben Murdoch257744e2011-11-30 15:57:28 +0000305const int kPCJumpExtraTag = (1 << kExtraTagBits) - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000306
307const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
308const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100309const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000310
311const int kVariableLengthPCJumpTopTag = 1;
312const int kChunkBits = 7;
313const int kChunkMask = (1 << kChunkBits) - 1;
314const int kLastChunkTagBits = 1;
315const int kLastChunkTagMask = 1;
316const int kLastChunkTag = 1;
317
318
Ben Murdoch257744e2011-11-30 15:57:28 +0000319const int kDataJumpExtraTag = kPCJumpExtraTag - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000320
Ben Murdoch257744e2011-11-30 15:57:28 +0000321const int kCodeWithIdTag = 0;
322const int kNonstatementPositionTag = 1;
323const int kStatementPositionTag = 2;
324const int kCommentTag = 3;
Steve Blocka7e24c12009-10-30 11:49:00 +0000325
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000326const int kPoolExtraTag = kPCJumpExtraTag - 2;
327const int kConstPoolTag = 0;
328const int kVeneerPoolTag = 1;
329
Steve Blocka7e24c12009-10-30 11:49:00 +0000330
331uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
332 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
333 // Otherwise write a variable length PC jump for the bits that do
334 // not fit in the kSmallPCDeltaBits bits.
335 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
Ben Murdoch257744e2011-11-30 15:57:28 +0000336 WriteExtraTag(kPCJumpExtraTag, kVariableLengthPCJumpTopTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000337 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000338 DCHECK(pc_jump > 0);
Steve Blocka7e24c12009-10-30 11:49:00 +0000339 // Write kChunkBits size chunks of the pc_jump.
340 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
341 byte b = pc_jump & kChunkMask;
342 *--pos_ = b << kLastChunkTagBits;
343 }
344 // Tag the last chunk so it can be identified.
345 *pos_ = *pos_ | kLastChunkTag;
346 // Return the remaining kSmallPCDeltaBits of the pc_delta.
347 return pc_delta & kSmallPCDeltaMask;
348}
349
350
351void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
352 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
353 pc_delta = WriteVariableLengthPCJump(pc_delta);
354 *--pos_ = pc_delta << kTagBits | tag;
355}
356
357
358void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000359 *--pos_ = static_cast<byte>(data_delta << kLocatableTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000360}
361
362
363void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000364 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
365 extra_tag << kTagBits |
366 kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000367}
368
369
370void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
371 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
372 pc_delta = WriteVariableLengthPCJump(pc_delta);
373 WriteExtraTag(extra_tag, 0);
374 *--pos_ = pc_delta;
375}
376
377
Ben Murdoch257744e2011-11-30 15:57:28 +0000378void RelocInfoWriter::WriteExtraTaggedIntData(int data_delta, int top_tag) {
379 WriteExtraTag(kDataJumpExtraTag, top_tag);
380 for (int i = 0; i < kIntSize; i++) {
381 *--pos_ = static_cast<byte>(data_delta);
382 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
383 data_delta = data_delta >> kBitsPerByte;
384 }
385}
386
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387
388void RelocInfoWriter::WriteExtraTaggedPoolData(int data, int pool_type) {
389 WriteExtraTag(kPoolExtraTag, pool_type);
390 for (int i = 0; i < kIntSize; i++) {
391 *--pos_ = static_cast<byte>(data);
392 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
393 data = data >> kBitsPerByte;
394 }
395}
396
397
Steve Blocka7e24c12009-10-30 11:49:00 +0000398void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000399 WriteExtraTag(kDataJumpExtraTag, top_tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000400 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000401 *--pos_ = static_cast<byte>(data_delta);
Ben Murdoch257744e2011-11-30 15:57:28 +0000402 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 data_delta = data_delta >> kBitsPerByte;
404 }
405}
406
407
408void RelocInfoWriter::Write(const RelocInfo* rinfo) {
409#ifdef DEBUG
410 byte* begin_pos = pos_;
411#endif
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000412 DCHECK(rinfo->rmode() < RelocInfo::NUMBER_OF_MODES);
413 DCHECK(rinfo->pc() - last_pc_ >= 0);
414 DCHECK(RelocInfo::LAST_STANDARD_NONCOMPACT_ENUM - RelocInfo::LAST_COMPACT_ENUM
415 <= kMaxStandardNonCompactModes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000417 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000418 RelocInfo::Mode rmode = rinfo->rmode();
419
420 // The two most common modes are given small tags, and usually fit in a byte.
421 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
422 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
423 } else if (rmode == RelocInfo::CODE_TARGET) {
424 WriteTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425 DCHECK(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Ben Murdoch257744e2011-11-30 15:57:28 +0000426 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
427 // Use signed delta-encoding for id.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000428 DCHECK(static_cast<int>(rinfo->data()) == rinfo->data());
Ben Murdoch257744e2011-11-30 15:57:28 +0000429 int id_delta = static_cast<int>(rinfo->data()) - last_id_;
430 // Check if delta is small enough to fit in a tagged byte.
431 if (is_intn(id_delta, kSmallDataBits)) {
432 WriteTaggedPC(pc_delta, kLocatableTag);
433 WriteTaggedData(id_delta, kCodeWithIdTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 } else {
435 // Otherwise, use costly encoding.
Ben Murdoch257744e2011-11-30 15:57:28 +0000436 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
437 WriteExtraTaggedIntData(id_delta, kCodeWithIdTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000438 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000439 last_id_ = static_cast<int>(rinfo->data());
440 } else if (RelocInfo::IsPosition(rmode)) {
441 // Use signed delta-encoding for position.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000442 DCHECK(static_cast<int>(rinfo->data()) == rinfo->data());
Ben Murdoch257744e2011-11-30 15:57:28 +0000443 int pos_delta = static_cast<int>(rinfo->data()) - last_position_;
444 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag
445 : kStatementPositionTag;
446 // Check if delta is small enough to fit in a tagged byte.
447 if (is_intn(pos_delta, kSmallDataBits)) {
448 WriteTaggedPC(pc_delta, kLocatableTag);
449 WriteTaggedData(pos_delta, pos_type_tag);
450 } else {
451 // Otherwise, use costly encoding.
452 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
453 WriteExtraTaggedIntData(pos_delta, pos_type_tag);
454 }
455 last_position_ = static_cast<int>(rinfo->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000456 } else if (RelocInfo::IsComment(rmode)) {
457 // Comments are normally not generated, so we use the costly encoding.
Ben Murdoch257744e2011-11-30 15:57:28 +0000458 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
459 WriteExtraTaggedData(rinfo->data(), kCommentTag);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000460 DCHECK(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize);
461 } else if (RelocInfo::IsConstPool(rmode) || RelocInfo::IsVeneerPool(rmode)) {
462 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
463 WriteExtraTaggedPoolData(static_cast<int>(rinfo->data()),
464 RelocInfo::IsConstPool(rmode) ? kConstPoolTag
465 : kVeneerPoolTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000466 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000467 DCHECK(rmode > RelocInfo::LAST_COMPACT_ENUM);
Ben Murdoch257744e2011-11-30 15:57:28 +0000468 int saved_mode = rmode - RelocInfo::LAST_COMPACT_ENUM;
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 // For all other modes we simply use the mode as the extra tag.
470 // None of these modes need a data component.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000471 DCHECK(saved_mode < kPCJumpExtraTag && saved_mode < kDataJumpExtraTag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000472 WriteExtraTaggedPC(pc_delta, saved_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000473 }
474 last_pc_ = rinfo->pc();
475#ifdef DEBUG
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000476 DCHECK(begin_pos - pos_ <= kMaxSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000477#endif
478}
479
480
481inline int RelocIterator::AdvanceGetTag() {
482 return *--pos_ & kTagMask;
483}
484
485
486inline int RelocIterator::GetExtraTag() {
487 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
488}
489
490
491inline int RelocIterator::GetTopTag() {
492 return *pos_ >> (kTagBits + kExtraTagBits);
493}
494
495
496inline void RelocIterator::ReadTaggedPC() {
497 rinfo_.pc_ += *pos_ >> kTagBits;
498}
499
500
501inline void RelocIterator::AdvanceReadPC() {
502 rinfo_.pc_ += *--pos_;
503}
504
505
Ben Murdoch257744e2011-11-30 15:57:28 +0000506void RelocIterator::AdvanceReadId() {
507 int x = 0;
508 for (int i = 0; i < kIntSize; i++) {
509 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
510 }
511 last_id_ += x;
512 rinfo_.data_ = last_id_;
513}
514
515
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000516void RelocIterator::AdvanceReadPoolData() {
517 int x = 0;
518 for (int i = 0; i < kIntSize; i++) {
519 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
520 }
521 rinfo_.data_ = x;
522}
523
524
Ben Murdoch257744e2011-11-30 15:57:28 +0000525void RelocIterator::AdvanceReadPosition() {
526 int x = 0;
527 for (int i = 0; i < kIntSize; i++) {
528 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
529 }
530 last_position_ += x;
531 rinfo_.data_ = last_position_;
532}
533
534
Steve Blocka7e24c12009-10-30 11:49:00 +0000535void RelocIterator::AdvanceReadData() {
536 intptr_t x = 0;
537 for (int i = 0; i < kIntptrSize; i++) {
538 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
539 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000540 rinfo_.data_ = x;
Steve Blocka7e24c12009-10-30 11:49:00 +0000541}
542
543
544void RelocIterator::AdvanceReadVariableLengthPCJump() {
545 // Read the 32-kSmallPCDeltaBits most significant bits of the
546 // pc jump in kChunkBits bit chunks and shift them into place.
547 // Stop when the last chunk is encountered.
548 uint32_t pc_jump = 0;
549 for (int i = 0; i < kIntSize; i++) {
550 byte pc_jump_part = *--pos_;
551 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
552 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
553 }
554 // The least significant kSmallPCDeltaBits bits will be added
555 // later.
556 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
557}
558
559
Ben Murdoch257744e2011-11-30 15:57:28 +0000560inline int RelocIterator::GetLocatableTypeTag() {
561 return *pos_ & ((1 << kLocatableTypeTagBits) - 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000562}
563
564
Ben Murdoch257744e2011-11-30 15:57:28 +0000565inline void RelocIterator::ReadTaggedId() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000566 int8_t signed_b = *pos_;
567 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Ben Murdoch257744e2011-11-30 15:57:28 +0000568 last_id_ += signed_b >> kLocatableTypeTagBits;
569 rinfo_.data_ = last_id_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000570}
571
572
Ben Murdoch257744e2011-11-30 15:57:28 +0000573inline void RelocIterator::ReadTaggedPosition() {
574 int8_t signed_b = *pos_;
575 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
576 last_position_ += signed_b >> kLocatableTypeTagBits;
577 rinfo_.data_ = last_position_;
578}
579
580
581static inline RelocInfo::Mode GetPositionModeFromTag(int tag) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000582 DCHECK(tag == kNonstatementPositionTag ||
Ben Murdoch257744e2011-11-30 15:57:28 +0000583 tag == kStatementPositionTag);
584 return (tag == kNonstatementPositionTag) ?
585 RelocInfo::POSITION :
586 RelocInfo::STATEMENT_POSITION;
Steve Blocka7e24c12009-10-30 11:49:00 +0000587}
588
589
590void RelocIterator::next() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000591 DCHECK(!done());
Steve Blocka7e24c12009-10-30 11:49:00 +0000592 // Basically, do the opposite of RelocInfoWriter::Write.
593 // Reading of data is as far as possible avoided for unwanted modes,
594 // but we must always update the pc.
595 //
596 // We exit this loop by returning when we find a mode we want.
597 while (pos_ > end_) {
598 int tag = AdvanceGetTag();
599 if (tag == kEmbeddedObjectTag) {
600 ReadTaggedPC();
601 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
602 } else if (tag == kCodeTargetTag) {
603 ReadTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000604 if (SetMode(RelocInfo::CODE_TARGET)) return;
Ben Murdoch257744e2011-11-30 15:57:28 +0000605 } else if (tag == kLocatableTag) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000606 ReadTaggedPC();
607 Advance();
Ben Murdoch257744e2011-11-30 15:57:28 +0000608 int locatable_tag = GetLocatableTypeTag();
609 if (locatable_tag == kCodeWithIdTag) {
610 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
611 ReadTaggedId();
612 return;
613 }
614 } else {
615 // Compact encoding is never used for comments,
616 // so it must be a position.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000617 DCHECK(locatable_tag == kNonstatementPositionTag ||
Ben Murdoch257744e2011-11-30 15:57:28 +0000618 locatable_tag == kStatementPositionTag);
619 if (mode_mask_ & RelocInfo::kPositionMask) {
620 ReadTaggedPosition();
621 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
622 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000623 }
624 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000625 DCHECK(tag == kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000626 int extra_tag = GetExtraTag();
Ben Murdoch257744e2011-11-30 15:57:28 +0000627 if (extra_tag == kPCJumpExtraTag) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000628 if (GetTopTag() == kVariableLengthPCJumpTopTag) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000629 AdvanceReadVariableLengthPCJump();
630 } else {
631 AdvanceReadPC();
632 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000633 } else if (extra_tag == kDataJumpExtraTag) {
634 int locatable_tag = GetTopTag();
635 if (locatable_tag == kCodeWithIdTag) {
636 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
637 AdvanceReadId();
638 return;
639 }
640 Advance(kIntSize);
641 } else if (locatable_tag != kCommentTag) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000642 DCHECK(locatable_tag == kNonstatementPositionTag ||
Ben Murdoch257744e2011-11-30 15:57:28 +0000643 locatable_tag == kStatementPositionTag);
644 if (mode_mask_ & RelocInfo::kPositionMask) {
645 AdvanceReadPosition();
646 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
647 } else {
648 Advance(kIntSize);
649 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000650 } else {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000651 DCHECK(locatable_tag == kCommentTag);
Ben Murdoch257744e2011-11-30 15:57:28 +0000652 if (SetMode(RelocInfo::COMMENT)) {
653 AdvanceReadData();
654 return;
655 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000656 Advance(kIntptrSize);
657 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000658 } else if (extra_tag == kPoolExtraTag) {
659 int pool_type = GetTopTag();
660 DCHECK(pool_type == kConstPoolTag || pool_type == kVeneerPoolTag);
661 RelocInfo::Mode rmode = (pool_type == kConstPoolTag) ?
662 RelocInfo::CONST_POOL : RelocInfo::VENEER_POOL;
663 if (SetMode(rmode)) {
664 AdvanceReadPoolData();
665 return;
666 }
667 Advance(kIntSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000668 } else {
669 AdvanceReadPC();
Ben Murdoch257744e2011-11-30 15:57:28 +0000670 int rmode = extra_tag + RelocInfo::LAST_COMPACT_ENUM;
671 if (SetMode(static_cast<RelocInfo::Mode>(rmode))) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000672 }
673 }
674 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000675 if (code_age_sequence_ != NULL) {
676 byte* old_code_age_sequence = code_age_sequence_;
677 code_age_sequence_ = NULL;
678 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) {
679 rinfo_.data_ = 0;
680 rinfo_.pc_ = old_code_age_sequence;
681 return;
682 }
683 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000684 done_ = true;
685}
686
687
688RelocIterator::RelocIterator(Code* code, int mode_mask) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100689 rinfo_.host_ = code;
Steve Blocka7e24c12009-10-30 11:49:00 +0000690 rinfo_.pc_ = code->instruction_start();
691 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100692 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000693 pos_ = code->relocation_start() + code->relocation_size();
694 end_ = code->relocation_start();
695 done_ = false;
696 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000697 last_id_ = 0;
698 last_position_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000699 byte* sequence = code->FindCodeAgeSequence();
700 // We get the isolate from the map, because at serialization time
701 // the code pointer has been cloned and isn't really in heap space.
702 Isolate* isolate = code->map()->GetIsolate();
703 if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) {
704 code_age_sequence_ = sequence;
705 } else {
706 code_age_sequence_ = NULL;
707 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000708 if (mode_mask_ == 0) pos_ = end_;
709 next();
710}
711
712
713RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
714 rinfo_.pc_ = desc.buffer;
715 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100716 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000717 pos_ = desc.buffer + desc.buffer_size;
718 end_ = pos_ - desc.reloc_size;
719 done_ = false;
720 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000721 last_id_ = 0;
722 last_position_ = 0;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000723 code_age_sequence_ = NULL;
Steve Blocka7e24c12009-10-30 11:49:00 +0000724 if (mode_mask_ == 0) pos_ = end_;
725 next();
726}
727
728
729// -----------------------------------------------------------------------------
730// Implementation of RelocInfo
731
732
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000733#ifdef DEBUG
734bool RelocInfo::RequiresRelocation(const CodeDesc& desc) {
735 // Ensure there are no code targets or embedded objects present in the
736 // deoptimization entries, they would require relocation after code
737 // generation.
738 int mode_mask = RelocInfo::kCodeTargetMask |
739 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
740 RelocInfo::ModeMask(RelocInfo::CELL) |
741 RelocInfo::kApplyMask;
742 RelocIterator it(desc, mode_mask);
743 return !it.done();
744}
745#endif
746
747
Steve Blocka7e24c12009-10-30 11:49:00 +0000748#ifdef ENABLE_DISASSEMBLER
749const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
750 switch (rmode) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000751 case RelocInfo::NONE32:
752 return "no reloc 32";
753 case RelocInfo::NONE64:
754 return "no reloc 64";
Steve Blocka7e24c12009-10-30 11:49:00 +0000755 case RelocInfo::EMBEDDED_OBJECT:
756 return "embedded object";
Steve Blocka7e24c12009-10-30 11:49:00 +0000757 case RelocInfo::CONSTRUCT_CALL:
758 return "code target (js construct call)";
Andrei Popescu402d9372010-02-26 13:31:12 +0000759 case RelocInfo::DEBUG_BREAK:
Andrei Popescu402d9372010-02-26 13:31:12 +0000760 return "debug break";
Steve Blocka7e24c12009-10-30 11:49:00 +0000761 case RelocInfo::CODE_TARGET:
762 return "code target";
Ben Murdoch257744e2011-11-30 15:57:28 +0000763 case RelocInfo::CODE_TARGET_WITH_ID:
764 return "code target with id";
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000765 case RelocInfo::CELL:
766 return "property cell";
Steve Blocka7e24c12009-10-30 11:49:00 +0000767 case RelocInfo::RUNTIME_ENTRY:
768 return "runtime entry";
769 case RelocInfo::JS_RETURN:
770 return "js return";
771 case RelocInfo::COMMENT:
772 return "comment";
773 case RelocInfo::POSITION:
774 return "position";
775 case RelocInfo::STATEMENT_POSITION:
776 return "statement position";
777 case RelocInfo::EXTERNAL_REFERENCE:
778 return "external reference";
779 case RelocInfo::INTERNAL_REFERENCE:
780 return "internal reference";
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000781 case RelocInfo::CONST_POOL:
782 return "constant pool";
783 case RelocInfo::VENEER_POOL:
784 return "veneer pool";
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100785 case RelocInfo::DEBUG_BREAK_SLOT:
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100786 return "debug break slot";
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000787 case RelocInfo::CODE_AGE_SEQUENCE:
788 return "code_age_sequence";
Steve Blocka7e24c12009-10-30 11:49:00 +0000789 case RelocInfo::NUMBER_OF_MODES:
790 UNREACHABLE();
791 return "number_of_modes";
792 }
793 return "unknown relocation type";
794}
795
796
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000797void RelocInfo::Print(Isolate* isolate, OStream& os) { // NOLINT
798 os << pc_ << " " << RelocModeName(rmode_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000799 if (IsComment(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000800 os << " (" << reinterpret_cast<char*>(data_) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000801 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000802 os << " (" << Brief(target_object()) << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000803 } else if (rmode_ == EXTERNAL_REFERENCE) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000804 ExternalReferenceEncoder ref_encoder(isolate);
805 os << " (" << ref_encoder.NameOfAddress(target_reference()) << ") ("
806 << target_reference() << ")";
Steve Blocka7e24c12009-10-30 11:49:00 +0000807 } else if (IsCodeTarget(rmode_)) {
808 Code* code = Code::GetCodeFromTargetAddress(target_address());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000809 os << " (" << Code::Kind2String(code->kind()) << ") (" << target_address()
810 << ")";
Ben Murdoch257744e2011-11-30 15:57:28 +0000811 if (rmode_ == CODE_TARGET_WITH_ID) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000812 os << " (id=" << static_cast<int>(data_) << ")";
Ben Murdoch257744e2011-11-30 15:57:28 +0000813 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000814 } else if (IsPosition(rmode_)) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000815 os << " (" << data() << ")";
816 } else if (IsRuntimeEntry(rmode_) &&
817 isolate->deoptimizer_data() != NULL) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100818 // Depotimization bailouts are stored as runtime entries.
819 int id = Deoptimizer::GetDeoptimizationId(
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000820 isolate, target_address(), Deoptimizer::EAGER);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100821 if (id != Deoptimizer::kNotDeoptimizationEntry) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000822 os << " (deoptimization bailout " << id << ")";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100823 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000824 }
825
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000826 os << "\n";
Steve Blocka7e24c12009-10-30 11:49:00 +0000827}
828#endif // ENABLE_DISASSEMBLER
829
830
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000831#ifdef VERIFY_HEAP
832void RelocInfo::Verify(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000833 switch (rmode_) {
834 case EMBEDDED_OBJECT:
835 Object::VerifyPointer(target_object());
836 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000837 case CELL:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100838 Object::VerifyPointer(target_cell());
839 break;
Andrei Popescu402d9372010-02-26 13:31:12 +0000840 case DEBUG_BREAK:
Steve Blocka7e24c12009-10-30 11:49:00 +0000841 case CONSTRUCT_CALL:
Ben Murdoch257744e2011-11-30 15:57:28 +0000842 case CODE_TARGET_WITH_ID:
Steve Blocka7e24c12009-10-30 11:49:00 +0000843 case CODE_TARGET: {
844 // convert inline target address to code object
845 Address addr = target_address();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000846 CHECK(addr != NULL);
Steve Blocka7e24c12009-10-30 11:49:00 +0000847 // Check that we can find the right code object.
848 Code* code = Code::GetCodeFromTargetAddress(addr);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000849 Object* found = isolate->FindCodeObject(addr);
850 CHECK(found->IsCode());
851 CHECK(code->address() == HeapObject::cast(found)->address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000852 break;
853 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000854 case RUNTIME_ENTRY:
855 case JS_RETURN:
856 case COMMENT:
857 case POSITION:
858 case STATEMENT_POSITION:
859 case EXTERNAL_REFERENCE:
860 case INTERNAL_REFERENCE:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000861 case CONST_POOL:
862 case VENEER_POOL:
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100863 case DEBUG_BREAK_SLOT:
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000864 case NONE32:
865 case NONE64:
Steve Blocka7e24c12009-10-30 11:49:00 +0000866 break;
867 case NUMBER_OF_MODES:
868 UNREACHABLE();
869 break;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000870 case CODE_AGE_SEQUENCE:
871 DCHECK(Code::IsYoungSequence(isolate, pc_) || code_age_stub()->IsCode());
872 break;
Steve Blocka7e24c12009-10-30 11:49:00 +0000873 }
874}
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000875#endif // VERIFY_HEAP
Steve Blocka7e24c12009-10-30 11:49:00 +0000876
877
878// -----------------------------------------------------------------------------
879// Implementation of ExternalReference
880
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000881void ExternalReference::SetUp() {
882 double_constants.min_int = kMinInt;
883 double_constants.one_half = 0.5;
884 double_constants.minus_one_half = -0.5;
885 double_constants.canonical_non_hole_nan = base::OS::nan_value();
886 double_constants.the_hole_nan = bit_cast<double>(kHoleNanInt64);
887 double_constants.negative_infinity = -V8_INFINITY;
888 double_constants.uint32_bias =
889 static_cast<double>(static_cast<uint32_t>(0xFFFFFFFF)) + 1;
890
891 math_exp_data_mutex = new base::Mutex();
892}
893
894
895void ExternalReference::InitializeMathExpData() {
896 // Early return?
897 if (math_exp_data_initialized) return;
898
899 base::LockGuard<base::Mutex> lock_guard(math_exp_data_mutex);
900 if (!math_exp_data_initialized) {
901 // If this is changed, generated code must be adapted too.
902 const int kTableSizeBits = 11;
903 const int kTableSize = 1 << kTableSizeBits;
904 const double kTableSizeDouble = static_cast<double>(kTableSize);
905
906 math_exp_constants_array = new double[9];
907 // Input values smaller than this always return 0.
908 math_exp_constants_array[0] = -708.39641853226408;
909 // Input values larger than this always return +Infinity.
910 math_exp_constants_array[1] = 709.78271289338397;
911 math_exp_constants_array[2] = V8_INFINITY;
912 // The rest is black magic. Do not attempt to understand it. It is
913 // loosely based on the "expd" function published at:
914 // http://herumi.blogspot.com/2011/08/fast-double-precision-exponential.html
915 const double constant3 = (1 << kTableSizeBits) / std::log(2.0);
916 math_exp_constants_array[3] = constant3;
917 math_exp_constants_array[4] =
918 static_cast<double>(static_cast<int64_t>(3) << 51);
919 math_exp_constants_array[5] = 1 / constant3;
920 math_exp_constants_array[6] = 3.0000000027955394;
921 math_exp_constants_array[7] = 0.16666666685227835;
922 math_exp_constants_array[8] = 1;
923
924 math_exp_log_table_array = new double[kTableSize];
925 for (int i = 0; i < kTableSize; i++) {
926 double value = std::pow(2, i / kTableSizeDouble);
927 uint64_t bits = bit_cast<uint64_t, double>(value);
928 bits &= (static_cast<uint64_t>(1) << 52) - 1;
929 double mantissa = bit_cast<double, uint64_t>(bits);
930 math_exp_log_table_array[i] = mantissa;
931 }
932
933 math_exp_data_initialized = true;
934 }
935}
936
937
938void ExternalReference::TearDownMathExpData() {
939 delete[] math_exp_constants_array;
940 math_exp_constants_array = NULL;
941 delete[] math_exp_log_table_array;
942 math_exp_log_table_array = NULL;
943 delete math_exp_data_mutex;
944 math_exp_data_mutex = NULL;
945}
946
947
Steve Block44f0eee2011-05-26 01:26:41 +0100948ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
949 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000950
951
Steve Block1e0659c2011-05-24 12:43:12 +0100952ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100953 ApiFunction* fun,
954 Type type = ExternalReference::BUILTIN_CALL,
955 Isolate* isolate = NULL)
956 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +0000957
958
Steve Block44f0eee2011-05-26 01:26:41 +0100959ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
960 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000961
962
Steve Block44f0eee2011-05-26 01:26:41 +0100963ExternalReference::ExternalReference(Runtime::FunctionId id,
964 Isolate* isolate)
965 : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000966
967
Steve Block44f0eee2011-05-26 01:26:41 +0100968ExternalReference::ExternalReference(const Runtime::Function* f,
969 Isolate* isolate)
970 : address_(Redirect(isolate, f->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000971
972
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000973ExternalReference ExternalReference::isolate_address(Isolate* isolate) {
974 return ExternalReference(isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100975}
976
977
978ExternalReference::ExternalReference(const IC_Utility& ic_utility,
979 Isolate* isolate)
980 : address_(Redirect(isolate, ic_utility.address())) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000981
Steve Blocka7e24c12009-10-30 11:49:00 +0000982
983ExternalReference::ExternalReference(StatsCounter* counter)
984 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
985
986
Steve Block44f0eee2011-05-26 01:26:41 +0100987ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
988 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000989
990
991ExternalReference::ExternalReference(const SCTableReference& table_ref)
992 : address_(table_ref.address()) {}
993
994
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100995ExternalReference ExternalReference::
996 incremental_marking_record_write_function(Isolate* isolate) {
997 return ExternalReference(Redirect(
998 isolate,
999 FUNCTION_ADDR(IncrementalMarking::RecordWriteFromCode)));
1000}
1001
1002
1003ExternalReference ExternalReference::
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001004 store_buffer_overflow_function(Isolate* isolate) {
1005 return ExternalReference(Redirect(
1006 isolate,
1007 FUNCTION_ADDR(StoreBuffer::StoreBufferOverflow)));
1008}
1009
1010
1011ExternalReference ExternalReference::flush_icache_function(Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001012 return ExternalReference(
1013 Redirect(isolate, FUNCTION_ADDR(CpuFeatures::FlushICache)));
Steve Block6ded16b2010-05-10 14:33:55 +01001014}
1015
1016
Steve Block44f0eee2011-05-26 01:26:41 +01001017ExternalReference ExternalReference::delete_handle_scope_extensions(
1018 Isolate* isolate) {
1019 return ExternalReference(Redirect(
1020 isolate,
1021 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -07001022}
1023
1024
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001025ExternalReference ExternalReference::get_date_field_function(
1026 Isolate* isolate) {
1027 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(JSDate::GetField)));
1028}
1029
1030
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001031ExternalReference ExternalReference::get_make_code_young_function(
1032 Isolate* isolate) {
1033 return ExternalReference(Redirect(
1034 isolate, FUNCTION_ADDR(Code::MakeCodeAgeSequenceYoung)));
1035}
1036
1037
1038ExternalReference ExternalReference::get_mark_code_as_executed_function(
1039 Isolate* isolate) {
1040 return ExternalReference(Redirect(
1041 isolate, FUNCTION_ADDR(Code::MarkCodeAsExecuted)));
1042}
1043
1044
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001045ExternalReference ExternalReference::date_cache_stamp(Isolate* isolate) {
1046 return ExternalReference(isolate->date_cache()->stamp_address());
1047}
1048
1049
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001050ExternalReference ExternalReference::stress_deopt_count(Isolate* isolate) {
1051 return ExternalReference(isolate->stress_deopt_count_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +01001052}
1053
1054
Steve Block44f0eee2011-05-26 01:26:41 +01001055ExternalReference ExternalReference::new_deoptimizer_function(
1056 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +01001057 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001058 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001059}
1060
1061
Steve Block44f0eee2011-05-26 01:26:41 +01001062ExternalReference ExternalReference::compute_output_frames_function(
1063 Isolate* isolate) {
1064 return ExternalReference(
1065 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001066}
1067
1068
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001069ExternalReference ExternalReference::log_enter_external_function(
1070 Isolate* isolate) {
1071 return ExternalReference(
1072 Redirect(isolate, FUNCTION_ADDR(Logger::EnterExternal)));
1073}
1074
1075
1076ExternalReference ExternalReference::log_leave_external_function(
1077 Isolate* isolate) {
1078 return ExternalReference(
1079 Redirect(isolate, FUNCTION_ADDR(Logger::LeaveExternal)));
1080}
1081
1082
Steve Block44f0eee2011-05-26 01:26:41 +01001083ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
1084 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001085}
1086
1087
Steve Block44f0eee2011-05-26 01:26:41 +01001088ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
1089 Isolate* isolate) {
1090 return ExternalReference(
1091 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001092}
1093
1094
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001095ExternalReference ExternalReference::roots_array_start(Isolate* isolate) {
1096 return ExternalReference(isolate->heap()->roots_array_start());
Steve Blocka7e24c12009-10-30 11:49:00 +00001097}
1098
1099
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001100ExternalReference ExternalReference::allocation_sites_list_address(
1101 Isolate* isolate) {
1102 return ExternalReference(isolate->heap()->allocation_sites_list_address());
1103}
1104
1105
Steve Block44f0eee2011-05-26 01:26:41 +01001106ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
1107 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +00001108}
1109
1110
Steve Block44f0eee2011-05-26 01:26:41 +01001111ExternalReference ExternalReference::address_of_real_stack_limit(
1112 Isolate* isolate) {
1113 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +00001114}
1115
1116
Steve Block44f0eee2011-05-26 01:26:41 +01001117ExternalReference ExternalReference::address_of_regexp_stack_limit(
1118 Isolate* isolate) {
1119 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +00001120}
1121
1122
Steve Block44f0eee2011-05-26 01:26:41 +01001123ExternalReference ExternalReference::new_space_start(Isolate* isolate) {
1124 return ExternalReference(isolate->heap()->NewSpaceStart());
Andrei Popescu402d9372010-02-26 13:31:12 +00001125}
1126
1127
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001128ExternalReference ExternalReference::store_buffer_top(Isolate* isolate) {
1129 return ExternalReference(isolate->heap()->store_buffer()->TopAddress());
1130}
1131
1132
Steve Block44f0eee2011-05-26 01:26:41 +01001133ExternalReference ExternalReference::new_space_mask(Isolate* isolate) {
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001134 return ExternalReference(reinterpret_cast<Address>(
1135 isolate->heap()->NewSpaceMask()));
Steve Blocka7e24c12009-10-30 11:49:00 +00001136}
1137
1138
Steve Block44f0eee2011-05-26 01:26:41 +01001139ExternalReference ExternalReference::new_space_allocation_top_address(
1140 Isolate* isolate) {
1141 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +00001142}
1143
1144
Steve Block44f0eee2011-05-26 01:26:41 +01001145ExternalReference ExternalReference::new_space_allocation_limit_address(
1146 Isolate* isolate) {
1147 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +00001148}
1149
Steve Blockd0582a62009-12-15 09:54:21 +00001150
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001151ExternalReference ExternalReference::old_pointer_space_allocation_top_address(
1152 Isolate* isolate) {
1153 return ExternalReference(
1154 isolate->heap()->OldPointerSpaceAllocationTopAddress());
Steve Blockd0582a62009-12-15 09:54:21 +00001155}
1156
1157
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001158ExternalReference ExternalReference::old_pointer_space_allocation_limit_address(
1159 Isolate* isolate) {
1160 return ExternalReference(
1161 isolate->heap()->OldPointerSpaceAllocationLimitAddress());
Steve Blockd0582a62009-12-15 09:54:21 +00001162}
1163
1164
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001165ExternalReference ExternalReference::old_data_space_allocation_top_address(
1166 Isolate* isolate) {
1167 return ExternalReference(
1168 isolate->heap()->OldDataSpaceAllocationTopAddress());
1169}
1170
1171
1172ExternalReference ExternalReference::old_data_space_allocation_limit_address(
1173 Isolate* isolate) {
1174 return ExternalReference(
1175 isolate->heap()->OldDataSpaceAllocationLimitAddress());
1176}
1177
1178
1179ExternalReference ExternalReference::handle_scope_level_address(
1180 Isolate* isolate) {
1181 return ExternalReference(HandleScope::current_level_address(isolate));
1182}
1183
1184
1185ExternalReference ExternalReference::handle_scope_next_address(
1186 Isolate* isolate) {
1187 return ExternalReference(HandleScope::current_next_address(isolate));
1188}
1189
1190
1191ExternalReference ExternalReference::handle_scope_limit_address(
1192 Isolate* isolate) {
1193 return ExternalReference(HandleScope::current_limit_address(isolate));
Steve Blockd0582a62009-12-15 09:54:21 +00001194}
1195
1196
Steve Block44f0eee2011-05-26 01:26:41 +01001197ExternalReference ExternalReference::scheduled_exception_address(
1198 Isolate* isolate) {
1199 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +00001200}
1201
1202
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001203ExternalReference ExternalReference::address_of_pending_message_obj(
1204 Isolate* isolate) {
1205 return ExternalReference(isolate->pending_message_obj_address());
1206}
1207
1208
1209ExternalReference ExternalReference::address_of_has_pending_message(
1210 Isolate* isolate) {
1211 return ExternalReference(isolate->has_pending_message_address());
1212}
1213
1214
1215ExternalReference ExternalReference::address_of_pending_message_script(
1216 Isolate* isolate) {
1217 return ExternalReference(isolate->pending_message_script_address());
1218}
1219
1220
Ben Murdochb0fe1622011-05-05 13:52:32 +01001221ExternalReference ExternalReference::address_of_min_int() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001222 return ExternalReference(reinterpret_cast<void*>(&double_constants.min_int));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001223}
1224
1225
1226ExternalReference ExternalReference::address_of_one_half() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001227 return ExternalReference(reinterpret_cast<void*>(&double_constants.one_half));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001228}
1229
1230
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001231ExternalReference ExternalReference::address_of_minus_one_half() {
1232 return ExternalReference(
1233 reinterpret_cast<void*>(&double_constants.minus_one_half));
Ben Murdoch257744e2011-11-30 15:57:28 +00001234}
1235
1236
Ben Murdochb0fe1622011-05-05 13:52:32 +01001237ExternalReference ExternalReference::address_of_negative_infinity() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001238 return ExternalReference(
1239 reinterpret_cast<void*>(&double_constants.negative_infinity));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001240}
1241
1242
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001243ExternalReference ExternalReference::address_of_canonical_non_hole_nan() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001244 return ExternalReference(
1245 reinterpret_cast<void*>(&double_constants.canonical_non_hole_nan));
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001246}
1247
1248
1249ExternalReference ExternalReference::address_of_the_hole_nan() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001250 return ExternalReference(
1251 reinterpret_cast<void*>(&double_constants.the_hole_nan));
1252}
1253
1254
1255ExternalReference ExternalReference::address_of_uint32_bias() {
1256 return ExternalReference(
1257 reinterpret_cast<void*>(&double_constants.uint32_bias));
1258}
1259
1260
1261ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) {
1262 return ExternalReference(isolate->cpu_profiler()->is_profiling_address());
1263}
1264
1265
1266ExternalReference ExternalReference::invoke_function_callback(
1267 Isolate* isolate) {
1268 Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
1269 ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
1270 ApiFunction thunk_fun(thunk_address);
1271 return ExternalReference(&thunk_fun, thunk_type, isolate);
1272}
1273
1274
1275ExternalReference ExternalReference::invoke_accessor_getter_callback(
1276 Isolate* isolate) {
1277 Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
1278 ExternalReference::Type thunk_type =
1279 ExternalReference::PROFILING_GETTER_CALL;
1280 ApiFunction thunk_fun(thunk_address);
1281 return ExternalReference(&thunk_fun, thunk_type, isolate);
Steve Block44f0eee2011-05-26 01:26:41 +01001282}
1283
1284
Steve Block6ded16b2010-05-10 14:33:55 +01001285#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001286
Steve Block44f0eee2011-05-26 01:26:41 +01001287ExternalReference ExternalReference::re_check_stack_guard_state(
1288 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001289 Address function;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001290#if V8_TARGET_ARCH_X64
Steve Blocka7e24c12009-10-30 11:49:00 +00001291 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
1292#elif V8_TARGET_ARCH_IA32
1293 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001294#elif V8_TARGET_ARCH_ARM64
1295 function = FUNCTION_ADDR(RegExpMacroAssemblerARM64::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +00001296#elif V8_TARGET_ARCH_ARM
1297 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +01001298#elif V8_TARGET_ARCH_MIPS
1299 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001300#elif V8_TARGET_ARCH_MIPS64
1301 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
1302#elif V8_TARGET_ARCH_X87
1303 function = FUNCTION_ADDR(RegExpMacroAssemblerX87::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +00001304#else
Leon Clarke4515c472010-02-03 11:58:03 +00001305 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +00001306#endif
Steve Block44f0eee2011-05-26 01:26:41 +01001307 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +00001308}
1309
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001310
Steve Block44f0eee2011-05-26 01:26:41 +01001311ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001312 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +01001313 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001314}
1315
Steve Block44f0eee2011-05-26 01:26:41 +01001316ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
1317 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001318 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +01001319 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +00001320 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
1321}
1322
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001323
Leon Clarkee46be812010-01-19 14:06:41 +00001324ExternalReference ExternalReference::re_word_character_map() {
1325 return ExternalReference(
1326 NativeRegExpMacroAssembler::word_character_map_address());
1327}
1328
Steve Block44f0eee2011-05-26 01:26:41 +01001329ExternalReference ExternalReference::address_of_static_offsets_vector(
1330 Isolate* isolate) {
1331 return ExternalReference(
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001332 reinterpret_cast<Address>(isolate->jsregexp_static_offsets_vector()));
Leon Clarkee46be812010-01-19 14:06:41 +00001333}
1334
Steve Block44f0eee2011-05-26 01:26:41 +01001335ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
1336 Isolate* isolate) {
1337 return ExternalReference(
1338 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +00001339}
1340
Steve Block44f0eee2011-05-26 01:26:41 +01001341ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
1342 Isolate* isolate) {
1343 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +00001344}
1345
Steve Block6ded16b2010-05-10 14:33:55 +01001346#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001347
1348
Steve Block44f0eee2011-05-26 01:26:41 +01001349ExternalReference ExternalReference::math_log_double_function(
1350 Isolate* isolate) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001351 typedef double (*d2d)(double x);
Steve Block44f0eee2011-05-26 01:26:41 +01001352 return ExternalReference(Redirect(isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001353 FUNCTION_ADDR(static_cast<d2d>(std::log)),
Ben Murdoch257744e2011-11-30 15:57:28 +00001354 BUILTIN_FP_CALL));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001355}
1356
1357
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001358ExternalReference ExternalReference::math_exp_constants(int constant_index) {
1359 DCHECK(math_exp_data_initialized);
1360 return ExternalReference(
1361 reinterpret_cast<void*>(math_exp_constants_array + constant_index));
1362}
1363
1364
1365ExternalReference ExternalReference::math_exp_log_table() {
1366 DCHECK(math_exp_data_initialized);
1367 return ExternalReference(reinterpret_cast<void*>(math_exp_log_table_array));
1368}
1369
1370
1371ExternalReference ExternalReference::page_flags(Page* page) {
1372 return ExternalReference(reinterpret_cast<Address>(page) +
1373 MemoryChunk::kFlagsOffset);
1374}
1375
1376
1377ExternalReference ExternalReference::ForDeoptEntry(Address entry) {
1378 return ExternalReference(entry);
1379}
1380
1381
1382ExternalReference ExternalReference::cpu_features() {
1383 DCHECK(CpuFeatures::initialized_);
1384 return ExternalReference(&CpuFeatures::supported_);
1385}
1386
1387
1388ExternalReference ExternalReference::debug_is_active_address(
1389 Isolate* isolate) {
1390 return ExternalReference(isolate->debug()->is_active_address());
1391}
1392
1393
1394ExternalReference ExternalReference::debug_after_break_target_address(
1395 Isolate* isolate) {
1396 return ExternalReference(isolate->debug()->after_break_target_address());
1397}
1398
1399
1400ExternalReference
1401 ExternalReference::debug_restarter_frame_function_pointer_address(
1402 Isolate* isolate) {
1403 return ExternalReference(
1404 isolate->debug()->restarter_frame_function_pointer_address());
1405}
1406
1407
1408double power_helper(double x, double y) {
1409 int y_int = static_cast<int>(y);
1410 if (y == y_int) {
1411 return power_double_int(x, y_int); // Returns 1 if exponent is 0.
1412 }
1413 if (y == 0.5) {
1414 return (std::isinf(x)) ? V8_INFINITY
1415 : fast_sqrt(x + 0.0); // Convert -0 to +0.
1416 }
1417 if (y == -0.5) {
1418 return (std::isinf(x)) ? 0 : 1.0 / fast_sqrt(x + 0.0); // Convert -0 to +0.
1419 }
1420 return power_double_double(x, y);
1421}
1422
1423
Ben Murdochb0fe1622011-05-05 13:52:32 +01001424// Helper function to compute x^y, where y is known to be an
1425// integer. Uses binary decomposition to limit the number of
1426// multiplications; see the discussion in "Hacker's Delight" by Henry
1427// S. Warren, Jr., figure 11-6, page 213.
1428double power_double_int(double x, int y) {
1429 double m = (y < 0) ? 1 / x : x;
1430 unsigned n = (y < 0) ? -y : y;
1431 double p = 1;
1432 while (n != 0) {
1433 if ((n & 1) != 0) p *= m;
1434 m *= m;
1435 if ((n & 2) != 0) p *= m;
1436 m *= m;
1437 n >>= 2;
1438 }
1439 return p;
1440}
1441
1442
1443double power_double_double(double x, double y) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001444#if defined(__MINGW64_VERSION_MAJOR) && \
1445 (!defined(__MINGW64_VERSION_RC) || __MINGW64_VERSION_RC < 1)
1446 // MinGW64 has a custom implementation for pow. This handles certain
1447 // special cases that are different.
1448 if ((x == 0.0 || std::isinf(x)) && std::isfinite(y)) {
1449 double f;
1450 if (std::modf(y, &f) != 0.0) {
1451 return ((x == 0.0) ^ (y > 0)) ? V8_INFINITY : 0;
1452 }
1453 }
1454
1455 if (x == 2.0) {
1456 int y_int = static_cast<int>(y);
1457 if (y == y_int) {
1458 return std::ldexp(1.0, y_int);
1459 }
1460 }
1461#endif
1462
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001463 // The checks for special cases can be dropped in ia32 because it has already
1464 // been done in generated code before bailing out here.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001465 if (std::isnan(y) || ((x == 1 || x == -1) && std::isinf(y))) {
1466 return base::OS::nan_value();
1467 }
1468 return std::pow(x, y);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001469}
1470
1471
Steve Block44f0eee2011-05-26 01:26:41 +01001472ExternalReference ExternalReference::power_double_double_function(
1473 Isolate* isolate) {
1474 return ExternalReference(Redirect(isolate,
1475 FUNCTION_ADDR(power_double_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001476 BUILTIN_FP_FP_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001477}
1478
1479
Steve Block44f0eee2011-05-26 01:26:41 +01001480ExternalReference ExternalReference::power_double_int_function(
1481 Isolate* isolate) {
1482 return ExternalReference(Redirect(isolate,
1483 FUNCTION_ADDR(power_double_int),
Ben Murdoch257744e2011-11-30 15:57:28 +00001484 BUILTIN_FP_INT_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001485}
1486
1487
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001488bool EvalComparison(Token::Value op, double op1, double op2) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001489 DCHECK(Token::IsCompareOp(op));
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001490 switch (op) {
1491 case Token::EQ:
1492 case Token::EQ_STRICT: return (op1 == op2);
1493 case Token::NE: return (op1 != op2);
1494 case Token::LT: return (op1 < op2);
1495 case Token::GT: return (op1 > op2);
1496 case Token::LTE: return (op1 <= op2);
1497 case Token::GTE: return (op1 >= op2);
1498 default:
1499 UNREACHABLE();
1500 return false;
1501 }
1502}
1503
1504
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001505ExternalReference ExternalReference::mod_two_doubles_operation(
1506 Isolate* isolate) {
Steve Block44f0eee2011-05-26 01:26:41 +01001507 return ExternalReference(Redirect(isolate,
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001508 FUNCTION_ADDR(modulo),
Ben Murdoch257744e2011-11-30 15:57:28 +00001509 BUILTIN_FP_FP_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001510}
1511
1512
Steve Block44f0eee2011-05-26 01:26:41 +01001513ExternalReference ExternalReference::debug_break(Isolate* isolate) {
Ben Murdoch8b112d22011-06-08 16:22:53 +01001514 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug_Break)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001515}
1516
1517
Steve Block44f0eee2011-05-26 01:26:41 +01001518ExternalReference ExternalReference::debug_step_in_fp_address(
1519 Isolate* isolate) {
1520 return ExternalReference(isolate->debug()->step_in_fp_addr());
Steve Blocka7e24c12009-10-30 11:49:00 +00001521}
Steve Blocka7e24c12009-10-30 11:49:00 +00001522
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001523
Ben Murdochb0fe1622011-05-05 13:52:32 +01001524void PositionsRecorder::RecordPosition(int pos) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001525 DCHECK(pos != RelocInfo::kNoPosition);
1526 DCHECK(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001527 state_.current_position = pos;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001528 LOG_CODE_EVENT(assembler_->isolate(),
1529 CodeLinePosInfoAddPositionEvent(jit_handler_data_,
1530 assembler_->pc_offset(),
1531 pos));
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001532}
1533
1534
1535void PositionsRecorder::RecordStatementPosition(int pos) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001536 DCHECK(pos != RelocInfo::kNoPosition);
1537 DCHECK(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001538 state_.current_statement_position = pos;
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001539 LOG_CODE_EVENT(assembler_->isolate(),
1540 CodeLinePosInfoAddStatementPositionEvent(
1541 jit_handler_data_,
1542 assembler_->pc_offset(),
1543 pos));
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001544}
1545
1546
1547bool PositionsRecorder::WriteRecordedPositions() {
1548 bool written = false;
1549
1550 // Write the statement position if it is different from what was written last
1551 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001552 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001553 EnsureSpace ensure_space(assembler_);
1554 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001555 state_.current_statement_position);
1556 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001557 written = true;
1558 }
1559
1560 // Write the position if it is different from what was written last time and
Ben Murdochb0fe1622011-05-05 13:52:32 +01001561 // also different from the written statement position.
1562 if (state_.current_position != state_.written_position &&
1563 state_.current_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001564 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001565 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1566 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001567 written = true;
1568 }
1569
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001570 // Return whether something was written.
1571 return written;
1572}
1573
Steve Blocka7e24c12009-10-30 11:49:00 +00001574} } // namespace v8::internal