Home | History | Annotate | Download | only in gc
      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  */
     16 
     17 #include "common_test.h"
     18 #include "gc/accounting/card_table-inl.h"
     19 #include "gc/accounting/space_bitmap-inl.h"
     20 #include "mirror/class-inl.h"
     21 #include "mirror/object-inl.h"
     22 #include "mirror/object_array-inl.h"
     23 #include "sirt_ref.h"
     24 
     25 namespace art {
     26 namespace gc {
     27 
     28 class HeapTest : public CommonTest {};
     29 
     30 TEST_F(HeapTest, ClearGrowthLimit) {
     31   Heap* heap = Runtime::Current()->GetHeap();
     32   int64_t max_memory_before = heap->GetMaxMemory();
     33   int64_t total_memory_before = heap->GetTotalMemory();
     34   heap->ClearGrowthLimit();
     35   int64_t max_memory_after = heap->GetMaxMemory();
     36   int64_t total_memory_after = heap->GetTotalMemory();
     37   EXPECT_GE(max_memory_after, max_memory_before);
     38   EXPECT_GE(total_memory_after, total_memory_before);
     39 }
     40 
     41 TEST_F(HeapTest, GarbageCollectClassLinkerInit) {
     42   {
     43     ScopedObjectAccess soa(Thread::Current());
     44     // garbage is created during ClassLinker::Init
     45 
     46     mirror::Class* c = class_linker_->FindSystemClass("[Ljava/lang/Object;");
     47     for (size_t i = 0; i < 1024; ++i) {
     48       SirtRef<mirror::ObjectArray<mirror::Object> > array(soa.Self(),
     49           mirror::ObjectArray<mirror::Object>::Alloc(soa.Self(), c, 2048));
     50       for (size_t j = 0; j < 2048; ++j) {
     51         array->Set(j, mirror::String::AllocFromModifiedUtf8(soa.Self(), "hello, world!"));
     52       }
     53     }
     54   }
     55   Runtime::Current()->GetHeap()->CollectGarbage(false);
     56 }
     57 
     58 TEST_F(HeapTest, HeapBitmapCapacityTest) {
     59   byte* heap_begin = reinterpret_cast<byte*>(0x1000);
     60   const size_t heap_capacity = accounting::SpaceBitmap::kAlignment * (sizeof(intptr_t) * 8 + 1);
     61   UniquePtr<accounting::SpaceBitmap> bitmap(accounting::SpaceBitmap::Create("test bitmap",
     62                                                                             heap_begin,
     63                                                                             heap_capacity));
     64   mirror::Object* fake_end_of_heap_object =
     65       reinterpret_cast<mirror::Object*>(&heap_begin[heap_capacity -
     66                                                     accounting::SpaceBitmap::kAlignment]);
     67   bitmap->Set(fake_end_of_heap_object);
     68 }
     69 
     70 }  // namespace gc
     71 }  // namespace art
     72