aoqi@0: /* aoqi@0: * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "gc_interface/collectedHeap.hpp" aoqi@0: #include "memory/gcLocker.inline.hpp" aoqi@0: #include "memory/universe.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "runtime/thread.hpp" aoqi@0: #include "runtime/unhandledOops.hpp" aoqi@0: #include "utilities/globalDefinitions.hpp" aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: #ifdef CHECK_UNHANDLED_OOPS aoqi@0: const int free_list_size = 256; aoqi@0: aoqi@0: aoqi@0: UnhandledOops::UnhandledOops(Thread* thread) { aoqi@0: _thread = thread; aoqi@0: _oop_list = new (ResourceObj::C_HEAP, mtInternal) aoqi@0: GrowableArray(free_list_size, true); aoqi@0: _level = 0; aoqi@0: } aoqi@0: aoqi@0: UnhandledOops::~UnhandledOops() { aoqi@0: delete _oop_list; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void UnhandledOops::dump_oops(UnhandledOops *list) { aoqi@0: for (int k = 0; k < list->_oop_list->length(); k++) { aoqi@0: UnhandledOopEntry entry = list->_oop_list->at(k); aoqi@0: tty->print(" " INTPTR_FORMAT, entry._oop_ptr); aoqi@0: } aoqi@0: tty->cr(); aoqi@0: } aoqi@0: aoqi@0: // For debugging unhandled oop detector _in the debugger_ aoqi@0: // You don't want to turn it on in compiled code here. aoqi@0: static bool unhandled_oop_print=0; aoqi@0: aoqi@0: void UnhandledOops::register_unhandled_oop(oop* op, address pc) { aoqi@0: if (!_thread->is_in_stack((address)op)) aoqi@0: return; aoqi@0: aoqi@0: _level ++; aoqi@0: if (unhandled_oop_print) { aoqi@0: for (int i=0; i<_level; i++) tty->print(" "); aoqi@0: tty->print_cr("r " INTPTR_FORMAT, op); aoqi@0: } aoqi@0: UnhandledOopEntry entry(op, pc); aoqi@0: _oop_list->push(entry); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: bool match_oop_entry(void *op, UnhandledOopEntry e) { aoqi@0: return (e.oop_ptr() == op); aoqi@0: } aoqi@0: aoqi@0: // Mark unhandled oop as okay for GC - the containing struct has an oops_do and aoqi@0: // for some reason the oop has to be on the stack. aoqi@0: // May not be called for the current thread, as in the case of aoqi@0: // VM_GetOrSetLocal in jvmti. aoqi@0: void UnhandledOops::allow_unhandled_oop(oop* op) { aoqi@0: assert (CheckUnhandledOops, "should only be called with checking option"); aoqi@0: aoqi@0: int i = _oop_list->find_from_end(op, match_oop_entry); aoqi@0: assert(i!=-1, "safe for gc oop not in unhandled_oop_list"); aoqi@0: aoqi@0: UnhandledOopEntry entry = _oop_list->at(i); aoqi@0: assert(!entry._ok_for_gc, "duplicate entry"); aoqi@0: entry._ok_for_gc = true; aoqi@0: _oop_list->at_put(i, entry); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Called by the oop destructor to remove unhandled oop from the thread's aoqi@0: // oop list. All oops given are assumed to be on the list. If not, aoqi@0: // there's a bug in the unhandled oop detector. aoqi@0: void UnhandledOops::unregister_unhandled_oop(oop* op) { aoqi@0: if (!_thread->is_in_stack((address)op)) return; aoqi@0: aoqi@0: _level --; aoqi@0: if (unhandled_oop_print) { aoqi@0: for (int i=0; i<_level; i++) tty->print(" "); aoqi@0: tty->print_cr("u "INTPTR_FORMAT, op); aoqi@0: } aoqi@0: aoqi@0: int i = _oop_list->find_from_end(op, match_oop_entry); aoqi@0: assert(i!=-1, "oop not in unhandled_oop_list"); aoqi@0: _oop_list->remove_at(i); aoqi@0: } aoqi@0: aoqi@0: void UnhandledOops::clear_unhandled_oops() { aoqi@0: assert (CheckUnhandledOops, "should only be called with checking option"); aoqi@0: aoqi@0: for (int k = 0; k < _oop_list->length(); k++) { aoqi@0: UnhandledOopEntry entry = _oop_list->at(k); aoqi@0: // If an entry is on the unhandled oop list but isn't on the stack aoqi@0: // anymore, it must not have gotten unregistered properly and it's a bug aoqi@0: // in the unhandled oop generator. aoqi@0: if(!_thread->is_in_stack((address)entry._oop_ptr)) { aoqi@0: tty->print_cr("oop_ptr is " INTPTR_FORMAT, (address)entry._oop_ptr); aoqi@0: tty->print_cr("thread is " INTPTR_FORMAT " from pc " INTPTR_FORMAT, aoqi@0: (address)_thread, (address)entry._pc); aoqi@0: assert(false, "heap is corrupted by the unhandled oop detector"); aoqi@0: } aoqi@0: // Set unhandled oops to a pattern that will crash distinctively aoqi@0: if (!entry._ok_for_gc) *(intptr_t*)(entry._oop_ptr) = BAD_OOP_ADDR; aoqi@0: } aoqi@0: } aoqi@0: #endif // CHECK_UNHANDLED_OOPS