6885
|
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_METABLOCK_HPP
|
|
25 #define SHARE_VM_MEMORY_METABLOCK_HPP
|
|
26
|
|
27 // Metablock are the unit of allocation from a Chunk. It is initialized
|
|
28 // with the size of the requested allocation. That size is overwritten
|
|
29 // once the allocation returns.
|
|
30 //
|
|
31 // A Metablock may be reused by its SpaceManager but are never moved between
|
|
32 // SpaceManagers. There is no explicit link to the Metachunk
|
|
33 // from which it was allocated. Metablock may be deallocated and
|
|
34 // put on a freelist but the space is never freed, rather
|
|
35 // the Metachunk it is a part of will be deallocated when it's
|
|
36 // associated class loader is collected.
|
|
37
|
|
38 class Metablock VALUE_OBJ_CLASS_SPEC {
|
|
39 friend class VMStructs;
|
|
40 private:
|
|
41 // Used to align the allocation (see below).
|
|
42 union block_t {
|
|
43 void* _data[3];
|
|
44 struct header_t {
|
|
45 size_t _word_size;
|
|
46 Metablock* _next;
|
|
47 Metablock* _prev;
|
|
48 } _header;
|
|
49 } _block;
|
|
50 static size_t _min_block_byte_size;
|
|
51
|
|
52 typedef union block_t Block;
|
|
53 typedef struct header_t Header;
|
|
54 const Block* block() const { return &_block; }
|
|
55 const Block::header_t* header() const { return &(block()->_header); }
|
|
56 public:
|
|
57
|
|
58 static Metablock* initialize(MetaWord* p, size_t word_size);
|
|
59
|
|
60 // This places the body of the block at a 2 word boundary
|
|
61 // because every block starts on a 2 word boundary. Work out
|
|
62 // how to make the body on a 2 word boundary if the block
|
|
63 // starts on a arbitrary boundary. JJJ
|
|
64
|
|
65 size_t word_size() const { return header()->_word_size; }
|
|
66 void set_word_size(size_t v) { _block._header._word_size = v; }
|
|
67 size_t size() const volatile { return _block._header._word_size; }
|
|
68 void set_size(size_t v) { _block._header._word_size = v; }
|
|
69 Metablock* next() const { return header()->_next; }
|
|
70 void set_next(Metablock* v) { _block._header._next = v; }
|
|
71 Metablock* prev() const { return header()->_prev; }
|
|
72 void set_prev(Metablock* v) { _block._header._prev = v; }
|
|
73
|
|
74 static size_t min_block_byte_size() { return _min_block_byte_size; }
|
|
75
|
|
76 bool is_free() { return header()->_word_size != 0; }
|
|
77 void clear_next() { set_next(NULL); }
|
|
78 void link_prev(Metablock* ptr) { set_prev(ptr); }
|
|
79 uintptr_t* end() { return ((uintptr_t*) this) + size(); }
|
|
80 bool cantCoalesce() const { return false; }
|
|
81 void link_next(Metablock* ptr) { set_next(ptr); }
|
|
82 void link_after(Metablock* ptr){
|
|
83 link_next(ptr);
|
|
84 if (ptr != NULL) ptr->link_prev(this);
|
|
85 }
|
|
86
|
|
87 // Should not be needed in a free list of Metablocks
|
|
88 void markNotFree() { ShouldNotReachHere(); }
|
|
89
|
|
90 // Debug support
|
|
91 #ifdef ASSERT
|
|
92 void* prev_addr() const { return (void*)&_block._header._prev; }
|
|
93 void* next_addr() const { return (void*)&_block._header._next; }
|
|
94 void* size_addr() const { return (void*)&_block._header._word_size; }
|
|
95 #endif
|
|
96 bool verify_chunk_in_free_list(Metablock* tc) const { return true; }
|
|
97 bool verify_par_locked() { return true; }
|
|
98
|
|
99 void assert_is_mangled() const {/* Don't check "\*/}
|
|
100 };
|
|
101 #endif // SHARE_VM_MEMORY_METABLOCK_HPP
|