| 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/pages.h" | 6 #include "vm/pages.h" |
| 7 #include "vm/unit_test.h" | 7 #include "vm/unit_test.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| 11 TEST_CASE(Pages) { | 11 TEST_CASE(Pages) { |
| 12 PageSpace* space = new PageSpace(NULL, 4 * MBInWords); | 12 PageSpace* space = new PageSpace(NULL, 4 * MBInWords, 8 * MBInWords); |
| 13 EXPECT(!space->Contains(reinterpret_cast<uword>(&space))); | 13 EXPECT(!space->Contains(reinterpret_cast<uword>(&space))); |
| 14 uword block = space->TryAllocate(8 * kWordSize); | 14 uword block = space->TryAllocate(8 * kWordSize); |
| 15 EXPECT(block != 0); | 15 EXPECT(block != 0); |
| 16 uword total = 0; | 16 uword total = 0; |
| 17 while (total < 2 * MB) { | 17 while (total < 2 * MB) { |
| 18 const intptr_t kBlockSize = 16 * kWordSize; | 18 const intptr_t kBlockSize = 16 * kWordSize; |
| 19 uword new_block = space->TryAllocate(kBlockSize); | 19 uword new_block = space->TryAllocate(kBlockSize); |
| 20 EXPECT(block != 0); | 20 EXPECT(block != 0); |
| 21 EXPECT(block != new_block); | 21 EXPECT(block != new_block); |
| 22 EXPECT(space->IsValidAddress(new_block)); | 22 EXPECT(space->IsValidAddress(new_block)); |
| 23 block = new_block; | 23 block = new_block; |
| 24 total += kBlockSize; | 24 total += kBlockSize; |
| 25 } | 25 } |
| 26 // Allocate a large block. | 26 // Allocate a large block. |
| 27 uword large_block = space->TryAllocate(1 * MB); | 27 uword large_block = space->TryAllocate(1 * MB); |
| 28 EXPECT(large_block != 0); | 28 EXPECT(large_block != 0); |
| 29 EXPECT(block != large_block); | 29 EXPECT(block != large_block); |
| 30 EXPECT(space->IsValidAddress(large_block)); | 30 EXPECT(space->IsValidAddress(large_block)); |
| 31 delete space; | 31 delete space; |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace dart | 34 } // namespace dart |
| OLD | NEW |