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