< prev index next >

src/hotspot/cpu/x86/runtime_x86_64.cpp

Print this page

  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 #include "precompiled.hpp"
 26 #ifdef COMPILER2
 27 #include "asm/macroAssembler.hpp"
 28 #include "asm/macroAssembler.inline.hpp"

 29 #include "code/vmreg.hpp"
 30 #include "interpreter/interpreter.hpp"
 31 #include "opto/runtime.hpp"
 32 #include "runtime/sharedRuntime.hpp"
 33 #include "runtime/stubRoutines.hpp"
 34 #include "runtime/vframeArray.hpp"
 35 #include "utilities/globalDefinitions.hpp"
 36 #include "vmreg_x86.inline.hpp"
 37 
 38 class SimpleRuntimeFrame {
 39 
 40   public:
 41 
 42   // Most of the runtime stubs have this simple frame layout.
 43   // This class exists to make the layout shared in one place.
 44   // Offsets are for compiler stack slots, which are jints.
 45   enum layout {
 46     // The frame sender code expects that rbp will be in the "natural" place and
 47     // will override any oopMap setting for it. We must therefore force the layout
 48     // so that it agrees with the frame sender code.

249 // Results:
250 //   rax: exception oop
251 //   rdx: exception pc in caller or ???
252 //   destination: exception handler of caller
253 //
254 // Note: the exception pc MUST be at a call (precise debug information)
255 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
256 //
257 
258 void OptoRuntime::generate_exception_blob() {
259   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
260   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
261   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
262 
263   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
264 
265   // Allocate space for the code
266   ResourceMark rm;
267   // Setup code generation tools
268   CodeBuffer buffer("exception_blob", 2048, 1024);
269   MacroAssembler* masm = new MacroAssembler(&buffer);
270 







271 

272   address start = __ pc();
273 
274   // Exception pc is 'return address' for stack walker
275   __ push(rdx);
276   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
277 
278   // Save callee-saved registers.  See x86_64.ad.
279 
280   // rbp is an implicitly saved callee saved register (i.e., the calling
281   // convention will save/restore it in the prolog/epilog). Other than that
282   // there are no callee save registers now that adapter frames are gone.
283 
284   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
285 
286   // Store exception in Thread object. We cannot pass any arguments to the
287   // handle_exception call, since we do not want to make any assumption
288   // about the size of the frame where the exception happened in.
289   // c_rarg0 is either rdi (Linux) or rcx (Windows).
290   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
291   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

297   // registers of the frame being removed.
298   //
299   // address OptoRuntime::handle_exception_C(JavaThread* thread)
300 
301   // At a method handle call, the stack may not be properly aligned
302   // when returning with an exception.
303   address the_pc = __ pc();
304   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
305   __ mov(c_rarg0, r15_thread);
306   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
307   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
308 
309   // Set an oopmap for the call site.  This oopmap will only be used if we
310   // are unwinding the stack.  Hence, all locations will be dead.
311   // Callee-saved registers will be the same as the frame above (i.e.,
312   // handle_exception_stub), since they were restored when we got the
313   // exception.
314 
315   OopMapSet* oop_maps = new OopMapSet();
316 
317   oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));

318 
319   __ reset_last_Java_frame(false);
320 
321   // Restore callee-saved registers
322 
323   // rbp is an implicitly saved callee-saved register (i.e., the calling
324   // convention will save restore it in prolog/epilog) Other than that
325   // there are no callee save registers now that adapter frames are gone.
326 
327   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
328 
329   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
330   __ pop(rdx);                  // No need for exception pc anymore
331 
332   // rax: exception handler
333 
334   // We have a handler in rax (could be deopt blob).
335   __ mov(r8, rax);
336 
337   // Get the exception oop
338   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
339   // Get the exception pc in case we are deoptimized
340   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
341 #ifdef ASSERT
342   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
343   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
344 #endif
345   // Clear the exception oop so GC no longer processes it as a root.
346   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
347 
348   // rax: exception oop
349   // r8:  exception handler
350   // rdx: exception pc
351   // Jump to handler
352 
353   __ jmp(r8);
354 
355   // Make sure all code is generated
356   masm->flush();
357 

358   // Set exception blob
359   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
360 }
361 #endif // COMPILER2

  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 #include "precompiled.hpp"
 26 #ifdef COMPILER2
 27 #include "asm/macroAssembler.hpp"
 28 #include "asm/macroAssembler.inline.hpp"
 29 #include "code/SCCache.hpp"
 30 #include "code/vmreg.hpp"
 31 #include "interpreter/interpreter.hpp"
 32 #include "opto/runtime.hpp"
 33 #include "runtime/sharedRuntime.hpp"
 34 #include "runtime/stubRoutines.hpp"
 35 #include "runtime/vframeArray.hpp"
 36 #include "utilities/globalDefinitions.hpp"
 37 #include "vmreg_x86.inline.hpp"
 38 
 39 class SimpleRuntimeFrame {
 40 
 41   public:
 42 
 43   // Most of the runtime stubs have this simple frame layout.
 44   // This class exists to make the layout shared in one place.
 45   // Offsets are for compiler stack slots, which are jints.
 46   enum layout {
 47     // The frame sender code expects that rbp will be in the "natural" place and
 48     // will override any oopMap setting for it. We must therefore force the layout
 49     // so that it agrees with the frame sender code.

250 // Results:
251 //   rax: exception oop
252 //   rdx: exception pc in caller or ???
253 //   destination: exception handler of caller
254 //
255 // Note: the exception pc MUST be at a call (precise debug information)
256 //       Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
257 //
258 
259 void OptoRuntime::generate_exception_blob() {
260   assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
261   assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
262   assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
263 
264   assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
265 
266   // Allocate space for the code
267   ResourceMark rm;
268   // Setup code generation tools
269   CodeBuffer buffer("exception_blob", 2048, 1024);
270   int pc_offset = 0;
271   if (SCCache::load_exception_blob(&buffer, &pc_offset)) {
272     OopMapSet* oop_maps = new OopMapSet();
273     oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
274 
275     // Set exception blob
276     _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
277     return;
278   }
279 
280   MacroAssembler* masm = new MacroAssembler(&buffer);
281   address start = __ pc();
282 
283   // Exception pc is 'return address' for stack walker
284   __ push(rdx);
285   __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
286 
287   // Save callee-saved registers.  See x86_64.ad.
288 
289   // rbp is an implicitly saved callee saved register (i.e., the calling
290   // convention will save/restore it in the prolog/epilog). Other than that
291   // there are no callee save registers now that adapter frames are gone.
292 
293   __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
294 
295   // Store exception in Thread object. We cannot pass any arguments to the
296   // handle_exception call, since we do not want to make any assumption
297   // about the size of the frame where the exception happened in.
298   // c_rarg0 is either rdi (Linux) or rcx (Windows).
299   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
300   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);

306   // registers of the frame being removed.
307   //
308   // address OptoRuntime::handle_exception_C(JavaThread* thread)
309 
310   // At a method handle call, the stack may not be properly aligned
311   // when returning with an exception.
312   address the_pc = __ pc();
313   __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
314   __ mov(c_rarg0, r15_thread);
315   __ andptr(rsp, -(StackAlignmentInBytes));    // Align stack
316   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
317 
318   // Set an oopmap for the call site.  This oopmap will only be used if we
319   // are unwinding the stack.  Hence, all locations will be dead.
320   // Callee-saved registers will be the same as the frame above (i.e.,
321   // handle_exception_stub), since they were restored when we got the
322   // exception.
323 
324   OopMapSet* oop_maps = new OopMapSet();
325 
326   pc_offset = the_pc - start;
327   oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
328 
329   __ reset_last_Java_frame(false);
330 
331   // Restore callee-saved registers
332 
333   // rbp is an implicitly saved callee-saved register (i.e., the calling
334   // convention will save restore it in prolog/epilog) Other than that
335   // there are no callee save registers now that adapter frames are gone.
336 
337   __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
338 
339   __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
340   __ pop(rdx);                  // No need for exception pc anymore
341 
342   // rax: exception handler
343 
344   // We have a handler in rax (could be deopt blob).
345   __ mov(r8, rax);
346 
347   // Get the exception oop
348   __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
349   // Get the exception pc in case we are deoptimized
350   __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
351 #ifdef ASSERT
352   __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
353   __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
354 #endif
355   // Clear the exception oop so GC no longer processes it as a root.
356   __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
357 
358   // rax: exception oop
359   // r8:  exception handler
360   // rdx: exception pc
361   // Jump to handler
362 
363   __ jmp(r8);
364 
365   // Make sure all code is generated
366   masm->flush();
367 
368   SCCache::store_exception_blob(&buffer, pc_offset);
369   // Set exception blob
370   _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
371 }
372 #endif // COMPILER2
< prev index next >