OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 126 matching lines...) Loading... |
137 intptr_t OS::MaxVirtualMemory() { | 137 intptr_t OS::MaxVirtualMemory() { |
138 return 0; | 138 return 0; |
139 } | 139 } |
140 | 140 |
141 | 141 |
142 double ceiling(double x) { | 142 double ceiling(double x) { |
143 return ceil(x); | 143 return ceil(x); |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 static Mutex* limit_mutex = NULL; | |
148 | |
149 #if V8_TARGET_ARCH_IA32 | 147 #if V8_TARGET_ARCH_IA32 |
150 static void MemMoveWrapper(void* dest, const void* src, size_t size) { | 148 static void MemMoveWrapper(void* dest, const void* src, size_t size) { |
151 memmove(dest, src, size); | 149 memmove(dest, src, size); |
152 } | 150 } |
153 | 151 |
154 | 152 |
155 // Initialize to library version so we can call this at any time during startup. | 153 // Initialize to library version so we can call this at any time during startup. |
156 static OS::MemMoveFunction memmove_function = &MemMoveWrapper; | 154 static OS::MemMoveFunction memmove_function = &MemMoveWrapper; |
157 | 155 |
158 // Defined in codegen-ia32.cc. | 156 // Defined in codegen-ia32.cc. |
(...skipping 584 matching lines...) Loading... |
743 n = _TRUNCATE; | 741 n = _TRUNCATE; |
744 int result = strncpy_s(dest.start(), dest.length(), src, n); | 742 int result = strncpy_s(dest.start(), dest.length(), src, n); |
745 USE(result); | 743 USE(result); |
746 ASSERT(result == 0 || (n == _TRUNCATE && result == STRUNCATE)); | 744 ASSERT(result == 0 || (n == _TRUNCATE && result == STRUNCATE)); |
747 } | 745 } |
748 | 746 |
749 | 747 |
750 #undef _TRUNCATE | 748 #undef _TRUNCATE |
751 #undef STRUNCATE | 749 #undef STRUNCATE |
752 | 750 |
753 // We keep the lowest and highest addresses mapped as a quick way of | |
754 // determining that pointers are outside the heap (used mostly in assertions | |
755 // and verification). The estimate is conservative, i.e., not all addresses in | |
756 // 'allocated' space are actually allocated to our heap. The range is | |
757 // [lowest, highest), inclusive on the low and and exclusive on the high end. | |
758 static void* lowest_ever_allocated = reinterpret_cast<void*>(-1); | |
759 static void* highest_ever_allocated = reinterpret_cast<void*>(0); | |
760 | |
761 | |
762 static void UpdateAllocatedSpaceLimits(void* address, int size) { | |
763 ASSERT(limit_mutex != NULL); | |
764 LockGuard<Mutex> lock_guard(limit_mutex); | |
765 | |
766 lowest_ever_allocated = Min(lowest_ever_allocated, address); | |
767 highest_ever_allocated = | |
768 Max(highest_ever_allocated, | |
769 reinterpret_cast<void*>(reinterpret_cast<char*>(address) + size)); | |
770 } | |
771 | |
772 | |
773 bool OS::IsOutsideAllocatedSpace(void* pointer) { | |
774 if (pointer < lowest_ever_allocated || pointer >= highest_ever_allocated) | |
775 return true; | |
776 // Ask the Windows API | |
777 if (IsBadWritePtr(pointer, 1)) | |
778 return true; | |
779 return false; | |
780 } | |
781 | |
782 | 751 |
783 // Get the system's page size used by VirtualAlloc() or the next power | 752 // Get the system's page size used by VirtualAlloc() or the next power |
784 // of two. The reason for always returning a power of two is that the | 753 // of two. The reason for always returning a power of two is that the |
785 // rounding up in OS::Allocate expects that. | 754 // rounding up in OS::Allocate expects that. |
786 static size_t GetPageSize() { | 755 static size_t GetPageSize() { |
787 static size_t page_size = 0; | 756 static size_t page_size = 0; |
788 if (page_size == 0) { | 757 if (page_size == 0) { |
789 SYSTEM_INFO info; | 758 SYSTEM_INFO info; |
790 GetSystemInfo(&info); | 759 GetSystemInfo(&info); |
791 page_size = RoundUpToPowerOf2(info.dwPageSize); | 760 page_size = RoundUpToPowerOf2(info.dwPageSize); |
(...skipping 73 matching lines...) Loading... |
865 prot); | 834 prot); |
866 | 835 |
867 if (mbase == NULL) { | 836 if (mbase == NULL) { |
868 LOG(ISOLATE, StringEvent("OS::Allocate", "VirtualAlloc failed")); | 837 LOG(ISOLATE, StringEvent("OS::Allocate", "VirtualAlloc failed")); |
869 return NULL; | 838 return NULL; |
870 } | 839 } |
871 | 840 |
872 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); | 841 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); |
873 | 842 |
874 *allocated = msize; | 843 *allocated = msize; |
875 UpdateAllocatedSpaceLimits(mbase, static_cast<int>(msize)); | |
876 return mbase; | 844 return mbase; |
877 } | 845 } |
878 | 846 |
879 | 847 |
880 void OS::Free(void* address, const size_t size) { | 848 void OS::Free(void* address, const size_t size) { |
881 // TODO(1240712): VirtualFree has a return value which is ignored here. | 849 // TODO(1240712): VirtualFree has a return value which is ignored here. |
882 VirtualFree(address, 0, MEM_RELEASE); | 850 VirtualFree(address, 0, MEM_RELEASE); |
883 USE(size); | 851 USE(size); |
884 } | 852 } |
885 | 853 |
(...skipping 597 matching lines...) Loading... |
1483 void* VirtualMemory::ReserveRegion(size_t size) { | 1451 void* VirtualMemory::ReserveRegion(size_t size) { |
1484 return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS); | 1452 return RandomizedVirtualAlloc(size, MEM_RESERVE, PAGE_NOACCESS); |
1485 } | 1453 } |
1486 | 1454 |
1487 | 1455 |
1488 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { | 1456 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { |
1489 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 1457 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
1490 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) { | 1458 if (NULL == VirtualAlloc(base, size, MEM_COMMIT, prot)) { |
1491 return false; | 1459 return false; |
1492 } | 1460 } |
1493 | |
1494 UpdateAllocatedSpaceLimits(base, static_cast<int>(size)); | |
1495 return true; | 1461 return true; |
1496 } | 1462 } |
1497 | 1463 |
1498 | 1464 |
1499 bool VirtualMemory::UncommitRegion(void* base, size_t size) { | 1465 bool VirtualMemory::UncommitRegion(void* base, size_t size) { |
1500 return VirtualFree(base, size, MEM_DECOMMIT) != 0; | 1466 return VirtualFree(base, size, MEM_DECOMMIT) != 0; |
1501 } | 1467 } |
1502 | 1468 |
1503 | 1469 |
1504 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { | 1470 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { |
(...skipping 111 matching lines...) Loading... |
1616 | 1582 |
1617 | 1583 |
1618 void OS::SetUp() { | 1584 void OS::SetUp() { |
1619 // Seed the random number generator. | 1585 // Seed the random number generator. |
1620 // Convert the current time to a 64-bit integer first, before converting it | 1586 // Convert the current time to a 64-bit integer first, before converting it |
1621 // to an unsigned. Going directly can cause an overflow and the seed to be | 1587 // to an unsigned. Going directly can cause an overflow and the seed to be |
1622 // set to all ones. The seed will be identical for different instances that | 1588 // set to all ones. The seed will be identical for different instances that |
1623 // call this setup code within the same millisecond. | 1589 // call this setup code within the same millisecond. |
1624 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); | 1590 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); |
1625 srand(static_cast<unsigned int>(seed)); | 1591 srand(static_cast<unsigned int>(seed)); |
1626 limit_mutex = new Mutex(); | |
1627 } | 1592 } |
1628 | 1593 |
1629 | |
1630 void OS::TearDown() { | |
1631 delete limit_mutex; | |
1632 } | |
1633 | |
1634 | |
1635 } } // namespace v8::internal | 1594 } } // namespace v8::internal |
OLD | NEW |