image_space.h revision 2974bc3d8a5d161d449dd66826d668d87bdc3cbe
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 17#ifndef ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_ 18#define ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_ 19 20#include "gc/accounting/space_bitmap.h" 21#include "runtime.h" 22#include "space.h" 23 24namespace art { 25 26class OatFile; 27 28namespace gc { 29namespace space { 30 31// An image space is a space backed with a memory mapped image. 32class ImageSpace : public MemMapSpace { 33 public: 34 SpaceType GetType() const { 35 return kSpaceTypeImageSpace; 36 } 37 38 // Create a Space from an image file for a specified instruction 39 // set. Cannot be used for future allocation or collected. 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. 46 static ImageSpace* Create(const char* image, const InstructionSet image_isa) 47 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 48 49 // Releases the OatFile from the ImageSpace so it can be transfer to 50 // the caller, presumably the ClassLinker. 51 OatFile* ReleaseOatFile() 52 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 53 54 void VerifyImageAllocations() 55 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 56 57 const ImageHeader& GetImageHeader() const { 58 return *reinterpret_cast<ImageHeader*>(Begin()); 59 } 60 61 const std::string GetImageFilename() const { 62 return GetName(); 63 } 64 65 accounting::ContinuousSpaceBitmap* GetLiveBitmap() const OVERRIDE { 66 return live_bitmap_.get(); 67 } 68 69 accounting::ContinuousSpaceBitmap* GetMarkBitmap() const OVERRIDE { 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 77 // Sweeping image spaces is a NOP. 78 void Sweep(bool /* swap_bitmaps */, size_t* /* freed_objects */, size_t* /* freed_bytes */) { 79 } 80 81 bool CanMoveObjects() const OVERRIDE { 82 return false; 83 } 84 85 private: 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. 93 static ImageSpace* Init(const char* image, bool validate_oat_file, std::string* error_msg) 94 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 95 96 OatFile* OpenOatFile(const char* image, std::string* error_msg) const 97 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 98 99 bool ValidateOatFile(std::string* error_msg) const 100 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); 101 102 friend class Space; 103 104 static Atomic<uint32_t> bitmap_index_; 105 106 UniquePtr<accounting::ContinuousSpaceBitmap> live_bitmap_; 107 108 ImageSpace(const std::string& name, MemMap* mem_map, 109 accounting::ContinuousSpaceBitmap* live_bitmap); 110 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 116 DISALLOW_COPY_AND_ASSIGN(ImageSpace); 117}; 118 119} // namespace space 120} // namespace gc 121} // namespace art 122 123#endif // ART_RUNTIME_GC_SPACE_IMAGE_SPACE_H_ 124