< prev index next >

test/hotspot/gtest/gc/shared/test_oopStorage.cpp

Print this page




 513 
 514 #ifndef DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
 515 TEST_VM_F(OopStorageTest, invalid_pointer) {
 516   {
 517     char* mem = NEW_C_HEAP_ARRAY(char, 1000, mtInternal);
 518     oop* ptr = reinterpret_cast<oop*>(align_down(mem + 250, sizeof(oop)));
 519     // Predicate returns false for some malloc'ed block.
 520     EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(ptr));
 521     FREE_C_HEAP_ARRAY(char, mem);
 522   }
 523 
 524   {
 525     oop obj;
 526     oop* ptr = &obj;
 527     // Predicate returns false for some "random" location.
 528     EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(ptr));
 529   }
 530 }
 531 #endif // DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
 532 
 533 class OopStorageTest::CountingIterateClosure VALUE_OBJ_CLASS_SPEC {
 534 public:
 535   size_t _const_count;
 536   size_t _const_non_null;
 537   size_t _non_const_count;
 538   size_t _non_const_non_null;
 539 
 540   void do_oop(const oop* ptr) {
 541     ++_const_count;
 542     if (*ptr != NULL) {
 543       ++_const_non_null;
 544     }
 545   }
 546 
 547   void do_oop(oop* ptr) {
 548     ++_non_const_count;
 549     if (*ptr != NULL) {
 550       ++_non_const_non_null;
 551     }
 552   }
 553 


 655     for (size_t i = initial_release; i < _max_entries; i += 3) {
 656       release_entry(_storage, _entries[i], false);
 657       _states[0][i] = mark_released;
 658     }
 659     process_deferred_updates(_storage);
 660   }
 661 
 662   class VerifyState;
 663   class VerifyFn;
 664   template<bool is_const> class VM_Verify;
 665 
 666   class VerifyClosure;
 667   class VM_VerifyUsingOopsDo;
 668 };
 669 
 670 const unsigned char OopStorageTestIteration::mark_released;
 671 const unsigned char OopStorageTestIteration::mark_invalid;
 672 const unsigned char OopStorageTestIteration::mark_const;
 673 const unsigned char OopStorageTestIteration::mark_non_const;
 674 
 675 class OopStorageTestIteration::VerifyState VALUE_OBJ_CLASS_SPEC {
 676 public:
 677   unsigned char _expected_mark;
 678   const oop* const* _entries;
 679   unsigned char (&_states)[_max_workers][_max_entries];
 680 
 681   VerifyState(unsigned char expected_mark,
 682               const oop* const* entries,
 683               unsigned char (&states)[_max_workers][_max_entries]) :
 684     _expected_mark(expected_mark),
 685     _entries(entries),
 686     _states(states)
 687   { }
 688 
 689   bool update(const oop* ptr, uint worker_id, unsigned char mark) const {
 690     size_t index = 0;
 691     bool found = find_entry(ptr, &index);
 692     EXPECT_TRUE(found);
 693     EXPECT_GT(_max_entries, index);
 694     EXPECT_GT(_max_workers, worker_id);
 695     if (!found) {


 725       } else if ((mark & mark_released) != 0) {
 726         EXPECT_EQ(mark_released, mark);
 727       } else {
 728         EXPECT_EQ(_expected_mark, mark);
 729       }
 730     }
 731   }
 732 
 733 private:
 734   bool find_entry(const oop* ptr, size_t* index) const {
 735     for (size_t i = 0; i < _max_entries; ++i) {
 736       if (ptr == _entries[i]) {
 737         *index = i;
 738         return true;
 739       }
 740     }
 741     return false;
 742   }
 743 };
 744 
 745 class OopStorageTestIteration::VerifyFn VALUE_OBJ_CLASS_SPEC {
 746 public:
 747   VerifyFn(VerifyState* state, uint worker_id = 0) :
 748     _state(state),
 749     _worker_id(worker_id)
 750   {}
 751 
 752   bool operator()(      oop* ptr) const {
 753     return _state->update(ptr, _worker_id, mark_non_const);
 754   }
 755 
 756   bool operator()(const oop* ptr) const {
 757     return _state->update(ptr, _worker_id, mark_const);
 758   }
 759 
 760 private:
 761   VerifyState* _state;
 762   uint _worker_id;
 763 };
 764 
 765 class OopStorageTestIteration::VerifyClosure VALUE_OBJ_CLASS_SPEC {
 766 public:
 767   VerifyClosure(VerifyState* state, uint worker_id = 0) :
 768     _state(state),
 769     _worker_id(worker_id)
 770   {}
 771 
 772   void do_oop(oop* ptr) {
 773     _state->update(ptr, _worker_id, mark_non_const);
 774   }
 775 
 776   void do_oop(const oop* ptr) {
 777     _state->update(ptr, _worker_id, mark_const);
 778   }
 779 
 780 private:
 781   VerifyState* _state;
 782   uint _worker_id;
 783 };
 784 
 785 const size_t OopStorageTestIteration::_max_workers;




 513 
 514 #ifndef DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
 515 TEST_VM_F(OopStorageTest, invalid_pointer) {
 516   {
 517     char* mem = NEW_C_HEAP_ARRAY(char, 1000, mtInternal);
 518     oop* ptr = reinterpret_cast<oop*>(align_down(mem + 250, sizeof(oop)));
 519     // Predicate returns false for some malloc'ed block.
 520     EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(ptr));
 521     FREE_C_HEAP_ARRAY(char, mem);
 522   }
 523 
 524   {
 525     oop obj;
 526     oop* ptr = &obj;
 527     // Predicate returns false for some "random" location.
 528     EXPECT_EQ(OopStorage::INVALID_ENTRY, _storage.allocation_status(ptr));
 529   }
 530 }
 531 #endif // DISABLE_GARBAGE_ALLOCATION_STATUS_TESTS
 532 
 533 class OopStorageTest::CountingIterateClosure {
 534 public:
 535   size_t _const_count;
 536   size_t _const_non_null;
 537   size_t _non_const_count;
 538   size_t _non_const_non_null;
 539 
 540   void do_oop(const oop* ptr) {
 541     ++_const_count;
 542     if (*ptr != NULL) {
 543       ++_const_non_null;
 544     }
 545   }
 546 
 547   void do_oop(oop* ptr) {
 548     ++_non_const_count;
 549     if (*ptr != NULL) {
 550       ++_non_const_non_null;
 551     }
 552   }
 553 


 655     for (size_t i = initial_release; i < _max_entries; i += 3) {
 656       release_entry(_storage, _entries[i], false);
 657       _states[0][i] = mark_released;
 658     }
 659     process_deferred_updates(_storage);
 660   }
 661 
 662   class VerifyState;
 663   class VerifyFn;
 664   template<bool is_const> class VM_Verify;
 665 
 666   class VerifyClosure;
 667   class VM_VerifyUsingOopsDo;
 668 };
 669 
 670 const unsigned char OopStorageTestIteration::mark_released;
 671 const unsigned char OopStorageTestIteration::mark_invalid;
 672 const unsigned char OopStorageTestIteration::mark_const;
 673 const unsigned char OopStorageTestIteration::mark_non_const;
 674 
 675 class OopStorageTestIteration::VerifyState {
 676 public:
 677   unsigned char _expected_mark;
 678   const oop* const* _entries;
 679   unsigned char (&_states)[_max_workers][_max_entries];
 680 
 681   VerifyState(unsigned char expected_mark,
 682               const oop* const* entries,
 683               unsigned char (&states)[_max_workers][_max_entries]) :
 684     _expected_mark(expected_mark),
 685     _entries(entries),
 686     _states(states)
 687   { }
 688 
 689   bool update(const oop* ptr, uint worker_id, unsigned char mark) const {
 690     size_t index = 0;
 691     bool found = find_entry(ptr, &index);
 692     EXPECT_TRUE(found);
 693     EXPECT_GT(_max_entries, index);
 694     EXPECT_GT(_max_workers, worker_id);
 695     if (!found) {


 725       } else if ((mark & mark_released) != 0) {
 726         EXPECT_EQ(mark_released, mark);
 727       } else {
 728         EXPECT_EQ(_expected_mark, mark);
 729       }
 730     }
 731   }
 732 
 733 private:
 734   bool find_entry(const oop* ptr, size_t* index) const {
 735     for (size_t i = 0; i < _max_entries; ++i) {
 736       if (ptr == _entries[i]) {
 737         *index = i;
 738         return true;
 739       }
 740     }
 741     return false;
 742   }
 743 };
 744 
 745 class OopStorageTestIteration::VerifyFn {
 746 public:
 747   VerifyFn(VerifyState* state, uint worker_id = 0) :
 748     _state(state),
 749     _worker_id(worker_id)
 750   {}
 751 
 752   bool operator()(      oop* ptr) const {
 753     return _state->update(ptr, _worker_id, mark_non_const);
 754   }
 755 
 756   bool operator()(const oop* ptr) const {
 757     return _state->update(ptr, _worker_id, mark_const);
 758   }
 759 
 760 private:
 761   VerifyState* _state;
 762   uint _worker_id;
 763 };
 764 
 765 class OopStorageTestIteration::VerifyClosure {
 766 public:
 767   VerifyClosure(VerifyState* state, uint worker_id = 0) :
 768     _state(state),
 769     _worker_id(worker_id)
 770   {}
 771 
 772   void do_oop(oop* ptr) {
 773     _state->update(ptr, _worker_id, mark_non_const);
 774   }
 775 
 776   void do_oop(const oop* ptr) {
 777     _state->update(ptr, _worker_id, mark_const);
 778   }
 779 
 780 private:
 781   VerifyState* _state;
 782   uint _worker_id;
 783 };
 784 
 785 const size_t OopStorageTestIteration::_max_workers;


< prev index next >