blob: 881a7651312c0727a6cfe33953437f42aefcc205 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Carlstrom1f870082011-08-23 16:02:11 -070016
17#include "common_test.h"
Ian Rogers1f539342012-10-03 21:09:42 -070018#include "sirt_ref.h"
Brian Carlstrom1f870082011-08-23 16:02:11 -070019
20namespace art {
21
22class HeapTest : public CommonTest {};
23
jeffhaoc1160702011-10-27 15:48:45 -070024TEST_F(HeapTest, ClearGrowthLimit) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080025 Heap* heap = Runtime::Current()->GetHeap();
26 int64_t max_memory_before = heap->GetMaxMemory();
27 int64_t total_memory_before = heap->GetTotalMemory();
28 heap->ClearGrowthLimit();
29 int64_t max_memory_after = heap->GetMaxMemory();
30 int64_t total_memory_after = heap->GetTotalMemory();
jeffhaoc1160702011-10-27 15:48:45 -070031 EXPECT_GE(max_memory_after, max_memory_before);
32 EXPECT_GE(total_memory_after, total_memory_before);
33}
34
Brian Carlstrom693267a2011-09-06 09:25:34 -070035TEST_F(HeapTest, GarbageCollectClassLinkerInit) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -070036 {
37 ScopedObjectAccess soa(Thread::Current());
38 // garbage is created during ClassLinker::Init
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070039
Ian Rogers00f7d0e2012-07-19 15:28:27 -070040 Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;");
41 for (size_t i = 0; i < 1024; ++i) {
Ian Rogers1f539342012-10-03 21:09:42 -070042 SirtRef<ObjectArray<Object> > array(soa.Self(), ObjectArray<Object>::Alloc(c, 2048));
Ian Rogers00f7d0e2012-07-19 15:28:27 -070043 for (size_t j = 0; j < 2048; ++j) {
44 array->Set(j, String::AllocFromModifiedUtf8("hello, world!"));
45 }
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070046 }
47 }
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080048 Runtime::Current()->GetHeap()->CollectGarbage(false);
Brian Carlstrom1f870082011-08-23 16:02:11 -070049}
50
Mathieu Chartier61c9cb52012-07-03 14:39:54 -070051TEST_F(HeapTest, HeapBitmapCapacityTest) {
52 byte* heap_begin = reinterpret_cast<byte*>(0x1000);
Mathieu Chartierb062fdd2012-07-03 09:51:48 -070053 const size_t heap_capacity = SpaceBitmap::kAlignment * (sizeof(intptr_t) * 8 + 1);
54 UniquePtr<SpaceBitmap> bitmap(SpaceBitmap::Create("test-bitmap", heap_begin, heap_capacity));
55 bitmap->Set(reinterpret_cast<const Object*>(&heap_begin[heap_capacity - SpaceBitmap::kAlignment]));
Mathieu Chartier61c9cb52012-07-03 14:39:54 -070056}
57
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070058} // namespace art