hotspot/src/cpu/x86/vm/runtime_x86_32.cpp
author twisti
Thu, 08 Apr 2010 10:55:40 +0200
changeset 5252 58f23871a5b6
parent 4564 55dfb20908d0
child 5690 796ff3814b23
child 5547 f4b087cbb361
permissions -rw-r--r--
6941529: SharedRuntime::raw_exception_handler_for_return_address must reset thread MethodHandle flag Summary: During testing a bug was hit when an exception returned to the interpreter and the SP was wrong. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 1888
diff changeset
     2
 * Copyright 1998-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
#include "incls/_runtime_x86_32.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
#define __ masm->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
ExceptionBlob*     OptoRuntime::_exception_blob;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//------------------------------generate_exception_blob---------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// creates exception blob at the end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// Using exception blob, this code is jumped from a compiled method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Given an exception pc at a call we call into the runtime for the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// handler in this method. This handler might merely restore state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// (i.e. callee save registers) unwind the frame and jump to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// exception handler for the nmethod if there is no Java level handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// for the nmethod.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// This code is entered with a jmp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// Arguments:
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 2105
diff changeset
    46
//   rax: exception oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//   rdx: exception pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// Results:
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 2105
diff changeset
    50
//   rax: exception oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
//   rdx: exception pc in caller or ???
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
//   destination: exception handler of caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// Note: the exception pc MUST be at a call (precise debug information)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
//       Only register rax, rdx, rcx are not callee saved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
void OptoRuntime::generate_exception_blob() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // Capture info about frame layout
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  enum layout {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    thread_off,                 // last_java_sp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    // The frame sender code expects that rbp will be in the "natural" place and
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    // will override any oopMap setting for it. We must therefore force the layout
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    // so that it agrees with the frame sender code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    rbp_off,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    return_off,                 // slot for return address
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    framesize
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // allocate space for the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // setup code generation tools
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  CodeBuffer   buffer("exception_blob", 512, 512);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  MacroAssembler* masm = new MacroAssembler(&buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  OopMapSet *oop_maps = new OopMapSet();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  address start = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
    81
  __ push(rdx);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
    82
  __ subptr(rsp, return_off * wordSize);   // Prolog!
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // rbp, location is implicitly known
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
    85
  __ movptr(Address(rsp,rbp_off  *wordSize), rbp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Store exception in Thread object. We cannot pass any arguments to the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // handle_exception call, since we do not want to make any assumption
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  // about the size of the frame where the exception happened in.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  __ get_thread(rcx);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
    91
  __ movptr(Address(rcx, JavaThread::exception_oop_offset()), rax);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
    92
  __ movptr(Address(rcx, JavaThread::exception_pc_offset()),  rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // This call does all the hard work.  It checks if an exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // exists in the method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  // If so, it returns the handler address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // If not, it prepares for stack-unwinding, restoring the callee-save
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // registers of the frame being removed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  //
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   100
  __ movptr(Address(rsp, thread_off * wordSize), rcx); // Thread is first argument
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  __ set_last_Java_frame(rcx, noreg, noreg, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  // No registers to map, rbp is known implicitly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  oop_maps->add_gc_map( __ pc() - start,  new OopMap( framesize, 0 ));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  __ get_thread(rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  __ reset_last_Java_frame(rcx, false, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // Restore callee-saved registers
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   111
  __ movptr(rbp, Address(rsp, rbp_off * wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   113
  __ addptr(rsp, return_off * wordSize);   // Epilog!
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   114
  __ pop(rdx); // Exception pc
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 2105
diff changeset
   116
  // rax: exception handler for given <exception oop/exception pc>
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
5252
58f23871a5b6 6941529: SharedRuntime::raw_exception_handler_for_return_address must reset thread MethodHandle flag
twisti
parents: 4564
diff changeset
   118
  // Restore SP from BP if the exception PC is a MethodHandle call site.
58f23871a5b6 6941529: SharedRuntime::raw_exception_handler_for_return_address must reset thread MethodHandle flag
twisti
parents: 4564
diff changeset
   119
  __ cmpl(Address(rcx, JavaThread::is_method_handle_return_offset()), 0);
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 2105
diff changeset
   120
  __ cmovptr(Assembler::notEqual, rsp, rbp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // We have a handler in rax, (could be deopt blob)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  // rdx - throwing pc, deopt blob will need it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   125
  __ push(rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Get the exception
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   128
  __ movptr(rax, Address(rcx, JavaThread::exception_oop_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Get the exception pc in case we are deoptimized
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   130
  __ movptr(rdx, Address(rcx, JavaThread::exception_pc_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
#ifdef ASSERT
1888
bbf498fb4354 6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t
xlu
parents: 1217
diff changeset
   132
  __ movptr(Address(rcx, JavaThread::exception_handler_pc_offset()), NULL_WORD);
bbf498fb4354 6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t
xlu
parents: 1217
diff changeset
   133
  __ movptr(Address(rcx, JavaThread::exception_pc_offset()), NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  // Clear the exception oop so GC no longer processes it as a root.
1888
bbf498fb4354 6787106: Hotspot 32 bit build fails on platforms having different definitions for intptr_t & int32_t
xlu
parents: 1217
diff changeset
   136
  __ movptr(Address(rcx, JavaThread::exception_oop_offset()), NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 1
diff changeset
   138
  __ pop(rcx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 2105
diff changeset
   140
  // rax: exception oop
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // rcx: exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // rdx: exception pc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  __ jmp (rcx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // -------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  // make sure all code is generated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  masm->flush();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
}