blob: 7bd9ee65f2c98c7622e34df862d4d72f5d9bee95 [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"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040041#include "src/runtime/runtime.h"
Steve Blocka7e24c12009-10-30 11:49:00 +000042
43namespace v8 {
Ben Murdoch3ef787d2012-04-12 10:51:47 +010044
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000045// Forward declarations.
Ben Murdoch3ef787d2012-04-12 10:51:47 +010046class ApiFunction;
47
Steve Blocka7e24c12009-10-30 11:49:00 +000048namespace internal {
49
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000050// Forward declarations.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000051class StatsCounter;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000052
Steve Blocka7e24c12009-10-30 11:49:00 +000053// -----------------------------------------------------------------------------
Steve Block44f0eee2011-05-26 01:26:41 +010054// Platform independent assembler base class.
55
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000056enum class CodeObjectRequired { kNo, kYes };
57
58
Steve Block44f0eee2011-05-26 01:26:41 +010059class AssemblerBase: public Malloced {
60 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000061 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size);
62 virtual ~AssemblerBase();
Steve Block44f0eee2011-05-26 01:26:41 +010063
64 Isolate* isolate() const { return isolate_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000065 int jit_cookie() const { return jit_cookie_; }
66
67 bool emit_debug_code() const { return emit_debug_code_; }
68 void set_emit_debug_code(bool value) { emit_debug_code_ = value; }
69
70 bool serializer_enabled() const { return serializer_enabled_; }
71 void enable_serializer() { serializer_enabled_ = true; }
72
73 bool predictable_code_size() const { return predictable_code_size_; }
74 void set_predictable_code_size(bool value) { predictable_code_size_ = value; }
75
76 uint64_t enabled_cpu_features() const { return enabled_cpu_features_; }
77 void set_enabled_cpu_features(uint64_t features) {
78 enabled_cpu_features_ = features;
79 }
80 bool IsEnabled(CpuFeature f) {
81 return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
82 }
Steve Block44f0eee2011-05-26 01:26:41 +010083
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000084 bool is_constant_pool_available() const {
85 if (FLAG_enable_embedded_constant_pool) {
86 return constant_pool_available_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040087 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000088 // Embedded constant pool not supported on this architecture.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040089 UNREACHABLE();
90 return false;
91 }
92 }
93
Ben Murdochdb1b4382012-04-26 19:03:50 +010094 // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
95 // cross-snapshotting.
96 static void QuietNaN(HeapObject* nan) { }
97
Ben Murdochb8a8cc12014-11-26 15:28:44 +000098 int pc_offset() const { return static_cast<int>(pc_ - buffer_); }
99
100 // This function is called when code generation is aborted, so that
101 // the assembler could clean up internal data structures.
102 virtual void AbortedCodeGeneration() { }
103
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000104 // Debugging
105 void Print();
106
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 static const int kMinimalBufferSize = 4*KB;
108
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000109 static void FlushICache(Isolate* isolate, void* start, size_t size);
110
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000111 protected:
112 // The buffer into which code and relocation info are generated. It could
113 // either be owned by the assembler or be provided externally.
114 byte* buffer_;
115 int buffer_size_;
116 bool own_buffer_;
117
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118 void set_constant_pool_available(bool available) {
119 if (FLAG_enable_embedded_constant_pool) {
120 constant_pool_available_ = available;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400121 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000122 // Embedded constant pool not supported on this architecture.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400123 UNREACHABLE();
124 }
125 }
126
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000127 // The program counter, which points into the buffer above and moves forward.
128 byte* pc_;
129
Steve Block44f0eee2011-05-26 01:26:41 +0100130 private:
131 Isolate* isolate_;
Steve Block053d10c2011-06-13 19:13:29 +0100132 int jit_cookie_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000133 uint64_t enabled_cpu_features_;
134 bool emit_debug_code_;
135 bool predictable_code_size_;
136 bool serializer_enabled_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400137
138 // Indicates whether the constant pool can be accessed, which is only possible
139 // if the pp register points to the current code object's constant pool.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000140 bool constant_pool_available_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400141
142 // Constant pool.
143 friend class FrameAndConstantPoolScope;
144 friend class ConstantPoolUnavailableScope;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000145};
146
147
148// Avoids emitting debug code during the lifetime of this scope object.
149class DontEmitDebugCodeScope BASE_EMBEDDED {
150 public:
151 explicit DontEmitDebugCodeScope(AssemblerBase* assembler)
152 : assembler_(assembler), old_value_(assembler->emit_debug_code()) {
153 assembler_->set_emit_debug_code(false);
154 }
155 ~DontEmitDebugCodeScope() {
156 assembler_->set_emit_debug_code(old_value_);
157 }
158 private:
159 AssemblerBase* assembler_;
160 bool old_value_;
161};
162
163
164// Avoids using instructions that vary in size in unpredictable ways between the
165// snapshot and the running VM.
166class PredictableCodeSizeScope {
167 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000168 explicit PredictableCodeSizeScope(AssemblerBase* assembler);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000169 PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size);
170 ~PredictableCodeSizeScope();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000171 void ExpectSize(int expected_size) { expected_size_ = expected_size; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000172
173 private:
174 AssemblerBase* assembler_;
175 int expected_size_;
176 int start_offset_;
177 bool old_value_;
178};
179
180
181// Enable a specified feature within a scope.
182class CpuFeatureScope BASE_EMBEDDED {
183 public:
184#ifdef DEBUG
185 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f);
186 ~CpuFeatureScope();
187
188 private:
189 AssemblerBase* assembler_;
190 uint64_t old_enabled_;
191#else
192 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {}
193#endif
194};
195
196
197// CpuFeatures keeps track of which features are supported by the target CPU.
198// Supported features must be enabled by a CpuFeatureScope before use.
199// Example:
200// if (assembler->IsSupported(SSE3)) {
201// CpuFeatureScope fscope(assembler, SSE3);
202// // Generate code containing SSE3 instructions.
203// } else {
204// // Generate alternative code.
205// }
206class CpuFeatures : public AllStatic {
207 public:
208 static void Probe(bool cross_compile) {
209 STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt);
210 if (initialized_) return;
211 initialized_ = true;
212 ProbeImpl(cross_compile);
213 }
214
215 static unsigned SupportedFeatures() {
216 Probe(false);
217 return supported_;
218 }
219
220 static bool IsSupported(CpuFeature f) {
221 return (supported_ & (1u << f)) != 0;
222 }
223
224 static inline bool SupportsCrankshaft();
225
Ben Murdoch097c5b22016-05-18 11:27:45 +0100226 static inline unsigned icache_line_size() {
227 DCHECK(icache_line_size_ != 0);
228 return icache_line_size_;
229 }
230
231 static inline unsigned dcache_line_size() {
232 DCHECK(dcache_line_size_ != 0);
233 return dcache_line_size_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000234 }
235
236 static void PrintTarget();
237 static void PrintFeatures();
238
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239 private:
240 friend class ExternalReference;
241 friend class AssemblerBase;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000242 // Flush instruction cache.
243 static void FlushICache(void* start, size_t size);
244
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000245 // Platform-dependent implementation.
246 static void ProbeImpl(bool cross_compile);
247
248 static unsigned supported_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100249 static unsigned icache_line_size_;
250 static unsigned dcache_line_size_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000251 static bool initialized_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252 DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
Steve Block44f0eee2011-05-26 01:26:41 +0100253};
254
Ben Murdochb0fe1622011-05-05 13:52:32 +0100255
256// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000257// Labels represent pc locations; they are typically jump or call targets.
258// After declaration, a label can be freely used to denote known or (yet)
259// unknown pc location. Assembler::bind() is used to bind a label to the
260// current pc. A label can be bound only once.
261
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400262class Label {
Steve Blocka7e24c12009-10-30 11:49:00 +0000263 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000264 enum Distance {
265 kNear, kFar
266 };
267
268 INLINE(Label()) {
269 Unuse();
270 UnuseNear();
271 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000272
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000273 INLINE(~Label()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000274 DCHECK(!is_linked());
275 DCHECK(!is_near_linked());
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000276 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000277
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000278 INLINE(void Unuse()) { pos_ = 0; }
279 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
280
281 INLINE(bool is_bound() const) { return pos_ < 0; }
282 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
283 INLINE(bool is_linked() const) { return pos_ > 0; }
Ben Murdoch257744e2011-11-30 15:57:28 +0000284 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000285
286 // Returns the position of bound or linked labels. Cannot be used
287 // for unused labels.
288 int pos() const;
Ben Murdoch257744e2011-11-30 15:57:28 +0000289 int near_link_pos() const { return near_link_pos_ - 1; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000290
291 private:
292 // pos_ encodes both the binding state (via its sign)
293 // and the binding position (via its value) of a label.
294 //
295 // pos_ < 0 bound label, pos() returns the jump target position
296 // pos_ == 0 unused label
297 // pos_ > 0 linked label, pos() returns the last reference position
298 int pos_;
299
Ben Murdoch257744e2011-11-30 15:57:28 +0000300 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
301 int near_link_pos_;
302
Steve Blocka7e24c12009-10-30 11:49:00 +0000303 void bind_to(int pos) {
304 pos_ = -pos - 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000305 DCHECK(is_bound());
Steve Blocka7e24c12009-10-30 11:49:00 +0000306 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000307 void link_to(int pos, Distance distance = kFar) {
308 if (distance == kNear) {
309 near_link_pos_ = pos + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000310 DCHECK(is_near_linked());
Ben Murdoch257744e2011-11-30 15:57:28 +0000311 } else {
312 pos_ = pos + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000313 DCHECK(is_linked());
Ben Murdoch257744e2011-11-30 15:57:28 +0000314 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000315 }
316
317 friend class Assembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000318 friend class Displacement;
Steve Blocka7e24c12009-10-30 11:49:00 +0000319 friend class RegExpMacroAssemblerIrregexp;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000320
321#if V8_TARGET_ARCH_ARM64
322 // On ARM64, the Assembler keeps track of pointers to Labels to resolve
323 // branches to distant targets. Copying labels would confuse the Assembler.
324 DISALLOW_COPY_AND_ASSIGN(Label); // NOLINT
325#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000326};
327
328
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100329enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
330
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000331enum ArgvMode { kArgvOnStack, kArgvInRegister };
332
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000333// Specifies whether to perform icache flush operations on RelocInfo updates.
334// If FLUSH_ICACHE_IF_NEEDED, the icache will always be flushed if an
335// instruction was modified. If SKIP_ICACHE_FLUSH the flush will always be
336// skipped (only use this if you will flush the icache manually before it is
337// executed).
338enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH };
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100339
Steve Blocka7e24c12009-10-30 11:49:00 +0000340// -----------------------------------------------------------------------------
341// Relocation information
342
343
344// Relocation information consists of the address (pc) of the datum
345// to which the relocation information applies, the relocation mode
346// (rmode), and an optional data field. The relocation mode may be
347// "descriptive" and not indicate a need for relocation, but simply
348// describe a property of the datum. Such rmodes are useful for GC
349// and nice disassembly output.
350
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000351class RelocInfo {
Steve Blocka7e24c12009-10-30 11:49:00 +0000352 public:
353 // The constant kNoPosition is used with the collecting of source positions
354 // in the relocation information. Two types of source positions are collected
355 // "position" (RelocMode position) and "statement position" (RelocMode
356 // statement_position). The "position" is collected at places in the source
357 // code which are of interest when making stack traces to pin-point the source
358 // location of a stack frame as close as possible. The "statement position" is
359 // collected at the beginning at each statement, and is used to indicate
360 // possible break locations. kNoPosition is used to indicate an
361 // invalid/uninitialized position value.
362 static const int kNoPosition = -1;
363
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100364 // This string is used to add padding comments to the reloc info in cases
365 // where we are not sure to have enough space for patching in during
366 // lazy deoptimization. This is the case if we have indirect calls for which
367 // we do not normally record relocation info.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000368 static const char* const kFillerCommentString;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100369
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000370 // The minimum size of a comment is equal to two bytes for the extra tagged
371 // pc and kPointerSize for the actual pointer to the comment.
372 static const int kMinRelocCommentSize = 2 + kPointerSize;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100373
374 // The maximum size for a call instruction including pc-jump.
375 static const int kMaxCallSize = 6;
376
Steve Block44f0eee2011-05-26 01:26:41 +0100377 // The maximum pc delta that will use the short encoding.
378 static const int kMaxSmallPCDelta;
379
Steve Blocka7e24c12009-10-30 11:49:00 +0000380 enum Mode {
381 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
Ben Murdoch257744e2011-11-30 15:57:28 +0000382 CODE_TARGET, // Code target which is not any of the above.
383 CODE_TARGET_WITH_ID,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000384 DEBUGGER_STATEMENT, // Code target for the debugger statement.
Steve Blocka7e24c12009-10-30 11:49:00 +0000385 EMBEDDED_OBJECT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000386 CELL,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100387
Steve Blocka7e24c12009-10-30 11:49:00 +0000388 // Everything after runtime_entry (inclusive) is not GC'ed.
389 RUNTIME_ENTRY,
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 COMMENT,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000391 POSITION, // See comment for kNoPosition above.
Steve Blocka7e24c12009-10-30 11:49:00 +0000392 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000393
394 // Additional code inserted for debug break slot.
395 DEBUG_BREAK_SLOT_AT_POSITION,
396 DEBUG_BREAK_SLOT_AT_RETURN,
397 DEBUG_BREAK_SLOT_AT_CALL,
398
Steve Blocka7e24c12009-10-30 11:49:00 +0000399 EXTERNAL_REFERENCE, // The address of an external C++ function.
400 INTERNAL_REFERENCE, // An address inside the same function.
401
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000402 // Encoded internal reference, used only on MIPS, MIPS64 and PPC.
403 INTERNAL_REFERENCE_ENCODED,
404
405 // Continuation points for a generator yield.
406 GENERATOR_CONTINUATION,
407
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000408 // Marks constant and veneer pools. Only used on ARM and ARM64.
409 // They use a custom noncompact encoding.
410 CONST_POOL,
411 VENEER_POOL,
412
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000413 DEOPT_REASON, // Deoptimization reason index.
414
415 // This is not an actual reloc mode, but used to encode a long pc jump that
416 // cannot be encoded as part of another record.
417 PC_JUMP,
418
Steve Blocka7e24c12009-10-30 11:49:00 +0000419 // Pseudo-types
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000420 NUMBER_OF_MODES,
421 NONE32, // never recorded 32-bit value
422 NONE64, // never recorded 64-bit value
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000423 CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by
424 // code aging.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000425
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000426 FIRST_REAL_RELOC_MODE = CODE_TARGET,
427 LAST_REAL_RELOC_MODE = VENEER_POOL,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000428 LAST_CODE_ENUM = DEBUGGER_STATEMENT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000429 LAST_GCED_ENUM = CELL,
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 };
431
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000432 STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000434 explicit RelocInfo(Isolate* isolate) : isolate_(isolate) {
435 DCHECK_NOT_NULL(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000436 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437
438 RelocInfo(Isolate* isolate, byte* pc, Mode rmode, intptr_t data, Code* host)
439 : isolate_(isolate), pc_(pc), rmode_(rmode), data_(data), host_(host) {
440 DCHECK_NOT_NULL(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000441 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000442
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000443 static inline bool IsRealRelocMode(Mode mode) {
444 return mode >= FIRST_REAL_RELOC_MODE &&
445 mode <= LAST_REAL_RELOC_MODE;
446 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000447 static inline bool IsCodeTarget(Mode mode) {
448 return mode <= LAST_CODE_ENUM;
449 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100450 static inline bool IsEmbeddedObject(Mode mode) {
451 return mode == EMBEDDED_OBJECT;
452 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000453 static inline bool IsCell(Mode mode) { return mode == CELL; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000454 static inline bool IsRuntimeEntry(Mode mode) {
455 return mode == RUNTIME_ENTRY;
456 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000457 // Is the relocation mode affected by GC?
458 static inline bool IsGCRelocMode(Mode mode) {
459 return mode <= LAST_GCED_ENUM;
460 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000461 static inline bool IsComment(Mode mode) {
462 return mode == COMMENT;
463 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000464 static inline bool IsConstPool(Mode mode) {
465 return mode == CONST_POOL;
466 }
467 static inline bool IsVeneerPool(Mode mode) {
468 return mode == VENEER_POOL;
469 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000470 static inline bool IsDeoptReason(Mode mode) {
471 return mode == DEOPT_REASON;
472 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000473 static inline bool IsPosition(Mode mode) {
474 return mode == POSITION || mode == STATEMENT_POSITION;
475 }
476 static inline bool IsStatementPosition(Mode mode) {
477 return mode == STATEMENT_POSITION;
478 }
479 static inline bool IsExternalReference(Mode mode) {
480 return mode == EXTERNAL_REFERENCE;
481 }
482 static inline bool IsInternalReference(Mode mode) {
483 return mode == INTERNAL_REFERENCE;
484 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000485 static inline bool IsInternalReferenceEncoded(Mode mode) {
486 return mode == INTERNAL_REFERENCE_ENCODED;
487 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100488 static inline bool IsDebugBreakSlot(Mode mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000489 return IsDebugBreakSlotAtPosition(mode) || IsDebugBreakSlotAtReturn(mode) ||
490 IsDebugBreakSlotAtCall(mode);
491 }
492 static inline bool IsDebugBreakSlotAtPosition(Mode mode) {
493 return mode == DEBUG_BREAK_SLOT_AT_POSITION;
494 }
495 static inline bool IsDebugBreakSlotAtReturn(Mode mode) {
496 return mode == DEBUG_BREAK_SLOT_AT_RETURN;
497 }
498 static inline bool IsDebugBreakSlotAtCall(Mode mode) {
499 return mode == DEBUG_BREAK_SLOT_AT_CALL;
500 }
501 static inline bool IsDebuggerStatement(Mode mode) {
502 return mode == DEBUGGER_STATEMENT;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100503 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000504 static inline bool IsNone(Mode mode) {
505 return mode == NONE32 || mode == NONE64;
506 }
507 static inline bool IsCodeAgeSequence(Mode mode) {
508 return mode == CODE_AGE_SEQUENCE;
509 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000510 static inline bool IsGeneratorContinuation(Mode mode) {
511 return mode == GENERATOR_CONTINUATION;
512 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000513 static inline int ModeMask(Mode mode) { return 1 << mode; }
514
515 // Accessors
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000516 Isolate* isolate() const { return isolate_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100517 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000518 void set_pc(byte* pc) { pc_ = pc; }
519 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100520 intptr_t data() const { return data_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100521 Code* host() const { return host_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000522 void set_host(Code* host) { host_ = host; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000523
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000524 // Apply a relocation by delta bytes. When the code object is moved, PC
525 // relative addresses have to be updated as well as absolute addresses
526 // inside the code (internal references).
527 // Do not forget to flush the icache afterwards!
528 INLINE(void apply(intptr_t delta));
Steve Blocka7e24c12009-10-30 11:49:00 +0000529
Leon Clarkef7060e22010-06-03 12:02:55 +0100530 // Is the pointer this relocation info refers to coded like a plain pointer
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100531 // or is it strange in some way (e.g. relative or patched into a series of
Leon Clarkef7060e22010-06-03 12:02:55 +0100532 // instructions).
533 bool IsCodedSpecially();
534
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000535 // If true, the pointer this relocation info refers to is an entry in the
536 // constant pool, otherwise the pointer is embedded in the instruction stream.
537 bool IsInConstantPool();
538
Steve Blocka7e24c12009-10-30 11:49:00 +0000539 // this relocation applies to;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000540 // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Steve Blocka7e24c12009-10-30 11:49:00 +0000541 INLINE(Address target_address());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100542 INLINE(void set_target_address(Address target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000543 WriteBarrierMode write_barrier_mode =
544 UPDATE_WRITE_BARRIER,
545 ICacheFlushMode icache_flush_mode =
546 FLUSH_ICACHE_IF_NEEDED));
Steve Blocka7e24c12009-10-30 11:49:00 +0000547 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000548 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100549 INLINE(void set_target_object(Object* target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000550 WriteBarrierMode write_barrier_mode =
551 UPDATE_WRITE_BARRIER,
552 ICacheFlushMode icache_flush_mode =
553 FLUSH_ICACHE_IF_NEEDED));
554 INLINE(Address target_runtime_entry(Assembler* origin));
555 INLINE(void set_target_runtime_entry(Address target,
556 WriteBarrierMode write_barrier_mode =
557 UPDATE_WRITE_BARRIER,
558 ICacheFlushMode icache_flush_mode =
559 FLUSH_ICACHE_IF_NEEDED));
560 INLINE(Cell* target_cell());
561 INLINE(Handle<Cell> target_cell_handle());
562 INLINE(void set_target_cell(Cell* cell,
563 WriteBarrierMode write_barrier_mode =
564 UPDATE_WRITE_BARRIER,
565 ICacheFlushMode icache_flush_mode =
566 FLUSH_ICACHE_IF_NEEDED));
567 INLINE(Handle<Object> code_age_stub_handle(Assembler* origin));
568 INLINE(Code* code_age_stub());
569 INLINE(void set_code_age_stub(Code* stub,
570 ICacheFlushMode icache_flush_mode =
571 FLUSH_ICACHE_IF_NEEDED));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100572
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000573 // Returns the address of the constant pool entry where the target address
574 // is held. This should only be called if IsInConstantPool returns true.
575 INLINE(Address constant_pool_entry_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000576
Leon Clarkef7060e22010-06-03 12:02:55 +0100577 // Read the address of the word containing the target_address in an
578 // instruction stream. What this means exactly is architecture-independent.
579 // The only architecture-independent user of this function is the serializer.
580 // The serializer uses it to find out how many raw bytes of instruction to
581 // output before the next target. Architecture-independent code shouldn't
582 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000583 INLINE(Address target_address_address());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000584
Leon Clarkef7060e22010-06-03 12:02:55 +0100585 // This indicates how much space a target takes up when deserializing a code
586 // stream. For most architectures this is just the size of a pointer. For
587 // an instruction like movw/movt where the target bits are mixed into the
588 // instruction bits the size of the target will be zero, indicating that the
589 // serializer should not step forwards in memory after a target is resolved
590 // and written. In this case the target_address_address function above
591 // should return the end of the instructions to be patched, allowing the
592 // deserializer to deserialize the instructions as raw bytes and put them in
593 // place, ready to be patched with the target.
594 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000595
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000596 // Read the reference in the instruction this relocation
597 // applies to; can only be called if rmode_ is EXTERNAL_REFERENCE.
598 INLINE(Address target_external_reference());
599
600 // Read the reference in the instruction this relocation
601 // applies to; can only be called if rmode_ is INTERNAL_REFERENCE.
602 INLINE(Address target_internal_reference());
603
604 // Return the reference address this relocation applies to;
605 // can only be called if rmode_ is INTERNAL_REFERENCE.
606 INLINE(Address target_internal_reference_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000607
608 // Read/modify the address of a call instruction. This is used to relocate
609 // the break points where straight-line code is patched with a call
610 // instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000611 INLINE(Address debug_call_address());
612 INLINE(void set_debug_call_address(Address target));
Steve Blocka7e24c12009-10-30 11:49:00 +0000613
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000614 // Wipe out a relocation to a fixed value, used for making snapshots
615 // reproducible.
616 INLINE(void WipeOut());
617
Steve Block44f0eee2011-05-26 01:26:41 +0100618 template<typename StaticVisitor> inline void Visit(Heap* heap);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000619 inline void Visit(Isolate* isolate, ObjectVisitor* v);
Leon Clarkef7060e22010-06-03 12:02:55 +0100620
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100621 // Check whether this debug break slot has been patched with a call to the
622 // debugger.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100623 bool IsPatchedDebugBreakSlotSequence();
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100624
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 Murdoch097c5b22016-05-18 11:27:45 +0100822 // Builtin call returning object pair.
823 // ObjectPair f(v8::internal::Arguments).
824 BUILTIN_CALL_PAIR,
825
826 // Builtin call that returns .
827 // ObjectTriple f(v8::internal::Arguments).
828 BUILTIN_CALL_TRIPLE,
829
Ben Murdoch257744e2011-11-30 15:57:28 +0000830 // Builtin that takes float arguments and returns an int.
831 // int f(double, double).
832 BUILTIN_COMPARE_CALL,
833
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100834 // Builtin call that returns floating point.
835 // double f(double, double).
Ben Murdoch257744e2011-11-30 15:57:28 +0000836 BUILTIN_FP_FP_CALL,
837
838 // Builtin call that returns floating point.
839 // double f(double).
840 BUILTIN_FP_CALL,
841
842 // Builtin call that returns floating point.
843 // double f(double, int).
844 BUILTIN_FP_INT_CALL,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100845
846 // Direct call to API function callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000847 // void f(v8::FunctionCallbackInfo&)
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100848 DIRECT_API_CALL,
849
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000850 // Call to function callback via InvokeFunctionCallback.
851 // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
852 PROFILING_API_CALL,
853
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100854 // Direct call to accessor getter callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000855 // void f(Local<Name> property, PropertyCallbackInfo& info)
856 DIRECT_GETTER_CALL,
857
858 // Call to accessor getter callback via InvokeAccessorGetterCallback.
859 // void f(Local<Name> property, PropertyCallbackInfo& info,
860 // AccessorNameGetterCallback callback)
861 PROFILING_GETTER_CALL
Steve Block1e0659c2011-05-24 12:43:12 +0100862 };
863
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000864 static void SetUp();
865 static void InitializeMathExpData();
866 static void TearDownMathExpData();
867
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000868 typedef void* ExternalReferenceRedirector(Isolate* isolate, void* original,
869 Type type);
Steve Block1e0659c2011-05-24 12:43:12 +0100870
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000871 ExternalReference() : address_(NULL) {}
872
Steve Block44f0eee2011-05-26 01:26:41 +0100873 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000874
Steve Block44f0eee2011-05-26 01:26:41 +0100875 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000876
Steve Block44f0eee2011-05-26 01:26:41 +0100877 ExternalReference(Builtins::Name name, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000878
Steve Block44f0eee2011-05-26 01:26:41 +0100879 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000880
Steve Block44f0eee2011-05-26 01:26:41 +0100881 ExternalReference(const Runtime::Function* f, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000882
Steve Blocka7e24c12009-10-30 11:49:00 +0000883 explicit ExternalReference(StatsCounter* counter);
884
Steve Block44f0eee2011-05-26 01:26:41 +0100885 ExternalReference(Isolate::AddressId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000886
887 explicit ExternalReference(const SCTableReference& table_ref);
888
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000889 // Isolate as an external reference.
890 static ExternalReference isolate_address(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100891
Steve Blocka7e24c12009-10-30 11:49:00 +0000892 // One-of-a-kind references. These references are not part of a general
893 // pattern. This means that they have to be added to the
894 // ExternalReferenceTable in serialize.cc manually.
895
Ben Murdoch097c5b22016-05-18 11:27:45 +0100896 static ExternalReference interpreter_dispatch_table_address(Isolate* isolate);
897
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100898 static ExternalReference incremental_marking_record_write_function(
899 Isolate* isolate);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100900 static ExternalReference incremental_marking_record_write_code_entry_function(
901 Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100902 static ExternalReference store_buffer_overflow_function(
903 Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100904 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000905
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100906 static ExternalReference get_date_field_function(Isolate* isolate);
907 static ExternalReference date_cache_stamp(Isolate* isolate);
908
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000909 static ExternalReference get_make_code_young_function(Isolate* isolate);
910 static ExternalReference get_mark_code_as_executed_function(Isolate* isolate);
911
Ben Murdochb0fe1622011-05-05 13:52:32 +0100912 // Deoptimization support.
Steve Block44f0eee2011-05-26 01:26:41 +0100913 static ExternalReference new_deoptimizer_function(Isolate* isolate);
914 static ExternalReference compute_output_frames_function(Isolate* isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100915
Ben Murdoch097c5b22016-05-18 11:27:45 +0100916 static ExternalReference f32_trunc_wrapper_function(Isolate* isolate);
917 static ExternalReference f32_floor_wrapper_function(Isolate* isolate);
918 static ExternalReference f32_ceil_wrapper_function(Isolate* isolate);
919 static ExternalReference f32_nearest_int_wrapper_function(Isolate* isolate);
920 static ExternalReference f64_trunc_wrapper_function(Isolate* isolate);
921 static ExternalReference f64_floor_wrapper_function(Isolate* isolate);
922 static ExternalReference f64_ceil_wrapper_function(Isolate* isolate);
923 static ExternalReference f64_nearest_int_wrapper_function(Isolate* isolate);
924
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000925 // Log support.
926 static ExternalReference log_enter_external_function(Isolate* isolate);
927 static ExternalReference log_leave_external_function(Isolate* isolate);
928
Leon Clarkee46be812010-01-19 14:06:41 +0000929 // Static data in the keyed lookup cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100930 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
931 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000932
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100933 // Static variable Heap::roots_array_start()
934 static ExternalReference roots_array_start(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000935
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000936 // Static variable Heap::allocation_sites_list_address()
937 static ExternalReference allocation_sites_list_address(Isolate* isolate);
938
Steve Blocka7e24c12009-10-30 11:49:00 +0000939 // Static variable StackGuard::address_of_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100940 static ExternalReference address_of_stack_limit(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000941
942 // Static variable StackGuard::address_of_real_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100943 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000944
945 // Static variable RegExpStack::limit_address()
Steve Block44f0eee2011-05-26 01:26:41 +0100946 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000947
Leon Clarkee46be812010-01-19 14:06:41 +0000948 // Static variables for RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100949 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
950 static ExternalReference address_of_regexp_stack_memory_address(
951 Isolate* isolate);
952 static ExternalReference address_of_regexp_stack_memory_size(
953 Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000954
Steve Blocka7e24c12009-10-30 11:49:00 +0000955 // Static variable Heap::NewSpaceStart()
Steve Block44f0eee2011-05-26 01:26:41 +0100956 static ExternalReference new_space_start(Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100957
958 // Write barrier.
959 static ExternalReference store_buffer_top(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000960
961 // Used for fast allocation in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100962 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
963 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000964 static ExternalReference old_space_allocation_top_address(Isolate* isolate);
965 static ExternalReference old_space_allocation_limit_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000966
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000967 static ExternalReference mod_two_doubles_operation(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100968 static ExternalReference power_double_double_function(Isolate* isolate);
969 static ExternalReference power_double_int_function(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000970
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000971 static ExternalReference handle_scope_next_address(Isolate* isolate);
972 static ExternalReference handle_scope_limit_address(Isolate* isolate);
973 static ExternalReference handle_scope_level_address(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000974
Steve Block44f0eee2011-05-26 01:26:41 +0100975 static ExternalReference scheduled_exception_address(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000976 static ExternalReference address_of_pending_message_obj(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000977
Ben Murdochb0fe1622011-05-05 13:52:32 +0100978 // Static variables containing common double constants.
979 static ExternalReference address_of_min_int();
980 static ExternalReference address_of_one_half();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000981 static ExternalReference address_of_minus_one_half();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100982 static ExternalReference address_of_negative_infinity();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000983 static ExternalReference address_of_the_hole_nan();
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000984 static ExternalReference address_of_uint32_bias();
Ben Murdochb0fe1622011-05-05 13:52:32 +0100985
Steve Block44f0eee2011-05-26 01:26:41 +0100986 static ExternalReference math_log_double_function(Isolate* isolate);
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100987
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000988 static ExternalReference math_exp_constants(int constant_index);
989 static ExternalReference math_exp_log_table();
Steve Blocka7e24c12009-10-30 11:49:00 +0000990
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000991 static ExternalReference page_flags(Page* page);
992
993 static ExternalReference ForDeoptEntry(Address entry);
994
995 static ExternalReference cpu_features();
996
997 static ExternalReference debug_is_active_address(Isolate* isolate);
998 static ExternalReference debug_after_break_target_address(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000999
1000 static ExternalReference is_profiling_address(Isolate* isolate);
1001 static ExternalReference invoke_function_callback(Isolate* isolate);
1002 static ExternalReference invoke_accessor_getter_callback(Isolate* isolate);
1003
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001004 static ExternalReference virtual_handler_register(Isolate* isolate);
1005 static ExternalReference virtual_slot_register(Isolate* isolate);
1006
1007 static ExternalReference runtime_function_table_address(Isolate* isolate);
1008
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001009 Address address() const { return reinterpret_cast<Address>(address_); }
1010
Steve Blocka7e24c12009-10-30 11:49:00 +00001011 // Used to check if single stepping is enabled in generated code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001012 static ExternalReference debug_step_in_enabled_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001013
Steve Block6ded16b2010-05-10 14:33:55 +01001014#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001015 // C functions called from RegExp generated code.
1016
1017 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
Steve Block44f0eee2011-05-26 01:26:41 +01001018 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001019
1020 // Function RegExpMacroAssembler*::CheckStackGuardState()
Steve Block44f0eee2011-05-26 01:26:41 +01001021 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001022
1023 // Function NativeRegExpMacroAssembler::GrowStack()
Steve Block44f0eee2011-05-26 01:26:41 +01001024 static ExternalReference re_grow_stack(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +00001025
1026 // byte NativeRegExpMacroAssembler::word_character_bitmap
1027 static ExternalReference re_word_character_map();
1028
Steve Blocka7e24c12009-10-30 11:49:00 +00001029#endif
1030
1031 // This lets you register a function that rewrites all external references.
1032 // Used by the ARM simulator to catch calls to external references.
Ben Murdoch257744e2011-11-30 15:57:28 +00001033 static void set_redirector(Isolate* isolate,
1034 ExternalReferenceRedirector* redirector) {
Steve Block44f0eee2011-05-26 01:26:41 +01001035 // We can't stack them.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001036 DCHECK(isolate->external_reference_redirector() == NULL);
Ben Murdoch257744e2011-11-30 15:57:28 +00001037 isolate->set_external_reference_redirector(
Steve Block44f0eee2011-05-26 01:26:41 +01001038 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
Steve Blocka7e24c12009-10-30 11:49:00 +00001039 }
1040
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001041 static ExternalReference stress_deopt_count(Isolate* isolate);
1042
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001043 static ExternalReference fixed_typed_array_base_data_offset();
1044
Steve Blocka7e24c12009-10-30 11:49:00 +00001045 private:
1046 explicit ExternalReference(void* address)
1047 : address_(address) {}
1048
Steve Block44f0eee2011-05-26 01:26:41 +01001049 static void* Redirect(Isolate* isolate,
Steve Block44f0eee2011-05-26 01:26:41 +01001050 Address address_arg,
Steve Block1e0659c2011-05-24 12:43:12 +01001051 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +01001052 ExternalReferenceRedirector* redirector =
1053 reinterpret_cast<ExternalReferenceRedirector*>(
1054 isolate->external_reference_redirector());
Steve Blocka7e24c12009-10-30 11:49:00 +00001055 void* address = reinterpret_cast<void*>(address_arg);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001056 void* answer =
1057 (redirector == NULL) ? address : (*redirector)(isolate, address, type);
Steve Blockd0582a62009-12-15 09:54:21 +00001058 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +00001059 }
1060
1061 void* address_;
1062};
1063
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001064bool operator==(ExternalReference, ExternalReference);
1065bool operator!=(ExternalReference, ExternalReference);
1066
1067size_t hash_value(ExternalReference);
1068
1069std::ostream& operator<<(std::ostream&, ExternalReference);
1070
Steve Blocka7e24c12009-10-30 11:49:00 +00001071
1072// -----------------------------------------------------------------------------
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001073// Position recording support
1074
Ben Murdochb0fe1622011-05-05 13:52:32 +01001075struct PositionState {
1076 PositionState() : current_position(RelocInfo::kNoPosition),
1077 written_position(RelocInfo::kNoPosition),
1078 current_statement_position(RelocInfo::kNoPosition),
1079 written_statement_position(RelocInfo::kNoPosition) {}
1080
1081 int current_position;
1082 int written_position;
1083
1084 int current_statement_position;
1085 int written_statement_position;
1086};
1087
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001088
1089class PositionsRecorder BASE_EMBEDDED {
1090 public:
1091 explicit PositionsRecorder(Assembler* assembler)
Ben Murdochb8e0da22011-05-16 14:20:40 +01001092 : assembler_(assembler) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001093 jit_handler_data_ = NULL;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001094 }
1095
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001096 void AttachJITHandlerData(void* user_data) {
1097 jit_handler_data_ = user_data;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001098 }
1099
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001100 void* DetachJITHandlerData() {
1101 void* old_data = jit_handler_data_;
1102 jit_handler_data_ = NULL;
1103 return old_data;
Ben Murdochb8e0da22011-05-16 14:20:40 +01001104 }
Ben Murdochb0fe1622011-05-05 13:52:32 +01001105 // Set current position to pos.
1106 void RecordPosition(int pos);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001107
1108 // Set current statement position to pos.
1109 void RecordStatementPosition(int pos);
1110
1111 // Write recorded positions to relocation information.
1112 bool WriteRecordedPositions();
1113
Ben Murdochb0fe1622011-05-05 13:52:32 +01001114 int current_position() const { return state_.current_position; }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001115
Ben Murdochb0fe1622011-05-05 13:52:32 +01001116 int current_statement_position() const {
1117 return state_.current_statement_position;
1118 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001119
1120 private:
1121 Assembler* assembler_;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001122 PositionState state_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001123
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001124 // Currently jit_handler_data_ is used to store JITHandler-specific data
1125 // over the lifetime of a PositionsRecorder
1126 void* jit_handler_data_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001127
Ben Murdochb0fe1622011-05-05 13:52:32 +01001128 DISALLOW_COPY_AND_ASSIGN(PositionsRecorder);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001129};
1130
1131
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001132// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +00001133// Utility functions
1134
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001135inline int NumberOfBitsSet(uint32_t x) {
Andrei Popescu31002712010-02-23 13:46:05 +00001136 unsigned int num_bits_set;
1137 for (num_bits_set = 0; x; x >>= 1) {
1138 num_bits_set += x & 1;
1139 }
1140 return num_bits_set;
1141}
Steve Blocka7e24c12009-10-30 11:49:00 +00001142
Ben Murdochb0fe1622011-05-05 13:52:32 +01001143// Computes pow(x, y) with the special cases in the spec for Math.pow.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001144double power_helper(Isolate* isolate, double x, double y);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001145double power_double_int(double x, int y);
1146double power_double_double(double x, double y);
1147
Ben Murdoch257744e2011-11-30 15:57:28 +00001148// Helper class for generating code or data associated with the code
1149// right after a call instruction. As an example this can be used to
1150// generate safepoint data after calls for crankshaft.
1151class CallWrapper {
1152 public:
1153 CallWrapper() { }
1154 virtual ~CallWrapper() { }
1155 // Called just before emitting a call. Argument is the size of the generated
1156 // call code.
1157 virtual void BeforeCall(int call_size) const = 0;
1158 // Called just after emitting a call, i.e., at the return site for the call.
1159 virtual void AfterCall() const = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001160 // Return whether call needs to check for debug stepping.
1161 virtual bool NeedsDebugStepCheck() const { return false; }
Ben Murdoch257744e2011-11-30 15:57:28 +00001162};
1163
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001164
Ben Murdoch257744e2011-11-30 15:57:28 +00001165class NullCallWrapper : public CallWrapper {
1166 public:
1167 NullCallWrapper() { }
1168 virtual ~NullCallWrapper() { }
1169 virtual void BeforeCall(int call_size) const { }
1170 virtual void AfterCall() const { }
1171};
1172
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001173
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001174class CheckDebugStepCallWrapper : public CallWrapper {
1175 public:
1176 CheckDebugStepCallWrapper() {}
1177 virtual ~CheckDebugStepCallWrapper() {}
1178 virtual void BeforeCall(int call_size) const {}
1179 virtual void AfterCall() const {}
1180 virtual bool NeedsDebugStepCheck() const { return true; }
1181};
Steve Blocka7e24c12009-10-30 11:49:00 +00001182
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001183
1184// -----------------------------------------------------------------------------
1185// Constant pool support
1186
1187class ConstantPoolEntry {
1188 public:
1189 ConstantPoolEntry() {}
1190 ConstantPoolEntry(int position, intptr_t value, bool sharing_ok)
1191 : position_(position),
1192 merged_index_(sharing_ok ? SHARING_ALLOWED : SHARING_PROHIBITED),
1193 value_(value) {}
1194 ConstantPoolEntry(int position, double value)
1195 : position_(position), merged_index_(SHARING_ALLOWED), value64_(value) {}
1196
1197 int position() const { return position_; }
1198 bool sharing_ok() const { return merged_index_ != SHARING_PROHIBITED; }
1199 bool is_merged() const { return merged_index_ >= 0; }
1200 int merged_index(void) const {
1201 DCHECK(is_merged());
1202 return merged_index_;
1203 }
1204 void set_merged_index(int index) {
1205 merged_index_ = index;
1206 DCHECK(is_merged());
1207 }
1208 int offset(void) const {
1209 DCHECK(merged_index_ >= 0);
1210 return merged_index_;
1211 }
1212 void set_offset(int offset) {
1213 DCHECK(offset >= 0);
1214 merged_index_ = offset;
1215 }
1216 intptr_t value() const { return value_; }
1217 uint64_t value64() const { return bit_cast<uint64_t>(value64_); }
1218
1219 enum Type { INTPTR, DOUBLE, NUMBER_OF_TYPES };
1220
1221 static int size(Type type) {
1222 return (type == INTPTR) ? kPointerSize : kDoubleSize;
1223 }
1224
1225 enum Access { REGULAR, OVERFLOWED };
1226
1227 private:
1228 int position_;
1229 int merged_index_;
1230 union {
1231 intptr_t value_;
1232 double value64_;
1233 };
1234 enum { SHARING_PROHIBITED = -2, SHARING_ALLOWED = -1 };
1235};
1236
1237
1238// -----------------------------------------------------------------------------
1239// Embedded constant pool support
1240
1241class ConstantPoolBuilder BASE_EMBEDDED {
1242 public:
1243 ConstantPoolBuilder(int ptr_reach_bits, int double_reach_bits);
1244
1245 // Add pointer-sized constant to the embedded constant pool
1246 ConstantPoolEntry::Access AddEntry(int position, intptr_t value,
1247 bool sharing_ok) {
1248 ConstantPoolEntry entry(position, value, sharing_ok);
1249 return AddEntry(entry, ConstantPoolEntry::INTPTR);
1250 }
1251
1252 // Add double constant to the embedded constant pool
1253 ConstantPoolEntry::Access AddEntry(int position, double value) {
1254 ConstantPoolEntry entry(position, value);
1255 return AddEntry(entry, ConstantPoolEntry::DOUBLE);
1256 }
1257
1258 // Previews the access type required for the next new entry to be added.
1259 ConstantPoolEntry::Access NextAccess(ConstantPoolEntry::Type type) const;
1260
1261 bool IsEmpty() {
1262 return info_[ConstantPoolEntry::INTPTR].entries.empty() &&
1263 info_[ConstantPoolEntry::INTPTR].shared_entries.empty() &&
1264 info_[ConstantPoolEntry::DOUBLE].entries.empty() &&
1265 info_[ConstantPoolEntry::DOUBLE].shared_entries.empty();
1266 }
1267
1268 // Emit the constant pool. Invoke only after all entries have been
1269 // added and all instructions have been emitted.
1270 // Returns position of the emitted pool (zero implies no constant pool).
1271 int Emit(Assembler* assm);
1272
1273 // Returns the label associated with the start of the constant pool.
1274 // Linking to this label in the function prologue may provide an
1275 // efficient means of constant pool pointer register initialization
1276 // on some architectures.
1277 inline Label* EmittedPosition() { return &emitted_label_; }
1278
1279 private:
1280 ConstantPoolEntry::Access AddEntry(ConstantPoolEntry& entry,
1281 ConstantPoolEntry::Type type);
1282 void EmitSharedEntries(Assembler* assm, ConstantPoolEntry::Type type);
1283 void EmitGroup(Assembler* assm, ConstantPoolEntry::Access access,
1284 ConstantPoolEntry::Type type);
1285
1286 struct PerTypeEntryInfo {
1287 PerTypeEntryInfo() : regular_count(0), overflow_start(-1) {}
1288 bool overflow() const {
1289 return (overflow_start >= 0 &&
1290 overflow_start < static_cast<int>(entries.size()));
1291 }
1292 int regular_reach_bits;
1293 int regular_count;
1294 int overflow_start;
1295 std::vector<ConstantPoolEntry> entries;
1296 std::vector<ConstantPoolEntry> shared_entries;
1297 };
1298
1299 Label emitted_label_; // Records pc_offset of emitted pool
1300 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES];
1301};
1302
1303} // namespace internal
1304} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001305#endif // V8_ASSEMBLER_H_