blob: afec5b7305a863b7b22ecb4fdf21bf2c3881e4aa [file] [log] [blame]
Ian Rogers1d54e732013-05-02 21:10:01 -07001/*
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#ifndef ART_SRC_GC_SPACE_IMAGE_SPACE_H_
18#define ART_SRC_GC_SPACE_IMAGE_SPACE_H_
19
20#include "space.h"
21
22namespace art {
23namespace gc {
24namespace space {
25
26// An image space is a space backed with a memory mapped image.
27class ImageSpace : public MemMapSpace {
28 public:
29 bool CanAllocateInto() const {
30 return false;
31 }
32
33 SpaceType GetType() const {
34 return kSpaceTypeImageSpace;
35 }
36
37 // create a Space from an image file. cannot be used for future allocation or collected.
38 static ImageSpace* Create(const std::string& image)
39 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
40
41 const ImageHeader& GetImageHeader() const {
42 return *reinterpret_cast<ImageHeader*>(Begin());
43 }
44
45 const std::string GetImageFilename() const {
46 return GetName();
47 }
48
49 // Mark the objects defined in this space in the given live bitmap
50 void RecordImageAllocations(accounting::SpaceBitmap* live_bitmap) const
51 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
52
53 accounting::SpaceBitmap* GetLiveBitmap() const {
54 return live_bitmap_.get();
55 }
56
57 accounting::SpaceBitmap* GetMarkBitmap() const {
58 // ImageSpaces have the same bitmap for both live and marked. This helps reduce the number of
59 // special cases to test against.
60 return live_bitmap_.get();
61 }
62
63 void Dump(std::ostream& os) const;
64
65 private:
66 friend class Space;
67
68 static size_t bitmap_index_;
69
70 UniquePtr<accounting::SpaceBitmap> live_bitmap_;
71
72 ImageSpace(const std::string& name, MemMap* mem_map);
73
74 DISALLOW_COPY_AND_ASSIGN(ImageSpace);
75};
76
77} // namespace space
78} // namespace gc
79} // namespace art
80
81#endif // ART_SRC_GC_SPACE_IMAGE_SPACE_H_