Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: src/assembler.h

Issue 2732273003: Disentangle assembler from isolate. (Closed)
Patch Set: Address feedback. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/arm64/macro-assembler-arm64.cc ('k') | src/assembler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 1994-2006 Sun Microsystems Inc. 1 // Copyright (c) 1994-2006 Sun Microsystems Inc.
2 // All Rights Reserved. 2 // All Rights Reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // - Redistributions of source code must retain the above copyright notice, 8 // - Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer. 9 // this list of conditions and the following disclaimer.
10 // 10 //
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 class StatsCounter; 57 class StatsCounter;
58 58
59 // ----------------------------------------------------------------------------- 59 // -----------------------------------------------------------------------------
60 // Platform independent assembler base class. 60 // Platform independent assembler base class.
61 61
62 enum class CodeObjectRequired { kNo, kYes }; 62 enum class CodeObjectRequired { kNo, kYes };
63 63
64 64
65 class AssemblerBase: public Malloced { 65 class AssemblerBase: public Malloced {
66 public: 66 public:
67 AssemblerBase(Isolate* isolate, void* buffer, int buffer_size); 67 struct IsolateData {
68 explicit IsolateData(Isolate* isolate);
69 IsolateData(const IsolateData&) = default;
70
71 bool serializer_enabled_;
72 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
73 size_t max_old_generation_size_;
74 #endif
75 #if V8_TARGET_ARCH_X64
76 Address code_range_start_;
77 #endif
78 };
79
80 AssemblerBase(IsolateData isolate_data, void* buffer, int buffer_size);
68 virtual ~AssemblerBase(); 81 virtual ~AssemblerBase();
69 82
70 Isolate* isolate() const { return isolate_; } 83 IsolateData isolate_data() const { return isolate_data_; }
71 int jit_cookie() const { return jit_cookie_; } 84
85 bool serializer_enabled() const { return isolate_data_.serializer_enabled_; }
86 void enable_serializer() { isolate_data_.serializer_enabled_ = true; }
72 87
73 bool emit_debug_code() const { return emit_debug_code_; } 88 bool emit_debug_code() const { return emit_debug_code_; }
74 void set_emit_debug_code(bool value) { emit_debug_code_ = value; } 89 void set_emit_debug_code(bool value) { emit_debug_code_ = value; }
75 90
76 bool serializer_enabled() const { return serializer_enabled_; }
77 void enable_serializer() { serializer_enabled_ = true; }
78
79 bool predictable_code_size() const { return predictable_code_size_; } 91 bool predictable_code_size() const { return predictable_code_size_; }
80 void set_predictable_code_size(bool value) { predictable_code_size_ = value; } 92 void set_predictable_code_size(bool value) { predictable_code_size_ = value; }
81 93
82 uint64_t enabled_cpu_features() const { return enabled_cpu_features_; } 94 uint64_t enabled_cpu_features() const { return enabled_cpu_features_; }
83 void set_enabled_cpu_features(uint64_t features) { 95 void set_enabled_cpu_features(uint64_t features) {
84 enabled_cpu_features_ = features; 96 enabled_cpu_features_ = features;
85 } 97 }
86 // Features are usually enabled by CpuFeatureScope, which also asserts that 98 // Features are usually enabled by CpuFeatureScope, which also asserts that
87 // the features are supported before they are enabled. 99 // the features are supported before they are enabled.
88 bool IsEnabled(CpuFeature f) { 100 bool IsEnabled(CpuFeature f) {
(...skipping 17 matching lines...) Expand all
106 // cross-snapshotting. 118 // cross-snapshotting.
107 static void QuietNaN(HeapObject* nan) { } 119 static void QuietNaN(HeapObject* nan) { }
108 120
109 int pc_offset() const { return static_cast<int>(pc_ - buffer_); } 121 int pc_offset() const { return static_cast<int>(pc_ - buffer_); }
110 122
111 // This function is called when code generation is aborted, so that 123 // This function is called when code generation is aborted, so that
112 // the assembler could clean up internal data structures. 124 // the assembler could clean up internal data structures.
113 virtual void AbortedCodeGeneration() { } 125 virtual void AbortedCodeGeneration() { }
114 126
115 // Debugging 127 // Debugging
116 void Print(); 128 void Print(Isolate* isolate);
117 129
118 static const int kMinimalBufferSize = 4*KB; 130 static const int kMinimalBufferSize = 4*KB;
119 131
120 static void FlushICache(Isolate* isolate, void* start, size_t size); 132 static void FlushICache(Isolate* isolate, void* start, size_t size);
121 133
122 protected: 134 protected:
123 // The buffer into which code and relocation info are generated. It could 135 // The buffer into which code and relocation info are generated. It could
124 // either be owned by the assembler or be provided externally. 136 // either be owned by the assembler or be provided externally.
125 byte* buffer_; 137 byte* buffer_;
126 int buffer_size_; 138 int buffer_size_;
127 bool own_buffer_; 139 bool own_buffer_;
128 140
129 void set_constant_pool_available(bool available) { 141 void set_constant_pool_available(bool available) {
130 if (FLAG_enable_embedded_constant_pool) { 142 if (FLAG_enable_embedded_constant_pool) {
131 constant_pool_available_ = available; 143 constant_pool_available_ = available;
132 } else { 144 } else {
133 // Embedded constant pool not supported on this architecture. 145 // Embedded constant pool not supported on this architecture.
134 UNREACHABLE(); 146 UNREACHABLE();
135 } 147 }
136 } 148 }
137 149
138 // The program counter, which points into the buffer above and moves forward. 150 // The program counter, which points into the buffer above and moves forward.
139 byte* pc_; 151 byte* pc_;
140 152
141 private: 153 private:
142 Isolate* isolate_; 154 IsolateData isolate_data_;
143 int jit_cookie_;
144 uint64_t enabled_cpu_features_; 155 uint64_t enabled_cpu_features_;
145 bool emit_debug_code_; 156 bool emit_debug_code_;
146 bool predictable_code_size_; 157 bool predictable_code_size_;
147 bool serializer_enabled_;
148 158
149 // Indicates whether the constant pool can be accessed, which is only possible 159 // Indicates whether the constant pool can be accessed, which is only possible
150 // if the pp register points to the current code object's constant pool. 160 // if the pp register points to the current code object's constant pool.
151 bool constant_pool_available_; 161 bool constant_pool_available_;
152 162
153 // Constant pool. 163 // Constant pool.
154 friend class FrameAndConstantPoolScope; 164 friend class FrameAndConstantPoolScope;
155 friend class ConstantPoolUnavailableScope; 165 friend class ConstantPoolUnavailableScope;
156 }; 166 };
157 167
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 375
366 FIRST_REAL_RELOC_MODE = CODE_TARGET, 376 FIRST_REAL_RELOC_MODE = CODE_TARGET,
367 LAST_REAL_RELOC_MODE = VENEER_POOL, 377 LAST_REAL_RELOC_MODE = VENEER_POOL,
368 LAST_CODE_ENUM = CODE_TARGET_WITH_ID, 378 LAST_CODE_ENUM = CODE_TARGET_WITH_ID,
369 LAST_GCED_ENUM = WASM_FUNCTION_TABLE_SIZE_REFERENCE, 379 LAST_GCED_ENUM = WASM_FUNCTION_TABLE_SIZE_REFERENCE,
370 FIRST_SHAREABLE_RELOC_MODE = CELL, 380 FIRST_SHAREABLE_RELOC_MODE = CELL,
371 }; 381 };
372 382
373 STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt); 383 STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
374 384
375 explicit RelocInfo(Isolate* isolate) : isolate_(isolate) { 385 RelocInfo() = default;
376 DCHECK_NOT_NULL(isolate);
377 }
378 386
379 RelocInfo(Isolate* isolate, byte* pc, Mode rmode, intptr_t data, Code* host) 387 RelocInfo(byte* pc, Mode rmode, intptr_t data, Code* host)
380 : isolate_(isolate), pc_(pc), rmode_(rmode), data_(data), host_(host) { 388 : pc_(pc), rmode_(rmode), data_(data), host_(host) {}
381 DCHECK_NOT_NULL(isolate);
382 }
383 389
384 static inline bool IsRealRelocMode(Mode mode) { 390 static inline bool IsRealRelocMode(Mode mode) {
385 return mode >= FIRST_REAL_RELOC_MODE && mode <= LAST_REAL_RELOC_MODE; 391 return mode >= FIRST_REAL_RELOC_MODE && mode <= LAST_REAL_RELOC_MODE;
386 } 392 }
387 static inline bool IsCodeTarget(Mode mode) { 393 static inline bool IsCodeTarget(Mode mode) {
388 return mode <= LAST_CODE_ENUM; 394 return mode <= LAST_CODE_ENUM;
389 } 395 }
390 static inline bool IsEmbeddedObject(Mode mode) { 396 static inline bool IsEmbeddedObject(Mode mode) {
391 return mode == EMBEDDED_OBJECT; 397 return mode == EMBEDDED_OBJECT;
392 } 398 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 static inline bool IsWasmPtrReference(Mode mode) { 477 static inline bool IsWasmPtrReference(Mode mode) {
472 return mode == WASM_MEMORY_REFERENCE || mode == WASM_GLOBAL_REFERENCE; 478 return mode == WASM_MEMORY_REFERENCE || mode == WASM_GLOBAL_REFERENCE;
473 } 479 }
474 static inline bool IsWasmProtectedLanding(Mode mode) { 480 static inline bool IsWasmProtectedLanding(Mode mode) {
475 return mode == WASM_PROTECTED_INSTRUCTION_LANDING; 481 return mode == WASM_PROTECTED_INSTRUCTION_LANDING;
476 } 482 }
477 483
478 static inline int ModeMask(Mode mode) { return 1 << mode; } 484 static inline int ModeMask(Mode mode) { return 1 << mode; }
479 485
480 // Accessors 486 // Accessors
481 Isolate* isolate() const { return isolate_; }
482 byte* pc() const { return pc_; } 487 byte* pc() const { return pc_; }
483 void set_pc(byte* pc) { pc_ = pc; } 488 void set_pc(byte* pc) { pc_ = pc; }
484 Mode rmode() const { return rmode_; } 489 Mode rmode() const { return rmode_; }
485 intptr_t data() const { return data_; } 490 intptr_t data() const { return data_; }
486 Code* host() const { return host_; } 491 Code* host() const { return host_; }
487 void set_host(Code* host) { host_ = host; } 492 void set_host(Code* host) { host_ = host; }
488 493
489 // Apply a relocation by delta bytes. When the code object is moved, PC 494 // Apply a relocation by delta bytes. When the code object is moved, PC
490 // relative addresses have to be updated as well as absolute addresses 495 // relative addresses have to be updated as well as absolute addresses
491 // inside the code (internal references). 496 // inside the code (internal references).
492 // Do not forget to flush the icache afterwards! 497 // Do not forget to flush the icache afterwards!
493 INLINE(void apply(intptr_t delta)); 498 INLINE(void apply(intptr_t delta));
494 499
495 // Is the pointer this relocation info refers to coded like a plain pointer 500 // Is the pointer this relocation info refers to coded like a plain pointer
496 // or is it strange in some way (e.g. relative or patched into a series of 501 // or is it strange in some way (e.g. relative or patched into a series of
497 // instructions). 502 // instructions).
498 bool IsCodedSpecially(); 503 bool IsCodedSpecially();
499 504
500 // If true, the pointer this relocation info refers to is an entry in the 505 // If true, the pointer this relocation info refers to is an entry in the
501 // constant pool, otherwise the pointer is embedded in the instruction stream. 506 // constant pool, otherwise the pointer is embedded in the instruction stream.
502 bool IsInConstantPool(); 507 bool IsInConstantPool();
503 508
504 Address wasm_memory_reference(); 509 Address wasm_memory_reference();
505 Address wasm_global_reference(); 510 Address wasm_global_reference();
506 uint32_t wasm_function_table_size_reference(); 511 uint32_t wasm_function_table_size_reference();
507 uint32_t wasm_memory_size_reference(); 512 uint32_t wasm_memory_size_reference();
508 void update_wasm_memory_reference( 513 void update_wasm_memory_reference(
509 Address old_base, Address new_base, 514 Isolate* isolate, Address old_base, Address new_base,
510 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED); 515 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
511 void update_wasm_memory_size( 516 void update_wasm_memory_size(
512 uint32_t old_size, uint32_t new_size, 517 Isolate* isolate, uint32_t old_size, uint32_t new_size,
513 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED); 518 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
514 void update_wasm_global_reference( 519 void update_wasm_global_reference(
515 Address old_base, Address new_base, 520 Isolate* isolate, Address old_base, Address new_base,
516 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED); 521 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
517 void update_wasm_function_table_size_reference( 522 void update_wasm_function_table_size_reference(
518 uint32_t old_base, uint32_t new_base, 523 Isolate* isolate, uint32_t old_base, uint32_t new_base,
519 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED); 524 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
520 void set_target_address( 525 void set_target_address(
521 Address target, 526 Isolate* isolate, Address target,
522 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER, 527 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
523 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED); 528 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED);
524 529
525 // this relocation applies to; 530 // this relocation applies to;
526 // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_) 531 // can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
527 INLINE(Address target_address()); 532 INLINE(Address target_address());
528 INLINE(HeapObject* target_object()); 533 INLINE(HeapObject* target_object());
529 INLINE(Handle<HeapObject> target_object_handle(Assembler* origin)); 534 INLINE(Handle<HeapObject> target_object_handle(Assembler* origin));
530 INLINE(void set_target_object( 535 INLINE(void set_target_object(
531 HeapObject* target, 536 HeapObject* target,
532 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER, 537 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
533 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED)); 538 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED));
534 INLINE(Address target_runtime_entry(Assembler* origin)); 539 INLINE(Address target_runtime_entry(Assembler* origin));
535 INLINE(void set_target_runtime_entry( 540 INLINE(void set_target_runtime_entry(
536 Address target, 541 Isolate* isolate, Address target,
537 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER, 542 WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
538 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED)); 543 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED));
539 INLINE(Cell* target_cell()); 544 INLINE(Cell* target_cell());
540 INLINE(Handle<Cell> target_cell_handle()); 545 INLINE(Handle<Cell> target_cell_handle());
541 INLINE(void set_target_cell( 546 INLINE(void set_target_cell(
542 Cell* cell, WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER, 547 Cell* cell, WriteBarrierMode write_barrier_mode = UPDATE_WRITE_BARRIER,
543 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED)); 548 ICacheFlushMode icache_flush_mode = FLUSH_ICACHE_IF_NEEDED));
544 INLINE(Handle<Code> code_age_stub_handle(Assembler* origin)); 549 INLINE(Handle<Code> code_age_stub_handle(Assembler* origin));
545 INLINE(Code* code_age_stub()); 550 INLINE(Code* code_age_stub());
546 INLINE(void set_code_age_stub( 551 INLINE(void set_code_age_stub(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 INLINE(Address target_internal_reference()); 583 INLINE(Address target_internal_reference());
579 584
580 // Return the reference address this relocation applies to; 585 // Return the reference address this relocation applies to;
581 // can only be called if rmode_ is INTERNAL_REFERENCE. 586 // can only be called if rmode_ is INTERNAL_REFERENCE.
582 INLINE(Address target_internal_reference_address()); 587 INLINE(Address target_internal_reference_address());
583 588
584 // Read/modify the address of a call instruction. This is used to relocate 589 // Read/modify the address of a call instruction. This is used to relocate
585 // the break points where straight-line code is patched with a call 590 // the break points where straight-line code is patched with a call
586 // instruction. 591 // instruction.
587 INLINE(Address debug_call_address()); 592 INLINE(Address debug_call_address());
588 INLINE(void set_debug_call_address(Address target)); 593 INLINE(void set_debug_call_address(Isolate*, Address target));
589 594
590 // Wipe out a relocation to a fixed value, used for making snapshots 595 // Wipe out a relocation to a fixed value, used for making snapshots
591 // reproducible. 596 // reproducible.
592 INLINE(void WipeOut()); 597 INLINE(void WipeOut(Isolate* isolate));
593 598
594 template<typename StaticVisitor> inline void Visit(Heap* heap); 599 template<typename StaticVisitor> inline void Visit(Heap* heap);
595 600
596 template <typename ObjectVisitor> 601 template <typename ObjectVisitor>
597 inline void Visit(Isolate* isolate, ObjectVisitor* v); 602 inline void Visit(Isolate* isolate, ObjectVisitor* v);
598 603
599 // Check whether this debug break slot has been patched with a call to the 604 // Check whether this debug break slot has been patched with a call to the
600 // debugger. 605 // debugger.
601 bool IsPatchedDebugBreakSlotSequence(); 606 bool IsPatchedDebugBreakSlotSequence();
602 607
603 #ifdef DEBUG 608 #ifdef DEBUG
604 // Check whether the given code contains relocation information that 609 // Check whether the given code contains relocation information that
605 // either is position-relative or movable by the garbage collector. 610 // either is position-relative or movable by the garbage collector.
606 static bool RequiresRelocation(const CodeDesc& desc); 611 static bool RequiresRelocation(Isolate* isolate, const CodeDesc& desc);
607 #endif 612 #endif
608 613
609 #ifdef ENABLE_DISASSEMBLER 614 #ifdef ENABLE_DISASSEMBLER
610 // Printing 615 // Printing
611 static const char* RelocModeName(Mode rmode); 616 static const char* RelocModeName(Mode rmode);
612 void Print(Isolate* isolate, std::ostream& os); // NOLINT 617 void Print(Isolate* isolate, std::ostream& os); // NOLINT
613 #endif // ENABLE_DISASSEMBLER 618 #endif // ENABLE_DISASSEMBLER
614 #ifdef VERIFY_HEAP 619 #ifdef VERIFY_HEAP
615 void Verify(Isolate* isolate); 620 void Verify(Isolate* isolate);
616 #endif 621 #endif
617 622
618 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1; 623 static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
619 static const int kDataMask = (1 << CODE_TARGET_WITH_ID) | (1 << COMMENT); 624 static const int kDataMask = (1 << CODE_TARGET_WITH_ID) | (1 << COMMENT);
620 static const int kDebugBreakSlotMask = 1 << DEBUG_BREAK_SLOT_AT_POSITION | 625 static const int kDebugBreakSlotMask = 1 << DEBUG_BREAK_SLOT_AT_POSITION |
621 1 << DEBUG_BREAK_SLOT_AT_RETURN | 626 1 << DEBUG_BREAK_SLOT_AT_RETURN |
622 1 << DEBUG_BREAK_SLOT_AT_CALL; 627 1 << DEBUG_BREAK_SLOT_AT_CALL;
623 static const int kApplyMask; // Modes affected by apply. Depends on arch. 628 static const int kApplyMask; // Modes affected by apply. Depends on arch.
624 629
625 private: 630 private:
626 void unchecked_update_wasm_memory_reference(Address address, 631 void unchecked_update_wasm_memory_reference(Isolate* isolate, Address address,
627 ICacheFlushMode flush_mode); 632 ICacheFlushMode flush_mode);
628 void unchecked_update_wasm_size(uint32_t size, ICacheFlushMode flush_mode); 633 void unchecked_update_wasm_size(Isolate* isolate, uint32_t size,
634 ICacheFlushMode flush_mode);
629 635
630 Isolate* isolate_;
631 // On ARM, note that pc_ is the address of the constant pool entry 636 // On ARM, note that pc_ is the address of the constant pool entry
632 // to be relocated and not the address of the instruction 637 // to be relocated and not the address of the instruction
633 // referencing the constant pool entry (except when rmode_ == 638 // referencing the constant pool entry (except when rmode_ ==
634 // comment). 639 // comment).
635 byte* pc_; 640 byte* pc_;
636 Mode rmode_; 641 Mode rmode_;
637 intptr_t data_; 642 intptr_t data_;
638 Code* host_; 643 Code* host_;
639 friend class RelocIterator; 644 friend class RelocIterator;
640 }; 645 };
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 std::vector<ConstantPoolEntry> shared_entries; 1248 std::vector<ConstantPoolEntry> shared_entries;
1244 }; 1249 };
1245 1250
1246 Label emitted_label_; // Records pc_offset of emitted pool 1251 Label emitted_label_; // Records pc_offset of emitted pool
1247 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES]; 1252 PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES];
1248 }; 1253 };
1249 1254
1250 } // namespace internal 1255 } // namespace internal
1251 } // namespace v8 1256 } // namespace v8
1252 #endif // V8_ASSEMBLER_H_ 1257 #endif // V8_ASSEMBLER_H_
OLDNEW
« no previous file with comments | « src/arm64/macro-assembler-arm64.cc ('k') | src/assembler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698