1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/memory/compactingPermGenGen.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,248 @@ 1.4 +/* 1.5 + * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// All heaps contains a "permanent generation," containing permanent 1.29 +// (reflective) objects. This is like a regular generation in some ways, 1.30 +// but unlike one in others, and so is split apart. 1.31 + 1.32 +class PermanentGenerationSpec; 1.33 + 1.34 +// This is the "generation" view of a CompactingPermGen. 1.35 +class CompactingPermGenGen: public OneContigSpaceCardGeneration { 1.36 + friend class VMStructs; 1.37 + // Abstractly, this is a subtype that gets access to protected fields. 1.38 + friend class CompactingPermGen; 1.39 + 1.40 +private: 1.41 + // Shared spaces 1.42 + PermanentGenerationSpec* _spec; 1.43 + size_t _shared_space_size; 1.44 + VirtualSpace _ro_vs; 1.45 + VirtualSpace _rw_vs; 1.46 + VirtualSpace _md_vs; 1.47 + VirtualSpace _mc_vs; 1.48 + BlockOffsetSharedArray* _ro_bts; 1.49 + BlockOffsetSharedArray* _rw_bts; 1.50 + OffsetTableContigSpace* _ro_space; 1.51 + OffsetTableContigSpace* _rw_space; 1.52 + 1.53 + // With shared spaces there is a dicotomy in the use of the 1.54 + // _virtual_space of the generation. There is a portion of the 1.55 + // _virtual_space that is used for the unshared part of the 1.56 + // permanent generation and a portion that is reserved for the shared part. 1.57 + // The _reserved field in the generation represents both the 1.58 + // unshared and shared parts of the generation. The _reserved 1.59 + // variable is initialized for only the unshared part but is 1.60 + // later extended to include the shared part during initialization 1.61 + // if shared spaces are being used. 1.62 + // The reserved size for the _virtual_space for CompactingPermGenGen 1.63 + // is the size of the space for the permanent generation including the 1.64 + // the shared spaces. This can be seen by the use of MaxPermSize 1.65 + // in the allocation of PermanentGenerationSpec. The space for the 1.66 + // shared spaces is committed separately (???). 1.67 + // In general at initialization only a part of the 1.68 + // space for the unshared part of the permanent generation is 1.69 + // committed and more is committed as the permanent generation is 1.70 + // grown. In growing the permanent generation the capacity() and 1.71 + // max_capacity() of the generation are used. For the permanent 1.72 + // generation (implemented with a CompactingPermGenGen) the capacity() 1.73 + // is taken from the capacity of the space (_the_space variable used for the 1.74 + // unshared part of the generation) and the max_capacity() is based 1.75 + // on the size of the _reserved variable (which includes the size of the 1.76 + // shared spaces) minus the size of the shared spaces. 1.77 + 1.78 + // These values are redundant, but are called out separately to avoid 1.79 + // going through heap/space/gen pointers for performance. 1.80 + static HeapWord* unshared_bottom; 1.81 + static HeapWord* unshared_end; 1.82 + static HeapWord* shared_bottom; 1.83 + static HeapWord* readonly_bottom; 1.84 + static HeapWord* readonly_end; 1.85 + static HeapWord* readwrite_bottom; 1.86 + static HeapWord* readwrite_end; 1.87 + static HeapWord* miscdata_bottom; 1.88 + static HeapWord* miscdata_end; 1.89 + static HeapWord* misccode_bottom; 1.90 + static HeapWord* misccode_end; 1.91 + static HeapWord* shared_end; 1.92 + 1.93 + // List of klassOops whose vtbl entries are used to patch others. 1.94 + static void** _vtbl_list; 1.95 + 1.96 + // Performance Counters 1.97 + GenerationCounters* _gen_counters; 1.98 + CSpaceCounters* _space_counters; 1.99 + 1.100 + void initialize_performance_counters(); 1.101 + 1.102 +public: 1.103 + 1.104 + enum { 1.105 + vtbl_list_size = 16, // number of entries in the shared space vtable list. 1.106 + num_virtuals = 100 // number of virtual methods in Klass (or 1.107 + // subclass) objects, or greater. 1.108 + }; 1.109 + 1.110 + enum { 1.111 + ro = 0, // read-only shared space in the heap 1.112 + rw = 1, // read-write shared space in the heap 1.113 + md = 2, // miscellaneous data for initializing tables, etc. 1.114 + mc = 3, // miscellaneous code - vtable replacement. 1.115 + n_regions = 4 1.116 + }; 1.117 + 1.118 + CompactingPermGenGen(ReservedSpace rs, ReservedSpace shared_rs, 1.119 + size_t initial_byte_size, int level, GenRemSet* remset, 1.120 + ContiguousSpace* space, 1.121 + PermanentGenerationSpec* perm_spec); 1.122 + 1.123 + const char* name() const { 1.124 + return "compacting perm gen"; 1.125 + } 1.126 + 1.127 + const char* short_name() const { 1.128 + return "Perm"; 1.129 + } 1.130 + 1.131 + // Return the maximum capacity for the object space. This 1.132 + // explicitly does not include the shared spaces. 1.133 + size_t max_capacity() const; 1.134 + 1.135 + void update_counters(); 1.136 + 1.137 + void compute_new_size() { 1.138 + assert(false, "Should not call this -- handled at PermGen level."); 1.139 + } 1.140 + 1.141 + bool must_be_youngest() const { return false; } 1.142 + bool must_be_oldest() const { return false; } 1.143 + 1.144 + OffsetTableContigSpace* ro_space() const { return _ro_space; } 1.145 + OffsetTableContigSpace* rw_space() const { return _rw_space; } 1.146 + VirtualSpace* md_space() { return &_md_vs; } 1.147 + VirtualSpace* mc_space() { return &_mc_vs; } 1.148 + ContiguousSpace* unshared_space() const { return _the_space; } 1.149 + 1.150 + static bool inline is_shared(const oopDesc* p) { 1.151 + return (HeapWord*)p >= shared_bottom && (HeapWord*)p < shared_end; 1.152 + } 1.153 + // RedefineClasses note: this tester is used to check residence of 1.154 + // the specified oop in the shared readonly space and not whether 1.155 + // the oop is readonly. 1.156 + static bool inline is_shared_readonly(const oopDesc* p) { 1.157 + return (HeapWord*)p >= readonly_bottom && (HeapWord*)p < readonly_end; 1.158 + } 1.159 + // RedefineClasses note: this tester is used to check residence of 1.160 + // the specified oop in the shared readwrite space and not whether 1.161 + // the oop is readwrite. 1.162 + static bool inline is_shared_readwrite(const oopDesc* p) { 1.163 + return (HeapWord*)p >= readwrite_bottom && (HeapWord*)p < readwrite_end; 1.164 + } 1.165 + 1.166 + bool is_in_unshared(const void* p) const { 1.167 + return OneContigSpaceCardGeneration::is_in(p); 1.168 + } 1.169 + 1.170 + bool is_in_shared(const void* p) const { 1.171 + return p >= shared_bottom && p < shared_end; 1.172 + } 1.173 + 1.174 + inline bool is_in(const void* p) const { 1.175 + return is_in_unshared(p) || is_in_shared(p); 1.176 + } 1.177 + 1.178 + inline PermanentGenerationSpec* spec() const { return _spec; } 1.179 + inline void set_spec(PermanentGenerationSpec* spec) { _spec = spec; } 1.180 + 1.181 + void pre_adjust_pointers(); 1.182 + void adjust_pointers(); 1.183 + void space_iterate(SpaceClosure* blk, bool usedOnly = false); 1.184 + void print_on(outputStream* st) const; 1.185 + void younger_refs_iterate(OopsInGenClosure* blk); 1.186 + void compact(); 1.187 + void post_compact(); 1.188 + size_t contiguous_available() const; 1.189 + bool grow_by(size_t bytes); 1.190 + void grow_to_reserved(); 1.191 + 1.192 + void clear_remembered_set(); 1.193 + void invalidate_remembered_set(); 1.194 + 1.195 + inline bool block_is_obj(const HeapWord* addr) const { 1.196 + if (addr < the_space()->top()) return true; 1.197 + else if (addr < the_space()->end()) return false; 1.198 + else if (addr < ro_space()->top()) return true; 1.199 + else if (addr < ro_space()->end()) return false; 1.200 + else if (addr < rw_space()->top()) return true; 1.201 + else return false; 1.202 + } 1.203 + 1.204 + 1.205 + inline size_t block_size(const HeapWord* addr) const { 1.206 + if (addr < the_space()->top()) { 1.207 + return oop(addr)->size(); 1.208 + } 1.209 + else if (addr < the_space()->end()) { 1.210 + assert(addr == the_space()->top(), "non-block head arg to block_size"); 1.211 + return the_space()->end() - the_space()->top(); 1.212 + } 1.213 + 1.214 + else if (addr < ro_space()->top()) { 1.215 + return oop(addr)->size(); 1.216 + } 1.217 + else if (addr < ro_space()->end()) { 1.218 + assert(addr == ro_space()->top(), "non-block head arg to block_size"); 1.219 + return ro_space()->end() - ro_space()->top(); 1.220 + } 1.221 + 1.222 + else if (addr < rw_space()->top()) { 1.223 + return oop(addr)->size(); 1.224 + } 1.225 + else { 1.226 + assert(addr == rw_space()->top(), "non-block head arg to block_size"); 1.227 + return rw_space()->end() - rw_space()->top(); 1.228 + } 1.229 + } 1.230 + 1.231 + static void generate_vtable_methods(void** vtbl_list, 1.232 + void** vtable, 1.233 + char** md_top, char* md_end, 1.234 + char** mc_top, char* mc_end); 1.235 + 1.236 + void verify(bool allow_dirty); 1.237 + 1.238 + // Serialization 1.239 + static void initialize_oops() KERNEL_RETURN; 1.240 + static void serialize_oops(SerializeOopClosure* soc); 1.241 + void serialize_bts(SerializeOopClosure* soc); 1.242 + 1.243 + // Initiate dumping of shared file. 1.244 + static jint dump_shared(GrowableArray<oop>* class_promote_order, TRAPS); 1.245 + 1.246 + // JVM/TI RedefineClasses() support: 1.247 + // Remap the shared readonly space to shared readwrite, private if 1.248 + // sharing is enabled. Simply returns true if sharing is not enabled 1.249 + // or if the remapping has already been done by a prior call. 1.250 + static bool remap_shared_readonly_as_readwrite(); 1.251 +};