hotspot/src/cpu/ppc/vm/runtime_ppc.cpp
author simonis
Wed, 23 Aug 2017 18:24:47 +0200
changeset 46960 b498e2123d2f
parent 37248 11a660dbbb8e
permissions -rw-r--r--
8186667: InterpreterCodeSize overflows on AIX Reviewed-by: goetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     1
/*
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35594
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 35085
diff changeset
     3
 * Copyright (c) 2012, 2015 SAP SE. All rights reserved.
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     5
 *
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     8
 * published by the Free Software Foundation.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
     9
 *
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    14
 * accompanied this code).
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    15
 *
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    19
 *
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    22
 * questions.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    23
 *
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    24
 */
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    25
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    26
#include "precompiled.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    27
#ifdef COMPILER2
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    28
#include "asm/assembler.inline.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    29
#include "asm/macroAssembler.inline.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    30
#include "classfile/systemDictionary.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    31
#include "code/vmreg.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    32
#include "interpreter/interpreter.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 23211
diff changeset
    33
#include "interpreter/interp_masm.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 35594
diff changeset
    34
#include "memory/resourceArea.hpp"
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    35
#include "nativeInst_ppc.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    36
#include "opto/runtime.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    37
#include "runtime/interfaceSupport.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    38
#include "runtime/sharedRuntime.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    39
#include "runtime/stubRoutines.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    40
#include "runtime/vframeArray.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    41
#include "utilities/globalDefinitions.hpp"
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    42
#endif
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    43
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    44
#define __ masm->
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    45
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    46
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    47
#ifdef COMPILER2
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    48
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    49
//------------------------------generate_exception_blob---------------------------
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    50
// Creates exception blob at the end.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    51
// Using exception blob, this code is jumped from a compiled method.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    52
//
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    53
// Given an exception pc at a call we call into the runtime for the
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    54
// handler in this method. This handler might merely restore state
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    55
// (i.e. callee save registers) unwind the frame and jump to the
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    56
// exception handler for the nmethod if there is no Java level handler
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    57
// for the nmethod.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    58
//
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    59
// This code is entered with a jmp.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    60
//
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    61
// Arguments:
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    62
//   R3_ARG1: exception oop
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    63
//   R4_ARG2: exception pc
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    64
//
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    65
// Results:
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    66
//   R3_ARG1: exception oop
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    67
//   R4_ARG2: exception pc in caller
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    68
//   destination: exception handler of caller
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    69
//
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    70
// Note: the exception pc MUST be at a call (precise debug information)
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    71
//
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    72
void OptoRuntime::generate_exception_blob() {
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    73
  // Allocate space for the code.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    74
  ResourceMark rm;
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    75
  // Setup code generation tools.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    76
  CodeBuffer buffer("exception_blob", 2048, 1024);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    77
  InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    78
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    79
  address start = __ pc();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    80
23211
954e3a81da29 8035647: PPC64: Support for elf v2 abi.
goetz
parents: 22861
diff changeset
    81
  int frame_size_in_bytes = frame::abi_reg_args_size;
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    82
  OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    83
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    84
  // Exception pc is 'return address' for stack walker.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    85
  __ std(R4_ARG2/*exception pc*/, _abi(lr), R1_SP);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    86
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    87
  // Store the exception in the Thread object.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    88
  __ std(R3_ARG1/*exception oop*/, in_bytes(JavaThread::exception_oop_offset()), R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    89
  __ std(R4_ARG2/*exception pc*/,  in_bytes(JavaThread::exception_pc_offset()),  R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    90
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    91
  // Save callee-saved registers.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    92
  // Push a C frame for the exception blob. It is needed for the C call later on.
23211
954e3a81da29 8035647: PPC64: Support for elf v2 abi.
goetz
parents: 22861
diff changeset
    93
  __ push_frame_reg_args(0, R11_scratch1);
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    94
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    95
  // This call does all the hard work. It checks if an exception handler
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    96
  // exists in the method.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    97
  // If so, it returns the handler address.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    98
  // If not, it prepares for stack-unwinding, restoring the callee-save
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
    99
  // registers of the frame being removed.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   100
  __ set_last_Java_frame(/*sp=*/R1_SP, noreg);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   101
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   102
  __ mr(R3_ARG1, R16_thread);
23211
954e3a81da29 8035647: PPC64: Support for elf v2 abi.
goetz
parents: 22861
diff changeset
   103
#if defined(ABI_ELFv2)
954e3a81da29 8035647: PPC64: Support for elf v2 abi.
goetz
parents: 22861
diff changeset
   104
  __ call_c((address) OptoRuntime::handle_exception_C, relocInfo::none);
954e3a81da29 8035647: PPC64: Support for elf v2 abi.
goetz
parents: 22861
diff changeset
   105
#else
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   106
  __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, OptoRuntime::handle_exception_C),
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   107
            relocInfo::none);
23211
954e3a81da29 8035647: PPC64: Support for elf v2 abi.
goetz
parents: 22861
diff changeset
   108
#endif
22861
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   109
  address calls_return_pc = __ last_calls_return_pc();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   110
# ifdef ASSERT
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   111
  __ cmpdi(CCR0, R3_RET, 0);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   112
  __ asm_assert_ne("handle_exception_C must not return NULL", 0x601);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   113
# endif
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   114
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   115
  // Set an oopmap for the call site. This oopmap will only be used if we
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   116
  // are unwinding the stack. Hence, all locations will be dead.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   117
  // Callee-saved registers will be the same as the frame above (i.e.,
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   118
  // handle_exception_stub), since they were restored when we got the
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   119
  // exception.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   120
  OopMapSet* oop_maps = new OopMapSet();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   121
  oop_maps->add_gc_map(calls_return_pc - start, map);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   122
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   123
  __ mtctr(R3_RET); // Move address of exception handler to SR_CTR.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   124
  __ reset_last_Java_frame();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   125
  __ pop_frame();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   126
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   127
  // We have a handler in register SR_CTR (could be deopt blob).
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   128
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   129
  // Get the exception oop.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   130
  __ ld(R3_ARG1, in_bytes(JavaThread::exception_oop_offset()), R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   131
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   132
  // Get the exception pc in case we are deoptimized.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   133
  __ ld(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   134
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   135
  // Reset thread values.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   136
  __ li(R0, 0);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   137
#ifdef ASSERT
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   138
  __ std(R0, in_bytes(JavaThread::exception_handler_pc_offset()), R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   139
  __ std(R0, in_bytes(JavaThread::exception_pc_offset()), R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   140
#endif
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   141
  // Clear the exception oop so GC no longer processes it as a root.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   142
  __ std(R0, in_bytes(JavaThread::exception_oop_offset()), R16_thread);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   143
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   144
  // Move exception pc into SR_LR.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   145
  __ mtlr(R4_ARG2);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   146
  __ bctr();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   147
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   148
  // Make sure all code is generated.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   149
  masm->flush();
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   150
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   151
  // Set exception blob.
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   152
  _exception_blob = ExceptionBlob::create(&buffer, oop_maps,
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   153
                                          frame_size_in_bytes/wordSize);
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   154
}
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   155
f5c393d456fc 8029940: PPC64 (part 122): C2 compiler port
goetz
parents:
diff changeset
   156
#endif // COMPILER2