32 #include "runtime/frame.inline.hpp" 33 #include "runtime/handles.inline.hpp" 34 #include "runtime/javaCalls.hpp" 35 #include "runtime/monitorChunk.hpp" 36 #include "runtime/signature.hpp" 37 #include "runtime/stubCodeGenerator.hpp" 38 #include "runtime/stubRoutines.hpp" 39 #include "vmreg_ppc.inline.hpp" 40 #ifdef COMPILER1 41 #include "c1/c1_Runtime1.hpp" 42 #include "runtime/vframeArray.hpp" 43 #endif 44 45 #ifdef ASSERT 46 void RegisterMap::check_location_valid() { 47 } 48 #endif // ASSERT 49 50 bool frame::safe_for_sender(JavaThread *thread) { 51 bool safe = false; 52 address cursp = (address)sp(); 53 address curfp = (address)fp(); 54 if ((cursp != NULL && curfp != NULL && 55 (cursp <= thread->stack_base() && cursp >= thread->stack_base() - thread->stack_size())) && 56 (curfp <= thread->stack_base() && curfp >= thread->stack_base() - thread->stack_size())) { 57 safe = true; 58 } 59 return safe; 60 } 61 62 bool frame::is_interpreted_frame() const { 63 return Interpreter::contains(pc()); 64 } 65 66 frame frame::sender_for_entry_frame(RegisterMap *map) const { 67 assert(map != NULL, "map must be set"); 68 // Java frame called from C; skip all C frames and return top C 69 // frame of that chunk as the sender. 70 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 71 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 72 assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack"); 73 map->clear(); 74 assert(map->include_argument_oops(), "should be set by clear"); 75 76 if (jfa->last_Java_pc() != NULL) { 77 frame fr(jfa->last_Java_sp(), jfa->last_Java_pc()); 78 return fr; 79 } | 32 #include "runtime/frame.inline.hpp" 33 #include "runtime/handles.inline.hpp" 34 #include "runtime/javaCalls.hpp" 35 #include "runtime/monitorChunk.hpp" 36 #include "runtime/signature.hpp" 37 #include "runtime/stubCodeGenerator.hpp" 38 #include "runtime/stubRoutines.hpp" 39 #include "vmreg_ppc.inline.hpp" 40 #ifdef COMPILER1 41 #include "c1/c1_Runtime1.hpp" 42 #include "runtime/vframeArray.hpp" 43 #endif 44 45 #ifdef ASSERT 46 void RegisterMap::check_location_valid() { 47 } 48 #endif // ASSERT 49 50 bool frame::safe_for_sender(JavaThread *thread) { 51 bool safe = false; 52 address sp = (address)_sp; 53 address fp = (address)_fp; 54 address unextended_sp = (address)_unextended_sp; 55 56 // Consider stack guards when trying to determine "safe" stack pointers 57 static size_t stack_guard_size = os::uses_stack_guard_pages() ? 58 thread->stack_red_zone_size() + thread->stack_yellow_zone_size() : 0; 59 size_t usable_stack_size = thread->stack_size() - stack_guard_size; 60 61 // sp must be within the usable part of the stack (not in guards) 62 bool sp_safe = (sp < thread->stack_base()) && 63 (sp >= thread->stack_base() - usable_stack_size); 64 65 66 if (!sp_safe) { 67 return false; 68 } 69 70 // Unextended sp must be within the stack and above or equal sp 71 bool unextended_sp_safe = (unextended_sp < thread->stack_base()) && (unextended_sp >= sp); 72 73 if (!unextended_sp_safe) { 74 return false; 75 } 76 77 // An fp must be within the stack and above (but not equal) sp. 78 bool fp_safe = (fp <= thread->stack_base()) && (fp > sp); 79 // an interpreter fp must be within the stack and above (but not equal) sp 80 bool fp_interp_safe = (fp <= thread->stack_base()) && (fp > sp) && 81 ((fp - sp) >= (ijava_state_size + top_ijava_frame_abi_size)); 82 83 // We know sp/unextended_sp are safe, only fp is questionable here 84 85 // If the current frame is known to the code cache then we can attempt to 86 // to construct the sender and do some validation of it. This goes a long way 87 // toward eliminating issues when we get in frame construction code 88 89 if (_cb != NULL ){ 90 // Entry frame checks 91 if (is_entry_frame()) { 92 // An entry frame must have a valid fp. 93 return fp_safe && is_entry_frame_valid(thread); 94 } 95 96 // Now check if the frame is complete and the test is 97 // reliable. Unfortunately we can only check frame completeness for 98 // runtime stubs and nmethods. Other generic buffer blobs are more 99 // problematic so we just assume they are OK. Adapter blobs never have a 100 // complete frame and are never OK 101 if (!_cb->is_frame_complete_at(_pc)) { 102 if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) { 103 return false; 104 } 105 } 106 107 // Could just be some random pointer within the codeBlob. 108 if (!_cb->code_contains(_pc)) { 109 return false; 110 } 111 112 if (is_interpreted_frame() && !fp_interp_safe) { 113 return false; 114 } 115 116 abi_minframe* sender_abi = (abi_minframe*) fp; 117 intptr_t* sender_sp = (intptr_t*) fp; 118 address sender_pc = (address) sender_abi->lr;; 119 120 // We must always be able to find a recognizable pc. 121 CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc); 122 if (sender_blob == NULL) { 123 return false; 124 } 125 126 // Could be a zombie method 127 if (sender_blob->is_zombie() || sender_blob->is_unloaded()) { 128 return false; 129 } 130 131 // It should be safe to construct the sender though it might not be valid. 132 133 frame sender(sender_sp, sender_pc); 134 135 // Do we have a valid fp? 136 address sender_fp = (address) sender.fp(); 137 138 // sender_fp must be within the stack and above (but not 139 // equal) current frame's fp. 140 if (sender_fp > thread->stack_base() || sender_fp <= fp) { 141 return false; 142 } 143 144 // If the potential sender is the interpreter then we can do some more checking. 145 if (Interpreter::contains(sender_pc)) { 146 return sender.is_interpreted_frame_valid(thread); 147 } 148 149 // Could just be some random pointer within the codeBlob. 150 if (!sender.cb()->code_contains(sender_pc)) { 151 return false; 152 } 153 154 // We should never be able to see an adapter if the current frame is something from code cache. 155 if (sender_blob->is_adapter_blob()) { 156 return false; 157 } 158 159 if (sender.is_entry_frame()) { 160 return sender.is_entry_frame_valid(thread); 161 } 162 163 // Frame size is always greater than zero. If the sender frame size is zero or less, 164 // something is really weird and we better give up. 165 if (sender_blob->frame_size() <= 0) { 166 return false; 167 } 168 169 return true; 170 } 171 172 // Must be native-compiled frame. Since sender will try and use fp to find 173 // linkages it must be safe 174 175 if (!fp_safe) { 176 return false; 177 } 178 179 return true; 180 } 181 182 bool frame::is_interpreted_frame() const { 183 return Interpreter::contains(pc()); 184 } 185 186 frame frame::sender_for_entry_frame(RegisterMap *map) const { 187 assert(map != NULL, "map must be set"); 188 // Java frame called from C; skip all C frames and return top C 189 // frame of that chunk as the sender. 190 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor(); 191 assert(!entry_frame_is_first(), "next Java fp must be non zero"); 192 assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack"); 193 map->clear(); 194 assert(map->include_argument_oops(), "should be set by clear"); 195 196 if (jfa->last_Java_pc() != NULL) { 197 frame fr(jfa->last_Java_sp(), jfa->last_Java_pc()); 198 return fr; 199 } |