src/share/vm/runtime/unhandledOops.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/runtime/unhandledOops.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,89 @@
     1.4 +/*
     1.5 + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP
    1.29 +#define SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP
    1.30 +
    1.31 +#ifdef CHECK_UNHANDLED_OOPS
    1.32 +
    1.33 +// Detect unhanded oops in VM code
    1.34 +
    1.35 +// The design is that when an oop is declared on the stack as a local
    1.36 +// variable, the oop is actually a C++ struct with constructor and
    1.37 +// destructor.  The constructor adds the oop address on a list
    1.38 +// off each thread and the destructor removes the oop.  At a potential
    1.39 +// safepoint, the stack addresses of the local variable oops are trashed
    1.40 +// with a recognizeable value.  If the local variable is used again, it
    1.41 +// will segfault, indicating an unsafe use of that oop.
    1.42 +// eg:
    1.43 +//    oop o;    //register &o on list
    1.44 +//    funct();  // if potential safepoint - causes clear_naked_oops()
    1.45 +//              // which trashes o above.
    1.46 +//    o->do_something();  // Crashes because o is unsafe.
    1.47 +//
    1.48 +// This code implements the details of the unhandled oop list on the thread.
    1.49 +//
    1.50 +
    1.51 +class oop;
    1.52 +class Thread;
    1.53 +
    1.54 +class UnhandledOopEntry : public CHeapObj<mtThread> {
    1.55 + friend class UnhandledOops;
    1.56 + private:
    1.57 +  oop* _oop_ptr;
    1.58 +  bool _ok_for_gc;
    1.59 +  address _pc;
    1.60 + public:
    1.61 +  oop* oop_ptr() { return _oop_ptr; }
    1.62 +  UnhandledOopEntry() : _oop_ptr(NULL), _ok_for_gc(false), _pc(NULL) {}
    1.63 +  UnhandledOopEntry(oop* op, address pc) :
    1.64 +                        _oop_ptr(op),   _ok_for_gc(false), _pc(pc) {}
    1.65 +};
    1.66 +
    1.67 +
    1.68 +class UnhandledOops : public CHeapObj<mtThread> {
    1.69 + friend class Thread;
    1.70 + private:
    1.71 +  Thread* _thread;
    1.72 +  int _level;
    1.73 +  GrowableArray<UnhandledOopEntry> *_oop_list;
    1.74 +  void allow_unhandled_oop(oop* op);
    1.75 +  void clear_unhandled_oops();
    1.76 +  UnhandledOops(Thread* thread);
    1.77 +  ~UnhandledOops();
    1.78 +
    1.79 + public:
    1.80 +  static void dump_oops(UnhandledOops* list);
    1.81 +  void register_unhandled_oop(oop* op, address pc);
    1.82 +  void unregister_unhandled_oop(oop* op);
    1.83 +};
    1.84 +
    1.85 +#ifdef _LP64
    1.86 +const intptr_t BAD_OOP_ADDR =  0xfffffffffffffff1;
    1.87 +#else
    1.88 +const intptr_t BAD_OOP_ADDR =  0xfffffff1;
    1.89 +#endif // _LP64
    1.90 +#endif // CHECK_UNHANDLED_OOPS
    1.91 +
    1.92 +#endif // SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP

mercurial