Home | History | Annotate | Download | only in accounting
      1 /*
      2  * Copyright (C) 2012 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 #ifndef ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_
     18 #define ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_
     19 
     20 #include <android-base/logging.h>
     21 
     22 #include "base/allocator.h"
     23 #include "base/macros.h"
     24 #include "base/mutex.h"
     25 #include "space_bitmap.h"
     26 
     27 namespace art {
     28 namespace gc {
     29 
     30 class Heap;
     31 
     32 namespace collector {
     33 class ConcurrentCopying;
     34 }  // namespace collector
     35 
     36 namespace accounting {
     37 
     38 class HeapBitmap {
     39  public:
     40   bool Test(const mirror::Object* obj) REQUIRES_SHARED(Locks::heap_bitmap_lock_);
     41   void Clear(const mirror::Object* obj) REQUIRES(Locks::heap_bitmap_lock_);
     42   template<typename LargeObjectSetVisitor>
     43   bool Set(const mirror::Object* obj, const LargeObjectSetVisitor& visitor)
     44       REQUIRES_SHARED(Locks::mutator_lock_)
     45       REQUIRES(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
     46   template<typename LargeObjectSetVisitor>
     47   bool AtomicTestAndSet(const mirror::Object* obj, const LargeObjectSetVisitor& visitor)
     48       REQUIRES_SHARED(Locks::mutator_lock_)
     49       REQUIRES(Locks::heap_bitmap_lock_) ALWAYS_INLINE;
     50   ContinuousSpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) const;
     51   LargeObjectBitmap* GetLargeObjectBitmap(const mirror::Object* obj) const;
     52 
     53   template <typename Visitor>
     54   ALWAYS_INLINE void Visit(Visitor&& visitor)
     55       REQUIRES(Locks::heap_bitmap_lock_)
     56       REQUIRES_SHARED(Locks::mutator_lock_);
     57 
     58   // Find and replace a bitmap pointer, this is used by for the bitmap swapping in the GC.
     59   void ReplaceBitmap(ContinuousSpaceBitmap* old_bitmap, ContinuousSpaceBitmap* new_bitmap)
     60       REQUIRES(Locks::heap_bitmap_lock_);
     61 
     62   // Find and replace a object set pointer, this is used by for the bitmap swapping in the GC.
     63   void ReplaceLargeObjectBitmap(LargeObjectBitmap* old_bitmap, LargeObjectBitmap* new_bitmap)
     64       REQUIRES(Locks::heap_bitmap_lock_);
     65 
     66   explicit HeapBitmap(Heap* heap) : heap_(heap) {}
     67 
     68  private:
     69   const Heap* const heap_;
     70 
     71   void AddContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
     72   void RemoveContinuousSpaceBitmap(ContinuousSpaceBitmap* bitmap);
     73   void AddLargeObjectBitmap(LargeObjectBitmap* bitmap);
     74   void RemoveLargeObjectBitmap(LargeObjectBitmap* bitmap);
     75 
     76   // Bitmaps covering continuous spaces.
     77   std::vector<ContinuousSpaceBitmap*,
     78               TrackingAllocator<ContinuousSpaceBitmap*, kAllocatorTagHeapBitmap>>
     79       continuous_space_bitmaps_;
     80 
     81   // Sets covering discontinuous spaces.
     82   std::vector<LargeObjectBitmap*,
     83               TrackingAllocator<LargeObjectBitmap*, kAllocatorTagHeapBitmapLOS>>
     84       large_object_bitmaps_;
     85 
     86   friend class art::gc::Heap;
     87   friend class art::gc::collector::ConcurrentCopying;
     88 };
     89 
     90 }  // namespace accounting
     91 }  // namespace gc
     92 }  // namespace art
     93 
     94 #endif  // ART_RUNTIME_GC_ACCOUNTING_HEAP_BITMAP_H_
     95