src/share/vm/runtime/unhandledOops.cpp

Thu, 28 Jun 2012 17:03:16 -0400

author
zgu
date
Thu, 28 Jun 2012 17:03:16 -0400
changeset 3900
d2a62e0f25eb
parent 2314
f95d63e2154a
child 4037
da91efe96a93
permissions
-rw-r--r--

6995781: Native Memory Tracking (Phase 1)
7151532: DCmd for hotspot native memory tracking
Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd
Reviewed-by: acorn, coleenp, fparain

duke@435 1 /*
stefank@2314 2 * Copyright (c) 2005, 2010, 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
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "gc_interface/collectedHeap.hpp"
stefank@2314 27 #include "memory/gcLocker.inline.hpp"
stefank@2314 28 #include "memory/universe.hpp"
stefank@2314 29 #include "oops/oop.inline.hpp"
stefank@2314 30 #include "runtime/thread.hpp"
stefank@2314 31 #include "runtime/unhandledOops.hpp"
stefank@2314 32 #include "utilities/globalDefinitions.hpp"
duke@435 33
duke@435 34 #ifdef CHECK_UNHANDLED_OOPS
duke@435 35 const int free_list_size = 256;
duke@435 36
duke@435 37
duke@435 38 UnhandledOops::UnhandledOops(Thread* thread) {
duke@435 39 _thread = thread;
zgu@3900 40 _oop_list = new (ResourceObj::C_HEAP, mtInternal)
duke@435 41 GrowableArray<UnhandledOopEntry>(free_list_size, true);
duke@435 42 _level = 0;
duke@435 43 }
duke@435 44
duke@435 45 UnhandledOops::~UnhandledOops() {
duke@435 46 delete _oop_list;
duke@435 47 }
duke@435 48
duke@435 49
duke@435 50 void UnhandledOops::dump_oops(UnhandledOops *list) {
duke@435 51 for (int k = 0; k < list->_oop_list->length(); k++) {
duke@435 52 UnhandledOopEntry entry = list->_oop_list->at(k);
duke@435 53 tty->print(" " INTPTR_FORMAT, entry._oop_ptr);
duke@435 54 }
duke@435 55 tty->cr();
duke@435 56 }
duke@435 57
duke@435 58 // For debugging unhandled oop detector _in the debugger_
duke@435 59 // You don't want to turn it on in compiled code here.
duke@435 60 static bool unhandled_oop_print=0;
duke@435 61
duke@435 62 void UnhandledOops::register_unhandled_oop(oop* op, address pc) {
duke@435 63 if (!_thread->is_in_stack((address)op))
duke@435 64 return;
duke@435 65
duke@435 66 _level ++;
duke@435 67 if (unhandled_oop_print) {
duke@435 68 for (int i=0; i<_level; i++) tty->print(" ");
duke@435 69 tty->print_cr("r " INTPTR_FORMAT, op);
duke@435 70 }
duke@435 71 UnhandledOopEntry entry(op, pc);
duke@435 72 _oop_list->push(entry);
duke@435 73 }
duke@435 74
duke@435 75
duke@435 76 bool match_oop_entry(void *op, UnhandledOopEntry e) {
duke@435 77 return (e.oop_ptr() == op);
duke@435 78 }
duke@435 79
duke@435 80 // Mark unhandled oop as okay for GC - the containing struct has an oops_do and
duke@435 81 // for some reason the oop has to be on the stack.
duke@435 82 // May not be called for the current thread, as in the case of
duke@435 83 // VM_GetOrSetLocal in jvmti.
duke@435 84 void UnhandledOops::allow_unhandled_oop(oop* op) {
duke@435 85 assert (CheckUnhandledOops, "should only be called with checking option");
duke@435 86
duke@435 87 int i = _oop_list->find_at_end(op, match_oop_entry);
duke@435 88 assert(i!=-1, "safe for gc oop not in unhandled_oop_list");
duke@435 89
duke@435 90 UnhandledOopEntry entry = _oop_list->at(i);
duke@435 91 assert(!entry._ok_for_gc, "duplicate entry");
duke@435 92 entry._ok_for_gc = true;
duke@435 93 _oop_list->at_put(i, entry);
duke@435 94 }
duke@435 95
duke@435 96
duke@435 97 // Called by the oop destructor to remove unhandled oop from the thread's
duke@435 98 // oop list. All oops given are assumed to be on the list. If not,
duke@435 99 // there's a bug in the unhandled oop detector.
duke@435 100 void UnhandledOops::unregister_unhandled_oop(oop* op) {
duke@435 101 if (!_thread->is_in_stack((address)op)) return;
duke@435 102
duke@435 103 _level --;
duke@435 104 if (unhandled_oop_print) {
duke@435 105 for (int i=0; i<_level; i++) tty->print(" ");
duke@435 106 tty->print_cr("u "INTPTR_FORMAT, op);
duke@435 107 }
duke@435 108
duke@435 109 int i = _oop_list->find_at_end(op, match_oop_entry);
duke@435 110 assert(i!=-1, "oop not in unhandled_oop_list");
duke@435 111 _oop_list->remove_at(i);
duke@435 112 }
duke@435 113
duke@435 114 void UnhandledOops::clear_unhandled_oops() {
duke@435 115 assert (CheckUnhandledOops, "should only be called with checking option");
duke@435 116 if (_thread->is_gc_locked_out()) {
duke@435 117 return;
duke@435 118 }
duke@435 119 for (int k = 0; k < _oop_list->length(); k++) {
duke@435 120 UnhandledOopEntry entry = _oop_list->at(k);
duke@435 121 // If an entry is on the unhandled oop list but isn't on the stack
duke@435 122 // anymore, it must not have gotten unregistered properly and it's a bug
duke@435 123 // in the unhandled oop generator.
duke@435 124 if(!_thread->is_in_stack((address)entry._oop_ptr)) {
duke@435 125 tty->print_cr("oop_ptr is " INTPTR_FORMAT, (address)entry._oop_ptr);
duke@435 126 tty->print_cr("thread is " INTPTR_FORMAT " from pc " INTPTR_FORMAT,
duke@435 127 (address)_thread, (address)entry._pc);
duke@435 128 assert(false, "heap is corrupted by the unhandled oop detector");
duke@435 129 }
duke@435 130 // Set unhandled oops to a pattern that will crash distinctively
duke@435 131 if (!entry._ok_for_gc) *(intptr_t*)(entry._oop_ptr) = BAD_OOP_ADDR;
duke@435 132 }
duke@435 133 }
duke@435 134 #endif // CHECK_UNHANDLED_OOPS

mercurial