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

Side by Side Diff: src/assembler.cc

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/assembler.h ('k') | src/compiler/arm/code-generator-arm.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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 uint64_t a; 131 uint64_t a;
132 uint64_t b; 132 uint64_t b;
133 } double_negate_constant = {V8_UINT64_C(0x8000000000000000), 133 } double_negate_constant = {V8_UINT64_C(0x8000000000000000),
134 V8_UINT64_C(0x8000000000000000)}; 134 V8_UINT64_C(0x8000000000000000)};
135 135
136 const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING"; 136 const char* const RelocInfo::kFillerCommentString = "DEOPTIMIZATION PADDING";
137 137
138 // ----------------------------------------------------------------------------- 138 // -----------------------------------------------------------------------------
139 // Implementation of AssemblerBase 139 // Implementation of AssemblerBase
140 140
141 AssemblerBase::AssemblerBase(Isolate* isolate, void* buffer, int buffer_size) 141 AssemblerBase::IsolateData::IsolateData(Isolate* isolate)
142 : isolate_(isolate), 142 : serializer_enabled_(isolate->serializer_enabled())
143 jit_cookie_(0), 143 #if V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
144 ,
145 max_old_generation_size_(isolate->heap()->MaxOldGenerationSize())
146 #endif
147 #if V8_TARGET_ARCH_X64
148 ,
149 code_range_start_(
150 isolate->heap()->memory_allocator()->code_range()->start())
151 #endif
152 {
153 }
154
155 AssemblerBase::AssemblerBase(IsolateData isolate_data, void* buffer,
156 int buffer_size)
157 : isolate_data_(isolate_data),
144 enabled_cpu_features_(0), 158 enabled_cpu_features_(0),
145 emit_debug_code_(FLAG_debug_code), 159 emit_debug_code_(FLAG_debug_code),
146 predictable_code_size_(false), 160 predictable_code_size_(false),
147 // We may use the assembler without an isolate.
148 serializer_enabled_(isolate && isolate->serializer_enabled()),
149 constant_pool_available_(false) { 161 constant_pool_available_(false) {
150 DCHECK_NOT_NULL(isolate);
151 if (FLAG_mask_constants_with_cookie) {
152 jit_cookie_ = isolate->random_number_generator()->NextInt();
153 }
154 own_buffer_ = buffer == NULL; 162 own_buffer_ = buffer == NULL;
155 if (buffer_size == 0) buffer_size = kMinimalBufferSize; 163 if (buffer_size == 0) buffer_size = kMinimalBufferSize;
156 DCHECK(buffer_size > 0); 164 DCHECK(buffer_size > 0);
157 if (own_buffer_) buffer = NewArray<byte>(buffer_size); 165 if (own_buffer_) buffer = NewArray<byte>(buffer_size);
158 buffer_ = static_cast<byte*>(buffer); 166 buffer_ = static_cast<byte*>(buffer);
159 buffer_size_ = buffer_size; 167 buffer_size_ = buffer_size;
160
161 pc_ = buffer_; 168 pc_ = buffer_;
162 } 169 }
163 170
164
165 AssemblerBase::~AssemblerBase() { 171 AssemblerBase::~AssemblerBase() {
166 if (own_buffer_) DeleteArray(buffer_); 172 if (own_buffer_) DeleteArray(buffer_);
167 } 173 }
168 174
169
170 void AssemblerBase::FlushICache(Isolate* isolate, void* start, size_t size) { 175 void AssemblerBase::FlushICache(Isolate* isolate, void* start, size_t size) {
171 if (size == 0) return; 176 if (size == 0) return;
172 177
173 #if defined(USE_SIMULATOR) 178 #if defined(USE_SIMULATOR)
174 base::LockGuard<base::Mutex> lock_guard(isolate->simulator_i_cache_mutex()); 179 base::LockGuard<base::Mutex> lock_guard(isolate->simulator_i_cache_mutex());
175 Simulator::FlushICache(isolate->simulator_i_cache(), start, size); 180 Simulator::FlushICache(isolate->simulator_i_cache(), start, size);
176 #else 181 #else
177 CpuFeatures::FlushICache(start, size); 182 CpuFeatures::FlushICache(start, size);
178 #endif // USE_SIMULATOR 183 #endif // USE_SIMULATOR
179 } 184 }
180 185
181 186 void AssemblerBase::Print(Isolate* isolate) {
182 void AssemblerBase::Print() {
183 OFStream os(stdout); 187 OFStream os(stdout);
184 v8::internal::Disassembler::Decode(isolate(), &os, buffer_, pc_, nullptr); 188 v8::internal::Disassembler::Decode(isolate, &os, buffer_, pc_, nullptr);
185 } 189 }
186 190
187 191
188 // ----------------------------------------------------------------------------- 192 // -----------------------------------------------------------------------------
189 // Implementation of PredictableCodeSizeScope 193 // Implementation of PredictableCodeSizeScope
190 194
191 PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler) 195 PredictableCodeSizeScope::PredictableCodeSizeScope(AssemblerBase* assembler)
192 : PredictableCodeSizeScope(assembler, -1) {} 196 : PredictableCodeSizeScope(assembler, -1) {}
193 197
194 198
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 const int kChunkBits = 7; 305 const int kChunkBits = 7;
302 const int kChunkMask = (1 << kChunkBits) - 1; 306 const int kChunkMask = (1 << kChunkBits) - 1;
303 const int kLastChunkTagBits = 1; 307 const int kLastChunkTagBits = 1;
304 const int kLastChunkTagMask = 1; 308 const int kLastChunkTagMask = 1;
305 const int kLastChunkTag = 1; 309 const int kLastChunkTag = 1;
306 310
307 const int kCodeWithIdTag = 0; 311 const int kCodeWithIdTag = 0;
308 const int kDeoptReasonTag = 1; 312 const int kDeoptReasonTag = 1;
309 313
310 void RelocInfo::update_wasm_memory_reference( 314 void RelocInfo::update_wasm_memory_reference(
311 Address old_base, Address new_base, ICacheFlushMode icache_flush_mode) { 315 Isolate* isolate, Address old_base, Address new_base,
316 ICacheFlushMode icache_flush_mode) {
312 DCHECK(IsWasmMemoryReference(rmode_)); 317 DCHECK(IsWasmMemoryReference(rmode_));
313 DCHECK_GE(wasm_memory_reference(), old_base); 318 DCHECK_GE(wasm_memory_reference(), old_base);
314 Address updated_reference = new_base + (wasm_memory_reference() - old_base); 319 Address updated_reference = new_base + (wasm_memory_reference() - old_base);
315 // The reference is not checked here but at runtime. Validity of references 320 // The reference is not checked here but at runtime. Validity of references
316 // may change over time. 321 // may change over time.
317 unchecked_update_wasm_memory_reference(updated_reference, icache_flush_mode); 322 unchecked_update_wasm_memory_reference(isolate, updated_reference,
323 icache_flush_mode);
318 } 324 }
319 325
320 void RelocInfo::update_wasm_memory_size(uint32_t old_size, uint32_t new_size, 326 void RelocInfo::update_wasm_memory_size(Isolate* isolate, uint32_t old_size,
327 uint32_t new_size,
321 ICacheFlushMode icache_flush_mode) { 328 ICacheFlushMode icache_flush_mode) {
322 DCHECK(IsWasmMemorySizeReference(rmode_)); 329 DCHECK(IsWasmMemorySizeReference(rmode_));
323 uint32_t current_size_reference = wasm_memory_size_reference(); 330 uint32_t current_size_reference = wasm_memory_size_reference();
324 uint32_t updated_size_reference = 331 uint32_t updated_size_reference =
325 new_size + (current_size_reference - old_size); 332 new_size + (current_size_reference - old_size);
326 unchecked_update_wasm_size(updated_size_reference, icache_flush_mode); 333 unchecked_update_wasm_size(isolate, updated_size_reference,
334 icache_flush_mode);
327 } 335 }
328 336
329 void RelocInfo::update_wasm_global_reference( 337 void RelocInfo::update_wasm_global_reference(
330 Address old_base, Address new_base, ICacheFlushMode icache_flush_mode) { 338 Isolate* isolate, Address old_base, Address new_base,
339 ICacheFlushMode icache_flush_mode) {
331 DCHECK(IsWasmGlobalReference(rmode_)); 340 DCHECK(IsWasmGlobalReference(rmode_));
332 Address updated_reference; 341 Address updated_reference;
333 DCHECK_LE(old_base, wasm_global_reference()); 342 DCHECK_LE(old_base, wasm_global_reference());
334 updated_reference = new_base + (wasm_global_reference() - old_base); 343 updated_reference = new_base + (wasm_global_reference() - old_base);
335 DCHECK_LE(new_base, updated_reference); 344 DCHECK_LE(new_base, updated_reference);
336 unchecked_update_wasm_memory_reference(updated_reference, icache_flush_mode); 345 unchecked_update_wasm_memory_reference(isolate, updated_reference,
346 icache_flush_mode);
337 } 347 }
338 348
339 void RelocInfo::update_wasm_function_table_size_reference( 349 void RelocInfo::update_wasm_function_table_size_reference(
340 uint32_t old_size, uint32_t new_size, ICacheFlushMode icache_flush_mode) { 350 Isolate* isolate, uint32_t old_size, uint32_t new_size,
351 ICacheFlushMode icache_flush_mode) {
341 DCHECK(IsWasmFunctionTableSizeReference(rmode_)); 352 DCHECK(IsWasmFunctionTableSizeReference(rmode_));
342 uint32_t current_size_reference = wasm_function_table_size_reference(); 353 uint32_t current_size_reference = wasm_function_table_size_reference();
343 uint32_t updated_size_reference = 354 uint32_t updated_size_reference =
344 new_size + (current_size_reference - old_size); 355 new_size + (current_size_reference - old_size);
345 unchecked_update_wasm_size(updated_size_reference, icache_flush_mode); 356 unchecked_update_wasm_size(isolate, updated_size_reference,
357 icache_flush_mode);
346 } 358 }
347 359
348 void RelocInfo::set_target_address(Address target, 360 void RelocInfo::set_target_address(Isolate* isolate, Address target,
349 WriteBarrierMode write_barrier_mode, 361 WriteBarrierMode write_barrier_mode,
350 ICacheFlushMode icache_flush_mode) { 362 ICacheFlushMode icache_flush_mode) {
351 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)); 363 DCHECK(IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_));
352 Assembler::set_target_address_at(isolate_, pc_, host_, target, 364 Assembler::set_target_address_at(isolate, pc_, host_, target,
353 icache_flush_mode); 365 icache_flush_mode);
354 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL && 366 if (write_barrier_mode == UPDATE_WRITE_BARRIER && host() != NULL &&
355 IsCodeTarget(rmode_)) { 367 IsCodeTarget(rmode_)) {
356 Object* target_code = Code::GetCodeFromTargetAddress(target); 368 Code* target_code = Code::GetCodeFromTargetAddress(target);
357 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode( 369 host()->GetHeap()->incremental_marking()->RecordWriteIntoCode(host(), this,
358 host(), this, HeapObject::cast(target_code)); 370 target_code);
359 } 371 }
360 } 372 }
361 373
362 uint32_t RelocInfoWriter::WriteLongPCJump(uint32_t pc_delta) { 374 uint32_t RelocInfoWriter::WriteLongPCJump(uint32_t pc_delta) {
363 // Return if the pc_delta can fit in kSmallPCDeltaBits bits. 375 // Return if the pc_delta can fit in kSmallPCDeltaBits bits.
364 // Otherwise write a variable length PC jump for the bits that do 376 // Otherwise write a variable length PC jump for the bits that do
365 // not fit in the kSmallPCDeltaBits bits. 377 // not fit in the kSmallPCDeltaBits bits.
366 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta; 378 if (is_uintn(pc_delta, kSmallPCDeltaBits)) return pc_delta;
367 WriteMode(RelocInfo::PC_JUMP); 379 WriteMode(RelocInfo::PC_JUMP);
368 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits; 380 uint32_t pc_jump = pc_delta >> kSmallPCDeltaBits;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 code_age_sequence_ = NULL; 643 code_age_sequence_ = NULL;
632 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) { 644 if (SetMode(RelocInfo::CODE_AGE_SEQUENCE)) {
633 rinfo_.data_ = 0; 645 rinfo_.data_ = 0;
634 rinfo_.pc_ = old_code_age_sequence; 646 rinfo_.pc_ = old_code_age_sequence;
635 return; 647 return;
636 } 648 }
637 } 649 }
638 done_ = true; 650 done_ = true;
639 } 651 }
640 652
641 653 RelocIterator::RelocIterator(Code* code, int mode_mask) {
642 RelocIterator::RelocIterator(Code* code, int mode_mask)
643 : rinfo_(code->map()->GetIsolate()) {
644 rinfo_.host_ = code; 654 rinfo_.host_ = code;
645 rinfo_.pc_ = code->instruction_start(); 655 rinfo_.pc_ = code->instruction_start();
646 rinfo_.data_ = 0; 656 rinfo_.data_ = 0;
647 // Relocation info is read backwards. 657 // Relocation info is read backwards.
648 pos_ = code->relocation_start() + code->relocation_size(); 658 pos_ = code->relocation_start() + code->relocation_size();
649 end_ = code->relocation_start(); 659 end_ = code->relocation_start();
650 done_ = false; 660 done_ = false;
651 mode_mask_ = mode_mask; 661 mode_mask_ = mode_mask;
652 last_id_ = 0; 662 last_id_ = 0;
653 byte* sequence = code->FindCodeAgeSequence(); 663 byte* sequence = code->FindCodeAgeSequence();
654 // We get the isolate from the map, because at serialization time 664 // We get the isolate from the map, because at serialization time
655 // the code pointer has been cloned and isn't really in heap space. 665 // the code pointer has been cloned and isn't really in heap space.
656 Isolate* isolate = code->map()->GetIsolate(); 666 Isolate* isolate = code->map()->GetIsolate();
657 if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) { 667 if (sequence != NULL && !Code::IsYoungSequence(isolate, sequence)) {
658 code_age_sequence_ = sequence; 668 code_age_sequence_ = sequence;
659 } else { 669 } else {
660 code_age_sequence_ = NULL; 670 code_age_sequence_ = NULL;
661 } 671 }
662 if (mode_mask_ == 0) pos_ = end_; 672 if (mode_mask_ == 0) pos_ = end_;
663 next(); 673 next();
664 } 674 }
665 675
666 676 RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask) {
667 RelocIterator::RelocIterator(const CodeDesc& desc, int mode_mask)
668 : rinfo_(desc.origin->isolate()) {
669 rinfo_.pc_ = desc.buffer; 677 rinfo_.pc_ = desc.buffer;
670 rinfo_.data_ = 0; 678 rinfo_.data_ = 0;
671 // Relocation info is read backwards. 679 // Relocation info is read backwards.
672 pos_ = desc.buffer + desc.buffer_size; 680 pos_ = desc.buffer + desc.buffer_size;
673 end_ = pos_ - desc.reloc_size; 681 end_ = pos_ - desc.reloc_size;
674 done_ = false; 682 done_ = false;
675 mode_mask_ = mode_mask; 683 mode_mask_ = mode_mask;
676 last_id_ = 0; 684 last_id_ = 0;
677 code_age_sequence_ = NULL; 685 code_age_sequence_ = NULL;
678 if (mode_mask_ == 0) pos_ = end_; 686 if (mode_mask_ == 0) pos_ = end_;
679 next(); 687 next();
680 } 688 }
681 689
682 690
683 // ----------------------------------------------------------------------------- 691 // -----------------------------------------------------------------------------
684 // Implementation of RelocInfo 692 // Implementation of RelocInfo
685 693
686 bool RelocInfo::IsPatchedDebugBreakSlotSequence() { 694 bool RelocInfo::IsPatchedDebugBreakSlotSequence() {
687 return DebugCodegen::DebugBreakSlotIsPatched(pc_); 695 return DebugCodegen::DebugBreakSlotIsPatched(pc_);
688 } 696 }
689 697
690 #ifdef DEBUG 698 #ifdef DEBUG
691 bool RelocInfo::RequiresRelocation(const CodeDesc& desc) { 699 bool RelocInfo::RequiresRelocation(Isolate* isolate, const CodeDesc& desc) {
692 // Ensure there are no code targets or embedded objects present in the 700 // Ensure there are no code targets or embedded objects present in the
693 // deoptimization entries, they would require relocation after code 701 // deoptimization entries, they would require relocation after code
694 // generation. 702 // generation.
695 int mode_mask = RelocInfo::kCodeTargetMask | 703 int mode_mask = RelocInfo::kCodeTargetMask |
696 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) | 704 RelocInfo::ModeMask(RelocInfo::EMBEDDED_OBJECT) |
697 RelocInfo::ModeMask(RelocInfo::CELL) | 705 RelocInfo::ModeMask(RelocInfo::CELL) |
698 RelocInfo::kApplyMask; 706 RelocInfo::kApplyMask;
699 RelocIterator it(desc, mode_mask); 707 RelocIterator it(desc, mode_mask);
700 return !it.done(); 708 return !it.done();
701 } 709 }
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 } 1897 }
1890 1898
1891 return !empty ? emitted_label_.pos() : 0; 1899 return !empty ? emitted_label_.pos() : 0;
1892 } 1900 }
1893 1901
1894 1902
1895 // Platform specific but identical code for all the platforms. 1903 // Platform specific but identical code for all the platforms.
1896 1904
1897 void Assembler::RecordDeoptReason(DeoptimizeReason reason, 1905 void Assembler::RecordDeoptReason(DeoptimizeReason reason,
1898 SourcePosition position, int id) { 1906 SourcePosition position, int id) {
1899 if (FLAG_trace_deopt || isolate()->is_profiling()) { 1907 EnsureSpace ensure_space(this);
1900 EnsureSpace ensure_space(this); 1908 RecordRelocInfo(RelocInfo::DEOPT_SCRIPT_OFFSET, position.ScriptOffset());
1901 RecordRelocInfo(RelocInfo::DEOPT_SCRIPT_OFFSET, position.ScriptOffset()); 1909 RecordRelocInfo(RelocInfo::DEOPT_INLINING_ID, position.InliningId());
1902 RecordRelocInfo(RelocInfo::DEOPT_INLINING_ID, position.InliningId()); 1910 RecordRelocInfo(RelocInfo::DEOPT_REASON, static_cast<int>(reason));
1903 RecordRelocInfo(RelocInfo::DEOPT_REASON, static_cast<int>(reason)); 1911 RecordRelocInfo(RelocInfo::DEOPT_ID, id);
1904 RecordRelocInfo(RelocInfo::DEOPT_ID, id);
1905 }
1906 } 1912 }
1907 1913
1908 1914
1909 void Assembler::RecordComment(const char* msg) { 1915 void Assembler::RecordComment(const char* msg) {
1910 if (FLAG_code_comments) { 1916 if (FLAG_code_comments) {
1911 EnsureSpace ensure_space(this); 1917 EnsureSpace ensure_space(this);
1912 RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg)); 1918 RecordRelocInfo(RelocInfo::COMMENT, reinterpret_cast<intptr_t>(msg));
1913 } 1919 }
1914 } 1920 }
1915 1921
1916 1922
1917 void Assembler::RecordDebugBreakSlot(RelocInfo::Mode mode) { 1923 void Assembler::RecordDebugBreakSlot(RelocInfo::Mode mode) {
1918 EnsureSpace ensure_space(this); 1924 EnsureSpace ensure_space(this);
1919 DCHECK(RelocInfo::IsDebugBreakSlot(mode)); 1925 DCHECK(RelocInfo::IsDebugBreakSlot(mode));
1920 RecordRelocInfo(mode); 1926 RecordRelocInfo(mode);
1921 } 1927 }
1922 1928
1923 1929
1924 void Assembler::DataAlign(int m) { 1930 void Assembler::DataAlign(int m) {
1925 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m)); 1931 DCHECK(m >= 2 && base::bits::IsPowerOfTwo32(m));
1926 while ((pc_offset() & (m - 1)) != 0) { 1932 while ((pc_offset() & (m - 1)) != 0) {
1927 db(0); 1933 db(0);
1928 } 1934 }
1929 } 1935 }
1930 } // namespace internal 1936 } // namespace internal
1931 } // namespace v8 1937 } // namespace v8
OLDNEW
« no previous file with comments | « src/assembler.h ('k') | src/compiler/arm/code-generator-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698