| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/virtual_memory.h" | 5 #include "vm/virtual_memory.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 | 11 |
| 12 bool VirtualMemory::InSamePage(uword address0, uword address1) { |
| 13 return (Utils::RoundDown(address0, PageSize()) == |
| 14 Utils::RoundDown(address1, PageSize())); |
| 15 } |
| 16 |
| 17 |
| 12 VirtualMemory* VirtualMemory::ReserveAligned(intptr_t size, | 18 VirtualMemory* VirtualMemory::ReserveAligned(intptr_t size, |
| 13 intptr_t alignment) { | 19 intptr_t alignment) { |
| 14 ASSERT((size & (PageSize() - 1)) == 0); | 20 ASSERT((size & (PageSize() - 1)) == 0); |
| 15 ASSERT(Utils::IsPowerOfTwo(alignment)); | 21 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 16 ASSERT(alignment >= PageSize()); | 22 ASSERT(alignment >= PageSize()); |
| 17 VirtualMemory* result = VirtualMemory::Reserve(size + alignment); | 23 VirtualMemory* result = VirtualMemory::Reserve(size + alignment); |
| 18 if (result == NULL) { | 24 if (result == NULL) { |
| 19 FATAL("Out of memory.\n"); | 25 FATAL("Out of memory.\n"); |
| 20 } | 26 } |
| 21 uword start = result->start(); | 27 uword start = result->start(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 34 FreeSubSegment(address(), split); | 40 FreeSubSegment(address(), split); |
| 35 region_.Subregion(region_, split, size() - split); | 41 region_.Subregion(region_, split, size() - split); |
| 36 } | 42 } |
| 37 ASSERT(new_size <= size()); | 43 ASSERT(new_size <= size()); |
| 38 FreeSubSegment(reinterpret_cast<void*>(start() + new_size), | 44 FreeSubSegment(reinterpret_cast<void*>(start() + new_size), |
| 39 size() - new_size); | 45 size() - new_size); |
| 40 region_.Subregion(region_, 0, new_size); | 46 region_.Subregion(region_, 0, new_size); |
| 41 } | 47 } |
| 42 | 48 |
| 43 } // namespace dart | 49 } // namespace dart |
| OLD | NEW |