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_MOD_UNION_TABLE_INL_H_
     18 #define ART_RUNTIME_GC_ACCOUNTING_MOD_UNION_TABLE_INL_H_
     19 
     20 #include "mod_union_table.h"
     21 
     22 #include "gc/space/space.h"
     23 
     24 namespace art {
     25 namespace gc {
     26 namespace accounting {
     27 
     28 // A mod-union table to record image references to the Zygote and alloc space.
     29 class ModUnionTableToZygoteAllocspace : public ModUnionTableReferenceCache {
     30  public:
     31   explicit ModUnionTableToZygoteAllocspace(Heap* heap) : ModUnionTableReferenceCache(heap) {}
     32 
     33   bool AddReference(const mirror::Object* /* obj */, const mirror::Object* ref) {
     34     const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
     35     typedef std::vector<space::ContinuousSpace*>::const_iterator It;
     36     for (It it = spaces.begin(); it != spaces.end(); ++it) {
     37       if ((*it)->Contains(ref)) {
     38         return (*it)->IsDlMallocSpace();
     39       }
     40     }
     41     // Assume it points to a large object.
     42     // TODO: Check.
     43     return true;
     44   }
     45 };
     46 
     47 // A mod-union table to record Zygote references to the alloc space.
     48 class ModUnionTableToAllocspace : public ModUnionTableReferenceCache {
     49  public:
     50   explicit ModUnionTableToAllocspace(Heap* heap) : ModUnionTableReferenceCache(heap) {}
     51 
     52   bool AddReference(const mirror::Object* /* obj */, const mirror::Object* ref) {
     53     const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
     54     typedef std::vector<space::ContinuousSpace*>::const_iterator It;
     55     for (It it = spaces.begin(); it != spaces.end(); ++it) {
     56       space::ContinuousSpace* space = *it;
     57       if (space->Contains(ref)) {
     58         // The allocation space is always considered for collection whereas the Zygote space is
     59         //
     60         return space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect;
     61       }
     62     }
     63     // Assume it points to a large object.
     64     // TODO: Check.
     65     return true;
     66   }
     67 };
     68 
     69 }  // namespace accounting
     70 }  // namespace gc
     71 }  // namespace art
     72 
     73 #endif  // ART_RUNTIME_GC_ACCOUNTING_MOD_UNION_TABLE_INL_H_
     74