blob: 381a98e3860db2b80dbe72659b8ef085b288340d [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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_
18#define ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_
Ian Rogers1d54e732013-05-02 21:10:01 -070019
20#include "space.h"
21
22namespace art {
Brian Carlstrom56d947f2013-07-15 13:14:23 -070023
24class OatFile;
25
Ian Rogers1d54e732013-05-02 21:10:01 -070026namespace gc {
27namespace space {
28
29// An image space is a space backed with a memory mapped image.
30class ImageSpace : public MemMapSpace {
31 public:
32 bool CanAllocateInto() const {
33 return false;
34 }
35
36 SpaceType GetType() const {
37 return kSpaceTypeImageSpace;
38 }
39
Brian Carlstrom56d947f2013-07-15 13:14:23 -070040 // Create a Space from an image file. Cannot be used for future
41 // allocation or collected.
42 //
43 // Create also opens the OatFile associated with the image file so
44 // that it be contiguously allocated with the image before the
45 // creation of the alloc space. The ReleaseOatFile will later be
46 // used to transfer ownership of the OatFile to the ClassLinker when
47 // it is initialized.
Ian Rogers1d54e732013-05-02 21:10:01 -070048 static ImageSpace* Create(const std::string& image)
49 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
50
Brian Carlstrom56d947f2013-07-15 13:14:23 -070051 // Releases the OatFile from the ImageSpace so it can be transfer to
52 // the caller, presumably the ClassLinker.
53 OatFile& ReleaseOatFile()
54 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
55
Mathieu Chartier31e89252013-08-28 11:29:12 -070056 void VerifyImageAllocations()
57 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
58
Ian Rogers1d54e732013-05-02 21:10:01 -070059 const ImageHeader& GetImageHeader() const {
60 return *reinterpret_cast<ImageHeader*>(Begin());
61 }
62
63 const std::string GetImageFilename() const {
64 return GetName();
65 }
66
Ian Rogers1d54e732013-05-02 21:10:01 -070067 accounting::SpaceBitmap* GetLiveBitmap() const {
68 return live_bitmap_.get();
69 }
70
71 accounting::SpaceBitmap* GetMarkBitmap() const {
72 // ImageSpaces have the same bitmap for both live and marked. This helps reduce the number of
73 // special cases to test against.
74 return live_bitmap_.get();
75 }
76
77 void Dump(std::ostream& os) const;
78
79 private:
Brian Carlstrom56d947f2013-07-15 13:14:23 -070080 // Tries to initialize an ImageSpace from the given image path,
81 // returning NULL on error.
82 //
83 // If validate_oat_file is false (for /system), do not verify that
84 // image's OatFile is up-to-date relative to its DexFile
85 // inputs. Otherwise (for /data), validate the inputs and generate
86 // the OatFile in /data/dalvik-cache if necessary.
87 static ImageSpace* Init(const std::string& image, bool validate_oat_file)
88 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
89
90 OatFile* OpenOatFile() const
91 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
92
93 bool ValidateOatFile() const
94 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
95
Ian Rogers1d54e732013-05-02 21:10:01 -070096 friend class Space;
97
Mathieu Chartier31e89252013-08-28 11:29:12 -070098 static AtomicInteger bitmap_index_;
Ian Rogers1d54e732013-05-02 21:10:01 -070099
100 UniquePtr<accounting::SpaceBitmap> live_bitmap_;
101
Mathieu Chartier31e89252013-08-28 11:29:12 -0700102 ImageSpace(const std::string& name, MemMap* mem_map, accounting::SpaceBitmap* live_bitmap);
Ian Rogers1d54e732013-05-02 21:10:01 -0700103
Brian Carlstrom56d947f2013-07-15 13:14:23 -0700104 // The OatFile associated with the image during early startup to
105 // reserve space contiguous to the image. It is later released to
106 // the ClassLinker during it's initialization.
107 UniquePtr<OatFile> oat_file_;
108
Ian Rogers1d54e732013-05-02 21:10:01 -0700109 DISALLOW_COPY_AND_ASSIGN(ImageSpace);
110};
111
112} // namespace space
113} // namespace gc
114} // namespace art
115
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700116#endif // ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_