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" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 18 | #include "gc/card_table-inl.h" |
| 19 | #include "gc/space_bitmap-inl.h" |
| 20 | #include "mirror/class-inl.h" |
| 21 | #include "mirror/object-inl.h" |
| 22 | #include "mirror/object_array-inl.h" |
Ian Rogers | 1f53934 | 2012-10-03 21:09:42 -0700 | [diff] [blame] | 23 | #include "sirt_ref.h" |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | class HeapTest : public CommonTest {}; |
| 28 | |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 29 | TEST_F(HeapTest, ClearGrowthLimit) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 30 | Heap* heap = Runtime::Current()->GetHeap(); |
| 31 | int64_t max_memory_before = heap->GetMaxMemory(); |
| 32 | int64_t total_memory_before = heap->GetTotalMemory(); |
| 33 | heap->ClearGrowthLimit(); |
| 34 | int64_t max_memory_after = heap->GetMaxMemory(); |
| 35 | int64_t total_memory_after = heap->GetTotalMemory(); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 36 | EXPECT_GE(max_memory_after, max_memory_before); |
| 37 | EXPECT_GE(total_memory_after, total_memory_before); |
| 38 | } |
| 39 | |
Brian Carlstrom | 693267a | 2011-09-06 09:25:34 -0700 | [diff] [blame] | 40 | TEST_F(HeapTest, GarbageCollectClassLinkerInit) { |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 41 | { |
| 42 | ScopedObjectAccess soa(Thread::Current()); |
| 43 | // garbage is created during ClassLinker::Init |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 44 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 45 | mirror::Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;"); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 46 | for (size_t i = 0; i < 1024; ++i) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 47 | SirtRef<mirror::ObjectArray<mirror::Object> > array(soa.Self(), |
| 48 | mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), c, 2048)); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 49 | for (size_t j = 0; j < 2048; ++j) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 50 | array->Set(j, mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello, world!")); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 51 | } |
Elliott Hughes | 3b6baaa | 2011-10-14 19:13:56 -0700 | [diff] [blame] | 52 | } |
| 53 | } |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 54 | Runtime::Current()->GetHeap()->CollectGarbage(false); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Mathieu Chartier | 61c9cb5 | 2012-07-03 14:39:54 -0700 | [diff] [blame] | 57 | TEST_F(HeapTest, HeapBitmapCapacityTest) { |
| 58 | byte* heap_begin = reinterpret_cast<byte*>(0x1000); |
Mathieu Chartier | b062fdd | 2012-07-03 09:51:48 -0700 | [diff] [blame] | 59 | const size_t heap_capacity = SpaceBitmap::kAlignment * (sizeof(intptr_t) * 8 + 1); |
Ian Rogers | a40307e | 2013-02-22 11:32:44 -0800 | [diff] [blame] | 60 | UniquePtr<SpaceBitmap> bitmap(SpaceBitmap::Create("test bitmap", heap_begin, heap_capacity)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 61 | bitmap->Set(reinterpret_cast<const mirror::Object*>(&heap_begin[heap_capacity - SpaceBitmap::kAlignment])); |
Mathieu Chartier | 61c9cb5 | 2012-07-03 14:39:54 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 64 | } // namespace art |