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