blob: fbd808958044611bcd93ac4e77a53c07a07bcf28 [file] [log] [blame]
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001// Copyright (c) 2011 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 Murdoch257744e2011-11-30 15:57:28 +000033// Copyright 2011 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35#include "v8.h"
36
37#include "arguments.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010038#include "deoptimizer.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000039#include "execution.h"
40#include "ic-inl.h"
41#include "factory.h"
42#include "runtime.h"
Ben Murdochb0fe1622011-05-05 13:52:32 +010043#include "runtime-profiler.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000044#include "serialize.h"
45#include "stub-cache.h"
46#include "regexp-stack.h"
47#include "ast.h"
48#include "regexp-macro-assembler.h"
Leon Clarkee46be812010-01-19 14:06:41 +000049#include "platform.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000050// Include native regexp-macro-assembler.
Steve Block6ded16b2010-05-10 14:33:55 +010051#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000052#if V8_TARGET_ARCH_IA32
53#include "ia32/regexp-macro-assembler-ia32.h"
54#elif V8_TARGET_ARCH_X64
55#include "x64/regexp-macro-assembler-x64.h"
56#elif V8_TARGET_ARCH_ARM
57#include "arm/regexp-macro-assembler-arm.h"
Steve Block44f0eee2011-05-26 01:26:41 +010058#elif V8_TARGET_ARCH_MIPS
59#include "mips/regexp-macro-assembler-mips.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000060#else // Unknown architecture.
61#error "Unknown architecture."
62#endif // Target architecture.
Steve Block6ded16b2010-05-10 14:33:55 +010063#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +000064
65namespace v8 {
66namespace internal {
67
68
Ben Murdochb0fe1622011-05-05 13:52:32 +010069const double DoubleConstant::min_int = kMinInt;
70const double DoubleConstant::one_half = 0.5;
Ben Murdochb8e0da22011-05-16 14:20:40 +010071const double DoubleConstant::minus_zero = -0.0;
Ben Murdoch257744e2011-11-30 15:57:28 +000072const double DoubleConstant::uint8_max_value = 255;
73const double DoubleConstant::zero = 0.0;
Ben Murdoch3fb3ca82011-12-02 17:19:32 +000074const double DoubleConstant::canonical_non_hole_nan = OS::nan_value();
75const double DoubleConstant::the_hole_nan = BitCast<double>(kHoleNanInt64);
Ben Murdochb0fe1622011-05-05 13:52:32 +010076const double DoubleConstant::negative_infinity = -V8_INFINITY;
Ben Murdoche0cee9b2011-05-25 10:26:03 +010077const char* RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING";
Ben Murdochb0fe1622011-05-05 13:52:32 +010078
Steve Blocka7e24c12009-10-30 11:49:00 +000079// -----------------------------------------------------------------------------
Steve Block053d10c2011-06-13 19:13:29 +010080// Implementation of AssemblerBase
81
82AssemblerBase::AssemblerBase(Isolate* isolate)
83 : isolate_(isolate),
84 jit_cookie_(0) {
85 if (FLAG_mask_constants_with_cookie && isolate != NULL) {
86 jit_cookie_ = V8::RandomPrivate(isolate);
87 }
88}
89
90
91// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +000092// Implementation of Label
93
94int Label::pos() const {
95 if (pos_ < 0) return -pos_ - 1;
96 if (pos_ > 0) return pos_ - 1;
97 UNREACHABLE();
98 return 0;
99}
100
101
102// -----------------------------------------------------------------------------
103// Implementation of RelocInfoWriter and RelocIterator
104//
Ben Murdoch257744e2011-11-30 15:57:28 +0000105// Relocation information is written backwards in memory, from high addresses
106// towards low addresses, byte by byte. Therefore, in the encodings listed
107// below, the first byte listed it at the highest address, and successive
108// bytes in the record are at progressively lower addresses.
109//
Steve Blocka7e24c12009-10-30 11:49:00 +0000110// Encoding
111//
112// The most common modes are given single-byte encodings. Also, it is
113// easy to identify the type of reloc info and skip unwanted modes in
114// an iteration.
115//
Ben Murdoch257744e2011-11-30 15:57:28 +0000116// The encoding relies on the fact that there are fewer than 14
117// different non-compactly encoded relocation modes.
Steve Blocka7e24c12009-10-30 11:49:00 +0000118//
Ben Murdoch257744e2011-11-30 15:57:28 +0000119// The first byte of a relocation record has a tag in its low 2 bits:
120// Here are the record schemes, depending on the low tag and optional higher
121// tags.
Steve Blocka7e24c12009-10-30 11:49:00 +0000122//
Ben Murdoch257744e2011-11-30 15:57:28 +0000123// Low tag:
124// 00: embedded_object: [6-bit pc delta] 00
Steve Blocka7e24c12009-10-30 11:49:00 +0000125//
Ben Murdoch257744e2011-11-30 15:57:28 +0000126// 01: code_target: [6-bit pc delta] 01
Steve Blocka7e24c12009-10-30 11:49:00 +0000127//
Ben Murdoch257744e2011-11-30 15:57:28 +0000128// 10: short_data_record: [6-bit pc delta] 10 followed by
129// [6-bit data delta] [2-bit data type tag]
Steve Blocka7e24c12009-10-30 11:49:00 +0000130//
Ben Murdoch257744e2011-11-30 15:57:28 +0000131// 11: long_record [2-bit high tag][4 bit middle_tag] 11
132// followed by variable data depending on type.
Steve Blocka7e24c12009-10-30 11:49:00 +0000133//
Ben Murdoch257744e2011-11-30 15:57:28 +0000134// 2-bit data type tags, used in short_data_record and data_jump long_record:
135// code_target_with_id: 00
136// position: 01
137// statement_position: 10
138// comment: 11 (not used in short_data_record)
Steve Blocka7e24c12009-10-30 11:49:00 +0000139//
Ben Murdoch257744e2011-11-30 15:57:28 +0000140// Long record format:
141// 4-bit middle_tag:
142// 0000 - 1100 : Short record for RelocInfo::Mode middle_tag + 2
143// (The middle_tag encodes rmode - RelocInfo::LAST_COMPACT_ENUM,
144// and is between 0000 and 1100)
145// The format is:
146// 00 [4 bit middle_tag] 11 followed by
147// 00 [6 bit pc delta]
Steve Blocka7e24c12009-10-30 11:49:00 +0000148//
Ben Murdoch257744e2011-11-30 15:57:28 +0000149// 1101: not used (would allow one more relocation mode to be added)
150// 1110: long_data_record
151// The format is: [2-bit data_type_tag] 1110 11
152// signed intptr_t, lowest byte written first
153// (except data_type code_target_with_id, which
154// is followed by a signed int, not intptr_t.)
Steve Blocka7e24c12009-10-30 11:49:00 +0000155//
Ben Murdoch257744e2011-11-30 15:57:28 +0000156// 1111: long_pc_jump
157// The format is:
158// pc-jump: 00 1111 11,
159// 00 [6 bits pc delta]
160// or
161// pc-jump (variable length):
162// 01 1111 11,
163// [7 bits data] 0
164// ...
165// [7 bits data] 1
166// (Bits 6..31 of pc delta, with leading zeroes
167// dropped, and last non-zero chunk tagged with 1.)
168
169
Steve Blocka7e24c12009-10-30 11:49:00 +0000170const int kMaxRelocModes = 14;
171
172const int kTagBits = 2;
173const int kTagMask = (1 << kTagBits) - 1;
174const int kExtraTagBits = 4;
Ben Murdoch257744e2011-11-30 15:57:28 +0000175const int kLocatableTypeTagBits = 2;
176const int kSmallDataBits = kBitsPerByte - kLocatableTypeTagBits;
Steve Blocka7e24c12009-10-30 11:49:00 +0000177
178const int kEmbeddedObjectTag = 0;
179const int kCodeTargetTag = 1;
Ben Murdoch257744e2011-11-30 15:57:28 +0000180const int kLocatableTag = 2;
Steve Blocka7e24c12009-10-30 11:49:00 +0000181const int kDefaultTag = 3;
182
Ben Murdoch257744e2011-11-30 15:57:28 +0000183const int kPCJumpExtraTag = (1 << kExtraTagBits) - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000184
185const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
186const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100187const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000188
189const int kVariableLengthPCJumpTopTag = 1;
190const int kChunkBits = 7;
191const int kChunkMask = (1 << kChunkBits) - 1;
192const int kLastChunkTagBits = 1;
193const int kLastChunkTagMask = 1;
194const int kLastChunkTag = 1;
195
196
Ben Murdoch257744e2011-11-30 15:57:28 +0000197const int kDataJumpExtraTag = kPCJumpExtraTag - 1;
Steve Blocka7e24c12009-10-30 11:49:00 +0000198
Ben Murdoch257744e2011-11-30 15:57:28 +0000199const int kCodeWithIdTag = 0;
200const int kNonstatementPositionTag = 1;
201const int kStatementPositionTag = 2;
202const int kCommentTag = 3;
Steve Blocka7e24c12009-10-30 11:49:00 +0000203
204
205uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
206 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
207 // Otherwise write a variable length PC jump for the bits that do
208 // not fit in the kSmallPCDeltaBits bits.
209 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
Ben Murdoch257744e2011-11-30 15:57:28 +0000210 WriteExtraTag(kPCJumpExtraTag, kVariableLengthPCJumpTopTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000211 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
212 ASSERT(pc_jump > 0);
213 // Write kChunkBits size chunks of the pc_jump.
214 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
215 byte b = pc_jump & kChunkMask;
216 *--pos_ = b << kLastChunkTagBits;
217 }
218 // Tag the last chunk so it can be identified.
219 *pos_ = *pos_ | kLastChunkTag;
220 // Return the remaining kSmallPCDeltaBits of the pc_delta.
221 return pc_delta & kSmallPCDeltaMask;
222}
223
224
225void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
226 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
227 pc_delta = WriteVariableLengthPCJump(pc_delta);
228 *--pos_ = pc_delta << kTagBits | tag;
229}
230
231
232void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000233 *--pos_ = static_cast<byte>(data_delta << kLocatableTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000234}
235
236
237void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000238 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
239 extra_tag << kTagBits |
240 kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000241}
242
243
244void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
245 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
246 pc_delta = WriteVariableLengthPCJump(pc_delta);
247 WriteExtraTag(extra_tag, 0);
248 *--pos_ = pc_delta;
249}
250
251
Ben Murdoch257744e2011-11-30 15:57:28 +0000252void RelocInfoWriter::WriteExtraTaggedIntData(int data_delta, int top_tag) {
253 WriteExtraTag(kDataJumpExtraTag, top_tag);
254 for (int i = 0; i < kIntSize; i++) {
255 *--pos_ = static_cast<byte>(data_delta);
256 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
257 data_delta = data_delta >> kBitsPerByte;
258 }
259}
260
Steve Blocka7e24c12009-10-30 11:49:00 +0000261void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
Ben Murdoch257744e2011-11-30 15:57:28 +0000262 WriteExtraTag(kDataJumpExtraTag, top_tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000263 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000264 *--pos_ = static_cast<byte>(data_delta);
Ben Murdoch257744e2011-11-30 15:57:28 +0000265 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Steve Blocka7e24c12009-10-30 11:49:00 +0000266 data_delta = data_delta >> kBitsPerByte;
267 }
268}
269
270
271void RelocInfoWriter::Write(const RelocInfo* rinfo) {
272#ifdef DEBUG
273 byte* begin_pos = pos_;
274#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000275 ASSERT(rinfo->pc() - last_pc_ >= 0);
Ben Murdoch257744e2011-11-30 15:57:28 +0000276 ASSERT(RelocInfo::NUMBER_OF_MODES - RelocInfo::LAST_COMPACT_ENUM <=
277 kMaxRelocModes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000278 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000279 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000280 RelocInfo::Mode rmode = rinfo->rmode();
281
282 // The two most common modes are given small tags, and usually fit in a byte.
283 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
284 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
285 } else if (rmode == RelocInfo::CODE_TARGET) {
286 WriteTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100287 ASSERT(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Ben Murdoch257744e2011-11-30 15:57:28 +0000288 } else if (rmode == RelocInfo::CODE_TARGET_WITH_ID) {
289 // Use signed delta-encoding for id.
290 ASSERT(static_cast<int>(rinfo->data()) == rinfo->data());
291 int id_delta = static_cast<int>(rinfo->data()) - last_id_;
292 // Check if delta is small enough to fit in a tagged byte.
293 if (is_intn(id_delta, kSmallDataBits)) {
294 WriteTaggedPC(pc_delta, kLocatableTag);
295 WriteTaggedData(id_delta, kCodeWithIdTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000296 } else {
297 // Otherwise, use costly encoding.
Ben Murdoch257744e2011-11-30 15:57:28 +0000298 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
299 WriteExtraTaggedIntData(id_delta, kCodeWithIdTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000300 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000301 last_id_ = static_cast<int>(rinfo->data());
302 } else if (RelocInfo::IsPosition(rmode)) {
303 // Use signed delta-encoding for position.
304 ASSERT(static_cast<int>(rinfo->data()) == rinfo->data());
305 int pos_delta = static_cast<int>(rinfo->data()) - last_position_;
306 int pos_type_tag = (rmode == RelocInfo::POSITION) ? kNonstatementPositionTag
307 : kStatementPositionTag;
308 // Check if delta is small enough to fit in a tagged byte.
309 if (is_intn(pos_delta, kSmallDataBits)) {
310 WriteTaggedPC(pc_delta, kLocatableTag);
311 WriteTaggedData(pos_delta, pos_type_tag);
312 } else {
313 // Otherwise, use costly encoding.
314 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
315 WriteExtraTaggedIntData(pos_delta, pos_type_tag);
316 }
317 last_position_ = static_cast<int>(rinfo->data());
Steve Blocka7e24c12009-10-30 11:49:00 +0000318 } else if (RelocInfo::IsComment(rmode)) {
319 // Comments are normally not generated, so we use the costly encoding.
Ben Murdoch257744e2011-11-30 15:57:28 +0000320 WriteExtraTaggedPC(pc_delta, kPCJumpExtraTag);
321 WriteExtraTaggedData(rinfo->data(), kCommentTag);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100322 ASSERT(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000323 } else {
Ben Murdoch257744e2011-11-30 15:57:28 +0000324 ASSERT(rmode > RelocInfo::LAST_COMPACT_ENUM);
325 int saved_mode = rmode - RelocInfo::LAST_COMPACT_ENUM;
Steve Blocka7e24c12009-10-30 11:49:00 +0000326 // For all other modes we simply use the mode as the extra tag.
327 // None of these modes need a data component.
Ben Murdoch257744e2011-11-30 15:57:28 +0000328 ASSERT(saved_mode < kPCJumpExtraTag && saved_mode < kDataJumpExtraTag);
329 WriteExtraTaggedPC(pc_delta, saved_mode);
Steve Blocka7e24c12009-10-30 11:49:00 +0000330 }
331 last_pc_ = rinfo->pc();
332#ifdef DEBUG
333 ASSERT(begin_pos - pos_ <= kMaxSize);
334#endif
335}
336
337
338inline int RelocIterator::AdvanceGetTag() {
339 return *--pos_ & kTagMask;
340}
341
342
343inline int RelocIterator::GetExtraTag() {
344 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
345}
346
347
348inline int RelocIterator::GetTopTag() {
349 return *pos_ >> (kTagBits + kExtraTagBits);
350}
351
352
353inline void RelocIterator::ReadTaggedPC() {
354 rinfo_.pc_ += *pos_ >> kTagBits;
355}
356
357
358inline void RelocIterator::AdvanceReadPC() {
359 rinfo_.pc_ += *--pos_;
360}
361
362
Ben Murdoch257744e2011-11-30 15:57:28 +0000363void RelocIterator::AdvanceReadId() {
364 int x = 0;
365 for (int i = 0; i < kIntSize; i++) {
366 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
367 }
368 last_id_ += x;
369 rinfo_.data_ = last_id_;
370}
371
372
373void RelocIterator::AdvanceReadPosition() {
374 int x = 0;
375 for (int i = 0; i < kIntSize; i++) {
376 x |= static_cast<int>(*--pos_) << i * kBitsPerByte;
377 }
378 last_position_ += x;
379 rinfo_.data_ = last_position_;
380}
381
382
Steve Blocka7e24c12009-10-30 11:49:00 +0000383void RelocIterator::AdvanceReadData() {
384 intptr_t x = 0;
385 for (int i = 0; i < kIntptrSize; i++) {
386 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
387 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000388 rinfo_.data_ = x;
Steve Blocka7e24c12009-10-30 11:49:00 +0000389}
390
391
392void RelocIterator::AdvanceReadVariableLengthPCJump() {
393 // Read the 32-kSmallPCDeltaBits most significant bits of the
394 // pc jump in kChunkBits bit chunks and shift them into place.
395 // Stop when the last chunk is encountered.
396 uint32_t pc_jump = 0;
397 for (int i = 0; i < kIntSize; i++) {
398 byte pc_jump_part = *--pos_;
399 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
400 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
401 }
402 // The least significant kSmallPCDeltaBits bits will be added
403 // later.
404 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
405}
406
407
Ben Murdoch257744e2011-11-30 15:57:28 +0000408inline int RelocIterator::GetLocatableTypeTag() {
409 return *pos_ & ((1 << kLocatableTypeTagBits) - 1);
Steve Blocka7e24c12009-10-30 11:49:00 +0000410}
411
412
Ben Murdoch257744e2011-11-30 15:57:28 +0000413inline void RelocIterator::ReadTaggedId() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000414 int8_t signed_b = *pos_;
415 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
Ben Murdoch257744e2011-11-30 15:57:28 +0000416 last_id_ += signed_b >> kLocatableTypeTagBits;
417 rinfo_.data_ = last_id_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000418}
419
420
Ben Murdoch257744e2011-11-30 15:57:28 +0000421inline void RelocIterator::ReadTaggedPosition() {
422 int8_t signed_b = *pos_;
423 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
424 last_position_ += signed_b >> kLocatableTypeTagBits;
425 rinfo_.data_ = last_position_;
426}
427
428
429static inline RelocInfo::Mode GetPositionModeFromTag(int tag) {
430 ASSERT(tag == kNonstatementPositionTag ||
431 tag == kStatementPositionTag);
432 return (tag == kNonstatementPositionTag) ?
433 RelocInfo::POSITION :
434 RelocInfo::STATEMENT_POSITION;
Steve Blocka7e24c12009-10-30 11:49:00 +0000435}
436
437
438void RelocIterator::next() {
439 ASSERT(!done());
440 // Basically, do the opposite of RelocInfoWriter::Write.
441 // Reading of data is as far as possible avoided for unwanted modes,
442 // but we must always update the pc.
443 //
444 // We exit this loop by returning when we find a mode we want.
445 while (pos_ > end_) {
446 int tag = AdvanceGetTag();
447 if (tag == kEmbeddedObjectTag) {
448 ReadTaggedPC();
449 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
450 } else if (tag == kCodeTargetTag) {
451 ReadTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000452 if (SetMode(RelocInfo::CODE_TARGET)) return;
Ben Murdoch257744e2011-11-30 15:57:28 +0000453 } else if (tag == kLocatableTag) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000454 ReadTaggedPC();
455 Advance();
Ben Murdoch257744e2011-11-30 15:57:28 +0000456 int locatable_tag = GetLocatableTypeTag();
457 if (locatable_tag == kCodeWithIdTag) {
458 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
459 ReadTaggedId();
460 return;
461 }
462 } else {
463 // Compact encoding is never used for comments,
464 // so it must be a position.
465 ASSERT(locatable_tag == kNonstatementPositionTag ||
466 locatable_tag == kStatementPositionTag);
467 if (mode_mask_ & RelocInfo::kPositionMask) {
468 ReadTaggedPosition();
469 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
470 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000471 }
472 } else {
473 ASSERT(tag == kDefaultTag);
474 int extra_tag = GetExtraTag();
Ben Murdoch257744e2011-11-30 15:57:28 +0000475 if (extra_tag == kPCJumpExtraTag) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000476 int top_tag = GetTopTag();
477 if (top_tag == kVariableLengthPCJumpTopTag) {
478 AdvanceReadVariableLengthPCJump();
479 } else {
480 AdvanceReadPC();
481 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000482 } else if (extra_tag == kDataJumpExtraTag) {
483 int locatable_tag = GetTopTag();
484 if (locatable_tag == kCodeWithIdTag) {
485 if (SetMode(RelocInfo::CODE_TARGET_WITH_ID)) {
486 AdvanceReadId();
487 return;
488 }
489 Advance(kIntSize);
490 } else if (locatable_tag != kCommentTag) {
491 ASSERT(locatable_tag == kNonstatementPositionTag ||
492 locatable_tag == kStatementPositionTag);
493 if (mode_mask_ & RelocInfo::kPositionMask) {
494 AdvanceReadPosition();
495 if (SetMode(GetPositionModeFromTag(locatable_tag))) return;
496 } else {
497 Advance(kIntSize);
498 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 } else {
Ben Murdoch257744e2011-11-30 15:57:28 +0000500 ASSERT(locatable_tag == kCommentTag);
501 if (SetMode(RelocInfo::COMMENT)) {
502 AdvanceReadData();
503 return;
504 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000505 Advance(kIntptrSize);
506 }
507 } else {
508 AdvanceReadPC();
Ben Murdoch257744e2011-11-30 15:57:28 +0000509 int rmode = extra_tag + RelocInfo::LAST_COMPACT_ENUM;
510 if (SetMode(static_cast<RelocInfo::Mode>(rmode))) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000511 }
512 }
513 }
514 done_ = true;
515}
516
517
518RelocIterator::RelocIterator(Code* code, int mode_mask) {
519 rinfo_.pc_ = code->instruction_start();
520 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100521 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000522 pos_ = code->relocation_start() + code->relocation_size();
523 end_ = code->relocation_start();
524 done_ = false;
525 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000526 last_id_ = 0;
527 last_position_ = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000528 if (mode_mask_ == 0) pos_ = end_;
529 next();
530}
531
532
533RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
534 rinfo_.pc_ = desc.buffer;
535 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100536 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 pos_ = desc.buffer + desc.buffer_size;
538 end_ = pos_ - desc.reloc_size;
539 done_ = false;
540 mode_mask_ = mode_mask;
Ben Murdoch257744e2011-11-30 15:57:28 +0000541 last_id_ = 0;
542 last_position_ = 0;
Steve Blocka7e24c12009-10-30 11:49:00 +0000543 if (mode_mask_ == 0) pos_ = end_;
544 next();
545}
546
547
548// -----------------------------------------------------------------------------
549// Implementation of RelocInfo
550
551
552#ifdef ENABLE_DISASSEMBLER
553const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
554 switch (rmode) {
555 case RelocInfo::NONE:
556 return "no reloc";
557 case RelocInfo::EMBEDDED_OBJECT:
558 return "embedded object";
Steve Blocka7e24c12009-10-30 11:49:00 +0000559 case RelocInfo::CONSTRUCT_CALL:
560 return "code target (js construct call)";
561 case RelocInfo::CODE_TARGET_CONTEXT:
562 return "code target (context)";
Andrei Popescu402d9372010-02-26 13:31:12 +0000563 case RelocInfo::DEBUG_BREAK:
564#ifndef ENABLE_DEBUGGER_SUPPORT
565 UNREACHABLE();
566#endif
567 return "debug break";
Steve Blocka7e24c12009-10-30 11:49:00 +0000568 case RelocInfo::CODE_TARGET:
569 return "code target";
Ben Murdoch257744e2011-11-30 15:57:28 +0000570 case RelocInfo::CODE_TARGET_WITH_ID:
571 return "code target with id";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100572 case RelocInfo::GLOBAL_PROPERTY_CELL:
573 return "global property cell";
Steve Blocka7e24c12009-10-30 11:49:00 +0000574 case RelocInfo::RUNTIME_ENTRY:
575 return "runtime entry";
576 case RelocInfo::JS_RETURN:
577 return "js return";
578 case RelocInfo::COMMENT:
579 return "comment";
580 case RelocInfo::POSITION:
581 return "position";
582 case RelocInfo::STATEMENT_POSITION:
583 return "statement position";
584 case RelocInfo::EXTERNAL_REFERENCE:
585 return "external reference";
586 case RelocInfo::INTERNAL_REFERENCE:
587 return "internal reference";
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100588 case RelocInfo::DEBUG_BREAK_SLOT:
589#ifndef ENABLE_DEBUGGER_SUPPORT
590 UNREACHABLE();
591#endif
592 return "debug break slot";
Steve Blocka7e24c12009-10-30 11:49:00 +0000593 case RelocInfo::NUMBER_OF_MODES:
594 UNREACHABLE();
595 return "number_of_modes";
596 }
597 return "unknown relocation type";
598}
599
600
Ben Murdochb0fe1622011-05-05 13:52:32 +0100601void RelocInfo::Print(FILE* out) {
602 PrintF(out, "%p %s", pc_, RelocModeName(rmode_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000603 if (IsComment(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100604 PrintF(out, " (%s)", reinterpret_cast<char*>(data_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000605 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100606 PrintF(out, " (");
607 target_object()->ShortPrint(out);
608 PrintF(out, ")");
Steve Blocka7e24c12009-10-30 11:49:00 +0000609 } else if (rmode_ == EXTERNAL_REFERENCE) {
610 ExternalReferenceEncoder ref_encoder;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100611 PrintF(out, " (%s) (%p)",
Steve Blocka7e24c12009-10-30 11:49:00 +0000612 ref_encoder.NameOfAddress(*target_reference_address()),
613 *target_reference_address());
614 } else if (IsCodeTarget(rmode_)) {
615 Code* code = Code::GetCodeFromTargetAddress(target_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100616 PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()),
617 target_address());
Ben Murdoch257744e2011-11-30 15:57:28 +0000618 if (rmode_ == CODE_TARGET_WITH_ID) {
619 PrintF(" (id=%d)", static_cast<int>(data_));
620 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000621 } else if (IsPosition(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100622 PrintF(out, " (%" V8_PTR_PREFIX "d)", data());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100623 } else if (rmode_ == RelocInfo::RUNTIME_ENTRY &&
624 Isolate::Current()->deoptimizer_data() != NULL) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100625 // Depotimization bailouts are stored as runtime entries.
626 int id = Deoptimizer::GetDeoptimizationId(
627 target_address(), Deoptimizer::EAGER);
628 if (id != Deoptimizer::kNotDeoptimizationEntry) {
629 PrintF(out, " (deoptimization bailout %d)", id);
630 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000631 }
632
Ben Murdochb0fe1622011-05-05 13:52:32 +0100633 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000634}
635#endif // ENABLE_DISASSEMBLER
636
637
638#ifdef DEBUG
639void RelocInfo::Verify() {
640 switch (rmode_) {
641 case EMBEDDED_OBJECT:
642 Object::VerifyPointer(target_object());
643 break;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100644 case GLOBAL_PROPERTY_CELL:
645 Object::VerifyPointer(target_cell());
646 break;
Andrei Popescu402d9372010-02-26 13:31:12 +0000647 case DEBUG_BREAK:
648#ifndef ENABLE_DEBUGGER_SUPPORT
649 UNREACHABLE();
650 break;
651#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000652 case CONSTRUCT_CALL:
653 case CODE_TARGET_CONTEXT:
Ben Murdoch257744e2011-11-30 15:57:28 +0000654 case CODE_TARGET_WITH_ID:
Steve Blocka7e24c12009-10-30 11:49:00 +0000655 case CODE_TARGET: {
656 // convert inline target address to code object
657 Address addr = target_address();
658 ASSERT(addr != NULL);
659 // Check that we can find the right code object.
660 Code* code = Code::GetCodeFromTargetAddress(addr);
Steve Block44f0eee2011-05-26 01:26:41 +0100661 Object* found = HEAP->FindCodeObject(addr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000662 ASSERT(found->IsCode());
663 ASSERT(code->address() == HeapObject::cast(found)->address());
664 break;
665 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000666 case RUNTIME_ENTRY:
667 case JS_RETURN:
668 case COMMENT:
669 case POSITION:
670 case STATEMENT_POSITION:
671 case EXTERNAL_REFERENCE:
672 case INTERNAL_REFERENCE:
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100673 case DEBUG_BREAK_SLOT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000674 case NONE:
675 break;
676 case NUMBER_OF_MODES:
677 UNREACHABLE();
678 break;
679 }
680}
681#endif // DEBUG
682
683
684// -----------------------------------------------------------------------------
685// Implementation of ExternalReference
686
Steve Block44f0eee2011-05-26 01:26:41 +0100687ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
688 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000689
690
Steve Block1e0659c2011-05-24 12:43:12 +0100691ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100692 ApiFunction* fun,
693 Type type = ExternalReference::BUILTIN_CALL,
694 Isolate* isolate = NULL)
695 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +0000696
697
Steve Block44f0eee2011-05-26 01:26:41 +0100698ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
699 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000700
701
Steve Block44f0eee2011-05-26 01:26:41 +0100702ExternalReference::ExternalReference(Runtime::FunctionId id,
703 Isolate* isolate)
704 : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000705
706
Steve Block44f0eee2011-05-26 01:26:41 +0100707ExternalReference::ExternalReference(const Runtime::Function* f,
708 Isolate* isolate)
709 : address_(Redirect(isolate, f->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000710
711
Steve Block44f0eee2011-05-26 01:26:41 +0100712ExternalReference ExternalReference::isolate_address() {
713 return ExternalReference(Isolate::Current());
714}
715
716
717ExternalReference::ExternalReference(const IC_Utility& ic_utility,
718 Isolate* isolate)
719 : address_(Redirect(isolate, ic_utility.address())) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000720
721#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100722ExternalReference::ExternalReference(const Debug_Address& debug_address,
723 Isolate* isolate)
724 : address_(debug_address.address(isolate)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000725#endif
726
727ExternalReference::ExternalReference(StatsCounter* counter)
728 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
729
730
Steve Block44f0eee2011-05-26 01:26:41 +0100731ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
732 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000733
734
735ExternalReference::ExternalReference(const SCTableReference& table_ref)
736 : address_(table_ref.address()) {}
737
738
Steve Block44f0eee2011-05-26 01:26:41 +0100739ExternalReference ExternalReference::perform_gc_function(Isolate* isolate) {
740 return ExternalReference(Redirect(isolate,
741 FUNCTION_ADDR(Runtime::PerformGC)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000742}
743
744
Steve Block44f0eee2011-05-26 01:26:41 +0100745ExternalReference ExternalReference::fill_heap_number_with_random_function(
746 Isolate* isolate) {
747 return ExternalReference(Redirect(
748 isolate,
749 FUNCTION_ADDR(V8::FillHeapNumberWithRandom)));
Steve Block6ded16b2010-05-10 14:33:55 +0100750}
751
752
Steve Block44f0eee2011-05-26 01:26:41 +0100753ExternalReference ExternalReference::delete_handle_scope_extensions(
754 Isolate* isolate) {
755 return ExternalReference(Redirect(
756 isolate,
757 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -0700758}
759
760
Steve Block44f0eee2011-05-26 01:26:41 +0100761ExternalReference ExternalReference::random_uint32_function(
762 Isolate* isolate) {
763 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000764}
765
766
Steve Block44f0eee2011-05-26 01:26:41 +0100767ExternalReference ExternalReference::transcendental_cache_array_address(
768 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100769 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100770 isolate->transcendental_cache()->cache_array_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100771}
772
773
Steve Block44f0eee2011-05-26 01:26:41 +0100774ExternalReference ExternalReference::new_deoptimizer_function(
775 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100776 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100777 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100778}
779
780
Steve Block44f0eee2011-05-26 01:26:41 +0100781ExternalReference ExternalReference::compute_output_frames_function(
782 Isolate* isolate) {
783 return ExternalReference(
784 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100785}
786
787
Steve Block44f0eee2011-05-26 01:26:41 +0100788ExternalReference ExternalReference::global_contexts_list(Isolate* isolate) {
789 return ExternalReference(isolate->heap()->global_contexts_list_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000790}
791
792
Steve Block44f0eee2011-05-26 01:26:41 +0100793ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
794 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000795}
796
797
Steve Block44f0eee2011-05-26 01:26:41 +0100798ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
799 Isolate* isolate) {
800 return ExternalReference(
801 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000802}
803
804
Steve Block44f0eee2011-05-26 01:26:41 +0100805ExternalReference ExternalReference::the_hole_value_location(Isolate* isolate) {
806 return ExternalReference(isolate->factory()->the_hole_value().location());
Ben Murdoch086aeea2011-05-13 15:57:08 +0100807}
808
809
Steve Block44f0eee2011-05-26 01:26:41 +0100810ExternalReference ExternalReference::arguments_marker_location(
811 Isolate* isolate) {
812 return ExternalReference(isolate->factory()->arguments_marker().location());
Steve Blocka7e24c12009-10-30 11:49:00 +0000813}
814
815
Steve Block44f0eee2011-05-26 01:26:41 +0100816ExternalReference ExternalReference::roots_address(Isolate* isolate) {
817 return ExternalReference(isolate->heap()->roots_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000818}
819
820
Steve Block44f0eee2011-05-26 01:26:41 +0100821ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
822 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +0000823}
824
825
Steve Block44f0eee2011-05-26 01:26:41 +0100826ExternalReference ExternalReference::address_of_real_stack_limit(
827 Isolate* isolate) {
828 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +0000829}
830
831
Steve Block44f0eee2011-05-26 01:26:41 +0100832ExternalReference ExternalReference::address_of_regexp_stack_limit(
833 Isolate* isolate) {
834 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000835}
836
837
Steve Block44f0eee2011-05-26 01:26:41 +0100838ExternalReference ExternalReference::new_space_start(Isolate* isolate) {
839 return ExternalReference(isolate->heap()->NewSpaceStart());
Andrei Popescu402d9372010-02-26 13:31:12 +0000840}
841
842
Steve Block44f0eee2011-05-26 01:26:41 +0100843ExternalReference ExternalReference::new_space_mask(Isolate* isolate) {
844 Address mask = reinterpret_cast<Address>(isolate->heap()->NewSpaceMask());
845 return ExternalReference(mask);
Steve Blocka7e24c12009-10-30 11:49:00 +0000846}
847
848
Steve Block44f0eee2011-05-26 01:26:41 +0100849ExternalReference ExternalReference::new_space_allocation_top_address(
850 Isolate* isolate) {
851 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000852}
853
854
Steve Block44f0eee2011-05-26 01:26:41 +0100855ExternalReference ExternalReference::heap_always_allocate_scope_depth(
856 Isolate* isolate) {
857 Heap* heap = isolate->heap();
858 return ExternalReference(heap->always_allocate_scope_depth_address());
859}
860
861
862ExternalReference ExternalReference::new_space_allocation_limit_address(
863 Isolate* isolate) {
864 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000865}
866
Steve Blockd0582a62009-12-15 09:54:21 +0000867
John Reck59135872010-11-02 12:39:01 -0700868ExternalReference ExternalReference::handle_scope_level_address() {
869 return ExternalReference(HandleScope::current_level_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000870}
871
872
873ExternalReference ExternalReference::handle_scope_next_address() {
874 return ExternalReference(HandleScope::current_next_address());
875}
876
877
878ExternalReference ExternalReference::handle_scope_limit_address() {
879 return ExternalReference(HandleScope::current_limit_address());
880}
881
882
Steve Block44f0eee2011-05-26 01:26:41 +0100883ExternalReference ExternalReference::scheduled_exception_address(
884 Isolate* isolate) {
885 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000886}
887
888
Ben Murdochb0fe1622011-05-05 13:52:32 +0100889ExternalReference ExternalReference::address_of_min_int() {
890 return ExternalReference(reinterpret_cast<void*>(
891 const_cast<double*>(&DoubleConstant::min_int)));
892}
893
894
895ExternalReference ExternalReference::address_of_one_half() {
896 return ExternalReference(reinterpret_cast<void*>(
897 const_cast<double*>(&DoubleConstant::one_half)));
898}
899
900
Ben Murdochb8e0da22011-05-16 14:20:40 +0100901ExternalReference ExternalReference::address_of_minus_zero() {
902 return ExternalReference(reinterpret_cast<void*>(
903 const_cast<double*>(&DoubleConstant::minus_zero)));
904}
905
906
Ben Murdoch257744e2011-11-30 15:57:28 +0000907ExternalReference ExternalReference::address_of_zero() {
908 return ExternalReference(reinterpret_cast<void*>(
909 const_cast<double*>(&DoubleConstant::zero)));
910}
911
912
913ExternalReference ExternalReference::address_of_uint8_max_value() {
914 return ExternalReference(reinterpret_cast<void*>(
915 const_cast<double*>(&DoubleConstant::uint8_max_value)));
916}
917
918
Ben Murdochb0fe1622011-05-05 13:52:32 +0100919ExternalReference ExternalReference::address_of_negative_infinity() {
920 return ExternalReference(reinterpret_cast<void*>(
921 const_cast<double*>(&DoubleConstant::negative_infinity)));
922}
923
924
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000925ExternalReference ExternalReference::address_of_canonical_non_hole_nan() {
Steve Block44f0eee2011-05-26 01:26:41 +0100926 return ExternalReference(reinterpret_cast<void*>(
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000927 const_cast<double*>(&DoubleConstant::canonical_non_hole_nan)));
928}
929
930
931ExternalReference ExternalReference::address_of_the_hole_nan() {
932 return ExternalReference(reinterpret_cast<void*>(
933 const_cast<double*>(&DoubleConstant::the_hole_nan)));
Steve Block44f0eee2011-05-26 01:26:41 +0100934}
935
936
Steve Block6ded16b2010-05-10 14:33:55 +0100937#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000938
Steve Block44f0eee2011-05-26 01:26:41 +0100939ExternalReference ExternalReference::re_check_stack_guard_state(
940 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000941 Address function;
942#ifdef V8_TARGET_ARCH_X64
943 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
944#elif V8_TARGET_ARCH_IA32
945 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
946#elif V8_TARGET_ARCH_ARM
947 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +0100948#elif V8_TARGET_ARCH_MIPS
949 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +0000950#else
Leon Clarke4515c472010-02-03 11:58:03 +0000951 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000952#endif
Steve Block44f0eee2011-05-26 01:26:41 +0100953 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +0000954}
955
Steve Block44f0eee2011-05-26 01:26:41 +0100956ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000957 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100958 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000959}
960
Steve Block44f0eee2011-05-26 01:26:41 +0100961ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
962 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000963 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +0100964 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +0000965 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
966}
967
Leon Clarkee46be812010-01-19 14:06:41 +0000968ExternalReference ExternalReference::re_word_character_map() {
969 return ExternalReference(
970 NativeRegExpMacroAssembler::word_character_map_address());
971}
972
Steve Block44f0eee2011-05-26 01:26:41 +0100973ExternalReference ExternalReference::address_of_static_offsets_vector(
974 Isolate* isolate) {
975 return ExternalReference(
976 OffsetsVector::static_offsets_vector_address(isolate));
Leon Clarkee46be812010-01-19 14:06:41 +0000977}
978
Steve Block44f0eee2011-05-26 01:26:41 +0100979ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
980 Isolate* isolate) {
981 return ExternalReference(
982 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000983}
984
Steve Block44f0eee2011-05-26 01:26:41 +0100985ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
986 Isolate* isolate) {
987 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000988}
989
Steve Block6ded16b2010-05-10 14:33:55 +0100990#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000991
992
993static double add_two_doubles(double x, double y) {
994 return x + y;
995}
996
997
998static double sub_two_doubles(double x, double y) {
999 return x - y;
1000}
1001
1002
1003static double mul_two_doubles(double x, double y) {
1004 return x * y;
1005}
1006
1007
1008static double div_two_doubles(double x, double y) {
1009 return x / y;
1010}
1011
1012
1013static double mod_two_doubles(double x, double y) {
Leon Clarkee46be812010-01-19 14:06:41 +00001014 return modulo(x, y);
Steve Blocka7e24c12009-10-30 11:49:00 +00001015}
1016
1017
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001018static double math_sin_double(double x) {
1019 return sin(x);
1020}
1021
1022
1023static double math_cos_double(double x) {
1024 return cos(x);
1025}
1026
1027
1028static double math_log_double(double x) {
1029 return log(x);
1030}
1031
1032
Steve Block44f0eee2011-05-26 01:26:41 +01001033ExternalReference ExternalReference::math_sin_double_function(
1034 Isolate* isolate) {
1035 return ExternalReference(Redirect(isolate,
1036 FUNCTION_ADDR(math_sin_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001037 BUILTIN_FP_CALL));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001038}
1039
1040
Steve Block44f0eee2011-05-26 01:26:41 +01001041ExternalReference ExternalReference::math_cos_double_function(
1042 Isolate* isolate) {
1043 return ExternalReference(Redirect(isolate,
1044 FUNCTION_ADDR(math_cos_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001045 BUILTIN_FP_CALL));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001046}
1047
1048
Steve Block44f0eee2011-05-26 01:26:41 +01001049ExternalReference ExternalReference::math_log_double_function(
1050 Isolate* isolate) {
1051 return ExternalReference(Redirect(isolate,
1052 FUNCTION_ADDR(math_log_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001053 BUILTIN_FP_CALL));
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001054}
1055
1056
Ben Murdochb0fe1622011-05-05 13:52:32 +01001057// Helper function to compute x^y, where y is known to be an
1058// integer. Uses binary decomposition to limit the number of
1059// multiplications; see the discussion in "Hacker's Delight" by Henry
1060// S. Warren, Jr., figure 11-6, page 213.
1061double power_double_int(double x, int y) {
1062 double m = (y < 0) ? 1 / x : x;
1063 unsigned n = (y < 0) ? -y : y;
1064 double p = 1;
1065 while (n != 0) {
1066 if ((n & 1) != 0) p *= m;
1067 m *= m;
1068 if ((n & 2) != 0) p *= m;
1069 m *= m;
1070 n >>= 2;
1071 }
1072 return p;
1073}
1074
1075
1076double power_double_double(double x, double y) {
1077 int y_int = static_cast<int>(y);
1078 if (y == y_int) {
1079 return power_double_int(x, y_int); // Returns 1.0 for exponent 0.
1080 }
1081 if (!isinf(x)) {
Steve Block1e0659c2011-05-24 12:43:12 +01001082 if (y == 0.5) return sqrt(x + 0.0); // -0 must be converted to +0.
1083 if (y == -0.5) return 1.0 / sqrt(x + 0.0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001084 }
1085 if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
1086 return OS::nan_value();
1087 }
1088 return pow(x, y);
1089}
1090
1091
Steve Block44f0eee2011-05-26 01:26:41 +01001092ExternalReference ExternalReference::power_double_double_function(
1093 Isolate* isolate) {
1094 return ExternalReference(Redirect(isolate,
1095 FUNCTION_ADDR(power_double_double),
Ben Murdoch257744e2011-11-30 15:57:28 +00001096 BUILTIN_FP_FP_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001097}
1098
1099
Steve Block44f0eee2011-05-26 01:26:41 +01001100ExternalReference ExternalReference::power_double_int_function(
1101 Isolate* isolate) {
1102 return ExternalReference(Redirect(isolate,
1103 FUNCTION_ADDR(power_double_int),
Ben Murdoch257744e2011-11-30 15:57:28 +00001104 BUILTIN_FP_INT_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +01001105}
1106
1107
Leon Clarkee46be812010-01-19 14:06:41 +00001108static int native_compare_doubles(double y, double x) {
1109 if (x == y) return EQUAL;
1110 return x < y ? LESS : GREATER;
Steve Blocka7e24c12009-10-30 11:49:00 +00001111}
1112
1113
1114ExternalReference ExternalReference::double_fp_operation(
Steve Block44f0eee2011-05-26 01:26:41 +01001115 Token::Value operation, Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +00001116 typedef double BinaryFPOperation(double x, double y);
1117 BinaryFPOperation* function = NULL;
1118 switch (operation) {
1119 case Token::ADD:
1120 function = &add_two_doubles;
1121 break;
1122 case Token::SUB:
1123 function = &sub_two_doubles;
1124 break;
1125 case Token::MUL:
1126 function = &mul_two_doubles;
1127 break;
1128 case Token::DIV:
1129 function = &div_two_doubles;
1130 break;
1131 case Token::MOD:
1132 function = &mod_two_doubles;
1133 break;
1134 default:
1135 UNREACHABLE();
1136 }
Steve Block44f0eee2011-05-26 01:26:41 +01001137 return ExternalReference(Redirect(isolate,
1138 FUNCTION_ADDR(function),
Ben Murdoch257744e2011-11-30 15:57:28 +00001139 BUILTIN_FP_FP_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001140}
1141
1142
Steve Block44f0eee2011-05-26 01:26:41 +01001143ExternalReference ExternalReference::compare_doubles(Isolate* isolate) {
1144 return ExternalReference(Redirect(isolate,
1145 FUNCTION_ADDR(native_compare_doubles),
Ben Murdoch257744e2011-11-30 15:57:28 +00001146 BUILTIN_COMPARE_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001147}
1148
1149
Steve Blocka7e24c12009-10-30 11:49:00 +00001150#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +01001151ExternalReference ExternalReference::debug_break(Isolate* isolate) {
Ben Murdoch8b112d22011-06-08 16:22:53 +01001152 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug_Break)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001153}
1154
1155
Steve Block44f0eee2011-05-26 01:26:41 +01001156ExternalReference ExternalReference::debug_step_in_fp_address(
1157 Isolate* isolate) {
1158 return ExternalReference(isolate->debug()->step_in_fp_addr());
Steve Blocka7e24c12009-10-30 11:49:00 +00001159}
1160#endif
1161
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001162
Ben Murdochb0fe1622011-05-05 13:52:32 +01001163void PositionsRecorder::RecordPosition(int pos) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001164 ASSERT(pos != RelocInfo::kNoPosition);
1165 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001166 state_.current_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001167#ifdef ENABLE_GDB_JIT_INTERFACE
1168 if (gdbjit_lineinfo_ != NULL) {
1169 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, false);
1170 }
1171#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001172}
1173
1174
1175void PositionsRecorder::RecordStatementPosition(int pos) {
1176 ASSERT(pos != RelocInfo::kNoPosition);
1177 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001178 state_.current_statement_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001179#ifdef ENABLE_GDB_JIT_INTERFACE
1180 if (gdbjit_lineinfo_ != NULL) {
1181 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, true);
1182 }
1183#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001184}
1185
1186
1187bool PositionsRecorder::WriteRecordedPositions() {
1188 bool written = false;
1189
1190 // Write the statement position if it is different from what was written last
1191 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001192 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001193 EnsureSpace ensure_space(assembler_);
1194 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001195 state_.current_statement_position);
1196 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001197 written = true;
1198 }
1199
1200 // Write the position if it is different from what was written last time and
Ben Murdochb0fe1622011-05-05 13:52:32 +01001201 // also different from the written statement position.
1202 if (state_.current_position != state_.written_position &&
1203 state_.current_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001204 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001205 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1206 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001207 written = true;
1208 }
1209
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001210 // Return whether something was written.
1211 return written;
1212}
1213
Steve Blocka7e24c12009-10-30 11:49:00 +00001214} } // namespace v8::internal