Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_ |
| 18 | #define ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_ |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 19 | |
| 20 | #include "space.h" |
| 21 | |
| 22 | namespace art { |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 23 | |
| 24 | class OatFile; |
| 25 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 26 | namespace gc { |
| 27 | namespace space { |
| 28 | |
| 29 | // An image space is a space backed with a memory mapped image. |
| 30 | class ImageSpace : public MemMapSpace { |
| 31 | public: |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 32 | SpaceType GetType() const { |
| 33 | return kSpaceTypeImageSpace; |
| 34 | } |
| 35 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 36 | // Create a Space from an image file. Cannot be used for future |
| 37 | // allocation or collected. |
| 38 | // |
| 39 | // Create also opens the OatFile associated with the image file so |
| 40 | // that it be contiguously allocated with the image before the |
| 41 | // creation of the alloc space. The ReleaseOatFile will later be |
| 42 | // used to transfer ownership of the OatFile to the ClassLinker when |
| 43 | // it is initialized. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 44 | static ImageSpace* Create(const char* image) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 45 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 46 | // Releases the OatFile from the ImageSpace so it can be transfer to |
| 47 | // the caller, presumably the ClassLinker. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 48 | OatFile* ReleaseOatFile() |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 49 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 50 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 51 | void VerifyImageAllocations() |
| 52 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 53 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 54 | const ImageHeader& GetImageHeader() const { |
| 55 | return *reinterpret_cast<ImageHeader*>(Begin()); |
| 56 | } |
| 57 | |
| 58 | const std::string GetImageFilename() const { |
| 59 | return GetName(); |
| 60 | } |
| 61 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 62 | accounting::SpaceBitmap* GetLiveBitmap() const { |
| 63 | return live_bitmap_.get(); |
| 64 | } |
| 65 | |
| 66 | accounting::SpaceBitmap* GetMarkBitmap() const { |
| 67 | // ImageSpaces have the same bitmap for both live and marked. This helps reduce the number of |
| 68 | // special cases to test against. |
| 69 | return live_bitmap_.get(); |
| 70 | } |
| 71 | |
| 72 | void Dump(std::ostream& os) const; |
| 73 | |
Mathieu Chartier | a1602f2 | 2014-01-13 17:19:19 -0800 | [diff] [blame^] | 74 | // Sweeping image spaces is a NOP. |
| 75 | void Sweep(bool /* swap_bitmaps */, size_t* /* freed_objects */, size_t* /* freed_bytes */) { |
| 76 | } |
| 77 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 78 | private: |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 79 | // Tries to initialize an ImageSpace from the given image path, |
| 80 | // returning NULL on error. |
| 81 | // |
| 82 | // If validate_oat_file is false (for /system), do not verify that |
| 83 | // image's OatFile is up-to-date relative to its DexFile |
| 84 | // inputs. Otherwise (for /data), validate the inputs and generate |
| 85 | // the OatFile in /data/dalvik-cache if necessary. |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 86 | static ImageSpace* Init(const char* image, bool validate_oat_file, std::string* error_msg) |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 87 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 88 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 89 | OatFile* OpenOatFile(std::string* error_msg) const |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 90 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 91 | |
Ian Rogers | 8d31bbd | 2013-10-13 10:44:14 -0700 | [diff] [blame] | 92 | bool ValidateOatFile(std::string* error_msg) const |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 93 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 94 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 95 | friend class Space; |
| 96 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 97 | static AtomicInteger bitmap_index_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 98 | |
| 99 | UniquePtr<accounting::SpaceBitmap> live_bitmap_; |
| 100 | |
Mathieu Chartier | 31e8925 | 2013-08-28 11:29:12 -0700 | [diff] [blame] | 101 | ImageSpace(const std::string& name, MemMap* mem_map, accounting::SpaceBitmap* live_bitmap); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 102 | |
Brian Carlstrom | 56d947f | 2013-07-15 13:14:23 -0700 | [diff] [blame] | 103 | // The OatFile associated with the image during early startup to |
| 104 | // reserve space contiguous to the image. It is later released to |
| 105 | // the ClassLinker during it's initialization. |
| 106 | UniquePtr<OatFile> oat_file_; |
| 107 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 108 | DISALLOW_COPY_AND_ASSIGN(ImageSpace); |
| 109 | }; |
| 110 | |
| 111 | } // namespace space |
| 112 | } // namespace gc |
| 113 | } // namespace art |
| 114 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 115 | #endif // ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_ |