1 /*
2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24 #ifdef CHECK_UNHANDLED_OOPS
25
26 // Detect unhanded oops in VM code
27
28 // The design is that when an oop is declared on the stack as a local
29 // variable, the oop is actually a C++ struct with constructor and
30 // destructor. The constructor adds the oop address on a list
31 // off each thread and the destructor removes the oop. At a potential
32 // safepoint, the stack addresses of the local variable oops are trashed
33 // with a recognizeable value. If the local variable is used again, it
34 // will segfault, indicating an unsafe use of that oop.
35 // eg:
36 // oop o; //register &o on list
37 // funct(); // if potential safepoint - causes clear_naked_oops()
38 // // which trashes o above.
39 // o->do_something(); // Crashes because o is unsafe.
40 //
41 // This code implements the details of the unhandled oop list on the thread.
42 //
43
64 Thread* _thread;
65 int _level;
66 GrowableArray<UnhandledOopEntry> *_oop_list;
67 void allow_unhandled_oop(oop* op);
68 void clear_unhandled_oops();
69 UnhandledOops(Thread* thread);
70 ~UnhandledOops();
71
72 public:
73 static void dump_oops(UnhandledOops* list);
74 void register_unhandled_oop(oop* op, address pc);
75 void unregister_unhandled_oop(oop* op);
76 };
77
78 #ifdef _LP64
79 const intptr_t BAD_OOP_ADDR = 0xfffffffffffffff1;
80 #else
81 const intptr_t BAD_OOP_ADDR = 0xfffffff1;
82 #endif // _LP64
83 #endif // CHECK_UNHANDLED_OOPS
|
1 /*
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP
26 #define SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP
27 #ifdef CHECK_UNHANDLED_OOPS
28
29 // Detect unhanded oops in VM code
30
31 // The design is that when an oop is declared on the stack as a local
32 // variable, the oop is actually a C++ struct with constructor and
33 // destructor. The constructor adds the oop address on a list
34 // off each thread and the destructor removes the oop. At a potential
35 // safepoint, the stack addresses of the local variable oops are trashed
36 // with a recognizeable value. If the local variable is used again, it
37 // will segfault, indicating an unsafe use of that oop.
38 // eg:
39 // oop o; //register &o on list
40 // funct(); // if potential safepoint - causes clear_naked_oops()
41 // // which trashes o above.
42 // o->do_something(); // Crashes because o is unsafe.
43 //
44 // This code implements the details of the unhandled oop list on the thread.
45 //
46
67 Thread* _thread;
68 int _level;
69 GrowableArray<UnhandledOopEntry> *_oop_list;
70 void allow_unhandled_oop(oop* op);
71 void clear_unhandled_oops();
72 UnhandledOops(Thread* thread);
73 ~UnhandledOops();
74
75 public:
76 static void dump_oops(UnhandledOops* list);
77 void register_unhandled_oop(oop* op, address pc);
78 void unregister_unhandled_oop(oop* op);
79 };
80
81 #ifdef _LP64
82 const intptr_t BAD_OOP_ADDR = 0xfffffffffffffff1;
83 #else
84 const intptr_t BAD_OOP_ADDR = 0xfffffff1;
85 #endif // _LP64
86 #endif // CHECK_UNHANDLED_OOPS
87
88 #endif // SHARE_VM_RUNTIME_UNHANDLEDOOPS_HPP
|