v8  3.14.5(node0.10.28)
V8 is Google's open source JavaScript engine
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
assembler.h
Go to the documentation of this file.
1 // 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 2012 the V8 project authors. All rights reserved.
34 
35 #ifndef V8_ASSEMBLER_H_
36 #define V8_ASSEMBLER_H_
37 
38 #include "v8.h"
39 
40 #include "allocation.h"
41 #include "builtins.h"
42 #include "gdb-jit.h"
43 #include "isolate.h"
44 #include "runtime.h"
45 #include "token.h"
46 
47 namespace v8 {
48 
49 class ApiFunction;
50 
51 namespace internal {
52 
53 struct StatsCounter;
54 // -----------------------------------------------------------------------------
55 // Platform independent assembler base class.
56 
57 class AssemblerBase: public Malloced {
58  public:
59  explicit AssemblerBase(Isolate* isolate);
60 
61  Isolate* isolate() const { return isolate_; }
62  int jit_cookie() { return jit_cookie_; }
63 
64  // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
65  // cross-snapshotting.
66  static void QuietNaN(HeapObject* nan) { }
67 
68  private:
69  Isolate* isolate_;
70  int jit_cookie_;
71 };
72 
73 
74 // -----------------------------------------------------------------------------
75 // Labels represent pc locations; they are typically jump or call targets.
76 // After declaration, a label can be freely used to denote known or (yet)
77 // unknown pc location. Assembler::bind() is used to bind a label to the
78 // current pc. A label can be bound only once.
79 
80 class Label BASE_EMBEDDED {
81  public:
82  enum Distance {
83  kNear, kFar
84  };
85 
86  INLINE(Label()) {
87  Unuse();
88  UnuseNear();
89  }
90 
91  INLINE(~Label()) {
92  ASSERT(!is_linked());
93  ASSERT(!is_near_linked());
94  }
95 
96  INLINE(void Unuse()) { pos_ = 0; }
97  INLINE(void UnuseNear()) { near_link_pos_ = 0; }
98 
99  INLINE(bool is_bound() const) { return pos_ < 0; }
100  INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
101  INLINE(bool is_linked() const) { return pos_ > 0; }
102  INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
103 
104  // Returns the position of bound or linked labels. Cannot be used
105  // for unused labels.
106  int pos() const;
107  int near_link_pos() const { return near_link_pos_ - 1; }
108 
109  private:
110  // pos_ encodes both the binding state (via its sign)
111  // and the binding position (via its value) of a label.
112  //
113  // pos_ < 0 bound label, pos() returns the jump target position
114  // pos_ == 0 unused label
115  // pos_ > 0 linked label, pos() returns the last reference position
116  int pos_;
117 
118  // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
119  int near_link_pos_;
120 
121  void bind_to(int pos) {
122  pos_ = -pos - 1;
123  ASSERT(is_bound());
124  }
125  void link_to(int pos, Distance distance = kFar) {
126  if (distance == kNear) {
127  near_link_pos_ = pos + 1;
128  ASSERT(is_near_linked());
129  } else {
130  pos_ = pos + 1;
131  ASSERT(is_linked());
132  }
133  }
134 
135  friend class Assembler;
136  friend class RegexpAssembler;
137  friend class Displacement;
138  friend class RegExpMacroAssemblerIrregexp;
139 };
140 
141 
143 
144 
145 // -----------------------------------------------------------------------------
146 // Relocation information
147 
148 
149 // Relocation information consists of the address (pc) of the datum
150 // to which the relocation information applies, the relocation mode
151 // (rmode), and an optional data field. The relocation mode may be
152 // "descriptive" and not indicate a need for relocation, but simply
153 // describe a property of the datum. Such rmodes are useful for GC
154 // and nice disassembly output.
155 
156 class RelocInfo BASE_EMBEDDED {
157  public:
158  // The constant kNoPosition is used with the collecting of source positions
159  // in the relocation information. Two types of source positions are collected
160  // "position" (RelocMode position) and "statement position" (RelocMode
161  // statement_position). The "position" is collected at places in the source
162  // code which are of interest when making stack traces to pin-point the source
163  // location of a stack frame as close as possible. The "statement position" is
164  // collected at the beginning at each statement, and is used to indicate
165  // possible break locations. kNoPosition is used to indicate an
166  // invalid/uninitialized position value.
167  static const int kNoPosition = -1;
168 
169  // This string is used to add padding comments to the reloc info in cases
170  // where we are not sure to have enough space for patching in during
171  // lazy deoptimization. This is the case if we have indirect calls for which
172  // we do not normally record relocation info.
173  static const char* const kFillerCommentString;
174 
175  // The minimum size of a comment is equal to three bytes for the extra tagged
176  // pc + the tag for the data, and kPointerSize for the actual pointer to the
177  // comment.
178  static const int kMinRelocCommentSize = 3 + kPointerSize;
179 
180  // The maximum size for a call instruction including pc-jump.
181  static const int kMaxCallSize = 6;
182 
183  // The maximum pc delta that will use the short encoding.
184  static const int kMaxSmallPCDelta;
185 
186  enum Mode {
187  // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
188  CODE_TARGET, // Code target which is not any of the above.
190  CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
191  CODE_TARGET_CONTEXT, // Code target used for contextual loads and stores.
192  DEBUG_BREAK, // Code target for the debugger statement.
195 
196  // Everything after runtime_entry (inclusive) is not GC'ed.
198  JS_RETURN, // Marks start of the ExitJSFrame code.
200  POSITION, // See comment for kNoPosition above.
201  STATEMENT_POSITION, // See comment for kNoPosition above.
202  DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
203  EXTERNAL_REFERENCE, // The address of an external C++ function.
204  INTERNAL_REFERENCE, // An address inside the same function.
205 
206  // Marks a constant pool. Only used on ARM.
207  // It uses a custom noncompact encoding.
209 
210  // add more as needed
211  // Pseudo-types
212  NUMBER_OF_MODES, // There are at most 15 modes with noncompact encoding.
213  NONE, // never recorded
214  LAST_CODE_ENUM = DEBUG_BREAK,
215  LAST_GCED_ENUM = GLOBAL_PROPERTY_CELL,
216  // Modes <= LAST_COMPACT_ENUM are guaranteed to have compact encoding.
217  LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID,
218  LAST_STANDARD_NONCOMPACT_ENUM = INTERNAL_REFERENCE
219  };
220 
221 
223 
224  RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host)
225  : pc_(pc), rmode_(rmode), data_(data), host_(host) {
226  }
227 
228  static inline bool IsConstructCall(Mode mode) {
229  return mode == CONSTRUCT_CALL;
230  }
231  static inline bool IsCodeTarget(Mode mode) {
232  return mode <= LAST_CODE_ENUM;
233  }
234  static inline bool IsEmbeddedObject(Mode mode) {
235  return mode == EMBEDDED_OBJECT;
236  }
237  // Is the relocation mode affected by GC?
238  static inline bool IsGCRelocMode(Mode mode) {
239  return mode <= LAST_GCED_ENUM;
240  }
241  static inline bool IsJSReturn(Mode mode) {
242  return mode == JS_RETURN;
243  }
244  static inline bool IsComment(Mode mode) {
245  return mode == COMMENT;
246  }
247  static inline bool IsConstPool(Mode mode) {
248  return mode == CONST_POOL;
249  }
250  static inline bool IsPosition(Mode mode) {
251  return mode == POSITION || mode == STATEMENT_POSITION;
252  }
253  static inline bool IsStatementPosition(Mode mode) {
254  return mode == STATEMENT_POSITION;
255  }
256  static inline bool IsExternalReference(Mode mode) {
257  return mode == EXTERNAL_REFERENCE;
258  }
259  static inline bool IsInternalReference(Mode mode) {
260  return mode == INTERNAL_REFERENCE;
261  }
262  static inline bool IsDebugBreakSlot(Mode mode) {
263  return mode == DEBUG_BREAK_SLOT;
264  }
265  static inline int ModeMask(Mode mode) { return 1 << mode; }
266 
267  // Accessors
268  byte* pc() const { return pc_; }
269  void set_pc(byte* pc) { pc_ = pc; }
270  Mode rmode() const { return rmode_; }
271  intptr_t data() const { return data_; }
272  Code* host() const { return host_; }
273 
274  // Apply a relocation by delta bytes
275  INLINE(void apply(intptr_t delta));
276 
277  // Is the pointer this relocation info refers to coded like a plain pointer
278  // or is it strange in some way (e.g. relative or patched into a series of
279  // instructions).
280  bool IsCodedSpecially();
281 
282  // Read/modify the code target in the branch/call instruction
283  // this relocation applies to;
284  // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
285  INLINE(Address target_address());
286  INLINE(void set_target_address(Address target,
288  INLINE(Object* target_object());
289  INLINE(Handle<Object> target_object_handle(Assembler* origin));
290  INLINE(Object** target_object_address());
291  INLINE(void set_target_object(Object* target,
293  INLINE(JSGlobalPropertyCell* target_cell());
294  INLINE(Handle<JSGlobalPropertyCell> target_cell_handle());
295  INLINE(void set_target_cell(JSGlobalPropertyCell* cell,
297 
298 
299  // Read the address of the word containing the target_address in an
300  // instruction stream. What this means exactly is architecture-independent.
301  // The only architecture-independent user of this function is the serializer.
302  // The serializer uses it to find out how many raw bytes of instruction to
303  // output before the next target. Architecture-independent code shouldn't
304  // dereference the pointer it gets back from this.
305  INLINE(Address target_address_address());
306  // This indicates how much space a target takes up when deserializing a code
307  // stream. For most architectures this is just the size of a pointer. For
308  // an instruction like movw/movt where the target bits are mixed into the
309  // instruction bits the size of the target will be zero, indicating that the
310  // serializer should not step forwards in memory after a target is resolved
311  // and written. In this case the target_address_address function above
312  // should return the end of the instructions to be patched, allowing the
313  // deserializer to deserialize the instructions as raw bytes and put them in
314  // place, ready to be patched with the target.
315  INLINE(int target_address_size());
316 
317  // Read/modify the reference in the instruction this relocation
318  // applies to; can only be called if rmode_ is external_reference
319  INLINE(Address* target_reference_address());
320 
321  // Read/modify the address of a call instruction. This is used to relocate
322  // the break points where straight-line code is patched with a call
323  // instruction.
324  INLINE(Address call_address());
325  INLINE(void set_call_address(Address target));
326  INLINE(Object* call_object());
327  INLINE(void set_call_object(Object* target));
328  INLINE(Object** call_object_address());
329 
330  template<typename StaticVisitor> inline void Visit(Heap* heap);
331  inline void Visit(ObjectVisitor* v);
332 
333  // Patch the code with some other code.
334  void PatchCode(byte* instructions, int instruction_count);
335 
336  // Patch the code with a call.
337  void PatchCodeWithCall(Address target, int guard_bytes);
338 
339  // Check whether this return sequence has been patched
340  // with a call to the debugger.
341  INLINE(bool IsPatchedReturnSequence());
342 
343  // Check whether this debug break slot has been patched with a call to the
344  // debugger.
345  INLINE(bool IsPatchedDebugBreakSlotSequence());
346 
347 #ifdef ENABLE_DISASSEMBLER
348  // Printing
349  static const char* RelocModeName(Mode rmode);
350  void Print(FILE* out);
351 #endif // ENABLE_DISASSEMBLER
352 #ifdef VERIFY_HEAP
353  void Verify();
354 #endif
355 
356  static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
357  static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
358  static const int kDataMask =
359  (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
360  static const int kApplyMask; // Modes affected by apply. Depends on arch.
361 
362  private:
363  // On ARM, note that pc_ is the address of the constant pool entry
364  // to be relocated and not the address of the instruction
365  // referencing the constant pool entry (except when rmode_ ==
366  // comment).
367  byte* pc_;
368  Mode rmode_;
369  intptr_t data_;
370  Code* host_;
371  // Code and Embedded Object pointers on some platforms are stored split
372  // across two consecutive 32-bit instructions. Heap management
373  // routines expect to access these pointers indirectly. The following
374  // location provides a place for these pointers to exist naturally
375  // when accessed via the Iterator.
376  Object* reconstructed_obj_ptr_;
377  // External-reference pointers are also split across instruction-pairs
378  // on some platforms, but are accessed via indirect pointers. This location
379  // provides a place for that pointer to exist naturally. Its address
380  // is returned by RelocInfo::target_reference_address().
381  Address reconstructed_adr_ptr_;
382  friend class RelocIterator;
383 };
384 
385 
386 // RelocInfoWriter serializes a stream of relocation info. It writes towards
387 // lower addresses.
388 class RelocInfoWriter BASE_EMBEDDED {
389  public:
391  last_pc_(NULL),
392  last_id_(0),
393  last_position_(0) {}
394  RelocInfoWriter(byte* pos, byte* pc) : pos_(pos),
395  last_pc_(pc),
396  last_id_(0),
397  last_position_(0) {}
398 
399  byte* pos() const { return pos_; }
400  byte* last_pc() const { return last_pc_; }
401 
402  void Write(const RelocInfo* rinfo);
403 
404  // Update the state of the stream after reloc info buffer
405  // and/or code is moved while the stream is active.
406  void Reposition(byte* pos, byte* pc) {
407  pos_ = pos;
408  last_pc_ = pc;
409  }
410 
411  // Max size (bytes) of a written RelocInfo. Longest encoding is
412  // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
413  // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
414  // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
415  // Here we use the maximum of the two.
416  static const int kMaxSize = 16;
417 
418  private:
419  inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
420  inline void WriteTaggedPC(uint32_t pc_delta, int tag);
421  inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
422  inline void WriteExtraTaggedIntData(int data_delta, int top_tag);
423  inline void WriteExtraTaggedConstPoolData(int data);
424  inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
425  inline void WriteTaggedData(intptr_t data_delta, int tag);
426  inline void WriteExtraTag(int extra_tag, int top_tag);
427 
428  byte* pos_;
429  byte* last_pc_;
430  int last_id_;
431  int last_position_;
432  DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
433 };
434 
435 
436 // A RelocIterator iterates over relocation information.
437 // Typical use:
438 //
439 // for (RelocIterator it(code); !it.done(); it.next()) {
440 // // do something with it.rinfo() here
441 // }
442 //
443 // A mask can be specified to skip unwanted modes.
444 class RelocIterator: public Malloced {
445  public:
446  // Create a new iterator positioned at
447  // the beginning of the reloc info.
448  // Relocation information with mode k is included in the
449  // iteration iff bit k of mode_mask is set.
450  explicit RelocIterator(Code* code, int mode_mask = -1);
451  explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
452 
453  // Iteration
454  bool done() const { return done_; }
455  void next();
456 
457  // Return pointer valid until next next().
458  RelocInfo* rinfo() {
459  ASSERT(!done());
460  return &rinfo_;
461  }
462 
463  private:
464  // Advance* moves the position before/after reading.
465  // *Read* reads from current byte(s) into rinfo_.
466  // *Get* just reads and returns info on current byte.
467  void Advance(int bytes = 1) { pos_ -= bytes; }
468  int AdvanceGetTag();
469  int GetExtraTag();
470  int GetTopTag();
471  void ReadTaggedPC();
472  void AdvanceReadPC();
473  void AdvanceReadId();
474  void AdvanceReadConstPoolData();
475  void AdvanceReadPosition();
476  void AdvanceReadData();
477  void AdvanceReadVariableLengthPCJump();
478  int GetLocatableTypeTag();
479  void ReadTaggedId();
480  void ReadTaggedPosition();
481 
482  // If the given mode is wanted, set it in rinfo_ and return true.
483  // Else return false. Used for efficiently skipping unwanted modes.
484  bool SetMode(RelocInfo::Mode mode) {
485  return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
486  }
487 
488  byte* pos_;
489  byte* end_;
490  RelocInfo rinfo_;
491  bool done_;
492  int mode_mask_;
493  int last_id_;
494  int last_position_;
495  DISALLOW_COPY_AND_ASSIGN(RelocIterator);
496 };
497 
498 
499 //------------------------------------------------------------------------------
500 // External function
501 
502 //----------------------------------------------------------------------------
503 class IC_Utility;
504 class SCTableReference;
505 #ifdef ENABLE_DEBUGGER_SUPPORT
506 class Debug_Address;
507 #endif
508 
509 
510 // An ExternalReference represents a C++ address used in the generated
511 // code. All references to C++ functions and variables must be encapsulated in
512 // an ExternalReference instance. This is done in order to track the origin of
513 // all external references in the code so that they can be bound to the correct
514 // addresses when deserializing a heap.
515 class ExternalReference BASE_EMBEDDED {
516  public:
517  // Used in the simulator to support different native api calls.
518  enum Type {
519  // Builtin call.
520  // MaybeObject* f(v8::internal::Arguments).
521  BUILTIN_CALL, // default
522 
523  // Builtin that takes float arguments and returns an int.
524  // int f(double, double).
526 
527  // Builtin call that returns floating point.
528  // double f(double, double).
530 
531  // Builtin call that returns floating point.
532  // double f(double).
534 
535  // Builtin call that returns floating point.
536  // double f(double, int).
538 
539  // Direct call to API function callback.
540  // Handle<Value> f(v8::Arguments&)
542 
543  // Direct call to accessor getter callback.
544  // Handle<value> f(Local<String> property, AccessorInfo& info)
545  DIRECT_GETTER_CALL
546  };
547 
548  static void SetUp();
549 
550  typedef void* ExternalReferenceRedirector(void* original, Type type);
551 
552  ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
553 
554  ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
555 
556  ExternalReference(Builtins::Name name, Isolate* isolate);
557 
558  ExternalReference(Runtime::FunctionId id, Isolate* isolate);
559 
560  ExternalReference(const Runtime::Function* f, Isolate* isolate);
561 
562  ExternalReference(const IC_Utility& ic_utility, Isolate* isolate);
563 
564 #ifdef ENABLE_DEBUGGER_SUPPORT
565  ExternalReference(const Debug_Address& debug_address, Isolate* isolate);
566 #endif
567 
568  explicit ExternalReference(StatsCounter* counter);
569 
570  ExternalReference(Isolate::AddressId id, Isolate* isolate);
571 
572  explicit ExternalReference(const SCTableReference& table_ref);
573 
574  // Isolate::Current() as an external reference.
575  static ExternalReference isolate_address();
576 
577  // One-of-a-kind references. These references are not part of a general
578  // pattern. This means that they have to be added to the
579  // ExternalReferenceTable in serialize.cc manually.
580 
581  static ExternalReference incremental_marking_record_write_function(
582  Isolate* isolate);
583  static ExternalReference incremental_evacuation_record_write_function(
584  Isolate* isolate);
585  static ExternalReference store_buffer_overflow_function(
586  Isolate* isolate);
587  static ExternalReference flush_icache_function(Isolate* isolate);
588  static ExternalReference perform_gc_function(Isolate* isolate);
589  static ExternalReference fill_heap_number_with_random_function(
590  Isolate* isolate);
591  static ExternalReference random_uint32_function(Isolate* isolate);
592  static ExternalReference transcendental_cache_array_address(Isolate* isolate);
593  static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
594 
595  static ExternalReference get_date_field_function(Isolate* isolate);
596  static ExternalReference date_cache_stamp(Isolate* isolate);
597 
598  // Deoptimization support.
599  static ExternalReference new_deoptimizer_function(Isolate* isolate);
600  static ExternalReference compute_output_frames_function(Isolate* isolate);
601 
602  // Static data in the keyed lookup cache.
603  static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
604  static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
605 
606  // Static variable Heap::roots_array_start()
607  static ExternalReference roots_array_start(Isolate* isolate);
608 
609  // Static variable StackGuard::address_of_jslimit()
610  static ExternalReference address_of_stack_limit(Isolate* isolate);
611 
612  // Static variable StackGuard::address_of_real_jslimit()
613  static ExternalReference address_of_real_stack_limit(Isolate* isolate);
614 
615  // Static variable RegExpStack::limit_address()
616  static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
617 
618  // Static variables for RegExp.
619  static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
620  static ExternalReference address_of_regexp_stack_memory_address(
621  Isolate* isolate);
622  static ExternalReference address_of_regexp_stack_memory_size(
623  Isolate* isolate);
624 
625  // Static variable Heap::NewSpaceStart()
626  static ExternalReference new_space_start(Isolate* isolate);
627  static ExternalReference new_space_mask(Isolate* isolate);
628  static ExternalReference heap_always_allocate_scope_depth(Isolate* isolate);
629  static ExternalReference new_space_mark_bits(Isolate* isolate);
630 
631  // Write barrier.
632  static ExternalReference store_buffer_top(Isolate* isolate);
633 
634  // Used for fast allocation in generated code.
635  static ExternalReference new_space_allocation_top_address(Isolate* isolate);
636  static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
637 
638  static ExternalReference double_fp_operation(Token::Value operation,
639  Isolate* isolate);
640  static ExternalReference compare_doubles(Isolate* isolate);
641  static ExternalReference power_double_double_function(Isolate* isolate);
642  static ExternalReference power_double_int_function(Isolate* isolate);
643 
644  static ExternalReference handle_scope_next_address();
645  static ExternalReference handle_scope_limit_address();
646  static ExternalReference handle_scope_level_address();
647 
648  static ExternalReference scheduled_exception_address(Isolate* isolate);
649  static ExternalReference address_of_pending_message_obj(Isolate* isolate);
650  static ExternalReference address_of_has_pending_message(Isolate* isolate);
651  static ExternalReference address_of_pending_message_script(Isolate* isolate);
652 
653  // Static variables containing common double constants.
654  static ExternalReference address_of_min_int();
655  static ExternalReference address_of_one_half();
656  static ExternalReference address_of_minus_zero();
657  static ExternalReference address_of_zero();
658  static ExternalReference address_of_uint8_max_value();
659  static ExternalReference address_of_negative_infinity();
660  static ExternalReference address_of_canonical_non_hole_nan();
661  static ExternalReference address_of_the_hole_nan();
662 
663  static ExternalReference math_sin_double_function(Isolate* isolate);
664  static ExternalReference math_cos_double_function(Isolate* isolate);
665  static ExternalReference math_tan_double_function(Isolate* isolate);
666  static ExternalReference math_log_double_function(Isolate* isolate);
667 
668  static ExternalReference page_flags(Page* page);
669 
670  Address address() const {return reinterpret_cast<Address>(address_);}
671 
672 #ifdef ENABLE_DEBUGGER_SUPPORT
673  // Function Debug::Break()
674  static ExternalReference debug_break(Isolate* isolate);
675 
676  // Used to check if single stepping is enabled in generated code.
677  static ExternalReference debug_step_in_fp_address(Isolate* isolate);
678 #endif
679 
680 #ifndef V8_INTERPRETED_REGEXP
681  // C functions called from RegExp generated code.
682 
683  // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
684  static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
685 
686  // Function RegExpMacroAssembler*::CheckStackGuardState()
687  static ExternalReference re_check_stack_guard_state(Isolate* isolate);
688 
689  // Function NativeRegExpMacroAssembler::GrowStack()
690  static ExternalReference re_grow_stack(Isolate* isolate);
691 
692  // byte NativeRegExpMacroAssembler::word_character_bitmap
693  static ExternalReference re_word_character_map();
694 
695 #endif
696 
697  // This lets you register a function that rewrites all external references.
698  // Used by the ARM simulator to catch calls to external references.
699  static void set_redirector(Isolate* isolate,
700  ExternalReferenceRedirector* redirector) {
701  // We can't stack them.
702  ASSERT(isolate->external_reference_redirector() == NULL);
703  isolate->set_external_reference_redirector(
704  reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
705  }
706 
707  private:
708  explicit ExternalReference(void* address)
709  : address_(address) {}
710 
711  static void* Redirect(Isolate* isolate,
712  void* address,
713  Type type = ExternalReference::BUILTIN_CALL) {
714  ExternalReferenceRedirector* redirector =
715  reinterpret_cast<ExternalReferenceRedirector*>(
716  isolate->external_reference_redirector());
717  if (redirector == NULL) return address;
718  void* answer = (*redirector)(address, type);
719  return answer;
720  }
721 
722  static void* Redirect(Isolate* isolate,
723  Address address_arg,
724  Type type = ExternalReference::BUILTIN_CALL) {
725  ExternalReferenceRedirector* redirector =
726  reinterpret_cast<ExternalReferenceRedirector*>(
727  isolate->external_reference_redirector());
728  void* address = reinterpret_cast<void*>(address_arg);
729  void* answer = (redirector == NULL) ?
730  address :
731  (*redirector)(address, type);
732  return answer;
733  }
734 
735  void* address_;
736 };
737 
738 
739 // -----------------------------------------------------------------------------
740 // Position recording support
741 
743  PositionState() : current_position(RelocInfo::kNoPosition),
744  written_position(RelocInfo::kNoPosition),
745  current_statement_position(RelocInfo::kNoPosition),
746  written_statement_position(RelocInfo::kNoPosition) {}
747 
750 
753 };
754 
755 
756 class PositionsRecorder BASE_EMBEDDED {
757  public:
758  explicit PositionsRecorder(Assembler* assembler)
759  : assembler_(assembler) {
760 #ifdef ENABLE_GDB_JIT_INTERFACE
761  gdbjit_lineinfo_ = NULL;
762 #endif
763  }
764 
765 #ifdef ENABLE_GDB_JIT_INTERFACE
766  ~PositionsRecorder() {
767  delete gdbjit_lineinfo_;
768  }
769 
770  void StartGDBJITLineInfoRecording() {
771  if (FLAG_gdbjit) {
772  gdbjit_lineinfo_ = new GDBJITLineInfo();
773  }
774  }
775 
776  GDBJITLineInfo* DetachGDBJITLineInfo() {
777  GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
778  gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
779  return lineinfo;
780  }
781 #endif
782 
783  // Set current position to pos.
784  void RecordPosition(int pos);
785 
786  // Set current statement position to pos.
787  void RecordStatementPosition(int pos);
788 
789  // Write recorded positions to relocation information.
790  bool WriteRecordedPositions();
791 
792  int current_position() const { return state_.current_position; }
793 
795  return state_.current_statement_position;
796  }
797 
798  private:
799  Assembler* assembler_;
800  PositionState state_;
801 #ifdef ENABLE_GDB_JIT_INTERFACE
802  GDBJITLineInfo* gdbjit_lineinfo_;
803 #endif
804 
805  friend class PreservePositionScope;
806 
807  DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
808 };
809 
810 
811 class PreservePositionScope BASE_EMBEDDED {
812  public:
813  explicit PreservePositionScope(PositionsRecorder* positions_recorder)
814  : positions_recorder_(positions_recorder),
815  saved_state_(positions_recorder->state_) {}
816 
818  positions_recorder_->state_ = saved_state_;
819  }
820 
821  private:
822  PositionsRecorder* positions_recorder_;
823  const PositionState saved_state_;
824 
825  DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
826 };
827 
828 
829 // -----------------------------------------------------------------------------
830 // Utility functions
831 
832 inline bool is_intn(int x, int n) {
833  return -(1 << (n-1)) <= x && x < (1 << (n-1));
834 }
835 
836 inline bool is_int8(int x) { return is_intn(x, 8); }
837 inline bool is_int16(int x) { return is_intn(x, 16); }
838 inline bool is_int18(int x) { return is_intn(x, 18); }
839 inline bool is_int24(int x) { return is_intn(x, 24); }
840 
841 inline bool is_uintn(int x, int n) {
842  return (x & -(1 << n)) == 0;
843 }
844 
845 inline bool is_uint2(int x) { return is_uintn(x, 2); }
846 inline bool is_uint3(int x) { return is_uintn(x, 3); }
847 inline bool is_uint4(int x) { return is_uintn(x, 4); }
848 inline bool is_uint5(int x) { return is_uintn(x, 5); }
849 inline bool is_uint6(int x) { return is_uintn(x, 6); }
850 inline bool is_uint8(int x) { return is_uintn(x, 8); }
851 inline bool is_uint10(int x) { return is_uintn(x, 10); }
852 inline bool is_uint12(int x) { return is_uintn(x, 12); }
853 inline bool is_uint16(int x) { return is_uintn(x, 16); }
854 inline bool is_uint24(int x) { return is_uintn(x, 24); }
855 inline bool is_uint26(int x) { return is_uintn(x, 26); }
856 inline bool is_uint28(int x) { return is_uintn(x, 28); }
857 
858 inline int NumberOfBitsSet(uint32_t x) {
859  unsigned int num_bits_set;
860  for (num_bits_set = 0; x; x >>= 1) {
861  num_bits_set += x & 1;
862  }
863  return num_bits_set;
864 }
865 
866 bool EvalComparison(Token::Value op, double op1, double op2);
867 
868 // Computes pow(x, y) with the special cases in the spec for Math.pow.
869 double power_double_int(double x, int y);
870 double power_double_double(double x, double y);
871 
872 // Helper class for generating code or data associated with the code
873 // right after a call instruction. As an example this can be used to
874 // generate safepoint data after calls for crankshaft.
875 class CallWrapper {
876  public:
878  virtual ~CallWrapper() { }
879  // Called just before emitting a call. Argument is the size of the generated
880  // call code.
881  virtual void BeforeCall(int call_size) const = 0;
882  // Called just after emitting a call, i.e., at the return site for the call.
883  virtual void AfterCall() const = 0;
884 };
885 
886 class NullCallWrapper : public CallWrapper {
887  public:
889  virtual ~NullCallWrapper() { }
890  virtual void BeforeCall(int call_size) const { }
891  virtual void AfterCall() const { }
892 };
893 
894 } } // namespace v8::internal
895 
896 #endif // V8_ASSEMBLER_H_
byte * Address
Definition: globals.h:157
RelocIterator(Code *code, int mode_mask=-1)
Definition: assembler.cc:577
static bool IsDebugBreakSlot(Mode mode)
Definition: assembler.h:262
Isolate * isolate() const
Definition: assembler.h:61
bool is_int24(int x)
Definition: assembler.h:839
int near_link_pos() const
Definition: assembler.h:107
static bool IsExternalReference(Mode mode)
Definition: assembler.h:256
RelocInfo(byte *pc, Mode rmode, intptr_t data, Code *host)
Definition: assembler.h:224
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 instructions(ARM only)") DEFINE_bool(enable_vfp2
bool is_intn(int x, int n)
Definition: assembler.h:832
virtual void BeforeCall(int call_size) const =0
bool is_int18(int x)
Definition: assembler.h:838
bool is_uint26(int x)
Definition: assembler.h:855
static void set_redirector(Isolate *isolate, ExternalReferenceRedirector *redirector)
Definition: assembler.h:699
PositionsRecorder(Assembler *assembler)
Definition: assembler.h:758
byte * last_pc() const
Definition: assembler.h:400
bool is_uint10(int x)
Definition: assembler.h:851
void * ExternalReferenceRedirector(void *original, Type type)
Definition: assembler.h:550
int current_statement_position() const
Definition: assembler.h:794
bool is_uint3(int x)
Definition: assembler.h:846
bool is_int8(int x)
Definition: assembler.h:836
bool is_uint24(int x)
Definition: assembler.h:854
#define ASSERT(condition)
Definition: checks.h:270
v8::Handle< v8::Value > Print(const v8::Arguments &args)
bool is_uint6(int x)
Definition: assembler.h:849
static bool IsComment(Mode mode)
Definition: assembler.h:244
Code * host() const
Definition: assembler.h:272
static void QuietNaN(HeapObject *nan)
Definition: assembler.h:66
bool is_uint12(int x)
Definition: assembler.h:852
uint8_t byte
Definition: globals.h:156
void Reposition(byte *pos, byte *pc)
Definition: assembler.h:406
PreservePositionScope(PositionsRecorder *positions_recorder)
Definition: assembler.h:813
static bool IsConstPool(Mode mode)
Definition: assembler.h:247
static const int kApplyMask
Definition: assembler.h:360
const int kPointerSize
Definition: globals.h:220
double power_double_double(double x, double y)
Definition: assembler.cc:1214
bool is_uint5(int x)
Definition: assembler.h:848
bool is_uint16(int x)
Definition: assembler.h:853
virtual void AfterCall() const
Definition: assembler.h:891
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: globals.h:307
static bool IsJSReturn(Mode mode)
Definition: assembler.h:241
const Register pc
static const int kMaxSmallPCDelta
Definition: assembler.h:184
double power_double_int(double x, int y)
Definition: assembler.cc:1199
#define BASE_EMBEDDED
Definition: allocation.h:68
static bool IsStatementPosition(Mode mode)
Definition: assembler.h:253
static bool IsEmbeddedObject(Mode mode)
Definition: assembler.h:234
INLINE(bool is_near_linked() const)
Definition: assembler.h:102
AssemblerBase(Isolate *isolate)
Definition: assembler.cc:109
bool is_uint2(int x)
Definition: assembler.h:845
static bool IsPosition(Mode mode)
Definition: assembler.h:250
bool is_int16(int x)
Definition: assembler.h:837
INLINE(static HeapObject *EnsureDoubleAligned(Heap *heap, HeapObject *object, int size))
static bool IsGCRelocMode(Mode mode)
Definition: assembler.h:238
static int ModeMask(Mode mode)
Definition: assembler.h:265
static bool IsCodeTarget(Mode mode)
Definition: assembler.h:231
static bool IsInternalReference(Mode mode)
Definition: assembler.h:259
RelocInfoWriter(byte *pos, byte *pc)
Definition: assembler.h:394
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
Definition: flags.cc:301
static bool IsConstructCall(Mode mode)
Definition: assembler.h:228
virtual void AfterCall() const =0
INLINE(bool is_unused() const)
Definition: assembler.h:100
bool is_uint28(int x)
Definition: assembler.h:856
bool is_uint8(int x)
Definition: assembler.h:850
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
Address address() const
Definition: assembler.h:670
virtual void BeforeCall(int call_size) const
Definition: assembler.h:890
INLINE(void UnuseNear())
Definition: assembler.h:97
int NumberOfBitsSet(uint32_t x)
Definition: assembler.h:858
INLINE(bool is_linked() const)
Definition: assembler.h:101
intptr_t data() const
Definition: assembler.h:271
bool EvalComparison(Token::Value op, double op1, double op2)
Definition: assembler.cc:1258
bool is_uintn(int x, int n)
Definition: assembler.h:841
int current_position() const
Definition: assembler.h:792
INLINE(bool is_bound() const)
Definition: assembler.h:99
static const char *const kFillerCommentString
Definition: assembler.h:173
bool is_uint4(int x)
Definition: assembler.h:847