blob: 192d16b64d7ba8613d90b4b4ab7369426c0d7dde [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 Murdochda12d292016-06-02 14:46:10 +010041#include "src/log.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.
Ben Murdochb8a8cc12014-11-26 15:28:44 +000052class StatsCounter;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000053
Steve Blocka7e24c12009-10-30 11:49:00 +000054// -----------------------------------------------------------------------------
Steve Block44f0eee2011-05-26 01:26:41 +010055// Platform independent assembler base class.
56
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057enum class CodeObjectRequired { kNo, kYes };
58
59
Steve Block44f0eee2011-05-26 01:26:41 +010060class AssemblerBase: public Malloced {
61 public:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size);
63 virtual ~AssemblerBase();
Steve Block44f0eee2011-05-26 01:26:41 +010064
65 Isolate* isolate() const { return isolate_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +000066 int jit_cookie() const { return jit_cookie_; }
67
68 bool emit_debug_code() const { return emit_debug_code_; }
69 void set_emit_debug_code(bool value) { emit_debug_code_ = value; }
70
71 bool serializer_enabled() const { return serializer_enabled_; }
72 void enable_serializer() { serializer_enabled_ = true; }
73
74 bool predictable_code_size() const { return predictable_code_size_; }
75 void set_predictable_code_size(bool value) { predictable_code_size_ = value; }
76
77 uint64_t enabled_cpu_features() const { return enabled_cpu_features_; }
78 void set_enabled_cpu_features(uint64_t features) {
79 enabled_cpu_features_ = features;
80 }
81 bool IsEnabled(CpuFeature f) {
82 return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
83 }
Steve Block44f0eee2011-05-26 01:26:41 +010084
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000085 bool is_constant_pool_available() const {
86 if (FLAG_enable_embedded_constant_pool) {
87 return constant_pool_available_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040088 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000089 // Embedded constant pool not supported on this architecture.
Emily Bernierd0a1eb72015-03-24 16:35:39 -040090 UNREACHABLE();
91 return false;
92 }
93 }
94
Ben Murdochdb1b4382012-04-26 19:03:50 +010095 // Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
96 // cross-snapshotting.
97 static void QuietNaN(HeapObject* nan) { }
98
Ben Murdochb8a8cc12014-11-26 15:28:44 +000099 int pc_offset() const { return static_cast<int>(pc_ - buffer_); }
100
101 // This function is called when code generation is aborted, so that
102 // the assembler could clean up internal data structures.
103 virtual void AbortedCodeGeneration() { }
104
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000105 // Debugging
106 void Print();
107
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000108 static const int kMinimalBufferSize = 4*KB;
109
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110 static void FlushICache(Isolate* isolate, void* start, size_t size);
111
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000112 protected:
113 // The buffer into which code and relocation info are generated. It could
114 // either be owned by the assembler or be provided externally.
115 byte* buffer_;
116 int buffer_size_;
117 bool own_buffer_;
118
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000119 void set_constant_pool_available(bool available) {
120 if (FLAG_enable_embedded_constant_pool) {
121 constant_pool_available_ = available;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400122 } else {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000123 // Embedded constant pool not supported on this architecture.
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400124 UNREACHABLE();
125 }
126 }
127
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000128 // The program counter, which points into the buffer above and moves forward.
129 byte* pc_;
130
Steve Block44f0eee2011-05-26 01:26:41 +0100131 private:
132 Isolate* isolate_;
Steve Block053d10c2011-06-13 19:13:29 +0100133 int jit_cookie_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000134 uint64_t enabled_cpu_features_;
135 bool emit_debug_code_;
136 bool predictable_code_size_;
137 bool serializer_enabled_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400138
139 // Indicates whether the constant pool can be accessed, which is only possible
140 // if the pp register points to the current code object's constant pool.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000141 bool constant_pool_available_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400142
143 // Constant pool.
144 friend class FrameAndConstantPoolScope;
145 friend class ConstantPoolUnavailableScope;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000146};
147
148
149// Avoids emitting debug code during the lifetime of this scope object.
150class DontEmitDebugCodeScope BASE_EMBEDDED {
151 public:
152 explicit DontEmitDebugCodeScope(AssemblerBase* assembler)
153 : assembler_(assembler), old_value_(assembler->emit_debug_code()) {
154 assembler_->set_emit_debug_code(false);
155 }
156 ~DontEmitDebugCodeScope() {
157 assembler_->set_emit_debug_code(old_value_);
158 }
159 private:
160 AssemblerBase* assembler_;
161 bool old_value_;
162};
163
164
165// Avoids using instructions that vary in size in unpredictable ways between the
166// snapshot and the running VM.
167class PredictableCodeSizeScope {
168 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000169 explicit PredictableCodeSizeScope(AssemblerBase* assembler);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000170 PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size);
171 ~PredictableCodeSizeScope();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000172 void ExpectSize(int expected_size) { expected_size_ = expected_size; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000173
174 private:
175 AssemblerBase* assembler_;
176 int expected_size_;
177 int start_offset_;
178 bool old_value_;
179};
180
181
182// Enable a specified feature within a scope.
183class CpuFeatureScope BASE_EMBEDDED {
184 public:
185#ifdef DEBUG
186 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f);
187 ~CpuFeatureScope();
188
189 private:
190 AssemblerBase* assembler_;
191 uint64_t old_enabled_;
192#else
193 CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {}
194#endif
195};
196
197
198// CpuFeatures keeps track of which features are supported by the target CPU.
199// Supported features must be enabled by a CpuFeatureScope before use.
200// Example:
201// if (assembler->IsSupported(SSE3)) {
202// CpuFeatureScope fscope(assembler, SSE3);
203// // Generate code containing SSE3 instructions.
204// } else {
205// // Generate alternative code.
206// }
207class CpuFeatures : public AllStatic {
208 public:
209 static void Probe(bool cross_compile) {
210 STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt);
211 if (initialized_) return;
212 initialized_ = true;
213 ProbeImpl(cross_compile);
214 }
215
216 static unsigned SupportedFeatures() {
217 Probe(false);
218 return supported_;
219 }
220
221 static bool IsSupported(CpuFeature f) {
222 return (supported_ & (1u << f)) != 0;
223 }
224
225 static inline bool SupportsCrankshaft();
226
Ben Murdoch097c5b22016-05-18 11:27:45 +0100227 static inline unsigned icache_line_size() {
228 DCHECK(icache_line_size_ != 0);
229 return icache_line_size_;
230 }
231
232 static inline unsigned dcache_line_size() {
233 DCHECK(dcache_line_size_ != 0);
234 return dcache_line_size_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000235 }
236
237 static void PrintTarget();
238 static void PrintFeatures();
239
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000240 private:
241 friend class ExternalReference;
242 friend class AssemblerBase;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000243 // Flush instruction cache.
244 static void FlushICache(void* start, size_t size);
245
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000246 // Platform-dependent implementation.
247 static void ProbeImpl(bool cross_compile);
248
249 static unsigned supported_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100250 static unsigned icache_line_size_;
251 static unsigned dcache_line_size_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000252 static bool initialized_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000253 DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
Steve Block44f0eee2011-05-26 01:26:41 +0100254};
255
Ben Murdochb0fe1622011-05-05 13:52:32 +0100256
257// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000258// Labels represent pc locations; they are typically jump or call targets.
259// After declaration, a label can be freely used to denote known or (yet)
260// unknown pc location. Assembler::bind() is used to bind a label to the
261// current pc. A label can be bound only once.
262
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400263class Label {
Steve Blocka7e24c12009-10-30 11:49:00 +0000264 public:
Ben Murdoch257744e2011-11-30 15:57:28 +0000265 enum Distance {
266 kNear, kFar
267 };
268
269 INLINE(Label()) {
270 Unuse();
271 UnuseNear();
272 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000273
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000274 INLINE(~Label()) {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000275 DCHECK(!is_linked());
276 DCHECK(!is_near_linked());
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000277 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000278
Ben Murdoch3fb3ca82011-12-02 17:19:32 +0000279 INLINE(void Unuse()) { pos_ = 0; }
280 INLINE(void UnuseNear()) { near_link_pos_ = 0; }
281
282 INLINE(bool is_bound() const) { return pos_ < 0; }
283 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
284 INLINE(bool is_linked() const) { return pos_ > 0; }
Ben Murdoch257744e2011-11-30 15:57:28 +0000285 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000286
287 // Returns the position of bound or linked labels. Cannot be used
288 // for unused labels.
289 int pos() const;
Ben Murdoch257744e2011-11-30 15:57:28 +0000290 int near_link_pos() const { return near_link_pos_ - 1; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000291
292 private:
293 // pos_ encodes both the binding state (via its sign)
294 // and the binding position (via its value) of a label.
295 //
296 // pos_ < 0 bound label, pos() returns the jump target position
297 // pos_ == 0 unused label
298 // pos_ > 0 linked label, pos() returns the last reference position
299 int pos_;
300
Ben Murdoch257744e2011-11-30 15:57:28 +0000301 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
302 int near_link_pos_;
303
Steve Blocka7e24c12009-10-30 11:49:00 +0000304 void bind_to(int pos) {
305 pos_ = -pos - 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000306 DCHECK(is_bound());
Steve Blocka7e24c12009-10-30 11:49:00 +0000307 }
Ben Murdoch257744e2011-11-30 15:57:28 +0000308 void link_to(int pos, Distance distance = kFar) {
309 if (distance == kNear) {
310 near_link_pos_ = pos + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000311 DCHECK(is_near_linked());
Ben Murdoch257744e2011-11-30 15:57:28 +0000312 } else {
313 pos_ = pos + 1;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000314 DCHECK(is_linked());
Ben Murdoch257744e2011-11-30 15:57:28 +0000315 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000316 }
317
318 friend class Assembler;
Steve Blocka7e24c12009-10-30 11:49:00 +0000319 friend class Displacement;
Steve Blocka7e24c12009-10-30 11:49:00 +0000320 friend class RegExpMacroAssemblerIrregexp;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000321
322#if V8_TARGET_ARCH_ARM64
323 // On ARM64, the Assembler keeps track of pointers to Labels to resolve
324 // branches to distant targets. Copying labels would confuse the Assembler.
325 DISALLOW_COPY_AND_ASSIGN(Label); // NOLINT
326#endif
Steve Blocka7e24c12009-10-30 11:49:00 +0000327};
328
329
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100330enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
331
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000332enum ArgvMode { kArgvOnStack, kArgvInRegister };
333
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000334// Specifies whether to perform icache flush operations on RelocInfo updates.
335// If FLUSH_ICACHE_IF_NEEDED, the icache will always be flushed if an
336// instruction was modified. If SKIP_ICACHE_FLUSH the flush will always be
337// skipped (only use this if you will flush the icache manually before it is
338// executed).
339enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH };
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100340
Steve Blocka7e24c12009-10-30 11:49:00 +0000341// -----------------------------------------------------------------------------
342// Relocation information
343
344
345// Relocation information consists of the address (pc) of the datum
346// to which the relocation information applies, the relocation mode
347// (rmode), and an optional data field. The relocation mode may be
348// "descriptive" and not indicate a need for relocation, but simply
349// describe a property of the datum. Such rmodes are useful for GC
350// and nice disassembly output.
351
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000352class RelocInfo {
Steve Blocka7e24c12009-10-30 11:49:00 +0000353 public:
354 // The constant kNoPosition is used with the collecting of source positions
355 // in the relocation information. Two types of source positions are collected
356 // "position" (RelocMode position) and "statement position" (RelocMode
357 // statement_position). The "position" is collected at places in the source
358 // code which are of interest when making stack traces to pin-point the source
359 // location of a stack frame as close as possible. The "statement position" is
360 // collected at the beginning at each statement, and is used to indicate
361 // possible break locations. kNoPosition is used to indicate an
362 // invalid/uninitialized position value.
363 static const int kNoPosition = -1;
364
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100365 // This string is used to add padding comments to the reloc info in cases
366 // where we are not sure to have enough space for patching in during
367 // lazy deoptimization. This is the case if we have indirect calls for which
368 // we do not normally record relocation info.
Ben Murdoch69a99ed2011-11-30 16:03:39 +0000369 static const char* const kFillerCommentString;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100370
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000371 // The minimum size of a comment is equal to two bytes for the extra tagged
372 // pc and kPointerSize for the actual pointer to the comment.
373 static const int kMinRelocCommentSize = 2 + kPointerSize;
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100374
375 // The maximum size for a call instruction including pc-jump.
376 static const int kMaxCallSize = 6;
377
Steve Block44f0eee2011-05-26 01:26:41 +0100378 // The maximum pc delta that will use the short encoding.
379 static const int kMaxSmallPCDelta;
380
Steve Blocka7e24c12009-10-30 11:49:00 +0000381 enum Mode {
382 // Please note the order is important (see IsCodeTarget, IsGCRelocMode).
Ben Murdoch257744e2011-11-30 15:57:28 +0000383 CODE_TARGET, // Code target which is not any of the above.
384 CODE_TARGET_WITH_ID,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000385 DEBUGGER_STATEMENT, // Code target for the debugger statement.
Steve Blocka7e24c12009-10-30 11:49:00 +0000386 EMBEDDED_OBJECT,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000387 CELL,
Ben Murdochda12d292016-06-02 14:46:10 +0100388 // To relocate pointers into the wasm memory embedded in wasm code
389 WASM_MEMORY_REFERENCE,
Ben Murdochb0fe1622011-05-05 13:52:32 +0100390
Steve Blocka7e24c12009-10-30 11:49:00 +0000391 // Everything after runtime_entry (inclusive) is not GC'ed.
392 RUNTIME_ENTRY,
Steve Blocka7e24c12009-10-30 11:49:00 +0000393 COMMENT,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000394 POSITION, // See comment for kNoPosition above.
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 STATEMENT_POSITION, // See comment for kNoPosition above.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000396
397 // Additional code inserted for debug break slot.
398 DEBUG_BREAK_SLOT_AT_POSITION,
399 DEBUG_BREAK_SLOT_AT_RETURN,
400 DEBUG_BREAK_SLOT_AT_CALL,
Ben Murdochda12d292016-06-02 14:46:10 +0100401 DEBUG_BREAK_SLOT_AT_TAIL_CALL,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000402
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 EXTERNAL_REFERENCE, // The address of an external C++ function.
404 INTERNAL_REFERENCE, // An address inside the same function.
405
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000406 // Encoded internal reference, used only on MIPS, MIPS64 and PPC.
407 INTERNAL_REFERENCE_ENCODED,
408
409 // Continuation points for a generator yield.
410 GENERATOR_CONTINUATION,
411
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000412 // Marks constant and veneer pools. Only used on ARM and ARM64.
413 // They use a custom noncompact encoding.
414 CONST_POOL,
415 VENEER_POOL,
416
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000417 DEOPT_REASON, // Deoptimization reason index.
418
419 // This is not an actual reloc mode, but used to encode a long pc jump that
420 // cannot be encoded as part of another record.
421 PC_JUMP,
422
Steve Blocka7e24c12009-10-30 11:49:00 +0000423 // Pseudo-types
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000424 NUMBER_OF_MODES,
425 NONE32, // never recorded 32-bit value
426 NONE64, // never recorded 64-bit value
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000427 CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by
428 // code aging.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000429
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000430 FIRST_REAL_RELOC_MODE = CODE_TARGET,
431 LAST_REAL_RELOC_MODE = VENEER_POOL,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000432 LAST_CODE_ENUM = DEBUGGER_STATEMENT,
Ben Murdochda12d292016-06-02 14:46:10 +0100433 LAST_GCED_ENUM = WASM_MEMORY_REFERENCE,
434 FIRST_SHAREABLE_RELOC_MODE = CELL,
Steve Blocka7e24c12009-10-30 11:49:00 +0000435 };
436
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000437 STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100438
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000439 explicit RelocInfo(Isolate* isolate) : isolate_(isolate) {
440 DCHECK_NOT_NULL(isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000441 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000442
443 RelocInfo(Isolate* isolate, byte* pc, Mode rmode, intptr_t data, Code* host)
444 : isolate_(isolate), pc_(pc), rmode_(rmode), data_(data), host_(host) {
445 DCHECK_NOT_NULL(isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000446 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000447
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000448 static inline bool IsRealRelocMode(Mode mode) {
449 return mode >= FIRST_REAL_RELOC_MODE &&
450 mode <= LAST_REAL_RELOC_MODE;
451 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000452 static inline bool IsCodeTarget(Mode mode) {
453 return mode <= LAST_CODE_ENUM;
454 }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100455 static inline bool IsEmbeddedObject(Mode mode) {
456 return mode == EMBEDDED_OBJECT;
457 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000458 static inline bool IsCell(Mode mode) { return mode == CELL; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000459 static inline bool IsRuntimeEntry(Mode mode) {
460 return mode == RUNTIME_ENTRY;
461 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000462 // Is the relocation mode affected by GC?
463 static inline bool IsGCRelocMode(Mode mode) {
464 return mode <= LAST_GCED_ENUM;
465 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000466 static inline bool IsComment(Mode mode) {
467 return mode == COMMENT;
468 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000469 static inline bool IsConstPool(Mode mode) {
470 return mode == CONST_POOL;
471 }
472 static inline bool IsVeneerPool(Mode mode) {
473 return mode == VENEER_POOL;
474 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000475 static inline bool IsDeoptReason(Mode mode) {
476 return mode == DEOPT_REASON;
477 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000478 static inline bool IsPosition(Mode mode) {
479 return mode == POSITION || mode == STATEMENT_POSITION;
480 }
481 static inline bool IsStatementPosition(Mode mode) {
482 return mode == STATEMENT_POSITION;
483 }
484 static inline bool IsExternalReference(Mode mode) {
485 return mode == EXTERNAL_REFERENCE;
486 }
487 static inline bool IsInternalReference(Mode mode) {
488 return mode == INTERNAL_REFERENCE;
489 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000490 static inline bool IsInternalReferenceEncoded(Mode mode) {
491 return mode == INTERNAL_REFERENCE_ENCODED;
492 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100493 static inline bool IsDebugBreakSlot(Mode mode) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000494 return IsDebugBreakSlotAtPosition(mode) || IsDebugBreakSlotAtReturn(mode) ||
Ben Murdochda12d292016-06-02 14:46:10 +0100495 IsDebugBreakSlotAtCall(mode) || IsDebugBreakSlotAtTailCall(mode);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000496 }
497 static inline bool IsDebugBreakSlotAtPosition(Mode mode) {
498 return mode == DEBUG_BREAK_SLOT_AT_POSITION;
499 }
500 static inline bool IsDebugBreakSlotAtReturn(Mode mode) {
501 return mode == DEBUG_BREAK_SLOT_AT_RETURN;
502 }
503 static inline bool IsDebugBreakSlotAtCall(Mode mode) {
504 return mode == DEBUG_BREAK_SLOT_AT_CALL;
505 }
Ben Murdochda12d292016-06-02 14:46:10 +0100506 static inline bool IsDebugBreakSlotAtTailCall(Mode mode) {
507 return mode == DEBUG_BREAK_SLOT_AT_TAIL_CALL;
508 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000509 static inline bool IsDebuggerStatement(Mode mode) {
510 return mode == DEBUGGER_STATEMENT;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100511 }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000512 static inline bool IsNone(Mode mode) {
513 return mode == NONE32 || mode == NONE64;
514 }
515 static inline bool IsCodeAgeSequence(Mode mode) {
516 return mode == CODE_AGE_SEQUENCE;
517 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000518 static inline bool IsGeneratorContinuation(Mode mode) {
519 return mode == GENERATOR_CONTINUATION;
520 }
Ben Murdochda12d292016-06-02 14:46:10 +0100521 static inline bool IsWasmMemoryReference(Mode mode) {
522 return mode == WASM_MEMORY_REFERENCE;
523 }
Steve Blocka7e24c12009-10-30 11:49:00 +0000524 static inline int ModeMask(Mode mode) { return 1 << mode; }
525
526 // Accessors
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000527 Isolate* isolate() const { return isolate_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100528 byte* pc() const { return pc_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000529 void set_pc(byte* pc) { pc_ = pc; }
530 Mode rmode() const { return rmode_; }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100531 intptr_t data() const { return data_; }
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100532 Code* host() const { return host_; }
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000533 void set_host(Code* host) { host_ = host; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000534
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000535 // Apply a relocation by delta bytes. When the code object is moved, PC
536 // relative addresses have to be updated as well as absolute addresses
537 // inside the code (internal references).
538 // Do not forget to flush the icache afterwards!
539 INLINE(void apply(intptr_t delta));
Steve Blocka7e24c12009-10-30 11:49:00 +0000540
Leon Clarkef7060e22010-06-03 12:02:55 +0100541 // Is the pointer this relocation info refers to coded like a plain pointer
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100542 // or is it strange in some way (e.g. relative or patched into a series of
Leon Clarkef7060e22010-06-03 12:02:55 +0100543 // instructions).
544 bool IsCodedSpecially();
545
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000546 // If true, the pointer this relocation info refers to is an entry in the
547 // constant pool, otherwise the pointer is embedded in the instruction stream.
548 bool IsInConstantPool();
549
Steve Blocka7e24c12009-10-30 11:49:00 +0000550 // this relocation applies to;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000551 // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
Steve Blocka7e24c12009-10-30 11:49:00 +0000552 INLINE(Address target_address());
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100553 INLINE(void set_target_address(Address target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000554 WriteBarrierMode write_barrier_mode =
555 UPDATE_WRITE_BARRIER,
556 ICacheFlushMode icache_flush_mode =
557 FLUSH_ICACHE_IF_NEEDED));
Steve Blocka7e24c12009-10-30 11:49:00 +0000558 INLINE(Object* target_object());
Steve Block3ce2e202009-11-05 08:53:23 +0000559 INLINE(Handle<Object> target_object_handle(Assembler* origin));
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100560 INLINE(void set_target_object(Object* target,
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000561 WriteBarrierMode write_barrier_mode =
562 UPDATE_WRITE_BARRIER,
563 ICacheFlushMode icache_flush_mode =
564 FLUSH_ICACHE_IF_NEEDED));
565 INLINE(Address target_runtime_entry(Assembler* origin));
566 INLINE(void set_target_runtime_entry(Address target,
567 WriteBarrierMode write_barrier_mode =
568 UPDATE_WRITE_BARRIER,
569 ICacheFlushMode icache_flush_mode =
570 FLUSH_ICACHE_IF_NEEDED));
571 INLINE(Cell* target_cell());
572 INLINE(Handle<Cell> target_cell_handle());
573 INLINE(void set_target_cell(Cell* cell,
574 WriteBarrierMode write_barrier_mode =
575 UPDATE_WRITE_BARRIER,
576 ICacheFlushMode icache_flush_mode =
577 FLUSH_ICACHE_IF_NEEDED));
578 INLINE(Handle<Object> code_age_stub_handle(Assembler* origin));
579 INLINE(Code* code_age_stub());
580 INLINE(void set_code_age_stub(Code* stub,
581 ICacheFlushMode icache_flush_mode =
582 FLUSH_ICACHE_IF_NEEDED));
Ben Murdochb0fe1622011-05-05 13:52:32 +0100583
Ben Murdochda12d292016-06-02 14:46:10 +0100584 INLINE(Address wasm_memory_reference());
585 INLINE(void update_wasm_memory_reference(
586 Address old_base, Address new_base, size_t old_size, size_t new_size,
587 ICacheFlushMode icache_flush_mode = SKIP_ICACHE_FLUSH));
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000588 // Returns the address of the constant pool entry where the target address
589 // is held. This should only be called if IsInConstantPool returns true.
590 INLINE(Address constant_pool_entry_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000591
Leon Clarkef7060e22010-06-03 12:02:55 +0100592 // Read the address of the word containing the target_address in an
593 // instruction stream. What this means exactly is architecture-independent.
594 // The only architecture-independent user of this function is the serializer.
595 // The serializer uses it to find out how many raw bytes of instruction to
596 // output before the next target. Architecture-independent code shouldn't
597 // dereference the pointer it gets back from this.
Steve Blocka7e24c12009-10-30 11:49:00 +0000598 INLINE(Address target_address_address());
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000599
Leon Clarkef7060e22010-06-03 12:02:55 +0100600 // This indicates how much space a target takes up when deserializing a code
601 // stream. For most architectures this is just the size of a pointer. For
602 // an instruction like movw/movt where the target bits are mixed into the
603 // instruction bits the size of the target will be zero, indicating that the
604 // serializer should not step forwards in memory after a target is resolved
605 // and written. In this case the target_address_address function above
606 // should return the end of the instructions to be patched, allowing the
607 // deserializer to deserialize the instructions as raw bytes and put them in
608 // place, ready to be patched with the target.
609 INLINE(int target_address_size());
Steve Blocka7e24c12009-10-30 11:49:00 +0000610
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000611 // Read the reference in the instruction this relocation
612 // applies to; can only be called if rmode_ is EXTERNAL_REFERENCE.
613 INLINE(Address target_external_reference());
614
615 // Read the reference in the instruction this relocation
616 // applies to; can only be called if rmode_ is INTERNAL_REFERENCE.
617 INLINE(Address target_internal_reference());
618
619 // Return the reference address this relocation applies to;
620 // can only be called if rmode_ is INTERNAL_REFERENCE.
621 INLINE(Address target_internal_reference_address());
Steve Blocka7e24c12009-10-30 11:49:00 +0000622
623 // Read/modify the address of a call instruction. This is used to relocate
624 // the break points where straight-line code is patched with a call
625 // instruction.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000626 INLINE(Address debug_call_address());
627 INLINE(void set_debug_call_address(Address target));
Steve Blocka7e24c12009-10-30 11:49:00 +0000628
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000629 // Wipe out a relocation to a fixed value, used for making snapshots
630 // reproducible.
631 INLINE(void WipeOut());
632
Steve Block44f0eee2011-05-26 01:26:41 +0100633 template<typename StaticVisitor> inline void Visit(Heap* heap);
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000634 inline void Visit(Isolate* isolate, ObjectVisitor* v);
Leon Clarkef7060e22010-06-03 12:02:55 +0100635
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100636 // Check whether this debug break slot has been patched with a call to the
637 // debugger.
Ben Murdoch097c5b22016-05-18 11:27:45 +0100638 bool IsPatchedDebugBreakSlotSequence();
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100639
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000640#ifdef DEBUG
641 // Check whether the given code contains relocation information that
642 // either is position-relative or movable by the garbage collector.
643 static bool RequiresRelocation(const CodeDesc& desc);
644#endif
645
Steve Blocka7e24c12009-10-30 11:49:00 +0000646#ifdef ENABLE_DISASSEMBLER
647 // Printing
648 static const char* RelocModeName(Mode rmode);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400649 void Print(Isolate* isolate, std::ostream& os); // NOLINT
Steve Blocka7e24c12009-10-30 11:49:00 +0000650#endif // ENABLE_DISASSEMBLER
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000651#ifdef VERIFY_HEAP
652 void Verify(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000653#endif
654
655 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
656 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
Ben Murdoch257744e2011-11-30 15:57:28 +0000657 static const int kDataMask =
658 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000659 static const int kDebugBreakSlotMask = 1 << DEBUG_BREAK_SLOT_AT_POSITION |
660 1 << DEBUG_BREAK_SLOT_AT_RETURN |
661 1 << DEBUG_BREAK_SLOT_AT_CALL;
662 static const int kApplyMask; // Modes affected by apply. Depends on arch.
Steve Blocka7e24c12009-10-30 11:49:00 +0000663
664 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000665 Isolate* isolate_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000666 // On ARM, note that pc_ is the address of the constant pool entry
667 // to be relocated and not the address of the instruction
668 // referencing the constant pool entry (except when rmode_ ==
669 // comment).
670 byte* pc_;
671 Mode rmode_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000672 intptr_t data_;
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100673 Code* host_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000674 friend class RelocIterator;
675};
676
677
678// RelocInfoWriter serializes a stream of relocation info. It writes towards
679// lower addresses.
680class RelocInfoWriter BASE_EMBEDDED {
681 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000682 RelocInfoWriter()
683 : pos_(NULL),
684 last_pc_(NULL),
685 last_id_(0),
686 last_position_(0),
687 last_mode_(RelocInfo::NUMBER_OF_MODES),
688 next_position_candidate_pos_delta_(0),
689 next_position_candidate_pc_delta_(0),
690 next_position_candidate_flushed_(true) {}
691 RelocInfoWriter(byte* pos, byte* pc)
692 : pos_(pos),
693 last_pc_(pc),
694 last_id_(0),
695 last_position_(0),
696 last_mode_(RelocInfo::NUMBER_OF_MODES),
697 next_position_candidate_pos_delta_(0),
698 next_position_candidate_pc_delta_(0),
699 next_position_candidate_flushed_(true) {}
Steve Blocka7e24c12009-10-30 11:49:00 +0000700
701 byte* pos() const { return pos_; }
702 byte* last_pc() const { return last_pc_; }
703
704 void Write(const RelocInfo* rinfo);
705
706 // Update the state of the stream after reloc info buffer
707 // and/or code is moved while the stream is active.
708 void Reposition(byte* pos, byte* pc) {
709 pos_ = pos;
710 last_pc_ = pc;
711 }
712
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000713 void Finish() { FlushPosition(); }
714
Steve Blocka7e24c12009-10-30 11:49:00 +0000715 // Max size (bytes) of a written RelocInfo. Longest encoding is
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000716 // ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, data_delta.
717 // On ia32 and arm this is 1 + 4 + 1 + 1 + 4 = 11.
718 // On x64 this is 1 + 4 + 1 + 1 + 8 == 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000719 // Here we use the maximum of the two.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000720 static const int kMaxSize = 15;
Steve Blocka7e24c12009-10-30 11:49:00 +0000721
722 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000723 inline uint32_t WriteLongPCJump(uint32_t pc_delta);
724
725 inline void WriteShortTaggedPC(uint32_t pc_delta, int tag);
726 inline void WriteShortTaggedData(intptr_t data_delta, int tag);
727
728 inline void WriteMode(RelocInfo::Mode rmode);
729 inline void WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode);
730 inline void WriteIntData(int data_delta);
731 inline void WriteData(intptr_t data_delta);
732 inline void WritePosition(int pc_delta, int pos_delta, RelocInfo::Mode rmode);
733
734 void FlushPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000735
736 byte* pos_;
737 byte* last_pc_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000738 int last_id_;
739 int last_position_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000740 RelocInfo::Mode last_mode_;
741 int next_position_candidate_pos_delta_;
742 uint32_t next_position_candidate_pc_delta_;
743 bool next_position_candidate_flushed_;
744
Steve Blocka7e24c12009-10-30 11:49:00 +0000745 DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
746};
747
748
749// A RelocIterator iterates over relocation information.
750// Typical use:
751//
752// for (RelocIterator it(code); !it.done(); it.next()) {
753// // do something with it.rinfo() here
754// }
755//
756// A mask can be specified to skip unwanted modes.
757class RelocIterator: public Malloced {
758 public:
759 // Create a new iterator positioned at
760 // the beginning of the reloc info.
761 // Relocation information with mode k is included in the
762 // iteration iff bit k of mode_mask is set.
763 explicit RelocIterator(Code* code, int mode_mask = -1);
764 explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
765
766 // Iteration
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100767 bool done() const { return done_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000768 void next();
769
770 // Return pointer valid until next next().
771 RelocInfo* rinfo() {
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000772 DCHECK(!done());
Steve Blocka7e24c12009-10-30 11:49:00 +0000773 return &rinfo_;
774 }
775
776 private:
777 // Advance* moves the position before/after reading.
778 // *Read* reads from current byte(s) into rinfo_.
779 // *Get* just reads and returns info on current byte.
780 void Advance(int bytes = 1) { pos_ -= bytes; }
781 int AdvanceGetTag();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000782 RelocInfo::Mode GetMode();
783
784 void AdvanceReadLongPCJump();
785
786 int GetShortDataTypeTag();
787 void ReadShortTaggedPC();
788 void ReadShortTaggedId();
789 void ReadShortTaggedPosition();
790 void ReadShortTaggedData();
791
Steve Blocka7e24c12009-10-30 11:49:00 +0000792 void AdvanceReadPC();
Ben Murdoch257744e2011-11-30 15:57:28 +0000793 void AdvanceReadId();
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000794 void AdvanceReadInt();
Ben Murdoch257744e2011-11-30 15:57:28 +0000795 void AdvanceReadPosition();
Steve Blocka7e24c12009-10-30 11:49:00 +0000796 void AdvanceReadData();
Steve Blocka7e24c12009-10-30 11:49:00 +0000797
798 // If the given mode is wanted, set it in rinfo_ and return true.
799 // Else return false. Used for efficiently skipping unwanted modes.
800 bool SetMode(RelocInfo::Mode mode) {
Ben Murdochb0fe1622011-05-05 13:52:32 +0100801 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
Steve Blocka7e24c12009-10-30 11:49:00 +0000802 }
803
804 byte* pos_;
805 byte* end_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000806 byte* code_age_sequence_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000807 RelocInfo rinfo_;
808 bool done_;
809 int mode_mask_;
Ben Murdoch257744e2011-11-30 15:57:28 +0000810 int last_id_;
811 int last_position_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000812 DISALLOW_COPY_AND_ASSIGN(RelocIterator);
813};
814
815
816//------------------------------------------------------------------------------
817// External function
818
819//----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000820class SCTableReference;
Steve Blocka7e24c12009-10-30 11:49:00 +0000821class Debug_Address;
Steve Blocka7e24c12009-10-30 11:49:00 +0000822
823
Steve Blocka7e24c12009-10-30 11:49:00 +0000824// An ExternalReference represents a C++ address used in the generated
825// code. All references to C++ functions and variables must be encapsulated in
826// an ExternalReference instance. This is done in order to track the origin of
827// all external references in the code so that they can be bound to the correct
828// addresses when deserializing a heap.
829class ExternalReference BASE_EMBEDDED {
830 public:
Steve Block1e0659c2011-05-24 12:43:12 +0100831 // Used in the simulator to support different native api calls.
Steve Block1e0659c2011-05-24 12:43:12 +0100832 enum Type {
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100833 // Builtin call.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000834 // Object* f(v8::internal::Arguments).
Steve Block1e0659c2011-05-24 12:43:12 +0100835 BUILTIN_CALL, // default
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100836
Ben Murdoch097c5b22016-05-18 11:27:45 +0100837 // Builtin call returning object pair.
838 // ObjectPair f(v8::internal::Arguments).
839 BUILTIN_CALL_PAIR,
840
841 // Builtin call that returns .
842 // ObjectTriple f(v8::internal::Arguments).
843 BUILTIN_CALL_TRIPLE,
844
Ben Murdoch257744e2011-11-30 15:57:28 +0000845 // Builtin that takes float arguments and returns an int.
846 // int f(double, double).
847 BUILTIN_COMPARE_CALL,
848
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100849 // Builtin call that returns floating point.
850 // double f(double, double).
Ben Murdoch257744e2011-11-30 15:57:28 +0000851 BUILTIN_FP_FP_CALL,
852
853 // Builtin call that returns floating point.
854 // double f(double).
855 BUILTIN_FP_CALL,
856
857 // Builtin call that returns floating point.
858 // double f(double, int).
859 BUILTIN_FP_INT_CALL,
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100860
861 // Direct call to API function callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000862 // void f(v8::FunctionCallbackInfo&)
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100863 DIRECT_API_CALL,
864
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000865 // Call to function callback via InvokeFunctionCallback.
866 // void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
867 PROFILING_API_CALL,
868
Ben Murdoche0cee9b2011-05-25 10:26:03 +0100869 // Direct call to accessor getter callback.
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000870 // void f(Local<Name> property, PropertyCallbackInfo& info)
871 DIRECT_GETTER_CALL,
872
873 // Call to accessor getter callback via InvokeAccessorGetterCallback.
874 // void f(Local<Name> property, PropertyCallbackInfo& info,
875 // AccessorNameGetterCallback callback)
876 PROFILING_GETTER_CALL
Steve Block1e0659c2011-05-24 12:43:12 +0100877 };
878
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000879 static void SetUp();
880 static void InitializeMathExpData();
881 static void TearDownMathExpData();
882
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000883 typedef void* ExternalReferenceRedirector(Isolate* isolate, void* original,
884 Type type);
Steve Block1e0659c2011-05-24 12:43:12 +0100885
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000886 ExternalReference() : address_(NULL) {}
887
Steve Block44f0eee2011-05-26 01:26:41 +0100888 ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000889
Steve Block44f0eee2011-05-26 01:26:41 +0100890 ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000891
Steve Block44f0eee2011-05-26 01:26:41 +0100892 ExternalReference(Builtins::Name name, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000893
Steve Block44f0eee2011-05-26 01:26:41 +0100894 ExternalReference(Runtime::FunctionId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000895
Steve Block44f0eee2011-05-26 01:26:41 +0100896 ExternalReference(const Runtime::Function* f, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000897
Steve Blocka7e24c12009-10-30 11:49:00 +0000898 explicit ExternalReference(StatsCounter* counter);
899
Steve Block44f0eee2011-05-26 01:26:41 +0100900 ExternalReference(Isolate::AddressId id, Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000901
902 explicit ExternalReference(const SCTableReference& table_ref);
903
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000904 // Isolate as an external reference.
905 static ExternalReference isolate_address(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100906
Steve Blocka7e24c12009-10-30 11:49:00 +0000907 // One-of-a-kind references. These references are not part of a general
908 // pattern. This means that they have to be added to the
909 // ExternalReferenceTable in serialize.cc manually.
910
Ben Murdoch097c5b22016-05-18 11:27:45 +0100911 static ExternalReference interpreter_dispatch_table_address(Isolate* isolate);
912
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100913 static ExternalReference incremental_marking_record_write_function(
914 Isolate* isolate);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100915 static ExternalReference incremental_marking_record_write_code_entry_function(
916 Isolate* isolate);
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100917 static ExternalReference store_buffer_overflow_function(
918 Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +0100919 static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000920
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100921 static ExternalReference get_date_field_function(Isolate* isolate);
922 static ExternalReference date_cache_stamp(Isolate* isolate);
923
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000924 static ExternalReference get_make_code_young_function(Isolate* isolate);
925 static ExternalReference get_mark_code_as_executed_function(Isolate* isolate);
926
Ben Murdochb0fe1622011-05-05 13:52:32 +0100927 // Deoptimization support.
Steve Block44f0eee2011-05-26 01:26:41 +0100928 static ExternalReference new_deoptimizer_function(Isolate* isolate);
929 static ExternalReference compute_output_frames_function(Isolate* isolate);
Ben Murdochb0fe1622011-05-05 13:52:32 +0100930
Ben Murdochda12d292016-06-02 14:46:10 +0100931 static ExternalReference wasm_f32_trunc(Isolate* isolate);
932 static ExternalReference wasm_f32_floor(Isolate* isolate);
933 static ExternalReference wasm_f32_ceil(Isolate* isolate);
934 static ExternalReference wasm_f32_nearest_int(Isolate* isolate);
935 static ExternalReference wasm_f64_trunc(Isolate* isolate);
936 static ExternalReference wasm_f64_floor(Isolate* isolate);
937 static ExternalReference wasm_f64_ceil(Isolate* isolate);
938 static ExternalReference wasm_f64_nearest_int(Isolate* isolate);
939 static ExternalReference wasm_int64_to_float32(Isolate* isolate);
940 static ExternalReference wasm_uint64_to_float32(Isolate* isolate);
941 static ExternalReference wasm_int64_to_float64(Isolate* isolate);
942 static ExternalReference wasm_uint64_to_float64(Isolate* isolate);
943 static ExternalReference wasm_float32_to_int64(Isolate* isolate);
944 static ExternalReference wasm_float32_to_uint64(Isolate* isolate);
945 static ExternalReference wasm_float64_to_int64(Isolate* isolate);
946 static ExternalReference wasm_float64_to_uint64(Isolate* isolate);
947 static ExternalReference wasm_int64_div(Isolate* isolate);
948 static ExternalReference wasm_int64_mod(Isolate* isolate);
949 static ExternalReference wasm_uint64_div(Isolate* isolate);
950 static ExternalReference wasm_uint64_mod(Isolate* isolate);
951
952 static ExternalReference f64_acos_wrapper_function(Isolate* isolate);
953 static ExternalReference f64_asin_wrapper_function(Isolate* isolate);
954 static ExternalReference f64_atan_wrapper_function(Isolate* isolate);
955 static ExternalReference f64_cos_wrapper_function(Isolate* isolate);
956 static ExternalReference f64_sin_wrapper_function(Isolate* isolate);
957 static ExternalReference f64_tan_wrapper_function(Isolate* isolate);
958 static ExternalReference f64_exp_wrapper_function(Isolate* isolate);
959 static ExternalReference f64_log_wrapper_function(Isolate* isolate);
960 static ExternalReference f64_atan2_wrapper_function(Isolate* isolate);
961 static ExternalReference f64_pow_wrapper_function(Isolate* isolate);
962 static ExternalReference f64_mod_wrapper_function(Isolate* isolate);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100963
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000964 // Log support.
965 static ExternalReference log_enter_external_function(Isolate* isolate);
966 static ExternalReference log_leave_external_function(Isolate* isolate);
967
Leon Clarkee46be812010-01-19 14:06:41 +0000968 // Static data in the keyed lookup cache.
Steve Block44f0eee2011-05-26 01:26:41 +0100969 static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
970 static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000971
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100972 // Static variable Heap::roots_array_start()
973 static ExternalReference roots_array_start(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000974
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000975 // Static variable Heap::allocation_sites_list_address()
976 static ExternalReference allocation_sites_list_address(Isolate* isolate);
977
Steve Blocka7e24c12009-10-30 11:49:00 +0000978 // Static variable StackGuard::address_of_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100979 static ExternalReference address_of_stack_limit(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +0000980
981 // Static variable StackGuard::address_of_real_jslimit()
Steve Block44f0eee2011-05-26 01:26:41 +0100982 static ExternalReference address_of_real_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000983
984 // Static variable RegExpStack::limit_address()
Steve Block44f0eee2011-05-26 01:26:41 +0100985 static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000986
Leon Clarkee46be812010-01-19 14:06:41 +0000987 // Static variables for RegExp.
Steve Block44f0eee2011-05-26 01:26:41 +0100988 static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
989 static ExternalReference address_of_regexp_stack_memory_address(
990 Isolate* isolate);
991 static ExternalReference address_of_regexp_stack_memory_size(
992 Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +0000993
Ben Murdoch3ef787d2012-04-12 10:51:47 +0100994 // Write barrier.
995 static ExternalReference store_buffer_top(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +0000996
997 // Used for fast allocation in generated code.
Steve Block44f0eee2011-05-26 01:26:41 +0100998 static ExternalReference new_space_allocation_top_address(Isolate* isolate);
999 static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001000 static ExternalReference old_space_allocation_top_address(Isolate* isolate);
1001 static ExternalReference old_space_allocation_limit_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001002
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001003 static ExternalReference mod_two_doubles_operation(Isolate* isolate);
Steve Block44f0eee2011-05-26 01:26:41 +01001004 static ExternalReference power_double_double_function(Isolate* isolate);
1005 static ExternalReference power_double_int_function(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001006
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001007 static ExternalReference handle_scope_next_address(Isolate* isolate);
1008 static ExternalReference handle_scope_limit_address(Isolate* isolate);
1009 static ExternalReference handle_scope_level_address(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +00001010
Steve Block44f0eee2011-05-26 01:26:41 +01001011 static ExternalReference scheduled_exception_address(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001012 static ExternalReference address_of_pending_message_obj(Isolate* isolate);
Steve Blockd0582a62009-12-15 09:54:21 +00001013
Ben Murdochb0fe1622011-05-05 13:52:32 +01001014 // Static variables containing common double constants.
1015 static ExternalReference address_of_min_int();
1016 static ExternalReference address_of_one_half();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001017 static ExternalReference address_of_minus_one_half();
Ben Murdochb0fe1622011-05-05 13:52:32 +01001018 static ExternalReference address_of_negative_infinity();
Ben Murdoch3fb3ca82011-12-02 17:19:32 +00001019 static ExternalReference address_of_the_hole_nan();
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001020 static ExternalReference address_of_uint32_bias();
Ben Murdochb0fe1622011-05-05 13:52:32 +01001021
Steve Block44f0eee2011-05-26 01:26:41 +01001022 static ExternalReference math_log_double_function(Isolate* isolate);
Ben Murdoche0cee9b2011-05-25 10:26:03 +01001023
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001024 static ExternalReference math_exp_constants(int constant_index);
1025 static ExternalReference math_exp_log_table();
Steve Blocka7e24c12009-10-30 11:49:00 +00001026
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001027 static ExternalReference page_flags(Page* page);
1028
1029 static ExternalReference ForDeoptEntry(Address entry);
1030
1031 static ExternalReference cpu_features();
1032
Ben Murdochda12d292016-06-02 14:46:10 +01001033 static ExternalReference is_tail_call_elimination_enabled_address(
1034 Isolate* isolate);
1035
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001036 static ExternalReference debug_is_active_address(Isolate* isolate);
1037 static ExternalReference debug_after_break_target_address(Isolate* isolate);
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001038
1039 static ExternalReference is_profiling_address(Isolate* isolate);
1040 static ExternalReference invoke_function_callback(Isolate* isolate);
1041 static ExternalReference invoke_accessor_getter_callback(Isolate* isolate);
1042
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001043 static ExternalReference virtual_handler_register(Isolate* isolate);
1044 static ExternalReference virtual_slot_register(Isolate* isolate);
1045
1046 static ExternalReference runtime_function_table_address(Isolate* isolate);
1047
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001048 Address address() const { return reinterpret_cast<Address>(address_); }
1049
Steve Blocka7e24c12009-10-30 11:49:00 +00001050 // Used to check if single stepping is enabled in generated code.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001051 static ExternalReference debug_step_in_enabled_address(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001052
Steve Block6ded16b2010-05-10 14:33:55 +01001053#ifndef V8_INTERPRETED_REGEXP
Steve Blocka7e24c12009-10-30 11:49:00 +00001054 // C functions called from RegExp generated code.
1055
1056 // Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
Steve Block44f0eee2011-05-26 01:26:41 +01001057 static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001058
1059 // Function RegExpMacroAssembler*::CheckStackGuardState()
Steve Block44f0eee2011-05-26 01:26:41 +01001060 static ExternalReference re_check_stack_guard_state(Isolate* isolate);
Steve Blocka7e24c12009-10-30 11:49:00 +00001061
1062 // Function NativeRegExpMacroAssembler::GrowStack()
Steve Block44f0eee2011-05-26 01:26:41 +01001063 static ExternalReference re_grow_stack(Isolate* isolate);
Leon Clarkee46be812010-01-19 14:06:41 +00001064
1065 // byte NativeRegExpMacroAssembler::word_character_bitmap
1066 static ExternalReference re_word_character_map();
1067
Steve Blocka7e24c12009-10-30 11:49:00 +00001068#endif
1069
1070 // This lets you register a function that rewrites all external references.
1071 // Used by the ARM simulator to catch calls to external references.
Ben Murdoch257744e2011-11-30 15:57:28 +00001072 static void set_redirector(Isolate* isolate,
1073 ExternalReferenceRedirector* redirector) {
Steve Block44f0eee2011-05-26 01:26:41 +01001074 // We can't stack them.
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001075 DCHECK(isolate->external_reference_redirector() == NULL);
Ben Murdoch257744e2011-11-30 15:57:28 +00001076 isolate->set_external_reference_redirector(
Steve Block44f0eee2011-05-26 01:26:41 +01001077 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
Steve Blocka7e24c12009-10-30 11:49:00 +00001078 }
1079
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001080 static ExternalReference stress_deopt_count(Isolate* isolate);
1081
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001082 static ExternalReference fixed_typed_array_base_data_offset();
1083
Steve Blocka7e24c12009-10-30 11:49:00 +00001084 private:
1085 explicit ExternalReference(void* address)
1086 : address_(address) {}
1087
Steve Block44f0eee2011-05-26 01:26:41 +01001088 static void* Redirect(Isolate* isolate,
Steve Block44f0eee2011-05-26 01:26:41 +01001089 Address address_arg,
Steve Block1e0659c2011-05-24 12:43:12 +01001090 Type type = ExternalReference::BUILTIN_CALL) {
Steve Block44f0eee2011-05-26 01:26:41 +01001091 ExternalReferenceRedirector* redirector =
1092 reinterpret_cast<ExternalReferenceRedirector*>(
1093 isolate->external_reference_redirector());
Steve Blocka7e24c12009-10-30 11:49:00 +00001094 void* address = reinterpret_cast<void*>(address_arg);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001095 void* answer =
1096 (redirector == NULL) ? address : (*redirector)(isolate, address, type);
Steve Blockd0582a62009-12-15 09:54:21 +00001097 return answer;
Steve Blocka7e24c12009-10-30 11:49:00 +00001098 }
1099
1100 void* address_;
1101};
1102
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001103bool operator==(ExternalReference, ExternalReference);
1104bool operator!=(ExternalReference, ExternalReference);
1105
1106size_t hash_value(ExternalReference);
1107
1108std::ostream& operator<<(std::ostream&, ExternalReference);
1109
Steve Blocka7e24c12009-10-30 11:49:00 +00001110
1111// -----------------------------------------------------------------------------
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001112// Position recording support
1113
Ben Murdochb0fe1622011-05-05 13:52:32 +01001114struct PositionState {
1115 PositionState() : current_position(RelocInfo::kNoPosition),
1116 written_position(RelocInfo::kNoPosition),
1117 current_statement_position(RelocInfo::kNoPosition),
1118 written_statement_position(RelocInfo::kNoPosition) {}
1119
1120 int current_position;
1121 int written_position;
1122
1123 int current_statement_position;
1124 int written_statement_position;
1125};
1126
Ben Murdochda12d292016-06-02 14:46:10 +01001127class AssemblerPositionsRecorder : public PositionsRecorder {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001128 public:
Ben Murdochda12d292016-06-02 14:46:10 +01001129 explicit AssemblerPositionsRecorder(Assembler* assembler)
1130 : assembler_(assembler) {}
Ben Murdochb8e0da22011-05-16 14:20:40 +01001131
Ben Murdochb0fe1622011-05-05 13:52:32 +01001132 // Set current position to pos.
1133 void RecordPosition(int pos);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001134
1135 // Set current statement position to pos.
1136 void RecordStatementPosition(int pos);
1137
1138 // Write recorded positions to relocation information.
1139 bool WriteRecordedPositions();
1140
Ben Murdochb0fe1622011-05-05 13:52:32 +01001141 int current_position() const { return state_.current_position; }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001142
Ben Murdochb0fe1622011-05-05 13:52:32 +01001143 int current_statement_position() const {
1144 return state_.current_statement_position;
1145 }
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001146
1147 private:
1148 Assembler* assembler_;
Ben Murdochb0fe1622011-05-05 13:52:32 +01001149 PositionState state_;
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001150
Ben Murdochda12d292016-06-02 14:46:10 +01001151 DISALLOW_COPY_AND_ASSIGN(AssemblerPositionsRecorder);
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001152};
1153
1154
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -08001155// -----------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +00001156// Utility functions
1157
Ben Murdoch3ef787d2012-04-12 10:51:47 +01001158inline int NumberOfBitsSet(uint32_t x) {
Andrei Popescu31002712010-02-23 13:46:05 +00001159 unsigned int num_bits_set;
1160 for (num_bits_set = 0; x; x >>= 1) {
1161 num_bits_set += x & 1;
1162 }
1163 return num_bits_set;
1164}
Steve Blocka7e24c12009-10-30 11:49:00 +00001165
Ben Murdochb0fe1622011-05-05 13:52:32 +01001166// Computes pow(x, y) with the special cases in the spec for Math.pow.
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001167double power_helper(Isolate* isolate, double x, double y);
Ben Murdochb0fe1622011-05-05 13:52:32 +01001168double power_double_int(double x, int y);
1169double power_double_double(double x, double y);
1170
Ben Murdoch257744e2011-11-30 15:57:28 +00001171// Helper class for generating code or data associated with the code
1172// right after a call instruction. As an example this can be used to
1173// generate safepoint data after calls for crankshaft.
1174class CallWrapper {
1175 public:
1176 CallWrapper() { }
1177 virtual ~CallWrapper() { }
1178 // Called just before emitting a call. Argument is the size of the generated
1179 // call code.
1180 virtual void BeforeCall(int call_size) const = 0;
1181 // Called just after emitting a call, i.e., at the return site for the call.
1182 virtual void AfterCall() const = 0;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001183 // Return whether call needs to check for debug stepping.
1184 virtual bool NeedsDebugStepCheck() const { return false; }
Ben Murdoch257744e2011-11-30 15:57:28 +00001185};
1186
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001187
Ben Murdoch257744e2011-11-30 15:57:28 +00001188class NullCallWrapper : public CallWrapper {
1189 public:
1190 NullCallWrapper() { }
1191 virtual ~NullCallWrapper() { }
1192 virtual void BeforeCall(int call_size) const { }
1193 virtual void AfterCall() const { }
1194};
1195
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001196
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001197class CheckDebugStepCallWrapper : public CallWrapper {
1198 public:
1199 CheckDebugStepCallWrapper() {}
1200 virtual ~CheckDebugStepCallWrapper() {}
1201 virtual void BeforeCall(int call_size) const {}
1202 virtual void AfterCall() const {}
1203 virtual bool NeedsDebugStepCheck() const { return true; }
1204};
Steve Blocka7e24c12009-10-30 11:49:00 +00001205
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001206
1207// -----------------------------------------------------------------------------
1208// Constant pool support
1209
1210class ConstantPoolEntry {
1211 public:
1212 ConstantPoolEntry() {}
1213 ConstantPoolEntry(int position, intptr_t value, bool sharing_ok)
1214 : position_(position),
1215 merged_index_(sharing_ok ? SHARING_ALLOWED : SHARING_PROHIBITED),
1216 value_(value) {}
1217 ConstantPoolEntry(int position, double value)
1218 : position_(position), merged_index_(SHARING_ALLOWED), value64_(value) {}
1219
1220 int position() const { return position_; }
1221 bool sharing_ok() const { return merged_index_ != SHARING_PROHIBITED; }
1222 bool is_merged() const { return merged_index_ >= 0; }
1223 int merged_index(void) const {
1224 DCHECK(is_merged());
1225 return merged_index_;
1226 }
1227 void set_merged_index(int index) {
1228 merged_index_ = index;
1229 DCHECK(is_merged());
1230 }
1231 int offset(void) const {
1232 DCHECK(merged_index_ >= 0);
1233 return merged_index_;
1234 }
1235 void set_offset(int offset) {
1236 DCHECK(offset >= 0);
1237 merged_index_ = offset;
1238 }
1239 intptr_t value() const { return value_; }
1240 uint64_t value64() const { return bit_cast<uint64_t>(value64_); }
1241
1242 enum Type { INTPTR, DOUBLE, NUMBER_OF_TYPES };
1243
1244 static int size(Type type) {
1245 return (type == INTPTR) ? kPointerSize : kDoubleSize;
1246 }
1247
1248 enum Access { REGULAR, OVERFLOWED };
1249
1250 private:
1251 int position_;
1252 int merged_index_;
1253 union {
1254 intptr_t value_;
1255 double value64_;
1256 };
1257 enum { SHARING_PROHIBITED = -2, SHARING_ALLOWED = -1 };
1258};
1259
1260
1261// -----------------------------------------------------------------------------
1262// Embedded constant pool support
1263
1264class ConstantPoolBuilder BASE_EMBEDDED {
1265 public:
1266 ConstantPoolBuilder(int ptr_reach_bits, int double_reach_bits);
1267
1268 // Add pointer-sized constant to the embedded constant pool
1269 ConstantPoolEntry::Access AddEntry(int position, intptr_t value,
1270 bool sharing_ok) {
1271 ConstantPoolEntry entry(position, value, sharing_ok);
1272 return AddEntry(entry, ConstantPoolEntry::INTPTR);
1273 }
1274
1275 // Add double constant to the embedded constant pool
1276 ConstantPoolEntry::Access AddEntry(int position, double value) {
1277 ConstantPoolEntry entry(position, value);
1278 return AddEntry(entry, ConstantPoolEntry::DOUBLE);
1279 }
1280
1281 // Previews the access type required for the next new entry to be added.
1282 ConstantPoolEntry::Access NextAccess(ConstantPoolEntry::Type type) const;
1283
1284 bool IsEmpty() {
1285 return info_[ConstantPoolEntry::INTPTR].entries.empty() &&
1286 info_[ConstantPoolEntry::INTPTR].shared_entries.empty() &&
1287 info_[ConstantPoolEntry::DOUBLE].entries.empty() &&
1288 info_[ConstantPoolEntry::DOUBLE].shared_entries.empty();
1289 }
1290
1291 // Emit the constant pool. Invoke only after all entries have been
1292 // added and all instructions have been emitted.
1293 // Returns position of the emitted pool (zero implies no constant pool).
1294 int Emit(Assembler* assm);
1295
1296 // Returns the label associated with the start of the constant pool.
1297 // Linking to this label in the function prologue may provide an
1298 // efficient means of constant pool pointer register initialization
1299 // on some architectures.
1300 inline Label* EmittedPosition() { return &emitted_label_; }
1301
1302 private:
1303 ConstantPoolEntry::Access AddEntry(ConstantPoolEntry& entry,
1304 ConstantPoolEntry::Type type);
1305 void EmitSharedEntries(Assembler* assm, ConstantPoolEntry::Type type);
1306 void EmitGroup(Assembler* assm, ConstantPoolEntry::Access access,
1307 ConstantPoolEntry::Type type);
1308
1309 struct PerTypeEntryInfo {
1310 PerTypeEntryInfo() : regular_count(0), overflow_start(-1) {}
1311 bool overflow() const {
1312 return (overflow_start >= 0 &&
1313 overflow_start < static_cast<int>(entries.size()));
1314 }
1315 int regular_reach_bits;
1316 int regular_count;
1317 int overflow_start;
1318 std::vector<ConstantPoolEntry> entries;
1319 std::vector<ConstantPoolEntry> shared_entries;
1320 };
1321
1322 Label emitted_label_; // Records pc_offset of emitted pool
1323 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES];
1324};
1325
1326} // namespace internal
1327} // namespace v8
Steve Blocka7e24c12009-10-30 11:49:00 +00001328#endif // V8_ASSEMBLER_H_