Mon, 03 Jan 2011 14:09:11 -0500
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
Summary: enhance the error reporting mechanism to help user to fix the problem rather than making it look like a VM error.
Reviewed-by: kvn, kamg
1 /*
2 * Copyright (c) 2002, 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 */
25 #ifndef SHARE_VM_RUNTIME_REGISTERMAP_HPP
26 #define SHARE_VM_RUNTIME_REGISTERMAP_HPP
28 #include "code/vmreg.hpp"
29 #include "utilities/globalDefinitions.hpp"
30 #ifdef TARGET_ARCH_x86
31 # include "register_x86.hpp"
32 #endif
33 #ifdef TARGET_ARCH_sparc
34 # include "register_sparc.hpp"
35 #endif
36 #ifdef TARGET_ARCH_zero
37 # include "register_zero.hpp"
38 #endif
40 class JavaThread;
42 //
43 // RegisterMap
44 //
45 // A companion structure used for stack traversal. The RegisterMap contains
46 // misc. information needed in order to do correct stack traversal of stack
47 // frames. Hence, it must always be passed in as an argument to
48 // frame::sender(RegisterMap*).
49 //
50 // In particular,
51 // 1) It provides access to the thread for which the stack belongs. The
52 // thread object is needed in order to get sender of a deoptimized frame.
53 //
54 // 2) It is used to pass information from a callee frame to its caller
55 // frame about how the frame should be traversed. This is used to let
56 // the caller frame take care of calling oops-do of out-going
57 // arguments, when the callee frame is not instantiated yet. This
58 // happens, e.g., when a compiled frame calls into
59 // resolve_virtual_call. (Hence, it is critical that the same
60 // RegisterMap object is used for the entire stack walk. Normally,
61 // this is hidden by using the StackFrameStream.) This is used when
62 // doing follow_oops and oops_do.
63 //
64 // 3) The RegisterMap keeps track of the values of callee-saved registers
65 // from frame to frame (hence, the name). For some stack traversal the
66 // values of the callee-saved registers does not matter, e.g., if you
67 // only need the static properies such as frame type, pc, and such.
68 // Updating of the RegisterMap can be turned off by instantiating the
69 // register map as: RegisterMap map(thread, false);
71 class RegisterMap : public StackObj {
72 public:
73 typedef julong LocationValidType;
74 enum {
75 reg_count = ConcreteRegisterImpl::number_of_registers,
76 location_valid_type_size = sizeof(LocationValidType)*8,
77 location_valid_size = (reg_count+location_valid_type_size-1)/location_valid_type_size
78 };
79 private:
80 intptr_t* _location[reg_count]; // Location of registers (intptr_t* looks better than address in the debugger)
81 LocationValidType _location_valid[location_valid_size];
82 bool _include_argument_oops; // Should include argument_oop marked locations for compiler
83 JavaThread* _thread; // Reference to current thread
84 bool _update_map; // Tells if the register map need to be
85 // updated when traversing the stack
87 #ifdef ASSERT
88 void check_location_valid();
89 #else
90 void check_location_valid() {}
91 #endif
93 public:
94 debug_only(intptr_t* _update_for_id;) // Assert that RegisterMap is not updated twice for same frame
95 RegisterMap(JavaThread *thread, bool update_map = true);
96 RegisterMap(const RegisterMap* map);
98 address location(VMReg reg) const {
99 int index = reg->value() / location_valid_type_size;
100 assert(0 <= reg->value() && reg->value() < reg_count, "range check");
101 assert(0 <= index && index < location_valid_size, "range check");
102 if (_location_valid[index] & ((LocationValidType)1 << (reg->value() % location_valid_type_size))) {
103 return (address) _location[reg->value()];
104 } else {
105 return pd_location(reg);
106 }
107 }
109 void set_location(VMReg reg, address loc) {
110 int index = reg->value() / location_valid_type_size;
111 assert(0 <= reg->value() && reg->value() < reg_count, "range check");
112 assert(0 <= index && index < location_valid_size, "range check");
113 assert(_update_map, "updating map that does not need updating");
114 _location[reg->value()] = (intptr_t*) loc;
115 _location_valid[index] |= ((LocationValidType)1 << (reg->value() % location_valid_type_size));
116 check_location_valid();
117 }
119 // Called by an entry frame.
120 void clear();
122 bool include_argument_oops() const { return _include_argument_oops; }
123 void set_include_argument_oops(bool f) { _include_argument_oops = f; }
125 JavaThread *thread() const { return _thread; }
126 bool update_map() const { return _update_map; }
128 void print_on(outputStream* st) const;
129 void print() const;
131 // the following contains the definition of pd_xxx methods
132 #ifdef TARGET_ARCH_x86
133 # include "registerMap_x86.hpp"
134 #endif
135 #ifdef TARGET_ARCH_sparc
136 # include "registerMap_sparc.hpp"
137 #endif
138 #ifdef TARGET_ARCH_zero
139 # include "registerMap_zero.hpp"
140 #endif
142 };
144 #endif // SHARE_VM_RUNTIME_REGISTERMAP_HPP