Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame^] | 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_SRC_GC_MOD_UNION_TABLE_INL_H_ |
| 18 | #define ART_SRC_GC_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 | ModUnionTableToZygoteAllocspace(Heap* heap) : ModUnionTableReferenceCache(heap) { |
| 32 | } |
| 33 | |
| 34 | bool AddReference(const mirror::Object* /* obj */, const mirror::Object* ref) { |
| 35 | const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces(); |
| 36 | typedef std::vector<space::ContinuousSpace*>::const_iterator It; |
| 37 | for (It it = spaces.begin(); it != spaces.end(); ++it) { |
| 38 | if ((*it)->Contains(ref)) { |
| 39 | return (*it)->IsDlMallocSpace(); |
| 40 | } |
| 41 | } |
| 42 | // Assume it points to a large object. |
| 43 | // TODO: Check. |
| 44 | return true; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | // A mod-union table to record Zygote references to the alloc space. |
| 49 | class ModUnionTableToAllocspace : public ModUnionTableReferenceCache { |
| 50 | public: |
| 51 | ModUnionTableToAllocspace(Heap* heap) : ModUnionTableReferenceCache(heap) { |
| 52 | } |
| 53 | |
| 54 | bool AddReference(const mirror::Object* /* obj */, const mirror::Object* ref) { |
| 55 | const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces(); |
| 56 | typedef std::vector<space::ContinuousSpace*>::const_iterator It; |
| 57 | for (It it = spaces.begin(); it != spaces.end(); ++it) { |
| 58 | space::ContinuousSpace* space = *it; |
| 59 | if (space->Contains(ref)) { |
| 60 | // The allocation space is always considered for collection whereas the Zygote space is |
| 61 | // |
| 62 | return space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect; |
| 63 | } |
| 64 | } |
| 65 | // Assume it points to a large object. |
| 66 | // TODO: Check. |
| 67 | return true; |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | } // namespace accounting |
| 72 | } // namespace gc |
| 73 | } // namespace art |
| 74 | |
| 75 | #endif // ART_SRC_GC_MOD_UNION_TABLE_INL_H_ |