runtime_x86_32.cpp 5.6 KB
Newer Older
D
duke 已提交
1
/*
2
 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include "precompiled.hpp"
#ifdef COMPILER2
#include "asm/assembler.hpp"
#include "assembler_x86.inline.hpp"
#include "classfile/systemDictionary.hpp"
#include "code/vmreg.hpp"
#include "interpreter/interpreter.hpp"
#include "nativeInst_x86.hpp"
#include "opto/runtime.hpp"
#include "runtime/interfaceSupport.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stubRoutines.hpp"
#include "runtime/vframeArray.hpp"
#include "utilities/globalDefinitions.hpp"
#include "vmreg_x86.inline.hpp"
#endif
D
duke 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57


#define __ masm->

//------------------------------generate_exception_blob---------------------------
// creates exception blob at the end
// Using exception blob, this code is jumped from a compiled method.
//
// Given an exception pc at a call we call into the runtime for the
// handler in this method. This handler might merely restore state
// (i.e. callee save registers) unwind the frame and jump to the
// exception handler for the nmethod if there is no Java level handler
// for the nmethod.
//
// This code is entered with a jmp.
//
// Arguments:
58
//   rax: exception oop
D
duke 已提交
59 60 61
//   rdx: exception pc
//
// Results:
62
//   rax: exception oop
D
duke 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
//   rdx: exception pc in caller or ???
//   destination: exception handler of caller
//
// Note: the exception pc MUST be at a call (precise debug information)
//       Only register rax, rdx, rcx are not callee saved.
//

void OptoRuntime::generate_exception_blob() {

  // Capture info about frame layout
  enum layout {
    thread_off,                 // last_java_sp
    // The frame sender code expects that rbp will be in the "natural" place and
    // will override any oopMap setting for it. We must therefore force the layout
    // so that it agrees with the frame sender code.
    rbp_off,
    return_off,                 // slot for return address
    framesize
  };

  // allocate space for the code
  ResourceMark rm;
  // setup code generation tools
  CodeBuffer   buffer("exception_blob", 512, 512);
  MacroAssembler* masm = new MacroAssembler(&buffer);

  OopMapSet *oop_maps = new OopMapSet();

  address start = __ pc();

93 94
  __ push(rdx);
  __ subptr(rsp, return_off * wordSize);   // Prolog!
D
duke 已提交
95 96

  // rbp, location is implicitly known
97
  __ movptr(Address(rsp,rbp_off  *wordSize), rbp);
D
duke 已提交
98 99 100 101 102

  // Store exception in Thread object. We cannot pass any arguments to the
  // handle_exception call, since we do not want to make any assumption
  // about the size of the frame where the exception happened in.
  __ get_thread(rcx);
103 104
  __ movptr(Address(rcx, JavaThread::exception_oop_offset()), rax);
  __ movptr(Address(rcx, JavaThread::exception_pc_offset()),  rdx);
D
duke 已提交
105 106 107 108 109 110 111

  // This call does all the hard work.  It checks if an exception handler
  // exists in the method.
  // If so, it returns the handler address.
  // If not, it prepares for stack-unwinding, restoring the callee-save
  // registers of the frame being removed.
  //
112
  __ movptr(Address(rsp, thread_off * wordSize), rcx); // Thread is first argument
D
duke 已提交
113 114 115 116 117 118 119 120 121 122
  __ set_last_Java_frame(rcx, noreg, noreg, NULL);

  __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));

  // No registers to map, rbp is known implicitly
  oop_maps->add_gc_map( __ pc() - start,  new OopMap( framesize, 0 ));
  __ get_thread(rcx);
  __ reset_last_Java_frame(rcx, false, false);

  // Restore callee-saved registers
123
  __ movptr(rbp, Address(rsp, rbp_off * wordSize));
D
duke 已提交
124

125 126
  __ addptr(rsp, return_off * wordSize);   // Epilog!
  __ pop(rdx); // Exception pc
D
duke 已提交
127

128
  // rax: exception handler for given <exception oop/exception pc>
D
duke 已提交
129

130 131
  // Restore SP from BP if the exception PC is a MethodHandle call site.
  __ cmpl(Address(rcx, JavaThread::is_method_handle_return_offset()), 0);
132
  __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save);
D
duke 已提交
133 134 135 136

  // We have a handler in rax, (could be deopt blob)
  // rdx - throwing pc, deopt blob will need it.

137
  __ push(rax);
D
duke 已提交
138 139

  // Get the exception
140
  __ movptr(rax, Address(rcx, JavaThread::exception_oop_offset()));
D
duke 已提交
141
  // Get the exception pc in case we are deoptimized
142
  __ movptr(rdx, Address(rcx, JavaThread::exception_pc_offset()));
D
duke 已提交
143
#ifdef ASSERT
144 145
  __ movptr(Address(rcx, JavaThread::exception_handler_pc_offset()), NULL_WORD);
  __ movptr(Address(rcx, JavaThread::exception_pc_offset()), NULL_WORD);
D
duke 已提交
146 147
#endif
  // Clear the exception oop so GC no longer processes it as a root.
148
  __ movptr(Address(rcx, JavaThread::exception_oop_offset()), NULL_WORD);
D
duke 已提交
149

150
  __ pop(rcx);
D
duke 已提交
151

152
  // rax: exception oop
D
duke 已提交
153 154 155 156 157 158 159 160 161 162
  // rcx: exception handler
  // rdx: exception pc
  __ jmp (rcx);

  // -------------
  // make sure all code is generated
  masm->flush();

  _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize);
}