14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "utilities/debug.hpp"
28 #include "utilities/globalDefinitions.hpp"
29 #include "memory/metaspace/metachunk.hpp"
30 #include "memory/metaspace/occupancyMap.hpp"
31 #include "runtime/os.hpp"
32
33 namespace metaspace {
34 namespace internals {
35
36 OccupancyMap::OccupancyMap(const MetaWord* reference_address, size_t word_size, size_t smallest_chunk_word_size) :
37 _reference_address(reference_address), _word_size(word_size),
38 _smallest_chunk_word_size(smallest_chunk_word_size)
39 {
40 assert(reference_address != NULL, "invalid reference address");
41 assert(is_aligned(reference_address, smallest_chunk_word_size),
42 "Reference address not aligned to smallest chunk size.");
43 assert(is_aligned(word_size, smallest_chunk_word_size),
44 "Word_size shall be a multiple of the smallest chunk size.");
45 // Calculate bitmap size: one bit per smallest_chunk_word_size'd area.
46 size_t num_bits = word_size / smallest_chunk_word_size;
47 _map_size = (num_bits + 7) / 8;
48 assert(_map_size * 8 >= num_bits, "sanity");
49 _map[0] = (uint8_t*) os::malloc(_map_size, mtInternal);
50 _map[1] = (uint8_t*) os::malloc(_map_size, mtInternal);
51 assert(_map[0] != NULL && _map[1] != NULL, "Occupancy Map: allocation failed.");
52 memset(_map[1], 0, _map_size);
53 memset(_map[0], 0, _map_size);
54 // Sanity test: the first respectively last possible chunk start address in
115 // must start in its area.
116 if (chunk->word_size() > _smallest_chunk_word_size) {
117 assert(!is_any_bit_set_in_region(((MetaWord*) chunk) + _smallest_chunk_word_size,
118 chunk->word_size() - _smallest_chunk_word_size, layer_chunk_start_map),
119 "No chunk must start within another chunk.");
120 }
121 if (!chunk->is_tagged_free()) {
122 assert(is_region_in_use((MetaWord*)chunk, chunk->word_size()),
123 "Chunk %p is in use but marked as free in map (%d %d).",
124 chunk, chunk->get_chunk_type(), chunk->get_origin());
125 } else {
126 assert(!is_region_in_use((MetaWord*)chunk, chunk->word_size()),
127 "Chunk %p is free but marked as in-use in map (%d %d).",
128 chunk, chunk->get_chunk_type(), chunk->get_origin());
129 }
130 }
131
132 #endif // ASSERT
133
134 } // namespace metaspace
135 } // namespace internals
136
137
|
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27 #include "utilities/debug.hpp"
28 #include "utilities/globalDefinitions.hpp"
29 #include "memory/metaspace/metachunk.hpp"
30 #include "memory/metaspace/occupancyMap.hpp"
31 #include "runtime/os.hpp"
32
33 namespace metaspace {
34
35 OccupancyMap::OccupancyMap(const MetaWord* reference_address, size_t word_size, size_t smallest_chunk_word_size) :
36 _reference_address(reference_address), _word_size(word_size),
37 _smallest_chunk_word_size(smallest_chunk_word_size)
38 {
39 assert(reference_address != NULL, "invalid reference address");
40 assert(is_aligned(reference_address, smallest_chunk_word_size),
41 "Reference address not aligned to smallest chunk size.");
42 assert(is_aligned(word_size, smallest_chunk_word_size),
43 "Word_size shall be a multiple of the smallest chunk size.");
44 // Calculate bitmap size: one bit per smallest_chunk_word_size'd area.
45 size_t num_bits = word_size / smallest_chunk_word_size;
46 _map_size = (num_bits + 7) / 8;
47 assert(_map_size * 8 >= num_bits, "sanity");
48 _map[0] = (uint8_t*) os::malloc(_map_size, mtInternal);
49 _map[1] = (uint8_t*) os::malloc(_map_size, mtInternal);
50 assert(_map[0] != NULL && _map[1] != NULL, "Occupancy Map: allocation failed.");
51 memset(_map[1], 0, _map_size);
52 memset(_map[0], 0, _map_size);
53 // Sanity test: the first respectively last possible chunk start address in
114 // must start in its area.
115 if (chunk->word_size() > _smallest_chunk_word_size) {
116 assert(!is_any_bit_set_in_region(((MetaWord*) chunk) + _smallest_chunk_word_size,
117 chunk->word_size() - _smallest_chunk_word_size, layer_chunk_start_map),
118 "No chunk must start within another chunk.");
119 }
120 if (!chunk->is_tagged_free()) {
121 assert(is_region_in_use((MetaWord*)chunk, chunk->word_size()),
122 "Chunk %p is in use but marked as free in map (%d %d).",
123 chunk, chunk->get_chunk_type(), chunk->get_origin());
124 } else {
125 assert(!is_region_in_use((MetaWord*)chunk, chunk->word_size()),
126 "Chunk %p is free but marked as in-use in map (%d %d).",
127 chunk, chunk->get_chunk_type(), chunk->get_origin());
128 }
129 }
130
131 #endif // ASSERT
132
133 } // namespace metaspace
134
135
|