< prev index next >

src/share/vm/gc/g1/bufferingOopClosure.cpp

Print this page




 138   };
 139 
 140   class DoNothingOopClosure : public OopClosure {
 141    public:
 142     void do_oop(narrowOop* p) {}
 143     void do_oop(oop* p)       {}
 144   };
 145 
 146   static void testCount(int num_narrow, int num_full, int do_oop_order) {
 147     FakeRoots fr(num_narrow, num_full);
 148 
 149     CountOopClosure coc;
 150     BufferingOopClosure boc(&coc);
 151 
 152     fr.oops_do(&boc, do_oop_order);
 153 
 154     boc.done();
 155 
 156     #define assert_testCount(got, expected)                                     \
 157        assert((got) == (expected),                                              \
 158            err_msg("Expected: %d, got: %d, when running testCount(%d, %d, %d)", \
 159                (got), (expected), num_narrow, num_full, do_oop_order))
 160 
 161     assert_testCount(num_narrow, coc.narrow_oop_count());
 162     assert_testCount(num_full, coc.full_oop_count());
 163     assert_testCount(num_narrow + num_full, coc.all_oop_count());
 164   }
 165 
 166   static void testCount() {
 167     int buffer_length = BufferingOopClosure::BufferLength;
 168 
 169     for (int order = 0; order < FakeRoots::MaxOrder; order++) {
 170       testCount(0,                 0,                 order);
 171       testCount(10,                0,                 order);
 172       testCount(0,                 10,                order);
 173       testCount(10,                10,                order);
 174       testCount(buffer_length,     10,                order);
 175       testCount(10,                buffer_length,     order);
 176       testCount(buffer_length,     buffer_length,     order);
 177       testCount(buffer_length + 1, 10,                order);
 178       testCount(10,                buffer_length + 1, order);
 179       testCount(buffer_length + 1, buffer_length,     order);
 180       testCount(buffer_length,     buffer_length + 1, order);
 181       testCount(buffer_length + 1, buffer_length + 1, order);
 182     }
 183   }
 184 
 185   static void testIsBufferEmptyOrFull(int num_narrow, int num_full, bool expect_empty, bool expect_full) {
 186     FakeRoots fr(num_narrow, num_full);
 187 
 188     DoNothingOopClosure cl;
 189     BufferingOopClosure boc(&cl);
 190 
 191     fr.oops_do(&boc, 0);
 192 
 193     #define assert_testIsBufferEmptyOrFull(got, expected)                             \
 194         assert((got) == (expected),                                                   \
 195             err_msg("Expected: %d, got: %d. testIsBufferEmptyOrFull(%d, %d, %s, %s)", \
 196                 (got), (expected), num_narrow, num_full,                              \
 197                 BOOL_TO_STR(expect_empty), BOOL_TO_STR(expect_full)))
 198 
 199     assert_testIsBufferEmptyOrFull(expect_empty, boc.is_buffer_empty());
 200     assert_testIsBufferEmptyOrFull(expect_full, boc.is_buffer_full());
 201   }
 202 
 203   static void testIsBufferEmptyOrFull() {
 204     int bl = BufferingOopClosure::BufferLength;
 205 
 206     testIsBufferEmptyOrFull(0,       0, true,  false);
 207     testIsBufferEmptyOrFull(1,       0, false, false);
 208     testIsBufferEmptyOrFull(0,       1, false, false);
 209     testIsBufferEmptyOrFull(1,       1, false, false);
 210     testIsBufferEmptyOrFull(10,      0, false, false);
 211     testIsBufferEmptyOrFull(0,      10, false, false);
 212     testIsBufferEmptyOrFull(10,     10, false, false);
 213     testIsBufferEmptyOrFull(0,      bl, false, true);
 214     testIsBufferEmptyOrFull(bl,      0, false, true);
 215     testIsBufferEmptyOrFull(bl/2, bl/2, false, true);
 216     testIsBufferEmptyOrFull(bl-1,    1, false, true);
 217     testIsBufferEmptyOrFull(1,    bl-1, false, true);
 218     // Processed
 219     testIsBufferEmptyOrFull(bl+1,    0, false, false);
 220     testIsBufferEmptyOrFull(bl*2,    0, false, true);
 221   }
 222 
 223   static void testEmptyAfterDone(int num_narrow, int num_full) {
 224     FakeRoots fr(num_narrow, num_full);
 225 
 226     DoNothingOopClosure cl;
 227     BufferingOopClosure boc(&cl);
 228 
 229     fr.oops_do(&boc, 0);
 230 
 231     // Make sure all get processed.
 232     boc.done();
 233 
 234     assert(boc.is_buffer_empty(),
 235         err_msg("Should be empty after call to done(). testEmptyAfterDone(%d, %d)",
 236             num_narrow, num_full));
 237   }
 238 
 239   static void testEmptyAfterDone() {
 240     int bl = BufferingOopClosure::BufferLength;
 241 
 242     testEmptyAfterDone(0,       0);
 243     testEmptyAfterDone(1,       0);
 244     testEmptyAfterDone(0,       1);
 245     testEmptyAfterDone(1,       1);
 246     testEmptyAfterDone(10,      0);
 247     testEmptyAfterDone(0,      10);
 248     testEmptyAfterDone(10,     10);
 249     testEmptyAfterDone(0,      bl);
 250     testEmptyAfterDone(bl,      0);
 251     testEmptyAfterDone(bl/2, bl/2);
 252     testEmptyAfterDone(bl-1,    1);
 253     testEmptyAfterDone(1,    bl-1);
 254     // Processed
 255     testEmptyAfterDone(bl+1,    0);
 256     testEmptyAfterDone(bl*2,    0);


 138   };
 139 
 140   class DoNothingOopClosure : public OopClosure {
 141    public:
 142     void do_oop(narrowOop* p) {}
 143     void do_oop(oop* p)       {}
 144   };
 145 
 146   static void testCount(int num_narrow, int num_full, int do_oop_order) {
 147     FakeRoots fr(num_narrow, num_full);
 148 
 149     CountOopClosure coc;
 150     BufferingOopClosure boc(&coc);
 151 
 152     fr.oops_do(&boc, do_oop_order);
 153 
 154     boc.done();
 155 
 156     #define assert_testCount(got, expected)                                \
 157        assert((got) == (expected),                                         \
 158               "Expected: %d, got: %d, when running testCount(%d, %d, %d)", \
 159               (got), (expected), num_narrow, num_full, do_oop_order)
 160 
 161     assert_testCount(num_narrow, coc.narrow_oop_count());
 162     assert_testCount(num_full, coc.full_oop_count());
 163     assert_testCount(num_narrow + num_full, coc.all_oop_count());
 164   }
 165 
 166   static void testCount() {
 167     int buffer_length = BufferingOopClosure::BufferLength;
 168 
 169     for (int order = 0; order < FakeRoots::MaxOrder; order++) {
 170       testCount(0,                 0,                 order);
 171       testCount(10,                0,                 order);
 172       testCount(0,                 10,                order);
 173       testCount(10,                10,                order);
 174       testCount(buffer_length,     10,                order);
 175       testCount(10,                buffer_length,     order);
 176       testCount(buffer_length,     buffer_length,     order);
 177       testCount(buffer_length + 1, 10,                order);
 178       testCount(10,                buffer_length + 1, order);
 179       testCount(buffer_length + 1, buffer_length,     order);
 180       testCount(buffer_length,     buffer_length + 1, order);
 181       testCount(buffer_length + 1, buffer_length + 1, order);
 182     }
 183   }
 184 
 185   static void testIsBufferEmptyOrFull(int num_narrow, int num_full, bool expect_empty, bool expect_full) {
 186     FakeRoots fr(num_narrow, num_full);
 187 
 188     DoNothingOopClosure cl;
 189     BufferingOopClosure boc(&cl);
 190 
 191     fr.oops_do(&boc, 0);
 192 
 193     #define assert_testIsBufferEmptyOrFull(got, expected)                        \
 194         assert((got) == (expected),                                              \
 195                "Expected: %d, got: %d. testIsBufferEmptyOrFull(%d, %d, %s, %s)", \
 196                (got), (expected), num_narrow, num_full,                          \
 197                BOOL_TO_STR(expect_empty), BOOL_TO_STR(expect_full))
 198 
 199     assert_testIsBufferEmptyOrFull(expect_empty, boc.is_buffer_empty());
 200     assert_testIsBufferEmptyOrFull(expect_full, boc.is_buffer_full());
 201   }
 202 
 203   static void testIsBufferEmptyOrFull() {
 204     int bl = BufferingOopClosure::BufferLength;
 205 
 206     testIsBufferEmptyOrFull(0,       0, true,  false);
 207     testIsBufferEmptyOrFull(1,       0, false, false);
 208     testIsBufferEmptyOrFull(0,       1, false, false);
 209     testIsBufferEmptyOrFull(1,       1, false, false);
 210     testIsBufferEmptyOrFull(10,      0, false, false);
 211     testIsBufferEmptyOrFull(0,      10, false, false);
 212     testIsBufferEmptyOrFull(10,     10, false, false);
 213     testIsBufferEmptyOrFull(0,      bl, false, true);
 214     testIsBufferEmptyOrFull(bl,      0, false, true);
 215     testIsBufferEmptyOrFull(bl/2, bl/2, false, true);
 216     testIsBufferEmptyOrFull(bl-1,    1, false, true);
 217     testIsBufferEmptyOrFull(1,    bl-1, false, true);
 218     // Processed
 219     testIsBufferEmptyOrFull(bl+1,    0, false, false);
 220     testIsBufferEmptyOrFull(bl*2,    0, false, true);
 221   }
 222 
 223   static void testEmptyAfterDone(int num_narrow, int num_full) {
 224     FakeRoots fr(num_narrow, num_full);
 225 
 226     DoNothingOopClosure cl;
 227     BufferingOopClosure boc(&cl);
 228 
 229     fr.oops_do(&boc, 0);
 230 
 231     // Make sure all get processed.
 232     boc.done();
 233 
 234     assert(boc.is_buffer_empty(),
 235            "Should be empty after call to done(). testEmptyAfterDone(%d, %d)",
 236            num_narrow, num_full);
 237   }
 238 
 239   static void testEmptyAfterDone() {
 240     int bl = BufferingOopClosure::BufferLength;
 241 
 242     testEmptyAfterDone(0,       0);
 243     testEmptyAfterDone(1,       0);
 244     testEmptyAfterDone(0,       1);
 245     testEmptyAfterDone(1,       1);
 246     testEmptyAfterDone(10,      0);
 247     testEmptyAfterDone(0,      10);
 248     testEmptyAfterDone(10,     10);
 249     testEmptyAfterDone(0,      bl);
 250     testEmptyAfterDone(bl,      0);
 251     testEmptyAfterDone(bl/2, bl/2);
 252     testEmptyAfterDone(bl-1,    1);
 253     testEmptyAfterDone(1,    bl-1);
 254     // Processed
 255     testEmptyAfterDone(bl+1,    0);
 256     testEmptyAfterDone(bl*2,    0);
< prev index next >