blob: 0077a772acc480eb93771940667fb8cbd199298b [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"
18
19namespace art {
20
21class HeapTest : public CommonTest {};
22
jeffhaoc1160702011-10-27 15:48:45 -070023TEST_F(HeapTest, ClearGrowthLimit) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080024 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();
jeffhaoc1160702011-10-27 15:48:45 -070030 EXPECT_GE(max_memory_after, max_memory_before);
31 EXPECT_GE(total_memory_after, total_memory_before);
32}
33
Brian Carlstrom693267a2011-09-06 09:25:34 -070034TEST_F(HeapTest, GarbageCollectClassLinkerInit) {
Brian Carlstrom1f870082011-08-23 16:02:11 -070035 // garbage is created during ClassLinker::Init
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070036
37 Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;");
38 for (size_t i = 0; i < 1024; ++i) {
Brian Carlstrom40381fb2011-10-19 14:13:40 -070039 SirtRef<ObjectArray<Object> > array(ObjectArray<Object>::Alloc(c, 2048));
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070040 for (size_t j = 0; j < 2048; ++j) {
41 array->Set(j, String::AllocFromModifiedUtf8("hello, world!"));
42 }
43 }
44
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080045 Runtime::Current()->GetHeap()->CollectGarbage(false);
Brian Carlstrom1f870082011-08-23 16:02:11 -070046}
47
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070048} // namespace art