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