35 #ifndef V8_ASSEMBLER_H_
36 #define V8_ASSEMBLER_H_
73 enabled_cpu_features_ = features;
76 return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
104 uint64_t enabled_cpu_features_;
105 bool emit_debug_code_;
106 bool predictable_code_size_;
134 uint64_t old_enabled_;
146 ~PlatformFeatureScope();
149 uint64_t old_cross_compile_;
172 ASSERT(!is_near_linked());
176 INLINE(
void UnuseNear()) { near_link_pos_ = 0; }
178 INLINE(
bool is_bound()
const) {
return pos_ < 0; }
179 INLINE(
bool is_unused()
const) {
return pos_ == 0 && near_link_pos_ == 0; }
180 INLINE(
bool is_linked()
const) {
return pos_ > 0; }
181 INLINE(
bool is_near_linked()
const) {
return near_link_pos_ > 0; }
200 void bind_to(
int pos) {
204 void link_to(
int pos, Distance distance = kFar) {
205 if (distance == kNear) {
206 near_link_pos_ = pos + 1;
214 friend class Assembler;
215 friend class Displacement;
216 friend class RegExpMacroAssemblerIrregexp;
218 #if V8_TARGET_ARCH_ARM64
251 static const int kNoPosition = -1;
265 static const int kMaxCallSize = 6;
301 FIRST_REAL_RELOC_MODE = CODE_TARGET,
302 LAST_REAL_RELOC_MODE = VENEER_POOL,
303 FIRST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE,
304 LAST_PSEUDO_RELOC_MODE = CODE_AGE_SEQUENCE,
306 LAST_GCED_ENUM = CELL,
308 LAST_COMPACT_ENUM = CODE_TARGET_WITH_ID,
309 LAST_STANDARD_NONCOMPACT_ENUM = INTERNAL_REFERENCE
316 : pc_(pc), rmode_(rmode), data_(data), host_(host) {
319 : pc_(pc), rmode_(NONE64), data64_(data64), host_(
NULL) {
323 return mode >= FIRST_REAL_RELOC_MODE &&
324 mode <= LAST_REAL_RELOC_MODE;
327 ASSERT(!IsRealRelocMode(mode));
328 return mode >= FIRST_PSEUDO_RELOC_MODE &&
329 mode <= LAST_PSEUDO_RELOC_MODE;
332 return mode == CONSTRUCT_CALL;
335 return mode <= LAST_CODE_ENUM;
338 return mode == EMBEDDED_OBJECT;
345 return mode <= LAST_GCED_ENUM;
348 return mode == JS_RETURN;
351 return mode == COMMENT;
354 return mode == CONST_POOL;
357 return mode == VENEER_POOL;
360 return mode == POSITION || mode == STATEMENT_POSITION;
363 return mode == STATEMENT_POSITION;
366 return mode == EXTERNAL_REFERENCE;
369 return mode == INTERNAL_REFERENCE;
372 return mode == DEBUG_BREAK_SLOT;
375 return mode == NONE32 || mode == NONE64;
378 return mode == CODE_AGE_SEQUENCE;
384 static inline bool IsEqual(RelocInfo first, RelocInfo second) {
385 return first.rmode() == second.rmode() &&
386 (first.rmode() == RelocInfo::NONE64 ?
387 first.raw_data64() == second.raw_data64() :
388 first.data() == second.data());
395 intptr_t
data()
const {
return data_; }
396 double data64()
const {
return data64_; }
398 return BitCast<uint64_t>(data64_);
404 INLINE(
void apply(intptr_t delta));
409 bool IsCodedSpecially();
413 bool IsInConstantPool();
458 INLINE(
int target_address_size());
477 template<
typename StaticVisitor>
inline void Visit(
Heap* heap);
478 inline void Visit(
Isolate* isolate, ObjectVisitor* v);
481 void PatchCode(
byte* instructions,
int instruction_count);
484 void PatchCodeWithCall(
Address target,
int guard_bytes);
488 INLINE(
bool IsPatchedReturnSequence());
492 INLINE(
bool IsPatchedDebugBreakSlotSequence());
497 static bool RequiresRelocation(
const CodeDesc& desc);
500 #ifdef ENABLE_DISASSEMBLER
502 static const char* RelocModeName(Mode rmode);
504 #endif // ENABLE_DISASSEMBLER
509 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
510 static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
511 static const int kDataMask =
512 (1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
531 Address reconstructed_adr_ptr_;
552 void Write(
const RelocInfo* rinfo);
566 static const int kMaxSize = 16;
569 inline uint32_t WriteVariableLengthPCJump(uint32_t pc_delta);
570 inline void WriteTaggedPC(uint32_t pc_delta,
int tag);
571 inline void WriteExtraTaggedPC(uint32_t pc_delta,
int extra_tag);
572 inline void WriteExtraTaggedIntData(
int data_delta,
int top_tag);
573 inline void WriteExtraTaggedPoolData(
int data,
int pool_type);
574 inline void WriteExtraTaggedData(intptr_t data_delta,
int top_tag);
575 inline void WriteTaggedData(intptr_t data_delta,
int tag);
576 inline void WriteExtraTag(
int extra_tag,
int top_tag);
604 bool done()
const {
return done_; }
617 void Advance(
int bytes = 1) { pos_ -= bytes; }
622 void AdvanceReadPC();
623 void AdvanceReadId();
624 void AdvanceReadPoolData();
625 void AdvanceReadPosition();
626 void AdvanceReadData();
627 void AdvanceReadVariableLengthPCJump();
628 int GetLocatableTypeTag();
630 void ReadTaggedPosition();
634 bool SetMode(RelocInfo::Mode
mode) {
635 return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ =
mode,
true) :
false;
640 byte* code_age_sequence_;
655 class SCTableReference;
656 #ifdef ENABLE_DEBUGGER_SUPPORT
705 PROFILING_GETTER_CALL
709 static void InitializeMathExpData();
710 static void TearDownMathExpData();
728 #ifdef ENABLE_DEBUGGER_SUPPORT
729 ExternalReference(
const Debug_Address& debug_address,
Isolate* isolate);
739 static ExternalReference isolate_address(
Isolate* isolate);
745 static ExternalReference incremental_marking_record_write_function(
747 static ExternalReference store_buffer_overflow_function(
749 static ExternalReference flush_icache_function(
Isolate* isolate);
750 static ExternalReference perform_gc_function(
Isolate* isolate);
751 static ExternalReference out_of_memory_function(
Isolate* isolate);
752 static ExternalReference delete_handle_scope_extensions(
Isolate* isolate);
754 static ExternalReference get_date_field_function(
Isolate* isolate);
755 static ExternalReference date_cache_stamp(
Isolate* isolate);
757 static ExternalReference get_make_code_young_function(
Isolate* isolate);
758 static ExternalReference get_mark_code_as_executed_function(
Isolate* isolate);
761 static ExternalReference new_deoptimizer_function(
Isolate* isolate);
762 static ExternalReference compute_output_frames_function(
Isolate* isolate);
765 static ExternalReference log_enter_external_function(
Isolate* isolate);
766 static ExternalReference log_leave_external_function(
Isolate* isolate);
769 static ExternalReference keyed_lookup_cache_keys(
Isolate* isolate);
770 static ExternalReference keyed_lookup_cache_field_offsets(
Isolate* isolate);
773 static ExternalReference roots_array_start(
Isolate* isolate);
776 static ExternalReference allocation_sites_list_address(
Isolate* isolate);
779 static ExternalReference address_of_stack_limit(
Isolate* isolate);
782 static ExternalReference address_of_real_stack_limit(
Isolate* isolate);
785 static ExternalReference address_of_regexp_stack_limit(
Isolate* isolate);
788 static ExternalReference address_of_static_offsets_vector(
Isolate* isolate);
789 static ExternalReference address_of_regexp_stack_memory_address(
791 static ExternalReference address_of_regexp_stack_memory_size(
795 static ExternalReference new_space_start(
Isolate* isolate);
796 static ExternalReference new_space_mask(
Isolate* isolate);
797 static ExternalReference heap_always_allocate_scope_depth(
Isolate* isolate);
798 static ExternalReference new_space_mark_bits(
Isolate* isolate);
801 static ExternalReference store_buffer_top(
Isolate* isolate);
804 static ExternalReference new_space_allocation_top_address(
Isolate* isolate);
805 static ExternalReference new_space_allocation_limit_address(
Isolate* isolate);
806 static ExternalReference old_pointer_space_allocation_top_address(
808 static ExternalReference old_pointer_space_allocation_limit_address(
810 static ExternalReference old_data_space_allocation_top_address(
812 static ExternalReference old_data_space_allocation_limit_address(
814 static ExternalReference new_space_high_promotion_mode_active_address(
817 static ExternalReference mod_two_doubles_operation(
Isolate* isolate);
818 static ExternalReference power_double_double_function(
Isolate* isolate);
819 static ExternalReference power_double_int_function(
Isolate* isolate);
821 static ExternalReference handle_scope_next_address(
Isolate* isolate);
822 static ExternalReference handle_scope_limit_address(
Isolate* isolate);
823 static ExternalReference handle_scope_level_address(
Isolate* isolate);
825 static ExternalReference scheduled_exception_address(
Isolate* isolate);
826 static ExternalReference address_of_pending_message_obj(
Isolate* isolate);
827 static ExternalReference address_of_has_pending_message(
Isolate* isolate);
828 static ExternalReference address_of_pending_message_script(
Isolate* isolate);
831 static ExternalReference address_of_min_int();
832 static ExternalReference address_of_one_half();
833 static ExternalReference address_of_minus_one_half();
834 static ExternalReference address_of_minus_zero();
835 static ExternalReference address_of_zero();
836 static ExternalReference address_of_uint8_max_value();
837 static ExternalReference address_of_negative_infinity();
838 static ExternalReference address_of_canonical_non_hole_nan();
839 static ExternalReference address_of_the_hole_nan();
840 static ExternalReference address_of_uint32_bias();
842 static ExternalReference math_log_double_function(
Isolate* isolate);
844 static ExternalReference math_exp_constants(
int constant_index);
845 static ExternalReference math_exp_log_table();
847 static ExternalReference page_flags(
Page* page);
849 static ExternalReference ForDeoptEntry(
Address entry);
851 static ExternalReference cpu_features();
855 #ifdef ENABLE_DEBUGGER_SUPPORT
857 static ExternalReference debug_break(
Isolate* isolate);
860 static ExternalReference debug_step_in_fp_address(
Isolate* isolate);
863 #ifndef V8_INTERPRETED_REGEXP
867 static ExternalReference re_case_insensitive_compare_uc16(
Isolate* isolate);
870 static ExternalReference re_check_stack_guard_state(
Isolate* isolate);
873 static ExternalReference re_grow_stack(
Isolate* isolate);
876 static ExternalReference re_word_character_map();
883 ExternalReferenceRedirector* redirector) {
885 ASSERT(isolate->external_reference_redirector() ==
NULL);
886 isolate->set_external_reference_redirector(
887 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
890 static ExternalReference stress_deopt_count(
Isolate* isolate);
893 return address_ == other.address_;
897 return !(*
this == other);
901 explicit ExternalReference(
void* address)
902 : address_(address) {}
904 static void* Redirect(
Isolate* isolate,
906 Type type = ExternalReference::BUILTIN_CALL) {
907 ExternalReferenceRedirector* redirector =
908 reinterpret_cast<ExternalReferenceRedirector*
>(
909 isolate->external_reference_redirector());
910 if (redirector ==
NULL)
return address;
911 void* answer = (*redirector)(address, type);
915 static void* Redirect(Isolate* isolate,
917 Type type = ExternalReference::BUILTIN_CALL) {
918 ExternalReferenceRedirector* redirector =
919 reinterpret_cast<ExternalReferenceRedirector*
>(
920 isolate->external_reference_redirector());
921 void* address =
reinterpret_cast<void*
>(address_arg);
922 void* answer = (redirector ==
NULL) ?
924 (*redirector)(address, type);
952 : assembler_(assembler) {
953 #ifdef ENABLE_GDB_JIT_INTERFACE
954 gdbjit_lineinfo_ =
NULL;
956 jit_handler_data_ =
NULL;
959 #ifdef ENABLE_GDB_JIT_INTERFACE
960 ~PositionsRecorder() {
961 delete gdbjit_lineinfo_;
964 void StartGDBJITLineInfoRecording() {
966 gdbjit_lineinfo_ =
new GDBJITLineInfo();
970 GDBJITLineInfo* DetachGDBJITLineInfo() {
971 GDBJITLineInfo* lineinfo = gdbjit_lineinfo_;
972 gdbjit_lineinfo_ =
NULL;
977 jit_handler_data_ = user_data;
981 void* old_data = jit_handler_data_;
982 jit_handler_data_ =
NULL;
986 void RecordPosition(
int pos);
989 void RecordStatementPosition(
int pos);
992 bool WriteRecordedPositions();
997 return state_.current_statement_position;
1003 #ifdef ENABLE_GDB_JIT_INTERFACE
1004 GDBJITLineInfo* gdbjit_lineinfo_;
1009 void* jit_handler_data_;
1010 friend class PreservePositionScope;
1019 : positions_recorder_(positions_recorder),
1020 saved_state_(positions_recorder->state_) {}
1023 positions_recorder_->state_ = saved_state_;
1027 PositionsRecorder* positions_recorder_;
1038 unsigned int num_bits_set;
1039 for (num_bits_set = 0; x; x >>= 1) {
1040 num_bits_set += x & 1;
1042 return num_bits_set;
1061 virtual void BeforeCall(
int call_size)
const = 0;
1091 #endif // V8_ASSEMBLER_H_
RelocIterator(Code *code, int mode_mask=-1)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
static bool IsDebugBreakSlot(Mode mode)
Isolate * isolate() const
int near_link_pos() const
static bool IsExternalReference(Mode mode)
RelocInfo(byte *pc, Mode rmode, intptr_t data, Code *host)
virtual void BeforeCall(int call_size) const =0
int written_statement_position
virtual ~NullCallWrapper()
static void set_redirector(Isolate *isolate, ExternalReferenceRedirector *redirector)
static bool IsNone(Mode mode)
PositionsRecorder(Assembler *assembler)
static bool IsRuntimeEntry(Mode mode)
double power_helper(double x, double y)
bool operator==(const ExternalReference &other) const
void * ExternalReferenceRedirector(void *original, Type type)
TypeImpl< ZoneTypeConfig > Type
int current_statement_position() const
static const int kMinimalBufferSize
#define ASSERT(condition)
virtual void AbortedCodeGeneration()
static bool IsComment(Mode mode)
PredictableCodeSizeScope(AssemblerBase *assembler, int expected_size)
static bool IsRealRelocMode(Mode mode)
static void QuietNaN(HeapObject *nan)
void set_emit_debug_code(bool value)
static bool IsPseudoRelocMode(Mode mode)
void set_host(Code *host)
static bool IsCodeAgeSequence(Mode mode)
void Reposition(byte *pos, byte *pc)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long mode(MIPS only)") DEFINE_string(expose_natives_as
PreservePositionScope(PositionsRecorder *positions_recorder)
bool predictable_code_size() const
static bool IsConstPool(Mode mode)
static const int kApplyMask
AssemblerBase(Isolate *isolate, void *buffer, int buffer_size)
double power_double_double(double x, double y)
void set_enabled_cpu_features(uint64_t features)
virtual void AfterCall() const
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
static bool IsJSReturn(Mode mode)
static const int kMaxSmallPCDelta
double power_double_int(double x, int y)
void AttachJITHandlerData(void *user_data)
static bool IsEqual(RelocInfo first, RelocInfo second)
static bool IsStatementPosition(Mode mode)
bool operator!=(const ExternalReference &other) const
MultiplierAndShift(int32_t d)
static bool IsEmbeddedObject(Mode mode)
INLINE(bool is_near_linked() const)
void set_predictable_code_size(bool value)
static bool IsPosition(Mode mode)
INLINE(static HeapObject *EnsureDoubleAligned(Heap *heap, HeapObject *object, int size))
bool emit_debug_code() const
static bool IsGCRelocMode(Mode mode)
static int ModeMask(Mode mode)
static bool IsCodeTarget(Mode mode)
int current_statement_position
uint64_t enabled_cpu_features() const
void * DetachJITHandlerData()
CpuFeatureScope(AssemblerBase *assembler, CpuFeature f)
void Print(const v8::FunctionCallbackInfo< v8::Value > &args)
static bool IsInternalReference(Mode mode)
int32_t multiplier() const
RelocInfoWriter(byte *pos, byte *pc)
~PredictableCodeSizeScope()
static bool IsVeneerPool(Mode mode)
static bool IsConstructCall(Mode mode)
RelocInfo(byte *pc, double data64)
virtual void AfterCall() const =0
INLINE(bool is_unused() const)
bool IsEnabled(CpuFeature f)
virtual void BeforeCall(int call_size) const
int NumberOfBitsSet(uint32_t x)
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter trace hydrogen to given file name trace inlining decisions trace store elimination trace all use positions trace global value numbering trace hydrogen escape analysis trace the tracking of allocation sites trace map generalization environment for every instruction deoptimize every n garbage collections put a break point before deoptimizing deoptimize uncommon cases use on stack replacement trace array bounds check elimination perform array index dehoisting use load elimination use store elimination use constant folding eliminate unreachable code number of stress runs when picking a function to watch for shared function not JSFunction itself flushes the cache of optimized code for closures on every GC functions with arguments object maximum number of escape analysis fix point iterations allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms concurrent on stack replacement do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes number of stack frames inspected by the profiler percentage of ICs that must have type info to allow optimization extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long expose natives in global object expose freeBuffer extension expose gc extension under the specified name expose externalize string extension number of stack frames to capture disable builtin natives files print name of functions for which code is generated use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations always try to OSR functions trace optimize function deoptimization minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions trace debugging JSON request response trace out of bounds accesses to external arrays trace_js_array_abuse automatically set the debug break flag when debugger commands are in the queue abort by crashing maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable always perform global GCs print one trace line following each garbage collection do not print trace line after scavenger collection print statistics of the maximum memory committed for the heap in name
INLINE(bool is_linked() const)
bool EvalComparison(Token::Value op, double op1, double op2)
int current_position() const
INLINE(bool is_bound() const)
static const char *const kFillerCommentString