hotspot/src/share/vm/interpreter/templateInterpreter.hpp
author jrose
Tue, 21 Apr 2009 23:21:04 -0700
changeset 2570 ecc7862946d4
parent 2534 08dac9ce0cd7
child 3600 27aa4477d039
permissions -rw-r--r--
6655646: dynamic languages need dynamically linked call sites Summary: invokedynamic instruction (JSR 292 RI) Reviewed-by: twisti, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2131
diff changeset
     2
 * Copyright 1997-2009 Sun Microsystems, Inc.  All Rights Reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1
diff changeset
    25
// This file contains the platform-independent parts
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// of the template interpreter and the template interpreter generator.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
#ifndef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// A little wrapper class to group tosca-specific entry points into a unit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// (tosca = Top-Of-Stack CAche)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
class EntryPoint VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  address _entry[number_of_states];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  // Construction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  EntryPoint();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  EntryPoint(address bentry, address centry, address sentry, address aentry, address ientry, address lentry, address fentry, address dentry, address ventry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  address entry(TosState state) const;                // return target address for a given tosca state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  void    set_entry(TosState state, address entry);   // set    target address for a given tosca state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  void    print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  bool operator == (const EntryPoint& y);             // for debugging only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//------------------------------------------------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
// A little wrapper class to group tosca-specific dispatch tables into a unit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
class DispatchTable VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  enum { length = 1 << BitsPerByte };                 // an entry point for each byte value (also for undefined bytecodes)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  address _table[number_of_states][length];           // dispatch tables, indexed by tosca and bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // Attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  EntryPoint entry(int i) const;                      // return entry point for a given bytecode i
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  void       set_entry(int i, EntryPoint& entry);     // set    entry point for a given bytecode i
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  address*   table_for(TosState state)          { return _table[state]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  address*   table_for()                        { return table_for((TosState)0); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  int        distance_from(address *table)      { return table - table_for(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  int        distance_from(TosState state)      { return distance_from(table_for(state)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  bool operator == (DispatchTable& y);                // for debugging only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
class TemplateInterpreter: public AbstractInterpreter {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  friend class InterpreterMacroAssembler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  friend class TemplateInterpreterGenerator;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2131
diff changeset
    80
  friend class InterpreterGenerator;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  friend class TemplateTable;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  // friend class Interpreter;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  enum MoreConstants {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    86
    number_of_return_entries  = number_of_states,               // number of return entry points
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    87
    number_of_deopt_entries   = number_of_states,               // number of deoptimization entry points
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    88
    number_of_return_addrs    = number_of_states                // number of return addresses
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  static address    _throw_ArrayIndexOutOfBoundsException_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  static address    _throw_ArrayStoreException_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  static address    _throw_ArithmeticException_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  static address    _throw_ClassCastException_entry;
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2131
diff changeset
    97
  static address    _throw_WrongMethodType_entry;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  static address    _throw_NullPointerException_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  static address    _throw_exception_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  static address    _throw_StackOverflowError_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  static address    _remove_activation_entry;                   // continuation address if an exception is not handled by current frame
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
#ifdef HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  static address    _remove_activation_preserving_args_entry;   // continuation address when current frame is being popped
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
#endif // HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static EntryPoint _trace_code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
#endif // !PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  static EntryPoint _return_entry[number_of_return_entries];    // entry points to return to from a call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static EntryPoint _earlyret_entry;                            // entry point to return early from a call
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
   113
  static EntryPoint _return_unbox_entry;                        // entry point to unbox a return value from a call
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  static EntryPoint _deopt_entry[number_of_deopt_entries];      // entry points to return to from a deoptimization
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static EntryPoint _continuation_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  static EntryPoint _safept_entry;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  static address    _return_3_addrs_by_index[number_of_return_addrs];     // for invokevirtual   return entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static address    _return_5_addrs_by_index[number_of_return_addrs];     // for invokeinterface return entries
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
   120
  static address    _return_5_unbox_addrs_by_index[number_of_return_addrs]; // for invokedynamic bootstrap methods
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  static DispatchTable _active_table;                           // the active    dispatch table (used by the interpreter for dispatch)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  static DispatchTable _normal_table;                           // the normal    dispatch table (used to set the active table in normal mode)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  static DispatchTable _safept_table;                           // the safepoint dispatch table (used to set the active table for safepoints)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  static address       _wentry_point[DispatchTable::length];    // wide instructions only (vtos tosca always)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  // Initialization/debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  static void       initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // this only returns whether a pc is within generated code for the interpreter.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static bool       contains(address pc)                        { return _code != NULL && _code->contains(pc); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  static address    remove_activation_early_entry(TosState state) { return _earlyret_entry.entry(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
#ifdef HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static address    remove_activation_preserving_args_entry()   { return _remove_activation_preserving_args_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
#endif // HOTSWAP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static address    remove_activation_entry()                   { return _remove_activation_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static address    throw_exception_entry()                     { return _throw_exception_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static address    throw_ArithmeticException_entry()           { return _throw_ArithmeticException_entry; }
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 2131
diff changeset
   144
  static address    throw_WrongMethodType_entry()               { return _throw_WrongMethodType_entry; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static address    throw_NullPointerException_entry()          { return _throw_NullPointerException_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static address    throw_StackOverflowError_entry()            { return _throw_StackOverflowError_entry; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Code generation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  static address    trace_code    (TosState state)              { return _trace_code.entry(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
#endif // !PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  static address    continuation  (TosState state)              { return _continuation_entry.entry(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static address*   dispatch_table(TosState state)              { return _active_table.table_for(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static address*   dispatch_table()                            { return _active_table.table_for(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  static int        distance_from_dispatch_table(TosState state){ return _active_table.distance_from(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  static address*   normal_table(TosState state)                { return _normal_table.table_for(state); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  static address*   normal_table()                              { return _normal_table.table_for(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  // Support for invokes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  static address*   return_3_addrs_by_index_table()             { return _return_3_addrs_by_index; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  static address*   return_5_addrs_by_index_table()             { return _return_5_addrs_by_index; }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
   162
  static address*   return_5_unbox_addrs_by_index_table()       { return _return_5_unbox_addrs_by_index; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  static int        TosState_as_index(TosState state);          // computes index into return_3_entry_by_index table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  static address    return_entry  (TosState state, int length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static address    deopt_entry   (TosState state, int length);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
   167
  static address    return_unbox_entry(TosState state, int length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // Safepoint support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  static void       notice_safepoints();                        // stops the thread when reaching a safepoint
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  static void       ignore_safepoints();                        // ignores safepoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Deoptimization support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  static address    continuation_for(methodOop method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
                                     address bcp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                                     int callee_parameters,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
                                     bool is_top_frame,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
                                     bool& use_next_mdp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
#include "incls/_templateInterpreter_pd.hpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
#endif // !CC_INTERP