hotspot/src/share/vm/prims/jvmtiTagMap.cpp
changeset 46329 53ccc37bda19
parent 43944 23334f30b9b2
equal deleted inserted replaced
46328:6061df52d610 46329:53ccc37bda19
   781 
   781 
   782   // add a field
   782   // add a field
   783   void add(int index, char type, int offset);
   783   void add(int index, char type, int offset);
   784 
   784 
   785   // returns the field count for the given class
   785   // returns the field count for the given class
   786   static int compute_field_count(instanceKlassHandle ikh);
   786   static int compute_field_count(InstanceKlass* ik);
   787 
   787 
   788  public:
   788  public:
   789   ~ClassFieldMap();
   789   ~ClassFieldMap();
   790 
   790 
   791   // access
   791   // access
   817 // Returns a heap allocated ClassFieldMap to describe the static fields
   817 // Returns a heap allocated ClassFieldMap to describe the static fields
   818 // of the given class.
   818 // of the given class.
   819 //
   819 //
   820 ClassFieldMap* ClassFieldMap::create_map_of_static_fields(Klass* k) {
   820 ClassFieldMap* ClassFieldMap::create_map_of_static_fields(Klass* k) {
   821   HandleMark hm;
   821   HandleMark hm;
   822   instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), k);
   822   InstanceKlass* ik = InstanceKlass::cast(k);
   823 
   823 
   824   // create the field map
   824   // create the field map
   825   ClassFieldMap* field_map = new ClassFieldMap();
   825   ClassFieldMap* field_map = new ClassFieldMap();
   826 
   826 
   827   FilteredFieldStream f(ikh, false, false);
   827   FilteredFieldStream f(ik, false, false);
   828   int max_field_index = f.field_count()-1;
   828   int max_field_index = f.field_count()-1;
   829 
   829 
   830   int index = 0;
   830   int index = 0;
   831   for (FilteredFieldStream fld(ikh, true, true); !fld.eos(); fld.next(), index++) {
   831   for (FilteredFieldStream fld(ik, true, true); !fld.eos(); fld.next(), index++) {
   832     // ignore instance fields
   832     // ignore instance fields
   833     if (!fld.access_flags().is_static()) {
   833     if (!fld.access_flags().is_static()) {
   834       continue;
   834       continue;
   835     }
   835     }
   836     field_map->add(max_field_index - index, fld.signature()->byte_at(0), fld.offset());
   836     field_map->add(max_field_index - index, fld.signature()->byte_at(0), fld.offset());
   842 // of the given class. All instance fields are included (this means public
   842 // of the given class. All instance fields are included (this means public
   843 // and private fields declared in superclasses and superinterfaces too).
   843 // and private fields declared in superclasses and superinterfaces too).
   844 //
   844 //
   845 ClassFieldMap* ClassFieldMap::create_map_of_instance_fields(oop obj) {
   845 ClassFieldMap* ClassFieldMap::create_map_of_instance_fields(oop obj) {
   846   HandleMark hm;
   846   HandleMark hm;
   847   instanceKlassHandle ikh = instanceKlassHandle(Thread::current(), obj->klass());
   847   InstanceKlass* ik = InstanceKlass::cast(obj->klass());
   848 
   848 
   849   // create the field map
   849   // create the field map
   850   ClassFieldMap* field_map = new ClassFieldMap();
   850   ClassFieldMap* field_map = new ClassFieldMap();
   851 
   851 
   852   FilteredFieldStream f(ikh, false, false);
   852   FilteredFieldStream f(ik, false, false);
   853 
   853 
   854   int max_field_index = f.field_count()-1;
   854   int max_field_index = f.field_count()-1;
   855 
   855 
   856   int index = 0;
   856   int index = 0;
   857   for (FilteredFieldStream fld(ikh, false, false); !fld.eos(); fld.next(), index++) {
   857   for (FilteredFieldStream fld(ik, false, false); !fld.eos(); fld.next(), index++) {
   858     // ignore static fields
   858     // ignore static fields
   859     if (fld.access_flags().is_static()) {
   859     if (fld.access_flags().is_static()) {
   860       continue;
   860       continue;
   861     }
   861     }
   862     field_map->add(max_field_index - index, fld.signature()->byte_at(0), fld.offset());
   862     field_map->add(max_field_index - index, fld.signature()->byte_at(0), fld.offset());
  1006   }
  1006   }
  1007   return false;
  1007   return false;
  1008 }
  1008 }
  1009 
  1009 
  1010 // helper function to indicate if an object is filtered by a klass filter
  1010 // helper function to indicate if an object is filtered by a klass filter
  1011 static inline bool is_filtered_by_klass_filter(oop obj, KlassHandle klass_filter) {
  1011 static inline bool is_filtered_by_klass_filter(oop obj, Klass* klass_filter) {
  1012   if (!klass_filter.is_null()) {
  1012   if (klass_filter != NULL) {
  1013     if (obj->klass() != klass_filter()) {
  1013     if (obj->klass() != klass_filter) {
  1014       return true;
  1014       return true;
  1015     }
  1015     }
  1016   }
  1016   }
  1017   return false;
  1017   return false;
  1018 }
  1018 }
  1270 // An ObjectClosure used to support the deprecated IterateOverHeap and
  1270 // An ObjectClosure used to support the deprecated IterateOverHeap and
  1271 // IterateOverInstancesOfClass functions
  1271 // IterateOverInstancesOfClass functions
  1272 class IterateOverHeapObjectClosure: public ObjectClosure {
  1272 class IterateOverHeapObjectClosure: public ObjectClosure {
  1273  private:
  1273  private:
  1274   JvmtiTagMap* _tag_map;
  1274   JvmtiTagMap* _tag_map;
  1275   KlassHandle _klass;
  1275   Klass* _klass;
  1276   jvmtiHeapObjectFilter _object_filter;
  1276   jvmtiHeapObjectFilter _object_filter;
  1277   jvmtiHeapObjectCallback _heap_object_callback;
  1277   jvmtiHeapObjectCallback _heap_object_callback;
  1278   const void* _user_data;
  1278   const void* _user_data;
  1279 
  1279 
  1280   // accessors
  1280   // accessors
  1281   JvmtiTagMap* tag_map() const                    { return _tag_map; }
  1281   JvmtiTagMap* tag_map() const                    { return _tag_map; }
  1282   jvmtiHeapObjectFilter object_filter() const     { return _object_filter; }
  1282   jvmtiHeapObjectFilter object_filter() const     { return _object_filter; }
  1283   jvmtiHeapObjectCallback object_callback() const { return _heap_object_callback; }
  1283   jvmtiHeapObjectCallback object_callback() const { return _heap_object_callback; }
  1284   KlassHandle klass() const                       { return _klass; }
  1284   Klass* klass() const                            { return _klass; }
  1285   const void* user_data() const                   { return _user_data; }
  1285   const void* user_data() const                   { return _user_data; }
  1286 
  1286 
  1287   // indicates if iteration has been aborted
  1287   // indicates if iteration has been aborted
  1288   bool _iteration_aborted;
  1288   bool _iteration_aborted;
  1289   bool is_iteration_aborted() const               { return _iteration_aborted; }
  1289   bool is_iteration_aborted() const               { return _iteration_aborted; }
  1290   void set_iteration_aborted(bool aborted)        { _iteration_aborted = aborted; }
  1290   void set_iteration_aborted(bool aborted)        { _iteration_aborted = aborted; }
  1291 
  1291 
  1292  public:
  1292  public:
  1293   IterateOverHeapObjectClosure(JvmtiTagMap* tag_map,
  1293   IterateOverHeapObjectClosure(JvmtiTagMap* tag_map,
  1294                                KlassHandle klass,
  1294                                Klass* klass,
  1295                                jvmtiHeapObjectFilter object_filter,
  1295                                jvmtiHeapObjectFilter object_filter,
  1296                                jvmtiHeapObjectCallback heap_object_callback,
  1296                                jvmtiHeapObjectCallback heap_object_callback,
  1297                                const void* user_data) :
  1297                                const void* user_data) :
  1298     _tag_map(tag_map),
  1298     _tag_map(tag_map),
  1299     _klass(klass),
  1299     _klass(klass),
  1314 
  1314 
  1315   // ignore any objects that aren't visible to profiler
  1315   // ignore any objects that aren't visible to profiler
  1316   if (!ServiceUtil::visible_oop(o)) return;
  1316   if (!ServiceUtil::visible_oop(o)) return;
  1317 
  1317 
  1318   // instanceof check when filtering by klass
  1318   // instanceof check when filtering by klass
  1319   if (!klass().is_null() && !o->is_a(klass()())) {
  1319   if (klass() != NULL && !o->is_a(klass())) {
  1320     return;
  1320     return;
  1321   }
  1321   }
  1322   // prepare for the calllback
  1322   // prepare for the calllback
  1323   CallbackWrapper wrapper(tag_map(), o);
  1323   CallbackWrapper wrapper(tag_map(), o);
  1324 
  1324 
  1343 
  1343 
  1344 // An ObjectClosure used to support the IterateThroughHeap function
  1344 // An ObjectClosure used to support the IterateThroughHeap function
  1345 class IterateThroughHeapObjectClosure: public ObjectClosure {
  1345 class IterateThroughHeapObjectClosure: public ObjectClosure {
  1346  private:
  1346  private:
  1347   JvmtiTagMap* _tag_map;
  1347   JvmtiTagMap* _tag_map;
  1348   KlassHandle _klass;
  1348   Klass* _klass;
  1349   int _heap_filter;
  1349   int _heap_filter;
  1350   const jvmtiHeapCallbacks* _callbacks;
  1350   const jvmtiHeapCallbacks* _callbacks;
  1351   const void* _user_data;
  1351   const void* _user_data;
  1352 
  1352 
  1353   // accessor functions
  1353   // accessor functions
  1354   JvmtiTagMap* tag_map() const                     { return _tag_map; }
  1354   JvmtiTagMap* tag_map() const                     { return _tag_map; }
  1355   int heap_filter() const                          { return _heap_filter; }
  1355   int heap_filter() const                          { return _heap_filter; }
  1356   const jvmtiHeapCallbacks* callbacks() const      { return _callbacks; }
  1356   const jvmtiHeapCallbacks* callbacks() const      { return _callbacks; }
  1357   KlassHandle klass() const                        { return _klass; }
  1357   Klass* klass() const                             { return _klass; }
  1358   const void* user_data() const                    { return _user_data; }
  1358   const void* user_data() const                    { return _user_data; }
  1359 
  1359 
  1360   // indicates if the iteration has been aborted
  1360   // indicates if the iteration has been aborted
  1361   bool _iteration_aborted;
  1361   bool _iteration_aborted;
  1362   bool is_iteration_aborted() const                { return _iteration_aborted; }
  1362   bool is_iteration_aborted() const                { return _iteration_aborted; }
  1372     return is_abort;
  1372     return is_abort;
  1373   }
  1373   }
  1374 
  1374 
  1375  public:
  1375  public:
  1376   IterateThroughHeapObjectClosure(JvmtiTagMap* tag_map,
  1376   IterateThroughHeapObjectClosure(JvmtiTagMap* tag_map,
  1377                                   KlassHandle klass,
  1377                                   Klass* klass,
  1378                                   int heap_filter,
  1378                                   int heap_filter,
  1379                                   const jvmtiHeapCallbacks* heap_callbacks,
  1379                                   const jvmtiHeapCallbacks* heap_callbacks,
  1380                                   const void* user_data) :
  1380                                   const void* user_data) :
  1381     _tag_map(tag_map),
  1381     _tag_map(tag_map),
  1382     _klass(klass),
  1382     _klass(klass),
  1468 };
  1468 };
  1469 
  1469 
  1470 
  1470 
  1471 // Deprecated function to iterate over all objects in the heap
  1471 // Deprecated function to iterate over all objects in the heap
  1472 void JvmtiTagMap::iterate_over_heap(jvmtiHeapObjectFilter object_filter,
  1472 void JvmtiTagMap::iterate_over_heap(jvmtiHeapObjectFilter object_filter,
  1473                                     KlassHandle klass,
  1473                                     Klass* klass,
  1474                                     jvmtiHeapObjectCallback heap_object_callback,
  1474                                     jvmtiHeapObjectCallback heap_object_callback,
  1475                                     const void* user_data)
  1475                                     const void* user_data)
  1476 {
  1476 {
  1477   MutexLocker ml(Heap_lock);
  1477   MutexLocker ml(Heap_lock);
  1478   IterateOverHeapObjectClosure blk(this,
  1478   IterateOverHeapObjectClosure blk(this,
  1485 }
  1485 }
  1486 
  1486 
  1487 
  1487 
  1488 // Iterates over all objects in the heap
  1488 // Iterates over all objects in the heap
  1489 void JvmtiTagMap::iterate_through_heap(jint heap_filter,
  1489 void JvmtiTagMap::iterate_through_heap(jint heap_filter,
  1490                                        KlassHandle klass,
  1490                                        Klass* klass,
  1491                                        const jvmtiHeapCallbacks* callbacks,
  1491                                        const jvmtiHeapCallbacks* callbacks,
  1492                                        const void* user_data)
  1492                                        const void* user_data)
  1493 {
  1493 {
  1494   MutexLocker ml(Heap_lock);
  1494   MutexLocker ml(Heap_lock);
  1495   IterateThroughHeapObjectClosure blk(this,
  1495   IterateThroughHeapObjectClosure blk(this,
  1804 // The advanced heap walk context for the FollowReferences functions.
  1804 // The advanced heap walk context for the FollowReferences functions.
  1805 // The context is the callbacks, and the fields used for filtering.
  1805 // The context is the callbacks, and the fields used for filtering.
  1806 class AdvancedHeapWalkContext: public HeapWalkContext {
  1806 class AdvancedHeapWalkContext: public HeapWalkContext {
  1807  private:
  1807  private:
  1808   jint _heap_filter;
  1808   jint _heap_filter;
  1809   KlassHandle _klass_filter;
  1809   Klass* _klass_filter;
  1810   const jvmtiHeapCallbacks* _heap_callbacks;
  1810   const jvmtiHeapCallbacks* _heap_callbacks;
  1811 
  1811 
  1812  public:
  1812  public:
  1813   AdvancedHeapWalkContext() : HeapWalkContext(false) { }
  1813   AdvancedHeapWalkContext() : HeapWalkContext(false) { }
  1814 
  1814 
  1815   AdvancedHeapWalkContext(jint heap_filter,
  1815   AdvancedHeapWalkContext(jint heap_filter,
  1816                            KlassHandle klass_filter,
  1816                            Klass* klass_filter,
  1817                            const jvmtiHeapCallbacks* heap_callbacks) :
  1817                            const jvmtiHeapCallbacks* heap_callbacks) :
  1818     HeapWalkContext(true),
  1818     HeapWalkContext(true),
  1819     _heap_filter(heap_filter),
  1819     _heap_filter(heap_filter),
  1820     _klass_filter(klass_filter),
  1820     _klass_filter(klass_filter),
  1821     _heap_callbacks(heap_callbacks) {
  1821     _heap_callbacks(heap_callbacks) {
  1822   }
  1822   }
  1823 
  1823 
  1824   // accessors
  1824   // accessors
  1825   jint heap_filter() const         { return _heap_filter; }
  1825   jint heap_filter() const         { return _heap_filter; }
  1826   KlassHandle klass_filter() const { return _klass_filter; }
  1826   Klass* klass_filter() const      { return _klass_filter; }
  1827 
  1827 
  1828   const jvmtiHeapReferenceCallback heap_reference_callback() const {
  1828   const jvmtiHeapReferenceCallback heap_reference_callback() const {
  1829     return _heap_callbacks->heap_reference_callback;
  1829     return _heap_callbacks->heap_reference_callback;
  1830   };
  1830   };
  1831   const jvmtiPrimitiveFieldCallback primitive_field_callback() const {
  1831   const jvmtiPrimitiveFieldCallback primitive_field_callback() const {
  3294   VMThread::execute(&op);
  3294   VMThread::execute(&op);
  3295 }
  3295 }
  3296 
  3296 
  3297 // follow references from an initial object or the GC roots
  3297 // follow references from an initial object or the GC roots
  3298 void JvmtiTagMap::follow_references(jint heap_filter,
  3298 void JvmtiTagMap::follow_references(jint heap_filter,
  3299                                     KlassHandle klass,
  3299                                     Klass* klass,
  3300                                     jobject object,
  3300                                     jobject object,
  3301                                     const jvmtiHeapCallbacks* callbacks,
  3301                                     const jvmtiHeapCallbacks* callbacks,
  3302                                     const void* user_data)
  3302                                     const void* user_data)
  3303 {
  3303 {
  3304   oop obj = JNIHandles::resolve(object);
  3304   oop obj = JNIHandles::resolve(object);