annotate src/share/vm/memory/memRegion.hpp @ 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 d2a62e0f25eb
children f9be75d21404
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_MEMORY_MEMREGION_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_MEMORY_MEMREGION_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "utilities/debug.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "utilities/globalDefinitions.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32 // A very simple data structure representing a contigous region
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // region of address space.
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Note that MemRegions are passed by value, not by reference.
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // The intent is that they remain very small and contain no
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // objects.
a61af66fc99e Initial load
duke
parents:
diff changeset
38
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
39 class MetaWord;
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
40
0
a61af66fc99e Initial load
duke
parents:
diff changeset
41 class MemRegion VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 friend class VMStructs;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
44 HeapWord* _start;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 size_t _word_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
48 MemRegion() : _start(NULL), _word_size(0) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
49 MemRegion(HeapWord* start, size_t word_size) :
a61af66fc99e Initial load
duke
parents:
diff changeset
50 _start(start), _word_size(word_size) {};
a61af66fc99e Initial load
duke
parents:
diff changeset
51 MemRegion(HeapWord* start, HeapWord* end) :
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _start(start), _word_size(pointer_delta(end, start)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 assert(end >= start, "incorrect constructor arguments");
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
55 MemRegion(MetaWord* start, MetaWord* end) :
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
56 _start((HeapWord*)start), _word_size(pointer_delta(end, start)) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
57 assert(end >= start, "incorrect constructor arguments");
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
58 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60 MemRegion(const MemRegion& mr): _start(mr._start), _word_size(mr._word_size) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 MemRegion intersection(const MemRegion mr2) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // regions must overlap or be adjacent
a61af66fc99e Initial load
duke
parents:
diff changeset
64 MemRegion _union(const MemRegion mr2) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // minus will fail a guarantee if mr2 is interior to this,
a61af66fc99e Initial load
duke
parents:
diff changeset
66 // since there's no way to return 2 disjoint regions.
a61af66fc99e Initial load
duke
parents:
diff changeset
67 MemRegion minus(const MemRegion mr2) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
68
a61af66fc99e Initial load
duke
parents:
diff changeset
69 HeapWord* start() const { return _start; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 HeapWord* end() const { return _start + _word_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 HeapWord* last() const { return _start + _word_size - 1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
72
a61af66fc99e Initial load
duke
parents:
diff changeset
73 void set_start(HeapWord* start) { _start = start; }
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void set_end(HeapWord* end) { _word_size = pointer_delta(end, _start); }
a61af66fc99e Initial load
duke
parents:
diff changeset
75 void set_word_size(size_t word_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
76 _word_size = word_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 bool contains(const MemRegion mr2) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return _start <= mr2._start && end() >= mr2.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 bool contains(const void* addr) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 return addr >= (void*)_start && addr < (void*)end();
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85 bool equals(const MemRegion mr2) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // first disjunct since we do not have a canonical empty set
a61af66fc99e Initial load
duke
parents:
diff changeset
87 return ((is_empty() && mr2.is_empty()) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
88 (start() == mr2.start() && end() == mr2.end()));
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 size_t byte_size() const { return _word_size * sizeof(HeapWord); }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 size_t word_size() const { return _word_size; }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
a61af66fc99e Initial load
duke
parents:
diff changeset
94 bool is_empty() const { return word_size() == 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
95 };
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // For iteration over MemRegion's.
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99 class MemRegionClosure : public StackObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
100 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
101 virtual void do_MemRegion(MemRegion mr) = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 };
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // A ResourceObj version of MemRegionClosure
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 class MemRegionClosureRO: public MemRegionClosure {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 public:
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
108 void* operator new(size_t size, ResourceObj::allocation_type type, MEMFLAGS flags) {
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
109 return ResourceObj::operator new(size, type, flags);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 void* operator new(size_t size, Arena *arena) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 return ResourceObj::operator new(size, arena);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 }
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void* operator new(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
115 return ResourceObj::operator new(size);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117
a61af66fc99e Initial load
duke
parents:
diff changeset
118 void operator delete(void* p) {} // nothing to do
a61af66fc99e Initial load
duke
parents:
diff changeset
119 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
120
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
121 #endif // SHARE_VM_MEMORY_MEMREGION_HPP