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 // -----------------------------------------------------------------------------
55 // Platform independent assembler base class.
57 class AssemblerBase: public Malloced {
59 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size);
60 virtual ~AssemblerBase();
62 Isolate* isolate() const { return isolate_; }
63 int jit_cookie() const { return jit_cookie_; }
65 bool emit_debug_code() const { return emit_debug_code_; }
66 void set_emit_debug_code(bool value) { emit_debug_code_ = value; }
68 bool predictable_code_size() const { return predictable_code_size_; }
69 void set_predictable_code_size(bool value) { predictable_code_size_ = value; }
71 uint64_t enabled_cpu_features() const { return enabled_cpu_features_; }
72 void set_enabled_cpu_features(uint64_t features) {
73 enabled_cpu_features_ = features;
75 bool IsEnabled(CpuFeature f) {
76 return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
79 // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
80 // cross-snapshotting.
81 static void QuietNaN(HeapObject* nan) { }
83 int pc_offset() const { return static_cast<int>(pc_ - buffer_); }
85 static const int kMinimalBufferSize = 4*KB;
88 // The buffer into which code and relocation info are generated. It could
89 // either be owned by the assembler or be provided externally.
94 // The program counter, which points into the buffer above and moves forward.
100 uint64_t enabled_cpu_features_;
101 bool emit_debug_code_;
102 bool predictable_code_size_;
106 // Avoids using instructions that vary in size in unpredictable ways between the
107 // snapshot and the running VM.
108 class PredictableCodeSizeScope {
110 PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size);
111 ~PredictableCodeSizeScope();
114 AssemblerBase* assembler_;
121 // Enable a specified feature within a scope.
122 class CpuFeatureScope BASE_EMBEDDED {
125 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f);
129 AssemblerBase* assembler_;
130 uint64_t old_enabled_;
132 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {}
137 // Enable a unsupported feature within a scope for cross-compiling for a
139 class PlatformFeatureScope BASE_EMBEDDED {
141 explicit PlatformFeatureScope(CpuFeature f);
142 ~PlatformFeatureScope();
145 uint64_t old_cross_compile_;
149 // -----------------------------------------------------------------------------
150 // Labels represent pc locations; they are typically jump or call targets.
151 // After declaration, a label can be freely used to denote known or (yet)
152 // unknown pc location. Assembler::bind() is used to bind a label to the
153 // current pc. A label can be bound only once.
155 class Label BASE_EMBEDDED {
167 ASSERT(!is_linked());
168 ASSERT(!is_near_linked());
171 INLINE(void Unuse()) { pos_ = 0; }
172 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
174 INLINE(bool is_bound() const) { return pos_ < 0; }
175 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
176 INLINE(bool is_linked() const) { return pos_ > 0; }
177 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
179 // Returns the position of bound or linked labels. Cannot be used
180 // for unused labels.
182 int near_link_pos() const { return near_link_pos_ - 1; }
185 // pos_ encodes both the binding state (via its sign)
186 // and the binding position (via its value) of a label.
188 // pos_ < 0 bound label, pos() returns the jump target position
189 // pos_ == 0 unused label
190 // pos_ > 0 linked label, pos() returns the last reference position
193 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
196 void bind_to(int pos) {
200 void link_to(int pos, Distance distance = kFar) {
201 if (distance == kNear) {
202 near_link_pos_ = pos + 1;
203 ASSERT(is_near_linked());
210 friend class Assembler;
211 friend class Displacement;
212 friend class RegExpMacroAssemblerIrregexp;
216 enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
219 // -----------------------------------------------------------------------------
220 // Relocation information
223 // Relocation information consists of the address (pc) of the datum
224 // to which the relocation information applies, the relocation mode
225 // (rmode), and an optional data field. The relocation mode may be
226 // "descriptive" and not indicate a need for relocation, but simply
227 // describe a property of the datum. Such rmodes are useful for GC
228 // and nice disassembly output.
230 class RelocInfo BASE_EMBEDDED {
232 // The constant kNoPosition is used with the collecting of source positions
233 // in the relocation information. Two types of source positions are collected
234 // "position" (RelocMode position) and "statement position" (RelocMode
235 // statement_position). The "position" is collected at places in the source
236 // code which are of interest when making stack traces to pin-point the source
237 // location of a stack frame as close as possible. The "statement position" is
238 // collected at the beginning at each statement, and is used to indicate
239 // possible break locations. kNoPosition is used to indicate an
240 // invalid/uninitialized position value.
241 static const int kNoPosition = -1;
243 // This string is used to add padding comments to the reloc info in cases
244 // where we are not sure to have enough space for patching in during
245 // lazy deoptimization. This is the case if we have indirect calls for which
246 // we do not normally record relocation info.
247 static const char* const kFillerCommentString;
249 // The minimum size of a comment is equal to three bytes for the extra tagged
250 // pc + the tag for the data, and kPointerSize for the actual pointer to the
252 static const int kMinRelocCommentSize = 3 + kPointerSize;
254 // The maximum size for a call instruction including pc-jump.
255 static const int kMaxCallSize = 6;
257 // The maximum pc delta that will use the short encoding.
258 static const int kMaxSmallPCDelta;
261 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
262 CODE_TARGET, // Code target which is not any of the above.
264 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
265 DEBUG_BREAK, // Code target for the debugger statement.
269 // Everything after runtime_entry (inclusive) is not GC'ed.
271 JS_RETURN, // Marks start of the ExitJSFrame code.
273 POSITION, // See comment for kNoPosition above.
274 STATEMENT_POSITION, // See comment for kNoPosition above.
275 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
276 EXTERNAL_REFERENCE, // The address of an external C++ function.
277 INTERNAL_REFERENCE, // An address inside the same function.
279 // Marks a constant pool. Only used on ARM.
280 // It uses a custom noncompact encoding.
283 // add more as needed
285 NUMBER_OF_MODES, // There are at most 15 modes with noncompact encoding.
286 NONE32, // never recorded 32-bit value
287 NONE64, // never recorded 64-bit value
288 CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by
290 FIRST_REAL_RELOC_MODE = CODE_TARGET,
291 LAST_REAL_RELOC_MODE = CONST_POOL,
292 FIRST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE,
293 LAST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE,
294 LAST_CODE_ENUM = DEBUG_BREAK,
295 LAST_GCED_ENUM = CELL,
296 // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding.
297 LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID,
298 LAST_STANDARD_NONCOMPACT_ENUM = INTERNAL_REFERENCE
304 RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host)
305 : pc_(pc), rmode_(rmode), data_(data), host_(host) {
307 RelocInfo(byte* pc, double data64)
308 : pc_(pc), rmode_(NONE64), data64_(data64), host_(NULL) {
311 static inline bool IsRealRelocMode(Mode mode) {
312 return mode >= FIRST_REAL_RELOC_MODE &&
313 mode <= LAST_REAL_RELOC_MODE;
315 static inline bool IsPseudoRelocMode(Mode mode) {
316 ASSERT(!IsRealRelocMode(mode));
317 return mode >= FIRST_PSEUDO_RELOC_MODE &&
318 mode <= LAST_PSEUDO_RELOC_MODE;
320 static inline bool IsConstructCall(Mode mode) {
321 return mode == CONSTRUCT_CALL;
323 static inline bool IsCodeTarget(Mode mode) {
324 return mode <= LAST_CODE_ENUM;
326 static inline bool IsEmbeddedObject(Mode mode) {
327 return mode == EMBEDDED_OBJECT;
329 static inline bool IsRuntimeEntry(Mode mode) {
330 return mode == RUNTIME_ENTRY;
332 // Is the relocation mode affected by GC?
333 static inline bool IsGCRelocMode(Mode mode) {
334 return mode <= LAST_GCED_ENUM;
336 static inline bool IsJSReturn(Mode mode) {
337 return mode == JS_RETURN;
339 static inline bool IsComment(Mode mode) {
340 return mode == COMMENT;
342 static inline bool IsConstPool(Mode mode) {
343 return mode == CONST_POOL;
345 static inline bool IsPosition(Mode mode) {
346 return mode == POSITION || mode == STATEMENT_POSITION;
348 static inline bool IsStatementPosition(Mode mode) {
349 return mode == STATEMENT_POSITION;
351 static inline bool IsExternalReference(Mode mode) {
352 return mode == EXTERNAL_REFERENCE;
354 static inline bool IsInternalReference(Mode mode) {
355 return mode == INTERNAL_REFERENCE;
357 static inline bool IsDebugBreakSlot(Mode mode) {
358 return mode == DEBUG_BREAK_SLOT;
360 static inline bool IsNone(Mode mode) {
361 return mode == NONE32 || mode == NONE64;
363 static inline bool IsCodeAgeSequence(Mode mode) {
364 return mode == CODE_AGE_SEQUENCE;
366 static inline int ModeMask(Mode mode) { return 1 << mode; }
369 byte* pc() const { return pc_; }
370 void set_pc(byte* pc) { pc_ = pc; }
371 Mode rmode() const { return rmode_; }
372 intptr_t data() const { return data_; }
373 double data64() const { return data64_; }
374 uint64_t raw_data64() {
375 return BitCast<uint64_t>(data64_);
377 Code* host() const { return host_; }
379 // Apply a relocation by delta bytes
380 INLINE(void apply(intptr_t delta));
382 // Is the pointer this relocation info refers to coded like a plain pointer
383 // or is it strange in some way (e.g. relative or patched into a series of
385 bool IsCodedSpecially();
387 // Read/modify the code target in the branch/call instruction
388 // this relocation applies to;
389 // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
390 INLINE(Address target_address());
391 INLINE(void set_target_address(Address target,
392 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
393 INLINE(Object* target_object());
394 INLINE(Handle<Object> target_object_handle(Assembler* origin));
395 INLINE(void set_target_object(Object* target,
396 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
397 INLINE(Address target_runtime_entry(Assembler* origin));
398 INLINE(void set_target_runtime_entry(Address target,
399 WriteBarrierMode mode =
400 UPDATE_WRITE_BARRIER));
401 INLINE(Cell* target_cell());
402 INLINE(Handle<Cell> target_cell_handle());
403 INLINE(void set_target_cell(Cell* cell,
404 WriteBarrierMode mode = UPDATE_WRITE_BARRIER));
405 INLINE(Handle<Object> code_age_stub_handle(Assembler* origin));
406 INLINE(Code* code_age_stub());
407 INLINE(void set_code_age_stub(Code* stub));
409 // Read the address of the word containing the target_address in an
410 // instruction stream. What this means exactly is architecture-independent.
411 // The only architecture-independent user of this function is the serializer.
412 // The serializer uses it to find out how many raw bytes of instruction to
413 // output before the next target. Architecture-independent code shouldn't
414 // dereference the pointer it gets back from this.
415 INLINE(Address target_address_address());
416 // This indicates how much space a target takes up when deserializing a code
417 // stream. For most architectures this is just the size of a pointer. For
418 // an instruction like movw/movt where the target bits are mixed into the
419 // instruction bits the size of the target will be zero, indicating that the
420 // serializer should not step forwards in memory after a target is resolved
421 // and written. In this case the target_address_address function above
422 // should return the end of the instructions to be patched, allowing the
423 // deserializer to deserialize the instructions as raw bytes and put them in
424 // place, ready to be patched with the target.
425 INLINE(int target_address_size());
427 // Read/modify the reference in the instruction this relocation
428 // applies to; can only be called if rmode_ is external_reference
429 INLINE(Address target_reference());
431 // Read/modify the address of a call instruction. This is used to relocate
432 // the break points where straight-line code is patched with a call
434 INLINE(Address call_address());
435 INLINE(void set_call_address(Address target));
436 INLINE(Object* call_object());
437 INLINE(void set_call_object(Object* target));
438 INLINE(Object** call_object_address());
440 // Wipe out a relocation to a fixed value, used for making snapshots
442 INLINE(void WipeOut());
444 template<typename StaticVisitor> inline void Visit(Heap* heap);
445 inline void Visit(Isolate* isolate, ObjectVisitor* v);
447 // Patch the code with some other code.
448 void PatchCode(byte* instructions, int instruction_count);
450 // Patch the code with a call.
451 void PatchCodeWithCall(Address target, int guard_bytes);
453 // Check whether this return sequence has been patched
454 // with a call to the debugger.
455 INLINE(bool IsPatchedReturnSequence());
457 // Check whether this debug break slot has been patched with a call to the
459 INLINE(bool IsPatchedDebugBreakSlotSequence());
462 // Check whether the given code contains relocation information that
463 // either is position-relative or movable by the garbage collector.
464 static bool RequiresRelocation(const CodeDesc& desc);
467 #ifdef ENABLE_DISASSEMBLER
469 static const char* RelocModeName(Mode rmode);
470 void Print(Isolate* isolate, FILE* out);
471 #endif // ENABLE_DISASSEMBLER
476 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
477 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
478 static const int kDataMask =
479 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
480 static const int kApplyMask; // Modes affected by apply. Depends on arch.
483 // On ARM, note that pc_ is the address of the constant pool entry
484 // to be relocated and not the address of the instruction
485 // referencing the constant pool entry (except when rmode_ ==
494 // External-reference pointers are also split across instruction-pairs
495 // on some platforms, but are accessed via indirect pointers. This location
496 // provides a place for that pointer to exist naturally. Its address
497 // is returned by RelocInfo::target_reference_address().
498 Address reconstructed_adr_ptr_;
499 friend class RelocIterator;
503 // RelocInfoWriter serializes a stream of relocation info. It writes towards
505 class RelocInfoWriter BASE_EMBEDDED {
507 RelocInfoWriter() : pos_(NULL),
511 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos),
516 byte* pos() const { return pos_; }
517 byte* last_pc() const { return last_pc_; }
519 void Write(const RelocInfo* rinfo);
521 // Update the state of the stream after reloc info buffer
522 // and/or code is moved while the stream is active.
523 void Reposition(byte* pos, byte* pc) {
528 // Max size (bytes) of a written RelocInfo. Longest encoding is
529 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
530 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
531 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
532 // Here we use the maximum of the two.
533 static const int kMaxSize = 16;
536 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
537 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
538 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
539 inline void WriteExtraTaggedIntData(int data_delta, int top_tag);
540 inline void WriteExtraTaggedConstPoolData(int data);
541 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
542 inline void WriteTaggedData(intptr_t data_delta, int tag);
543 inline void WriteExtraTag(int extra_tag, int top_tag);
549 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
553 // A RelocIterator iterates over relocation information.
556 // for (RelocIterator it(code); !it.done(); it.next()) {
557 // // do something with it.rinfo() here
560 // A mask can be specified to skip unwanted modes.
561 class RelocIterator: public Malloced {
563 // Create a new iterator positioned at
564 // the beginning of the reloc info.
565 // Relocation information with mode k is included in the
566 // iteration iff bit k of mode_mask is set.
567 explicit RelocIterator(Code* code, int mode_mask = -1);
568 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
571 bool done() const { return done_; }
574 // Return pointer valid until next next().
581 // Advance* moves the position before/after reading.
582 // *Read* reads from current byte(s) into rinfo_.
583 // *Get* just reads and returns info on current byte.
584 void Advance(int bytes = 1) { pos_ -= bytes; }
589 void AdvanceReadPC();
590 void AdvanceReadId();
591 void AdvanceReadConstPoolData();
592 void AdvanceReadPosition();
593 void AdvanceReadData();
594 void AdvanceReadVariableLengthPCJump();
595 int GetLocatableTypeTag();
597 void ReadTaggedPosition();
599 // If the given mode is wanted, set it in rinfo_ and return true.
600 // Else return false. Used for efficiently skipping unwanted modes.
601 bool SetMode(RelocInfo::Mode mode) {
602 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
607 byte* code_age_sequence_;
613 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
617 //------------------------------------------------------------------------------
620 //----------------------------------------------------------------------------
622 class SCTableReference;
623 #ifdef ENABLE_DEBUGGER_SUPPORT
628 // An ExternalReference represents a C++ address used in the generated
629 // code. All references to C++ functions and variables must be encapsulated in
630 // an ExternalReference instance. This is done in order to track the origin of
631 // all external references in the code so that they can be bound to the correct
632 // addresses when deserializing a heap.
633 class ExternalReference BASE_EMBEDDED {
635 // Used in the simulator to support different native api calls.
638 // MaybeObject* f(v8::internal::Arguments).
639 BUILTIN_CALL, // default
641 // Builtin that takes float arguments and returns an int.
642 // int f(double, double).
643 BUILTIN_COMPARE_CALL,
645 // Builtin call that returns floating point.
646 // double f(double, double).
649 // Builtin call that returns floating point.
653 // Builtin call that returns floating point.
654 // double f(double, int).
657 // Direct call to API function callback.
658 // void f(v8::FunctionCallbackInfo&)
661 // Call to function callback via InvokeFunctionCallback.
662 // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
665 // Direct call to accessor getter callback.
666 // void f(Local<String> property, PropertyCallbackInfo& info)
669 // Call to accessor getter callback via InvokeAccessorGetterCallback.
670 // void f(Local<String> property, PropertyCallbackInfo& info,
671 // AccessorGetterCallback callback)
672 PROFILING_GETTER_CALL
676 static void InitializeMathExpData();
677 static void TearDownMathExpData();
679 typedef void* ExternalReferenceRedirector(void* original, Type type);
681 ExternalReference() : address_(NULL) {}
683 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
685 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
687 ExternalReference(Builtins::Name name, Isolate* isolate);
689 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
691 ExternalReference(const Runtime::Function* f, Isolate* isolate);
693 ExternalReference(const IC_Utility& ic_utility, Isolate* isolate);
695 #ifdef ENABLE_DEBUGGER_SUPPORT
696 ExternalReference(const Debug_Address& debug_address, Isolate* isolate);
699 explicit ExternalReference(StatsCounter* counter);
701 ExternalReference(Isolate::AddressId id, Isolate* isolate);
703 explicit ExternalReference(const SCTableReference& table_ref);
705 // Isolate as an external reference.
706 static ExternalReference isolate_address(Isolate* isolate);
708 // One-of-a-kind references. These references are not part of a general
709 // pattern. This means that they have to be added to the
710 // ExternalReferenceTable in serialize.cc manually.
712 static ExternalReference incremental_marking_record_write_function(
714 static ExternalReference incremental_evacuation_record_write_function(
716 static ExternalReference store_buffer_overflow_function(
718 static ExternalReference flush_icache_function(Isolate* isolate);
719 static ExternalReference perform_gc_function(Isolate* isolate);
720 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
722 static ExternalReference get_date_field_function(Isolate* isolate);
723 static ExternalReference date_cache_stamp(Isolate* isolate);
725 static ExternalReference get_make_code_young_function(Isolate* isolate);
726 static ExternalReference get_mark_code_as_executed_function(Isolate* isolate);
728 // Deoptimization support.
729 static ExternalReference new_deoptimizer_function(Isolate* isolate);
730 static ExternalReference compute_output_frames_function(Isolate* isolate);
733 static ExternalReference log_enter_external_function(Isolate* isolate);
734 static ExternalReference log_leave_external_function(Isolate* isolate);
736 // Static data in the keyed lookup cache.
737 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
738 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
740 // Static variable Heap::roots_array_start()
741 static ExternalReference roots_array_start(Isolate* isolate);
743 // Static variable Heap::allocation_sites_list_address()
744 static ExternalReference allocation_sites_list_address(Isolate* isolate);
746 // Static variable StackGuard::address_of_jslimit()
747 static ExternalReference address_of_stack_limit(Isolate* isolate);
749 // Static variable StackGuard::address_of_real_jslimit()
750 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
752 // Static variable RegExpStack::limit_address()
753 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
755 // Static variables for RegExp.
756 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
757 static ExternalReference address_of_regexp_stack_memory_address(
759 static ExternalReference address_of_regexp_stack_memory_size(
762 // Static variable Heap::NewSpaceStart()
763 static ExternalReference new_space_start(Isolate* isolate);
764 static ExternalReference new_space_mask(Isolate* isolate);
765 static ExternalReference heap_always_allocate_scope_depth(Isolate* isolate);
766 static ExternalReference new_space_mark_bits(Isolate* isolate);
769 static ExternalReference store_buffer_top(Isolate* isolate);
771 // Used for fast allocation in generated code.
772 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
773 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
774 static ExternalReference old_pointer_space_allocation_top_address(
776 static ExternalReference old_pointer_space_allocation_limit_address(
778 static ExternalReference old_data_space_allocation_top_address(
780 static ExternalReference old_data_space_allocation_limit_address(
782 static ExternalReference new_space_high_promotion_mode_active_address(
785 static ExternalReference mod_two_doubles_operation(Isolate* isolate);
786 static ExternalReference power_double_double_function(Isolate* isolate);
787 static ExternalReference power_double_int_function(Isolate* isolate);
789 static ExternalReference handle_scope_next_address(Isolate* isolate);
790 static ExternalReference handle_scope_limit_address(Isolate* isolate);
791 static ExternalReference handle_scope_level_address(Isolate* isolate);
793 static ExternalReference scheduled_exception_address(Isolate* isolate);
794 static ExternalReference address_of_pending_message_obj(Isolate* isolate);
795 static ExternalReference address_of_has_pending_message(Isolate* isolate);
796 static ExternalReference address_of_pending_message_script(Isolate* isolate);
798 // Static variables containing common double constants.
799 static ExternalReference address_of_min_int();
800 static ExternalReference address_of_one_half();
801 static ExternalReference address_of_minus_one_half();
802 static ExternalReference address_of_minus_zero();
803 static ExternalReference address_of_zero();
804 static ExternalReference address_of_uint8_max_value();
805 static ExternalReference address_of_negative_infinity();
806 static ExternalReference address_of_canonical_non_hole_nan();
807 static ExternalReference address_of_the_hole_nan();
808 static ExternalReference address_of_uint32_bias();
810 static ExternalReference math_log_double_function(Isolate* isolate);
812 static ExternalReference math_exp_constants(int constant_index);
813 static ExternalReference math_exp_log_table();
815 static ExternalReference page_flags(Page* page);
817 static ExternalReference ForDeoptEntry(Address entry);
819 static ExternalReference cpu_features();
821 Address address() const { return reinterpret_cast<Address>(address_); }
823 #ifdef ENABLE_DEBUGGER_SUPPORT
824 // Function Debug::Break()
825 static ExternalReference debug_break(Isolate* isolate);
827 // Used to check if single stepping is enabled in generated code.
828 static ExternalReference debug_step_in_fp_address(Isolate* isolate);
831 #ifndef V8_INTERPRETED_REGEXP
832 // C functions called from RegExp generated code.
834 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
835 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
837 // Function RegExpMacroAssembler*::CheckStackGuardState()
838 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
840 // Function NativeRegExpMacroAssembler::GrowStack()
841 static ExternalReference re_grow_stack(Isolate* isolate);
843 // byte NativeRegExpMacroAssembler::word_character_bitmap
844 static ExternalReference re_word_character_map();
848 // This lets you register a function that rewrites all external references.
849 // Used by the ARM simulator to catch calls to external references.
850 static void set_redirector(Isolate* isolate,
851 ExternalReferenceRedirector* redirector) {
852 // We can't stack them.
853 ASSERT(isolate->external_reference_redirector() == NULL);
854 isolate->set_external_reference_redirector(
855 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
858 static ExternalReference stress_deopt_count(Isolate* isolate);
860 bool operator==(const ExternalReference& other) const {
861 return address_ == other.address_;
864 bool operator!=(const ExternalReference& other) const {
865 return !(*this == other);
869 explicit ExternalReference(void* address)
870 : address_(address) {}
872 static void* Redirect(Isolate* isolate,
874 Type type = ExternalReference::BUILTIN_CALL) {
875 ExternalReferenceRedirector* redirector =
876 reinterpret_cast<ExternalReferenceRedirector*>(
877 isolate->external_reference_redirector());
878 if (redirector == NULL) return address;
879 void* answer = (*redirector)(address, type);
883 static void* Redirect(Isolate* isolate,
885 Type type = ExternalReference::BUILTIN_CALL) {
886 ExternalReferenceRedirector* redirector =
887 reinterpret_cast<ExternalReferenceRedirector*>(
888 isolate->external_reference_redirector());
889 void* address = reinterpret_cast<void*>(address_arg);
890 void* answer = (redirector == NULL) ?
892 (*redirector)(address, type);
900 // -----------------------------------------------------------------------------
901 // Position recording support
903 struct PositionState {
904 PositionState() : current_position(RelocInfo::kNoPosition),
905 written_position(RelocInfo::kNoPosition),
906 current_statement_position(RelocInfo::kNoPosition),
907 written_statement_position(RelocInfo::kNoPosition) {}
909 int current_position;
910 int written_position;
912 int current_statement_position;
913 int written_statement_position;
917 class PositionsRecorder BASE_EMBEDDED {
919 explicit PositionsRecorder(Assembler* assembler)
920 : assembler_(assembler) {
921 #ifdef ENABLE_GDB_JIT_INTERFACE
922 gdbjit_lineinfo_ = NULL;
924 jit_handler_data_ = NULL;
927 #ifdef ENABLE_GDB_JIT_INTERFACE
928 ~PositionsRecorder() {
929 delete gdbjit_lineinfo_;
932 void StartGDBJITLineInfoRecording() {
934 gdbjit_lineinfo_ = new GDBJITLineInfo();
938 GDBJITLineInfo* DetachGDBJITLineInfo() {
939 GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
940 gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
944 void AttachJITHandlerData(void* user_data) {
945 jit_handler_data_ = user_data;
948 void* DetachJITHandlerData() {
949 void* old_data = jit_handler_data_;
950 jit_handler_data_ = NULL;
953 // Set current position to pos.
954 void RecordPosition(int pos);
956 // Set current statement position to pos.
957 void RecordStatementPosition(int pos);
959 // Write recorded positions to relocation information.
960 bool WriteRecordedPositions();
962 int current_position() const { return state_.current_position; }
964 int current_statement_position() const {
965 return state_.current_statement_position;
969 Assembler* assembler_;
970 PositionState state_;
971 #ifdef ENABLE_GDB_JIT_INTERFACE
972 GDBJITLineInfo* gdbjit_lineinfo_;
975 // Currently jit_handler_data_ is used to store JITHandler-specific data
976 // over the lifetime of a PositionsRecorder
977 void* jit_handler_data_;
978 friend class PreservePositionScope;
980 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
984 class PreservePositionScope BASE_EMBEDDED {
986 explicit PreservePositionScope(PositionsRecorder* positions_recorder)
987 : positions_recorder_(positions_recorder),
988 saved_state_(positions_recorder->state_) {}
990 ~PreservePositionScope() {
991 positions_recorder_->state_ = saved_state_;
995 PositionsRecorder* positions_recorder_;
996 const PositionState saved_state_;
998 DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
1002 // -----------------------------------------------------------------------------
1003 // Utility functions
1005 inline bool is_intn(int x, int n) {
1006 return -(1 << (n-1)) <= x && x < (1 << (n-1));
1009 inline bool is_int8(int x) { return is_intn(x, 8); }
1010 inline bool is_int16(int x) { return is_intn(x, 16); }
1011 inline bool is_int18(int x) { return is_intn(x, 18); }
1012 inline bool is_int24(int x) { return is_intn(x, 24); }
1014 inline bool is_uintn(int x, int n) {
1015 return (x & -(1 << n)) == 0;
1018 inline bool is_uint2(int x) { return is_uintn(x, 2); }
1019 inline bool is_uint3(int x) { return is_uintn(x, 3); }
1020 inline bool is_uint4(int x) { return is_uintn(x, 4); }
1021 inline bool is_uint5(int x) { return is_uintn(x, 5); }
1022 inline bool is_uint6(int x) { return is_uintn(x, 6); }
1023 inline bool is_uint8(int x) { return is_uintn(x, 8); }
1024 inline bool is_uint10(int x) { return is_uintn(x, 10); }
1025 inline bool is_uint12(int x) { return is_uintn(x, 12); }
1026 inline bool is_uint16(int x) { return is_uintn(x, 16); }
1027 inline bool is_uint24(int x) { return is_uintn(x, 24); }
1028 inline bool is_uint26(int x) { return is_uintn(x, 26); }
1029 inline bool is_uint28(int x) { return is_uintn(x, 28); }
1031 inline int NumberOfBitsSet(uint32_t x) {
1032 unsigned int num_bits_set;
1033 for (num_bits_set = 0; x; x >>= 1) {
1034 num_bits_set += x & 1;
1036 return num_bits_set;
1039 bool EvalComparison(Token::Value op, double op1, double op2);
1041 // Computes pow(x, y) with the special cases in the spec for Math.pow.
1042 double power_helper(double x, double y);
1043 double power_double_int(double x, int y);
1044 double power_double_double(double x, double y);
1046 // Helper class for generating code or data associated with the code
1047 // right after a call instruction. As an example this can be used to
1048 // generate safepoint data after calls for crankshaft.
1052 virtual ~CallWrapper() { }
1053 // Called just before emitting a call. Argument is the size of the generated
1055 virtual void BeforeCall(int call_size) const = 0;
1056 // Called just after emitting a call, i.e., at the return site for the call.
1057 virtual void AfterCall() const = 0;
1060 class NullCallWrapper : public CallWrapper {
1062 NullCallWrapper() { }
1063 virtual ~NullCallWrapper() { }
1064 virtual void BeforeCall(int call_size) const { }
1065 virtual void AfterCall() const { }
1068 } } // namespace v8::internal
1070 #endif // V8_ASSEMBLER_H_