blob: 2035ce881cbaac0ddf97a404cafd9603fe92b311 [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) {
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 Carlstrom693267a2011-09-06 09:25:34 -070033TEST_F(HeapTest, GarbageCollectClassLinkerInit) {
Brian Carlstrom1f870082011-08-23 16:02:11 -070034 // garbage is created during ClassLinker::Init
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070035
36 Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;");
37 for (size_t i = 0; i < 1024; ++i) {
Brian Carlstrom40381fb2011-10-19 14:13:40 -070038 SirtRef<ObjectArray<Object> > array(ObjectArray<Object>::Alloc(c, 2048));
Elliott Hughes3b6baaa2011-10-14 19:13:56 -070039 for (size_t j = 0; j < 2048; ++j) {
40 array->Set(j, String::AllocFromModifiedUtf8("hello, world!"));
41 }
42 }
43
Ian Rogers30fab402012-01-23 15:43:46 -080044 Heap::CollectGarbage(false);
Brian Carlstrom1f870082011-08-23 16:02:11 -070045}
46
Ian Rogers0cfe1fb2011-08-26 03:29:44 -070047} // namespace art