blob: 9c9ddcdda69e8c5f60e98964a50d9655cf2e0d46 [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"
38#include "execution.h"
39#include "ic-inl.h"
40#include "factory.h"
41#include "runtime.h"
42#include "serialize.h"
43#include "stub-cache.h"
44#include "regexp-stack.h"
45#include "ast.h"
46#include "regexp-macro-assembler.h"
47// Include native regexp-macro-assembler.
48#ifdef V8_NATIVE_REGEXP
49#if V8_TARGET_ARCH_IA32
50#include "ia32/regexp-macro-assembler-ia32.h"
51#elif V8_TARGET_ARCH_X64
52#include "x64/regexp-macro-assembler-x64.h"
53#elif V8_TARGET_ARCH_ARM
54#include "arm/regexp-macro-assembler-arm.h"
55#else // Unknown architecture.
56#error "Unknown architecture."
57#endif // Target architecture.
58#endif // V8_NATIVE_REGEXP
59
60namespace v8 {
61namespace internal {
62
63
64// -----------------------------------------------------------------------------
65// Implementation of Label
66
67int Label::pos() const {
68 if (pos_ < 0) return -pos_ - 1;
69 if (pos_ > 0) return pos_ - 1;
70 UNREACHABLE();
71 return 0;
72}
73
74
75// -----------------------------------------------------------------------------
76// Implementation of RelocInfoWriter and RelocIterator
77//
78// Encoding
79//
80// The most common modes are given single-byte encodings. Also, it is
81// easy to identify the type of reloc info and skip unwanted modes in
82// an iteration.
83//
84// The encoding relies on the fact that there are less than 14
85// different relocation modes.
86//
87// embedded_object: [6 bits pc delta] 00
88//
89// code_taget: [6 bits pc delta] 01
90//
91// position: [6 bits pc delta] 10,
92// [7 bits signed data delta] 0
93//
94// statement_position: [6 bits pc delta] 10,
95// [7 bits signed data delta] 1
96//
97// any nondata mode: 00 [4 bits rmode] 11, // rmode: 0..13 only
98// 00 [6 bits pc delta]
99//
100// pc-jump: 00 1111 11,
101// 00 [6 bits pc delta]
102//
103// pc-jump: 01 1111 11,
104// (variable length) 7 - 26 bit pc delta, written in chunks of 7
105// bits, the lowest 7 bits written first.
106//
107// data-jump + pos: 00 1110 11,
108// signed intptr_t, lowest byte written first
109//
110// data-jump + st.pos: 01 1110 11,
111// signed intptr_t, lowest byte written first
112//
113// data-jump + comm.: 10 1110 11,
114// signed intptr_t, lowest byte written first
115//
116const int kMaxRelocModes = 14;
117
118const int kTagBits = 2;
119const int kTagMask = (1 << kTagBits) - 1;
120const int kExtraTagBits = 4;
121const int kPositionTypeTagBits = 1;
122const int kSmallDataBits = kBitsPerByte - kPositionTypeTagBits;
123
124const int kEmbeddedObjectTag = 0;
125const int kCodeTargetTag = 1;
126const int kPositionTag = 2;
127const int kDefaultTag = 3;
128
129const int kPCJumpTag = (1 << kExtraTagBits) - 1;
130
131const int kSmallPCDeltaBits = kBitsPerByte - kTagBits;
132const int kSmallPCDeltaMask = (1 << kSmallPCDeltaBits) - 1;
133
134const int kVariableLengthPCJumpTopTag = 1;
135const int kChunkBits = 7;
136const int kChunkMask = (1 << kChunkBits) - 1;
137const int kLastChunkTagBits = 1;
138const int kLastChunkTagMask = 1;
139const int kLastChunkTag = 1;
140
141
142const int kDataJumpTag = kPCJumpTag - 1;
143
144const int kNonstatementPositionTag = 0;
145const int kStatementPositionTag = 1;
146const int kCommentTag = 2;
147
148
149uint32_t RelocInfoWriter::WriteVariableLengthPCJump(uint32_t pc_delta) {
150 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
151 // Otherwise write a variable length PC jump for the bits that do
152 // not fit in the kSmallPCDeltaBits bits.
153 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
154 WriteExtraTag(kPCJumpTag, kVariableLengthPCJumpTopTag);
155 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
156 ASSERT(pc_jump > 0);
157 // Write kChunkBits size chunks of the pc_jump.
158 for (; pc_jump > 0; pc_jump = pc_jump >> kChunkBits) {
159 byte b = pc_jump & kChunkMask;
160 *--pos_ = b << kLastChunkTagBits;
161 }
162 // Tag the last chunk so it can be identified.
163 *pos_ = *pos_ | kLastChunkTag;
164 // Return the remaining kSmallPCDeltaBits of the pc_delta.
165 return pc_delta & kSmallPCDeltaMask;
166}
167
168
169void RelocInfoWriter::WriteTaggedPC(uint32_t pc_delta, int tag) {
170 // Write a byte of tagged pc-delta, possibly preceded by var. length pc-jump.
171 pc_delta = WriteVariableLengthPCJump(pc_delta);
172 *--pos_ = pc_delta << kTagBits | tag;
173}
174
175
176void RelocInfoWriter::WriteTaggedData(intptr_t data_delta, int tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000177 *--pos_ = static_cast<byte>(data_delta << kPositionTypeTagBits | tag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000178}
179
180
181void RelocInfoWriter::WriteExtraTag(int extra_tag, int top_tag) {
Steve Blockd0582a62009-12-15 09:54:21 +0000182 *--pos_ = static_cast<int>(top_tag << (kTagBits + kExtraTagBits) |
183 extra_tag << kTagBits |
184 kDefaultTag);
Steve Blocka7e24c12009-10-30 11:49:00 +0000185}
186
187
188void RelocInfoWriter::WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag) {
189 // Write two-byte tagged pc-delta, possibly preceded by var. length pc-jump.
190 pc_delta = WriteVariableLengthPCJump(pc_delta);
191 WriteExtraTag(extra_tag, 0);
192 *--pos_ = pc_delta;
193}
194
195
196void RelocInfoWriter::WriteExtraTaggedData(intptr_t data_delta, int top_tag) {
197 WriteExtraTag(kDataJumpTag, top_tag);
198 for (int i = 0; i < kIntptrSize; i++) {
Steve Blockd0582a62009-12-15 09:54:21 +0000199 *--pos_ = static_cast<byte>(data_delta);
Steve Blocka7e24c12009-10-30 11:49:00 +0000200 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
201 data_delta = data_delta >> kBitsPerByte;
202 }
203}
204
205
206void RelocInfoWriter::Write(const RelocInfo* rinfo) {
207#ifdef DEBUG
208 byte* begin_pos = pos_;
209#endif
210 Counters::reloc_info_count.Increment();
211 ASSERT(rinfo->pc() - last_pc_ >= 0);
212 ASSERT(RelocInfo::NUMBER_OF_MODES < kMaxRelocModes);
213 // Use unsigned delta-encoding for pc.
Steve Blockd0582a62009-12-15 09:54:21 +0000214 uint32_t pc_delta = static_cast<uint32_t>(rinfo->pc() - last_pc_);
Steve Blocka7e24c12009-10-30 11:49:00 +0000215 RelocInfo::Mode rmode = rinfo->rmode();
216
217 // The two most common modes are given small tags, and usually fit in a byte.
218 if (rmode == RelocInfo::EMBEDDED_OBJECT) {
219 WriteTaggedPC(pc_delta, kEmbeddedObjectTag);
220 } else if (rmode == RelocInfo::CODE_TARGET) {
221 WriteTaggedPC(pc_delta, kCodeTargetTag);
222 } else if (RelocInfo::IsPosition(rmode)) {
223 // Use signed delta-encoding for data.
224 intptr_t data_delta = rinfo->data() - last_data_;
225 int pos_type_tag = rmode == RelocInfo::POSITION ? kNonstatementPositionTag
226 : kStatementPositionTag;
227 // Check if data is small enough to fit in a tagged byte.
228 // We cannot use is_intn because data_delta is not an int32_t.
229 if (data_delta >= -(1 << (kSmallDataBits-1)) &&
230 data_delta < 1 << (kSmallDataBits-1)) {
231 WriteTaggedPC(pc_delta, kPositionTag);
232 WriteTaggedData(data_delta, pos_type_tag);
233 last_data_ = rinfo->data();
234 } else {
235 // Otherwise, use costly encoding.
236 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
237 WriteExtraTaggedData(data_delta, pos_type_tag);
238 last_data_ = rinfo->data();
239 }
240 } else if (RelocInfo::IsComment(rmode)) {
241 // Comments are normally not generated, so we use the costly encoding.
242 WriteExtraTaggedPC(pc_delta, kPCJumpTag);
243 WriteExtraTaggedData(rinfo->data() - last_data_, kCommentTag);
244 last_data_ = rinfo->data();
245 } else {
246 // For all other modes we simply use the mode as the extra tag.
247 // None of these modes need a data component.
248 ASSERT(rmode < kPCJumpTag && rmode < kDataJumpTag);
249 WriteExtraTaggedPC(pc_delta, rmode);
250 }
251 last_pc_ = rinfo->pc();
252#ifdef DEBUG
253 ASSERT(begin_pos - pos_ <= kMaxSize);
254#endif
255}
256
257
258inline int RelocIterator::AdvanceGetTag() {
259 return *--pos_ & kTagMask;
260}
261
262
263inline int RelocIterator::GetExtraTag() {
264 return (*pos_ >> kTagBits) & ((1 << kExtraTagBits) - 1);
265}
266
267
268inline int RelocIterator::GetTopTag() {
269 return *pos_ >> (kTagBits + kExtraTagBits);
270}
271
272
273inline void RelocIterator::ReadTaggedPC() {
274 rinfo_.pc_ += *pos_ >> kTagBits;
275}
276
277
278inline void RelocIterator::AdvanceReadPC() {
279 rinfo_.pc_ += *--pos_;
280}
281
282
283void RelocIterator::AdvanceReadData() {
284 intptr_t x = 0;
285 for (int i = 0; i < kIntptrSize; i++) {
286 x |= static_cast<intptr_t>(*--pos_) << i * kBitsPerByte;
287 }
288 rinfo_.data_ += x;
289}
290
291
292void RelocIterator::AdvanceReadVariableLengthPCJump() {
293 // Read the 32-kSmallPCDeltaBits most significant bits of the
294 // pc jump in kChunkBits bit chunks and shift them into place.
295 // Stop when the last chunk is encountered.
296 uint32_t pc_jump = 0;
297 for (int i = 0; i < kIntSize; i++) {
298 byte pc_jump_part = *--pos_;
299 pc_jump |= (pc_jump_part >> kLastChunkTagBits) << i * kChunkBits;
300 if ((pc_jump_part & kLastChunkTagMask) == 1) break;
301 }
302 // The least significant kSmallPCDeltaBits bits will be added
303 // later.
304 rinfo_.pc_ += pc_jump << kSmallPCDeltaBits;
305}
306
307
308inline int RelocIterator::GetPositionTypeTag() {
309 return *pos_ & ((1 << kPositionTypeTagBits) - 1);
310}
311
312
313inline void RelocIterator::ReadTaggedData() {
314 int8_t signed_b = *pos_;
315 // Signed right shift is arithmetic shift. Tested in test-utils.cc.
316 rinfo_.data_ += signed_b >> kPositionTypeTagBits;
317}
318
319
320inline RelocInfo::Mode RelocIterator::DebugInfoModeFromTag(int tag) {
321 if (tag == kStatementPositionTag) {
322 return RelocInfo::STATEMENT_POSITION;
323 } else if (tag == kNonstatementPositionTag) {
324 return RelocInfo::POSITION;
325 } else {
326 ASSERT(tag == kCommentTag);
327 return RelocInfo::COMMENT;
328 }
329}
330
331
332void RelocIterator::next() {
333 ASSERT(!done());
334 // Basically, do the opposite of RelocInfoWriter::Write.
335 // Reading of data is as far as possible avoided for unwanted modes,
336 // but we must always update the pc.
337 //
338 // We exit this loop by returning when we find a mode we want.
339 while (pos_ > end_) {
340 int tag = AdvanceGetTag();
341 if (tag == kEmbeddedObjectTag) {
342 ReadTaggedPC();
343 if (SetMode(RelocInfo::EMBEDDED_OBJECT)) return;
344 } else if (tag == kCodeTargetTag) {
345 ReadTaggedPC();
Steve Blocka7e24c12009-10-30 11:49:00 +0000346 if (SetMode(RelocInfo::CODE_TARGET)) return;
347 } else if (tag == kPositionTag) {
348 ReadTaggedPC();
349 Advance();
350 // Check if we want source positions.
351 if (mode_mask_ & RelocInfo::kPositionMask) {
352 // Check if we want this type of source position.
353 if (SetMode(DebugInfoModeFromTag(GetPositionTypeTag()))) {
354 // Finally read the data before returning.
355 ReadTaggedData();
356 return;
357 }
358 }
359 } else {
360 ASSERT(tag == kDefaultTag);
361 int extra_tag = GetExtraTag();
362 if (extra_tag == kPCJumpTag) {
363 int top_tag = GetTopTag();
364 if (top_tag == kVariableLengthPCJumpTopTag) {
365 AdvanceReadVariableLengthPCJump();
366 } else {
367 AdvanceReadPC();
368 }
369 } else if (extra_tag == kDataJumpTag) {
370 // Check if we want debug modes (the only ones with data).
371 if (mode_mask_ & RelocInfo::kDebugMask) {
372 int top_tag = GetTopTag();
373 AdvanceReadData();
374 if (SetMode(DebugInfoModeFromTag(top_tag))) return;
375 } else {
376 // Otherwise, just skip over the data.
377 Advance(kIntptrSize);
378 }
379 } else {
380 AdvanceReadPC();
381 if (SetMode(static_cast<RelocInfo::Mode>(extra_tag))) return;
382 }
383 }
384 }
385 done_ = true;
386}
387
388
389RelocIterator::RelocIterator(Code* code, int mode_mask) {
390 rinfo_.pc_ = code->instruction_start();
391 rinfo_.data_ = 0;
392 // relocation info is read backwards
393 pos_ = code->relocation_start() + code->relocation_size();
394 end_ = code->relocation_start();
395 done_ = false;
396 mode_mask_ = mode_mask;
397 if (mode_mask_ == 0) pos_ = end_;
398 next();
399}
400
401
402RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
403 rinfo_.pc_ = desc.buffer;
404 rinfo_.data_ = 0;
405 // relocation info is read backwards
406 pos_ = desc.buffer + desc.buffer_size;
407 end_ = pos_ - desc.reloc_size;
408 done_ = false;
409 mode_mask_ = mode_mask;
410 if (mode_mask_ == 0) pos_ = end_;
411 next();
412}
413
414
415// -----------------------------------------------------------------------------
416// Implementation of RelocInfo
417
418
419#ifdef ENABLE_DISASSEMBLER
420const char* RelocInfo::RelocModeName(RelocInfo::Mode rmode) {
421 switch (rmode) {
422 case RelocInfo::NONE:
423 return "no reloc";
424 case RelocInfo::EMBEDDED_OBJECT:
425 return "embedded object";
426 case RelocInfo::EMBEDDED_STRING:
427 return "embedded string";
428 case RelocInfo::CONSTRUCT_CALL:
429 return "code target (js construct call)";
430 case RelocInfo::CODE_TARGET_CONTEXT:
431 return "code target (context)";
432 case RelocInfo::CODE_TARGET:
433 return "code target";
434 case RelocInfo::RUNTIME_ENTRY:
435 return "runtime entry";
436 case RelocInfo::JS_RETURN:
437 return "js return";
438 case RelocInfo::COMMENT:
439 return "comment";
440 case RelocInfo::POSITION:
441 return "position";
442 case RelocInfo::STATEMENT_POSITION:
443 return "statement position";
444 case RelocInfo::EXTERNAL_REFERENCE:
445 return "external reference";
446 case RelocInfo::INTERNAL_REFERENCE:
447 return "internal reference";
448 case RelocInfo::NUMBER_OF_MODES:
449 UNREACHABLE();
450 return "number_of_modes";
451 }
452 return "unknown relocation type";
453}
454
455
456void RelocInfo::Print() {
457 PrintF("%p %s", pc_, RelocModeName(rmode_));
458 if (IsComment(rmode_)) {
459 PrintF(" (%s)", data_);
460 } else if (rmode_ == EMBEDDED_OBJECT) {
461 PrintF(" (");
462 target_object()->ShortPrint();
463 PrintF(")");
464 } else if (rmode_ == EXTERNAL_REFERENCE) {
465 ExternalReferenceEncoder ref_encoder;
466 PrintF(" (%s) (%p)",
467 ref_encoder.NameOfAddress(*target_reference_address()),
468 *target_reference_address());
469 } else if (IsCodeTarget(rmode_)) {
470 Code* code = Code::GetCodeFromTargetAddress(target_address());
471 PrintF(" (%s) (%p)", Code::Kind2String(code->kind()), target_address());
472 } else if (IsPosition(rmode_)) {
473 PrintF(" (%d)", data());
474 }
475
476 PrintF("\n");
477}
478#endif // ENABLE_DISASSEMBLER
479
480
481#ifdef DEBUG
482void RelocInfo::Verify() {
483 switch (rmode_) {
484 case EMBEDDED_OBJECT:
485 Object::VerifyPointer(target_object());
486 break;
487 case CONSTRUCT_CALL:
488 case CODE_TARGET_CONTEXT:
489 case CODE_TARGET: {
490 // convert inline target address to code object
491 Address addr = target_address();
492 ASSERT(addr != NULL);
493 // Check that we can find the right code object.
494 Code* code = Code::GetCodeFromTargetAddress(addr);
495 Object* found = Heap::FindCodeObject(addr);
496 ASSERT(found->IsCode());
497 ASSERT(code->address() == HeapObject::cast(found)->address());
498 break;
499 }
500 case RelocInfo::EMBEDDED_STRING:
501 case RUNTIME_ENTRY:
502 case JS_RETURN:
503 case COMMENT:
504 case POSITION:
505 case STATEMENT_POSITION:
506 case EXTERNAL_REFERENCE:
507 case INTERNAL_REFERENCE:
508 case NONE:
509 break;
510 case NUMBER_OF_MODES:
511 UNREACHABLE();
512 break;
513 }
514}
515#endif // DEBUG
516
517
518// -----------------------------------------------------------------------------
519// Implementation of ExternalReference
520
521ExternalReference::ExternalReference(Builtins::CFunctionId id)
522 : address_(Redirect(Builtins::c_function_address(id))) {}
523
524
Steve Blockd0582a62009-12-15 09:54:21 +0000525ExternalReference::ExternalReference(ApiFunction* fun)
526 : address_(Redirect(fun->address())) {}
527
528
Steve Blocka7e24c12009-10-30 11:49:00 +0000529ExternalReference::ExternalReference(Builtins::Name name)
530 : address_(Builtins::builtin_address(name)) {}
531
532
533ExternalReference::ExternalReference(Runtime::FunctionId id)
534 : address_(Redirect(Runtime::FunctionForId(id)->entry)) {}
535
536
537ExternalReference::ExternalReference(Runtime::Function* f)
538 : address_(Redirect(f->entry)) {}
539
540
541ExternalReference::ExternalReference(const IC_Utility& ic_utility)
542 : address_(Redirect(ic_utility.address())) {}
543
544#ifdef ENABLE_DEBUGGER_SUPPORT
545ExternalReference::ExternalReference(const Debug_Address& debug_address)
546 : address_(debug_address.address()) {}
547#endif
548
549ExternalReference::ExternalReference(StatsCounter* counter)
550 : address_(reinterpret_cast<Address>(counter->GetInternalPointer())) {}
551
552
553ExternalReference::ExternalReference(Top::AddressId id)
554 : address_(Top::get_address_from_id(id)) {}
555
556
557ExternalReference::ExternalReference(const SCTableReference& table_ref)
558 : address_(table_ref.address()) {}
559
560
561ExternalReference ExternalReference::perform_gc_function() {
562 return ExternalReference(Redirect(FUNCTION_ADDR(Runtime::PerformGC)));
563}
564
565
566ExternalReference ExternalReference::builtin_passed_function() {
567 return ExternalReference(&Builtins::builtin_passed_function);
568}
569
570
571ExternalReference ExternalReference::random_positive_smi_function() {
572 return ExternalReference(Redirect(FUNCTION_ADDR(V8::RandomPositiveSmi)));
573}
574
575
576ExternalReference ExternalReference::the_hole_value_location() {
577 return ExternalReference(Factory::the_hole_value().location());
578}
579
580
581ExternalReference ExternalReference::roots_address() {
582 return ExternalReference(Heap::roots_address());
583}
584
585
Steve Blockd0582a62009-12-15 09:54:21 +0000586ExternalReference ExternalReference::address_of_stack_limit() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000587 return ExternalReference(StackGuard::address_of_jslimit());
588}
589
590
Steve Blockd0582a62009-12-15 09:54:21 +0000591ExternalReference ExternalReference::address_of_real_stack_limit() {
592 return ExternalReference(StackGuard::address_of_real_jslimit());
593}
594
595
Steve Blocka7e24c12009-10-30 11:49:00 +0000596ExternalReference ExternalReference::address_of_regexp_stack_limit() {
597 return ExternalReference(RegExpStack::limit_address());
598}
599
600
601ExternalReference ExternalReference::new_space_start() {
602 return ExternalReference(Heap::NewSpaceStart());
603}
604
605
606ExternalReference ExternalReference::new_space_allocation_top_address() {
607 return ExternalReference(Heap::NewSpaceAllocationTopAddress());
608}
609
610
611ExternalReference ExternalReference::heap_always_allocate_scope_depth() {
612 return ExternalReference(Heap::always_allocate_scope_depth_address());
613}
614
615
616ExternalReference ExternalReference::new_space_allocation_limit_address() {
617 return ExternalReference(Heap::NewSpaceAllocationLimitAddress());
618}
619
Steve Blockd0582a62009-12-15 09:54:21 +0000620
621ExternalReference ExternalReference::handle_scope_extensions_address() {
622 return ExternalReference(HandleScope::current_extensions_address());
623}
624
625
626ExternalReference ExternalReference::handle_scope_next_address() {
627 return ExternalReference(HandleScope::current_next_address());
628}
629
630
631ExternalReference ExternalReference::handle_scope_limit_address() {
632 return ExternalReference(HandleScope::current_limit_address());
633}
634
635
636ExternalReference ExternalReference::scheduled_exception_address() {
637 return ExternalReference(Top::scheduled_exception_address());
638}
639
640
Steve Blocka7e24c12009-10-30 11:49:00 +0000641#ifdef V8_NATIVE_REGEXP
642
643ExternalReference ExternalReference::re_check_stack_guard_state() {
644 Address function;
645#ifdef V8_TARGET_ARCH_X64
646 function = FUNCTION_ADDR(RegExpMacroAssemblerX64::CheckStackGuardState);
647#elif V8_TARGET_ARCH_IA32
648 function = FUNCTION_ADDR(RegExpMacroAssemblerIA32::CheckStackGuardState);
649#elif V8_TARGET_ARCH_ARM
650 function = FUNCTION_ADDR(RegExpMacroAssemblerARM::CheckStackGuardState);
651#else
652 UNREACHABLE("Unexpected architecture");
653#endif
654 return ExternalReference(Redirect(function));
655}
656
657ExternalReference ExternalReference::re_grow_stack() {
658 return ExternalReference(
659 Redirect(FUNCTION_ADDR(NativeRegExpMacroAssembler::GrowStack)));
660}
661
662ExternalReference ExternalReference::re_case_insensitive_compare_uc16() {
663 return ExternalReference(Redirect(
664 FUNCTION_ADDR(NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16)));
665}
666
667#endif
668
669
670static double add_two_doubles(double x, double y) {
671 return x + y;
672}
673
674
675static double sub_two_doubles(double x, double y) {
676 return x - y;
677}
678
679
680static double mul_two_doubles(double x, double y) {
681 return x * y;
682}
683
684
685static double div_two_doubles(double x, double y) {
686 return x / y;
687}
688
689
690static double mod_two_doubles(double x, double y) {
691 return fmod(x, y);
692}
693
694
695static int native_compare_doubles(double x, double y) {
696 if (x == y) return 0;
697 return x < y ? 1 : -1;
698}
699
700
701ExternalReference ExternalReference::double_fp_operation(
702 Token::Value operation) {
703 typedef double BinaryFPOperation(double x, double y);
704 BinaryFPOperation* function = NULL;
705 switch (operation) {
706 case Token::ADD:
707 function = &add_two_doubles;
708 break;
709 case Token::SUB:
710 function = &sub_two_doubles;
711 break;
712 case Token::MUL:
713 function = &mul_two_doubles;
714 break;
715 case Token::DIV:
716 function = &div_two_doubles;
717 break;
718 case Token::MOD:
719 function = &mod_two_doubles;
720 break;
721 default:
722 UNREACHABLE();
723 }
724 // Passing true as 2nd parameter indicates that they return an fp value.
725 return ExternalReference(Redirect(FUNCTION_ADDR(function), true));
726}
727
728
729ExternalReference ExternalReference::compare_doubles() {
730 return ExternalReference(Redirect(FUNCTION_ADDR(native_compare_doubles),
731 false));
732}
733
734
735ExternalReferenceRedirector* ExternalReference::redirector_ = NULL;
736
737
738#ifdef ENABLE_DEBUGGER_SUPPORT
739ExternalReference ExternalReference::debug_break() {
740 return ExternalReference(Redirect(FUNCTION_ADDR(Debug::Break)));
741}
742
743
744ExternalReference ExternalReference::debug_step_in_fp_address() {
745 return ExternalReference(Debug::step_in_fp_addr());
746}
747#endif
748
749} } // namespace v8::internal