src/hotspot/cpu/s390/runtime_s390.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 42065 hotspot/src/cpu/s390/vm/runtime_s390.cpp@6032b31e3719
child 49449 ef5d5d343e2a
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42065
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     1
/*
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     3
 * Copyright (c) 2016 SAP SE. All rights reserved.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     5
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
     9
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    14
 * accompanied this code).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    15
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    19
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    22
 * questions.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    23
 *
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    24
 */
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    25
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    26
#include "precompiled.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    27
#ifdef COMPILER2
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    28
#include "asm/macroAssembler.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    29
#include "classfile/systemDictionary.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    30
#include "code/vmreg.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    31
#include "interpreter/interpreter.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    32
#include "memory/resourceArea.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    33
#include "nativeInst_s390.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    34
#include "opto/runtime.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    35
#include "runtime/interfaceSupport.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    36
#include "runtime/sharedRuntime.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    37
#include "runtime/stubRoutines.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    38
#include "runtime/vframeArray.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    39
#include "utilities/globalDefinitions.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    40
#include "vmreg_s390.inline.hpp"
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    41
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    42
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    43
#define __ masm->
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    44
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    45
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    46
//------------------------------generate_exception_blob---------------------------
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    47
// creates exception blob at the end
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    48
// Using exception blob, this code is jumped from a compiled method.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    49
// (see emit_exception_handler in s390.ad file)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    50
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    51
// Given an exception pc at a call we call into the runtime for the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    52
// handler in this method. This handler might merely restore state
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    53
// (i.e. callee save registers), unwind the frame, and jump to the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    54
// exception handler for the nmethod if there is no Java level handler
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    55
// for the nmethod.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    56
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    57
// This code is entered with a branch.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    58
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    59
// Arguments:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    60
//   Z_R2(=Z_ARG1): exception oop
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    61
//   Z_R3(=Z_ARG2): exception pc
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    62
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    63
// Results:
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    64
//   Z_R2: exception oop
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    65
//   Z_R3: exception pc in caller
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    66
//   destination: exception handler of caller
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    67
//
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    68
// Note: the exception pc MUST be at a call (precise debug information)
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    69
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    70
void OptoRuntime::generate_exception_blob() {
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    71
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    72
  // Allocate space for the code
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    73
  ResourceMark rm;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    74
  // Setup code generation tools
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    75
  CodeBuffer buffer("exception_blob", 2048, 1024);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    76
  MacroAssembler* masm = new MacroAssembler(&buffer);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    77
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    78
  Register handle_exception = Z_ARG5;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    79
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    80
  __ verify_thread();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    81
  __ z_stg(Z_ARG1/*exception oop*/, Address(Z_thread, JavaThread::exception_oop_offset()));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    82
  __ z_stg(Z_ARG2/*issuing pc*/,    Address(Z_thread, JavaThread::exception_pc_offset()));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    83
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    84
  // Store issuing pc as return pc into
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    85
  // caller's frame. stack-walking needs it. R14 is not valid here,
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    86
  // because this code gets entered with a jump.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    87
  __ z_stg(Z_ARG2/*issuing pc*/, _z_abi(return_pc), Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    88
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    89
  // The following call to function OptoRuntime::handle_exception_C
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    90
  // does all the hard work. It checks if an
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    91
  // exception catch exists in the method. If so, it returns the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    92
  // handler address. If the nmethod has been deoptimized and it had
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    93
  // a handler the handler address is the deopt blob's
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    94
  // unpack_with_exception entry.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    95
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    96
  // push a C frame for the exception blob. it is needed for the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    97
  // C call later on.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    98
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
    99
  Register saved_sp = Z_R11;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   100
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   101
  __ z_lgr(saved_sp, Z_SP);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   102
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   103
  // push frame for blob.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   104
  int frame_size = __ push_frame_abi160(0);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   105
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   106
  __ get_PC(Z_R1/*scratch*/);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   107
  __ set_last_Java_frame(/*sp=*/Z_SP, /*pc=*/Z_R1);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   108
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   109
  // This call can lead to deoptimization of the nmethod holding the handler.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   110
  __ z_lgr(Z_ARG1, Z_thread);   // argument of C function
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   111
  __ call_c(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   112
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   113
  __ z_lgr(handle_exception, Z_RET);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   114
  __ reset_last_Java_frame();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   115
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   116
  // Pop the exception blob's C frame that has been pushed before.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   117
  __ z_lgr(Z_SP, saved_sp);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   118
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   119
  // [Z_RET]!=NULL was possible in hotspot5 but not in sapjvm6.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   120
  // C2I adapter extensions are now removed by a resize in the frame manager
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   121
  // (unwind_initial_activation_pending_exception).
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   122
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   123
  __ z_ltgr(handle_exception, handle_exception);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   124
  __ asm_assert_ne("handler must not be NULL", 0x852);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   125
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   126
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   127
  // Handle_exception contains the handler address. If the associated frame
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   128
  // has been deoptimized then the handler has been patched to jump to
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   129
  // the deoptimization blob.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   130
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   131
  // If the exception handler jumps to the deoptimization blob, the
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   132
  // exception pc will be read from there.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   133
  __ z_lg(Z_ARG2, Address(Z_thread, JavaThread::exception_pc_offset()));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   134
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   135
  __ z_lg(Z_ARG1, Address(Z_thread, JavaThread::exception_oop_offset()));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   136
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   137
  // Clear the exception oop so GC no longer processes it as a root.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   138
  __ clear_mem(Address(Z_thread, JavaThread::exception_oop_offset()),sizeof(intptr_t));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   139
#ifdef ASSERT
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   140
  __ clear_mem(Address(Z_thread, JavaThread::exception_handler_pc_offset()), sizeof(intptr_t));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   141
  __ clear_mem(Address(Z_thread, JavaThread::exception_pc_offset()), sizeof(intptr_t));
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   142
#endif
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   143
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   144
  __ z_br(handle_exception);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   145
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   146
  // Make sure all code is generated.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   147
  masm->flush();
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   148
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   149
  // Set exception blob.
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   150
  OopMapSet *oop_maps = NULL;
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   151
  _exception_blob =  ExceptionBlob::create(&buffer, oop_maps, frame_size/wordSize);
6032b31e3719 8167673: [s390] The s390 port.
goetz
parents:
diff changeset
   152
}