blob: 08c6b38541cf9a12802e2eb5dc9b0146192f6c01 [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.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010033// Copyright 2012 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +000034
35#ifndef V8_ASSEMBLER_H_
36#define V8_ASSEMBLER_H_
37
Ben Murdochb8a8cc12014-11-26 15:28:44 +000038#include "src/allocation.h"
39#include "src/builtins.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000040#include "src/isolate.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041#include "src/parsing/token.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040042#include "src/runtime/runtime.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000043
44namespace v8 {
Ben Murdoch3ef787d2012-04-12 10:51:47 +010045
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000046// Forward declarations.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010047class ApiFunction;
48
Steve Blocka7e24c12009-10-30 11:49:00 +000049namespace internal {
50
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000051// Forward declarations.
52class SourcePosition;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000053class StatsCounter;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054
Steve Blocka7e24c12009-10-30 11:49:00 +000055// -----------------------------------------------------------------------------
Steve Block44f0eee2011-05-26 01:26:41 +010056// Platform independent assembler base class.
57
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000058enum class CodeObjectRequired { kNo, kYes };
59
60
Steve Block44f0eee2011-05-26 01:26:41 +010061class AssemblerBase: public Malloced {
62 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000063 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size);
64 virtual ~AssemblerBase();
Steve Block44f0eee2011-05-26 01:26:41 +010065
66 Isolate* isolate() const { return isolate_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000067 int jit_cookie() const { return jit_cookie_; }
68
69 bool emit_debug_code() const { return emit_debug_code_; }
70 void set_emit_debug_code(bool value) { emit_debug_code_ = value; }
71
72 bool serializer_enabled() const { return serializer_enabled_; }
73 void enable_serializer() { serializer_enabled_ = true; }
74
75 bool predictable_code_size() const { return predictable_code_size_; }
76 void set_predictable_code_size(bool value) { predictable_code_size_ = value; }
77
78 uint64_t enabled_cpu_features() const { return enabled_cpu_features_; }
79 void set_enabled_cpu_features(uint64_t features) {
80 enabled_cpu_features_ = features;
81 }
82 bool IsEnabled(CpuFeature f) {
83 return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
84 }
Steve Block44f0eee2011-05-26 01:26:41 +010085
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000086 bool is_constant_pool_available() const {
87 if (FLAG_enable_embedded_constant_pool) {
88 return constant_pool_available_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040089 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000090 // Embedded constant pool not supported on this architecture.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040091 UNREACHABLE();
92 return false;
93 }
94 }
95
Ben Murdochdb1b4382012-04-26 19:03:50 +010096 // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
97 // cross-snapshotting.
98 static void QuietNaN(HeapObject* nan) { }
99
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000100 int pc_offset() const { return static_cast<int>(pc_ - buffer_); }
101
102 // This function is called when code generation is aborted, so that
103 // the assembler could clean up internal data structures.
104 virtual void AbortedCodeGeneration() { }
105
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000106 // Debugging
107 void Print();
108
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000109 static const int kMinimalBufferSize = 4*KB;
110
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000111 static void FlushICache(Isolate* isolate, void* start, size_t size);
112
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000113 protected:
114 // The buffer into which code and relocation info are generated. It could
115 // either be owned by the assembler or be provided externally.
116 byte* buffer_;
117 int buffer_size_;
118 bool own_buffer_;
119
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000120 void set_constant_pool_available(bool available) {
121 if (FLAG_enable_embedded_constant_pool) {
122 constant_pool_available_ = available;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400123 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124 // Embedded constant pool not supported on this architecture.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400125 UNREACHABLE();
126 }
127 }
128
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000129 // The program counter, which points into the buffer above and moves forward.
130 byte* pc_;
131
Steve Block44f0eee2011-05-26 01:26:41 +0100132 private:
133 Isolate* isolate_;
Steve Block053d10c2011-06-13 19:13:29 +0100134 int jit_cookie_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000135 uint64_t enabled_cpu_features_;
136 bool emit_debug_code_;
137 bool predictable_code_size_;
138 bool serializer_enabled_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400139
140 // Indicates whether the constant pool can be accessed, which is only possible
141 // if the pp register points to the current code object's constant pool.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000142 bool constant_pool_available_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400143
144 // Constant pool.
145 friend class FrameAndConstantPoolScope;
146 friend class ConstantPoolUnavailableScope;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000147};
148
149
150// Avoids emitting debug code during the lifetime of this scope object.
151class DontEmitDebugCodeScope BASE_EMBEDDED {
152 public:
153 explicit DontEmitDebugCodeScope(AssemblerBase* assembler)
154 : assembler_(assembler), old_value_(assembler->emit_debug_code()) {
155 assembler_->set_emit_debug_code(false);
156 }
157 ~DontEmitDebugCodeScope() {
158 assembler_->set_emit_debug_code(old_value_);
159 }
160 private:
161 AssemblerBase* assembler_;
162 bool old_value_;
163};
164
165
166// Avoids using instructions that vary in size in unpredictable ways between the
167// snapshot and the running VM.
168class PredictableCodeSizeScope {
169 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000170 explicit PredictableCodeSizeScope(AssemblerBase* assembler);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000171 PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size);
172 ~PredictableCodeSizeScope();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000173 void ExpectSize(int expected_size) { expected_size_ = expected_size; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000174
175 private:
176 AssemblerBase* assembler_;
177 int expected_size_;
178 int start_offset_;
179 bool old_value_;
180};
181
182
183// Enable a specified feature within a scope.
184class CpuFeatureScope BASE_EMBEDDED {
185 public:
186#ifdef DEBUG
187 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f);
188 ~CpuFeatureScope();
189
190 private:
191 AssemblerBase* assembler_;
192 uint64_t old_enabled_;
193#else
194 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {}
195#endif
196};
197
198
199// CpuFeatures keeps track of which features are supported by the target CPU.
200// Supported features must be enabled by a CpuFeatureScope before use.
201// Example:
202// if (assembler->IsSupported(SSE3)) {
203// CpuFeatureScope fscope(assembler, SSE3);
204// // Generate code containing SSE3 instructions.
205// } else {
206// // Generate alternative code.
207// }
208class CpuFeatures : public AllStatic {
209 public:
210 static void Probe(bool cross_compile) {
211 STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt);
212 if (initialized_) return;
213 initialized_ = true;
214 ProbeImpl(cross_compile);
215 }
216
217 static unsigned SupportedFeatures() {
218 Probe(false);
219 return supported_;
220 }
221
222 static bool IsSupported(CpuFeature f) {
223 return (supported_ & (1u << f)) != 0;
224 }
225
226 static inline bool SupportsCrankshaft();
227
228 static inline unsigned cache_line_size() {
229 DCHECK(cache_line_size_ != 0);
230 return cache_line_size_;
231 }
232
233 static void PrintTarget();
234 static void PrintFeatures();
235
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000236 private:
237 friend class ExternalReference;
238 friend class AssemblerBase;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000239 // Flush instruction cache.
240 static void FlushICache(void* start, size_t size);
241
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 // Platform-dependent implementation.
243 static void ProbeImpl(bool cross_compile);
244
245 static unsigned supported_;
246 static unsigned cache_line_size_;
247 static bool initialized_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000248 DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
Steve Block44f0eee2011-05-26 01:26:41 +0100249};
250
Ben Murdochb0fe1622011-05-05 13:52:32 +0100251
252// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000253// Labels represent pc locations; they are typically jump or call targets.
254// After declaration, a label can be freely used to denote known or (yet)
255// unknown pc location. Assembler::bind() is used to bind a label to the
256// current pc. A label can be bound only once.
257
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400258class Label {
Steve Blocka7e24c12009-10-30 11:49:00 +0000259 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000260 enum Distance {
261 kNear, kFar
262 };
263
264 INLINE(Label()) {
265 Unuse();
266 UnuseNear();
267 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000268
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000269 INLINE(~Label()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000270 DCHECK(!is_linked());
271 DCHECK(!is_near_linked());
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000272 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000273
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000274 INLINE(void Unuse()) { pos_ = 0; }
275 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
276
277 INLINE(bool is_bound() const) { return pos_ < 0; }
278 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
279 INLINE(bool is_linked() const) { return pos_ > 0; }
Ben Murdoch257744e2011-11-30 15:57:28 +0000280 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000281
282 // Returns the position of bound or linked labels. Cannot be used
283 // for unused labels.
284 int pos() const;
Ben Murdoch257744e2011-11-30 15:57:28 +0000285 int near_link_pos() const { return near_link_pos_ - 1; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000286
287 private:
288 // pos_ encodes both the binding state (via its sign)
289 // and the binding position (via its value) of a label.
290 //
291 // pos_ < 0 bound label, pos() returns the jump target position
292 // pos_ == 0 unused label
293 // pos_ > 0 linked label, pos() returns the last reference position
294 int pos_;
295
Ben Murdoch257744e2011-11-30 15:57:28 +0000296 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
297 int near_link_pos_;
298
Steve Blocka7e24c12009-10-30 11:49:00 +0000299 void bind_to(int pos) {
300 pos_ = -pos - 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000301 DCHECK(is_bound());
Steve Blocka7e24c12009-10-30 11:49:00 +0000302 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000303 void link_to(int pos, Distance distance = kFar) {
304 if (distance == kNear) {
305 near_link_pos_ = pos + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306 DCHECK(is_near_linked());
Ben Murdoch257744e2011-11-30 15:57:28 +0000307 } else {
308 pos_ = pos + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000309 DCHECK(is_linked());
Ben Murdoch257744e2011-11-30 15:57:28 +0000310 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000311 }
312
313 friend class Assembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000314 friend class Displacement;
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 friend class RegExpMacroAssemblerIrregexp;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000316
317#if V8_TARGET_ARCH_ARM64
318 // On ARM64, the Assembler keeps track of pointers to Labels to resolve
319 // branches to distant targets. Copying labels would confuse the Assembler.
320 DISALLOW_COPY_AND_ASSIGN(Label); // NOLINT
321#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000322};
323
324
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100325enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
326
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000327enum ArgvMode { kArgvOnStack, kArgvInRegister };
328
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000329// Specifies whether to perform icache flush operations on RelocInfo updates.
330// If FLUSH_ICACHE_IF_NEEDED, the icache will always be flushed if an
331// instruction was modified. If SKIP_ICACHE_FLUSH the flush will always be
332// skipped (only use this if you will flush the icache manually before it is
333// executed).
334enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH };
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100335
Steve Blocka7e24c12009-10-30 11:49:00 +0000336// -----------------------------------------------------------------------------
337// Relocation information
338
339
340// Relocation information consists of the address (pc) of the datum
341// to which the relocation information applies, the relocation mode
342// (rmode), and an optional data field. The relocation mode may be
343// "descriptive" and not indicate a need for relocation, but simply
344// describe a property of the datum. Such rmodes are useful for GC
345// and nice disassembly output.
346
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000347class RelocInfo {
Steve Blocka7e24c12009-10-30 11:49:00 +0000348 public:
349 // The constant kNoPosition is used with the collecting of source positions
350 // in the relocation information. Two types of source positions are collected
351 // "position" (RelocMode position) and "statement position" (RelocMode
352 // statement_position). The "position" is collected at places in the source
353 // code which are of interest when making stack traces to pin-point the source
354 // location of a stack frame as close as possible. The "statement position" is
355 // collected at the beginning at each statement, and is used to indicate
356 // possible break locations. kNoPosition is used to indicate an
357 // invalid/uninitialized position value.
358 static const int kNoPosition = -1;
359
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100360 // This string is used to add padding comments to the reloc info in cases
361 // where we are not sure to have enough space for patching in during
362 // lazy deoptimization. This is the case if we have indirect calls for which
363 // we do not normally record relocation info.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000364 static const char* const kFillerCommentString;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100365
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000366 // The minimum size of a comment is equal to two bytes for the extra tagged
367 // pc and kPointerSize for the actual pointer to the comment.
368 static const int kMinRelocCommentSize = 2 + kPointerSize;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100369
370 // The maximum size for a call instruction including pc-jump.
371 static const int kMaxCallSize = 6;
372
Steve Block44f0eee2011-05-26 01:26:41 +0100373 // The maximum pc delta that will use the short encoding.
374 static const int kMaxSmallPCDelta;
375
Steve Blocka7e24c12009-10-30 11:49:00 +0000376 enum Mode {
377 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
Ben Murdoch257744e2011-11-30 15:57:28 +0000378 CODE_TARGET, // Code target which is not any of the above.
379 CODE_TARGET_WITH_ID,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000380 DEBUGGER_STATEMENT, // Code target for the debugger statement.
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 EMBEDDED_OBJECT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000382 CELL,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100383
Steve Blocka7e24c12009-10-30 11:49:00 +0000384 // Everything after runtime_entry (inclusive) is not GC'ed.
385 RUNTIME_ENTRY,
Steve Blocka7e24c12009-10-30 11:49:00 +0000386 COMMENT,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000387 POSITION, // See comment for kNoPosition above.
Steve Blocka7e24c12009-10-30 11:49:00 +0000388 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000389
390 // Additional code inserted for debug break slot.
391 DEBUG_BREAK_SLOT_AT_POSITION,
392 DEBUG_BREAK_SLOT_AT_RETURN,
393 DEBUG_BREAK_SLOT_AT_CALL,
394
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 EXTERNAL_REFERENCE, // The address of an external C++ function.
396 INTERNAL_REFERENCE, // An address inside the same function.
397
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000398 // Encoded internal reference, used only on MIPS, MIPS64 and PPC.
399 INTERNAL_REFERENCE_ENCODED,
400
401 // Continuation points for a generator yield.
402 GENERATOR_CONTINUATION,
403
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000404 // Marks constant and veneer pools. Only used on ARM and ARM64.
405 // They use a custom noncompact encoding.
406 CONST_POOL,
407 VENEER_POOL,
408
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000409 DEOPT_REASON, // Deoptimization reason index.
410
411 // This is not an actual reloc mode, but used to encode a long pc jump that
412 // cannot be encoded as part of another record.
413 PC_JUMP,
414
Steve Blocka7e24c12009-10-30 11:49:00 +0000415 // Pseudo-types
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000416 NUMBER_OF_MODES,
417 NONE32, // never recorded 32-bit value
418 NONE64, // never recorded 64-bit value
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000419 CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by
420 // code aging.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000421
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000422 FIRST_REAL_RELOC_MODE = CODE_TARGET,
423 LAST_REAL_RELOC_MODE = VENEER_POOL,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000424 LAST_CODE_ENUM = DEBUGGER_STATEMENT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000425 LAST_GCED_ENUM = CELL,
Steve Blocka7e24c12009-10-30 11:49:00 +0000426 };
427
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000428 STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100429
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000430 explicit RelocInfo(Isolate* isolate) : isolate_(isolate) {
431 DCHECK_NOT_NULL(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000432 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000433
434 RelocInfo(Isolate* isolate, byte* pc, Mode rmode, intptr_t data, Code* host)
435 : isolate_(isolate), pc_(pc), rmode_(rmode), data_(data), host_(host) {
436 DCHECK_NOT_NULL(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000437 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000438
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000439 static inline bool IsRealRelocMode(Mode mode) {
440 return mode >= FIRST_REAL_RELOC_MODE &&
441 mode <= LAST_REAL_RELOC_MODE;
442 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000443 static inline bool IsCodeTarget(Mode mode) {
444 return mode <= LAST_CODE_ENUM;
445 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100446 static inline bool IsEmbeddedObject(Mode mode) {
447 return mode == EMBEDDED_OBJECT;
448 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000449 static inline bool IsCell(Mode mode) { return mode == CELL; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000450 static inline bool IsRuntimeEntry(Mode mode) {
451 return mode == RUNTIME_ENTRY;
452 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000453 // Is the relocation mode affected by GC?
454 static inline bool IsGCRelocMode(Mode mode) {
455 return mode <= LAST_GCED_ENUM;
456 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000457 static inline bool IsComment(Mode mode) {
458 return mode == COMMENT;
459 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000460 static inline bool IsConstPool(Mode mode) {
461 return mode == CONST_POOL;
462 }
463 static inline bool IsVeneerPool(Mode mode) {
464 return mode == VENEER_POOL;
465 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000466 static inline bool IsDeoptReason(Mode mode) {
467 return mode == DEOPT_REASON;
468 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000469 static inline bool IsPosition(Mode mode) {
470 return mode == POSITION || mode == STATEMENT_POSITION;
471 }
472 static inline bool IsStatementPosition(Mode mode) {
473 return mode == STATEMENT_POSITION;
474 }
475 static inline bool IsExternalReference(Mode mode) {
476 return mode == EXTERNAL_REFERENCE;
477 }
478 static inline bool IsInternalReference(Mode mode) {
479 return mode == INTERNAL_REFERENCE;
480 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000481 static inline bool IsInternalReferenceEncoded(Mode mode) {
482 return mode == INTERNAL_REFERENCE_ENCODED;
483 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100484 static inline bool IsDebugBreakSlot(Mode mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000485 return IsDebugBreakSlotAtPosition(mode) || IsDebugBreakSlotAtReturn(mode) ||
486 IsDebugBreakSlotAtCall(mode);
487 }
488 static inline bool IsDebugBreakSlotAtPosition(Mode mode) {
489 return mode == DEBUG_BREAK_SLOT_AT_POSITION;
490 }
491 static inline bool IsDebugBreakSlotAtReturn(Mode mode) {
492 return mode == DEBUG_BREAK_SLOT_AT_RETURN;
493 }
494 static inline bool IsDebugBreakSlotAtCall(Mode mode) {
495 return mode == DEBUG_BREAK_SLOT_AT_CALL;
496 }
497 static inline bool IsDebuggerStatement(Mode mode) {
498 return mode == DEBUGGER_STATEMENT;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100499 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000500 static inline bool IsNone(Mode mode) {
501 return mode == NONE32 || mode == NONE64;
502 }
503 static inline bool IsCodeAgeSequence(Mode mode) {
504 return mode == CODE_AGE_SEQUENCE;
505 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000506 static inline bool IsGeneratorContinuation(Mode mode) {
507 return mode == GENERATOR_CONTINUATION;
508 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000509 static inline int ModeMask(Mode mode) { return 1 << mode; }
510
511 // Accessors
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000512 Isolate* isolate() const { return isolate_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100513 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000514 void set_pc(byte* pc) { pc_ = pc; }
515 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100516 intptr_t data() const { return data_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100517 Code* host() const { return host_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000518 void set_host(Code* host) { host_ = host; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000519
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000520 // Apply a relocation by delta bytes. When the code object is moved, PC
521 // relative addresses have to be updated as well as absolute addresses
522 // inside the code (internal references).
523 // Do not forget to flush the icache afterwards!
524 INLINE(void apply(intptr_t delta));
Steve Blocka7e24c12009-10-30 11:49:00 +0000525
Leon Clarkef7060e22010-06-03 12:02:55 +0100526 // Is the pointer this relocation info refers to coded like a plain pointer
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100527 // or is it strange in some way (e.g. relative or patched into a series of
Leon Clarkef7060e22010-06-03 12:02:55 +0100528 // instructions).
529 bool IsCodedSpecially();
530
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000531 // If true, the pointer this relocation info refers to is an entry in the
532 // constant pool, otherwise the pointer is embedded in the instruction stream.
533 bool IsInConstantPool();
534
Steve Blocka7e24c12009-10-30 11:49:00 +0000535 // this relocation applies to;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000536 // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Steve Blocka7e24c12009-10-30 11:49:00 +0000537 INLINE(Address target_address());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100538 INLINE(void set_target_address(Address target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000539 WriteBarrierMode write_barrier_mode =
540 UPDATE_WRITE_BARRIER,
541 ICacheFlushMode icache_flush_mode =
542 FLUSH_ICACHE_IF_NEEDED));
Steve Blocka7e24c12009-10-30 11:49:00 +0000543 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000544 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100545 INLINE(void set_target_object(Object* target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 WriteBarrierMode write_barrier_mode =
547 UPDATE_WRITE_BARRIER,
548 ICacheFlushMode icache_flush_mode =
549 FLUSH_ICACHE_IF_NEEDED));
550 INLINE(Address target_runtime_entry(Assembler* origin));
551 INLINE(void set_target_runtime_entry(Address target,
552 WriteBarrierMode write_barrier_mode =
553 UPDATE_WRITE_BARRIER,
554 ICacheFlushMode icache_flush_mode =
555 FLUSH_ICACHE_IF_NEEDED));
556 INLINE(Cell* target_cell());
557 INLINE(Handle<Cell> target_cell_handle());
558 INLINE(void set_target_cell(Cell* cell,
559 WriteBarrierMode write_barrier_mode =
560 UPDATE_WRITE_BARRIER,
561 ICacheFlushMode icache_flush_mode =
562 FLUSH_ICACHE_IF_NEEDED));
563 INLINE(Handle<Object> code_age_stub_handle(Assembler* origin));
564 INLINE(Code* code_age_stub());
565 INLINE(void set_code_age_stub(Code* stub,
566 ICacheFlushMode icache_flush_mode =
567 FLUSH_ICACHE_IF_NEEDED));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100568
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000569 // Returns the address of the constant pool entry where the target address
570 // is held. This should only be called if IsInConstantPool returns true.
571 INLINE(Address constant_pool_entry_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000572
Leon Clarkef7060e22010-06-03 12:02:55 +0100573 // Read the address of the word containing the target_address in an
574 // instruction stream. What this means exactly is architecture-independent.
575 // The only architecture-independent user of this function is the serializer.
576 // The serializer uses it to find out how many raw bytes of instruction to
577 // output before the next target. Architecture-independent code shouldn't
578 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000579 INLINE(Address target_address_address());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000580
Leon Clarkef7060e22010-06-03 12:02:55 +0100581 // This indicates how much space a target takes up when deserializing a code
582 // stream. For most architectures this is just the size of a pointer. For
583 // an instruction like movw/movt where the target bits are mixed into the
584 // instruction bits the size of the target will be zero, indicating that the
585 // serializer should not step forwards in memory after a target is resolved
586 // and written. In this case the target_address_address function above
587 // should return the end of the instructions to be patched, allowing the
588 // deserializer to deserialize the instructions as raw bytes and put them in
589 // place, ready to be patched with the target.
590 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000591
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000592 // Read the reference in the instruction this relocation
593 // applies to; can only be called if rmode_ is EXTERNAL_REFERENCE.
594 INLINE(Address target_external_reference());
595
596 // Read the reference in the instruction this relocation
597 // applies to; can only be called if rmode_ is INTERNAL_REFERENCE.
598 INLINE(Address target_internal_reference());
599
600 // Return the reference address this relocation applies to;
601 // can only be called if rmode_ is INTERNAL_REFERENCE.
602 INLINE(Address target_internal_reference_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000603
604 // Read/modify the address of a call instruction. This is used to relocate
605 // the break points where straight-line code is patched with a call
606 // instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000607 INLINE(Address debug_call_address());
608 INLINE(void set_debug_call_address(Address target));
Steve Blocka7e24c12009-10-30 11:49:00 +0000609
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000610 // Wipe out a relocation to a fixed value, used for making snapshots
611 // reproducible.
612 INLINE(void WipeOut());
613
Steve Block44f0eee2011-05-26 01:26:41 +0100614 template<typename StaticVisitor> inline void Visit(Heap* heap);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000615 inline void Visit(Isolate* isolate, ObjectVisitor* v);
Leon Clarkef7060e22010-06-03 12:02:55 +0100616
Steve Block3ce2e202009-11-05 08:53:23 +0000617 // Check whether this return sequence has been patched
618 // with a call to the debugger.
619 INLINE(bool IsPatchedReturnSequence());
Steve Blocka7e24c12009-10-30 11:49:00 +0000620
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100621 // Check whether this debug break slot has been patched with a call to the
622 // debugger.
623 INLINE(bool IsPatchedDebugBreakSlotSequence());
624
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000625#ifdef DEBUG
626 // Check whether the given code contains relocation information that
627 // either is position-relative or movable by the garbage collector.
628 static bool RequiresRelocation(const CodeDesc& desc);
629#endif
630
Steve Blocka7e24c12009-10-30 11:49:00 +0000631#ifdef ENABLE_DISASSEMBLER
632 // Printing
633 static const char* RelocModeName(Mode rmode);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400634 void Print(Isolate* isolate, std::ostream& os); // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000635#endif // ENABLE_DISASSEMBLER
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000636#ifdef VERIFY_HEAP
637 void Verify(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000638#endif
639
640 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
641 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
Ben Murdoch257744e2011-11-30 15:57:28 +0000642 static const int kDataMask =
643 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000644 static const int kDebugBreakSlotMask = 1 << DEBUG_BREAK_SLOT_AT_POSITION |
645 1 << DEBUG_BREAK_SLOT_AT_RETURN |
646 1 << DEBUG_BREAK_SLOT_AT_CALL;
647 static const int kApplyMask; // Modes affected by apply. Depends on arch.
Steve Blocka7e24c12009-10-30 11:49:00 +0000648
649 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000650 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000651 // On ARM, note that pc_ is the address of the constant pool entry
652 // to be relocated and not the address of the instruction
653 // referencing the constant pool entry (except when rmode_ ==
654 // comment).
655 byte* pc_;
656 Mode rmode_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000657 intptr_t data_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100658 Code* host_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000659 friend class RelocIterator;
660};
661
662
663// RelocInfoWriter serializes a stream of relocation info. It writes towards
664// lower addresses.
665class RelocInfoWriter BASE_EMBEDDED {
666 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000667 RelocInfoWriter()
668 : pos_(NULL),
669 last_pc_(NULL),
670 last_id_(0),
671 last_position_(0),
672 last_mode_(RelocInfo::NUMBER_OF_MODES),
673 next_position_candidate_pos_delta_(0),
674 next_position_candidate_pc_delta_(0),
675 next_position_candidate_flushed_(true) {}
676 RelocInfoWriter(byte* pos, byte* pc)
677 : pos_(pos),
678 last_pc_(pc),
679 last_id_(0),
680 last_position_(0),
681 last_mode_(RelocInfo::NUMBER_OF_MODES),
682 next_position_candidate_pos_delta_(0),
683 next_position_candidate_pc_delta_(0),
684 next_position_candidate_flushed_(true) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000685
686 byte* pos() const { return pos_; }
687 byte* last_pc() const { return last_pc_; }
688
689 void Write(const RelocInfo* rinfo);
690
691 // Update the state of the stream after reloc info buffer
692 // and/or code is moved while the stream is active.
693 void Reposition(byte* pos, byte* pc) {
694 pos_ = pos;
695 last_pc_ = pc;
696 }
697
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000698 void Finish() { FlushPosition(); }
699
Steve Blocka7e24c12009-10-30 11:49:00 +0000700 // Max size (bytes) of a written RelocInfo. Longest encoding is
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000701 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, data_delta.
702 // On ia32 and arm this is 1 + 4 + 1 + 1 + 4 = 11.
703 // On x64 this is 1 + 4 + 1 + 1 + 8 == 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000704 // Here we use the maximum of the two.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000705 static const int kMaxSize = 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000706
707 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000708 inline uint32_t WriteLongPCJump(uint32_t pc_delta);
709
710 inline void WriteShortTaggedPC(uint32_t pc_delta, int tag);
711 inline void WriteShortTaggedData(intptr_t data_delta, int tag);
712
713 inline void WriteMode(RelocInfo::Mode rmode);
714 inline void WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode);
715 inline void WriteIntData(int data_delta);
716 inline void WriteData(intptr_t data_delta);
717 inline void WritePosition(int pc_delta, int pos_delta, RelocInfo::Mode rmode);
718
719 void FlushPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000720
721 byte* pos_;
722 byte* last_pc_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000723 int last_id_;
724 int last_position_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000725 RelocInfo::Mode last_mode_;
726 int next_position_candidate_pos_delta_;
727 uint32_t next_position_candidate_pc_delta_;
728 bool next_position_candidate_flushed_;
729
Steve Blocka7e24c12009-10-30 11:49:00 +0000730 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
731};
732
733
734// A RelocIterator iterates over relocation information.
735// Typical use:
736//
737// for (RelocIterator it(code); !it.done(); it.next()) {
738// // do something with it.rinfo() here
739// }
740//
741// A mask can be specified to skip unwanted modes.
742class RelocIterator: public Malloced {
743 public:
744 // Create a new iterator positioned at
745 // the beginning of the reloc info.
746 // Relocation information with mode k is included in the
747 // iteration iff bit k of mode_mask is set.
748 explicit RelocIterator(Code* code, int mode_mask = -1);
749 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
750
751 // Iteration
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100752 bool done() const { return done_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000753 void next();
754
755 // Return pointer valid until next next().
756 RelocInfo* rinfo() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000757 DCHECK(!done());
Steve Blocka7e24c12009-10-30 11:49:00 +0000758 return &rinfo_;
759 }
760
761 private:
762 // Advance* moves the position before/after reading.
763 // *Read* reads from current byte(s) into rinfo_.
764 // *Get* just reads and returns info on current byte.
765 void Advance(int bytes = 1) { pos_ -= bytes; }
766 int AdvanceGetTag();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000767 RelocInfo::Mode GetMode();
768
769 void AdvanceReadLongPCJump();
770
771 int GetShortDataTypeTag();
772 void ReadShortTaggedPC();
773 void ReadShortTaggedId();
774 void ReadShortTaggedPosition();
775 void ReadShortTaggedData();
776
Steve Blocka7e24c12009-10-30 11:49:00 +0000777 void AdvanceReadPC();
Ben Murdoch257744e2011-11-30 15:57:28 +0000778 void AdvanceReadId();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000779 void AdvanceReadInt();
Ben Murdoch257744e2011-11-30 15:57:28 +0000780 void AdvanceReadPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000781 void AdvanceReadData();
Steve Blocka7e24c12009-10-30 11:49:00 +0000782
783 // If the given mode is wanted, set it in rinfo_ and return true.
784 // Else return false. Used for efficiently skipping unwanted modes.
785 bool SetMode(RelocInfo::Mode mode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100786 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000787 }
788
789 byte* pos_;
790 byte* end_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000791 byte* code_age_sequence_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000792 RelocInfo rinfo_;
793 bool done_;
794 int mode_mask_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000795 int last_id_;
796 int last_position_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000797 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
798};
799
800
801//------------------------------------------------------------------------------
802// External function
803
804//----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000805class SCTableReference;
Steve Blocka7e24c12009-10-30 11:49:00 +0000806class Debug_Address;
Steve Blocka7e24c12009-10-30 11:49:00 +0000807
808
Steve Blocka7e24c12009-10-30 11:49:00 +0000809// An ExternalReference represents a C++ address used in the generated
810// code. All references to C++ functions and variables must be encapsulated in
811// an ExternalReference instance. This is done in order to track the origin of
812// all external references in the code so that they can be bound to the correct
813// addresses when deserializing a heap.
814class ExternalReference BASE_EMBEDDED {
815 public:
Steve Block1e0659c2011-05-24 12:43:12 +0100816 // Used in the simulator to support different native api calls.
Steve Block1e0659c2011-05-24 12:43:12 +0100817 enum Type {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100818 // Builtin call.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000819 // Object* f(v8::internal::Arguments).
Steve Block1e0659c2011-05-24 12:43:12 +0100820 BUILTIN_CALL, // default
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100821
Ben Murdoch257744e2011-11-30 15:57:28 +0000822 // Builtin that takes float arguments and returns an int.
823 // int f(double, double).
824 BUILTIN_COMPARE_CALL,
825
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100826 // Builtin call that returns floating point.
827 // double f(double, double).
Ben Murdoch257744e2011-11-30 15:57:28 +0000828 BUILTIN_FP_FP_CALL,
829
830 // Builtin call that returns floating point.
831 // double f(double).
832 BUILTIN_FP_CALL,
833
834 // Builtin call that returns floating point.
835 // double f(double, int).
836 BUILTIN_FP_INT_CALL,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100837
838 // Direct call to API function callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000839 // void f(v8::FunctionCallbackInfo&)
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100840 DIRECT_API_CALL,
841
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000842 // Call to function callback via InvokeFunctionCallback.
843 // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
844 PROFILING_API_CALL,
845
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100846 // Direct call to accessor getter callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000847 // void f(Local<Name> property, PropertyCallbackInfo& info)
848 DIRECT_GETTER_CALL,
849
850 // Call to accessor getter callback via InvokeAccessorGetterCallback.
851 // void f(Local<Name> property, PropertyCallbackInfo& info,
852 // AccessorNameGetterCallback callback)
853 PROFILING_GETTER_CALL
Steve Block1e0659c2011-05-24 12:43:12 +0100854 };
855
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000856 static void SetUp();
857 static void InitializeMathExpData();
858 static void TearDownMathExpData();
859
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000860 typedef void* ExternalReferenceRedirector(Isolate* isolate, void* original,
861 Type type);
Steve Block1e0659c2011-05-24 12:43:12 +0100862
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000863 ExternalReference() : address_(NULL) {}
864
Steve Block44f0eee2011-05-26 01:26:41 +0100865 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000866
Steve Block44f0eee2011-05-26 01:26:41 +0100867 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000868
Steve Block44f0eee2011-05-26 01:26:41 +0100869 ExternalReference(Builtins::Name name, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000870
Steve Block44f0eee2011-05-26 01:26:41 +0100871 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000872
Steve Block44f0eee2011-05-26 01:26:41 +0100873 ExternalReference(const Runtime::Function* f, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000874
Steve Blocka7e24c12009-10-30 11:49:00 +0000875 explicit ExternalReference(StatsCounter* counter);
876
Steve Block44f0eee2011-05-26 01:26:41 +0100877 ExternalReference(Isolate::AddressId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000878
879 explicit ExternalReference(const SCTableReference& table_ref);
880
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000881 // Isolate as an external reference.
882 static ExternalReference isolate_address(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100883
Steve Blocka7e24c12009-10-30 11:49:00 +0000884 // One-of-a-kind references. These references are not part of a general
885 // pattern. This means that they have to be added to the
886 // ExternalReferenceTable in serialize.cc manually.
887
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100888 static ExternalReference incremental_marking_record_write_function(
889 Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100890 static ExternalReference store_buffer_overflow_function(
891 Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100892 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000893
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100894 static ExternalReference get_date_field_function(Isolate* isolate);
895 static ExternalReference date_cache_stamp(Isolate* isolate);
896
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000897 static ExternalReference get_make_code_young_function(Isolate* isolate);
898 static ExternalReference get_mark_code_as_executed_function(Isolate* isolate);
899
Ben Murdochb0fe1622011-05-05 13:52:32 +0100900 // Deoptimization support.
Steve Block44f0eee2011-05-26 01:26:41 +0100901 static ExternalReference new_deoptimizer_function(Isolate* isolate);
902 static ExternalReference compute_output_frames_function(Isolate* isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100903
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000904 // Log support.
905 static ExternalReference log_enter_external_function(Isolate* isolate);
906 static ExternalReference log_leave_external_function(Isolate* isolate);
907
Leon Clarkee46be812010-01-19 14:06:41 +0000908 // Static data in the keyed lookup cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100909 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
910 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000911
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100912 // Static variable Heap::roots_array_start()
913 static ExternalReference roots_array_start(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000914
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000915 // Static variable Heap::allocation_sites_list_address()
916 static ExternalReference allocation_sites_list_address(Isolate* isolate);
917
Steve Blocka7e24c12009-10-30 11:49:00 +0000918 // Static variable StackGuard::address_of_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100919 static ExternalReference address_of_stack_limit(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000920
921 // Static variable StackGuard::address_of_real_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100922 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000923
924 // Static variable RegExpStack::limit_address()
Steve Block44f0eee2011-05-26 01:26:41 +0100925 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000926
Leon Clarkee46be812010-01-19 14:06:41 +0000927 // Static variables for RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100928 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
929 static ExternalReference address_of_regexp_stack_memory_address(
930 Isolate* isolate);
931 static ExternalReference address_of_regexp_stack_memory_size(
932 Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000933
Steve Blocka7e24c12009-10-30 11:49:00 +0000934 // Static variable Heap::NewSpaceStart()
Steve Block44f0eee2011-05-26 01:26:41 +0100935 static ExternalReference new_space_start(Isolate* isolate);
936 static ExternalReference new_space_mask(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100937
938 // Write barrier.
939 static ExternalReference store_buffer_top(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000940
941 // Used for fast allocation in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100942 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
943 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 static ExternalReference old_space_allocation_top_address(Isolate* isolate);
945 static ExternalReference old_space_allocation_limit_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000946
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000947 static ExternalReference mod_two_doubles_operation(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100948 static ExternalReference power_double_double_function(Isolate* isolate);
949 static ExternalReference power_double_int_function(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000950
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000951 static ExternalReference handle_scope_next_address(Isolate* isolate);
952 static ExternalReference handle_scope_limit_address(Isolate* isolate);
953 static ExternalReference handle_scope_level_address(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000954
Steve Block44f0eee2011-05-26 01:26:41 +0100955 static ExternalReference scheduled_exception_address(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000956 static ExternalReference address_of_pending_message_obj(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000957
Ben Murdochb0fe1622011-05-05 13:52:32 +0100958 // Static variables containing common double constants.
959 static ExternalReference address_of_min_int();
960 static ExternalReference address_of_one_half();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000961 static ExternalReference address_of_minus_one_half();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100962 static ExternalReference address_of_negative_infinity();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000963 static ExternalReference address_of_the_hole_nan();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000964 static ExternalReference address_of_uint32_bias();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100965
Steve Block44f0eee2011-05-26 01:26:41 +0100966 static ExternalReference math_log_double_function(Isolate* isolate);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100967
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000968 static ExternalReference math_exp_constants(int constant_index);
969 static ExternalReference math_exp_log_table();
Steve Blocka7e24c12009-10-30 11:49:00 +0000970
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000971 static ExternalReference page_flags(Page* page);
972
973 static ExternalReference ForDeoptEntry(Address entry);
974
975 static ExternalReference cpu_features();
976
977 static ExternalReference debug_is_active_address(Isolate* isolate);
978 static ExternalReference debug_after_break_target_address(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000979
980 static ExternalReference is_profiling_address(Isolate* isolate);
981 static ExternalReference invoke_function_callback(Isolate* isolate);
982 static ExternalReference invoke_accessor_getter_callback(Isolate* isolate);
983
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000984 static ExternalReference virtual_handler_register(Isolate* isolate);
985 static ExternalReference virtual_slot_register(Isolate* isolate);
986
987 static ExternalReference runtime_function_table_address(Isolate* isolate);
988
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000989 Address address() const { return reinterpret_cast<Address>(address_); }
990
Steve Blocka7e24c12009-10-30 11:49:00 +0000991 // Used to check if single stepping is enabled in generated code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000992 static ExternalReference debug_step_in_enabled_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000993
Steve Block6ded16b2010-05-10 14:33:55 +0100994#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +0000995 // C functions called from RegExp generated code.
996
997 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
Steve Block44f0eee2011-05-26 01:26:41 +0100998 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000999
1000 // Function RegExpMacroAssembler*::CheckStackGuardState()
Steve Block44f0eee2011-05-26 01:26:41 +01001001 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001002
1003 // Function NativeRegExpMacroAssembler::GrowStack()
Steve Block44f0eee2011-05-26 01:26:41 +01001004 static ExternalReference re_grow_stack(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +00001005
1006 // byte NativeRegExpMacroAssembler::word_character_bitmap
1007 static ExternalReference re_word_character_map();
1008
Steve Blocka7e24c12009-10-30 11:49:00 +00001009#endif
1010
1011 // This lets you register a function that rewrites all external references.
1012 // Used by the ARM simulator to catch calls to external references.
Ben Murdoch257744e2011-11-30 15:57:28 +00001013 static void set_redirector(Isolate* isolate,
1014 ExternalReferenceRedirector* redirector) {
Steve Block44f0eee2011-05-26 01:26:41 +01001015 // We can't stack them.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001016 DCHECK(isolate->external_reference_redirector() == NULL);
Ben Murdoch257744e2011-11-30 15:57:28 +00001017 isolate->set_external_reference_redirector(
Steve Block44f0eee2011-05-26 01:26:41 +01001018 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
Steve Blocka7e24c12009-10-30 11:49:00 +00001019 }
1020
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001021 static ExternalReference stress_deopt_count(Isolate* isolate);
1022
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001023 static ExternalReference fixed_typed_array_base_data_offset();
1024
Steve Blocka7e24c12009-10-30 11:49:00 +00001025 private:
1026 explicit ExternalReference(void* address)
1027 : address_(address) {}
1028
Steve Block44f0eee2011-05-26 01:26:41 +01001029 static void* Redirect(Isolate* isolate,
Steve Block44f0eee2011-05-26 01:26:41 +01001030 Address address_arg,
Steve Block1e0659c2011-05-24 12:43:12 +01001031 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +01001032 ExternalReferenceRedirector* redirector =
1033 reinterpret_cast<ExternalReferenceRedirector*>(
1034 isolate->external_reference_redirector());
Steve Blocka7e24c12009-10-30 11:49:00 +00001035 void* address = reinterpret_cast<void*>(address_arg);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001036 void* answer =
1037 (redirector == NULL) ? address : (*redirector)(isolate, address, type);
Steve Blockd0582a62009-12-15 09:54:21 +00001038 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +00001039 }
1040
1041 void* address_;
1042};
1043
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001044bool operator==(ExternalReference, ExternalReference);
1045bool operator!=(ExternalReference, ExternalReference);
1046
1047size_t hash_value(ExternalReference);
1048
1049std::ostream& operator<<(std::ostream&, ExternalReference);
1050
Steve Blocka7e24c12009-10-30 11:49:00 +00001051
1052// -----------------------------------------------------------------------------
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001053// Position recording support
1054
Ben Murdochb0fe1622011-05-05 13:52:32 +01001055struct PositionState {
1056 PositionState() : current_position(RelocInfo::kNoPosition),
1057 written_position(RelocInfo::kNoPosition),
1058 current_statement_position(RelocInfo::kNoPosition),
1059 written_statement_position(RelocInfo::kNoPosition) {}
1060
1061 int current_position;
1062 int written_position;
1063
1064 int current_statement_position;
1065 int written_statement_position;
1066};
1067
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001068
1069class PositionsRecorder BASE_EMBEDDED {
1070 public:
1071 explicit PositionsRecorder(Assembler* assembler)
Ben Murdochb8e0da22011-05-16 14:20:40 +01001072 : assembler_(assembler) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001073 jit_handler_data_ = NULL;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001074 }
1075
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001076 void AttachJITHandlerData(void* user_data) {
1077 jit_handler_data_ = user_data;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001078 }
1079
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001080 void* DetachJITHandlerData() {
1081 void* old_data = jit_handler_data_;
1082 jit_handler_data_ = NULL;
1083 return old_data;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001084 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001085 // Set current position to pos.
1086 void RecordPosition(int pos);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001087
1088 // Set current statement position to pos.
1089 void RecordStatementPosition(int pos);
1090
1091 // Write recorded positions to relocation information.
1092 bool WriteRecordedPositions();
1093
Ben Murdochb0fe1622011-05-05 13:52:32 +01001094 int current_position() const { return state_.current_position; }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001095
Ben Murdochb0fe1622011-05-05 13:52:32 +01001096 int current_statement_position() const {
1097 return state_.current_statement_position;
1098 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001099
1100 private:
1101 Assembler* assembler_;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001102 PositionState state_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001103
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001104 // Currently jit_handler_data_ is used to store JITHandler-specific data
1105 // over the lifetime of a PositionsRecorder
1106 void* jit_handler_data_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001107
Ben Murdochb0fe1622011-05-05 13:52:32 +01001108 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001109};
1110
1111
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001112// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +00001113// Utility functions
1114
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001115inline int NumberOfBitsSet(uint32_t x) {
Andrei Popescu31002712010-02-23 13:46:05 +00001116 unsigned int num_bits_set;
1117 for (num_bits_set = 0; x; x >>= 1) {
1118 num_bits_set += x & 1;
1119 }
1120 return num_bits_set;
1121}
Steve Blocka7e24c12009-10-30 11:49:00 +00001122
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001123bool EvalComparison(Token::Value op, double op1, double op2);
1124
Ben Murdochb0fe1622011-05-05 13:52:32 +01001125// Computes pow(x, y) with the special cases in the spec for Math.pow.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001126double power_helper(Isolate* isolate, double x, double y);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001127double power_double_int(double x, int y);
1128double power_double_double(double x, double y);
1129
Ben Murdoch257744e2011-11-30 15:57:28 +00001130// Helper class for generating code or data associated with the code
1131// right after a call instruction. As an example this can be used to
1132// generate safepoint data after calls for crankshaft.
1133class CallWrapper {
1134 public:
1135 CallWrapper() { }
1136 virtual ~CallWrapper() { }
1137 // Called just before emitting a call. Argument is the size of the generated
1138 // call code.
1139 virtual void BeforeCall(int call_size) const = 0;
1140 // Called just after emitting a call, i.e., at the return site for the call.
1141 virtual void AfterCall() const = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001142 // Return whether call needs to check for debug stepping.
1143 virtual bool NeedsDebugStepCheck() const { return false; }
Ben Murdoch257744e2011-11-30 15:57:28 +00001144};
1145
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001146
Ben Murdoch257744e2011-11-30 15:57:28 +00001147class NullCallWrapper : public CallWrapper {
1148 public:
1149 NullCallWrapper() { }
1150 virtual ~NullCallWrapper() { }
1151 virtual void BeforeCall(int call_size) const { }
1152 virtual void AfterCall() const { }
1153};
1154
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001155
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001156class CheckDebugStepCallWrapper : public CallWrapper {
1157 public:
1158 CheckDebugStepCallWrapper() {}
1159 virtual ~CheckDebugStepCallWrapper() {}
1160 virtual void BeforeCall(int call_size) const {}
1161 virtual void AfterCall() const {}
1162 virtual bool NeedsDebugStepCheck() const { return true; }
1163};
Steve Blocka7e24c12009-10-30 11:49:00 +00001164
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001165
1166// -----------------------------------------------------------------------------
1167// Constant pool support
1168
1169class ConstantPoolEntry {
1170 public:
1171 ConstantPoolEntry() {}
1172 ConstantPoolEntry(int position, intptr_t value, bool sharing_ok)
1173 : position_(position),
1174 merged_index_(sharing_ok ? SHARING_ALLOWED : SHARING_PROHIBITED),
1175 value_(value) {}
1176 ConstantPoolEntry(int position, double value)
1177 : position_(position), merged_index_(SHARING_ALLOWED), value64_(value) {}
1178
1179 int position() const { return position_; }
1180 bool sharing_ok() const { return merged_index_ != SHARING_PROHIBITED; }
1181 bool is_merged() const { return merged_index_ >= 0; }
1182 int merged_index(void) const {
1183 DCHECK(is_merged());
1184 return merged_index_;
1185 }
1186 void set_merged_index(int index) {
1187 merged_index_ = index;
1188 DCHECK(is_merged());
1189 }
1190 int offset(void) const {
1191 DCHECK(merged_index_ >= 0);
1192 return merged_index_;
1193 }
1194 void set_offset(int offset) {
1195 DCHECK(offset >= 0);
1196 merged_index_ = offset;
1197 }
1198 intptr_t value() const { return value_; }
1199 uint64_t value64() const { return bit_cast<uint64_t>(value64_); }
1200
1201 enum Type { INTPTR, DOUBLE, NUMBER_OF_TYPES };
1202
1203 static int size(Type type) {
1204 return (type == INTPTR) ? kPointerSize : kDoubleSize;
1205 }
1206
1207 enum Access { REGULAR, OVERFLOWED };
1208
1209 private:
1210 int position_;
1211 int merged_index_;
1212 union {
1213 intptr_t value_;
1214 double value64_;
1215 };
1216 enum { SHARING_PROHIBITED = -2, SHARING_ALLOWED = -1 };
1217};
1218
1219
1220// -----------------------------------------------------------------------------
1221// Embedded constant pool support
1222
1223class ConstantPoolBuilder BASE_EMBEDDED {
1224 public:
1225 ConstantPoolBuilder(int ptr_reach_bits, int double_reach_bits);
1226
1227 // Add pointer-sized constant to the embedded constant pool
1228 ConstantPoolEntry::Access AddEntry(int position, intptr_t value,
1229 bool sharing_ok) {
1230 ConstantPoolEntry entry(position, value, sharing_ok);
1231 return AddEntry(entry, ConstantPoolEntry::INTPTR);
1232 }
1233
1234 // Add double constant to the embedded constant pool
1235 ConstantPoolEntry::Access AddEntry(int position, double value) {
1236 ConstantPoolEntry entry(position, value);
1237 return AddEntry(entry, ConstantPoolEntry::DOUBLE);
1238 }
1239
1240 // Previews the access type required for the next new entry to be added.
1241 ConstantPoolEntry::Access NextAccess(ConstantPoolEntry::Type type) const;
1242
1243 bool IsEmpty() {
1244 return info_[ConstantPoolEntry::INTPTR].entries.empty() &&
1245 info_[ConstantPoolEntry::INTPTR].shared_entries.empty() &&
1246 info_[ConstantPoolEntry::DOUBLE].entries.empty() &&
1247 info_[ConstantPoolEntry::DOUBLE].shared_entries.empty();
1248 }
1249
1250 // Emit the constant pool. Invoke only after all entries have been
1251 // added and all instructions have been emitted.
1252 // Returns position of the emitted pool (zero implies no constant pool).
1253 int Emit(Assembler* assm);
1254
1255 // Returns the label associated with the start of the constant pool.
1256 // Linking to this label in the function prologue may provide an
1257 // efficient means of constant pool pointer register initialization
1258 // on some architectures.
1259 inline Label* EmittedPosition() { return &emitted_label_; }
1260
1261 private:
1262 ConstantPoolEntry::Access AddEntry(ConstantPoolEntry& entry,
1263 ConstantPoolEntry::Type type);
1264 void EmitSharedEntries(Assembler* assm, ConstantPoolEntry::Type type);
1265 void EmitGroup(Assembler* assm, ConstantPoolEntry::Access access,
1266 ConstantPoolEntry::Type type);
1267
1268 struct PerTypeEntryInfo {
1269 PerTypeEntryInfo() : regular_count(0), overflow_start(-1) {}
1270 bool overflow() const {
1271 return (overflow_start >= 0 &&
1272 overflow_start < static_cast<int>(entries.size()));
1273 }
1274 int regular_reach_bits;
1275 int regular_count;
1276 int overflow_start;
1277 std::vector<ConstantPoolEntry> entries;
1278 std::vector<ConstantPoolEntry> shared_entries;
1279 };
1280
1281 Label emitted_label_; // Records pc_offset of emitted pool
1282 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES];
1283};
1284
1285} // namespace internal
1286} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001287#endif // V8_ASSEMBLER_H_