blob: 4ef61e4b1402a7bc2c0e5ec0c8922a575b144236 [file] [log] [blame]
Steve Blocka7e24c12009-10-30 11:49:00 +00001// Copyright (c) 1994-2006 Sun Microsystems Inc.
2// All Rights Reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// - Redistributions of source code must retain the above copyright notice,
9// this list of conditions and the following disclaimer.
10//
11// - Redistribution in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// - Neither the name of Sun Microsystems or the names of contributors may
16// be used to endorse or promote products derived from this software without
17// specific prior written permission.
18//
19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31// The original source code covered by the above license above has been
32// modified significantly by Google Inc.
33// Copyright 2006-2009 the V8 project authors. All rights reserved.
34
35#ifndef V8_ASSEMBLER_H_
36#define V8_ASSEMBLER_H_
37
Ben Murdochb8e0da22011-05-16 14:20:40 +010038#include "gdb-jit.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000039#include "runtime.h"
40#include "top.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000041#include "token.h"
42
43namespace v8 {
44namespace internal {
45
46
47// -----------------------------------------------------------------------------
Ben Murdochb0fe1622011-05-05 13:52:32 +010048// Common double constants.
49
50class DoubleConstant: public AllStatic {
51 public:
52 static const double min_int;
53 static const double one_half;
Ben Murdochb8e0da22011-05-16 14:20:40 +010054 static const double minus_zero;
Ben Murdochb0fe1622011-05-05 13:52:32 +010055 static const double negative_infinity;
56};
57
58
59// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +000060// Labels represent pc locations; they are typically jump or call targets.
61// After declaration, a label can be freely used to denote known or (yet)
62// unknown pc location. Assembler::bind() is used to bind a label to the
63// current pc. A label can be bound only once.
64
65class Label BASE_EMBEDDED {
66 public:
67 INLINE(Label()) { Unuse(); }
68 INLINE(~Label()) { ASSERT(!is_linked()); }
69
70 INLINE(void Unuse()) { pos_ = 0; }
71
Kristian Monsen0d5e1162010-09-30 15:31:59 +010072 INLINE(bool is_bound() const) { return pos_ < 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +000073 INLINE(bool is_unused() const) { return pos_ == 0; }
74 INLINE(bool is_linked() const) { return pos_ > 0; }
75
76 // Returns the position of bound or linked labels. Cannot be used
77 // for unused labels.
78 int pos() const;
79
80 private:
81 // pos_ encodes both the binding state (via its sign)
82 // and the binding position (via its value) of a label.
83 //
84 // pos_ < 0 bound label, pos() returns the jump target position
85 // pos_ == 0 unused label
86 // pos_ > 0 linked label, pos() returns the last reference position
87 int pos_;
88
89 void bind_to(int pos) {
90 pos_ = -pos - 1;
91 ASSERT(is_bound());
92 }
93 void link_to(int pos) {
94 pos_ = pos + 1;
95 ASSERT(is_linked());
96 }
97
98 friend class Assembler;
99 friend class RegexpAssembler;
100 friend class Displacement;
101 friend class ShadowTarget;
102 friend class RegExpMacroAssemblerIrregexp;
103};
104
105
106// -----------------------------------------------------------------------------
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100107// NearLabels are labels used for short jumps (in Intel jargon).
108// NearLabels should be used if it can be guaranteed that the jump range is
109// within -128 to +127. We already use short jumps when jumping backwards,
110// so using a NearLabel will only have performance impact if used for forward
111// jumps.
112class NearLabel BASE_EMBEDDED {
113 public:
114 NearLabel() { Unuse(); }
115 ~NearLabel() { ASSERT(!is_linked()); }
116
117 void Unuse() {
118 pos_ = -1;
119 unresolved_branches_ = 0;
120#ifdef DEBUG
121 for (int i = 0; i < kMaxUnresolvedBranches; i++) {
122 unresolved_positions_[i] = -1;
123 }
124#endif
125 }
126
127 int pos() {
128 ASSERT(is_bound());
129 return pos_;
130 }
131
132 bool is_bound() { return pos_ >= 0; }
133 bool is_linked() { return !is_bound() && unresolved_branches_ > 0; }
134 bool is_unused() { return !is_bound() && unresolved_branches_ == 0; }
135
136 void bind_to(int position) {
137 ASSERT(!is_bound());
138 pos_ = position;
139 }
140
141 void link_to(int position) {
142 ASSERT(!is_bound());
143 ASSERT(unresolved_branches_ < kMaxUnresolvedBranches);
144 unresolved_positions_[unresolved_branches_++] = position;
145 }
146
147 private:
148 static const int kMaxUnresolvedBranches = 8;
149 int pos_;
150 int unresolved_branches_;
151 int unresolved_positions_[kMaxUnresolvedBranches];
152
153 friend class Assembler;
154};
155
156
157// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000158// Relocation information
159
160
161// Relocation information consists of the address (pc) of the datum
162// to which the relocation information applies, the relocation mode
163// (rmode), and an optional data field. The relocation mode may be
164// "descriptive" and not indicate a need for relocation, but simply
165// describe a property of the datum. Such rmodes are useful for GC
166// and nice disassembly output.
167
168class RelocInfo BASE_EMBEDDED {
169 public:
170 // The constant kNoPosition is used with the collecting of source positions
171 // in the relocation information. Two types of source positions are collected
172 // "position" (RelocMode position) and "statement position" (RelocMode
173 // statement_position). The "position" is collected at places in the source
174 // code which are of interest when making stack traces to pin-point the source
175 // location of a stack frame as close as possible. The "statement position" is
176 // collected at the beginning at each statement, and is used to indicate
177 // possible break locations. kNoPosition is used to indicate an
178 // invalid/uninitialized position value.
179 static const int kNoPosition = -1;
180
181 enum Mode {
182 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
183 CONSTRUCT_CALL, // code target that is a call to a JavaScript constructor.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100184 CODE_TARGET_CONTEXT, // Code target used for contextual loads.
185 DEBUG_BREAK, // Code target for the debugger statement.
186 CODE_TARGET, // Code target which is not any of the above.
Steve Blocka7e24c12009-10-30 11:49:00 +0000187 EMBEDDED_OBJECT,
Steve Blocka7e24c12009-10-30 11:49:00 +0000188
Ben Murdochb0fe1622011-05-05 13:52:32 +0100189 GLOBAL_PROPERTY_CELL,
190
Steve Blocka7e24c12009-10-30 11:49:00 +0000191 // Everything after runtime_entry (inclusive) is not GC'ed.
192 RUNTIME_ENTRY,
193 JS_RETURN, // Marks start of the ExitJSFrame code.
194 COMMENT,
195 POSITION, // See comment for kNoPosition above.
196 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100197 DEBUG_BREAK_SLOT, // Additional code inserted for debug break slot.
Steve Blocka7e24c12009-10-30 11:49:00 +0000198 EXTERNAL_REFERENCE, // The address of an external C++ function.
199 INTERNAL_REFERENCE, // An address inside the same function.
200
201 // add more as needed
202 // Pseudo-types
203 NUMBER_OF_MODES, // must be no greater than 14 - see RelocInfoWriter
204 NONE, // never recorded
205 LAST_CODE_ENUM = CODE_TARGET,
Leon Clarkef7060e22010-06-03 12:02:55 +0100206 LAST_GCED_ENUM = EMBEDDED_OBJECT
Steve Blocka7e24c12009-10-30 11:49:00 +0000207 };
208
209
210 RelocInfo() {}
211 RelocInfo(byte* pc, Mode rmode, intptr_t data)
212 : pc_(pc), rmode_(rmode), data_(data) {
213 }
214
215 static inline bool IsConstructCall(Mode mode) {
216 return mode == CONSTRUCT_CALL;
217 }
218 static inline bool IsCodeTarget(Mode mode) {
219 return mode <= LAST_CODE_ENUM;
220 }
221 // Is the relocation mode affected by GC?
222 static inline bool IsGCRelocMode(Mode mode) {
223 return mode <= LAST_GCED_ENUM;
224 }
225 static inline bool IsJSReturn(Mode mode) {
226 return mode == JS_RETURN;
227 }
228 static inline bool IsComment(Mode mode) {
229 return mode == COMMENT;
230 }
231 static inline bool IsPosition(Mode mode) {
232 return mode == POSITION || mode == STATEMENT_POSITION;
233 }
234 static inline bool IsStatementPosition(Mode mode) {
235 return mode == STATEMENT_POSITION;
236 }
237 static inline bool IsExternalReference(Mode mode) {
238 return mode == EXTERNAL_REFERENCE;
239 }
240 static inline bool IsInternalReference(Mode mode) {
241 return mode == INTERNAL_REFERENCE;
242 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100243 static inline bool IsDebugBreakSlot(Mode mode) {
244 return mode == DEBUG_BREAK_SLOT;
245 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000246 static inline int ModeMask(Mode mode) { return 1 << mode; }
247
248 // Accessors
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100249 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000250 void set_pc(byte* pc) { pc_ = pc; }
251 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100252 intptr_t data() const { return data_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000253
254 // Apply a relocation by delta bytes
255 INLINE(void apply(intptr_t delta));
256
Leon Clarkef7060e22010-06-03 12:02:55 +0100257 // Is the pointer this relocation info refers to coded like a plain pointer
258 // or is it strange in some way (eg relative or patched into a series of
259 // instructions).
260 bool IsCodedSpecially();
261
Steve Blocka7e24c12009-10-30 11:49:00 +0000262 // Read/modify the code target in the branch/call instruction
263 // this relocation applies to;
264 // can only be called if IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY
265 INLINE(Address target_address());
266 INLINE(void set_target_address(Address target));
267 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000268 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Steve Blocka7e24c12009-10-30 11:49:00 +0000269 INLINE(Object** target_object_address());
270 INLINE(void set_target_object(Object* target));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100271 INLINE(JSGlobalPropertyCell* target_cell());
272 INLINE(Handle<JSGlobalPropertyCell> target_cell_handle());
273 INLINE(void set_target_cell(JSGlobalPropertyCell* cell));
274
Steve Blocka7e24c12009-10-30 11:49:00 +0000275
Leon Clarkef7060e22010-06-03 12:02:55 +0100276 // Read the address of the word containing the target_address in an
277 // instruction stream. What this means exactly is architecture-independent.
278 // The only architecture-independent user of this function is the serializer.
279 // The serializer uses it to find out how many raw bytes of instruction to
280 // output before the next target. Architecture-independent code shouldn't
281 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000282 INLINE(Address target_address_address());
Leon Clarkef7060e22010-06-03 12:02:55 +0100283 // This indicates how much space a target takes up when deserializing a code
284 // stream. For most architectures this is just the size of a pointer. For
285 // an instruction like movw/movt where the target bits are mixed into the
286 // instruction bits the size of the target will be zero, indicating that the
287 // serializer should not step forwards in memory after a target is resolved
288 // and written. In this case the target_address_address function above
289 // should return the end of the instructions to be patched, allowing the
290 // deserializer to deserialize the instructions as raw bytes and put them in
291 // place, ready to be patched with the target.
292 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000293
294 // Read/modify the reference in the instruction this relocation
295 // applies to; can only be called if rmode_ is external_reference
296 INLINE(Address* target_reference_address());
297
298 // Read/modify the address of a call instruction. This is used to relocate
299 // the break points where straight-line code is patched with a call
300 // instruction.
301 INLINE(Address call_address());
302 INLINE(void set_call_address(Address target));
303 INLINE(Object* call_object());
Steve Blocka7e24c12009-10-30 11:49:00 +0000304 INLINE(void set_call_object(Object* target));
Ben Murdochbb769b22010-08-11 14:56:33 +0100305 INLINE(Object** call_object_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000306
Iain Merrick75681382010-08-19 15:07:18 +0100307 template<typename StaticVisitor> inline void Visit();
Leon Clarkef7060e22010-06-03 12:02:55 +0100308 inline void Visit(ObjectVisitor* v);
309
Steve Blocka7e24c12009-10-30 11:49:00 +0000310 // Patch the code with some other code.
311 void PatchCode(byte* instructions, int instruction_count);
312
313 // Patch the code with a call.
314 void PatchCodeWithCall(Address target, int guard_bytes);
Steve Block3ce2e202009-11-05 08:53:23 +0000315
316 // Check whether this return sequence has been patched
317 // with a call to the debugger.
318 INLINE(bool IsPatchedReturnSequence());
Steve Blocka7e24c12009-10-30 11:49:00 +0000319
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100320 // Check whether this debug break slot has been patched with a call to the
321 // debugger.
322 INLINE(bool IsPatchedDebugBreakSlotSequence());
323
Steve Blocka7e24c12009-10-30 11:49:00 +0000324#ifdef ENABLE_DISASSEMBLER
325 // Printing
326 static const char* RelocModeName(Mode rmode);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100327 void Print(FILE* out);
Steve Blocka7e24c12009-10-30 11:49:00 +0000328#endif // ENABLE_DISASSEMBLER
329#ifdef DEBUG
330 // Debugging
331 void Verify();
332#endif
333
334 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
335 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
336 static const int kDebugMask = kPositionMask | 1 << COMMENT;
337 static const int kApplyMask; // Modes affected by apply. Depends on arch.
338
339 private:
340 // On ARM, note that pc_ is the address of the constant pool entry
341 // to be relocated and not the address of the instruction
342 // referencing the constant pool entry (except when rmode_ ==
343 // comment).
344 byte* pc_;
345 Mode rmode_;
346 intptr_t data_;
347 friend class RelocIterator;
348};
349
350
351// RelocInfoWriter serializes a stream of relocation info. It writes towards
352// lower addresses.
353class RelocInfoWriter BASE_EMBEDDED {
354 public:
355 RelocInfoWriter() : pos_(NULL), last_pc_(NULL), last_data_(0) {}
356 RelocInfoWriter(byte* pos, byte* pc) : pos_(pos), last_pc_(pc),
357 last_data_(0) {}
358
359 byte* pos() const { return pos_; }
360 byte* last_pc() const { return last_pc_; }
361
362 void Write(const RelocInfo* rinfo);
363
364 // Update the state of the stream after reloc info buffer
365 // and/or code is moved while the stream is active.
366 void Reposition(byte* pos, byte* pc) {
367 pos_ = pos;
368 last_pc_ = pc;
369 }
370
371 // Max size (bytes) of a written RelocInfo. Longest encoding is
372 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, ExtraTag, data_delta.
373 // On ia32 and arm this is 1 + 4 + 1 + 1 + 1 + 4 = 12.
374 // On x64 this is 1 + 4 + 1 + 1 + 1 + 8 == 16;
375 // Here we use the maximum of the two.
376 static const int kMaxSize = 16;
377
378 private:
379 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
380 inline void WriteTaggedPC(uint32_t pc_delta, int tag);
381 inline void WriteExtraTaggedPC(uint32_t pc_delta, int extra_tag);
382 inline void WriteExtraTaggedData(intptr_t data_delta, int top_tag);
383 inline void WriteTaggedData(intptr_t data_delta, int tag);
384 inline void WriteExtraTag(int extra_tag, int top_tag);
385
386 byte* pos_;
387 byte* last_pc_;
388 intptr_t last_data_;
389 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
390};
391
392
393// A RelocIterator iterates over relocation information.
394// Typical use:
395//
396// for (RelocIterator it(code); !it.done(); it.next()) {
397// // do something with it.rinfo() here
398// }
399//
400// A mask can be specified to skip unwanted modes.
401class RelocIterator: public Malloced {
402 public:
403 // Create a new iterator positioned at
404 // the beginning of the reloc info.
405 // Relocation information with mode k is included in the
406 // iteration iff bit k of mode_mask is set.
407 explicit RelocIterator(Code* code, int mode_mask = -1);
408 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
409
410 // Iteration
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100411 bool done() const { return done_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000412 void next();
413
414 // Return pointer valid until next next().
415 RelocInfo* rinfo() {
416 ASSERT(!done());
417 return &rinfo_;
418 }
419
420 private:
421 // Advance* moves the position before/after reading.
422 // *Read* reads from current byte(s) into rinfo_.
423 // *Get* just reads and returns info on current byte.
424 void Advance(int bytes = 1) { pos_ -= bytes; }
425 int AdvanceGetTag();
426 int GetExtraTag();
427 int GetTopTag();
428 void ReadTaggedPC();
429 void AdvanceReadPC();
430 void AdvanceReadData();
431 void AdvanceReadVariableLengthPCJump();
432 int GetPositionTypeTag();
433 void ReadTaggedData();
434
435 static RelocInfo::Mode DebugInfoModeFromTag(int tag);
436
437 // If the given mode is wanted, set it in rinfo_ and return true.
438 // Else return false. Used for efficiently skipping unwanted modes.
439 bool SetMode(RelocInfo::Mode mode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100440 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000441 }
442
443 byte* pos_;
444 byte* end_;
445 RelocInfo rinfo_;
446 bool done_;
447 int mode_mask_;
448 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
449};
450
451
452//------------------------------------------------------------------------------
453// External function
454
455//----------------------------------------------------------------------------
456class IC_Utility;
457class SCTableReference;
458#ifdef ENABLE_DEBUGGER_SUPPORT
459class Debug_Address;
460#endif
461
462
463typedef void* ExternalReferenceRedirector(void* original, bool fp_return);
464
465
466// An ExternalReference represents a C++ address used in the generated
467// code. All references to C++ functions and variables must be encapsulated in
468// an ExternalReference instance. This is done in order to track the origin of
469// all external references in the code so that they can be bound to the correct
470// addresses when deserializing a heap.
471class ExternalReference BASE_EMBEDDED {
472 public:
473 explicit ExternalReference(Builtins::CFunctionId id);
474
Steve Blockd0582a62009-12-15 09:54:21 +0000475 explicit ExternalReference(ApiFunction* ptr);
476
Steve Blocka7e24c12009-10-30 11:49:00 +0000477 explicit ExternalReference(Builtins::Name name);
478
479 explicit ExternalReference(Runtime::FunctionId id);
480
481 explicit ExternalReference(Runtime::Function* f);
482
483 explicit ExternalReference(const IC_Utility& ic_utility);
484
485#ifdef ENABLE_DEBUGGER_SUPPORT
486 explicit ExternalReference(const Debug_Address& debug_address);
487#endif
488
489 explicit ExternalReference(StatsCounter* counter);
490
491 explicit ExternalReference(Top::AddressId id);
492
493 explicit ExternalReference(const SCTableReference& table_ref);
494
495 // One-of-a-kind references. These references are not part of a general
496 // pattern. This means that they have to be added to the
497 // ExternalReferenceTable in serialize.cc manually.
498
499 static ExternalReference perform_gc_function();
Steve Block6ded16b2010-05-10 14:33:55 +0100500 static ExternalReference fill_heap_number_with_random_function();
501 static ExternalReference random_uint32_function();
Andrei Popescu402d9372010-02-26 13:31:12 +0000502 static ExternalReference transcendental_cache_array_address();
John Reck59135872010-11-02 12:39:01 -0700503 static ExternalReference delete_handle_scope_extensions();
Steve Blocka7e24c12009-10-30 11:49:00 +0000504
Ben Murdochb0fe1622011-05-05 13:52:32 +0100505 // Deoptimization support.
506 static ExternalReference new_deoptimizer_function();
507 static ExternalReference compute_output_frames_function();
508 static ExternalReference global_contexts_list();
509
Leon Clarkee46be812010-01-19 14:06:41 +0000510 // Static data in the keyed lookup cache.
511 static ExternalReference keyed_lookup_cache_keys();
512 static ExternalReference keyed_lookup_cache_field_offsets();
513
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 // Static variable Factory::the_hole_value.location()
515 static ExternalReference the_hole_value_location();
516
Ben Murdoch086aeea2011-05-13 15:57:08 +0100517 // Static variable Factory::arguments_marker.location()
518 static ExternalReference arguments_marker_location();
519
Steve Blocka7e24c12009-10-30 11:49:00 +0000520 // Static variable Heap::roots_address()
521 static ExternalReference roots_address();
522
523 // Static variable StackGuard::address_of_jslimit()
Steve Blockd0582a62009-12-15 09:54:21 +0000524 static ExternalReference address_of_stack_limit();
525
526 // Static variable StackGuard::address_of_real_jslimit()
527 static ExternalReference address_of_real_stack_limit();
Steve Blocka7e24c12009-10-30 11:49:00 +0000528
529 // Static variable RegExpStack::limit_address()
530 static ExternalReference address_of_regexp_stack_limit();
531
Leon Clarkee46be812010-01-19 14:06:41 +0000532 // Static variables for RegExp.
533 static ExternalReference address_of_static_offsets_vector();
534 static ExternalReference address_of_regexp_stack_memory_address();
535 static ExternalReference address_of_regexp_stack_memory_size();
536
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 // Static variable Heap::NewSpaceStart()
538 static ExternalReference new_space_start();
Andrei Popescu402d9372010-02-26 13:31:12 +0000539 static ExternalReference new_space_mask();
Steve Blocka7e24c12009-10-30 11:49:00 +0000540 static ExternalReference heap_always_allocate_scope_depth();
541
542 // Used for fast allocation in generated code.
543 static ExternalReference new_space_allocation_top_address();
544 static ExternalReference new_space_allocation_limit_address();
545
546 static ExternalReference double_fp_operation(Token::Value operation);
547 static ExternalReference compare_doubles();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100548 static ExternalReference power_double_double_function();
549 static ExternalReference power_double_int_function();
Steve Blocka7e24c12009-10-30 11:49:00 +0000550
Steve Blockd0582a62009-12-15 09:54:21 +0000551 static ExternalReference handle_scope_next_address();
552 static ExternalReference handle_scope_limit_address();
John Reck59135872010-11-02 12:39:01 -0700553 static ExternalReference handle_scope_level_address();
Steve Blockd0582a62009-12-15 09:54:21 +0000554
555 static ExternalReference scheduled_exception_address();
556
Ben Murdochb0fe1622011-05-05 13:52:32 +0100557 // Static variables containing common double constants.
558 static ExternalReference address_of_min_int();
559 static ExternalReference address_of_one_half();
Ben Murdochb8e0da22011-05-16 14:20:40 +0100560 static ExternalReference address_of_minus_zero();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100561 static ExternalReference address_of_negative_infinity();
562
Steve Blocka7e24c12009-10-30 11:49:00 +0000563 Address address() const {return reinterpret_cast<Address>(address_);}
564
565#ifdef ENABLE_DEBUGGER_SUPPORT
566 // Function Debug::Break()
567 static ExternalReference debug_break();
568
569 // Used to check if single stepping is enabled in generated code.
570 static ExternalReference debug_step_in_fp_address();
571#endif
572
Steve Block6ded16b2010-05-10 14:33:55 +0100573#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000574 // C functions called from RegExp generated code.
575
576 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
577 static ExternalReference re_case_insensitive_compare_uc16();
578
579 // Function RegExpMacroAssembler*::CheckStackGuardState()
580 static ExternalReference re_check_stack_guard_state();
581
582 // Function NativeRegExpMacroAssembler::GrowStack()
583 static ExternalReference re_grow_stack();
Leon Clarkee46be812010-01-19 14:06:41 +0000584
585 // byte NativeRegExpMacroAssembler::word_character_bitmap
586 static ExternalReference re_word_character_map();
587
Steve Blocka7e24c12009-10-30 11:49:00 +0000588#endif
589
590 // This lets you register a function that rewrites all external references.
591 // Used by the ARM simulator to catch calls to external references.
592 static void set_redirector(ExternalReferenceRedirector* redirector) {
593 ASSERT(redirector_ == NULL); // We can't stack them.
594 redirector_ = redirector;
595 }
596
597 private:
598 explicit ExternalReference(void* address)
599 : address_(address) {}
600
601 static ExternalReferenceRedirector* redirector_;
602
603 static void* Redirect(void* address, bool fp_return = false) {
604 if (redirector_ == NULL) return address;
Steve Blockd0582a62009-12-15 09:54:21 +0000605 void* answer = (*redirector_)(address, fp_return);
606 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000607 }
608
609 static void* Redirect(Address address_arg, bool fp_return = false) {
610 void* address = reinterpret_cast<void*>(address_arg);
Steve Blockd0582a62009-12-15 09:54:21 +0000611 void* answer = (redirector_ == NULL) ?
612 address :
613 (*redirector_)(address, fp_return);
614 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +0000615 }
616
617 void* address_;
618};
619
620
621// -----------------------------------------------------------------------------
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800622// Position recording support
623
Ben Murdochb0fe1622011-05-05 13:52:32 +0100624struct PositionState {
625 PositionState() : current_position(RelocInfo::kNoPosition),
626 written_position(RelocInfo::kNoPosition),
627 current_statement_position(RelocInfo::kNoPosition),
628 written_statement_position(RelocInfo::kNoPosition) {}
629
630 int current_position;
631 int written_position;
632
633 int current_statement_position;
634 int written_statement_position;
635};
636
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800637
638class PositionsRecorder BASE_EMBEDDED {
639 public:
640 explicit PositionsRecorder(Assembler* assembler)
Ben Murdochb8e0da22011-05-16 14:20:40 +0100641 : assembler_(assembler) {
642#ifdef ENABLE_GDB_JIT_INTERFACE
643 gdbjit_lineinfo_ = NULL;
644#endif
645 }
646
647#ifdef ENABLE_GDB_JIT_INTERFACE
648 ~PositionsRecorder() {
649 delete gdbjit_lineinfo_;
650 }
651
652 void StartGDBJITLineInfoRecording() {
653 if (FLAG_gdbjit) {
654 gdbjit_lineinfo_ = new GDBJITLineInfo();
655 }
656 }
657
658 GDBJITLineInfo* DetachGDBJITLineInfo() {
659 GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
660 gdbjit_lineinfo_ = NULL; // To prevent deallocation in destructor.
661 return lineinfo;
662 }
663#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800664
Ben Murdochb0fe1622011-05-05 13:52:32 +0100665 // Set current position to pos.
666 void RecordPosition(int pos);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800667
668 // Set current statement position to pos.
669 void RecordStatementPosition(int pos);
670
671 // Write recorded positions to relocation information.
672 bool WriteRecordedPositions();
673
Ben Murdochb0fe1622011-05-05 13:52:32 +0100674 int current_position() const { return state_.current_position; }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800675
Ben Murdochb0fe1622011-05-05 13:52:32 +0100676 int current_statement_position() const {
677 return state_.current_statement_position;
678 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800679
680 private:
681 Assembler* assembler_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100682 PositionState state_;
Ben Murdochb8e0da22011-05-16 14:20:40 +0100683#ifdef ENABLE_GDB_JIT_INTERFACE
684 GDBJITLineInfo* gdbjit_lineinfo_;
685#endif
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800686
Ben Murdochb0fe1622011-05-05 13:52:32 +0100687 friend class PreservePositionScope;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800688
Ben Murdochb0fe1622011-05-05 13:52:32 +0100689 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800690};
691
692
Ben Murdochb0fe1622011-05-05 13:52:32 +0100693class PreservePositionScope BASE_EMBEDDED {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800694 public:
Ben Murdochb0fe1622011-05-05 13:52:32 +0100695 explicit PreservePositionScope(PositionsRecorder* positions_recorder)
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800696 : positions_recorder_(positions_recorder),
Ben Murdochb0fe1622011-05-05 13:52:32 +0100697 saved_state_(positions_recorder->state_) {}
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800698
Ben Murdochb0fe1622011-05-05 13:52:32 +0100699 ~PreservePositionScope() {
700 positions_recorder_->state_ = saved_state_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800701 }
702
703 private:
704 PositionsRecorder* positions_recorder_;
Ben Murdochb0fe1622011-05-05 13:52:32 +0100705 const PositionState saved_state_;
706
707 DISALLOW_COPY_AND_ASSIGN(PreservePositionScope);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800708};
709
710
711// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000712// Utility functions
713
714static inline bool is_intn(int x, int n) {
715 return -(1 << (n-1)) <= x && x < (1 << (n-1));
716}
717
Steve Blocka7e24c12009-10-30 11:49:00 +0000718static inline bool is_int8(int x) { return is_intn(x, 8); }
Andrei Popescu31002712010-02-23 13:46:05 +0000719static inline bool is_int16(int x) { return is_intn(x, 16); }
720static inline bool is_int18(int x) { return is_intn(x, 18); }
721static inline bool is_int24(int x) { return is_intn(x, 24); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000722
723static inline bool is_uintn(int x, int n) {
724 return (x & -(1 << n)) == 0;
725}
726
727static inline bool is_uint2(int x) { return is_uintn(x, 2); }
728static inline bool is_uint3(int x) { return is_uintn(x, 3); }
729static inline bool is_uint4(int x) { return is_uintn(x, 4); }
730static inline bool is_uint5(int x) { return is_uintn(x, 5); }
731static inline bool is_uint6(int x) { return is_uintn(x, 6); }
732static inline bool is_uint8(int x) { return is_uintn(x, 8); }
Andrei Popescu31002712010-02-23 13:46:05 +0000733static inline bool is_uint10(int x) { return is_uintn(x, 10); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000734static inline bool is_uint12(int x) { return is_uintn(x, 12); }
735static inline bool is_uint16(int x) { return is_uintn(x, 16); }
736static inline bool is_uint24(int x) { return is_uintn(x, 24); }
Andrei Popescu31002712010-02-23 13:46:05 +0000737static inline bool is_uint26(int x) { return is_uintn(x, 26); }
738static inline bool is_uint28(int x) { return is_uintn(x, 28); }
739
740static inline int NumberOfBitsSet(uint32_t x) {
741 unsigned int num_bits_set;
742 for (num_bits_set = 0; x; x >>= 1) {
743 num_bits_set += x & 1;
744 }
745 return num_bits_set;
746}
Steve Blocka7e24c12009-10-30 11:49:00 +0000747
Ben Murdochb0fe1622011-05-05 13:52:32 +0100748// Computes pow(x, y) with the special cases in the spec for Math.pow.
749double power_double_int(double x, int y);
750double power_double_double(double x, double y);
751
Steve Blocka7e24c12009-10-30 11:49:00 +0000752} } // namespace v8::internal
753
754#endif // V8_ASSEMBLER_H_