28 #include "memory/allocation.hpp" 29 #include "oops/markOop.hpp" 30 #include "utilities/growableArray.hpp" 31 // 32 // This class will save the original mark oop of a object sample object. 33 // It will then install an "identifier" mark oop to be used for 34 // identification purposes in the search for reference chains. 35 // The destructor will restore each modified oop with its original mark oop. 36 // 37 class ObjectSampleMarker : public StackObj { 38 private: 39 class ObjectSampleMarkWord : public ResourceObj { 40 friend class ObjectSampleMarker; 41 private: 42 oop _obj; 43 markWord _mark_word; 44 ObjectSampleMarkWord(const oop obj, 45 const markWord mark_word) : _obj(obj), 46 _mark_word(mark_word) {} 47 public: 48 ObjectSampleMarkWord() : _obj(NULL), _mark_word(0) {} 49 }; 50 51 GrowableArray<ObjectSampleMarkWord>* _store; 52 53 public: 54 ObjectSampleMarker() : 55 _store(new GrowableArray<ObjectSampleMarkWord>(16)) {} 56 ~ObjectSampleMarker() { 57 assert(_store != NULL, "invariant"); 58 // restore the saved, original, markWord for sample objects 59 while (_store->is_nonempty()) { 60 ObjectSampleMarkWord sample_oop = _store->pop(); 61 sample_oop._obj->set_mark(sample_oop._mark_word); 62 assert(sample_oop._obj->mark() == sample_oop._mark_word, "invariant"); 63 } 64 } 65 66 void mark(oop obj) { 67 assert(obj != NULL, "invariant"); 68 // save the original markWord 69 _store->push(ObjectSampleMarkWord(obj, obj->mark())); 70 // now we will "poison" the mark word of the sample object 71 // to the intermediate monitor INFLATING state. 72 // This is an "impossible" state during a safepoint, 73 // hence we will use it to quickly identify sample objects 74 // during the reachability search from gc roots. 75 assert(0 == markWord::INFLATING().value(), "invariant"); 76 obj->set_mark(markWord::INFLATING()); 77 assert(0 == obj->mark().value(), "invariant"); 78 } 79 }; 80 81 #endif // SHARE_JFR_LEAKPROFILER_CHAINS_OBJECTSAMPLEMARKER_HPP | 28 #include "memory/allocation.hpp" 29 #include "oops/markOop.hpp" 30 #include "utilities/growableArray.hpp" 31 // 32 // This class will save the original mark oop of a object sample object. 33 // It will then install an "identifier" mark oop to be used for 34 // identification purposes in the search for reference chains. 35 // The destructor will restore each modified oop with its original mark oop. 36 // 37 class ObjectSampleMarker : public StackObj { 38 private: 39 class ObjectSampleMarkWord : public ResourceObj { 40 friend class ObjectSampleMarker; 41 private: 42 oop _obj; 43 markWord _mark_word; 44 ObjectSampleMarkWord(const oop obj, 45 const markWord mark_word) : _obj(obj), 46 _mark_word(mark_word) {} 47 public: 48 ObjectSampleMarkWord() : _obj(NULL), _mark_word(markWord::zero) {} 49 }; 50 51 GrowableArray<ObjectSampleMarkWord>* _store; 52 53 public: 54 ObjectSampleMarker() : 55 _store(new GrowableArray<ObjectSampleMarkWord>(16)) {} 56 ~ObjectSampleMarker() { 57 assert(_store != NULL, "invariant"); 58 // restore the saved, original, markWord for sample objects 59 while (_store->is_nonempty()) { 60 ObjectSampleMarkWord sample_oop = _store->pop(); 61 sample_oop._obj->set_mark(sample_oop._mark_word); 62 assert(sample_oop._obj->mark() == sample_oop._mark_word, "invariant"); 63 } 64 } 65 66 void mark(oop obj) { 67 assert(obj != NULL, "invariant"); 68 // save the original markWord 69 _store->push(ObjectSampleMarkWord(obj, obj->mark())); 70 // now we will "poison" the mark word of the sample object 71 // to the intermediate monitor INFLATING state. 72 // This is an "impossible" state during a safepoint, 73 // hence we will use it to quickly identify sample objects 74 // during the reachability search from gc roots. 75 assert(NULL == markWord::INFLATING().to_pointer(), "invariant"); 76 obj->set_mark(markWord::INFLATING()); 77 assert(NULL == obj->mark().to_pointer(), "invariant"); 78 } 79 }; 80 81 #endif // SHARE_JFR_LEAKPROFILER_CHAINS_OBJECTSAMPLEMARKER_HPP |