duke@435: /* mikael@6198: * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ stefank@2314: stefank@2314: #ifndef SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP stefank@2314: #define SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP stefank@2314: duke@435: #ifdef CHECK_UNHANDLED_OOPS duke@435: duke@435: // Detect unhanded oops in VM code duke@435: duke@435: // The design is that when an oop is declared on the stack as a local duke@435: // variable, the oop is actually a C++ struct with constructor and duke@435: // destructor. The constructor adds the oop address on a list duke@435: // off each thread and the destructor removes the oop. At a potential duke@435: // safepoint, the stack addresses of the local variable oops are trashed duke@435: // with a recognizeable value. If the local variable is used again, it duke@435: // will segfault, indicating an unsafe use of that oop. duke@435: // eg: duke@435: // oop o; //register &o on list duke@435: // funct(); // if potential safepoint - causes clear_naked_oops() duke@435: // // which trashes o above. duke@435: // o->do_something(); // Crashes because o is unsafe. duke@435: // duke@435: // This code implements the details of the unhandled oop list on the thread. duke@435: // duke@435: duke@435: class oop; duke@435: class Thread; duke@435: minqi@5103: class UnhandledOopEntry : public CHeapObj { duke@435: friend class UnhandledOops; duke@435: private: duke@435: oop* _oop_ptr; duke@435: bool _ok_for_gc; duke@435: address _pc; duke@435: public: duke@435: oop* oop_ptr() { return _oop_ptr; } duke@435: UnhandledOopEntry() : _oop_ptr(NULL), _ok_for_gc(false), _pc(NULL) {} duke@435: UnhandledOopEntry(oop* op, address pc) : duke@435: _oop_ptr(op), _ok_for_gc(false), _pc(pc) {} duke@435: }; duke@435: duke@435: minqi@5103: class UnhandledOops : public CHeapObj { duke@435: friend class Thread; duke@435: private: duke@435: Thread* _thread; duke@435: int _level; duke@435: GrowableArray *_oop_list; duke@435: void allow_unhandled_oop(oop* op); duke@435: void clear_unhandled_oops(); duke@435: UnhandledOops(Thread* thread); duke@435: ~UnhandledOops(); duke@435: duke@435: public: duke@435: static void dump_oops(UnhandledOops* list); duke@435: void register_unhandled_oop(oop* op, address pc); duke@435: void unregister_unhandled_oop(oop* op); duke@435: }; duke@435: duke@435: #ifdef _LP64 duke@435: const intptr_t BAD_OOP_ADDR = 0xfffffffffffffff1; duke@435: #else duke@435: const intptr_t BAD_OOP_ADDR = 0xfffffff1; duke@435: #endif // _LP64 duke@435: #endif // CHECK_UNHANDLED_OOPS stefank@2314: stefank@2314: #endif // SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP