Skip to content

Commit

Permalink
8287661: Fix and improve BitMap::print_on(outputStream*)
Browse files Browse the repository at this point in the history
Reviewed-by: stefank
  • Loading branch information
shipilev committed Jun 3, 2022
1 parent b544b8b commit 625821d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/hotspot/share/utilities/bitMap.cpp
Expand Up @@ -691,11 +691,18 @@ void BitMap::write_to(bm_word_t* buffer, size_t buffer_size_in_bytes) const {
#ifndef PRODUCT

void BitMap::print_on(outputStream* st) const {
tty->print("Bitmap(" SIZE_FORMAT "):", size());
st->print("Bitmap (" SIZE_FORMAT " bits):", size());
for (idx_t index = 0; index < size(); index++) {
tty->print("%c", at(index) ? '1' : '0');
if ((index % 64) == 0) {
st->cr();
st->print(SIZE_FORMAT_W(5) ":", index);
}
if ((index % 8) == 0) {
st->print(" ");
}
st->print("%c", at(index) ? 'S' : '.');
}
tty->cr();
st->cr();
}

#endif
26 changes: 26 additions & 0 deletions test/hotspot/gtest/utilities/test_bitMap.cpp
Expand Up @@ -22,6 +22,7 @@
*/

#include "precompiled.hpp"
#include "logging/logStream.hpp"
#include "memory/resourceArea.hpp"
#include "utilities/bitMap.inline.hpp"
#include "unittest.hpp"
Expand Down Expand Up @@ -95,6 +96,21 @@ class BitMapTest {
EXPECT_TRUE(map.is_same(map2)) << "With init_size " << init_size;
}

#ifndef PRODUCT

static void testPrintOn(BitMap::idx_t size) {
ResourceMark rm;

ResourceBitMap map(size);
if (size > 0) {
map.set_bit(size / 2);
}

LogStreamHandle(Info, test) stream;
map.print_on(&stream);
}

#endif
};

TEST_VM(BitMap, resize_grow) {
Expand Down Expand Up @@ -148,3 +164,13 @@ TEST_VM(BitMap, reinitialize) {
BitMapTest::testReinitialize(BitMapTest::BITMAP_SIZE >> 3);
BitMapTest::testReinitialize(BitMapTest::BITMAP_SIZE);
}

#ifndef PRODUCT

TEST_VM(BitMap, print_on) {
BitMapTest::testPrintOn(0);
BitMapTest::testPrintOn(BitMapTest::BITMAP_SIZE >> 3);
BitMapTest::testPrintOn(BitMapTest::BITMAP_SIZE);
}

#endif

0 comments on commit 625821d

Please sign in to comment.