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) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 24 | Heap* heap = Runtime::Current()->GetHeap(); |
| 25 | int64_t max_memory_before = heap->GetMaxMemory(); |
| 26 | int64_t total_memory_before = heap->GetTotalMemory(); |
| 27 | heap->ClearGrowthLimit(); |
| 28 | int64_t max_memory_after = heap->GetMaxMemory(); |
| 29 | int64_t total_memory_after = heap->GetTotalMemory(); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 30 | EXPECT_GE(max_memory_after, max_memory_before); |
| 31 | EXPECT_GE(total_memory_after, total_memory_before); |
| 32 | } |
| 33 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 34 | TEST_F(HeapTest, GarbageCollectClassLinkerInit) { |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 35 | // garbage is created during ClassLinker::Init |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 36 | |
| 37 | Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;"); |
| 38 | for (size_t i = 0; i < 1024; ++i) { |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 39 | SirtRef<ObjectArray<Object> > array(ObjectArray<Object>::Alloc(c, 2048)); |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 40 | for (size_t j = 0; j < 2048; ++j) { |
| 41 | array->Set(j, String::AllocFromModifiedUtf8("hello, world!")); |
| 42 | } |
| 43 | } |
| 44 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 45 | Runtime::Current()->GetHeap()->CollectGarbage(false); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 48 | } // namespace art |