Chromium Code Reviews| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/unit_test.h" | 6 #include "vm/unit_test.h" |
| 7 #include "vm/virtual_memory.h" | 7 #include "vm/virtual_memory.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 buf[1] = 'c'; | 32 buf[1] = 'c'; |
| 33 buf[2] = '/'; | 33 buf[2] = '/'; |
| 34 buf[3] = 'd'; | 34 buf[3] = 'd'; |
| 35 buf[4] = 'c'; | 35 buf[4] = 'c'; |
| 36 buf[5] = 0; | 36 buf[5] = 0; |
| 37 EXPECT_STREQ("ac/dc", buf); | 37 EXPECT_STREQ("ac/dc", buf); |
| 38 | 38 |
| 39 delete vm; | 39 delete vm; |
| 40 } | 40 } |
| 41 | 41 |
| 42 | |
| 43 UNIT_TEST_CASE(FreeVirtualMemory) { | |
| 44 // Reservations should always be handed back to OS upon destruction. | |
| 45 const intptr_t kVirtualMemoryBlockSize = 10 * MB; | |
| 46 const intptr_t kIterations = 900; // Enough to exhaust 32-bit address space. | |
| 47 for (intptr_t i = 0; i < kIterations; ++i) { | |
| 48 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); | |
| 49 vm->Commit(false); | |
|
Ivan Posva
2014/10/09 18:31:56
You might want to alternate the value for the exec
| |
| 50 delete vm; | |
| 51 } | |
| 52 // Check that truncation does not introduce leaks. | |
| 53 for (intptr_t i = 0; i < kIterations; ++i) { | |
| 54 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); | |
| 55 vm->Commit(false); | |
| 56 vm->Truncate(kVirtualMemoryBlockSize / 2, true); | |
| 57 delete vm; | |
| 58 } | |
| 59 for (intptr_t i = 0; i < kIterations; ++i) { | |
| 60 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); | |
| 61 vm->Commit(false); | |
| 62 vm->Truncate(kVirtualMemoryBlockSize / 2, false); | |
| 63 delete vm; | |
| 64 } | |
| 65 for (intptr_t i = 0; i < kIterations; ++i) { | |
| 66 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); | |
| 67 vm->Commit(false); | |
| 68 vm->Truncate(0, true); | |
| 69 delete vm; | |
| 70 } | |
| 71 for (intptr_t i = 0; i < kIterations; ++i) { | |
| 72 VirtualMemory* vm = VirtualMemory::Reserve(kVirtualMemoryBlockSize); | |
| 73 vm->Commit(false); | |
| 74 vm->Truncate(0, false); | |
| 75 delete vm; | |
| 76 } | |
| 77 } | |
| 78 | |
| 42 } // namespace dart | 79 } // namespace dart |
| OLD | NEW |