blob: 32ac95f9f82dc8e576a9baa34bb5ca74247ac5d6 [file] [log] [blame]
Ian Rogers1d54e732013-05-02 21:10:01 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_GC_ACCOUNTING_MOD_UNION_TABLE_INL_H_
18#define ART_RUNTIME_GC_ACCOUNTING_MOD_UNION_TABLE_INL_H_
Ian Rogers1d54e732013-05-02 21:10:01 -070019
20#include "mod_union_table.h"
21
22#include "gc/space/space.h"
23
24namespace art {
25namespace gc {
26namespace accounting {
27
28// A mod-union table to record image references to the Zygote and alloc space.
29class ModUnionTableToZygoteAllocspace : public ModUnionTableReferenceCache {
30public:
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.
49class 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070075#endif // ART_RUNTIME_GC_ACCOUNTING_MOD_UNION_TABLE_INL_H_