src/share/vm/runtime/unhandledOops.cpp

Thu, 27 May 2010 19:08:38 -0700

author
trims
date
Thu, 27 May 2010 19:08:38 -0700
changeset 1907
c18cbe5936b8
parent 435
a61af66fc99e
child 2314
f95d63e2154a
permissions
-rw-r--r--

6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair

duke@435 1 /*
trims@1907 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_unhandledOops.cpp.incl"
duke@435 27
duke@435 28 #ifdef CHECK_UNHANDLED_OOPS
duke@435 29 const int free_list_size = 256;
duke@435 30
duke@435 31
duke@435 32 UnhandledOops::UnhandledOops(Thread* thread) {
duke@435 33 _thread = thread;
duke@435 34 _oop_list = new (ResourceObj::C_HEAP)
duke@435 35 GrowableArray<UnhandledOopEntry>(free_list_size, true);
duke@435 36 _level = 0;
duke@435 37 }
duke@435 38
duke@435 39 UnhandledOops::~UnhandledOops() {
duke@435 40 delete _oop_list;
duke@435 41 }
duke@435 42
duke@435 43
duke@435 44 void UnhandledOops::dump_oops(UnhandledOops *list) {
duke@435 45 for (int k = 0; k < list->_oop_list->length(); k++) {
duke@435 46 UnhandledOopEntry entry = list->_oop_list->at(k);
duke@435 47 tty->print(" " INTPTR_FORMAT, entry._oop_ptr);
duke@435 48 }
duke@435 49 tty->cr();
duke@435 50 }
duke@435 51
duke@435 52 // For debugging unhandled oop detector _in the debugger_
duke@435 53 // You don't want to turn it on in compiled code here.
duke@435 54 static bool unhandled_oop_print=0;
duke@435 55
duke@435 56 void UnhandledOops::register_unhandled_oop(oop* op, address pc) {
duke@435 57 if (!_thread->is_in_stack((address)op))
duke@435 58 return;
duke@435 59
duke@435 60 _level ++;
duke@435 61 if (unhandled_oop_print) {
duke@435 62 for (int i=0; i<_level; i++) tty->print(" ");
duke@435 63 tty->print_cr("r " INTPTR_FORMAT, op);
duke@435 64 }
duke@435 65 UnhandledOopEntry entry(op, pc);
duke@435 66 _oop_list->push(entry);
duke@435 67 }
duke@435 68
duke@435 69
duke@435 70 bool match_oop_entry(void *op, UnhandledOopEntry e) {
duke@435 71 return (e.oop_ptr() == op);
duke@435 72 }
duke@435 73
duke@435 74 // Mark unhandled oop as okay for GC - the containing struct has an oops_do and
duke@435 75 // for some reason the oop has to be on the stack.
duke@435 76 // May not be called for the current thread, as in the case of
duke@435 77 // VM_GetOrSetLocal in jvmti.
duke@435 78 void UnhandledOops::allow_unhandled_oop(oop* op) {
duke@435 79 assert (CheckUnhandledOops, "should only be called with checking option");
duke@435 80
duke@435 81 int i = _oop_list->find_at_end(op, match_oop_entry);
duke@435 82 assert(i!=-1, "safe for gc oop not in unhandled_oop_list");
duke@435 83
duke@435 84 UnhandledOopEntry entry = _oop_list->at(i);
duke@435 85 assert(!entry._ok_for_gc, "duplicate entry");
duke@435 86 entry._ok_for_gc = true;
duke@435 87 _oop_list->at_put(i, entry);
duke@435 88 }
duke@435 89
duke@435 90
duke@435 91 // Called by the oop destructor to remove unhandled oop from the thread's
duke@435 92 // oop list. All oops given are assumed to be on the list. If not,
duke@435 93 // there's a bug in the unhandled oop detector.
duke@435 94 void UnhandledOops::unregister_unhandled_oop(oop* op) {
duke@435 95 if (!_thread->is_in_stack((address)op)) return;
duke@435 96
duke@435 97 _level --;
duke@435 98 if (unhandled_oop_print) {
duke@435 99 for (int i=0; i<_level; i++) tty->print(" ");
duke@435 100 tty->print_cr("u "INTPTR_FORMAT, op);
duke@435 101 }
duke@435 102
duke@435 103 int i = _oop_list->find_at_end(op, match_oop_entry);
duke@435 104 assert(i!=-1, "oop not in unhandled_oop_list");
duke@435 105 _oop_list->remove_at(i);
duke@435 106 }
duke@435 107
duke@435 108 void UnhandledOops::clear_unhandled_oops() {
duke@435 109 assert (CheckUnhandledOops, "should only be called with checking option");
duke@435 110 if (_thread->is_gc_locked_out()) {
duke@435 111 return;
duke@435 112 }
duke@435 113 for (int k = 0; k < _oop_list->length(); k++) {
duke@435 114 UnhandledOopEntry entry = _oop_list->at(k);
duke@435 115 // If an entry is on the unhandled oop list but isn't on the stack
duke@435 116 // anymore, it must not have gotten unregistered properly and it's a bug
duke@435 117 // in the unhandled oop generator.
duke@435 118 if(!_thread->is_in_stack((address)entry._oop_ptr)) {
duke@435 119 tty->print_cr("oop_ptr is " INTPTR_FORMAT, (address)entry._oop_ptr);
duke@435 120 tty->print_cr("thread is " INTPTR_FORMAT " from pc " INTPTR_FORMAT,
duke@435 121 (address)_thread, (address)entry._pc);
duke@435 122 assert(false, "heap is corrupted by the unhandled oop detector");
duke@435 123 }
duke@435 124 // Set unhandled oops to a pattern that will crash distinctively
duke@435 125 if (!entry._ok_for_gc) *(intptr_t*)(entry._oop_ptr) = BAD_OOP_ADDR;
duke@435 126 }
duke@435 127 }
duke@435 128 #endif // CHECK_UNHANDLED_OOPS

mercurial