Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 16 | |
| 17 | #include "common_test.h" |
| 18 | |
| 19 | namespace art { |
| 20 | |
| 21 | class HeapTest : public CommonTest {}; |
| 22 | |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 23 | TEST_F(HeapTest, ClearGrowthLimit) { |
| 24 | int64_t max_memory_before = Heap::GetMaxMemory(); |
| 25 | int64_t total_memory_before = Heap::GetTotalMemory(); |
| 26 | Heap::ClearGrowthLimit(); |
| 27 | int64_t max_memory_after = Heap::GetMaxMemory(); |
| 28 | int64_t total_memory_after = Heap::GetTotalMemory(); |
| 29 | EXPECT_GE(max_memory_after, max_memory_before); |
| 30 | EXPECT_GE(total_memory_after, total_memory_before); |
| 31 | } |
| 32 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 33 | TEST_F(HeapTest, GarbageCollectClassLinkerInit) { |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 34 | // garbage is created during ClassLinker::Init |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 35 | |
| 36 | Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;"); |
| 37 | for (size_t i = 0; i < 1024; ++i) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 38 | SirtRef<ObjectArray<Object> > array(ObjectArray<Object>::Alloc(c, 2048)); |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 39 | for (size_t j = 0; j < 2048; ++j) { |
| 40 | array->Set(j, String::AllocFromModifiedUtf8("hello, world!")); |
| 41 | } |
| 42 | } |
| 43 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 44 | Heap::CollectGarbage(false); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 47 | } // namespace art |