Mercurial > hg > graal-compiler
comparison src/cpu/x86/vm/frame_x86.cpp @ 1200:ba263cfb7611
6917766: JSR 292 needs its own deopt handler
Summary: We need to introduce a new MH deopt handler so we can easily determine if the deopt happened at a MH call site or not.
Reviewed-by: never, jrose
author | twisti |
---|---|
date | Fri, 29 Jan 2010 12:13:05 +0100 |
parents | e66fd840cb6b |
children | 24128c2ffa87 |
comparison
equal
deleted
inserted
replaced
1199:0e14bd797dad | 1200:ba263cfb7611 |
---|---|
1 /* | 1 /* |
2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
220 tty->print_cr("patch_pc at address" INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "] ", | 220 tty->print_cr("patch_pc at address" INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "] ", |
221 &((address *)sp())[-1], ((address *)sp())[-1], pc); | 221 &((address *)sp())[-1], ((address *)sp())[-1], pc); |
222 } | 222 } |
223 ((address *)sp())[-1] = pc; | 223 ((address *)sp())[-1] = pc; |
224 _cb = CodeCache::find_blob(pc); | 224 _cb = CodeCache::find_blob(pc); |
225 if (_cb != NULL && _cb->is_nmethod() && ((nmethod*)_cb)->is_deopt_pc(_pc)) { | 225 address original_pc = nmethod::get_deopt_original_pc(this); |
226 address orig = (((nmethod*)_cb)->get_original_pc(this)); | 226 if (original_pc != NULL) { |
227 assert(orig == _pc, "expected original to be stored before patching"); | 227 assert(original_pc == _pc, "expected original PC to be stored before patching"); |
228 _deopt_state = is_deoptimized; | 228 _deopt_state = is_deoptimized; |
229 // leave _pc as is | 229 // leave _pc as is |
230 } else { | 230 } else { |
231 _deopt_state = not_deoptimized; | 231 _deopt_state = not_deoptimized; |
232 _pc = pc; | 232 _pc = pc; |
321 } | 321 } |
322 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp()); | 322 frame fr(jfa->last_Java_sp(), jfa->last_Java_fp()); |
323 return fr; | 323 return fr; |
324 } | 324 } |
325 | 325 |
326 | |
327 //------------------------------------------------------------------------------ | |
328 // frame::sender_for_interpreter_frame | |
326 frame frame::sender_for_interpreter_frame(RegisterMap* map) const { | 329 frame frame::sender_for_interpreter_frame(RegisterMap* map) const { |
327 // sp is the raw sp from the sender after adapter or interpreter extension | 330 // SP is the raw SP from the sender after adapter or interpreter |
328 intptr_t* sp = (intptr_t*) addr_at(sender_sp_offset); | 331 // extension. |
332 intptr_t* sender_sp = this->sender_sp(); | |
329 | 333 |
330 // This is the sp before any possible extension (adapter/locals). | 334 // This is the sp before any possible extension (adapter/locals). |
331 intptr_t* unextended_sp = interpreter_frame_sender_sp(); | 335 intptr_t* unextended_sp = interpreter_frame_sender_sp(); |
336 | |
337 // Stored FP. | |
338 intptr_t* saved_fp = link(); | |
332 | 339 |
333 address sender_pc = this->sender_pc(); | 340 address sender_pc = this->sender_pc(); |
334 CodeBlob* sender_cb = CodeCache::find_blob_unsafe(sender_pc); | 341 CodeBlob* sender_cb = CodeCache::find_blob_unsafe(sender_pc); |
335 assert(sender_cb, "sanity"); | 342 assert(sender_cb, "sanity"); |
336 nmethod* sender_nm = sender_cb->as_nmethod_or_null(); | 343 nmethod* sender_nm = sender_cb->as_nmethod_or_null(); |
337 if (sender_nm != NULL && sender_nm->is_method_handle_return(sender_pc)) { | 344 |
338 unextended_sp = (intptr_t*) at(link_offset); | 345 if (sender_nm != NULL) { |
346 // If the sender PC is a deoptimization point, get the original | |
347 // PC. For MethodHandle call site the unextended_sp is stored in | |
348 // saved_fp. | |
349 if (sender_nm->is_deopt_mh_entry(sender_pc)) { | |
350 DEBUG_ONLY(verify_deopt_mh_original_pc(sender_nm, saved_fp)); | |
351 unextended_sp = saved_fp; | |
352 } | |
353 else if (sender_nm->is_deopt_entry(sender_pc)) { | |
354 DEBUG_ONLY(verify_deopt_original_pc(sender_nm, unextended_sp)); | |
355 } | |
356 else if (sender_nm->is_method_handle_return(sender_pc)) { | |
357 unextended_sp = saved_fp; | |
358 } | |
339 } | 359 } |
340 | 360 |
341 // The interpreter and compiler(s) always save EBP/RBP in a known | 361 // The interpreter and compiler(s) always save EBP/RBP in a known |
342 // location on entry. We must record where that location is | 362 // location on entry. We must record where that location is |
343 // so this if EBP/RBP was live on callout from c2 we can find | 363 // so this if EBP/RBP was live on callout from c2 we can find |
357 if (true) { | 377 if (true) { |
358 map->set_location(rbp->as_VMReg()->next(), (address)addr_at(link_offset)); | 378 map->set_location(rbp->as_VMReg()->next(), (address)addr_at(link_offset)); |
359 } | 379 } |
360 #endif // AMD64 | 380 #endif // AMD64 |
361 } | 381 } |
362 #endif /* COMPILER2 */ | 382 #endif // COMPILER2 |
363 return frame(sp, unextended_sp, link(), sender_pc); | 383 |
364 } | 384 return frame(sender_sp, unextended_sp, saved_fp, sender_pc); |
365 | 385 } |
366 | 386 |
367 //------------------------------sender_for_compiled_frame----------------------- | 387 |
388 //------------------------------------------------------------------------------ | |
389 // frame::sender_for_compiled_frame | |
368 frame frame::sender_for_compiled_frame(RegisterMap* map) const { | 390 frame frame::sender_for_compiled_frame(RegisterMap* map) const { |
369 assert(map != NULL, "map must be set"); | 391 assert(map != NULL, "map must be set"); |
370 const bool c1_compiled = _cb->is_compiled_by_c1(); | |
371 | 392 |
372 // frame owned by optimizing compiler | 393 // frame owned by optimizing compiler |
373 intptr_t* sender_sp = NULL; | |
374 | |
375 assert(_cb->frame_size() >= 0, "must have non-zero frame size"); | 394 assert(_cb->frame_size() >= 0, "must have non-zero frame size"); |
376 sender_sp = unextended_sp() + _cb->frame_size(); | 395 intptr_t* sender_sp = unextended_sp() + _cb->frame_size(); |
396 intptr_t* unextended_sp = sender_sp; | |
377 | 397 |
378 // On Intel the return_address is always the word on the stack | 398 // On Intel the return_address is always the word on the stack |
379 address sender_pc = (address) *(sender_sp-1); | 399 address sender_pc = (address) *(sender_sp-1); |
380 | 400 |
381 // This is the saved value of ebp which may or may not really be an fp. | 401 // This is the saved value of EBP which may or may not really be an FP. |
382 // it is only an fp if the sender is an interpreter frame (or c1?) | 402 // It is only an FP if the sender is an interpreter frame (or C1?). |
383 | 403 intptr_t* saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset); |
384 intptr_t *saved_fp = (intptr_t*)*(sender_sp - frame::sender_sp_offset); | 404 |
385 | 405 // If we are returning to a compiled MethodHandle call site, the |
386 intptr_t* unextended_sp = sender_sp; | 406 // saved_fp will in fact be a saved value of the unextended SP. The |
387 // If we are returning to a compiled method handle call site, | 407 // simplest way to tell whether we are returning to such a call site |
388 // the saved_fp will in fact be a saved value of the unextended SP. | 408 // is as follows: |
389 // The simplest way to tell whether we are returning to such a call | |
390 // site is as follows: | |
391 CodeBlob* sender_cb = CodeCache::find_blob_unsafe(sender_pc); | 409 CodeBlob* sender_cb = CodeCache::find_blob_unsafe(sender_pc); |
392 assert(sender_cb, "sanity"); | 410 assert(sender_cb, "sanity"); |
393 nmethod* sender_nm = sender_cb->as_nmethod_or_null(); | 411 nmethod* sender_nm = sender_cb->as_nmethod_or_null(); |
394 if (sender_nm != NULL && sender_nm->is_method_handle_return(sender_pc)) { | 412 |
395 unextended_sp = saved_fp; | 413 if (sender_nm != NULL) { |
414 // If the sender PC is a deoptimization point, get the original | |
415 // PC. For MethodHandle call site the unextended_sp is stored in | |
416 // saved_fp. | |
417 if (sender_nm->is_deopt_mh_entry(sender_pc)) { | |
418 DEBUG_ONLY(verify_deopt_mh_original_pc(sender_nm, saved_fp)); | |
419 unextended_sp = saved_fp; | |
420 } | |
421 else if (sender_nm->is_deopt_entry(sender_pc)) { | |
422 DEBUG_ONLY(verify_deopt_original_pc(sender_nm, unextended_sp)); | |
423 } | |
424 else if (sender_nm->is_method_handle_return(sender_pc)) { | |
425 unextended_sp = saved_fp; | |
426 } | |
396 } | 427 } |
397 | 428 |
398 if (map->update_map()) { | 429 if (map->update_map()) { |
399 // Tell GC to use argument oopmaps for some runtime stubs that need it. | 430 // Tell GC to use argument oopmaps for some runtime stubs that need it. |
400 // For C1, the runtime stub might not have oop maps, so set this flag | 431 // For C1, the runtime stub might not have oop maps, so set this flag |
401 // outside of update_register_map. | 432 // outside of update_register_map. |
402 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); | 433 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread())); |
403 if (_cb->oop_maps() != NULL) { | 434 if (_cb->oop_maps() != NULL) { |
404 OopMapSet::update_register_map(this, map); | 435 OopMapSet::update_register_map(this, map); |
405 } | 436 } |
406 // Since the prolog does the save and restore of epb there is no oopmap | 437 // Since the prolog does the save and restore of EBP there is no oopmap |
407 // for it so we must fill in its location as if there was an oopmap entry | 438 // for it so we must fill in its location as if there was an oopmap entry |
408 // since if our caller was compiled code there could be live jvm state in it. | 439 // since if our caller was compiled code there could be live jvm state in it. |
409 map->set_location(rbp->as_VMReg(), (address) (sender_sp - frame::sender_sp_offset)); | 440 map->set_location(rbp->as_VMReg(), (address) (sender_sp - frame::sender_sp_offset)); |
410 #ifdef AMD64 | 441 #ifdef AMD64 |
411 // this is weird "H" ought to be at a higher address however the | 442 // this is weird "H" ought to be at a higher address however the |
420 | 451 |
421 assert(sender_sp != sp(), "must have changed"); | 452 assert(sender_sp != sp(), "must have changed"); |
422 return frame(sender_sp, unextended_sp, saved_fp, sender_pc); | 453 return frame(sender_sp, unextended_sp, saved_fp, sender_pc); |
423 } | 454 } |
424 | 455 |
456 | |
457 //------------------------------------------------------------------------------ | |
458 // frame::sender | |
425 frame frame::sender(RegisterMap* map) const { | 459 frame frame::sender(RegisterMap* map) const { |
426 // Default is we done have to follow them. The sender_for_xxx will | 460 // Default is we done have to follow them. The sender_for_xxx will |
427 // update it accordingly | 461 // update it accordingly |
428 map->set_include_argument_oops(false); | 462 map->set_include_argument_oops(false); |
429 | 463 |