author | ehelin |
Fri, 22 Mar 2013 16:10:01 +0100 | |
changeset 16451 | 2f68393e1bef |
parent 15086 | 2bfd799e9147 |
child 17101 | 3a82a58d9aa9 |
permissions | -rw-r--r-- |
14123 | 1 |
/* |
2 |
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
#ifndef SHARE_VM_MEMORY_METACHUNK_HPP |
|
25 |
#define SHARE_VM_MEMORY_METACHUNK_HPP |
|
26 |
||
27 |
// Metachunk - Quantum of allocation from a Virtualspace |
|
28 |
// Metachunks are reused (when freed are put on a global freelist) and |
|
29 |
// have no permanent association to a SpaceManager. |
|
30 |
||
31 |
// +--------------+ <- end |
|
32 |
// | | --+ ---+ |
|
33 |
// | | | free | |
|
34 |
// | | | | |
|
35 |
// | | | | capacity |
|
36 |
// | | | | |
|
37 |
// | | <- top --+ | |
|
38 |
// | | ---+ | |
|
39 |
// | | | used | |
|
40 |
// | | | | |
|
41 |
// | | | | |
|
42 |
// +--------------+ <- bottom ---+ ---+ |
|
43 |
||
44 |
class Metachunk VALUE_OBJ_CLASS_SPEC { |
|
45 |
// link to support lists of chunks |
|
46 |
Metachunk* _next; |
|
47 |
Metachunk* _prev; |
|
48 |
||
49 |
MetaWord* _bottom; |
|
50 |
MetaWord* _end; |
|
51 |
MetaWord* _top; |
|
52 |
size_t _word_size; |
|
53 |
// Used in a guarantee() so included in the Product builds |
|
54 |
// even through it is only for debugging. |
|
55 |
bool _is_free; |
|
56 |
||
57 |
// Metachunks are allocated out of a MetadataVirtualSpace and |
|
58 |
// and use some of its space to describe itself (plus alignment |
|
59 |
// considerations). Metadata is allocated in the rest of the chunk. |
|
60 |
// This size is the overhead of maintaining the Metachunk within |
|
61 |
// the space. |
|
62 |
static size_t _overhead; |
|
63 |
||
64 |
void set_bottom(MetaWord* v) { _bottom = v; } |
|
65 |
void set_end(MetaWord* v) { _end = v; } |
|
66 |
void set_top(MetaWord* v) { _top = v; } |
|
67 |
void set_word_size(size_t v) { _word_size = v; } |
|
68 |
public: |
|
69 |
#ifdef ASSERT |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
70 |
Metachunk() : _bottom(NULL), _end(NULL), _top(NULL), _is_free(false), |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
71 |
_next(NULL), _prev(NULL) {} |
14123 | 72 |
#else |
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
73 |
Metachunk() : _bottom(NULL), _end(NULL), _top(NULL), |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
74 |
_next(NULL), _prev(NULL) {} |
14123 | 75 |
#endif |
76 |
||
77 |
// Used to add a Metachunk to a list of Metachunks |
|
78 |
void set_next(Metachunk* v) { _next = v; assert(v != this, "Boom");} |
|
79 |
void set_prev(Metachunk* v) { _prev = v; assert(v != this, "Boom");} |
|
80 |
||
81 |
MetaWord* allocate(size_t word_size); |
|
82 |
static Metachunk* initialize(MetaWord* ptr, size_t word_size); |
|
83 |
||
84 |
// Accessors |
|
85 |
Metachunk* next() const { return _next; } |
|
86 |
Metachunk* prev() const { return _prev; } |
|
87 |
MetaWord* bottom() const { return _bottom; } |
|
88 |
MetaWord* end() const { return _end; } |
|
89 |
MetaWord* top() const { return _top; } |
|
90 |
size_t word_size() const { return _word_size; } |
|
91 |
size_t size() const volatile { return _word_size; } |
|
92 |
void set_size(size_t v) { _word_size = v; } |
|
93 |
bool is_free() { return _is_free; } |
|
94 |
void set_is_free(bool v) { _is_free = v; } |
|
95 |
static size_t overhead() { return _overhead; } |
|
96 |
void clear_next() { set_next(NULL); } |
|
97 |
void link_prev(Metachunk* ptr) { set_prev(ptr); } |
|
98 |
uintptr_t* end() { return ((uintptr_t*) this) + size(); } |
|
99 |
bool cantCoalesce() const { return false; } |
|
100 |
void link_next(Metachunk* ptr) { set_next(ptr); } |
|
101 |
void link_after(Metachunk* ptr){ |
|
102 |
link_next(ptr); |
|
103 |
if (ptr != NULL) ptr->link_prev(this); |
|
104 |
} |
|
105 |
||
106 |
// Reset top to bottom so chunk can be reused. |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
107 |
void reset_empty() { _top = (_bottom + _overhead); _next = NULL; _prev = NULL; } |
14123 | 108 |
bool is_empty() { return _top == (_bottom + _overhead); } |
109 |
||
110 |
// used (has been allocated) |
|
111 |
// free (available for future allocations) |
|
112 |
// capacity (total size of chunk) |
|
15086
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
113 |
size_t used_word_size() const; |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
114 |
size_t free_word_size() const; |
2bfd799e9147
8005082: NPG: Add specialized Metachunk sizes for reflection and anonymous classloaders
jmasa
parents:
14588
diff
changeset
|
115 |
size_t capacity_word_size()const; |
14123 | 116 |
|
117 |
// Debug support |
|
118 |
#ifdef ASSERT |
|
119 |
void* prev_addr() const { return (void*)&_prev; } |
|
120 |
void* next_addr() const { return (void*)&_next; } |
|
121 |
void* size_addr() const { return (void*)&_word_size; } |
|
122 |
#endif |
|
123 |
bool verify_chunk_in_free_list(Metachunk* tc) const { return true; } |
|
124 |
bool verify_par_locked() { return true; } |
|
125 |
||
126 |
void assert_is_mangled() const {/* Don't check "\*/} |
|
127 |
||
14588
8ec26d2d9339
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
14123
diff
changeset
|
128 |
NOT_PRODUCT(void mangle();) |
14123 | 129 |
|
130 |
void print_on(outputStream* st) const; |
|
131 |
void verify(); |
|
132 |
}; |
|
133 |
#endif // SHARE_VM_MEMORY_METACHUNK_HPP |