src/share/vm/memory/metaspace.hpp

Fri, 21 Feb 2014 10:01:20 +0100

author
stefank
date
Fri, 21 Feb 2014 10:01:20 +0100
changeset 6973
4af19b914f53
parent 6722
e204777ac770
child 6876
710a3c8b516e
child 7089
6e0cb14ce59b
permissions
-rw-r--r--

8035393: Use CLDClosure instead of CLDToOopClosure in frame::oops_interpreted_do
Reviewed-by: tschatzl, coleenp

coleenp@4037 1 /*
coleenp@6678 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
coleenp@4037 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
coleenp@4037 4 *
coleenp@4037 5 * This code is free software; you can redistribute it and/or modify it
coleenp@4037 6 * under the terms of the GNU General Public License version 2 only, as
coleenp@4037 7 * published by the Free Software Foundation.
coleenp@4037 8 *
coleenp@4037 9 * This code is distributed in the hope that it will be useful, but WITHOUT
coleenp@4037 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
coleenp@4037 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
coleenp@4037 12 * version 2 for more details (a copy is included in the LICENSE file that
coleenp@4037 13 * accompanied this code).
coleenp@4037 14 *
coleenp@4037 15 * You should have received a copy of the GNU General Public License version
coleenp@4037 16 * 2 along with this work; if not, write to the Free Software Foundation,
coleenp@4037 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
coleenp@4037 18 *
coleenp@4037 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
coleenp@4037 20 * or visit www.oracle.com if you need additional information or have any
coleenp@4037 21 * questions.
coleenp@4037 22 *
coleenp@4037 23 */
coleenp@4037 24 #ifndef SHARE_VM_MEMORY_METASPACE_HPP
coleenp@4037 25 #define SHARE_VM_MEMORY_METASPACE_HPP
coleenp@4037 26
coleenp@4037 27 #include "memory/allocation.hpp"
coleenp@4037 28 #include "memory/memRegion.hpp"
ehelin@6420 29 #include "memory/metaspaceChunkFreeListSummary.hpp"
coleenp@4037 30 #include "runtime/virtualspace.hpp"
coleenp@4037 31 #include "utilities/exceptions.hpp"
coleenp@4037 32
coleenp@4037 33 // Metaspace
coleenp@4037 34 //
coleenp@4037 35 // Metaspaces are Arenas for the VM's metadata.
coleenp@4037 36 // They are allocated one per class loader object, and one for the null
coleenp@4037 37 // bootstrap class loader
coleenp@4037 38 // Eventually for bootstrap loader we'll have a read-only section and read-write
coleenp@4037 39 // to write for DumpSharedSpaces and read for UseSharedSpaces
coleenp@4037 40 //
coleenp@4037 41 // block X ---+ +-------------------+
coleenp@4037 42 // | | Virtualspace |
coleenp@4037 43 // | | |
coleenp@4037 44 // | | |
coleenp@4037 45 // | |-------------------|
coleenp@4037 46 // | || Chunk |
coleenp@4037 47 // | || |
coleenp@4037 48 // | ||---------- |
coleenp@4037 49 // +------>||| block 0 | |
coleenp@4037 50 // ||---------- |
coleenp@4037 51 // ||| block 1 | |
coleenp@4037 52 // ||---------- |
coleenp@4037 53 // || |
coleenp@4037 54 // |-------------------|
coleenp@4037 55 // | |
coleenp@4037 56 // | |
coleenp@4037 57 // +-------------------+
coleenp@4037 58 //
coleenp@4037 59
stefank@5771 60 class ChunkManager;
coleenp@4037 61 class ClassLoaderData;
jmasa@4196 62 class Metablock;
stefank@5771 63 class Metachunk;
ehelin@6417 64 class MetaspaceTracer;
coleenp@4037 65 class MetaWord;
coleenp@4037 66 class Mutex;
coleenp@4037 67 class outputStream;
coleenp@4037 68 class SpaceManager;
stefank@5771 69 class VirtualSpaceList;
coleenp@4037 70
coleenp@4037 71 // Metaspaces each have a SpaceManager and allocations
coleenp@4037 72 // are done by the SpaceManager. Allocations are done
coleenp@4037 73 // out of the current Metachunk. When the current Metachunk
coleenp@4037 74 // is exhausted, the SpaceManager gets a new one from
coleenp@4037 75 // the current VirtualSpace. When the VirtualSpace is exhausted
coleenp@4037 76 // the SpaceManager gets a new one. The SpaceManager
coleenp@4037 77 // also manages freelists of available Chunks.
coleenp@4037 78 //
coleenp@4037 79 // Currently the space manager maintains the list of
coleenp@4037 80 // virtual spaces and the list of chunks in use. Its
coleenp@4037 81 // allocate() method returns a block for use as a
coleenp@4037 82 // quantum of metadata.
coleenp@4037 83
coleenp@4037 84 class Metaspace : public CHeapObj<mtClass> {
coleenp@4037 85 friend class VMStructs;
coleenp@4037 86 friend class SpaceManager;
coleenp@4037 87 friend class VM_CollectForMetadataAllocation;
coleenp@4037 88 friend class MetaspaceGC;
coleenp@4037 89 friend class MetaspaceAux;
coleenp@4037 90
coleenp@4037 91 public:
stefank@5863 92 enum MetadataType {
stefank@5863 93 ClassType,
stefank@5863 94 NonClassType,
stefank@5863 95 MetadataTypeCount
jmasa@5162 96 };
jmasa@4382 97 enum MetaspaceType {
jmasa@4382 98 StandardMetaspaceType,
jmasa@4382 99 BootMetaspaceType,
jmasa@4382 100 ROMetaspaceType,
jmasa@4382 101 ReadWriteMetaspaceType,
jmasa@4382 102 AnonymousMetaspaceType,
jmasa@4382 103 ReflectionMetaspaceType
jmasa@4382 104 };
coleenp@4037 105
coleenp@4037 106 private:
jmasa@4382 107 void initialize(Mutex* lock, MetaspaceType type);
jmasa@4382 108
stefank@5863 109 // Get the first chunk for a Metaspace. Used for
stefank@5863 110 // special cases such as the boot class loader, reflection
stefank@5863 111 // class loader and anonymous class loader.
stefank@5771 112 Metachunk* get_initialization_chunk(MetadataType mdtype,
stefank@5771 113 size_t chunk_word_size,
stefank@5771 114 size_t chunk_bunch);
stefank@5771 115
jmasa@4382 116 // Align up the word size to the allocation word size
jmasa@4382 117 static size_t align_word_size_up(size_t);
coleenp@4037 118
hseigel@5528 119 // Aligned size of the metaspace.
coleenp@6029 120 static size_t _compressed_class_space_size;
hseigel@5528 121
coleenp@6029 122 static size_t compressed_class_space_size() {
coleenp@6029 123 return _compressed_class_space_size;
hseigel@5528 124 }
goetz@6487 125
coleenp@6029 126 static void set_compressed_class_space_size(size_t size) {
coleenp@6029 127 _compressed_class_space_size = size;
hseigel@5528 128 }
hseigel@5528 129
coleenp@4037 130 static size_t _first_chunk_word_size;
jmasa@4382 131 static size_t _first_class_chunk_word_size;
coleenp@4037 132
stefank@5863 133 static size_t _commit_alignment;
stefank@5863 134 static size_t _reserve_alignment;
stefank@5863 135
coleenp@4037 136 SpaceManager* _vsm;
coleenp@4037 137 SpaceManager* vsm() const { return _vsm; }
coleenp@4037 138
coleenp@4037 139 SpaceManager* _class_vsm;
coleenp@4037 140 SpaceManager* class_vsm() const { return _class_vsm; }
coleenp@4037 141
jmasa@5015 142 // Allocate space for metadata of type mdtype. This is space
jmasa@5015 143 // within a Metachunk and is used by
jmasa@5015 144 // allocate(ClassLoaderData*, size_t, bool, MetadataType, TRAPS)
coleenp@4037 145 MetaWord* allocate(size_t word_size, MetadataType mdtype);
coleenp@4037 146
coleenp@4037 147 // Virtual Space lists for both classes and other metadata
coleenp@4037 148 static VirtualSpaceList* _space_list;
coleenp@4037 149 static VirtualSpaceList* _class_space_list;
coleenp@4037 150
stefank@5771 151 static ChunkManager* _chunk_manager_metadata;
stefank@5771 152 static ChunkManager* _chunk_manager_class;
stefank@5771 153
ehelin@6417 154 static const MetaspaceTracer* _tracer;
ehelin@6417 155
stefank@5771 156 public:
coleenp@4037 157 static VirtualSpaceList* space_list() { return _space_list; }
coleenp@4037 158 static VirtualSpaceList* class_space_list() { return _class_space_list; }
ehelin@5531 159 static VirtualSpaceList* get_space_list(MetadataType mdtype) {
ehelin@5531 160 assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
ehelin@5531 161 return mdtype == ClassType ? class_space_list() : space_list();
ehelin@5531 162 }
coleenp@4037 163
stefank@5771 164 static ChunkManager* chunk_manager_metadata() { return _chunk_manager_metadata; }
stefank@5771 165 static ChunkManager* chunk_manager_class() { return _chunk_manager_class; }
stefank@5771 166 static ChunkManager* get_chunk_manager(MetadataType mdtype) {
stefank@5771 167 assert(mdtype != MetadataTypeCount, "MetadaTypeCount can't be used as mdtype");
stefank@5771 168 return mdtype == ClassType ? chunk_manager_class() : chunk_manager_metadata();
stefank@5771 169 }
stefank@5771 170
ehelin@6417 171 static const MetaspaceTracer* tracer() { return _tracer; }
ehelin@6417 172
stefank@5771 173 private:
iklam@5208 174 // This is used by DumpSharedSpaces only, where only _vsm is used. So we will
iklam@5208 175 // maintain a single list for now.
iklam@5208 176 void record_allocation(void* ptr, MetaspaceObj::Type type, size_t word_size);
iklam@5208 177
hseigel@5528 178 #ifdef _LP64
hseigel@5528 179 static void set_narrow_klass_base_and_shift(address metaspace_base, address cds_base);
hseigel@5528 180
hseigel@5528 181 // Returns true if can use CDS with metaspace allocated as specified address.
hseigel@5528 182 static bool can_use_cds_with_metaspace_addr(char* metaspace_base, address cds_base);
hseigel@5528 183
hseigel@5528 184 static void allocate_metaspace_compressed_klass_ptrs(char* requested_addr, address cds_base);
hseigel@5528 185
hseigel@5528 186 static void initialize_class_space(ReservedSpace rs);
hseigel@5528 187 #endif
hseigel@5528 188
iklam@5208 189 class AllocRecord : public CHeapObj<mtClass> {
iklam@5208 190 public:
iklam@5208 191 AllocRecord(address ptr, MetaspaceObj::Type type, int byte_size)
iklam@5208 192 : _next(NULL), _ptr(ptr), _type(type), _byte_size(byte_size) {}
iklam@5208 193 AllocRecord *_next;
iklam@5208 194 address _ptr;
iklam@5208 195 MetaspaceObj::Type _type;
iklam@5208 196 int _byte_size;
iklam@5208 197 };
iklam@5208 198
iklam@5208 199 AllocRecord * _alloc_record_head;
iklam@5208 200 AllocRecord * _alloc_record_tail;
iklam@5208 201
hseigel@6027 202 size_t class_chunk_size(size_t word_size);
hseigel@6027 203
coleenp@4037 204 public:
coleenp@4037 205
jmasa@4382 206 Metaspace(Mutex* lock, MetaspaceType type);
coleenp@4037 207 ~Metaspace();
coleenp@4037 208
stefank@5863 209 static void ergo_initialize();
coleenp@4037 210 static void global_initialize();
ehelin@6722 211 static void post_initialize();
coleenp@4037 212
coleenp@4037 213 static size_t first_chunk_word_size() { return _first_chunk_word_size; }
jmasa@4382 214 static size_t first_class_chunk_word_size() { return _first_class_chunk_word_size; }
coleenp@4037 215
stefank@5863 216 static size_t reserve_alignment() { return _reserve_alignment; }
stefank@5863 217 static size_t reserve_alignment_words() { return _reserve_alignment / BytesPerWord; }
stefank@5863 218 static size_t commit_alignment() { return _commit_alignment; }
stefank@5863 219 static size_t commit_alignment_words() { return _commit_alignment / BytesPerWord; }
stefank@5863 220
coleenp@4037 221 char* bottom() const;
jmasa@5015 222 size_t used_words_slow(MetadataType mdtype) const;
ehelin@5703 223 size_t free_words_slow(MetadataType mdtype) const;
jmasa@5015 224 size_t capacity_words_slow(MetadataType mdtype) const;
coleenp@4037 225
jmasa@5015 226 size_t used_bytes_slow(MetadataType mdtype) const;
jmasa@5015 227 size_t capacity_bytes_slow(MetadataType mdtype) const;
jmasa@5015 228
stefank@5941 229 static MetaWord* allocate(ClassLoaderData* loader_data, size_t word_size,
stefank@5941 230 bool read_only, MetaspaceObj::Type type, TRAPS);
jmasa@4064 231 void deallocate(MetaWord* ptr, size_t byte_size, bool is_class);
coleenp@4037 232
jmasa@4064 233 MetaWord* expand_and_allocate(size_t size,
jmasa@4064 234 MetadataType mdtype);
coleenp@4037 235
coleenp@6678 236 static bool contains(const void* ptr);
coleenp@6678 237
coleenp@4037 238 void dump(outputStream* const out) const;
coleenp@4037 239
jmasa@5007 240 // Free empty virtualspaces
stefank@5771 241 static void purge(MetadataType mdtype);
jmasa@5007 242 static void purge();
jmasa@5007 243
stefank@5863 244 static void report_metadata_oome(ClassLoaderData* loader_data, size_t word_size,
ehelin@6419 245 MetaspaceObj::Type type, MetadataType mdtype, TRAPS);
stefank@5863 246
ehelin@6418 247 static const char* metadata_type_name(Metaspace::MetadataType mdtype);
ehelin@6418 248
coleenp@4037 249 void print_on(outputStream* st) const;
coleenp@4037 250 // Debugging support
coleenp@4037 251 void verify();
iklam@5208 252
iklam@5208 253 class AllocRecordClosure : public StackObj {
iklam@5208 254 public:
iklam@5208 255 virtual void doit(address ptr, MetaspaceObj::Type type, int byte_size) = 0;
iklam@5208 256 };
iklam@5208 257
iklam@5208 258 void iterate(AllocRecordClosure *closure);
hseigel@5528 259
ehelin@5694 260 // Return TRUE only if UseCompressedClassPointers is True and DumpSharedSpaces is False.
hseigel@5528 261 static bool using_class_space() {
ehelin@5694 262 return NOT_LP64(false) LP64_ONLY(UseCompressedClassPointers && !DumpSharedSpaces);
hseigel@5528 263 }
hseigel@5528 264
mgerdin@5808 265 static bool is_class_space_allocation(MetadataType mdType) {
mgerdin@5808 266 return mdType == ClassType && using_class_space();
mgerdin@5808 267 }
hseigel@6027 268
coleenp@4037 269 };
coleenp@4037 270
coleenp@4037 271 class MetaspaceAux : AllStatic {
ehelin@5703 272 static size_t free_chunks_total_words(Metaspace::MetadataType mdtype);
jmasa@5015 273
jmasa@5015 274 // These methods iterate over the classloader data graph
jmasa@5015 275 // for the given Metaspace type. These are slow.
jmasa@5015 276 static size_t used_bytes_slow(Metaspace::MetadataType mdtype);
ehelin@5703 277 static size_t free_bytes_slow(Metaspace::MetadataType mdtype);
jmasa@5015 278 static size_t capacity_bytes_slow(Metaspace::MetadataType mdtype);
ehelin@5703 279 static size_t capacity_bytes_slow();
coleenp@4037 280
jmasa@5015 281 // Running sum of space in all Metachunks that has been
jmasa@5015 282 // allocated to a Metaspace. This is used instead of
jmasa@5162 283 // iterating over all the classloaders. One for each
jmasa@5162 284 // type of Metadata
ehelin@6609 285 static size_t _capacity_words[Metaspace:: MetadataTypeCount];
ehelin@6609 286 // Running sum of space in all Metachunks that
jmasa@5162 287 // are being used for metadata. One for each
jmasa@5162 288 // type of Metadata.
ehelin@6609 289 static size_t _used_words[Metaspace:: MetadataTypeCount];
jmasa@5015 290
jmasa@5015 291 public:
jmasa@5015 292 // Decrement and increment _allocated_capacity_words
jmasa@5162 293 static void dec_capacity(Metaspace::MetadataType type, size_t words);
jmasa@5162 294 static void inc_capacity(Metaspace::MetadataType type, size_t words);
jmasa@5015 295
jmasa@5015 296 // Decrement and increment _allocated_used_words
jmasa@5162 297 static void dec_used(Metaspace::MetadataType type, size_t words);
jmasa@5162 298 static void inc_used(Metaspace::MetadataType type, size_t words);
jmasa@5015 299
jmasa@5015 300 // Total of space allocated to metadata in all Metaspaces.
jmasa@5015 301 // This sums the space used in each Metachunk by
jmasa@5015 302 // iterating over the classloader data graph
jmasa@5015 303 static size_t used_bytes_slow() {
jmasa@5015 304 return used_bytes_slow(Metaspace::ClassType) +
jmasa@5015 305 used_bytes_slow(Metaspace::NonClassType);
stefank@4371 306 }
coleenp@4037 307
jmasa@5015 308 // Used by MetaspaceCounters
ehelin@5703 309 static size_t free_chunks_total_words();
ehelin@5703 310 static size_t free_chunks_total_bytes();
ehelin@5703 311 static size_t free_chunks_total_bytes(Metaspace::MetadataType mdtype);
jmasa@5015 312
ehelin@6609 313 static size_t capacity_words(Metaspace::MetadataType mdtype) {
ehelin@6609 314 return _capacity_words[mdtype];
jmasa@5162 315 }
ehelin@6609 316 static size_t capacity_words() {
ehelin@6609 317 return capacity_words(Metaspace::NonClassType) +
ehelin@6609 318 capacity_words(Metaspace::ClassType);
jmasa@5162 319 }
ehelin@6609 320 static size_t capacity_bytes(Metaspace::MetadataType mdtype) {
ehelin@6609 321 return capacity_words(mdtype) * BytesPerWord;
jmasa@5015 322 }
ehelin@6609 323 static size_t capacity_bytes() {
ehelin@6609 324 return capacity_words() * BytesPerWord;
jmasa@5015 325 }
jmasa@5015 326
ehelin@6609 327 static size_t used_words(Metaspace::MetadataType mdtype) {
ehelin@6609 328 return _used_words[mdtype];
jmasa@5162 329 }
ehelin@6609 330 static size_t used_words() {
ehelin@6609 331 return used_words(Metaspace::NonClassType) +
ehelin@6609 332 used_words(Metaspace::ClassType);
jmasa@5162 333 }
ehelin@6609 334 static size_t used_bytes(Metaspace::MetadataType mdtype) {
ehelin@6609 335 return used_words(mdtype) * BytesPerWord;
jmasa@5015 336 }
ehelin@6609 337 static size_t used_bytes() {
ehelin@6609 338 return used_words() * BytesPerWord;
jmasa@5015 339 }
jmasa@5015 340
jmasa@5015 341 static size_t free_bytes();
ehelin@5531 342 static size_t free_bytes(Metaspace::MetadataType mdtype);
jmasa@5015 343
ehelin@5703 344 static size_t reserved_bytes(Metaspace::MetadataType mdtype);
ehelin@5703 345 static size_t reserved_bytes() {
ehelin@5703 346 return reserved_bytes(Metaspace::ClassType) +
ehelin@5703 347 reserved_bytes(Metaspace::NonClassType);
stefank@4371 348 }
coleenp@4037 349
stefank@5704 350 static size_t committed_bytes(Metaspace::MetadataType mdtype);
stefank@5704 351 static size_t committed_bytes() {
stefank@5704 352 return committed_bytes(Metaspace::ClassType) +
stefank@5704 353 committed_bytes(Metaspace::NonClassType);
stefank@5704 354 }
stefank@5704 355
ehelin@5703 356 static size_t min_chunk_size_words();
ehelin@5703 357 static size_t min_chunk_size_bytes() {
ehelin@5703 358 return min_chunk_size_words() * BytesPerWord;
stefank@4371 359 }
coleenp@4037 360
ehelin@6420 361 static bool has_chunk_free_list(Metaspace::MetadataType mdtype);
ehelin@6420 362 static MetaspaceChunkFreeListSummary chunk_free_list_summary(Metaspace::MetadataType mdtype);
ehelin@6420 363
coleenp@4037 364 // Print change in used metadata.
coleenp@4037 365 static void print_metaspace_change(size_t prev_metadata_used);
coleenp@4037 366 static void print_on(outputStream * out);
coleenp@4037 367 static void print_on(outputStream * out, Metaspace::MetadataType mdtype);
coleenp@4037 368
hseigel@5528 369 static void print_class_waste(outputStream* out);
coleenp@4037 370 static void print_waste(outputStream* out);
coleenp@4037 371 static void dump(outputStream* out);
mgerdin@4264 372 static void verify_free_chunks();
jmasa@5015 373 // Checks that the values returned by allocated_capacity_bytes() and
jmasa@5015 374 // capacity_bytes_slow() are the same.
jmasa@5015 375 static void verify_capacity();
jmasa@5015 376 static void verify_used();
jmasa@5015 377 static void verify_metrics();
coleenp@4037 378 };
coleenp@4037 379
coleenp@4037 380 // Metaspace are deallocated when their class loader are GC'ed.
coleenp@4037 381 // This class implements a policy for inducing GC's to recover
coleenp@4037 382 // Metaspaces.
coleenp@4037 383
coleenp@4037 384 class MetaspaceGC : AllStatic {
coleenp@4037 385
stefank@5863 386 // The current high-water-mark for inducing a GC.
stefank@5863 387 // When committed memory of all metaspaces reaches this value,
stefank@5863 388 // a GC is induced and the value is increased. Size is in bytes.
stefank@5863 389 static volatile intptr_t _capacity_until_GC;
coleenp@4037 390
coleenp@4037 391 // For a CMS collection, signal that a concurrent collection should
coleenp@4037 392 // be started.
coleenp@4037 393 static bool _should_concurrent_collect;
coleenp@4037 394
coleenp@4037 395 static uint _shrink_factor;
coleenp@4037 396
coleenp@4037 397 static size_t shrink_factor() { return _shrink_factor; }
coleenp@4037 398 void set_shrink_factor(uint v) { _shrink_factor = v; }
coleenp@4037 399
coleenp@4037 400 public:
coleenp@4037 401
ehelin@6722 402 static void initialize();
ehelin@6722 403 static void post_initialize();
stefank@5863 404
stefank@5863 405 static size_t capacity_until_GC();
stefank@5863 406 static size_t inc_capacity_until_GC(size_t v);
stefank@5863 407 static size_t dec_capacity_until_GC(size_t v);
coleenp@4037 408
coleenp@4037 409 static bool should_concurrent_collect() { return _should_concurrent_collect; }
coleenp@4037 410 static void set_should_concurrent_collect(bool v) {
coleenp@4037 411 _should_concurrent_collect = v;
coleenp@4037 412 }
coleenp@4037 413
coleenp@4037 414 // The amount to increase the high-water-mark (_capacity_until_GC)
stefank@5863 415 static size_t delta_capacity_until_GC(size_t bytes);
coleenp@4037 416
stefank@5863 417 // Tells if we have can expand metaspace without hitting set limits.
stefank@5863 418 static bool can_expand(size_t words, bool is_class);
stefank@5863 419
stefank@5863 420 // Returns amount that we can expand without hitting a GC,
stefank@5863 421 // measured in words.
stefank@5863 422 static size_t allowed_expansion();
coleenp@4037 423
coleenp@4037 424 // Calculate the new high-water mark at which to induce
coleenp@4037 425 // a GC.
coleenp@4037 426 static void compute_new_size();
coleenp@4037 427 };
coleenp@4037 428
coleenp@4037 429 #endif // SHARE_VM_MEMORY_METASPACE_HPP

mercurial