src/hotspot/cpu/x86/templateInterpreterGenerator_x86.cpp
author rehn
Thu, 31 Aug 2017 10:00:28 +0200
changeset 47881 0ce0ac68ace7
parent 47823 9c77ebad8c3a
child 47916 bdbef8638948
permissions -rw-r--r--
8189941: Implementation JEP 312: Thread-local handshake Summary: Introduce a way to execute a callback on threads without performing a global VM safepoint. Make it both possible and cheap to stop individual threads and not just all threads or none. Reviewed-by: mdoerr, neliasso, acorn, aph, coleenp, dholmes Contributed-by: mikael.gerdin@oracle.com, erik.osterlund@oracle.com, robbin.ehn@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46294
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. 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
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5419
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5419
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5419
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    25
#include "precompiled.hpp"
14626
0cf4eccf130f 8003240: x86: move MacroAssembler into separate file
twisti
parents: 13728
diff changeset
    26
#include "asm/macroAssembler.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    27
#include "interpreter/bytecodeHistogram.hpp"
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
    28
#include "interpreter/interp_masm.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    29
#include "interpreter/interpreter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    30
#include "interpreter/interpreterRuntime.hpp"
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
    31
#include "interpreter/templateInterpreterGenerator.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    32
#include "interpreter/templateTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    33
#include "oops/arrayOop.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    34
#include "oops/methodData.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
    35
#include "oops/method.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    36
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    37
#include "prims/jvmtiExport.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    38
#include "prims/jvmtiThreadState.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    39
#include "runtime/arguments.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    40
#include "runtime/deoptimization.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    41
#include "runtime/frame.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    42
#include "runtime/sharedRuntime.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    43
#include "runtime/stubRoutines.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    44
#include "runtime/synchronizer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    45
#include "runtime/timer.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    46
#include "runtime/vframeArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6453
diff changeset
    47
#include "utilities/debug.hpp"
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14745
diff changeset
    48
#include "utilities/macros.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
#define __ _masm->
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
35479
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    52
// Size of interpreter code.  Increase if too small.  Interpreter will
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    53
// fail with a guarantee ("not enough space for interpreter generation");
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    54
// if too small.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    55
// Run with +PrintInterpreter to get the VM to print out the size.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    56
// Max size with JVMTI
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    57
#ifdef AMD64
41328
2bea535779f6 8165457: [JVMCI] increase InterpreterCodeSize for JVMCI
dnsimon
parents: 40644
diff changeset
    58
int TemplateInterpreter::InterpreterCodeSize = JVMCI_ONLY(268) NOT_JVMCI(256) * 1024;
35479
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    59
#else
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    60
int TemplateInterpreter::InterpreterCodeSize = 224 * 1024;
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    61
#endif // AMD64
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    62
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
    63
// Global Register Names
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
    64
static const Register rbcp     = LP64_ONLY(r13) NOT_LP64(rsi);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
    65
static const Register rlocals  = LP64_ONLY(r14) NOT_LP64(rdi);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
    66
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
const int method_offset = frame::interpreter_frame_method_offset * wordSize;
25714
87fa6860b5ae 8004128: NPG: remove stackwalking in Threads::gc_prologue and gc_epilogue code
coleenp
parents: 24322
diff changeset
    68
const int bcp_offset    = frame::interpreter_frame_bcp_offset    * wordSize;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
35479
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
    71
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
//-----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    Label L;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
    80
    __ lea(rax, Address(rbp,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
    81
                        frame::interpreter_frame_monitor_block_top_offset *
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
    82
                        wordSize));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
    83
    __ cmpptr(rax, rsp); // rax = maximal rsp for current rbp (stack
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
    84
                         // grows negative)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    __ jcc(Assembler::aboveEqual, L); // check if frame is complete
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    __ stop ("interpreter frame not set up");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Restore bcp under the assumption that the current frame is still
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // interpreted
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  __ restore_bcp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  // expression stack must be empty before entering the VM if an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  // exception happened
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  __ empty_expression_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // throw exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
             CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                              InterpreterRuntime::throw_StackOverflowError));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
        const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // expression stack must be empty before entering the VM if an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // exception happened
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  __ empty_expression_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  // setup parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // ??? convention: expect aberrant index in register ebx
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   112
  Register rarg = NOT_LP64(rax) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   113
  __ lea(rarg, ExternalAddress((address)name));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
             CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
                              InterpreterRuntime::
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
                              throw_ArrayIndexOutOfBoundsException),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   118
             rarg, rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // object is at TOS
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   126
  Register rarg = NOT_LP64(rax) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   127
  __ pop(rarg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // expression stack must be empty before entering the VM if an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // exception happened
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  __ empty_expression_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
             CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
                              InterpreterRuntime::
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
                              throw_ClassCastException),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   137
             rarg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
address TemplateInterpreterGenerator::generate_exception_handler_common(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
        const char* name, const char* message, bool pass_oop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  assert(!pass_oop || message == NULL, "either oop or message but not both");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  address entry = __ pc();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   145
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   146
  Register rarg = NOT_LP64(rax) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   147
  Register rarg2 = NOT_LP64(rbx) LP64_ONLY(c_rarg2);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   148
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  if (pass_oop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    // object is at TOS
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   151
    __ pop(rarg2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  // expression stack must be empty before entering the VM if an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // exception happened
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  __ empty_expression_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // setup parameters
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   157
  __ lea(rarg, ExternalAddress((address)name));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  if (pass_oop) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    __ call_VM(rax, CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
                                     InterpreterRuntime::
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                                     create_klass_exception),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   162
               rarg, rarg2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  } else {
36301
cb578d8c6cba 8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents: 35479
diff changeset
   164
    __ lea(rarg2, ExternalAddress((address)message));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    __ call_VM(rax,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
               CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   167
               rarg, rarg2);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // throw exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
21198
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   174
address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   177
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   178
#ifdef COMPILER2
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   179
  // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   180
  if ((state == ftos && UseSSE < 1) || (state == dtos && UseSSE < 2)) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   181
    for (int i = 1; i < 8; i++) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   182
        __ ffree(i);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   183
    }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   184
  } else if (UseSSE < 2) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   185
    __ empty_FPU_stack();
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   186
  }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   187
#endif // COMPILER2
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   188
  if ((state == ftos && UseSSE < 1) || (state == dtos && UseSSE < 2)) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   189
    __ MacroAssembler::verify_FPU(1, "generate_return_entry_for compiled");
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   190
  } else {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   191
    __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   192
  }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   193
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   194
  if (state == ftos) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   195
    __ MacroAssembler::verify_FPU(UseSSE >= 1 ? 0 : 1, "generate_return_entry_for in interpreter");
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   196
  } else if (state == dtos) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   197
    __ MacroAssembler::verify_FPU(UseSSE >= 2 ? 0 : 1, "generate_return_entry_for in interpreter");
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   198
  }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   199
#endif // _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   200
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // Restore stack bottom in case i2c adjusted stack
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   202
  __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // and NULL it as marker that esp is now tos until next java call
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   204
  __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  __ restore_bcp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  __ restore_locals();
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   208
20709
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 19335
diff changeset
   209
  if (state == atos) {
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 19335
diff changeset
   210
    Register mdp = rbx;
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 19335
diff changeset
   211
    Register tmp = rcx;
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 19335
diff changeset
   212
    __ profile_return_type(mdp, rax, tmp);
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 19335
diff changeset
   213
  }
034be898bf04 8026054: New type profiling points: type of return values at calls
roland
parents: 19335
diff changeset
   214
21198
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   215
  const Register cache = rbx;
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   216
  const Register index = rcx;
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   217
  __ get_cache_and_index_at_bcp(cache, index, 1, index_size);
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   218
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   219
  const Register flags = cache;
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   220
  __ movl(flags, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset()));
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   221
  __ andl(flags, ConstantPoolCacheEntry::parameter_size_mask);
dd647e8d1d72 8026328: Setting a breakpoint on invokedynamic crashes the JVM
twisti
parents: 21095
diff changeset
   222
  __ lea(rsp, Address(rsp, flags, Interpreter::stackElementScale()));
46294
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   223
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   224
   const Register java_thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   225
   if (JvmtiExport::can_pop_frame()) {
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   226
     NOT_LP64(__ get_thread(java_thread));
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   227
     __ check_and_handle_popframe(java_thread);
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   228
   }
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   229
   if (JvmtiExport::can_force_early_return()) {
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   230
     NOT_LP64(__ get_thread(java_thread));
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   231
     __ check_and_handle_earlyret(java_thread);
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   232
   }
345a46524a19 8172020: Internal Error (cpu/arm/vm/frame_arm.cpp:571): assert(obj == __null || Universe::heap()->is_in(obj)) failed: sanity check #
cjplummer
parents: 46263
diff changeset
   233
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  __ dispatch_next(state, step);
4478
c3a8af0fc6b0 6829192: JSR 292 needs to support 64-bit x86
twisti
parents: 4429
diff changeset
   235
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   240
address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  address entry = __ pc();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   242
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   243
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   244
  if (state == ftos) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   245
    __ MacroAssembler::verify_FPU(UseSSE >= 1 ? 0 : 1, "generate_deopt_entry_for in interpreter");
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   246
  } else if (state == dtos) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   247
    __ MacroAssembler::verify_FPU(UseSSE >= 2 ? 0 : 1, "generate_deopt_entry_for in interpreter");
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   248
  }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   249
#endif // _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   250
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // NULL last_sp until next java call
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   252
  __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  __ restore_bcp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  __ restore_locals();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   255
  const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   256
  NOT_LP64(__ get_thread(thread));
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   257
#if INCLUDE_JVMCI
41736
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   258
  // Check if we need to take lock at entry of synchronized method.  This can
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   259
  // only occur on method entry so emit it only for vtos with step 0.
47823
9c77ebad8c3a 8182755: [JVMCI] Deoptimization in synchronized methods can lead to a crash or exception when using EnableJVMCI but not UseJVMCICompiler
gdub
parents: 47216
diff changeset
   260
  if ((EnableJVMCI || UseAOT) && state == vtos && step == 0) {
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   261
    Label L;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   262
    __ cmpb(Address(thread, JavaThread::pending_monitorenter_offset()), 0);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   263
    __ jcc(Assembler::zero, L);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   264
    // Clear flag.
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   265
    __ movb(Address(thread, JavaThread::pending_monitorenter_offset()), 0);
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   266
    // Satisfy calling convention for lock_method().
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   267
    __ get_method(rbx);
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   268
    // Take lock.
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   269
    lock_method();
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   270
    __ bind(L);
41736
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   271
  } else {
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   272
#ifdef ASSERT
47823
9c77ebad8c3a 8182755: [JVMCI] Deoptimization in synchronized methods can lead to a crash or exception when using EnableJVMCI but not UseJVMCICompiler
gdub
parents: 47216
diff changeset
   273
    if (EnableJVMCI) {
41736
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   274
      Label L;
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   275
      __ cmpb(Address(r15_thread, JavaThread::pending_monitorenter_offset()), 0);
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   276
      __ jccb(Assembler::zero, L);
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   277
      __ stop("unexpected pending monitor in deopt entry");
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   278
      __ bind(L);
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   279
    }
908e28baf9c2 8166972: [JVMCI] reduce size of interpreter when JVMCI is enabled
never
parents: 41330
diff changeset
   280
#endif
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   281
  }
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   282
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // handle exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
    Label L;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   286
    __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
    __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
               CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
                                InterpreterRuntime::throw_pending_exception));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    __ should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  __ dispatch_next(state, step);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
address TemplateInterpreterGenerator::generate_result_handler_for(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
        BasicType type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  switch (type) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  case T_BOOLEAN: __ c2bool(rax);            break;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   303
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   304
  case T_CHAR   : __ andptr(rax, 0xFFFF);    break;
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   305
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  case T_CHAR   : __ movzwl(rax, rax);       break;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   307
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  case T_BYTE   : __ sign_extend_byte(rax);  break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  case T_SHORT  : __ sign_extend_short(rax); break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  case T_INT    : /* nothing to do */        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  case T_LONG   : /* nothing to do */        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  case T_VOID   : /* nothing to do */        break;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   313
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   314
  case T_DOUBLE :
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   315
  case T_FLOAT  :
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   316
    { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   317
      __ pop(t);                            // remove return address first
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   318
      // Must return a result for interpreter or compiler. In SSE
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   319
      // mode, results are returned in xmm0 and the FPU stack must
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   320
      // be empty.
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   321
      if (type == T_FLOAT && UseSSE >= 1) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   322
        // Load ST0
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   323
        __ fld_d(Address(rsp, 0));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   324
        // Store as float and empty fpu stack
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   325
        __ fstp_s(Address(rsp, 0));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   326
        // and reload
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   327
        __ movflt(xmm0, Address(rsp, 0));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   328
      } else if (type == T_DOUBLE && UseSSE >= 2 ) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   329
        __ movdbl(xmm0, Address(rsp, 0));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   330
      } else {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   331
        // restore ST0
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   332
        __ fld_d(Address(rsp, 0));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   333
      }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   334
      // and pop the temp
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   335
      __ addptr(rsp, 2 * wordSize);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   336
      __ push(t);                           // restore return address
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   337
    }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   338
    break;
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   339
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  case T_FLOAT  : /* nothing to do */        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  case T_DOUBLE : /* nothing to do */        break;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   342
#endif // _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   343
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  case T_OBJECT :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    // retrieve result from frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   346
    __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    // and verify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    __ verify_oop(rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  default       : ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  __ ret(0);                                   // return from result handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
address TemplateInterpreterGenerator::generate_safept_entry_for(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
        TosState state,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
        address runtime_entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  __ push(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  __ call_VM(noreg, runtime_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
  __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
// Helpers for commoning out cases in the various type of method entries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
// increment invocation count & check for overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// Note: checking for negative value instead of overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
//       so we have a 'sticky' overflow test
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
// rbx: method
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   378
// rcx: invocation counter
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
//
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
   380
void TemplateInterpreterGenerator::generate_counter_incr(
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
        Label* overflow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
        Label* profile_method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
        Label* profile_method_continue) {
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   384
  Label done;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   385
  // Note: In tiered we increment either counters in Method* or in MDO depending if we're profiling or not.
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   386
  if (TieredCompilation) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   387
    int increment = InvocationCounter::count_increment;
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   388
    Label no_mdo;
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   389
    if (ProfileInterpreter) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   390
      // Are we profiling?
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   391
      __ movptr(rax, Address(rbx, Method::method_data_offset()));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   392
      __ testptr(rax, rax);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   393
      __ jccb(Assembler::zero, no_mdo);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   394
      // Increment counter in the MDO
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   395
      const Address mdo_invocation_counter(rax, in_bytes(MethodData::invocation_counter_offset()) +
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   396
                                                in_bytes(InvocationCounter::counter_offset()));
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   397
      const Address mask(rax, in_bytes(MethodData::invoke_mask_offset()));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   398
      __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rcx, false, Assembler::zero, overflow);
17037
34baf792b14d 8013041: guarantee(this->is8bit(imm8)) failed: Short forward jump exceeds 8-bit offset.
jiangli
parents: 17000
diff changeset
   399
      __ jmp(done);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   400
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   401
    __ bind(no_mdo);
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   402
    // Increment counter in MethodCounters
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   403
    const Address invocation_counter(rax,
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   404
                  MethodCounters::invocation_counter_offset() +
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   405
                  InvocationCounter::counter_offset());
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   406
    __ get_method_counters(rbx, rax, done);
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   407
    const Address mask(rax, in_bytes(MethodCounters::invoke_mask_offset()));
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   408
    __ increment_mask_and_jump(invocation_counter, increment, mask, rcx,
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   409
                               false, Assembler::zero, overflow);
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   410
    __ bind(done);
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   411
  } else { // not TieredCompilation
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   412
    const Address backedge_counter(rax,
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   413
                  MethodCounters::backedge_counter_offset() +
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   414
                  InvocationCounter::counter_offset());
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   415
    const Address invocation_counter(rax,
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   416
                  MethodCounters::invocation_counter_offset() +
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   417
                  InvocationCounter::counter_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   419
    __ get_method_counters(rbx, rax, done);
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   420
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   421
    if (ProfileInterpreter) {
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   422
      __ incrementl(Address(rax,
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   423
              MethodCounters::interpreter_invocation_counter_offset()));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   424
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   425
    // Update standard invocation counters
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   426
    __ movl(rcx, invocation_counter);
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   427
    __ incrementl(rcx, InvocationCounter::count_increment);
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   428
    __ movl(invocation_counter, rcx); // save invocation count
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   430
    __ movl(rax, backedge_counter);   // load backedge counter
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   431
    __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   433
    __ addl(rcx, rax);                // add both counters
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   435
    // profile_method is non-null only for interpreted method so
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   436
    // profile_method != NULL == !native_call
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   437
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   438
    if (ProfileInterpreter && profile_method != NULL) {
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   439
      // Test to see if we should create a method data oop
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   440
      __ movptr(rax, Address(rbx, Method::method_counters_offset()));
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   441
      __ cmp32(rcx, Address(rax, in_bytes(MethodCounters::interpreter_profile_limit_offset())));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   442
      __ jcc(Assembler::less, *profile_method_continue);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   444
      // if no method data exists, go to profile_method
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   445
      __ test_method_data_pointer(rax, *profile_method);
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   446
    }
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   447
28650
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   448
    __ movptr(rax, Address(rbx, Method::method_counters_offset()));
772aaab2582f 8059606: Enable per-method usage of CompileThresholdScaling (per-method compilation thresholds)
zmajo
parents: 25950
diff changeset
   449
    __ cmp32(rcx, Address(rax, in_bytes(MethodCounters::interpreter_invocation_limit_offset())));
6453
970dc585ab63 6953144: Tiered compilation
iveresov
parents: 5702
diff changeset
   450
    __ jcc(Assembler::aboveEqual, *overflow);
17000
11bf92e571a2 8010862: The Method counter fields used for profiling can be allocated lazily.
jiangli
parents: 16624
diff changeset
   451
    __ bind(done);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
   455
void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  // Asm interpreter on entry
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   458
  // r14/rdi - locals
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   459
  // r13/rsi - bcp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // rbx - method
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   461
  // rdx - cpool --- DOES NOT APPEAR TO BE TRUE
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  // rbp - interpreter frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  // Everything as it was on entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
  // rdx is not restored. Doesn't appear to really be set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  // InterpreterRuntime::frequency_counter_overflow takes two
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
  // arguments, the first (thread) is passed by call_VM, the second
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // indicates if the counter overflow occurs at a backwards branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  // (NULL bcp).  We pass zero for it.  The call returns the address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  // of the verified entry point for the method or NULL if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  // compilation did not complete (either went background or bailed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  // out).
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   475
  Register rarg = NOT_LP64(rax) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   476
  __ movl(rarg, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
             CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
                              InterpreterRuntime::frequency_counter_overflow),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   480
             rarg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   482
  __ movptr(rbx, Address(rbp, method_offset));   // restore Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
  // Preserve invariant that r13/r14 contain bcp/locals of sender frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  // and jump to the interpreted entry.
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
   485
  __ jmp(do_continue, relocInfo::none);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   488
// See if we've got enough room on the stack for locals plus overhead below
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   489
// JavaThread::stack_overflow_limit(). If not, throw a StackOverflowError
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   490
// without going through the signal handler, i.e., reserved and yellow zones
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   491
// will not be made usable. The shadow zone must suffice to handle the
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   492
// overflow.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
// The expression stack grows down incrementally, so the normal guard
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
// page mechanism will work for that.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
// NOTE: Since the additional locals are also always pushed (wasn't
25950
b5c40ed1d349 8003426: Remove UseFastAccessors and UseFastEmptyMethods except for zero
coleenp
parents: 25717
diff changeset
   497
// obvious in generate_fixed_frame) so the guard should work for them
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
// too.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
// Args:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
//      rdx: number of additional locals this frame needs (what we must check)
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   502
//      rbx: Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
// Kills:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
//      rax
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
   506
void TemplateInterpreterGenerator::generate_stack_overflow_check(void) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
25950
b5c40ed1d349 8003426: Remove UseFastAccessors and UseFastEmptyMethods except for zero
coleenp
parents: 25717
diff changeset
   508
  // monitor entry size: see picture of stack in frame_x86.hpp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  // total overhead size: entry_size + (saved rbp through expr stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  // bottom).  be sure to change this if you add/subtract anything
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
  // to/from the overhead area
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
  const int overhead_size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  const int page_size = os::vm_page_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  Label after_frame_check;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  // see if the frame is greater than one page in size. If so,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  // then we need to verify there is enough stack space remaining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  // for the additional locals.
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5046
diff changeset
   524
  __ cmpl(rdx, (page_size - overhead_size) / Interpreter::stackElementSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  __ jcc(Assembler::belowEqual, after_frame_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
  // compute rsp as if this were going to be the last frame on
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // the stack before the red zone
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   530
  Label after_frame_check_pop;
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   531
  const Register thread = NOT_LP64(rsi) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   532
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   533
  __ push(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   534
  __ get_thread(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   535
#endif
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   536
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   537
  const Address stack_limit(thread, JavaThread::stack_overflow_limit_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  // locals + overhead, in bytes
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   540
  __ mov(rax, rdx);
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   541
  __ shlptr(rax, Interpreter::logStackElementSize); // Convert parameter count to bytes.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   542
  __ addptr(rax, overhead_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
#ifdef ASSERT
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   545
  Label limit_okay;
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   546
  // Verify that thread stack overflow limit is non-zero.
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   547
  __ cmpptr(stack_limit, (int32_t)NULL_WORD);
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   548
  __ jcc(Assembler::notEqual, limit_okay);
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   549
  __ stop("stack overflow limit is zero");
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   550
  __ bind(limit_okay);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   553
  // Add locals/frame size to stack limit.
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   554
  __ addptr(rax, stack_limit);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   556
  // Check against the current stack bottom.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   557
  __ cmpptr(rsp, rax);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   558
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   559
  __ jcc(Assembler::above, after_frame_check_pop);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   560
  NOT_LP64(__ pop(rsi));  // get saved bcp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
11411
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   562
  // Restore sender's sp as SP. This is necessary if the sender's
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   563
  // frame is an extended compiled frame (see gen_c2i_adapter())
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   564
  // and safer anyway in case of JSR292 adaptations.
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   565
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   566
  __ pop(rax); // return address must be moved if SP is changed
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   567
  __ mov(rsp, rbcp);
11411
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   568
  __ push(rax);
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   569
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   570
  // Note: the restored frame is not necessarily interpreted.
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   571
  // Use the shared runtime version of the StackOverflowError.
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   572
  assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
16b151e1e088 7116216: StackOverflow GC crash
bdelsart
parents: 10966
diff changeset
   573
  __ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry()));
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   574
  // all done with frame size check
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   575
  __ bind(after_frame_check_pop);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   576
  NOT_LP64(__ pop(rsi));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  // all done with frame size check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  __ bind(after_frame_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
// Allocate monitor and lock method (asm interpreter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
// Args:
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   585
//      rbx: Method*
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   586
//      r14/rdi: locals
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
// Kills:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
//      rax
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
//      c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
//      rscratch1, rscratch2 (scratch regs)
33160
c59f1676d27e 8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents: 33070
diff changeset
   592
void TemplateInterpreterGenerator::lock_method() {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
  // synchronize method
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   594
  const Address access_flags(rbx, Method::access_flags_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  const Address monitor_block_top(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
        rbp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
        frame::interpreter_frame_monitor_block_top_offset * wordSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    __ testl(rax, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
    __ stop("method doesn't need synchronization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  // get synchronization object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
    Label done;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
    __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
    __ testl(rax, JVM_ACC_STATIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
    // get receiver (assume this is frequent case)
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   617
    __ movptr(rax, Address(rlocals, Interpreter::local_offset_in_bytes(0)));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
    __ jcc(Assembler::zero, done);
38074
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37152
diff changeset
   619
    __ load_mirror(rax, rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
      Label L;
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   624
      __ testptr(rax, rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
      __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
      __ stop("synchronization object is NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
    __ bind(done);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  // add space for monitor & lock
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   635
  __ subptr(rsp, entry_size); // add space for a monitor entry
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   636
  __ movptr(monitor_block_top, rsp);  // set new monitor block top
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  // store object
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   638
  __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   639
  const Register lockreg = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   640
  __ movptr(lockreg, rsp); // object address
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   641
  __ lock_object(lockreg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
// Generate a fixed interpreter frame. This is identical setup for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
// interpreted methods and for native methods hence the shared code.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
// Args:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
//      rax: return address
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   649
//      rbx: Method*
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   650
//      r14/rdi: pointer to locals
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   651
//      r13/rsi: sender sp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
//      rdx: cp cache
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  // initialize fixed part of activation frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   655
  __ push(rax);        // save return address
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  __ enter();          // save old & set new rbp
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   657
  __ push(rbcp);        // set sender sp
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   658
  __ push((int)NULL_WORD); // leave last_sp as null
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   659
  __ movptr(rbcp, Address(rbx, Method::const_offset()));      // get ConstMethod*
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   660
  __ lea(rbcp, Address(rbcp, ConstMethod::codes_offset())); // get codebase
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   661
  __ push(rbx);        // save Method*
38074
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37152
diff changeset
   662
  // Get mirror and store it in the frame as GC root for this Method*
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37152
diff changeset
   663
  __ load_mirror(rdx, rbx);
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37152
diff changeset
   664
  __ push(rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
    Label method_data_continue;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   667
    __ movptr(rdx, Address(rbx, in_bytes(Method::method_data_offset())));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   668
    __ testptr(rdx, rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
    __ jcc(Assembler::zero, method_data_continue);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   670
    __ addptr(rdx, in_bytes(MethodData::data_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
    __ bind(method_data_continue);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   672
    __ push(rdx);      // set the mdp (method data pointer)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  } else {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   674
    __ push(0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   677
  __ movptr(rdx, Address(rbx, Method::const_offset()));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   678
  __ movptr(rdx, Address(rdx, ConstMethod::constants_offset()));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   679
  __ movptr(rdx, Address(rdx, ConstantPool::cache_offset_in_bytes()));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   680
  __ push(rdx); // set constant pool cache
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   681
  __ push(rlocals); // set locals pointer
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
  if (native_call) {
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   683
    __ push(0); // no bcp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  } else {
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   685
    __ push(rbcp); // set bcp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
  }
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   687
  __ push(0); // reserve word for pointer to expression stack bottom
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   688
  __ movptr(Address(rsp, 0), rsp); // set expression stack bottom
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
// End of helpers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   693
// Method entry for java.lang.ref.Reference.get.
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
   694
address TemplateInterpreterGenerator::generate_Reference_get_entry(void) {
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14745
diff changeset
   695
#if INCLUDE_ALL_GCS
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   696
  // Code: _aload_0, _getfield, _areturn
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   697
  // parameter size = 1
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   698
  //
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   699
  // The code that gets generated by this routine is split into 2 parts:
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   700
  //    1. The "intrinsified" code for G1 (or any SATB based GC),
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   701
  //    2. The slow path - which is an expansion of the regular method entry.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   702
  //
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   703
  // Notes:-
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   704
  // * In the G1 code we do not check whether we need to block for
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   705
  //   a safepoint. If G1 is enabled then we must execute the specialized
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   706
  //   code for Reference.get (except when the Reference object is null)
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   707
  //   so that we can log the value in the referent field with an SATB
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   708
  //   update buffer.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   709
  //   If the code for the getfield template is modified so that the
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   710
  //   G1 pre-barrier code is executed when the current method is
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   711
  //   Reference.get() then going through the normal method entry
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   712
  //   will be fine.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   713
  // * The G1 code can, however, check the receiver object (the instance
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   714
  //   of java.lang.Reference) and jump to the slow path if null. If the
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   715
  //   Reference object is null then we obviously cannot fetch the referent
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   716
  //   and so we don't need to call the G1 pre-barrier. Thus we can use the
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   717
  //   regular method entry code to generate the NPE.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   718
  //
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   719
  // rbx: Method*
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   720
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   721
  // r13: senderSP must preserve for slow path, set SP to it on fast path
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   722
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   723
  address entry = __ pc();
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   724
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   725
  const int referent_offset = java_lang_ref_Reference::referent_offset;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   726
  guarantee(referent_offset > 0, "referent offset not initialized");
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   727
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   728
  if (UseG1GC) {
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   729
    Label slow_path;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   730
    // rbx: method
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   731
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   732
    // Check if local 0 != NULL
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   733
    // If the receiver is null then it is OK to jump to the slow path.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   734
    __ movptr(rax, Address(rsp, wordSize));
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   735
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   736
    __ testptr(rax, rax);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   737
    __ jcc(Assembler::zero, slow_path);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   738
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   739
    // rax: local 0
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   740
    // rbx: method (but can be used as scratch now)
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   741
    // rdx: scratch
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   742
    // rdi: scratch
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   743
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   744
    // Preserve the sender sp in case the pre-barrier
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   745
    // calls the runtime
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   746
    NOT_LP64(__ push(rsi));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   747
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   748
    // Generate the G1 pre-barrier code to log the value of
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   749
    // the referent field in an SATB buffer.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   750
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   751
    // Load the value of the referent field.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   752
    const Address field_address(rax, referent_offset);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   753
    __ load_heap_oop(rax, field_address);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   754
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   755
    const Register sender_sp = NOT_LP64(rsi) LP64_ONLY(r13);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   756
    const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   757
    NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   758
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   759
    // Generate the G1 pre-barrier code to log the value of
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   760
    // the referent field in an SATB buffer.
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   761
    __ g1_write_barrier_pre(noreg /* obj */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   762
                            rax /* pre_val */,
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   763
                            thread /* thread */,
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   764
                            rbx /* tmp */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   765
                            true /* tosca_live */,
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   766
                            true /* expand_call */);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   767
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   768
    // _areturn
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   769
    NOT_LP64(__ pop(rsi));      // get sender sp
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   770
    __ pop(rdi);                // get return address
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   771
    __ mov(rsp, sender_sp);     // set sp to sender sp
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   772
    __ jmp(rdi);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   773
    __ ret(0);
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   774
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   775
    // generate a vanilla interpreter entry as the slow path
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   776
    __ bind(slow_path);
33070
54f3f085b165 8136525: Generate interpreter entries only once and avoid unnecessary jump to jump
mdoerr
parents: 33066
diff changeset
   777
    __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals));
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   778
    return entry;
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   779
  }
15482
470d0b0c09f1 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 14745
diff changeset
   780
#endif // INCLUDE_ALL_GCS
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   781
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   782
  // If G1 is not enabled then attempt to go through the accessor entry point
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   783
  // Reference.get is an accessor
33070
54f3f085b165 8136525: Generate interpreter entries only once and avoid unnecessary jump to jump
mdoerr
parents: 33066
diff changeset
   784
  return NULL;
9176
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   785
}
42d9d1010f38 7009266: G1: assert(obj->is_oop_or_null(true )) failed: Error
johnc
parents: 8315
diff changeset
   786
35479
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   787
void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) {
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   788
  // Quick & dirty stack overflow checking: bang the stack & handle trap.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   789
  // Note that we do the banging after the frame is setup, since the exception
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   790
  // handling code expects to find a valid interpreter frame on the stack.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   791
  // Doing the banging earlier fails if the caller frame is not an interpreter
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   792
  // frame.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   793
  // (Also, the exception throwing code expects to unlock any synchronized
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   794
  // method receiever, so do the banging after locking the receiver.)
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   795
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   796
  // Bang each page in the shadow zone. We can't assume it's been done for
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   797
  // an interpreter frame with greater than a page of locals, so each page
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   798
  // needs to be checked.  Only true for non-native.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   799
  if (UseStackBanging) {
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   800
    const int page_size = os::vm_page_size();
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   801
    const int n_shadow_pages = ((int)JavaThread::stack_shadow_zone_size()) / page_size;
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   802
    const int start_page = native_call ? n_shadow_pages : 1;
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   803
    for (int pages = start_page; pages <= n_shadow_pages; pages++) {
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   804
      __ bang_stack_with_offset(pages*page_size);
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   805
    }
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   806
  }
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   807
}
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
   808
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   809
// Interpreter stub for calling a native method. (asm interpreter)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   810
// This sets up a somewhat different looking stack for calling the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   811
// native method than the typical interpreter frame setup.
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
   812
address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
  // determine code generation flags
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 28650
diff changeset
   814
  bool inc_counter  = UseCompiler || CountCompiledCalls || LogTouchedMethods;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   816
  // rbx: Method*
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   817
  // rbcp: sender sp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
  address entry_point = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   821
  const Address constMethod       (rbx, Method::const_offset());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   822
  const Address access_flags      (rbx, Method::access_flags_offset());
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   823
  const Address size_of_parameters(rcx, ConstMethod::
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   824
                                        size_of_parameters_offset());
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   825
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
  // get parameter size (always needed)
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   828
  __ movptr(rcx, constMethod);
2148
09c7f703773b 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 2131
diff changeset
   829
  __ load_unsigned_short(rcx, size_of_parameters);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
  // native calls don't need the stack size check since they have no
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
  // expression stack and the arguments are already on the stack and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
  // we only add a handful of words to the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   835
  // rbx: Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
  // rcx: size of parameters
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   837
  // rbcp: sender sp
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   838
  __ pop(rax);                                       // get return address
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
  // for natives the size of locals is zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   842
  // compute beginning of parameters
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   843
  __ lea(rlocals, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  // add 2 zero-initialized slots for native calls
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
  // initialize result_handler slot
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   847
  __ push((int) NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  // slot for oop temp
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  // (static native method holder mirror/jni oop result)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   850
  __ push((int) NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
  // initialize fixed part of activation frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  generate_fixed_frame(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // make sure method is native & not abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
    __ testl(rax, JVM_ACC_NATIVE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
    __ stop("tried to execute non-native method as native");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
    __ testl(rax, JVM_ACC_ABSTRACT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
    __ stop("tried to execute abstract method in interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
  // Since at this point in the method invocation the exception handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
  // would try to exit the monitor of synchronized methods which hasn't
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
  // been entered yet, we set the thread local variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
  // _do_not_unlock_if_synchronized to true. The remove_activation will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
  // check this flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   880
  const Register thread1 = NOT_LP64(rax) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   881
  NOT_LP64(__ get_thread(thread1));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   882
  const Address do_not_unlock_if_synchronized(thread1,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
        in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
  __ movbool(do_not_unlock_if_synchronized, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
  // increment invocation count & check for overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
  Label invocation_counter_overflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
  if (inc_counter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
    generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
  Label continue_after_compile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  __ bind(continue_after_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
  bang_stack_shadow_pages(true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
  // reset the _do_not_unlock_if_synchronized flag
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   898
  NOT_LP64(__ get_thread(thread1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
  __ movbool(do_not_unlock_if_synchronized, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
  // check for synchronized methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
  // Must happen AFTER invocation_counter check and stack overflow check,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
  // so method is not locked if overflows.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  if (synchronized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
    lock_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
    // no synchronization necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
      Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
      __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      __ testl(rax, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
      __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
      __ stop("method needs synchronization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  // start execution
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
    const Address monitor_block_top(rbp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
                 frame::interpreter_frame_monitor_block_top_offset * wordSize);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   926
    __ movptr(rax, monitor_block_top);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   927
    __ cmpptr(rax, rsp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
    __ stop("broken stack frame setup in interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  // jvmti support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
  __ notify_method_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
  // work registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
  const Register method = rbx;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   939
  const Register thread = NOT_LP64(rdi) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   940
  const Register t      = NOT_LP64(rcx) LP64_ONLY(r11);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
  // allocate space for parameters
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
  __ get_method(method);
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   944
  __ movptr(t, Address(method, Method::const_offset()));
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
   945
  __ load_unsigned_short(t, Address(t, ConstMethod::size_of_parameters_offset()));
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   946
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   947
#ifndef _LP64
39390
edf6a424a8b7 8159335: Fix problems with stack overflow handling.
goetz
parents: 38074
diff changeset
   948
  __ shlptr(t, Interpreter::logStackElementSize); // Convert parameter count to bytes.
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   949
  __ addptr(t, 2*wordSize);     // allocate two more slots for JNIEnv and possible mirror
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   950
  __ subptr(rsp, t);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   951
  __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   952
#else
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5046
diff changeset
   953
  __ shll(t, Interpreter::logStackElementSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   955
  __ subptr(rsp, t);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   956
  __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1066
diff changeset
   957
  __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   958
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
  // get signature handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
    Label L;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   963
    __ movptr(t, Address(method, Method::signature_handler_offset()));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   964
    __ testptr(t, t);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
    __ jcc(Assembler::notZero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
               CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
                                InterpreterRuntime::prepare_native_call),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
               method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
    __ get_method(method);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
   971
    __ movptr(t, Address(method, Method::signature_handler_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
  // call signature handler
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   976
  assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rlocals,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
         "adjust this code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
  assert(InterpreterRuntime::SignatureHandlerGenerator::to() == rsp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
         "adjust this code");
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   980
  assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == NOT_LP64(t) LP64_ONLY(rscratch1),
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
   981
         "adjust this code");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
  // The generated handlers do not touch RBX (the method oop).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
  // However, large signatures cannot be cached and are generated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
  // each time here.  The slow-path generator can do a GC on return,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
  // so we must reload it after the call.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
  __ call(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
  __ get_method(method);        // slow path can do a GC, reload RBX
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
  // result handler is in rax
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
  // set result handler
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   993
  __ movptr(Address(rbp,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   994
                    (frame::interpreter_frame_result_handler_offset) * wordSize),
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
   995
            rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
  // pass mirror handle if static call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
    Label L;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1000
    __ movl(t, Address(method, Method::access_flags_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
    __ testl(t, JVM_ACC_STATIC);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
    // get mirror
38074
8475fdc6dcc3 8154580: Save mirror in interpreter frame to enable cleanups of CLDClosure
coleenp
parents: 37152
diff changeset
  1004
    __ load_mirror(t, method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
    // copy mirror into activation frame
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1006
    __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
            t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    // pass handle to mirror
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1009
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1010
    __ lea(t, Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1011
    __ movptr(Address(rsp, wordSize), t);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1012
#else
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1013
    __ lea(c_rarg1,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1014
           Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1015
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
  // get native function entry point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
    Label L;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1022
    __ movptr(rax, Address(method, Method::native_function_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
    ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1024
    __ cmpptr(rax, unsatisfied.addr());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    __ jcc(Assembler::notEqual, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
    __ call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
               CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
                                InterpreterRuntime::prepare_native_call),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
               method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
    __ get_method(method);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1031
    __ movptr(rax, Address(method, Method::native_function_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
  // pass JNIEnv
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1036
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1037
   __ get_thread(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1038
   __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1039
   __ movptr(Address(rsp, 0), t);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1041
   // set_last_Java_frame_before_call
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1042
   // It is enough that the pc()
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1043
   // points into the right code segment. It does not have to be the correct return pc.
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1044
   __ set_last_Java_frame(thread, noreg, rbp, __ pc());
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1045
#else
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1046
   __ lea(c_rarg0, Address(r15_thread, JavaThread::jni_environment_offset()));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1047
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1048
   // It is enough that the pc() points into the right code
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1049
   // segment. It does not have to be the correct return pc.
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1050
   __ set_last_Java_frame(rsp, rbp, (address) __ pc());
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1051
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
  // change thread state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
    Label L;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1057
    __ movl(t, Address(thread, JavaThread::thread_state_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
    __ cmpl(t, _thread_in_Java);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    __ stop("Wrong thread state in native stub");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
  // Change state to native
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1067
  __ movl(Address(thread, JavaThread::thread_state_offset()),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
          _thread_in_native);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
  // Call the native method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
  __ call(rax);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1072
  // 32: result potentially in rdx:rax or ST0
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1073
  // 64: result potentially in rax or xmm0
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
16624
9dbd4b210bf9 8011102: Clear AVX registers after return from JNI call
kvn
parents: 15943
diff changeset
  1075
  // Verify or restore cpu control state after JNI call
9dbd4b210bf9 8011102: Clear AVX registers after return from JNI call
kvn
parents: 15943
diff changeset
  1076
  __ restore_cpu_control_state_after_jni();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  // NOTE: The order of these pushes is known to frame::interpreter_frame_result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  // in order to extract the result of a method call. If the order of these
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
  // pushes change or anything else is added to the stack then the code in
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
  // interpreter_frame_result must also change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1083
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1084
  // save potential result in ST(0) & rdx:rax
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1085
  // (if result handler is the T_FLOAT or T_DOUBLE handler, result must be in ST0 -
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1086
  // the check is necessary to avoid potential Intel FPU overflow problems by saving/restoring 'empty' FPU registers)
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1087
  // It is safe to do this push because state is _thread_in_native and return address will be found
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1088
  // via _last_native_pc and not via _last_jave_sp
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1089
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1090
  // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1091
  // If the order changes or anything else is added to the stack the code in
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1092
  // interpreter_frame_result will have to be changed.
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1093
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1094
  { Label L;
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1095
    Label push_double;
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1096
    ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1097
    ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1098
    __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1099
              float_handler.addr());
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1100
    __ jcc(Assembler::equal, push_double);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1101
    __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1102
              double_handler.addr());
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1103
    __ jcc(Assembler::notEqual, L);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1104
    __ bind(push_double);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1105
    __ push_d(); // FP values are returned using the FPU, so push FPU contents (even if UseSSE > 0).
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1106
    __ bind(L);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1107
  }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1108
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
  __ push(dtos);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1110
#endif // _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1111
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
  __ push(ltos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
  // change thread state
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1115
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1116
  __ movl(Address(thread, JavaThread::thread_state_offset()),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
          _thread_in_native_trans);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
  if (os::is_MP()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
    if (UseMembar) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
      // Force this write out before the read below
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
      __ membar(Assembler::Membar_mask_bits(
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
           Assembler::LoadLoad | Assembler::LoadStore |
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
           Assembler::StoreLoad | Assembler::StoreStore));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
      // Write serialization page so VM thread can do a pseudo remote membar.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
      // We use the current thread pointer to calculate a thread specific
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
      // offset to write to within the page. This minimizes bus traffic
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
      // due to cache line collision.
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1130
      __ serialize_memory(thread, rcx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1134
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1135
  if (AlwaysRestoreFPU) {
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1136
    //  Make sure the control word is correct.
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1137
    __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1138
  }
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1139
#endif // _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1140
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
  // check for safepoint operation in progress and/or pending suspend requests
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
    Label Continue;
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1144
    Label slow_path;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1146
#ifndef _LP64
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1147
    __ safepoint_poll(slow_path);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1148
#else
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1149
    __ safepoint_poll(slow_path, r15_thread, rscratch1);
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1150
#endif
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1151
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1152
    __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
    __ jcc(Assembler::equal, Continue);
47881
0ce0ac68ace7 8189941: Implementation JEP 312: Thread-local handshake
rehn
parents: 47823
diff changeset
  1154
    __ bind(slow_path);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
    // Don't use call_VM as it will see a possible pending exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
    // and forward it and never return here preventing us from
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
    // clearing _last_native_pc down below.  Also can't use
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
    // call_VM_leaf either as it will check to see if r13 & r14 are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
    // preserved and correspond to the bcp/locals pointers. So we do a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
    // runtime call by hand.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
    //
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1163
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1164
    __ push(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1165
    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1166
                                            JavaThread::check_special_condition_for_native_trans)));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1167
    __ increment(rsp, wordSize);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1168
    __ get_thread(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1169
#else
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1170
    __ mov(c_rarg0, r15_thread);
7401
ebde7415b521 6780143: hs203t003 hits SIGSEGV/EXCEPTION_ACCESS_VIOLATION with -XX:+UseCompressedOops
coleenp
parents: 7397
diff changeset
  1171
    __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1172
    __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1173
    __ andptr(rsp, -16); // align stack as required by ABI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1175
    __ mov(rsp, r12); // restore sp
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1176
    __ reinit_heapbase();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1177
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
    __ bind(Continue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
  // change thread state
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1182
  __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
  // reset_last_Java_frame
40644
39e631ed7145 8161598: Kitchensink fails: assert(nm->insts_contains(original_pc)) failed: original PC must be in nmethod/CompiledMethod
dlong
parents: 39390
diff changeset
  1185
  __ reset_last_Java_frame(thread, true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
41084
fc5db29fa08e 8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents: 40644
diff changeset
  1187
  if (CheckJNICalls) {
fc5db29fa08e 8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents: 40644
diff changeset
  1188
    // clear_pending_jni_exception_check
fc5db29fa08e 8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents: 40644
diff changeset
  1189
    __ movptr(Address(thread, JavaThread::pending_jni_exception_check_fn_offset()), NULL_WORD);
fc5db29fa08e 8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents: 40644
diff changeset
  1190
  }
fc5db29fa08e 8164086: Checked JNI pending exception check should be cleared when returning to Java frame
dsimms
parents: 40644
diff changeset
  1191
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
  // reset handle block
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1193
  __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
23844
0c29a324ae14 8039146: Fix 64-bit store to int JNIHandleBlock::_top
goetz
parents: 21198
diff changeset
  1194
  __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1195
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1196
  // If result is an oop unbox and store it in frame where gc will see it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1197
  // and result handler will pick it up
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1198
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1199
  {
44406
a46a6c4d1dd9 8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents: 44093
diff changeset
  1200
    Label no_oop, not_weak, store_result;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1201
    __ lea(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1202
    __ cmpptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1203
    __ jcc(Assembler::notEqual, no_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1204
    // retrieve result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1205
    __ pop(ltos);
44406
a46a6c4d1dd9 8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents: 44093
diff changeset
  1206
    // Unbox oop result, e.g. JNIHandles::resolve value.
a46a6c4d1dd9 8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents: 44093
diff changeset
  1207
    __ resolve_jobject(rax /* value */,
a46a6c4d1dd9 8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents: 44093
diff changeset
  1208
                       thread /* thread */,
a46a6c4d1dd9 8176100: [REDO][REDO] G1 Needs pre barrier on dereference of weak JNI handles
mgerdin
parents: 44093
diff changeset
  1209
                       t /* tmp */);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1210
    __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize), rax);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1211
    // keep stack depth as expected by pushing oop which will eventually be discarded
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1212
    __ push(ltos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1213
    __ bind(no_oop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1214
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1215
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1216
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1217
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1218
    Label no_reguard;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1219
    __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()),
35201
996db89f378e 8139864: Improve handling of stack protection zones.
goetz
parents: 35071
diff changeset
  1220
            JavaThread::stack_guard_yellow_reserved_disabled);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1221
    __ jcc(Assembler::notEqual, no_reguard);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1222
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1223
    __ pusha(); // XXX only save smashed registers
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1224
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1225
    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1226
    __ popa();
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1227
#else
7401
ebde7415b521 6780143: hs203t003 hits SIGSEGV/EXCEPTION_ACCESS_VIOLATION with -XX:+UseCompressedOops
coleenp
parents: 7397
diff changeset
  1228
    __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1229
    __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1230
    __ andptr(rsp, -16); // align stack as required by ABI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1231
    __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1232
    __ mov(rsp, r12); // restore sp
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1233
    __ popa(); // XXX only restore smashed registers
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1234
    __ reinit_heapbase();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1235
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1236
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1237
    __ bind(no_reguard);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1239
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1240
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1241
  // The method register is junk from after the thread_in_native transition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1242
  // until here.  Also can't call_VM until the bcp has been
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1243
  // restored.  Need bcp for throwing exception below so get it now.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1244
  __ get_method(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1245
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1246
  // restore to have legal interpreter frame, i.e., bci == 0 <=> code_base()
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1247
  __ movptr(rbcp, Address(method, Method::const_offset()));   // get ConstMethod*
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1248
  __ lea(rbcp, Address(rbcp, ConstMethod::codes_offset()));    // get codebase
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1249
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1250
  // handle exceptions (exception handling will handle unlocking!)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1251
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1252
    Label L;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1253
    __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1254
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1255
    // Note: At some point we may want to unify this with the code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1256
    // used in call_VM_base(); i.e., we should use the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1257
    // StubRoutines::forward_exception code. For now this doesn't work
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1258
    // here because the rsp is not correctly set at this point.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1259
    __ MacroAssembler::call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1260
                               CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1261
                               InterpreterRuntime::throw_pending_exception));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1262
    __ should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1263
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1264
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1265
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1266
  // do unlocking if necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1267
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1268
    Label L;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1269
    __ movl(t, Address(method, Method::access_flags_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1270
    __ testl(t, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1271
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1272
    // the code below should be shared with interpreter macro
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1273
    // assembler implementation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1274
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1275
      Label unlock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1276
      // BasicObjectLock will be first in list, since this is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1277
      // synchronized method. However, need to check that the object
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1278
      // has not been unlocked by an explicit monitorexit bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1279
      const Address monitor(rbp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1280
                            (intptr_t)(frame::interpreter_frame_initial_sp_offset *
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1281
                                       wordSize - (int)sizeof(BasicObjectLock)));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1282
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1283
      const Register regmon = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1284
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1285
      // monitor expect in c_rarg1 for slow unlock path
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1286
      __ lea(regmon, monitor); // address of first monitor
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1287
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1288
      __ movptr(t, Address(regmon, BasicObjectLock::obj_offset_in_bytes()));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1289
      __ testptr(t, t);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1290
      __ jcc(Assembler::notZero, unlock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1291
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1292
      // Entry already unlocked, need to throw exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1293
      __ MacroAssembler::call_VM(noreg,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1294
                                 CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1295
                   InterpreterRuntime::throw_illegal_monitor_state_exception));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1296
      __ should_not_reach_here();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1297
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1298
      __ bind(unlock);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1299
      __ unlock_object(regmon);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1300
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1301
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1302
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1303
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1304
  // jvmti support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1305
  // Note: This must happen _after_ handling/throwing any exceptions since
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1306
  //       the exception handler code notifies the runtime of method exits
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1307
  //       too. If this happens before, method entry/exit notifications are
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1308
  //       not properly paired (was bug - gri 11/22/99).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1309
  __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1310
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1311
  // restore potential result in edx:eax, call result handler to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1312
  // restore potential result in ST0 & handle result
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1313
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1314
  __ pop(ltos);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1315
  LP64_ONLY( __ pop(dtos));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1316
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1317
  __ movptr(t, Address(rbp,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1318
                       (frame::interpreter_frame_result_handler_offset) * wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1319
  __ call(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1320
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1321
  // remove activation
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1322
  __ movptr(t, Address(rbp,
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1323
                       frame::interpreter_frame_sender_sp_offset *
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1324
                       wordSize)); // get sender sp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1325
  __ leave();                                // remove frame anchor
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1326
  __ pop(rdi);                               // get return address
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1327
  __ mov(rsp, t);                            // set sp to sender sp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1328
  __ jmp(rdi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1329
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1330
  if (inc_counter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1331
    // Handle overflow of counter and compile method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1332
    __ bind(invocation_counter_overflow);
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
  1333
    generate_counter_overflow(continue_after_compile);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1335
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1336
  return entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1337
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1338
35479
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1339
// Abstract method entry
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1340
// Attempt to execute abstract method. Throw exception
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1341
address TemplateInterpreterGenerator::generate_abstract_entry(void) {
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1342
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1343
  address entry_point = __ pc();
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1344
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1345
  // abstract method entry
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1346
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1347
  //  pop return address, reset last_sp to NULL
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1348
  __ empty_expression_stack();
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1349
  __ restore_bcp();      // rsi must be correct for exception handler   (was destroyed)
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1350
  __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1351
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1352
  // throw exception
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1353
  __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1354
  // the call_VM checks for exception, so we should never return here.
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1355
  __ should_not_reach_here();
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1356
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1357
  return entry_point;
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1358
}
62c12ca7a45e 8146410: Interpreter functions are declared and defined in the wrong files
coleenp
parents: 35214
diff changeset
  1359
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1360
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1361
// Generic interpreted method entry to (asm) interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1362
//
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
  1363
address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1364
  // determine code generation flags
31790
4a08476437e8 8025692: Log what methods are touched at run-time
minqi
parents: 28650
diff changeset
  1365
  bool inc_counter  = UseCompiler || CountCompiledCalls || LogTouchedMethods;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1366
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1367
  // ebx: Method*
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1368
  // rbcp: sender sp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1369
  address entry_point = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1370
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1371
  const Address constMethod(rbx, Method::const_offset());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1372
  const Address access_flags(rbx, Method::access_flags_offset());
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1373
  const Address size_of_parameters(rdx,
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1374
                                   ConstMethod::size_of_parameters_offset());
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1375
  const Address size_of_locals(rdx, ConstMethod::size_of_locals_offset());
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1376
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1377
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1378
  // get parameter size (always needed)
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1379
  __ movptr(rdx, constMethod);
2148
09c7f703773b 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 2131
diff changeset
  1380
  __ load_unsigned_short(rcx, size_of_parameters);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1381
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13391
diff changeset
  1382
  // rbx: Method*
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1383
  // rcx: size of parameters
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1384
  // rbcp: sender_sp (could differ from sp+wordSize if we were called via c2i )
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1385
2148
09c7f703773b 6812678: macro assembler needs delayed binding of a few constants (for 6655638)
jrose
parents: 2131
diff changeset
  1386
  __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1387
  __ subl(rdx, rcx); // rdx = no. of additional locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1388
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1389
  // YYY
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1390
//   __ incrementl(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1391
//   __ andl(rdx, -2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1392
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1393
  // see if we've got enough room on the stack for locals plus overhead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1394
  generate_stack_overflow_check();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1395
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1396
  // get return address
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1397
  __ pop(rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1398
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1399
  // compute beginning of parameters
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1400
  __ lea(rlocals, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1401
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1402
  // rdx - # of additional locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1403
  // allocate space for locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1404
  // explicitly initialize locals
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1405
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1406
    Label exit, loop;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1407
    __ testl(rdx, rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1408
    __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1409
    __ bind(loop);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1410
    __ push((int) NULL_WORD); // initialize local variables
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1411
    __ decrementl(rdx); // until everything initialized
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1412
    __ jcc(Assembler::greater, loop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1413
    __ bind(exit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1414
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1415
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1416
  // initialize fixed part of activation frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1417
  generate_fixed_frame(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1418
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1419
  // make sure method is not native & not abstract
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1420
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1421
  __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1422
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1423
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1424
    __ testl(rax, JVM_ACC_NATIVE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1425
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1426
    __ stop("tried to execute native method as non-native");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1427
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1429
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1430
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1431
    __ testl(rax, JVM_ACC_ABSTRACT);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1432
    __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1433
    __ stop("tried to execute abstract method in interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1434
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1435
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1436
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1437
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1438
  // Since at this point in the method invocation the exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1439
  // handler would try to exit the monitor of synchronized methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1440
  // which hasn't been entered yet, we set the thread local variable
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1441
  // _do_not_unlock_if_synchronized to true. The remove_activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1442
  // will check this flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1443
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1444
  const Register thread = NOT_LP64(rax) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1445
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1446
  const Address do_not_unlock_if_synchronized(thread,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1447
        in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1448
  __ movbool(do_not_unlock_if_synchronized, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1449
21095
1a04f7b3946e 8026251: New type profiling points: parameters to methods
roland
parents: 20709
diff changeset
  1450
  __ profile_parameters_type(rax, rcx, rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1451
  // increment invocation count & check for overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1452
  Label invocation_counter_overflow;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1453
  Label profile_method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1454
  Label profile_method_continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1455
  if (inc_counter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1456
    generate_counter_incr(&invocation_counter_overflow,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1457
                          &profile_method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1458
                          &profile_method_continue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1459
    if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1460
      __ bind(profile_method_continue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1461
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1462
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1463
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1464
  Label continue_after_compile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1465
  __ bind(continue_after_compile);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1466
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1467
  // check for synchronized interpreted methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1468
  bang_stack_shadow_pages(false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1469
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1470
  // reset the _do_not_unlock_if_synchronized flag
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1471
  NOT_LP64(__ get_thread(thread));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1472
  __ movbool(do_not_unlock_if_synchronized, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1473
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1474
  // check for synchronized methods
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1475
  // Must happen AFTER invocation_counter check and stack overflow check,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1476
  // so method is not locked if overflows.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1477
  if (synchronized) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1478
    // Allocate monitor and lock method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1479
    lock_method();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1480
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1481
    // no synchronization necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1482
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1483
    {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1484
      Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1485
      __ movl(rax, access_flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1486
      __ testl(rax, JVM_ACC_SYNCHRONIZED);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1487
      __ jcc(Assembler::zero, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1488
      __ stop("method needs synchronization");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1489
      __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1490
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1491
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1492
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1493
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1494
  // start execution
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1495
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1496
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1497
    Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1498
     const Address monitor_block_top (rbp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1499
                 frame::interpreter_frame_monitor_block_top_offset * wordSize);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1500
    __ movptr(rax, monitor_block_top);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1501
    __ cmpptr(rax, rsp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1502
    __ jcc(Assembler::equal, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1503
    __ stop("broken stack frame setup in interpreter");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1504
    __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1505
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1506
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1507
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1508
  // jvmti support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1509
  __ notify_method_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1510
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1511
  __ dispatch_next(vtos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1512
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1513
  // invocation counter overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1514
  if (inc_counter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1515
    if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1516
      // We have decided to profile this method in the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1517
      __ bind(profile_method);
7889
02144432d0e1 4930919: race condition in MDO creation at back branch locations
iveresov
parents: 7401
diff changeset
  1518
      __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
02144432d0e1 4930919: race condition in MDO creation at back branch locations
iveresov
parents: 7401
diff changeset
  1519
      __ set_method_data_pointer_for_bcp();
7912
6d73dee171ea 7012766: assert(false) failed: DEBUG MESSAGE in MacroAssembler::debug32
iveresov
parents: 7889
diff changeset
  1520
      __ get_method(rbx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1521
      __ jmp(profile_method_continue);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1522
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1523
    // Handle overflow of counter and compile method
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1524
    __ bind(invocation_counter_overflow);
35214
d86005e0b4c2 8074457: Remove the non-Zero CPP Interpreter
coleenp
parents: 35201
diff changeset
  1525
    generate_counter_overflow(continue_after_compile);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1526
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1527
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1528
  return entry_point;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1529
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1530
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1531
//-----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1532
// Exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1533
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1534
void TemplateInterpreterGenerator::generate_throw_exception() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1535
  // Entry point in previous activation (i.e., if the caller was
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1536
  // interpreted)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1537
  Interpreter::_rethrow_exception_entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1538
  // Restore sp to interpreter_frame_last_sp even though we are going
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1539
  // to empty the expression stack for the exception processing.
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1540
  __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1541
  // rax: exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1542
  // rdx: return address/pc that threw exception
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1543
  __ restore_bcp();    // r13/rsi points to call/send
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1544
  __ restore_locals();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1545
  LP64_ONLY(__ reinit_heapbase());  // restore r12 as heapbase.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1546
  // Entry point for exceptions thrown within interpreter code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1547
  Interpreter::_throw_exception_entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1548
  // expression stack is undefined here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1549
  // rax: exception
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1550
  // r13/rsi: exception bcp
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1551
  __ verify_oop(rax);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1552
  Register rarg = NOT_LP64(rax) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1553
  LP64_ONLY(__ mov(c_rarg1, rax));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1554
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1555
  // expression stack must be empty before entering the VM in case of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1556
  // an exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1557
  __ empty_expression_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1558
  // find exception handler address and preserve exception oop
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1559
  __ call_VM(rdx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1560
             CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1561
                          InterpreterRuntime::exception_handler_for_exception),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1562
             rarg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1563
  // rax: exception handler entry point
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1564
  // rdx: preserved exception oop
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1565
  // r13/rsi: bcp for exception handler
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1566
  __ push_ptr(rdx); // push exception which is now the only value on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1567
  __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1568
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1569
  // If the exception is not handled in the current frame the frame is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1570
  // removed and the exception is rethrown (i.e. exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1571
  // continuation is _rethrow_exception).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1572
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1573
  // Note: At this point the bci is still the bxi for the instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1574
  // which caused the exception and the expression stack is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1575
  // empty. Thus, for any VM calls at this point, GC will find a legal
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1576
  // oop map (with empty expression stack).
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1577
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1578
  // In current activation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1579
  // tos: exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1580
  // esi: exception bcp
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1581
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1582
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1583
  // JVMTI PopFrame support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1584
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1585
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1586
  Interpreter::_remove_activation_preserving_args_entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1587
  __ empty_expression_stack();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1588
  // Set the popframe_processing bit in pending_popframe_condition
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1589
  // indicating that we are currently handling popframe, so that
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1590
  // call_VMs that may happen later do not trigger new popframe
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1591
  // handling cycles.
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1592
  const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1593
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1594
  __ movl(rdx, Address(thread, JavaThread::popframe_condition_offset()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1595
  __ orl(rdx, JavaThread::popframe_processing_bit);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1596
  __ movl(Address(thread, JavaThread::popframe_condition_offset()), rdx);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1597
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1598
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1599
    // Check to see whether we are returning to a deoptimized frame.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1600
    // (The PopFrame call ensures that the caller of the popped frame is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1601
    // either interpreted or compiled and deoptimizes it if compiled.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1602
    // In this case, we can't call dispatch_next() after the frame is
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1603
    // popped, but instead must save the incoming arguments and restore
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1604
    // them after deoptimization has occurred.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1605
    //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1606
    // Note that we don't compare the return PC against the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1607
    // deoptimization blob's unpack entry because of the presence of
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1608
    // adapter frames in C2.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1609
    Label caller_not_deoptimized;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1610
    Register rarg = NOT_LP64(rdx) LP64_ONLY(c_rarg1);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1611
    __ movptr(rarg, Address(rbp, frame::return_addr_offset * wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1612
    __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1613
                               InterpreterRuntime::interpreter_contains), rarg);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1614
    __ testl(rax, rax);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1615
    __ jcc(Assembler::notZero, caller_not_deoptimized);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1616
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1617
    // Compute size of arguments for saving when returning to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1618
    // deoptimized caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1619
    __ get_method(rax);
14745
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1620
    __ movptr(rax, Address(rax, Method::const_offset()));
03904dd8649b 8004076: Move _max_locals and _size_of_parameters to ConstMethod for better sharing.
jiangli
parents: 14626
diff changeset
  1621
    __ load_unsigned_short(rax, Address(rax, in_bytes(ConstMethod::
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1622
                                                size_of_parameters_offset())));
5419
f2e8cc8c12ea 6943304: remove tagged stack interpreter
twisti
parents: 5046
diff changeset
  1623
    __ shll(rax, Interpreter::logStackElementSize);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1624
    __ restore_locals();
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1625
    __ subptr(rlocals, rax);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1626
    __ addptr(rlocals, wordSize);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1627
    // Save these arguments
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1628
    NOT_LP64(__ get_thread(thread));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1629
    __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1630
                                           Deoptimization::
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1631
                                           popframe_preserve_args),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1632
                          thread, rax, rlocals);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1633
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1634
    __ remove_activation(vtos, rdx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1635
                         /* throw_monitor_exception */ false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1636
                         /* install_monitor_exception */ false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1637
                         /* notify_jvmdi */ false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1638
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1639
    // Inform deoptimization that it is responsible for restoring
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1640
    // these arguments
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1641
    NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1642
    __ movl(Address(thread, JavaThread::popframe_condition_offset()),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1643
            JavaThread::popframe_force_deopt_reexecution_bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1644
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1645
    // Continue in deoptimization handler
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1646
    __ jmp(rdx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1647
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1648
    __ bind(caller_not_deoptimized);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1649
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1650
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1651
  __ remove_activation(vtos, rdx, /* rdx result (retaddr) is not used */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1652
                       /* throw_monitor_exception */ false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1653
                       /* install_monitor_exception */ false,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1654
                       /* notify_jvmdi */ false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1655
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1656
  // Finish with popframe handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1657
  // A previous I2C followed by a deoptimization might have moved the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1658
  // outgoing arguments further up the stack. PopFrame expects the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1659
  // mutations to those outgoing arguments to be preserved and other
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1660
  // constraints basically require this frame to look exactly as
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1661
  // though it had previously invoked an interpreted activation with
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1662
  // no space between the top of the expression stack (current
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1663
  // last_sp) and the top of stack. Rather than force deopt to
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1664
  // maintain this kind of invariant all the time we call a small
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1665
  // fixup routine to move the mutated arguments onto the top of our
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1666
  // expression stack if necessary.
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1667
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1668
  __ mov(rax, rsp);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1669
  __ movptr(rbx, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1670
  __ get_thread(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1671
  // PC must point into interpreter here
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1672
  __ set_last_Java_frame(thread, noreg, rbp, __ pc());
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1673
  __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, rax, rbx);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1674
  __ get_thread(thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1675
#else
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1676
  __ mov(c_rarg1, rsp);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1677
  __ movptr(c_rarg2, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1678
  // PC must point into interpreter here
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1679
  __ set_last_Java_frame(noreg, rbp, __ pc());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1680
  __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), r15_thread, c_rarg1, c_rarg2);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1681
#endif
40644
39e631ed7145 8161598: Kitchensink fails: assert(nm->insts_contains(original_pc)) failed: original PC must be in nmethod/CompiledMethod
dlong
parents: 39390
diff changeset
  1682
  __ reset_last_Java_frame(thread, true);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1683
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1684
  // Restore the last_sp and null it out
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1685
  __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1686
  __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1687
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1688
  __ restore_bcp();
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1689
  __ restore_locals();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1690
  // The method data pointer was incremented already during
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1691
  // call profiling. We have to restore the mdp for the current bcp.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1692
  if (ProfileInterpreter) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1693
    __ set_method_data_pointer_for_bcp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1695
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1696
  // Clear the popframe condition flag
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1697
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1698
  __ movl(Address(thread, JavaThread::popframe_condition_offset()),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1699
          JavaThread::popframe_inactive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1700
19266
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1701
#if INCLUDE_JVMTI
24322
c2978d1578e3 8036956: remove EnableInvokeDynamic flag
anoll
parents: 24018
diff changeset
  1702
  {
19266
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1703
    Label L_done;
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1704
    const Register local0 = rlocals;
19266
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1705
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1706
    __ cmpb(Address(rbcp, 0), Bytecodes::_invokestatic);
19266
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1707
    __ jcc(Assembler::notEqual, L_done);
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1708
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1709
    // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call.
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1710
    // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL.
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1711
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1712
    __ get_method(rdx);
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1713
    __ movptr(rax, Address(local0, 0));
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1714
    __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), rax, rdx, rbcp);
19266
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1715
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1716
    __ testptr(rax, rax);
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1717
    __ jcc(Assembler::zero, L_done);
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1718
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1719
    __ movptr(Address(rbx, 0), rax);
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1720
    __ bind(L_done);
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1721
  }
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1722
#endif // INCLUDE_JVMTI
bb0324cbe0aa 7187554: JSR 292: JVMTI PopFrame needs to handle appendix arguments
sspitsyn
parents: 18507
diff changeset
  1723
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1724
  __ dispatch_next(vtos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1725
  // end of PopFrame support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1726
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1727
  Interpreter::_remove_activation_entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1728
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1729
  // preserve exception over this code sequence
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1730
  __ pop_ptr(rax);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1731
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1732
  __ movptr(Address(thread, JavaThread::vm_result_offset()), rax);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1733
  // remove the activation (without doing throws on illegalMonitorExceptions)
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1734
  __ remove_activation(vtos, rdx, false, true, false);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1735
  // restore exception
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1736
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1737
  __ get_vm_result(rax, thread);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1738
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1739
  // In between activations - previous activation type unknown yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1740
  // compute continuation point - the continuation point expects the
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1741
  // following registers set up:
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1742
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1743
  // rax: exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1744
  // rdx: return address/pc that threw exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1745
  // rsp: expression stack of caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1746
  // rbp: ebp of caller
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1747
  __ push(rax);                                  // save exception
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1748
  __ push(rdx);                                  // save return address
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1749
  __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1750
                          SharedRuntime::exception_handler_for_return_address),
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1751
                        thread, rdx);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1752
  __ mov(rbx, rax);                              // save exception handler
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1753
  __ pop(rdx);                                   // restore return address
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1754
  __ pop(rax);                                   // restore exception
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1755
  // Note that an "issuing PC" is actually the next PC after the call
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1756
  __ jmp(rbx);                                   // jump to exception
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1757
                                                 // handler of caller
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1758
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1759
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1760
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1761
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1762
// JVMTI ForceEarlyReturn support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1763
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1764
address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1765
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1766
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1767
  __ restore_bcp();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1768
  __ restore_locals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1769
  __ empty_expression_stack();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1770
  __ load_earlyret_value(state);  // 32 bits returns value in rdx, so don't reuse
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1771
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1772
  const Register thread = NOT_LP64(rcx) LP64_ONLY(r15_thread);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1773
  NOT_LP64(__ get_thread(thread));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1774
  __ movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset()));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1775
  Address cond_addr(rcx, JvmtiThreadState::earlyret_state_offset());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1776
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1777
  // Clear the earlyret state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1778
  __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1779
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1780
  __ remove_activation(state, rsi,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1781
                       false, /* throw_monitor_exception */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1782
                       false, /* install_monitor_exception */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1783
                       true); /* notify_jvmdi */
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1784
  __ jmp(rsi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1785
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1786
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1787
} // end of ForceEarlyReturn support
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1788
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1789
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1790
//-----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1791
// Helper for vtos entry point generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1792
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1793
void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1794
                                                         address& bep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1795
                                                         address& cep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1796
                                                         address& sep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1797
                                                         address& aep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1798
                                                         address& iep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1799
                                                         address& lep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1800
                                                         address& fep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1801
                                                         address& dep,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1802
                                                         address& vep) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1803
  assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1804
  Label L;
32391
01e2f5e916c7 8076373: In 32-bit VM interpreter and compiled code process NaN values differently
zmajo
parents: 31790
diff changeset
  1805
  aep = __ pc();  __ push_ptr();   __ jmp(L);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1806
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1807
  fep = __ pc(); __ push(ftos); __ jmp(L);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1808
  dep = __ pc(); __ push(dtos); __ jmp(L);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1809
#else
32391
01e2f5e916c7 8076373: In 32-bit VM interpreter and compiled code process NaN values differently
zmajo
parents: 31790
diff changeset
  1810
  fep = __ pc();  __ push_f(xmm0); __ jmp(L);
01e2f5e916c7 8076373: In 32-bit VM interpreter and compiled code process NaN values differently
zmajo
parents: 31790
diff changeset
  1811
  dep = __ pc();  __ push_d(xmm0); __ jmp(L);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1812
#endif // _LP64
32391
01e2f5e916c7 8076373: In 32-bit VM interpreter and compiled code process NaN values differently
zmajo
parents: 31790
diff changeset
  1813
  lep = __ pc();  __ push_l();     __ jmp(L);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1814
  bep = cep = sep =
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1815
  iep = __ pc();  __ push_i();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1816
  vep = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1817
  __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1818
  generate_and_dispatch(t);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1819
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1820
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1821
//-----------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1822
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1823
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1824
#ifndef PRODUCT
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1825
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1826
address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1827
  address entry = __ pc();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1828
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1829
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1830
  // prepare expression stack
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1831
  __ pop(rcx);          // pop return address so expression stack is 'pure'
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1832
  __ push(state);       // save tosca
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1833
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1834
  // pass tosca registers as arguments & call tracer
37152
29e68f1d35bb 8152065: TraceBytecodes breaks the interpreter expression stack
coleenp
parents: 36301
diff changeset
  1835
  __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), rcx, rax, rdx);
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1836
  __ mov(rcx, rax);     // make sure return address is not destroyed by pop(state)
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1837
  __ pop(state);        // restore tosca
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1838
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1839
  // return
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1840
  __ jmp(rcx);
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1841
#else
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1842
  __ push(state);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1843
  __ push(c_rarg0);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1844
  __ push(c_rarg1);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1845
  __ push(c_rarg2);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1846
  __ push(c_rarg3);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1847
  __ mov(c_rarg2, rax);  // Pass itos
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1848
#ifdef _WIN64
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1849
  __ movflt(xmm3, xmm0); // Pass ftos
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1850
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1851
  __ call_VM(noreg,
37152
29e68f1d35bb 8152065: TraceBytecodes breaks the interpreter expression stack
coleenp
parents: 36301
diff changeset
  1852
             CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1853
             c_rarg1, c_rarg2, c_rarg3);
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1854
  __ pop(c_rarg3);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1855
  __ pop(c_rarg2);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1856
  __ pop(c_rarg1);
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1857
  __ pop(c_rarg0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1858
  __ pop(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1859
  __ ret(0);                                   // return from result handler
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1860
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1861
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1862
  return entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1863
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1864
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1865
void TemplateInterpreterGenerator::count_bytecode() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1866
  __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1867
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1868
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1869
void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1870
  __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()]));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1871
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1872
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1873
void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1874
  __ mov32(rbx, ExternalAddress((address) &BytecodePairHistogram::_index));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1875
  __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1876
  __ orl(rbx,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1877
         ((int) t->bytecode()) <<
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1878
         BytecodePairHistogram::log2_number_of_codes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1879
  __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1880
  __ lea(rscratch1, ExternalAddress((address) BytecodePairHistogram::_counters));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1881
  __ incrementl(Address(rscratch1, rbx, Address::times_4));
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1882
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1883
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1884
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1885
void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1886
  // Call a little run-time stub to avoid blow-up for each bytecode.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1887
  // The run-time runtime saves the right registers, depending on
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1888
  // the tosca in-state for the given template.
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1889
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1890
  assert(Interpreter::trace_code(t->tos_in()) != NULL,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1891
         "entry must have been generated");
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1892
#ifndef _LP64
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1893
  __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1894
#else
7401
ebde7415b521 6780143: hs203t003 hits SIGSEGV/EXCEPTION_ACCESS_VIOLATION with -XX:+UseCompressedOops
coleenp
parents: 7397
diff changeset
  1895
  __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM)
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1896
  __ andptr(rsp, -16); // align stack as required by ABI
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1897
  __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
1066
717c3345024f 5108146: Merge i486 and amd64 cpu directories
never
parents: 670
diff changeset
  1898
  __ mov(rsp, r12); // restore sp
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
  1899
  __ reinit_heapbase();
34651
07b1cc0f6040 8144534: Refactor templateInterpreter and templateInterpreterGenerator functions
coleenp
parents: 33160
diff changeset
  1900
#endif // _LP64
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1901
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1902
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1903
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1904
void TemplateInterpreterGenerator::stop_interpreter_at() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1905
  Label L;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1906
  __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value),
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1907
           StopInterpreterAt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1908
  __ jcc(Assembler::notEqual, L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1909
  __ int3();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1910
  __ bind(L);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1911
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1912
#endif // !PRODUCT