| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits.h> | 5 #include <limits.h> |
| 6 #include <stdarg.h> | 6 #include <stdarg.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #if V8_TARGET_ARCH_MIPS | 10 #if V8_TARGET_ARCH_MIPS |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); | 801 intptr_t end_page = ((start + size) & ~CachePage::kPageMask); |
| 802 return start_page == end_page; | 802 return start_page == end_page; |
| 803 } | 803 } |
| 804 | 804 |
| 805 | 805 |
| 806 void Simulator::set_last_debugger_input(char* input) { | 806 void Simulator::set_last_debugger_input(char* input) { |
| 807 DeleteArray(last_debugger_input_); | 807 DeleteArray(last_debugger_input_); |
| 808 last_debugger_input_ = input; | 808 last_debugger_input_ = input; |
| 809 } | 809 } |
| 810 | 810 |
| 811 void Simulator::FlushICache(base::HashMap* i_cache, void* start_addr, | 811 void Simulator::FlushICache(base::CustomMatcherHashMap* i_cache, |
| 812 size_t size) { | 812 void* start_addr, size_t size) { |
| 813 intptr_t start = reinterpret_cast<intptr_t>(start_addr); | 813 intptr_t start = reinterpret_cast<intptr_t>(start_addr); |
| 814 int intra_line = (start & CachePage::kLineMask); | 814 int intra_line = (start & CachePage::kLineMask); |
| 815 start -= intra_line; | 815 start -= intra_line; |
| 816 size += intra_line; | 816 size += intra_line; |
| 817 size = ((size - 1) | CachePage::kLineMask) + 1; | 817 size = ((size - 1) | CachePage::kLineMask) + 1; |
| 818 int offset = (start & CachePage::kPageMask); | 818 int offset = (start & CachePage::kPageMask); |
| 819 while (!AllOnOnePage(start, size - 1)) { | 819 while (!AllOnOnePage(start, size - 1)) { |
| 820 int bytes_to_flush = CachePage::kPageSize - offset; | 820 int bytes_to_flush = CachePage::kPageSize - offset; |
| 821 FlushOnePage(i_cache, start, bytes_to_flush); | 821 FlushOnePage(i_cache, start, bytes_to_flush); |
| 822 start += bytes_to_flush; | 822 start += bytes_to_flush; |
| 823 size -= bytes_to_flush; | 823 size -= bytes_to_flush; |
| 824 DCHECK_EQ(0, start & CachePage::kPageMask); | 824 DCHECK_EQ(0, start & CachePage::kPageMask); |
| 825 offset = 0; | 825 offset = 0; |
| 826 } | 826 } |
| 827 if (size != 0) { | 827 if (size != 0) { |
| 828 FlushOnePage(i_cache, start, size); | 828 FlushOnePage(i_cache, start, size); |
| 829 } | 829 } |
| 830 } | 830 } |
| 831 | 831 |
| 832 CachePage* Simulator::GetCachePage(base::HashMap* i_cache, void* page) { | 832 CachePage* Simulator::GetCachePage(base::CustomMatcherHashMap* i_cache, |
| 833 base::HashMap::Entry* entry = i_cache->LookupOrInsert(page, ICacheHash(page)); | 833 void* page) { |
| 834 base::CustomMatcherHashMap::Entry* entry = |
| 835 i_cache->LookupOrInsert(page, ICacheHash(page)); |
| 834 if (entry->value == NULL) { | 836 if (entry->value == NULL) { |
| 835 CachePage* new_page = new CachePage(); | 837 CachePage* new_page = new CachePage(); |
| 836 entry->value = new_page; | 838 entry->value = new_page; |
| 837 } | 839 } |
| 838 return reinterpret_cast<CachePage*>(entry->value); | 840 return reinterpret_cast<CachePage*>(entry->value); |
| 839 } | 841 } |
| 840 | 842 |
| 841 | 843 |
| 842 // Flush from start up to and not including start + size. | 844 // Flush from start up to and not including start + size. |
| 843 void Simulator::FlushOnePage(base::HashMap* i_cache, intptr_t start, int size) { | 845 void Simulator::FlushOnePage(base::CustomMatcherHashMap* i_cache, |
| 846 intptr_t start, int size) { |
| 844 DCHECK(size <= CachePage::kPageSize); | 847 DCHECK(size <= CachePage::kPageSize); |
| 845 DCHECK(AllOnOnePage(start, size - 1)); | 848 DCHECK(AllOnOnePage(start, size - 1)); |
| 846 DCHECK((start & CachePage::kLineMask) == 0); | 849 DCHECK((start & CachePage::kLineMask) == 0); |
| 847 DCHECK((size & CachePage::kLineMask) == 0); | 850 DCHECK((size & CachePage::kLineMask) == 0); |
| 848 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); | 851 void* page = reinterpret_cast<void*>(start & (~CachePage::kPageMask)); |
| 849 int offset = (start & CachePage::kPageMask); | 852 int offset = (start & CachePage::kPageMask); |
| 850 CachePage* cache_page = GetCachePage(i_cache, page); | 853 CachePage* cache_page = GetCachePage(i_cache, page); |
| 851 char* valid_bytemap = cache_page->ValidityByte(offset); | 854 char* valid_bytemap = cache_page->ValidityByte(offset); |
| 852 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); | 855 memset(valid_bytemap, CachePage::LINE_INVALID, size >> CachePage::kLineShift); |
| 853 } | 856 } |
| 854 | 857 |
| 855 void Simulator::CheckICache(base::HashMap* i_cache, Instruction* instr) { | 858 void Simulator::CheckICache(base::CustomMatcherHashMap* i_cache, |
| 859 Instruction* instr) { |
| 856 intptr_t address = reinterpret_cast<intptr_t>(instr); | 860 intptr_t address = reinterpret_cast<intptr_t>(instr); |
| 857 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); | 861 void* page = reinterpret_cast<void*>(address & (~CachePage::kPageMask)); |
| 858 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); | 862 void* line = reinterpret_cast<void*>(address & (~CachePage::kLineMask)); |
| 859 int offset = (address & CachePage::kPageMask); | 863 int offset = (address & CachePage::kPageMask); |
| 860 CachePage* cache_page = GetCachePage(i_cache, page); | 864 CachePage* cache_page = GetCachePage(i_cache, page); |
| 861 char* cache_valid_byte = cache_page->ValidityByte(offset); | 865 char* cache_valid_byte = cache_page->ValidityByte(offset); |
| 862 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); | 866 bool cache_hit = (*cache_valid_byte == CachePage::LINE_VALID); |
| 863 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); | 867 char* cached_line = cache_page->CachedData(offset & ~CachePage::kLineMask); |
| 864 if (cache_hit) { | 868 if (cache_hit) { |
| 865 // Check that the data in memory matches the contents of the I-cache. | 869 // Check that the data in memory matches the contents of the I-cache. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 878 if (isolate->simulator_initialized()) return; | 882 if (isolate->simulator_initialized()) return; |
| 879 isolate->set_simulator_initialized(true); | 883 isolate->set_simulator_initialized(true); |
| 880 ::v8::internal::ExternalReference::set_redirector(isolate, | 884 ::v8::internal::ExternalReference::set_redirector(isolate, |
| 881 &RedirectExternalReference); | 885 &RedirectExternalReference); |
| 882 } | 886 } |
| 883 | 887 |
| 884 | 888 |
| 885 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { | 889 Simulator::Simulator(Isolate* isolate) : isolate_(isolate) { |
| 886 i_cache_ = isolate_->simulator_i_cache(); | 890 i_cache_ = isolate_->simulator_i_cache(); |
| 887 if (i_cache_ == NULL) { | 891 if (i_cache_ == NULL) { |
| 888 i_cache_ = new base::HashMap(&ICacheMatch); | 892 i_cache_ = new base::CustomMatcherHashMap(&ICacheMatch); |
| 889 isolate_->set_simulator_i_cache(i_cache_); | 893 isolate_->set_simulator_i_cache(i_cache_); |
| 890 } | 894 } |
| 891 Initialize(isolate); | 895 Initialize(isolate); |
| 892 // Set up simulator support first. Some of this information is needed to | 896 // Set up simulator support first. Some of this information is needed to |
| 893 // setup the architecture state. | 897 // setup the architecture state. |
| 894 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); | 898 stack_ = reinterpret_cast<char*>(malloc(stack_size_)); |
| 895 pc_modified_ = false; | 899 pc_modified_ = false; |
| 896 icount_ = 0; | 900 icount_ = 0; |
| 897 break_count_ = 0; | 901 break_count_ = 0; |
| 898 break_pc_ = NULL; | 902 break_pc_ = NULL; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 990 | 994 |
| 991 private: | 995 private: |
| 992 void* external_function_; | 996 void* external_function_; |
| 993 uint32_t swi_instruction_; | 997 uint32_t swi_instruction_; |
| 994 ExternalReference::Type type_; | 998 ExternalReference::Type type_; |
| 995 Redirection* next_; | 999 Redirection* next_; |
| 996 }; | 1000 }; |
| 997 | 1001 |
| 998 | 1002 |
| 999 // static | 1003 // static |
| 1000 void Simulator::TearDown(base::HashMap* i_cache, Redirection* first) { | 1004 void Simulator::TearDown(base::CustomMatcherHashMap* i_cache, |
| 1005 Redirection* first) { |
| 1001 Redirection::DeleteChain(first); | 1006 Redirection::DeleteChain(first); |
| 1002 if (i_cache != nullptr) { | 1007 if (i_cache != nullptr) { |
| 1003 for (base::HashMap::Entry* entry = i_cache->Start(); entry != nullptr; | 1008 for (base::CustomMatcherHashMap::Entry* entry = i_cache->Start(); |
| 1004 entry = i_cache->Next(entry)) { | 1009 entry != nullptr; entry = i_cache->Next(entry)) { |
| 1005 delete static_cast<CachePage*>(entry->value); | 1010 delete static_cast<CachePage*>(entry->value); |
| 1006 } | 1011 } |
| 1007 delete i_cache; | 1012 delete i_cache; |
| 1008 } | 1013 } |
| 1009 } | 1014 } |
| 1010 | 1015 |
| 1011 | 1016 |
| 1012 void* Simulator::RedirectExternalReference(Isolate* isolate, | 1017 void* Simulator::RedirectExternalReference(Isolate* isolate, |
| 1013 void* external_function, | 1018 void* external_function, |
| 1014 ExternalReference::Type type) { | 1019 ExternalReference::Type type) { |
| (...skipping 3674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4689 | 4694 |
| 4690 | 4695 |
| 4691 #undef UNSUPPORTED | 4696 #undef UNSUPPORTED |
| 4692 | 4697 |
| 4693 } // namespace internal | 4698 } // namespace internal |
| 4694 } // namespace v8 | 4699 } // namespace v8 |
| 4695 | 4700 |
| 4696 #endif // USE_SIMULATOR | 4701 #endif // USE_SIMULATOR |
| 4697 | 4702 |
| 4698 #endif // V8_TARGET_ARCH_MIPS | 4703 #endif // V8_TARGET_ARCH_MIPS |
| OLD | NEW |