comparison src/share/vm/memory/collectorPolicy.cpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents f08d439fab8c
children 8da5e203b993
comparison
equal deleted inserted replaced
6724:36d1d483d5d6 6725:da91efe96a93
1 /* 1 /*
2 * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
56 #endif 56 #endif
57 57
58 // CollectorPolicy methods. 58 // CollectorPolicy methods.
59 59
60 void CollectorPolicy::initialize_flags() { 60 void CollectorPolicy::initialize_flags() {
61 if (PermSize > MaxPermSize) { 61 if (MetaspaceSize > MaxMetaspaceSize) {
62 MaxPermSize = PermSize; 62 MaxMetaspaceSize = MetaspaceSize;
63 } 63 }
64 PermSize = MAX2(min_alignment(), align_size_down_(PermSize, min_alignment())); 64 MetaspaceSize = MAX2(min_alignment(), align_size_down_(MetaspaceSize, min_alignment()));
65 // Don't increase Perm size limit above specified. 65 // Don't increase Metaspace size limit above specified.
66 MaxPermSize = align_size_down(MaxPermSize, max_alignment()); 66 MaxMetaspaceSize = align_size_down(MaxMetaspaceSize, max_alignment());
67 if (PermSize > MaxPermSize) { 67 if (MetaspaceSize > MaxMetaspaceSize) {
68 PermSize = MaxPermSize; 68 MetaspaceSize = MaxMetaspaceSize;
69 } 69 }
70 70
71 MinPermHeapExpansion = MAX2(min_alignment(), align_size_down_(MinPermHeapExpansion, min_alignment())); 71 MinMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MinMetaspaceExpansion, min_alignment()));
72 MaxPermHeapExpansion = MAX2(min_alignment(), align_size_down_(MaxPermHeapExpansion, min_alignment())); 72 MaxMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MaxMetaspaceExpansion, min_alignment()));
73 73
74 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment()); 74 MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment());
75 75
76 SharedReadOnlySize = align_size_up(SharedReadOnlySize, max_alignment()); 76 assert(MetaspaceSize % min_alignment() == 0, "metapace alignment");
77 SharedReadWriteSize = align_size_up(SharedReadWriteSize, max_alignment()); 77 assert(MaxMetaspaceSize % max_alignment() == 0, "maximum metaspace alignment");
78 SharedMiscDataSize = align_size_up(SharedMiscDataSize, max_alignment()); 78 if (MetaspaceSize < 256*K) {
79 79 vm_exit_during_initialization("Too small initial Metaspace size");
80 assert(PermSize % min_alignment() == 0, "permanent space alignment");
81 assert(MaxPermSize % max_alignment() == 0, "maximum permanent space alignment");
82 assert(SharedReadOnlySize % max_alignment() == 0, "read-only space alignment");
83 assert(SharedReadWriteSize % max_alignment() == 0, "read-write space alignment");
84 assert(SharedMiscDataSize % max_alignment() == 0, "misc-data space alignment");
85 if (PermSize < M) {
86 vm_exit_during_initialization("Too small initial permanent heap");
87 } 80 }
88 } 81 }
89 82
90 void CollectorPolicy::initialize_size_info() { 83 void CollectorPolicy::initialize_size_info() {
91 // User inputs from -mx and ms are aligned 84 // User inputs from -mx and ms are aligned
129 122
130 if (PrintGCDetails && Verbose) { 123 if (PrintGCDetails && Verbose) {
131 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " 124 gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap "
132 SIZE_FORMAT " Maximum heap " SIZE_FORMAT, 125 SIZE_FORMAT " Maximum heap " SIZE_FORMAT,
133 min_heap_byte_size(), initial_heap_byte_size(), max_heap_byte_size()); 126 min_heap_byte_size(), initial_heap_byte_size(), max_heap_byte_size());
134 }
135 }
136
137 void CollectorPolicy::initialize_perm_generation(PermGen::Name pgnm) {
138 _permanent_generation =
139 new PermanentGenerationSpec(pgnm, PermSize, MaxPermSize,
140 SharedReadOnlySize,
141 SharedReadWriteSize,
142 SharedMiscDataSize,
143 SharedMiscCodeSize);
144 if (_permanent_generation == NULL) {
145 vm_exit_during_initialization("Unable to allocate gen spec");
146 } 127 }
147 } 128 }
148 129
149 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) { 130 bool CollectorPolicy::use_should_clear_all_soft_refs(bool v) {
150 bool result = _should_clear_all_soft_refs; 131 bool result = _should_clear_all_soft_refs;
751 // complete compaction phase than we've tried so far might be 732 // complete compaction phase than we've tried so far might be
752 // appropriate. 733 // appropriate.
753 return NULL; 734 return NULL;
754 } 735 }
755 736
737 MetaWord* CollectorPolicy::satisfy_failed_metadata_allocation(
738 ClassLoaderData* loader_data,
739 size_t word_size,
740 Metaspace::MetadataType mdtype) {
741 uint loop_count = 0;
742 uint gc_count = 0;
743 uint full_gc_count = 0;
744
745 do {
746 { // Need lock to get self consistent gc_count's
747 MutexLocker ml(Heap_lock);
748 gc_count = Universe::heap()->total_collections();
749 full_gc_count = Universe::heap()->total_full_collections();
750 }
751
752 // Generate a VM operation
753 VM_CollectForMetadataAllocation op(loader_data,
754 word_size,
755 mdtype,
756 gc_count,
757 full_gc_count,
758 GCCause::_metadata_GC_threshold);
759 VMThread::execute(&op);
760 if (op.prologue_succeeded()) {
761 return op.result();
762 }
763 loop_count++;
764 if ((QueuedAllocationWarningCount > 0) &&
765 (loop_count % QueuedAllocationWarningCount == 0)) {
766 warning("satisfy_failed_metadata_allocation() retries %d times \n\t"
767 " size=%d", loop_count, word_size);
768 }
769 } while (true); // Until a GC is done
770 }
771
756 // Return true if any of the following is true: 772 // Return true if any of the following is true:
757 // . the allocation won't fit into the current young gen heap 773 // . the allocation won't fit into the current young gen heap
758 // . gc locker is occupied (jni critical section) 774 // . gc locker is occupied (jni critical section)
759 // . heap memory is tight -- the most recent previous collection 775 // . heap memory is tight -- the most recent previous collection
760 // was a full collection because a partial collection (would 776 // was a full collection because a partial collection (would
776 MarkSweepPolicy::MarkSweepPolicy() { 792 MarkSweepPolicy::MarkSweepPolicy() {
777 initialize_all(); 793 initialize_all();
778 } 794 }
779 795
780 void MarkSweepPolicy::initialize_generations() { 796 void MarkSweepPolicy::initialize_generations() {
781 initialize_perm_generation(PermGen::MarkSweepCompact);
782 _generations = new GenerationSpecPtr[number_of_generations()]; 797 _generations = new GenerationSpecPtr[number_of_generations()];
783 if (_generations == NULL) 798 if (_generations == NULL)
784 vm_exit_during_initialization("Unable to allocate gen spec"); 799 vm_exit_during_initialization("Unable to allocate gen spec");
785 800
786 if (UseParNewGC && ParallelGCThreads > 0) { 801 if (UseParNewGC && ParallelGCThreads > 0) {