< prev index next >

src/hotspot/share/runtime/unhandledOops.cpp

Print this page




  38   _oop_list = new (ResourceObj::C_HEAP, mtInternal)
  39                     GrowableArray<UnhandledOopEntry>(free_list_size, true);
  40   _level = 0;
  41 }
  42 
  43 UnhandledOops::~UnhandledOops() {
  44   delete _oop_list;
  45 }
  46 
  47 
  48 void UnhandledOops::dump_oops(UnhandledOops *list) {
  49   for (int k = 0; k < list->_oop_list->length(); k++) {
  50     UnhandledOopEntry entry = list->_oop_list->at(k);
  51     tty->print(" " INTPTR_FORMAT, p2i(entry._oop_ptr));
  52   }
  53   tty->cr();
  54 }
  55 
  56 // For debugging unhandled oop detector _in the debugger_
  57 // You don't want to turn it on in compiled code here.
  58 static bool unhandled_oop_print=0;
  59 
  60 void UnhandledOops::register_unhandled_oop(oop* op, address pc) {
  61   if (!_thread->is_in_stack((address)op))
  62     return;
  63 
  64   _level ++;
  65   if (unhandled_oop_print) {
  66     for (int i=0; i<_level; i++) tty->print(" ");
  67     tty->print_cr("r " INTPTR_FORMAT, p2i(op));
  68   }
  69   UnhandledOopEntry entry(op, pc);
  70   _oop_list->push(entry);
  71 }
  72 
  73 
  74 bool match_oop_entry(void *op, UnhandledOopEntry e) {
  75   return (e.oop_ptr() == op);
  76 }
  77 
  78 // Mark unhandled oop as okay for GC - the containing struct has an oops_do and
  79 // for some reason the oop has to be on the stack.
  80 // May not be called for the current thread, as in the case of
  81 // VM_GetOrSetLocal in jvmti.
  82 void UnhandledOops::allow_unhandled_oop(oop* op) {
  83   assert (CheckUnhandledOops, "should only be called with checking option");
  84 
  85   int i = _oop_list->find_from_end(op, match_oop_entry);
  86   assert(i!=-1, "safe for gc oop not in unhandled_oop_list");
  87 
  88   UnhandledOopEntry entry = _oop_list->at(i);
  89   assert(!entry._ok_for_gc, "duplicate entry");
  90   entry._ok_for_gc = true;
  91   _oop_list->at_put(i, entry);
  92 }
  93 
  94 
  95 // Called by the oop destructor to remove unhandled oop from the thread's
  96 // oop list.  All oops given are assumed to be on the list.  If not,
  97 // there's a bug in the unhandled oop detector.
  98 void UnhandledOops::unregister_unhandled_oop(oop* op) {
  99   if (!_thread->is_in_stack((address)op)) return;
 100 
 101   _level --;
 102   if (unhandled_oop_print) {
 103     for (int i=0; i<_level; i++) tty->print(" ");
 104     tty->print_cr("u " INTPTR_FORMAT, p2i(op));
 105   }

 106 
 107   int i = _oop_list->find_from_end(op, match_oop_entry);
 108   assert(i!=-1, "oop not in unhandled_oop_list");
 109   _oop_list->remove_at(i);
 110 }
 111 
 112 void UnhandledOops::clear_unhandled_oops() {
 113   assert (CheckUnhandledOops, "should only be called with checking option");
 114 
 115   for (int k = 0; k < _oop_list->length(); k++) {
 116     UnhandledOopEntry entry = _oop_list->at(k);
 117     // If an entry is on the unhandled oop list but isn't on the stack
 118     // anymore, it must not have gotten unregistered properly and it's a bug
 119     // in the unhandled oop generator.
 120     if(!_thread->is_in_stack((address)entry._oop_ptr)) {
 121       tty->print_cr("oop_ptr is " INTPTR_FORMAT, p2i(entry._oop_ptr));
 122       tty->print_cr("thread is " INTPTR_FORMAT " from pc " INTPTR_FORMAT,
 123                      p2i(_thread), p2i(entry._pc));
 124       assert(false, "heap is corrupted by the unhandled oop detector");
 125     }


  38   _oop_list = new (ResourceObj::C_HEAP, mtInternal)
  39                     GrowableArray<UnhandledOopEntry>(free_list_size, true);
  40   _level = 0;
  41 }
  42 
  43 UnhandledOops::~UnhandledOops() {
  44   delete _oop_list;
  45 }
  46 
  47 
  48 void UnhandledOops::dump_oops(UnhandledOops *list) {
  49   for (int k = 0; k < list->_oop_list->length(); k++) {
  50     UnhandledOopEntry entry = list->_oop_list->at(k);
  51     tty->print(" " INTPTR_FORMAT, p2i(entry._oop_ptr));
  52   }
  53   tty->cr();
  54 }
  55 
  56 // For debugging unhandled oop detector _in the debugger_
  57 // You don't want to turn it on in compiled code here.
  58 static Thread* unhandled_oop_print = NULL;
  59 
  60 void UnhandledOops::register_unhandled_oop(oop* op, address pc) {
  61   if (!_thread->is_in_stack((address)op))
  62     return;
  63 
  64   _level++;
  65   if (unhandled_oop_print == _thread) {
  66     for (int i=0; i < _level; i++) tty->print(" ");
  67     tty->print_cr("r " INTPTR_FORMAT, p2i(op));
  68   }
  69   UnhandledOopEntry entry(op, pc);
  70   _oop_list->push(entry);
  71 }
  72 
  73 
  74 bool match_oop_entry(void *op, UnhandledOopEntry e) {
  75   return (e.oop_ptr() == op);
  76 }
  77 
  78 // Mark unhandled oop as okay for GC - the containing struct has an oops_do and
  79 // for some reason the oop has to be on the stack.
  80 // May not be called for the current thread, as in the case of
  81 // VM_GetOrSetLocal in jvmti.
  82 void UnhandledOops::allow_unhandled_oop(oop* op) {
  83   assert (CheckUnhandledOops, "should only be called with checking option");
  84 
  85   int i = _oop_list->find_from_end(op, match_oop_entry);
  86   assert(i!=-1, "safe for gc oop not in unhandled_oop_list");
  87 
  88   UnhandledOopEntry entry = _oop_list->at(i);
  89   assert(!entry._ok_for_gc, "duplicate entry");
  90   entry._ok_for_gc = true;
  91   _oop_list->at_put(i, entry);
  92 }
  93 
  94 
  95 // Called by the oop destructor to remove unhandled oop from the thread's
  96 // oop list.  All oops given are assumed to be on the list.  If not,
  97 // there's a bug in the unhandled oop detector.
  98 void UnhandledOops::unregister_unhandled_oop(oop* op) {
  99   if (!_thread->is_in_stack((address)op)) return;
 100 
 101   if (unhandled_oop_print == _thread) {
 102     for (int i=0; i < _level; i++) tty->print(" ");

 103     tty->print_cr("u " INTPTR_FORMAT, p2i(op));
 104   }
 105   _level--;
 106 
 107   int i = _oop_list->find_from_end(op, match_oop_entry);
 108   assert(i!=-1, "oop not in unhandled_oop_list");
 109   _oop_list->remove_at(i);
 110 }
 111 
 112 void UnhandledOops::clear_unhandled_oops() {
 113   assert (CheckUnhandledOops, "should only be called with checking option");
 114 
 115   for (int k = 0; k < _oop_list->length(); k++) {
 116     UnhandledOopEntry entry = _oop_list->at(k);
 117     // If an entry is on the unhandled oop list but isn't on the stack
 118     // anymore, it must not have gotten unregistered properly and it's a bug
 119     // in the unhandled oop generator.
 120     if(!_thread->is_in_stack((address)entry._oop_ptr)) {
 121       tty->print_cr("oop_ptr is " INTPTR_FORMAT, p2i(entry._oop_ptr));
 122       tty->print_cr("thread is " INTPTR_FORMAT " from pc " INTPTR_FORMAT,
 123                      p2i(_thread), p2i(entry._pc));
 124       assert(false, "heap is corrupted by the unhandled oop detector");
 125     }
< prev index next >