Thu, 15 Apr 2010 02:40:12 -0700
6941224: Improved stack overflow handling for Zero
Summary: Adding stack overflow checking to Shark brought to light a bunch of deficiencies in Zero's stack overflow code.
Reviewed-by: twisti
Contributed-by: Gary Benson <gbenson@redhat.com>
1 /*
2 * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved.
3 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 */
26 private:
27 ZeroStack _zero_stack;
28 ZeroFrame* _top_zero_frame;
30 void pd_initialize() {
31 _top_zero_frame = NULL;
32 }
34 public:
35 ZeroStack *zero_stack() {
36 return &_zero_stack;
37 }
39 public:
40 ZeroFrame *top_zero_frame() {
41 return _top_zero_frame;
42 }
43 void push_zero_frame(ZeroFrame *frame) {
44 *(ZeroFrame **) frame = _top_zero_frame;
45 _top_zero_frame = frame;
46 }
47 void pop_zero_frame() {
48 zero_stack()->set_sp((intptr_t *) _top_zero_frame + 1);
49 _top_zero_frame = *(ZeroFrame **) _top_zero_frame;
50 }
52 public:
53 static ByteSize zero_stack_offset() {
54 return byte_offset_of(JavaThread, _zero_stack);
55 }
56 static ByteSize top_zero_frame_offset() {
57 return byte_offset_of(JavaThread, _top_zero_frame);
58 }
60 public:
61 void record_base_of_stack_pointer() {
62 assert(top_zero_frame() == NULL, "junk on stack prior to Java call");
63 }
64 void set_base_of_stack_pointer(intptr_t* base_sp) {
65 assert(base_sp == NULL, "should be");
66 assert(top_zero_frame() == NULL, "junk on stack after Java call");
67 }
69 public:
70 void set_last_Java_frame() {
71 set_last_Java_frame(top_zero_frame());
72 }
73 void reset_last_Java_frame() {
74 set_last_Java_frame(NULL);
75 }
76 void set_last_Java_frame(ZeroFrame* frame) {
77 frame_anchor()->set_last_Java_sp((intptr_t *) frame);
78 }
80 private:
81 frame pd_last_frame() {
82 assert(has_last_Java_frame(), "must have last_Java_sp() when suspended");
83 return frame(last_Java_sp(), zero_stack()->sp());
84 }
86 public:
87 // Check for pending suspend requests and pending asynchronous
88 // exceptions. There are separate accessors for these, but
89 // _suspend_flags is volatile so using them would be unsafe.
90 bool has_special_condition_for_native_trans() {
91 return _suspend_flags != 0;
92 }
94 public:
95 bool pd_get_top_frame_for_signal_handler(frame* fr_addr,
96 void* ucontext,
97 bool isInJava) {
98 ShouldNotCallThis();
99 }
101 // These routines are only used on cpu architectures that
102 // have separate register stacks (Itanium).
103 static bool register_stack_overflow() { return false; }
104 static void enable_register_stack_guard() {}
105 static void disable_register_stack_guard() {}