src/share/vm/runtime/unhandledOops.cpp

Thu, 24 May 2018 19:24:53 +0800

author
aoqi
date
Thu, 24 May 2018 19:24:53 +0800
changeset 8861
2a33b32dd03c
parent 6876
710a3c8b516e
child 9448
73d689add964
permissions
-rw-r--r--

#7046 Disable the compilation when branch offset is beyond short branch
Contributed-by: fujie, aoqi

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

mercurial