1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
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.
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.
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.
31 // The original source code covered by the above license above has been
32 // modified significantly by Google Inc.
33 // Copyright 2012 the V8 project authors. All rights reserved.
35 #ifndef V8_ASSEMBLER_H_
36 #define V8_ASSEMBLER_H_
40 #include "allocation.h"
54 const unsigned kNoASTId = -1;
55 // -----------------------------------------------------------------------------
56 // Platform independent assembler base class.
58 class AssemblerBase: public Malloced {
60 explicit AssemblerBase(Isolate* isolate);
62 Isolate* isolate() const { return isolate_; }
63 int jit_cookie() { return jit_cookie_; }
65 // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
66 // cross-snapshotting.
67 static void QuietNaN(HeapObject* nan) { }
75 // -----------------------------------------------------------------------------
76 // Labels represent pc locations; they are typically jump or call targets.
77 // After declaration, a label can be freely used to denote known or (yet)
78 // unknown pc location. Assembler::bind() is used to bind a label to the
79 // current pc. A label can be bound only once.
81 class Label BASE_EMBEDDED {
94 ASSERT(!is_near_linked());
97 INLINE(void Unuse()) { pos_ = 0; }
98 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
100 INLINE(bool is_bound() const) { return pos_ < 0; }
101 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
102 INLINE(bool is_linked() const) { return pos_ > 0; }
103 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
105 // Returns the position of bound or linked labels. Cannot be used
106 // for unused labels.
108 int near_link_pos() const { return near_link_pos_ - 1; }
111 // pos_ encodes both the binding state (via its sign)
112 // and the binding position (via its value) of a label.
114 // pos_ < 0 bound label, pos() returns the jump target position
115 // pos_ == 0 unused label
116 // pos_ > 0 linked label, pos() returns the last reference position
119 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
122 void bind_to(int pos) {
126 void link_to(int pos, Distance distance = kFar) {
127 if (distance == kNear) {
128 near_link_pos_ = pos + 1;
129 ASSERT(is_near_linked());
136 friend class Assembler;
137 friend class RegexpAssembler;
138 friend class Displacement;
139 friend class RegExpMacroAssemblerIrregexp;
143 enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
146 // -----------------------------------------------------------------------------
147 // Relocation information
150 // Relocation information consists of the address (pc) of the datum
151 // to which the relocation information applies, the relocation mode
152 // (rmode), and an optional data field. The relocation mode may be
153 // "descriptive" and not indicate a need for relocation, but simply
154 // describe a property of the datum. Such rmodes are useful for GC
155 // and nice disassembly output.
157 class RelocInfo BASE_EMBEDDED {
159 // The constant kNoPosition is used with the collecting of source positions
160 // in the relocation information. Two types of source positions are collected
161 // "position" (RelocMode position) and "statement position" (RelocMode
162 // statement_position). The "position" is collected at places in the source
163 // code which are of interest when making stack traces to pin-point the source
164 // location of a stack frame as close as possible. The "statement position" is
165 // collected at the beginning at each statement, and is used to indicate
166 // possible break locations. kNoPosition is used to indicate an
167 // invalid/uninitialized position value.
168 static const int kNoPosition = -1;
170 // This string is used to add padding comments to the reloc info in cases
171 // where we are not sure to have enough space for patching in during
172 // lazy deoptimization. This is the case if we have indirect calls for which
173 // we do not normally record relocation info.
174 static const char* const kFillerCommentString;
176 // The minimum size of a comment is equal to three bytes for the extra tagged
177 // pc + the tag for the data, and kPointerSize for the actual pointer to the
179 static const int kMinRelocCommentSize = 3 + kPointerSize;
181 // The maximum size for a call instruction including pc-jump.
182 static const int kMaxCallSize = 6;
184 // The maximum pc delta that will use the short encoding.
185 static const int kMaxSmallPCDelta;
188 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
189 CODE_TARGET, // Code target which is not any of the above.
191 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
192 CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores.
193 DEBUG_BREAK, // Code target for the debugger statement.
195 GLOBAL_PROPERTY_CELL,
197 // Everything after runtime_entry (inclusive) is not GC'ed.
199 JS_RETURN, // Marks start of the ExitJSFrame code.
201 POSITION, // See comment for kNoPosition above.
202 STATEMENT_POSITION, // See comment for kNoPosition above.
203 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
204 EXTERNAL_REFERENCE, // The address of an external C++ function.
205 INTERNAL_REFERENCE, // An address inside the same function.
207 // add more as needed
209 NUMBER_OF_MODES, // There are at most 14 modes with noncompact encoding.
210 NONE, // never recorded
211 LAST_CODE_ENUM = DEBUG_BREAK,
212 LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL,
213 // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding.
214 LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID
220 RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host)
221 : pc_(pc), rmode_(rmode), data_(data), host_(host) {
224 static inline bool IsConstructCall(Mode mode) {
225 return mode == CONSTRUCT_CALL;
227 static inline bool IsCodeTarget(Mode mode) {
228 return mode <= LAST_CODE_ENUM;
230 static inline bool IsEmbeddedObject(Mode mode) {
231 return mode == EMBEDDED_OBJECT;
233 // Is the relocation mode affected by GC?
234 static inline bool IsGCRelocMode(Mode mode) {
235 return mode <= LAST_GCED_ENUM;
237 static inline bool IsJSReturn(Mode mode) {
238 return mode == JS_RETURN;
240 static inline bool IsComment(Mode mode) {
241 return mode == COMMENT;
243 static inline bool IsPosition(Mode mode) {
244 return mode == POSITION || mode == STATEMENT_POSITION;
246 static inline bool IsStatementPosition(Mode mode) {
247 return mode == STATEMENT_POSITION;
249 static inline bool IsExternalReference(Mode mode) {
250 return mode == EXTERNAL_REFERENCE;
252 static inline bool IsInternalReference(Mode mode) {
253 return mode == INTERNAL_REFERENCE;
255 static inline bool IsDebugBreakSlot(Mode mode) {
256 return mode == DEBUG_BREAK_SLOT;
258 static inline int ModeMask(Mode mode) { return 1 << mode; }
261 byte* pc() const { return pc_; }
262 void set_pc(byte* pc) { pc_ = pc; }
263 Mode rmode() const { return rmode_; }
264 intptr_t data() const { return data_; }
265 Code* host() const { return host_; }
267 // Apply a relocation by delta bytes
268 INLINE(void apply(intptr_t delta));
270 // Is the pointer this relocation info refers to coded like a plain pointer
271 // or is it strange in some way (e.g. relative or patched into a series of
273 bool IsCodedSpecially();
275 // Read/modify the code target in the branch/call instruction
276 // this relocation applies to;
277 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
278 INLINE(Address target_address());
279 INLINE(void set_target_address(Address target,
280 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
281 INLINE(Object* target_object());
282 INLINE(Handle<Object> target_object_handle(Assembler* origin));
283 INLINE(Object** target_object_address());
284 INLINE(void set_target_object(Object* target,
285 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
286 INLINE(JSGlobalPropertyCell* target_cell());
287 INLINE(Handle<JSGlobalPropertyCell> target_cell_handle());
288 INLINE(void set_target_cell(JSGlobalPropertyCell* cell,
289 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
292 // Read the address of the word containing the target_address in an
293 // instruction stream. What this means exactly is architecture-independent.
294 // The only architecture-independent user of this function is the serializer.
295 // The serializer uses it to find out how many raw bytes of instruction to
296 // output before the next target. Architecture-independent code shouldn't
297 // dereference the pointer it gets back from this.
298 INLINE(Address target_address_address());
299 // This indicates how much space a target takes up when deserializing a code
300 // stream. For most architectures this is just the size of a pointer. For
301 // an instruction like movw/movt where the target bits are mixed into the
302 // instruction bits the size of the target will be zero, indicating that the
303 // serializer should not step forwards in memory after a target is resolved
304 // and written. In this case the target_address_address function above
305 // should return the end of the instructions to be patched, allowing the
306 // deserializer to deserialize the instructions as raw bytes and put them in
307 // place, ready to be patched with the target.
308 INLINE(int target_address_size());
310 // Read/modify the reference in the instruction this relocation
311 // applies to; can only be called if rmode_ is external_reference
312 INLINE(Address* target_reference_address());
314 // Read/modify the address of a call instruction. This is used to relocate
315 // the break points where straight-line code is patched with a call
317 INLINE(Address call_address());
318 INLINE(void set_call_address(Address target));
319 INLINE(Object* call_object());
320 INLINE(void set_call_object(Object* target));
321 INLINE(Object** call_object_address());
323 template<typename StaticVisitor> inline void Visit(Heap* heap);
324 inline void Visit(ObjectVisitor* v);
326 // Patch the code with some other code.
327 void PatchCode(byte* instructions, int instruction_count);
329 // Patch the code with a call.
330 void PatchCodeWithCall(Address target, int guard_bytes);
332 // Check whether this return sequence has been patched
333 // with a call to the debugger.
334 INLINE(bool IsPatchedReturnSequence());
336 // Check whether this debug break slot has been patched with a call to the
338 INLINE(bool IsPatchedDebugBreakSlotSequence());
340 #ifdef ENABLE_DISASSEMBLER
342 static const char* RelocModeName(Mode rmode);
343 void Print(FILE* out);
344 #endif // ENABLE_DISASSEMBLER
350 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
351 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
352 static const int kDataMask =
353 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
354 static const int kApplyMask; // Modes affected by apply. Depends on arch.
357 // On ARM, note that pc_ is the address of the constant pool entry
358 // to be relocated and not the address of the instruction
359 // referencing the constant pool entry (except when rmode_ ==
365 #ifdef V8_TARGET_ARCH_MIPS
366 // Code and Embedded Object pointers in mips are stored split
367 // across two consecutive 32-bit instructions. Heap management
368 // routines expect to access these pointers indirectly. The following
369 // location provides a place for these pointers to exist natually
370 // when accessed via the Iterator.
371 Object* reconstructed_obj_ptr_;
372 // External-reference pointers are also split across instruction-pairs
373 // in mips, but are accessed via indirect pointers. This location
374 // provides a place for that pointer to exist naturally. Its address
375 // is returned by RelocInfo::target_reference_address().
376 Address reconstructed_adr_ptr_;
377 #endif // V8_TARGET_ARCH_MIPS
378 friend class RelocIterator;
382 // RelocInfoWriter serializes a stream of relocation info. It writes towards
384 class RelocInfoWriter BASE_EMBEDDED {
386 RelocInfoWriter() : pos_(NULL),
390 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos),
395 byte* pos() const { return pos_; }
396 byte* last_pc() const { return last_pc_; }
398 void Write(const RelocInfo* rinfo);
400 // Update the state of the stream after reloc info buffer
401 // and/or code is moved while the stream is active.
402 void Reposition(byte* pos, byte* pc) {
407 // Max size (bytes) of a written RelocInfo. Longest encoding is
408 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
409 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
410 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
411 // Here we use the maximum of the two.
412 static const int kMaxSize = 16;
415 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
416 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
417 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
418 inline void WriteExtraTaggedIntData(int data_delta, int top_tag);
419 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
420 inline void WriteTaggedData(intptr_t data_delta, int tag);
421 inline void WriteExtraTag(int extra_tag, int top_tag);
427 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
431 // A RelocIterator iterates over relocation information.
434 // for (RelocIterator it(code); !it.done(); it.next()) {
435 // // do something with it.rinfo() here
438 // A mask can be specified to skip unwanted modes.
439 class RelocIterator: public Malloced {
441 // Create a new iterator positioned at
442 // the beginning of the reloc info.
443 // Relocation information with mode k is included in the
444 // iteration iff bit k of mode_mask is set.
445 explicit RelocIterator(Code* code, int mode_mask = -1);
446 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
449 bool done() const { return done_; }
452 // Return pointer valid until next next().
459 // Advance* moves the position before/after reading.
460 // *Read* reads from current byte(s) into rinfo_.
461 // *Get* just reads and returns info on current byte.
462 void Advance(int bytes = 1) { pos_ -= bytes; }
467 void AdvanceReadPC();
468 void AdvanceReadId();
469 void AdvanceReadPosition();
470 void AdvanceReadData();
471 void AdvanceReadVariableLengthPCJump();
472 int GetLocatableTypeTag();
474 void ReadTaggedPosition();
476 // If the given mode is wanted, set it in rinfo_ and return true.
477 // Else return false. Used for efficiently skipping unwanted modes.
478 bool SetMode(RelocInfo::Mode mode) {
479 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
489 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
493 //------------------------------------------------------------------------------
496 //----------------------------------------------------------------------------
498 class SCTableReference;
499 #ifdef ENABLE_DEBUGGER_SUPPORT
504 // An ExternalReference represents a C++ address used in the generated
505 // code. All references to C++ functions and variables must be encapsulated in
506 // an ExternalReference instance. This is done in order to track the origin of
507 // all external references in the code so that they can be bound to the correct
508 // addresses when deserializing a heap.
509 class ExternalReference BASE_EMBEDDED {
511 // Used in the simulator to support different native api calls.
514 // MaybeObject* f(v8::internal::Arguments).
515 BUILTIN_CALL, // default
517 // Builtin that takes float arguments and returns an int.
518 // int f(double, double).
519 BUILTIN_COMPARE_CALL,
521 // Builtin call that returns floating point.
522 // double f(double, double).
525 // Builtin call that returns floating point.
529 // Builtin call that returns floating point.
530 // double f(double, int).
533 // Direct call to API function callback.
534 // Handle<Value> f(v8::Arguments&)
537 // Direct call to accessor getter callback.
538 // Handle<value> f(Local<String> property, AccessorInfo& info)
544 typedef void* ExternalReferenceRedirector(void* original, Type type);
546 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
548 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
550 ExternalReference(Builtins::Name name, Isolate* isolate);
552 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
554 ExternalReference(const Runtime::Function* f, Isolate* isolate);
556 ExternalReference(const IC_Utility& ic_utility, Isolate* isolate);
558 #ifdef ENABLE_DEBUGGER_SUPPORT
559 ExternalReference(const Debug_Address& debug_address, Isolate* isolate);
562 explicit ExternalReference(StatsCounter* counter);
564 ExternalReference(Isolate::AddressId id, Isolate* isolate);
566 explicit ExternalReference(const SCTableReference& table_ref);
568 // Isolate::Current() as an external reference.
569 static ExternalReference isolate_address();
571 // One-of-a-kind references. These references are not part of a general
572 // pattern. This means that they have to be added to the
573 // ExternalReferenceTable in serialize.cc manually.
575 static ExternalReference incremental_marking_record_write_function(
577 static ExternalReference incremental_evacuation_record_write_function(
579 static ExternalReference store_buffer_overflow_function(
581 static ExternalReference flush_icache_function(Isolate* isolate);
582 static ExternalReference perform_gc_function(Isolate* isolate);
583 static ExternalReference fill_heap_number_with_random_function(
585 static ExternalReference random_uint32_function(Isolate* isolate);
586 static ExternalReference transcendental_cache_array_address(Isolate* isolate);
587 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
589 static ExternalReference get_date_field_function(Isolate* isolate);
590 static ExternalReference date_cache_stamp(Isolate* isolate);
592 // Deoptimization support.
593 static ExternalReference new_deoptimizer_function(Isolate* isolate);
594 static ExternalReference compute_output_frames_function(Isolate* isolate);
596 // Static data in the keyed lookup cache.
597 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
598 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
600 // Static variable Heap::roots_array_start()
601 static ExternalReference roots_array_start(Isolate* isolate);
603 // Static variable StackGuard::address_of_jslimit()
604 static ExternalReference address_of_stack_limit(Isolate* isolate);
606 // Static variable StackGuard::address_of_real_jslimit()
607 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
609 // Static variable RegExpStack::limit_address()
610 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
612 // Static variables for RegExp.
613 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
614 static ExternalReference address_of_regexp_stack_memory_address(
616 static ExternalReference address_of_regexp_stack_memory_size(
619 // Static variable Heap::NewSpaceStart()
620 static ExternalReference new_space_start(Isolate* isolate);
621 static ExternalReference new_space_mask(Isolate* isolate);
622 static ExternalReference heap_always_allocate_scope_depth(Isolate* isolate);
623 static ExternalReference new_space_mark_bits(Isolate* isolate);
626 static ExternalReference store_buffer_top(Isolate* isolate);
628 // Used for fast allocation in generated code.
629 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
630 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
632 static ExternalReference double_fp_operation(Token::Value operation,
634 static ExternalReference compare_doubles(Isolate* isolate);
635 static ExternalReference power_double_double_function(Isolate* isolate);
636 static ExternalReference power_double_int_function(Isolate* isolate);
638 static ExternalReference handle_scope_next_address();
639 static ExternalReference handle_scope_limit_address();
640 static ExternalReference handle_scope_level_address();
642 static ExternalReference scheduled_exception_address(Isolate* isolate);
644 // Static variables containing common double constants.
645 static ExternalReference address_of_min_int();
646 static ExternalReference address_of_one_half();
647 static ExternalReference address_of_minus_zero();
648 static ExternalReference address_of_zero();
649 static ExternalReference address_of_uint8_max_value();
650 static ExternalReference address_of_negative_infinity();
651 static ExternalReference address_of_canonical_non_hole_nan();
652 static ExternalReference address_of_the_hole_nan();
654 static ExternalReference math_sin_double_function(Isolate* isolate);
655 static ExternalReference math_cos_double_function(Isolate* isolate);
656 static ExternalReference math_tan_double_function(Isolate* isolate);
657 static ExternalReference math_log_double_function(Isolate* isolate);
659 Address address() const {return reinterpret_cast<Address>(address_);}
661 #ifdef ENABLE_DEBUGGER_SUPPORT
662 // Function Debug::Break()
663 static ExternalReference debug_break(Isolate* isolate);
665 // Used to check if single stepping is enabled in generated code.
666 static ExternalReference debug_step_in_fp_address(Isolate* isolate);
669 #ifndef V8_INTERPRETED_REGEXP
670 // C functions called from RegExp generated code.
672 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
673 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
675 // Function RegExpMacroAssembler*::CheckStackGuardState()
676 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
678 // Function NativeRegExpMacroAssembler::GrowStack()
679 static ExternalReference re_grow_stack(Isolate* isolate);
681 // byte NativeRegExpMacroAssembler::word_character_bitmap
682 static ExternalReference re_word_character_map();
686 // This lets you register a function that rewrites all external references.
687 // Used by the ARM simulator to catch calls to external references.
688 static void set_redirector(Isolate* isolate,
689 ExternalReferenceRedirector* redirector) {
690 // We can't stack them.
691 ASSERT(isolate->external_reference_redirector() == NULL);
692 isolate->set_external_reference_redirector(
693 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
697 explicit ExternalReference(void* address)
698 : address_(address) {}
700 static void* Redirect(Isolate* isolate,
702 Type type = ExternalReference::BUILTIN_CALL) {
703 ExternalReferenceRedirector* redirector =
704 reinterpret_cast<ExternalReferenceRedirector*>(
705 isolate->external_reference_redirector());
706 if (redirector == NULL) return address;
707 void* answer = (*redirector)(address, type);
711 static void* Redirect(Isolate* isolate,
713 Type type = ExternalReference::BUILTIN_CALL) {
714 ExternalReferenceRedirector* redirector =
715 reinterpret_cast<ExternalReferenceRedirector*>(
716 isolate->external_reference_redirector());
717 void* address = reinterpret_cast<void*>(address_arg);
718 void* answer = (redirector == NULL) ?
720 (*redirector)(address, type);
728 // -----------------------------------------------------------------------------
729 // Position recording support
731 struct PositionState {
732 PositionState() : current_position(RelocInfo::kNoPosition),
733 written_position(RelocInfo::kNoPosition),
734 current_statement_position(RelocInfo::kNoPosition),
735 written_statement_position(RelocInfo::kNoPosition) {}
737 int current_position;
738 int written_position;
740 int current_statement_position;
741 int written_statement_position;
745 class PositionsRecorder BASE_EMBEDDED {
747 explicit PositionsRecorder(Assembler* assembler)
748 : assembler_(assembler) {
749 #ifdef ENABLE_GDB_JIT_INTERFACE
750 gdbjit_lineinfo_ = NULL;
754 #ifdef ENABLE_GDB_JIT_INTERFACE
755 ~PositionsRecorder() {
756 delete gdbjit_lineinfo_;
759 void StartGDBJITLineInfoRecording() {
761 gdbjit_lineinfo_ = new GDBJITLineInfo();
765 GDBJITLineInfo* DetachGDBJITLineInfo() {
766 GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
767 gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
772 // Set current position to pos.
773 void RecordPosition(int pos);
775 // Set current statement position to pos.
776 void RecordStatementPosition(int pos);
778 // Write recorded positions to relocation information.
779 bool WriteRecordedPositions();
781 int current_position() const { return state_.current_position; }
783 int current_statement_position() const {
784 return state_.current_statement_position;
788 Assembler* assembler_;
789 PositionState state_;
790 #ifdef ENABLE_GDB_JIT_INTERFACE
791 GDBJITLineInfo* gdbjit_lineinfo_;
794 friend class PreservePositionScope;
796 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
800 class PreservePositionScope BASE_EMBEDDED {
802 explicit PreservePositionScope(PositionsRecorder* positions_recorder)
803 : positions_recorder_(positions_recorder),
804 saved_state_(positions_recorder->state_) {}
806 ~PreservePositionScope() {
807 positions_recorder_->state_ = saved_state_;
811 PositionsRecorder* positions_recorder_;
812 const PositionState saved_state_;
814 DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
818 // -----------------------------------------------------------------------------
821 inline bool is_intn(int x, int n) {
822 return -(1 << (n-1)) <= x && x < (1 << (n-1));
825 inline bool is_int8(int x) { return is_intn(x, 8); }
826 inline bool is_int16(int x) { return is_intn(x, 16); }
827 inline bool is_int18(int x) { return is_intn(x, 18); }
828 inline bool is_int24(int x) { return is_intn(x, 24); }
830 inline bool is_uintn(int x, int n) {
831 return (x & -(1 << n)) == 0;
834 inline bool is_uint2(int x) { return is_uintn(x, 2); }
835 inline bool is_uint3(int x) { return is_uintn(x, 3); }
836 inline bool is_uint4(int x) { return is_uintn(x, 4); }
837 inline bool is_uint5(int x) { return is_uintn(x, 5); }
838 inline bool is_uint6(int x) { return is_uintn(x, 6); }
839 inline bool is_uint8(int x) { return is_uintn(x, 8); }
840 inline bool is_uint10(int x) { return is_uintn(x, 10); }
841 inline bool is_uint12(int x) { return is_uintn(x, 12); }
842 inline bool is_uint16(int x) { return is_uintn(x, 16); }
843 inline bool is_uint24(int x) { return is_uintn(x, 24); }
844 inline bool is_uint26(int x) { return is_uintn(x, 26); }
845 inline bool is_uint28(int x) { return is_uintn(x, 28); }
847 inline int NumberOfBitsSet(uint32_t x) {
848 unsigned int num_bits_set;
849 for (num_bits_set = 0; x; x >>= 1) {
850 num_bits_set += x & 1;
855 bool EvalComparison(Token::Value op, double op1, double op2);
857 // Computes pow(x, y) with the special cases in the spec for Math.pow.
858 double power_double_int(double x, int y);
859 double power_double_double(double x, double y);
861 // Helper class for generating code or data associated with the code
862 // right after a call instruction. As an example this can be used to
863 // generate safepoint data after calls for crankshaft.
867 virtual ~CallWrapper() { }
868 // Called just before emitting a call. Argument is the size of the generated
870 virtual void BeforeCall(int call_size) const = 0;
871 // Called just after emitting a call, i.e., at the return site for the call.
872 virtual void AfterCall() const = 0;
875 class NullCallWrapper : public CallWrapper {
877 NullCallWrapper() { }
878 virtual ~NullCallWrapper() { }
879 virtual void BeforeCall(int call_size) const { }
880 virtual void AfterCall() const { }
883 } } // namespace v8::internal
885 #endif // V8_ASSEMBLER_H_