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