blob: 0322747c083978daf706fec3aa96ada27e0422ec [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// -----------------------------------------------------------------------------
77// Implementation of Label
78
79int Label::pos() const {
80 if (pos_ < 0) return -pos_ - 1;
81 if (pos_ > 0) return pos_ - 1;
82 UNREACHABLE();
83 return 0;
84}
85
86
87// -----------------------------------------------------------------------------
88// Implementation of RelocInfoWriter and RelocIterator
89//
90// Encoding
91//
92// The most common modes are given single-byte encodings. Also, it is
93// easy to identify the type of reloc info and skip unwanted modes in
94// an iteration.
95//
96// The encoding relies on the fact that there are less than 14
97// different relocation modes.
98//
99// embedded_object: [6 bits pc delta] 00
100//
101// code_taget: [6 bits pc delta] 01
102//
103// position: [6 bits pc delta] 10,
104// [7 bits signed data delta] 0
105//
106// statement_position: [6 bits pc delta] 10,
107// [7 bits signed data delta] 1
108//
109// any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only
110// 00 [6 bits pc delta]
111//
112// pc-jump: 00 1111 11,
113// 00 [6 bits pc delta]
114//
115// pc-jump: 01 1111 11,
116// (variable length) 7 - 26 bit pc delta, written in chunks of 7
117// bits, the lowest 7 bits written first.
118//
119// data-jump + pos: 00 1110 11,
120// signed intptr_t, lowest byte written first
121//
122// data-jump + st.pos: 01 1110 11,
123// signed intptr_t, lowest byte written first
124//
125// data-jump + comm.: 10 1110 11,
126// signed intptr_t, lowest byte written first
127//
128const int kMaxRelocModes = 14;
129
130const int kTagBits = 2;
131const int kTagMask = (1 << kTagBits) - 1;
132const int kExtraTagBits = 4;
133const int kPositionTypeTagBits = 1;
134const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits;
135
136const int kEmbeddedObjectTag = 0;
137const int kCodeTargetTag = 1;
138const int kPositionTag = 2;
139const int kDefaultTag = 3;
140
141const int kPCJumpTag = (1 << kExtraTagBits) - 1;
142
143const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
144const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
Steve Block44f0eee2011-05-26 01:26:41 +0100145const int RelocInfo::kMaxSmallPCDelta = kSmallPCDeltaMask;
Steve Blocka7e24c12009-10-30 11:49:00 +0000146
147const int kVariableLengthPCJumpTopTag = 1;
148const int kChunkBits = 7;
149const int kChunkMask = (1 << kChunkBits) - 1;
150const int kLastChunkTagBits = 1;
151const int kLastChunkTagMask = 1;
152const int kLastChunkTag = 1;
153
154
155const int kDataJumpTag = kPCJumpTag - 1;
156
157const int kNonstatementPositionTag = 0;
158const int kStatementPositionTag = 1;
159const int kCommentTag = 2;
160
161
162uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
163 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
164 // Otherwise write a variable length PC jump for the bits that do
165 // not fit in the kSmallPCDeltaBits bits.
166 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
167 WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag);
168 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
169 ASSERT(pc_jump > 0);
170 // Write kChunkBits size chunks of the pc_jump.
171 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
172 byte b = pc_jump & kChunkMask;
173 *--pos_ = b << kLastChunkTagBits;
174 }
175 // Tag the last chunk so it can be identified.
176 *pos_ = *pos_ | kLastChunkTag;
177 // Return the remaining kSmallPCDeltaBits of the pc_delta.
178 return pc_delta & kSmallPCDeltaMask;
179}
180
181
182void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
183 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
184 pc_delta = WriteVariableLengthPCJump(pc_delta);
185 *--pos_ = pc_delta << kTagBits | tag;
186}
187
188
189void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000190 *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000191}
192
193
194void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000195 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
196 extra_tag << kTagBits |
197 kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000198}
199
200
201void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
202 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
203 pc_delta = WriteVariableLengthPCJump(pc_delta);
204 WriteExtraTag(extra_tag, 0);
205 *--pos_ = pc_delta;
206}
207
208
209void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
210 WriteExtraTag(kDataJumpTag, top_tag);
211 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000212 *--pos_ = static_cast<byte>(data_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000213 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
214 data_delta = data_delta >> kBitsPerByte;
215 }
216}
217
218
219void RelocInfoWriter::Write(const RelocInfo* rinfo) {
220#ifdef DEBUG
221 byte* begin_pos = pos_;
222#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000223 ASSERT(rinfo->pc() - last_pc_ >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100224 ASSERT(RelocInfo::NUMBER_OF_MODES <= kMaxRelocModes);
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000226 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000227 RelocInfo::Mode rmode = rinfo->rmode();
228
229 // The two most common modes are given small tags, and usually fit in a byte.
230 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
231 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
232 } else if (rmode == RelocInfo::CODE_TARGET) {
233 WriteTaggedPC(pc_delta, kCodeTargetTag);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100234 ASSERT(begin_pos - pos_ <= RelocInfo::kMaxCallSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 } else if (RelocInfo::IsPosition(rmode)) {
236 // Use signed delta-encoding for data.
237 intptr_t data_delta = rinfo->data() - last_data_;
238 int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag
239 : kStatementPositionTag;
240 // Check if data is small enough to fit in a tagged byte.
241 // We cannot use is_intn because data_delta is not an int32_t.
242 if (data_delta >= -(1 << (kSmallDataBits-1)) &&
243 data_delta < 1 << (kSmallDataBits-1)) {
244 WriteTaggedPC(pc_delta, kPositionTag);
245 WriteTaggedData(data_delta, pos_type_tag);
246 last_data_ = rinfo->data();
247 } else {
248 // Otherwise, use costly encoding.
249 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
250 WriteExtraTaggedData(data_delta, pos_type_tag);
251 last_data_ = rinfo->data();
252 }
253 } else if (RelocInfo::IsComment(rmode)) {
254 // Comments are normally not generated, so we use the costly encoding.
255 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
256 WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag);
257 last_data_ = rinfo->data();
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100258 ASSERT(begin_pos - pos_ >= RelocInfo::kMinRelocCommentSize);
Steve Blocka7e24c12009-10-30 11:49:00 +0000259 } else {
260 // For all other modes we simply use the mode as the extra tag.
261 // None of these modes need a data component.
262 ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag);
263 WriteExtraTaggedPC(pc_delta, rmode);
264 }
265 last_pc_ = rinfo->pc();
266#ifdef DEBUG
267 ASSERT(begin_pos - pos_ <= kMaxSize);
268#endif
269}
270
271
272inline int RelocIterator::AdvanceGetTag() {
273 return *--pos_ & kTagMask;
274}
275
276
277inline int RelocIterator::GetExtraTag() {
278 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
279}
280
281
282inline int RelocIterator::GetTopTag() {
283 return *pos_ >> (kTagBits + kExtraTagBits);
284}
285
286
287inline void RelocIterator::ReadTaggedPC() {
288 rinfo_.pc_ += *pos_ >> kTagBits;
289}
290
291
292inline void RelocIterator::AdvanceReadPC() {
293 rinfo_.pc_ += *--pos_;
294}
295
296
297void RelocIterator::AdvanceReadData() {
298 intptr_t x = 0;
299 for (int i = 0; i < kIntptrSize; i++) {
300 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
301 }
302 rinfo_.data_ += x;
303}
304
305
306void RelocIterator::AdvanceReadVariableLengthPCJump() {
307 // Read the 32-kSmallPCDeltaBits most significant bits of the
308 // pc jump in kChunkBits bit chunks and shift them into place.
309 // Stop when the last chunk is encountered.
310 uint32_t pc_jump = 0;
311 for (int i = 0; i < kIntSize; i++) {
312 byte pc_jump_part = *--pos_;
313 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
314 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
315 }
316 // The least significant kSmallPCDeltaBits bits will be added
317 // later.
318 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
319}
320
321
322inline int RelocIterator::GetPositionTypeTag() {
323 return *pos_ & ((1 << kPositionTypeTagBits) - 1);
324}
325
326
327inline void RelocIterator::ReadTaggedData() {
328 int8_t signed_b = *pos_;
329 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
330 rinfo_.data_ += signed_b >> kPositionTypeTagBits;
331}
332
333
334inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) {
335 if (tag == kStatementPositionTag) {
336 return RelocInfo::STATEMENT_POSITION;
337 } else if (tag == kNonstatementPositionTag) {
338 return RelocInfo::POSITION;
339 } else {
340 ASSERT(tag == kCommentTag);
341 return RelocInfo::COMMENT;
342 }
343}
344
345
346void RelocIterator::next() {
347 ASSERT(!done());
348 // Basically, do the opposite of RelocInfoWriter::Write.
349 // Reading of data is as far as possible avoided for unwanted modes,
350 // but we must always update the pc.
351 //
352 // We exit this loop by returning when we find a mode we want.
353 while (pos_ > end_) {
354 int tag = AdvanceGetTag();
355 if (tag == kEmbeddedObjectTag) {
356 ReadTaggedPC();
357 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
358 } else if (tag == kCodeTargetTag) {
359 ReadTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000360 if (SetMode(RelocInfo::CODE_TARGET)) return;
361 } else if (tag == kPositionTag) {
362 ReadTaggedPC();
363 Advance();
364 // Check if we want source positions.
365 if (mode_mask_ & RelocInfo::kPositionMask) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100366 ReadTaggedData();
367 if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) return;
Steve Blocka7e24c12009-10-30 11:49:00 +0000368 }
369 } else {
370 ASSERT(tag == kDefaultTag);
371 int extra_tag = GetExtraTag();
372 if (extra_tag == kPCJumpTag) {
373 int top_tag = GetTopTag();
374 if (top_tag == kVariableLengthPCJumpTopTag) {
375 AdvanceReadVariableLengthPCJump();
376 } else {
377 AdvanceReadPC();
378 }
379 } else if (extra_tag == kDataJumpTag) {
380 // Check if we want debug modes (the only ones with data).
381 if (mode_mask_ & RelocInfo::kDebugMask) {
382 int top_tag = GetTopTag();
383 AdvanceReadData();
384 if (SetMode(DebugInfoModeFromTag(top_tag))) return;
385 } else {
386 // Otherwise, just skip over the data.
387 Advance(kIntptrSize);
388 }
389 } else {
390 AdvanceReadPC();
391 if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return;
392 }
393 }
394 }
395 done_ = true;
396}
397
398
399RelocIterator::RelocIterator(Code* code, int mode_mask) {
400 rinfo_.pc_ = code->instruction_start();
401 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100402 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 pos_ = code->relocation_start() + code->relocation_size();
404 end_ = code->relocation_start();
405 done_ = false;
406 mode_mask_ = mode_mask;
407 if (mode_mask_ == 0) pos_ = end_;
408 next();
409}
410
411
412RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
413 rinfo_.pc_ = desc.buffer;
414 rinfo_.data_ = 0;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100415 // Relocation info is read backwards.
Steve Blocka7e24c12009-10-30 11:49:00 +0000416 pos_ = desc.buffer + desc.buffer_size;
417 end_ = pos_ - desc.reloc_size;
418 done_ = false;
419 mode_mask_ = mode_mask;
420 if (mode_mask_ == 0) pos_ = end_;
421 next();
422}
423
424
425// -----------------------------------------------------------------------------
426// Implementation of RelocInfo
427
428
429#ifdef ENABLE_DISASSEMBLER
430const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
431 switch (rmode) {
432 case RelocInfo::NONE:
433 return "no reloc";
434 case RelocInfo::EMBEDDED_OBJECT:
435 return "embedded object";
Steve Blocka7e24c12009-10-30 11:49:00 +0000436 case RelocInfo::CONSTRUCT_CALL:
437 return "code target (js construct call)";
438 case RelocInfo::CODE_TARGET_CONTEXT:
439 return "code target (context)";
Andrei Popescu402d9372010-02-26 13:31:12 +0000440 case RelocInfo::DEBUG_BREAK:
441#ifndef ENABLE_DEBUGGER_SUPPORT
442 UNREACHABLE();
443#endif
444 return "debug break";
Steve Blocka7e24c12009-10-30 11:49:00 +0000445 case RelocInfo::CODE_TARGET:
446 return "code target";
Ben Murdochb0fe1622011-05-05 13:52:32 +0100447 case RelocInfo::GLOBAL_PROPERTY_CELL:
448 return "global property cell";
Steve Blocka7e24c12009-10-30 11:49:00 +0000449 case RelocInfo::RUNTIME_ENTRY:
450 return "runtime entry";
451 case RelocInfo::JS_RETURN:
452 return "js return";
453 case RelocInfo::COMMENT:
454 return "comment";
455 case RelocInfo::POSITION:
456 return "position";
457 case RelocInfo::STATEMENT_POSITION:
458 return "statement position";
459 case RelocInfo::EXTERNAL_REFERENCE:
460 return "external reference";
461 case RelocInfo::INTERNAL_REFERENCE:
462 return "internal reference";
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100463 case RelocInfo::DEBUG_BREAK_SLOT:
464#ifndef ENABLE_DEBUGGER_SUPPORT
465 UNREACHABLE();
466#endif
467 return "debug break slot";
Steve Blocka7e24c12009-10-30 11:49:00 +0000468 case RelocInfo::NUMBER_OF_MODES:
469 UNREACHABLE();
470 return "number_of_modes";
471 }
472 return "unknown relocation type";
473}
474
475
Ben Murdochb0fe1622011-05-05 13:52:32 +0100476void RelocInfo::Print(FILE* out) {
477 PrintF(out, "%p %s", pc_, RelocModeName(rmode_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 if (IsComment(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100479 PrintF(out, " (%s)", reinterpret_cast<char*>(data_));
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 } else if (rmode_ == EMBEDDED_OBJECT) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100481 PrintF(out, " (");
482 target_object()->ShortPrint(out);
483 PrintF(out, ")");
Steve Blocka7e24c12009-10-30 11:49:00 +0000484 } else if (rmode_ == EXTERNAL_REFERENCE) {
485 ExternalReferenceEncoder ref_encoder;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100486 PrintF(out, " (%s) (%p)",
Steve Blocka7e24c12009-10-30 11:49:00 +0000487 ref_encoder.NameOfAddress(*target_reference_address()),
488 *target_reference_address());
489 } else if (IsCodeTarget(rmode_)) {
490 Code* code = Code::GetCodeFromTargetAddress(target_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100491 PrintF(out, " (%s) (%p)", Code::Kind2String(code->kind()),
492 target_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000493 } else if (IsPosition(rmode_)) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100494 PrintF(out, " (%" V8_PTR_PREFIX "d)", data());
495 } else if (rmode_ == RelocInfo::RUNTIME_ENTRY) {
496 // Depotimization bailouts are stored as runtime entries.
497 int id = Deoptimizer::GetDeoptimizationId(
498 target_address(), Deoptimizer::EAGER);
499 if (id != Deoptimizer::kNotDeoptimizationEntry) {
500 PrintF(out, " (deoptimization bailout %d)", id);
501 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000502 }
503
Ben Murdochb0fe1622011-05-05 13:52:32 +0100504 PrintF(out, "\n");
Steve Blocka7e24c12009-10-30 11:49:00 +0000505}
506#endif // ENABLE_DISASSEMBLER
507
508
509#ifdef DEBUG
510void RelocInfo::Verify() {
511 switch (rmode_) {
512 case EMBEDDED_OBJECT:
513 Object::VerifyPointer(target_object());
514 break;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100515 case GLOBAL_PROPERTY_CELL:
516 Object::VerifyPointer(target_cell());
517 break;
Andrei Popescu402d9372010-02-26 13:31:12 +0000518 case DEBUG_BREAK:
519#ifndef ENABLE_DEBUGGER_SUPPORT
520 UNREACHABLE();
521 break;
522#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000523 case CONSTRUCT_CALL:
524 case CODE_TARGET_CONTEXT:
525 case CODE_TARGET: {
526 // convert inline target address to code object
527 Address addr = target_address();
528 ASSERT(addr != NULL);
529 // Check that we can find the right code object.
530 Code* code = Code::GetCodeFromTargetAddress(addr);
Steve Block44f0eee2011-05-26 01:26:41 +0100531 Object* found = HEAP->FindCodeObject(addr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000532 ASSERT(found->IsCode());
533 ASSERT(code->address() == HeapObject::cast(found)->address());
534 break;
535 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000536 case RUNTIME_ENTRY:
537 case JS_RETURN:
538 case COMMENT:
539 case POSITION:
540 case STATEMENT_POSITION:
541 case EXTERNAL_REFERENCE:
542 case INTERNAL_REFERENCE:
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100543 case DEBUG_BREAK_SLOT:
Steve Blocka7e24c12009-10-30 11:49:00 +0000544 case NONE:
545 break;
546 case NUMBER_OF_MODES:
547 UNREACHABLE();
548 break;
549 }
550}
551#endif // DEBUG
552
553
554// -----------------------------------------------------------------------------
555// Implementation of ExternalReference
556
Steve Block44f0eee2011-05-26 01:26:41 +0100557ExternalReference::ExternalReference(Builtins::CFunctionId id, Isolate* isolate)
558 : address_(Redirect(isolate, Builtins::c_function_address(id))) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000559
560
Steve Block1e0659c2011-05-24 12:43:12 +0100561ExternalReference::ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100562 ApiFunction* fun,
563 Type type = ExternalReference::BUILTIN_CALL,
564 Isolate* isolate = NULL)
565 : address_(Redirect(isolate, fun->address(), type)) {}
Steve Blockd0582a62009-12-15 09:54:21 +0000566
567
Steve Block44f0eee2011-05-26 01:26:41 +0100568ExternalReference::ExternalReference(Builtins::Name name, Isolate* isolate)
569 : address_(isolate->builtins()->builtin_address(name)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000570
571
Steve Block44f0eee2011-05-26 01:26:41 +0100572ExternalReference::ExternalReference(Runtime::FunctionId id,
573 Isolate* isolate)
574 : address_(Redirect(isolate, Runtime::FunctionForId(id)->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000575
576
Steve Block44f0eee2011-05-26 01:26:41 +0100577ExternalReference::ExternalReference(const Runtime::Function* f,
578 Isolate* isolate)
579 : address_(Redirect(isolate, f->entry)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000580
581
Steve Block44f0eee2011-05-26 01:26:41 +0100582ExternalReference ExternalReference::isolate_address() {
583 return ExternalReference(Isolate::Current());
584}
585
586
587ExternalReference::ExternalReference(const IC_Utility& ic_utility,
588 Isolate* isolate)
589 : address_(Redirect(isolate, ic_utility.address())) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000590
591#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +0100592ExternalReference::ExternalReference(const Debug_Address& debug_address,
593 Isolate* isolate)
594 : address_(debug_address.address(isolate)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000595#endif
596
597ExternalReference::ExternalReference(StatsCounter* counter)
598 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
599
600
Steve Block44f0eee2011-05-26 01:26:41 +0100601ExternalReference::ExternalReference(Isolate::AddressId id, Isolate* isolate)
602 : address_(isolate->get_address_from_id(id)) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000603
604
605ExternalReference::ExternalReference(const SCTableReference& table_ref)
606 : address_(table_ref.address()) {}
607
608
Steve Block44f0eee2011-05-26 01:26:41 +0100609ExternalReference ExternalReference::perform_gc_function(Isolate* isolate) {
610 return ExternalReference(Redirect(isolate,
611 FUNCTION_ADDR(Runtime::PerformGC)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000612}
613
614
Steve Block44f0eee2011-05-26 01:26:41 +0100615ExternalReference ExternalReference::fill_heap_number_with_random_function(
616 Isolate* isolate) {
617 return ExternalReference(Redirect(
618 isolate,
619 FUNCTION_ADDR(V8::FillHeapNumberWithRandom)));
Steve Block6ded16b2010-05-10 14:33:55 +0100620}
621
622
Steve Block44f0eee2011-05-26 01:26:41 +0100623ExternalReference ExternalReference::delete_handle_scope_extensions(
624 Isolate* isolate) {
625 return ExternalReference(Redirect(
626 isolate,
627 FUNCTION_ADDR(HandleScope::DeleteExtensions)));
John Reck59135872010-11-02 12:39:01 -0700628}
629
630
Steve Block44f0eee2011-05-26 01:26:41 +0100631ExternalReference ExternalReference::random_uint32_function(
632 Isolate* isolate) {
633 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(V8::Random)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000634}
635
636
Steve Block44f0eee2011-05-26 01:26:41 +0100637ExternalReference ExternalReference::transcendental_cache_array_address(
638 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100639 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100640 isolate->transcendental_cache()->cache_array_address());
Ben Murdochb0fe1622011-05-05 13:52:32 +0100641}
642
643
Steve Block44f0eee2011-05-26 01:26:41 +0100644ExternalReference ExternalReference::new_deoptimizer_function(
645 Isolate* isolate) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100646 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100647 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::New)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100648}
649
650
Steve Block44f0eee2011-05-26 01:26:41 +0100651ExternalReference ExternalReference::compute_output_frames_function(
652 Isolate* isolate) {
653 return ExternalReference(
654 Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100655}
656
657
Steve Block44f0eee2011-05-26 01:26:41 +0100658ExternalReference ExternalReference::global_contexts_list(Isolate* isolate) {
659 return ExternalReference(isolate->heap()->global_contexts_list_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000660}
661
662
Steve Block44f0eee2011-05-26 01:26:41 +0100663ExternalReference ExternalReference::keyed_lookup_cache_keys(Isolate* isolate) {
664 return ExternalReference(isolate->keyed_lookup_cache()->keys_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000665}
666
667
Steve Block44f0eee2011-05-26 01:26:41 +0100668ExternalReference ExternalReference::keyed_lookup_cache_field_offsets(
669 Isolate* isolate) {
670 return ExternalReference(
671 isolate->keyed_lookup_cache()->field_offsets_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000672}
673
674
Steve Block44f0eee2011-05-26 01:26:41 +0100675ExternalReference ExternalReference::the_hole_value_location(Isolate* isolate) {
676 return ExternalReference(isolate->factory()->the_hole_value().location());
Ben Murdoch086aeea2011-05-13 15:57:08 +0100677}
678
679
Steve Block44f0eee2011-05-26 01:26:41 +0100680ExternalReference ExternalReference::arguments_marker_location(
681 Isolate* isolate) {
682 return ExternalReference(isolate->factory()->arguments_marker().location());
Steve Blocka7e24c12009-10-30 11:49:00 +0000683}
684
685
Steve Block44f0eee2011-05-26 01:26:41 +0100686ExternalReference ExternalReference::roots_address(Isolate* isolate) {
687 return ExternalReference(isolate->heap()->roots_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000688}
689
690
Steve Block44f0eee2011-05-26 01:26:41 +0100691ExternalReference ExternalReference::address_of_stack_limit(Isolate* isolate) {
692 return ExternalReference(isolate->stack_guard()->address_of_jslimit());
Steve Blockd0582a62009-12-15 09:54:21 +0000693}
694
695
Steve Block44f0eee2011-05-26 01:26:41 +0100696ExternalReference ExternalReference::address_of_real_stack_limit(
697 Isolate* isolate) {
698 return ExternalReference(isolate->stack_guard()->address_of_real_jslimit());
Steve Blocka7e24c12009-10-30 11:49:00 +0000699}
700
701
Steve Block44f0eee2011-05-26 01:26:41 +0100702ExternalReference ExternalReference::address_of_regexp_stack_limit(
703 Isolate* isolate) {
704 return ExternalReference(isolate->regexp_stack()->limit_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000705}
706
707
Steve Block44f0eee2011-05-26 01:26:41 +0100708ExternalReference ExternalReference::new_space_start(Isolate* isolate) {
709 return ExternalReference(isolate->heap()->NewSpaceStart());
Andrei Popescu402d9372010-02-26 13:31:12 +0000710}
711
712
Steve Block44f0eee2011-05-26 01:26:41 +0100713ExternalReference ExternalReference::new_space_mask(Isolate* isolate) {
714 Address mask = reinterpret_cast<Address>(isolate->heap()->NewSpaceMask());
715 return ExternalReference(mask);
Steve Blocka7e24c12009-10-30 11:49:00 +0000716}
717
718
Steve Block44f0eee2011-05-26 01:26:41 +0100719ExternalReference ExternalReference::new_space_allocation_top_address(
720 Isolate* isolate) {
721 return ExternalReference(isolate->heap()->NewSpaceAllocationTopAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000722}
723
724
Steve Block44f0eee2011-05-26 01:26:41 +0100725ExternalReference ExternalReference::heap_always_allocate_scope_depth(
726 Isolate* isolate) {
727 Heap* heap = isolate->heap();
728 return ExternalReference(heap->always_allocate_scope_depth_address());
729}
730
731
732ExternalReference ExternalReference::new_space_allocation_limit_address(
733 Isolate* isolate) {
734 return ExternalReference(isolate->heap()->NewSpaceAllocationLimitAddress());
Steve Blocka7e24c12009-10-30 11:49:00 +0000735}
736
Steve Blockd0582a62009-12-15 09:54:21 +0000737
John Reck59135872010-11-02 12:39:01 -0700738ExternalReference ExternalReference::handle_scope_level_address() {
739 return ExternalReference(HandleScope::current_level_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000740}
741
742
743ExternalReference ExternalReference::handle_scope_next_address() {
744 return ExternalReference(HandleScope::current_next_address());
745}
746
747
748ExternalReference ExternalReference::handle_scope_limit_address() {
749 return ExternalReference(HandleScope::current_limit_address());
750}
751
752
Steve Block44f0eee2011-05-26 01:26:41 +0100753ExternalReference ExternalReference::scheduled_exception_address(
754 Isolate* isolate) {
755 return ExternalReference(isolate->scheduled_exception_address());
Steve Blockd0582a62009-12-15 09:54:21 +0000756}
757
758
Ben Murdochb0fe1622011-05-05 13:52:32 +0100759ExternalReference ExternalReference::address_of_min_int() {
760 return ExternalReference(reinterpret_cast<void*>(
761 const_cast<double*>(&DoubleConstant::min_int)));
762}
763
764
765ExternalReference ExternalReference::address_of_one_half() {
766 return ExternalReference(reinterpret_cast<void*>(
767 const_cast<double*>(&DoubleConstant::one_half)));
768}
769
770
Ben Murdochb8e0da22011-05-16 14:20:40 +0100771ExternalReference ExternalReference::address_of_minus_zero() {
772 return ExternalReference(reinterpret_cast<void*>(
773 const_cast<double*>(&DoubleConstant::minus_zero)));
774}
775
776
Ben Murdochb0fe1622011-05-05 13:52:32 +0100777ExternalReference ExternalReference::address_of_negative_infinity() {
778 return ExternalReference(reinterpret_cast<void*>(
779 const_cast<double*>(&DoubleConstant::negative_infinity)));
780}
781
782
Steve Block44f0eee2011-05-26 01:26:41 +0100783ExternalReference ExternalReference::address_of_nan() {
784 return ExternalReference(reinterpret_cast<void*>(
785 const_cast<double*>(&DoubleConstant::nan)));
786}
787
788
Steve Block6ded16b2010-05-10 14:33:55 +0100789#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000790
Steve Block44f0eee2011-05-26 01:26:41 +0100791ExternalReference ExternalReference::re_check_stack_guard_state(
792 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000793 Address function;
794#ifdef V8_TARGET_ARCH_X64
795 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
796#elif V8_TARGET_ARCH_IA32
797 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
798#elif V8_TARGET_ARCH_ARM
799 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
Steve Block44f0eee2011-05-26 01:26:41 +0100800#elif V8_TARGET_ARCH_MIPS
801 function = FUNCTION_ADDR(RegExpMacroAssemblerMIPS::CheckStackGuardState);
Steve Blocka7e24c12009-10-30 11:49:00 +0000802#else
Leon Clarke4515c472010-02-03 11:58:03 +0000803 UNREACHABLE();
Steve Blocka7e24c12009-10-30 11:49:00 +0000804#endif
Steve Block44f0eee2011-05-26 01:26:41 +0100805 return ExternalReference(Redirect(isolate, function));
Steve Blocka7e24c12009-10-30 11:49:00 +0000806}
807
Steve Block44f0eee2011-05-26 01:26:41 +0100808ExternalReference ExternalReference::re_grow_stack(Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000809 return ExternalReference(
Steve Block44f0eee2011-05-26 01:26:41 +0100810 Redirect(isolate, FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
Steve Blocka7e24c12009-10-30 11:49:00 +0000811}
812
Steve Block44f0eee2011-05-26 01:26:41 +0100813ExternalReference ExternalReference::re_case_insensitive_compare_uc16(
814 Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000815 return ExternalReference(Redirect(
Steve Block44f0eee2011-05-26 01:26:41 +0100816 isolate,
Steve Blocka7e24c12009-10-30 11:49:00 +0000817 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
818}
819
Leon Clarkee46be812010-01-19 14:06:41 +0000820ExternalReference ExternalReference::re_word_character_map() {
821 return ExternalReference(
822 NativeRegExpMacroAssembler::word_character_map_address());
823}
824
Steve Block44f0eee2011-05-26 01:26:41 +0100825ExternalReference ExternalReference::address_of_static_offsets_vector(
826 Isolate* isolate) {
827 return ExternalReference(
828 OffsetsVector::static_offsets_vector_address(isolate));
Leon Clarkee46be812010-01-19 14:06:41 +0000829}
830
Steve Block44f0eee2011-05-26 01:26:41 +0100831ExternalReference ExternalReference::address_of_regexp_stack_memory_address(
832 Isolate* isolate) {
833 return ExternalReference(
834 isolate->regexp_stack()->memory_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000835}
836
Steve Block44f0eee2011-05-26 01:26:41 +0100837ExternalReference ExternalReference::address_of_regexp_stack_memory_size(
838 Isolate* isolate) {
839 return ExternalReference(isolate->regexp_stack()->memory_size_address());
Leon Clarkee46be812010-01-19 14:06:41 +0000840}
841
Steve Block6ded16b2010-05-10 14:33:55 +0100842#endif // V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000843
844
845static double add_two_doubles(double x, double y) {
846 return x + y;
847}
848
849
850static double sub_two_doubles(double x, double y) {
851 return x - y;
852}
853
854
855static double mul_two_doubles(double x, double y) {
856 return x * y;
857}
858
859
860static double div_two_doubles(double x, double y) {
861 return x / y;
862}
863
864
865static double mod_two_doubles(double x, double y) {
Leon Clarkee46be812010-01-19 14:06:41 +0000866 return modulo(x, y);
Steve Blocka7e24c12009-10-30 11:49:00 +0000867}
868
869
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100870static double math_sin_double(double x) {
871 return sin(x);
872}
873
874
875static double math_cos_double(double x) {
876 return cos(x);
877}
878
879
880static double math_log_double(double x) {
881 return log(x);
882}
883
884
Steve Block44f0eee2011-05-26 01:26:41 +0100885ExternalReference ExternalReference::math_sin_double_function(
886 Isolate* isolate) {
887 return ExternalReference(Redirect(isolate,
888 FUNCTION_ADDR(math_sin_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100889 FP_RETURN_CALL));
890}
891
892
Steve Block44f0eee2011-05-26 01:26:41 +0100893ExternalReference ExternalReference::math_cos_double_function(
894 Isolate* isolate) {
895 return ExternalReference(Redirect(isolate,
896 FUNCTION_ADDR(math_cos_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100897 FP_RETURN_CALL));
898}
899
900
Steve Block44f0eee2011-05-26 01:26:41 +0100901ExternalReference ExternalReference::math_log_double_function(
902 Isolate* isolate) {
903 return ExternalReference(Redirect(isolate,
904 FUNCTION_ADDR(math_log_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100905 FP_RETURN_CALL));
906}
907
908
Ben Murdochb0fe1622011-05-05 13:52:32 +0100909// Helper function to compute x^y, where y is known to be an
910// integer. Uses binary decomposition to limit the number of
911// multiplications; see the discussion in "Hacker's Delight" by Henry
912// S. Warren, Jr., figure 11-6, page 213.
913double power_double_int(double x, int y) {
914 double m = (y < 0) ? 1 / x : x;
915 unsigned n = (y < 0) ? -y : y;
916 double p = 1;
917 while (n != 0) {
918 if ((n & 1) != 0) p *= m;
919 m *= m;
920 if ((n & 2) != 0) p *= m;
921 m *= m;
922 n >>= 2;
923 }
924 return p;
925}
926
927
928double power_double_double(double x, double y) {
929 int y_int = static_cast<int>(y);
930 if (y == y_int) {
931 return power_double_int(x, y_int); // Returns 1.0 for exponent 0.
932 }
933 if (!isinf(x)) {
Steve Block1e0659c2011-05-24 12:43:12 +0100934 if (y == 0.5) return sqrt(x + 0.0); // -0 must be converted to +0.
935 if (y == -0.5) return 1.0 / sqrt(x + 0.0);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100936 }
937 if (isnan(y) || ((x == 1 || x == -1) && isinf(y))) {
938 return OS::nan_value();
939 }
940 return pow(x, y);
941}
942
943
Steve Block44f0eee2011-05-26 01:26:41 +0100944ExternalReference ExternalReference::power_double_double_function(
945 Isolate* isolate) {
946 return ExternalReference(Redirect(isolate,
947 FUNCTION_ADDR(power_double_double),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100948 FP_RETURN_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100949}
950
951
Steve Block44f0eee2011-05-26 01:26:41 +0100952ExternalReference ExternalReference::power_double_int_function(
953 Isolate* isolate) {
954 return ExternalReference(Redirect(isolate,
955 FUNCTION_ADDR(power_double_int),
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100956 FP_RETURN_CALL));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100957}
958
959
Leon Clarkee46be812010-01-19 14:06:41 +0000960static int native_compare_doubles(double y, double x) {
961 if (x == y) return EQUAL;
962 return x < y ? LESS : GREATER;
Steve Blocka7e24c12009-10-30 11:49:00 +0000963}
964
965
966ExternalReference ExternalReference::double_fp_operation(
Steve Block44f0eee2011-05-26 01:26:41 +0100967 Token::Value operation, Isolate* isolate) {
Steve Blocka7e24c12009-10-30 11:49:00 +0000968 typedef double BinaryFPOperation(double x, double y);
969 BinaryFPOperation* function = NULL;
970 switch (operation) {
971 case Token::ADD:
972 function = &add_two_doubles;
973 break;
974 case Token::SUB:
975 function = &sub_two_doubles;
976 break;
977 case Token::MUL:
978 function = &mul_two_doubles;
979 break;
980 case Token::DIV:
981 function = &div_two_doubles;
982 break;
983 case Token::MOD:
984 function = &mod_two_doubles;
985 break;
986 default:
987 UNREACHABLE();
988 }
989 // Passing true as 2nd parameter indicates that they return an fp value.
Steve Block44f0eee2011-05-26 01:26:41 +0100990 return ExternalReference(Redirect(isolate,
991 FUNCTION_ADDR(function),
992 FP_RETURN_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +0000993}
994
995
Steve Block44f0eee2011-05-26 01:26:41 +0100996ExternalReference ExternalReference::compare_doubles(Isolate* isolate) {
997 return ExternalReference(Redirect(isolate,
998 FUNCTION_ADDR(native_compare_doubles),
Steve Block1e0659c2011-05-24 12:43:12 +0100999 BUILTIN_CALL));
Steve Blocka7e24c12009-10-30 11:49:00 +00001000}
1001
1002
Steve Blocka7e24c12009-10-30 11:49:00 +00001003#ifdef ENABLE_DEBUGGER_SUPPORT
Steve Block44f0eee2011-05-26 01:26:41 +01001004ExternalReference ExternalReference::debug_break(Isolate* isolate) {
1005 return ExternalReference(Redirect(isolate, FUNCTION_ADDR(Debug::Break)));
Steve Blocka7e24c12009-10-30 11:49:00 +00001006}
1007
1008
Steve Block44f0eee2011-05-26 01:26:41 +01001009ExternalReference ExternalReference::debug_step_in_fp_address(
1010 Isolate* isolate) {
1011 return ExternalReference(isolate->debug()->step_in_fp_addr());
Steve Blocka7e24c12009-10-30 11:49:00 +00001012}
1013#endif
1014
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001015
Ben Murdochb0fe1622011-05-05 13:52:32 +01001016void PositionsRecorder::RecordPosition(int pos) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001017 ASSERT(pos != RelocInfo::kNoPosition);
1018 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001019 state_.current_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001020#ifdef ENABLE_GDB_JIT_INTERFACE
1021 if (gdbjit_lineinfo_ != NULL) {
1022 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, false);
1023 }
1024#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001025}
1026
1027
1028void PositionsRecorder::RecordStatementPosition(int pos) {
1029 ASSERT(pos != RelocInfo::kNoPosition);
1030 ASSERT(pos >= 0);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001031 state_.current_statement_position = pos;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001032#ifdef ENABLE_GDB_JIT_INTERFACE
1033 if (gdbjit_lineinfo_ != NULL) {
1034 gdbjit_lineinfo_->SetPosition(assembler_->pc_offset(), pos, true);
1035 }
1036#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001037}
1038
1039
1040bool PositionsRecorder::WriteRecordedPositions() {
1041 bool written = false;
1042
1043 // Write the statement position if it is different from what was written last
1044 // time.
Ben Murdochb0fe1622011-05-05 13:52:32 +01001045 if (state_.current_statement_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001046 EnsureSpace ensure_space(assembler_);
1047 assembler_->RecordRelocInfo(RelocInfo::STATEMENT_POSITION,
Ben Murdochb0fe1622011-05-05 13:52:32 +01001048 state_.current_statement_position);
1049 state_.written_statement_position = state_.current_statement_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001050 written = true;
1051 }
1052
1053 // Write the position if it is different from what was written last time and
Ben Murdochb0fe1622011-05-05 13:52:32 +01001054 // also different from the written statement position.
1055 if (state_.current_position != state_.written_position &&
1056 state_.current_position != state_.written_statement_position) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001057 EnsureSpace ensure_space(assembler_);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001058 assembler_->RecordRelocInfo(RelocInfo::POSITION, state_.current_position);
1059 state_.written_position = state_.current_position;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001060 written = true;
1061 }
1062
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001063 // Return whether something was written.
1064 return written;
1065}
1066
Steve Blocka7e24c12009-10-30 11:49:00 +00001067} } // namespace v8::internal