blob: bfecc774cb777b63eefb070e30ee63a0bcdabe50 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// 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.
33// Copyright 2006-2009 the V8 project authors. All rights reserved.
34
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;
Steve Block44f0eee2011-05-26 01:26:41 +010072const double DoubleConstant::nan = OS::nan_value();
Ben Murdochb0fe1622011-05-05 13:52:32 +010073const double DoubleConstant::negative_infinity = -V8_INFINITY;
Ben Murdoche0cee9b2011-05-25 10:26:03 +010074const char* RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING";
Ben Murdochb0fe1622011-05-05 13:52:32 +010075
Steve Blocka7e24c12009-10-30 11:49:00 +000076// -----------------------------------------------------------------------------
Steve Block053d10c2011-06-13 19:13:29 +010077// Implementation of AssemblerBase
78
79AssemblerBase::AssemblerBase(Isolate* isolate)
80 : isolate_(isolate),
81 jit_cookie_(0) {
82 if (FLAG_mask_constants_with_cookie && isolate != NULL) {
83 jit_cookie_ = V8::RandomPrivate(isolate);
84 }
85}
86
87
88// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +000089// Implementation of Label
90
91int Label::pos() const {
92 if (pos_ < 0) return -pos_ - 1;
93 if (pos_ > 0) return pos_ - 1;
94 UNREACHABLE();
95 return 0;
96}
97
98
99// -----------------------------------------------------------------------------
100// Implementation of RelocInfoWriter and RelocIterator
101//
102// Encoding
103//
104// The most common modes are given single-byte encodings. Also, it is
105// easy to identify the type of reloc info and skip unwanted modes in
106// an iteration.
107//
108// The encoding relies on the fact that there are less than 14
109// different relocation modes.
110//
111// embedded_object: [6 bits pc delta] 00
112//
113// code_taget: [6 bits pc delta] 01
114//
115// position: [6 bits pc delta] 10,
116// [7 bits signed data delta] 0
117//
118// statement_position: [6 bits pc delta] 10,
119// [7 bits signed data delta] 1
120//
121// any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only
122// 00 [6 bits pc delta]
123//
124// pc-jump: 00 1111 11,
125// 00 [6 bits pc delta]
126//
127// pc-jump: 01 1111 11,
128// (variable length) 7 - 26 bit pc delta, written in chunks of 7
129// bits, the lowest 7 bits written first.
130//
131// data-jump + pos: 00 1110 11,
132// signed intptr_t, lowest byte written first
133//
134// data-jump + st.pos: 01 1110 11,
135// signed intptr_t, lowest byte written first
136//
137// data-jump + comm.: 10 1110 11,
138// signed intptr_t, lowest byte written first
139//
140const int kMaxRelocModes = 14;
141
142const int kTagBits = 2;
143const int kTagMask = (1 << kTagBits) - 1;
144const int kExtraTagBits = 4;
145const int kPositionTypeTagBits = 1;
146const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits;
147
148const int kEmbeddedObjectTag = 0;
149const int kCodeTargetTag = 1;
150const int kPositionTag = 2;
151const int kDefaultTag = 3;
152
153const int kPCJumpTag = (1 << kExtraTagBits) - 1;
154
155const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
156const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100157const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000158
159const int kVariableLengthPCJumpTopTag = 1;
160const int kChunkBits = 7;
161const int kChunkMask = (1 << kChunkBits) - 1;
162const int kLastChunkTagBits = 1;
163const int kLastChunkTagMask = 1;
164const int kLastChunkTag = 1;
165
166
167const int kDataJumpTag = kPCJumpTag - 1;
168
169const int kNonstatementPositionTag = 0;
170const int kStatementPositionTag = 1;
171const int kCommentTag = 2;
172
173
174uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
175 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
176 // Otherwise write a variable length PC jump for the bits that do
177 // not fit in the kSmallPCDeltaBits bits.
178 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
179 WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag);
180 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
181 ASSERT(pc_jump > 0);
182 // Write kChunkBits size chunks of the pc_jump.
183 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
184 byte b = pc_jump & kChunkMask;
185 *--pos_ = b << kLastChunkTagBits;
186 }
187 // Tag the last chunk so it can be identified.
188 *pos_ = *pos_ | kLastChunkTag;
189 // Return the remaining kSmallPCDeltaBits of the pc_delta.
190 return pc_delta & kSmallPCDeltaMask;
191}
192
193
194void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
195 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
196 pc_delta = WriteVariableLengthPCJump(pc_delta);
197 *--pos_ = pc_delta << kTagBits | tag;
198}
199
200
201void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000202 *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000203}
204
205
206void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000207 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
208 extra_tag << kTagBits |
209 kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000210}
211
212
213void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
214 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
215 pc_delta = WriteVariableLengthPCJump(pc_delta);
216 WriteExtraTag(extra_tag, 0);
217 *--pos_ = pc_delta;
218}
219
220
221void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
222 WriteExtraTag(kDataJumpTag, top_tag);
223 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000224 *--pos_ = static_cast<byte>(data_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
226 data_delta = data_delta >> kBitsPerByte;
227 }
228}
229
230
231void RelocInfoWriter::Write(const RelocInfo* rinfo) {
232#ifdef DEBUG
233 byte* begin_pos = pos_;
234#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 ASSERT(rinfo->pc() - last_pc_ >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100236 ASSERT(RelocInfo::NUMBER_OF_MODES <= kMaxRelocModes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000238 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000239 RelocInfo::Mode rmode = rinfo->rmode();
240
241 // The two most common modes are given small tags, and usually fit in a byte.
242 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
243 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
244 } else if (rmode == RelocInfo::CODE_TARGET) {
245 WriteTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100246 ASSERT(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000247 } else if (RelocInfo::IsPosition(rmode)) {
248 // Use signed delta-encoding for data.
249 intptr_t data_delta = rinfo->data() - last_data_;
250 int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag
251 : kStatementPositionTag;
252 // Check if data is small enough to fit in a tagged byte.
253 // We cannot use is_intn because data_delta is not an int32_t.
254 if (data_delta >= -(1 << (kSmallDataBits-1)) &&
255 data_delta < 1 << (kSmallDataBits-1)) {
256 WriteTaggedPC(pc_delta, kPositionTag);
257 WriteTaggedData(data_delta, pos_type_tag);
258 last_data_ = rinfo->data();
259 } else {
260 // Otherwise, use costly encoding.
261 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
262 WriteExtraTaggedData(data_delta, pos_type_tag);
263 last_data_ = rinfo->data();
264 }
265 } else if (RelocInfo::IsComment(rmode)) {
266 // Comments are normally not generated, so we use the costly encoding.
267 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
268 WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag);
269 last_data_ = rinfo->data();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100270 ASSERT(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000271 } else {
272 // For all other modes we simply use the mode as the extra tag.
273 // None of these modes need a data component.
274 ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag);
275 WriteExtraTaggedPC(pc_delta, rmode);
276 }
277 last_pc_ = rinfo->pc();
278#ifdef DEBUG
279 ASSERT(begin_pos - pos_ <= kMaxSize);
280#endif
281}
282
283
284inline int RelocIterator::AdvanceGetTag() {
285 return *--pos_ & kTagMask;
286}
287
288
289inline int RelocIterator::GetExtraTag() {
290 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
291}
292
293
294inline int RelocIterator::GetTopTag() {
295 return *pos_ >> (kTagBits + kExtraTagBits);
296}
297
298
299inline void RelocIterator::ReadTaggedPC() {
300 rinfo_.pc_ += *pos_ >> kTagBits;
301}
302
303
304inline void RelocIterator::AdvanceReadPC() {
305 rinfo_.pc_ += *--pos_;
306}
307
308
309void RelocIterator::AdvanceReadData() {
310 intptr_t x = 0;
311 for (int i = 0; i < kIntptrSize; i++) {
312 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
313 }
314 rinfo_.data_ += x;
315}
316
317
318void RelocIterator::AdvanceReadVariableLengthPCJump() {
319 // Read the 32-kSmallPCDeltaBits most significant bits of the
320 // pc jump in kChunkBits bit chunks and shift them into place.
321 // Stop when the last chunk is encountered.
322 uint32_t pc_jump = 0;
323 for (int i = 0; i < kIntSize; i++) {
324 byte pc_jump_part = *--pos_;
325 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
326 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
327 }
328 // The least significant kSmallPCDeltaBits bits will be added
329 // later.
330 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
331}
332
333
334inline int RelocIterator::GetPositionTypeTag() {
335 return *pos_ & ((1 << kPositionTypeTagBits) - 1);
336}
337
338
339inline void RelocIterator::ReadTaggedData() {
340 int8_t signed_b = *pos_;
341 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
342 rinfo_.data_ += signed_b >> kPositionTypeTagBits;
343}
344
345
346inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) {
347 if (tag == kStatementPositionTag) {
348 return RelocInfo::STATEMENT_POSITION;
349 } else if (tag == kNonstatementPositionTag) {
350 return RelocInfo::POSITION;
351 } else {
352 ASSERT(tag == kCommentTag);
353 return RelocInfo::COMMENT;
354 }
355}
356
357
358void RelocIterator::next() {
359 ASSERT(!done());
360 // Basically, do the opposite of RelocInfoWriter::Write.
361 // Reading of data is as far as possible avoided for unwanted modes,
362 // but we must always update the pc.
363 //
364 // We exit this loop by returning when we find a mode we want.
365 while (pos_ > end_) {
366 int tag = AdvanceGetTag();
367 if (tag == kEmbeddedObjectTag) {
368 ReadTaggedPC();
369 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
370 } else if (tag == kCodeTargetTag) {
371 ReadTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000372 if (SetMode(RelocInfo::CODE_TARGET)) return;
373 } else if (tag == kPositionTag) {
374 ReadTaggedPC();
375 Advance();
376 // Check if we want source positions.
377 if (mode_mask_ & RelocInfo::kPositionMask) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100378 ReadTaggedData();
379 if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 }
381 } else {
382 ASSERT(tag == kDefaultTag);
383 int extra_tag = GetExtraTag();
384 if (extra_tag == kPCJumpTag) {
385 int top_tag = GetTopTag();
386 if (top_tag == kVariableLengthPCJumpTopTag) {
387 AdvanceReadVariableLengthPCJump();
388 } else {
389 AdvanceReadPC();
390 }
391 } else if (extra_tag == kDataJumpTag) {
392 // Check if we want debug modes (the only ones with data).
393 if (mode_mask_ & RelocInfo::kDebugMask) {
394 int top_tag = GetTopTag();
395 AdvanceReadData();
396 if (SetMode(DebugInfoModeFromTag(top_tag))) return;
397 } else {
398 // Otherwise, just skip over the data.
399 Advance(kIntptrSize);
400 }
401 } else {
402 AdvanceReadPC();
403 if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return;
404 }
405 }
406 }
407 done_ = true;
408}
409
410
411RelocIterator::RelocIterator(Code* code, int mode_mask) {
412 rinfo_.pc_ = code->instruction_start();
413 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100414 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000415 pos_ = code->relocation_start() + code->relocation_size();
416 end_ = code->relocation_start();
417 done_ = false;
418 mode_mask_ = mode_mask;
419 if (mode_mask_ == 0) pos_ = end_;
420 next();
421}
422
423
424RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
425 rinfo_.pc_ = desc.buffer;
426 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100427 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000428 pos_ = desc.buffer + desc.buffer_size;
429 end_ = pos_ - desc.reloc_size;
430 done_ = false;
431 mode_mask_ = mode_mask;
432 if (mode_mask_ == 0) pos_ = end_;
433 next();
434}
435
436
437// -----------------------------------------------------------------------------
438// Implementation of RelocInfo
439
440
441#ifdef ENABLE_DISASSEMBLER
442const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
443 switch (rmode) {
444 case RelocInfo::NONE:
445 return "no reloc";
446 case RelocInfo::EMBEDDED_OBJECT:
447 return "embedded object";
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 case RelocInfo::CONSTRUCT_CALL:
449 return "code target (js construct call)";
450 case RelocInfo::CODE_TARGET_CONTEXT:
451 return "code target (context)";
Andrei Popescu402d9372010-02-26 13:31:12 +0000452 case RelocInfo::DEBUG_BREAK:
453#ifndef ENABLE_DEBUGGER_SUPPORT
454 UNREACHABLE();
455#endif
456 return "debug break";
Steve Blocka7e24c12009-10-30 11:49:00 +0000457 case RelocInfo::CODE_TARGET:
458 return "code target";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100459 case RelocInfo::GLOBAL_PROPERTY_CELL:
460 return "global property cell";
Steve Blocka7e24c12009-10-30 11:49:00 +0000461 case RelocInfo::RUNTIME_ENTRY:
462 return "runtime entry";
463 case RelocInfo::JS_RETURN:
464 return "js return";
465 case RelocInfo::COMMENT:
466 return "comment";
467 case RelocInfo::POSITION:
468 return "position";
469 case RelocInfo::STATEMENT_POSITION:
470 return "statement position";
471 case RelocInfo::EXTERNAL_REFERENCE:
472 return "external reference";
473 case RelocInfo::INTERNAL_REFERENCE:
474 return "internal reference";
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100475 case RelocInfo::DEBUG_BREAK_SLOT:
476#ifndef ENABLE_DEBUGGER_SUPPORT
477 UNREACHABLE();
478#endif
479 return "debug break slot";
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 case RelocInfo::NUMBER_OF_MODES:
481 UNREACHABLE();
482 return "number_of_modes";
483 }
484 return "unknown relocation type";
485}
486
487
Ben Murdochb0fe1622011-05-05 13:52:32 +0100488void RelocInfo::Print(FILE* out) {
489 PrintF(out, "%p %s", pc_, RelocModeName(rmode_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000490 if (IsComment(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100491 PrintF(out, " (%s)", reinterpret_cast<char*>(data_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000492 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100493 PrintF(out, " (");
494 target_object()->ShortPrint(out);
495 PrintF(out, ")");
Steve Blocka7e24c12009-10-30 11:49:00 +0000496 } else if (rmode_ == EXTERNAL_REFERENCE) {
497 ExternalReferenceEncoder ref_encoder;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100498 PrintF(out, " (%s) (%p)",
Steve Blocka7e24c12009-10-30 11:49:00 +0000499 ref_encoder.NameOfAddress(*target_reference_address()),
500 *target_reference_address());
501 } else if (IsCodeTarget(rmode_)) {
502 Code* code = Code::GetCodeFromTargetAddress(target_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100503 PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()),
504 target_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000505 } else if (IsPosition(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100506 PrintF(out, " (%" V8_PTR_PREFIX "d)", data());
Ben Murdoch8b112d22011-06-08 16:22:53 +0100507 } else if (rmode_ == RelocInfo::RUNTIME_ENTRY &&
508 Isolate::Current()->deoptimizer_data() != NULL) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100509 // Depotimization bailouts are stored as runtime entries.
510 int id = Deoptimizer::GetDeoptimizationId(
511 target_address(), Deoptimizer::EAGER);
512 if (id != Deoptimizer::kNotDeoptimizationEntry) {
513 PrintF(out, " (deoptimization bailout %d)", id);
514 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000515 }
516
Ben Murdochb0fe1622011-05-05 13:52:32 +0100517 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000518}
519#endif // ENABLE_DISASSEMBLER
520
521
522#ifdef DEBUG
523void RelocInfo::Verify() {
524 switch (rmode_) {
525 case EMBEDDED_OBJECT:
526 Object::VerifyPointer(target_object());
527 break;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100528 case GLOBAL_PROPERTY_CELL:
529 Object::VerifyPointer(target_cell());
530 break;
Andrei Popescu402d9372010-02-26 13:31:12 +0000531 case DEBUG_BREAK:
532#ifndef ENABLE_DEBUGGER_SUPPORT
533 UNREACHABLE();
534 break;
535#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000536 case CONSTRUCT_CALL:
537 case CODE_TARGET_CONTEXT:
538 case CODE_TARGET: {
539 // convert inline target address to code object
540 Address addr = target_address();
541 ASSERT(addr != NULL);
542 // Check that we can find the right code object.
543 Code* code = Code::GetCodeFromTargetAddress(addr);
Steve Block44f0eee2011-05-26 01:26:41 +0100544 Object* found = HEAP->FindCodeObject(addr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000545 ASSERT(found->IsCode());
546 ASSERT(code->address() == HeapObject::cast(found)->address());
547 break;
548 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000549 case RUNTIME_ENTRY:
550 case JS_RETURN:
551 case COMMENT:
552 case POSITION:
553 case STATEMENT_POSITION:
554 case EXTERNAL_REFERENCE:
555 case INTERNAL_REFERENCE:
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100556 case DEBUG_BREAK_SLOT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000557 case NONE:
558 break;
559 case NUMBER_OF_MODES:
560 UNREACHABLE();
561 break;
562 }
563}
564#endif // DEBUG
565
566
567// -----------------------------------------------------------------------------
568// Implementation of ExternalReference
569
Steve Block44f0eee2011-05-26 01:26:41 +0100570ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
571 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000572
573
Steve Block1e0659c2011-05-24 12:43:12 +0100574ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100575 ApiFunction* fun,
576 Type type = ExternalReference::BUILTIN_CALL,
577 Isolate* isolate = NULL)
578 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +0000579
580
Steve Block44f0eee2011-05-26 01:26:41 +0100581ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
582 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000583
584
Steve Block44f0eee2011-05-26 01:26:41 +0100585ExternalReference::ExternalReference(Runtime::FunctionId id,
586 Isolate* isolate)
587 : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000588
589
Steve Block44f0eee2011-05-26 01:26:41 +0100590ExternalReference::ExternalReference(const Runtime::Function* f,
591 Isolate* isolate)
592 : address_(Redirect(isolate, f->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000593
594
Steve Block44f0eee2011-05-26 01:26:41 +0100595ExternalReference ExternalReference::isolate_address() {
596 return ExternalReference(Isolate::Current());
597}
598
599
600ExternalReference::ExternalReference(const IC_Utility& ic_utility,
601 Isolate* isolate)
602 : address_(Redirect(isolate, ic_utility.address())) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000603
604#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100605ExternalReference::ExternalReference(const Debug_Address& debug_address,
606 Isolate* isolate)
607 : address_(debug_address.address(isolate)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000608#endif
609
610ExternalReference::ExternalReference(StatsCounter* counter)
611 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
612
613
Steve Block44f0eee2011-05-26 01:26:41 +0100614ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
615 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000616
617
618ExternalReference::ExternalReference(const SCTableReference& table_ref)
619 : address_(table_ref.address()) {}
620
621
Steve Block44f0eee2011-05-26 01:26:41 +0100622ExternalReference ExternalReference::perform_gc_function(Isolate* isolate) {
623 return ExternalReference(Redirect(isolate,
624 FUNCTION_ADDR(Runtime::PerformGC)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000625}
626
627
Steve Block44f0eee2011-05-26 01:26:41 +0100628ExternalReference ExternalReference::fill_heap_number_with_random_function(
629 Isolate* isolate) {
630 return ExternalReference(Redirect(
631 isolate,
632 FUNCTION_ADDR(V8::FillHeapNumberWithRandom)));
Steve Block6ded16b2010-05-10 14:33:55 +0100633}
634
635
Steve Block44f0eee2011-05-26 01:26:41 +0100636ExternalReference ExternalReference::delete_handle_scope_extensions(
637 Isolate* isolate) {
638 return ExternalReference(Redirect(
639 isolate,
640 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -0700641}
642
643
Steve Block44f0eee2011-05-26 01:26:41 +0100644ExternalReference ExternalReference::random_uint32_function(
645 Isolate* isolate) {
646 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000647}
648
649
Steve Block44f0eee2011-05-26 01:26:41 +0100650ExternalReference ExternalReference::transcendental_cache_array_address(
651 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100652 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100653 isolate->transcendental_cache()->cache_array_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100654}
655
656
Steve Block44f0eee2011-05-26 01:26:41 +0100657ExternalReference ExternalReference::new_deoptimizer_function(
658 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100659 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100660 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100661}
662
663
Steve Block44f0eee2011-05-26 01:26:41 +0100664ExternalReference ExternalReference::compute_output_frames_function(
665 Isolate* isolate) {
666 return ExternalReference(
667 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100668}
669
670
Steve Block44f0eee2011-05-26 01:26:41 +0100671ExternalReference ExternalReference::global_contexts_list(Isolate* isolate) {
672 return ExternalReference(isolate->heap()->global_contexts_list_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000673}
674
675
Steve Block44f0eee2011-05-26 01:26:41 +0100676ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
677 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000678}
679
680
Steve Block44f0eee2011-05-26 01:26:41 +0100681ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
682 Isolate* isolate) {
683 return ExternalReference(
684 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000685}
686
687
Steve Block44f0eee2011-05-26 01:26:41 +0100688ExternalReference ExternalReference::the_hole_value_location(Isolate* isolate) {
689 return ExternalReference(isolate->factory()->the_hole_value().location());
Ben Murdoch086aeea2011-05-13 15:57:08 +0100690}
691
692
Steve Block44f0eee2011-05-26 01:26:41 +0100693ExternalReference ExternalReference::arguments_marker_location(
694 Isolate* isolate) {
695 return ExternalReference(isolate->factory()->arguments_marker().location());
Steve Blocka7e24c12009-10-30 11:49:00 +0000696}
697
698
Steve Block44f0eee2011-05-26 01:26:41 +0100699ExternalReference ExternalReference::roots_address(Isolate* isolate) {
700 return ExternalReference(isolate->heap()->roots_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000701}
702
703
Steve Block44f0eee2011-05-26 01:26:41 +0100704ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
705 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +0000706}
707
708
Steve Block44f0eee2011-05-26 01:26:41 +0100709ExternalReference ExternalReference::address_of_real_stack_limit(
710 Isolate* isolate) {
711 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +0000712}
713
714
Steve Block44f0eee2011-05-26 01:26:41 +0100715ExternalReference ExternalReference::address_of_regexp_stack_limit(
716 Isolate* isolate) {
717 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000718}
719
720
Steve Block44f0eee2011-05-26 01:26:41 +0100721ExternalReference ExternalReference::new_space_start(Isolate* isolate) {
722 return ExternalReference(isolate->heap()->NewSpaceStart());
Andrei Popescu402d9372010-02-26 13:31:12 +0000723}
724
725
Steve Block44f0eee2011-05-26 01:26:41 +0100726ExternalReference ExternalReference::new_space_mask(Isolate* isolate) {
727 Address mask = reinterpret_cast<Address>(isolate->heap()->NewSpaceMask());
728 return ExternalReference(mask);
Steve Blocka7e24c12009-10-30 11:49:00 +0000729}
730
731
Steve Block44f0eee2011-05-26 01:26:41 +0100732ExternalReference ExternalReference::new_space_allocation_top_address(
733 Isolate* isolate) {
734 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000735}
736
737
Steve Block44f0eee2011-05-26 01:26:41 +0100738ExternalReference ExternalReference::heap_always_allocate_scope_depth(
739 Isolate* isolate) {
740 Heap* heap = isolate->heap();
741 return ExternalReference(heap->always_allocate_scope_depth_address());
742}
743
744
745ExternalReference ExternalReference::new_space_allocation_limit_address(
746 Isolate* isolate) {
747 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000748}
749
Steve Blockd0582a62009-12-15 09:54:21 +0000750
John Reck59135872010-11-02 12:39:01 -0700751ExternalReference ExternalReference::handle_scope_level_address() {
752 return ExternalReference(HandleScope::current_level_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000753}
754
755
756ExternalReference ExternalReference::handle_scope_next_address() {
757 return ExternalReference(HandleScope::current_next_address());
758}
759
760
761ExternalReference ExternalReference::handle_scope_limit_address() {
762 return ExternalReference(HandleScope::current_limit_address());
763}
764
765
Steve Block44f0eee2011-05-26 01:26:41 +0100766ExternalReference ExternalReference::scheduled_exception_address(
767 Isolate* isolate) {
768 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000769}
770
771
Ben Murdochb0fe1622011-05-05 13:52:32 +0100772ExternalReference ExternalReference::address_of_min_int() {
773 return ExternalReference(reinterpret_cast<void*>(
774 const_cast<double*>(&DoubleConstant::min_int)));
775}
776
777
778ExternalReference ExternalReference::address_of_one_half() {
779 return ExternalReference(reinterpret_cast<void*>(
780 const_cast<double*>(&DoubleConstant::one_half)));
781}
782
783
Ben Murdochb8e0da22011-05-16 14:20:40 +0100784ExternalReference ExternalReference::address_of_minus_zero() {
785 return ExternalReference(reinterpret_cast<void*>(
786 const_cast<double*>(&DoubleConstant::minus_zero)));
787}
788
789
Ben Murdochb0fe1622011-05-05 13:52:32 +0100790ExternalReference ExternalReference::address_of_negative_infinity() {
791 return ExternalReference(reinterpret_cast<void*>(
792 const_cast<double*>(&DoubleConstant::negative_infinity)));
793}
794
795
Steve Block44f0eee2011-05-26 01:26:41 +0100796ExternalReference ExternalReference::address_of_nan() {
797 return ExternalReference(reinterpret_cast<void*>(
798 const_cast<double*>(&DoubleConstant::nan)));
799}
800
801
Steve Block6ded16b2010-05-10 14:33:55 +0100802#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000803
Steve Block44f0eee2011-05-26 01:26:41 +0100804ExternalReference ExternalReference::re_check_stack_guard_state(
805 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000806 Address function;
807#ifdef V8_TARGET_ARCH_X64
808 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
809#elif V8_TARGET_ARCH_IA32
810 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
811#elif V8_TARGET_ARCH_ARM
812 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +0100813#elif V8_TARGET_ARCH_MIPS
814 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +0000815#else
Leon Clarke4515c472010-02-03 11:58:03 +0000816 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000817#endif
Steve Block44f0eee2011-05-26 01:26:41 +0100818 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +0000819}
820
Steve Block44f0eee2011-05-26 01:26:41 +0100821ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000822 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100823 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000824}
825
Steve Block44f0eee2011-05-26 01:26:41 +0100826ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
827 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000828 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +0100829 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +0000830 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
831}
832
Leon Clarkee46be812010-01-19 14:06:41 +0000833ExternalReference ExternalReference::re_word_character_map() {
834 return ExternalReference(
835 NativeRegExpMacroAssembler::word_character_map_address());
836}
837
Steve Block44f0eee2011-05-26 01:26:41 +0100838ExternalReference ExternalReference::address_of_static_offsets_vector(
839 Isolate* isolate) {
840 return ExternalReference(
841 OffsetsVector::static_offsets_vector_address(isolate));
Leon Clarkee46be812010-01-19 14:06:41 +0000842}
843
Steve Block44f0eee2011-05-26 01:26:41 +0100844ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
845 Isolate* isolate) {
846 return ExternalReference(
847 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000848}
849
Steve Block44f0eee2011-05-26 01:26:41 +0100850ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
851 Isolate* isolate) {
852 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000853}
854
Steve Block6ded16b2010-05-10 14:33:55 +0100855#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000856
857
858static double add_two_doubles(double x, double y) {
859 return x + y;
860}
861
862
863static double sub_two_doubles(double x, double y) {
864 return x - y;
865}
866
867
868static double mul_two_doubles(double x, double y) {
869 return x * y;
870}
871
872
873static double div_two_doubles(double x, double y) {
874 return x / y;
875}
876
877
878static double mod_two_doubles(double x, double y) {
Leon Clarkee46be812010-01-19 14:06:41 +0000879 return modulo(x, y);
Steve Blocka7e24c12009-10-30 11:49:00 +0000880}
881
882
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100883static double math_sin_double(double x) {
884 return sin(x);
885}
886
887
888static double math_cos_double(double x) {
889 return cos(x);
890}
891
892
893static double math_log_double(double x) {
894 return log(x);
895}
896
897
Steve Block44f0eee2011-05-26 01:26:41 +0100898ExternalReference ExternalReference::math_sin_double_function(
899 Isolate* isolate) {
900 return ExternalReference(Redirect(isolate,
901 FUNCTION_ADDR(math_sin_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100902 FP_RETURN_CALL));
903}
904
905
Steve Block44f0eee2011-05-26 01:26:41 +0100906ExternalReference ExternalReference::math_cos_double_function(
907 Isolate* isolate) {
908 return ExternalReference(Redirect(isolate,
909 FUNCTION_ADDR(math_cos_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100910 FP_RETURN_CALL));
911}
912
913
Steve Block44f0eee2011-05-26 01:26:41 +0100914ExternalReference ExternalReference::math_log_double_function(
915 Isolate* isolate) {
916 return ExternalReference(Redirect(isolate,
917 FUNCTION_ADDR(math_log_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100918 FP_RETURN_CALL));
919}
920
921
Ben Murdochb0fe1622011-05-05 13:52:32 +0100922// Helper function to compute x^y, where y is known to be an
923// integer. Uses binary decomposition to limit the number of
924// multiplications; see the discussion in "Hacker's Delight" by Henry
925// S. Warren, Jr., figure 11-6, page 213.
926double power_double_int(double x, int y) {
927 double m = (y < 0) ? 1 / x : x;
928 unsigned n = (y < 0) ? -y : y;
929 double p = 1;
930 while (n != 0) {
931 if ((n & 1) != 0) p *= m;
932 m *= m;
933 if ((n & 2) != 0) p *= m;
934 m *= m;
935 n >>= 2;
936 }
937 return p;
938}
939
940
941double power_double_double(double x, double y) {
942 int y_int = static_cast<int>(y);
943 if (y == y_int) {
944 return power_double_int(x, y_int); // Returns 1.0 for exponent 0.
945 }
946 if (!isinf(x)) {
Steve Block1e0659c2011-05-24 12:43:12 +0100947 if (y == 0.5) return sqrt(x + 0.0); // -0 must be converted to +0.
948 if (y == -0.5) return 1.0 / sqrt(x + 0.0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100949 }
950 if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
951 return OS::nan_value();
952 }
953 return pow(x, y);
954}
955
956
Steve Block44f0eee2011-05-26 01:26:41 +0100957ExternalReference ExternalReference::power_double_double_function(
958 Isolate* isolate) {
959 return ExternalReference(Redirect(isolate,
960 FUNCTION_ADDR(power_double_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100961 FP_RETURN_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100962}
963
964
Steve Block44f0eee2011-05-26 01:26:41 +0100965ExternalReference ExternalReference::power_double_int_function(
966 Isolate* isolate) {
967 return ExternalReference(Redirect(isolate,
968 FUNCTION_ADDR(power_double_int),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100969 FP_RETURN_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100970}
971
972
Leon Clarkee46be812010-01-19 14:06:41 +0000973static int native_compare_doubles(double y, double x) {
974 if (x == y) return EQUAL;
975 return x < y ? LESS : GREATER;
Steve Blocka7e24c12009-10-30 11:49:00 +0000976}
977
978
979ExternalReference ExternalReference::double_fp_operation(
Steve Block44f0eee2011-05-26 01:26:41 +0100980 Token::Value operation, Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000981 typedef double BinaryFPOperation(double x, double y);
982 BinaryFPOperation* function = NULL;
983 switch (operation) {
984 case Token::ADD:
985 function = &add_two_doubles;
986 break;
987 case Token::SUB:
988 function = &sub_two_doubles;
989 break;
990 case Token::MUL:
991 function = &mul_two_doubles;
992 break;
993 case Token::DIV:
994 function = &div_two_doubles;
995 break;
996 case Token::MOD:
997 function = &mod_two_doubles;
998 break;
999 default:
1000 UNREACHABLE();
1001 }
1002 // Passing true as 2nd parameter indicates that they return an fp value.
Steve Block44f0eee2011-05-26 01:26:41 +01001003 return ExternalReference(Redirect(isolate,
1004 FUNCTION_ADDR(function),
1005 FP_RETURN_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001006}
1007
1008
Steve Block44f0eee2011-05-26 01:26:41 +01001009ExternalReference ExternalReference::compare_doubles(Isolate* isolate) {
1010 return ExternalReference(Redirect(isolate,
1011 FUNCTION_ADDR(native_compare_doubles),
Steve Block1e0659c2011-05-24 12:43:12 +01001012 BUILTIN_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001013}
1014
1015
Steve Blocka7e24c12009-10-30 11:49:00 +00001016#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +01001017ExternalReference ExternalReference::debug_break(Isolate* isolate) {
Ben Murdoch8b112d22011-06-08 16:22:53 +01001018 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug_Break)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001019}
1020
1021
Steve Block44f0eee2011-05-26 01:26:41 +01001022ExternalReference ExternalReference::debug_step_in_fp_address(
1023 Isolate* isolate) {
1024 return ExternalReference(isolate->debug()->step_in_fp_addr());
Steve Blocka7e24c12009-10-30 11:49:00 +00001025}
1026#endif
1027
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001028
Ben Murdochb0fe1622011-05-05 13:52:32 +01001029void PositionsRecorder::RecordPosition(int pos) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001030 ASSERT(pos != RelocInfo::kNoPosition);
1031 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001032 state_.current_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001033#ifdef ENABLE_GDB_JIT_INTERFACE
1034 if (gdbjit_lineinfo_ != NULL) {
1035 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, false);
1036 }
1037#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001038}
1039
1040
1041void PositionsRecorder::RecordStatementPosition(int pos) {
1042 ASSERT(pos != RelocInfo::kNoPosition);
1043 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001044 state_.current_statement_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001045#ifdef ENABLE_GDB_JIT_INTERFACE
1046 if (gdbjit_lineinfo_ != NULL) {
1047 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, true);
1048 }
1049#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001050}
1051
1052
1053bool PositionsRecorder::WriteRecordedPositions() {
1054 bool written = false;
1055
1056 // Write the statement position if it is different from what was written last
1057 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001058 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001059 EnsureSpace ensure_space(assembler_);
1060 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001061 state_.current_statement_position);
1062 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001063 written = true;
1064 }
1065
1066 // Write the position if it is different from what was written last time and
Ben Murdochb0fe1622011-05-05 13:52:32 +01001067 // also different from the written statement position.
1068 if (state_.current_position != state_.written_position &&
1069 state_.current_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001070 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001071 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1072 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001073 written = true;
1074 }
1075
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001076 // Return whether something was written.
1077 return written;
1078}
1079
Steve Blocka7e24c12009-10-30 11:49:00 +00001080} } // namespace v8::internal