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