hotspot/src/share/vm/interpreter/interpreterRuntime.hpp
author jrose
Tue, 21 Apr 2009 23:21:04 -0700
changeset 2570 ecc7862946d4
parent 2534 08dac9ce0cd7
child 3696 9e5d9b5e1049
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: 670
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// The InterpreterRuntime is called by the interpreter for everything
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// that cannot/should not be dealt with in assembly and needs C support.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
class InterpreterRuntime: AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
  friend class BytecodeClosure; // for method and bcp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
  friend class PrintingClosure; // for method and bcp
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // Helper functions to access current interpreter state
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  static frame     last_frame(JavaThread *thread)    { return thread->last_frame(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  static methodOop method(JavaThread *thread)        { return last_frame(thread).interpreter_frame_method(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  static address   bcp(JavaThread *thread)           { return last_frame(thread).interpreter_frame_bcp(); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  static void      set_bcp_and_mdp(address bcp, JavaThread*thread);
360
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    38
  static Bytecodes::Code code(JavaThread *thread)    {
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    39
    // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272)
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    40
    return Bytecodes::code_at(bcp(thread), method(thread));
21d113ecbf6a 6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents: 1
diff changeset
    41
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static bool      already_resolved(JavaThread *thread) { return cache_entry(thread)->is_resolved(code(thread)); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  static int       one_byte_index(JavaThread *thread)   { return bcp(thread)[1]; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static int       two_byte_index(JavaThread *thread)   { return Bytes::get_Java_u2(bcp(thread) + 1); }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    45
  static int       four_byte_index(JavaThread *thread)  { return Bytes::get_native_u4(bcp(thread) + 1); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  static int       number_of_dimensions(JavaThread *thread)  { return bcp(thread)[3]; }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    47
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    48
  static ConstantPoolCacheEntry* cache_entry_at(JavaThread *thread, int i)  { return method(thread)->constants()->cache()->entry_at(i); }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    49
  static ConstantPoolCacheEntry* cache_entry(JavaThread *thread)            { return cache_entry_at(thread, Bytes::get_native_u2(bcp(thread) + 1)); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  static void      note_trap(JavaThread *thread, int reason, TRAPS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  static void    ldc           (JavaThread* thread, bool wide);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // Allocation
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  static void    _new          (JavaThread* thread, constantPoolOopDesc* pool, int index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  static void    newarray      (JavaThread* thread, BasicType type, jint size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  static void    anewarray     (JavaThread* thread, constantPoolOopDesc* pool, int index, jint size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  static void    multianewarray(JavaThread* thread, jint* first_size_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static void    register_finalizer(JavaThread* thread, oopDesc* obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Quicken instance-of and check-cast bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  static void    quicken_io_cc(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Exceptions thrown by the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  static void    throw_AbstractMethodError(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  static void    throw_IncompatibleClassChangeError(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  static void    throw_StackOverflowError(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  static void    throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  static void    throw_ClassCastException(JavaThread* thread, oopDesc* obj);
2534
08dac9ce0cd7 6655638: dynamic languages need method handles
jrose
parents: 670
diff changeset
    72
  static void    throw_WrongMethodTypeException(JavaThread* thread, oopDesc* mtype = NULL, oopDesc* mhandle = NULL);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  static void    create_exception(JavaThread* thread, char* name, char* message);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static void    create_klass_exception(JavaThread* thread, char* name, oopDesc* obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static address exception_handler_for_exception(JavaThread* thread, oopDesc* exception);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  static void    throw_pending_exception(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  // Statics & fields
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static void    resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // Synchronization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  static void    monitorenter(JavaThread* thread, BasicObjectLock* elem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  static void    monitorexit (JavaThread* thread, BasicObjectLock* elem);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  static void    throw_illegal_monitor_state_exception(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  static void    new_illegal_monitor_state_exception(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Calls
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    89
  static void    resolve_invoke       (JavaThread* thread, Bytecodes::Code bytecode);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    90
  static void    resolve_invokedynamic(JavaThread* thread);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2534
diff changeset
    91
  static void  bootstrap_invokedynamic(JavaThread* thread, oopDesc* call_site);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Breakpoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  static void _breakpoint(JavaThread* thread, methodOopDesc* method, address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  static Bytecodes::Code get_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  static void            set_original_bytecode_at(JavaThread* thread, methodOopDesc* method, address bcp, Bytecodes::Code new_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  static bool is_breakpoint(JavaThread *thread) { return Bytecodes::code_or_bp_at(bcp(thread)) == Bytecodes::_breakpoint; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // Safepoints
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  static void    at_safepoint(JavaThread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  // Debugger support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  static void post_field_access(JavaThread *thread, oopDesc* obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    ConstantPoolCacheEntry *cp_entry);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  static void post_field_modification(JavaThread *thread, oopDesc* obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    ConstantPoolCacheEntry *cp_entry, jvalue *value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  static void post_method_entry(JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  static void post_method_exit (JavaThread *thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  static int  interpreter_contains(address pc);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Native signature handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  static void prepare_native_call(JavaThread* thread, methodOopDesc* method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  static address slow_signature_handler(JavaThread* thread,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
                                        methodOopDesc* method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
                                        intptr_t* from, intptr_t* to);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
#if defined(IA32) || defined(AMD64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // Popframe support (only needed on x86 and AMD64)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  static void popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  // Platform dependent stuff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  #include "incls/_interpreterRT_pd.hpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Interpreter's frequency counter overflow
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static nmethod* frequency_counter_overflow(JavaThread* thread, address branch_bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  // Interpreter profiling support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  static jint    bcp_to_di(methodOopDesc* method, address cur_bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  static jint    profile_method(JavaThread* thread, address cur_bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  static void    update_mdp_for_ret(JavaThread* thread, int bci);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  static void    verify_mdp(methodOopDesc* method, address bcp, address mdp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
#endif // ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
class SignatureHandlerLibrary: public AllStatic {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  enum { buffer_size =  1*K }; // the size of the temporary code buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  enum { blob_size   = 32*K }; // the size of a handler code blob.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static BufferBlob*              _handler_blob; // the current buffer blob containing the generated handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static address                  _handler;      // next available address within _handler_blob;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static GrowableArray<address>*  _handlers;     // the corresponding handlers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  static address                  _buffer;       // the temporary code buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  static address set_handler_blob();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  static void initialize();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  static address set_handler(CodeBuffer* buffer);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static void pd_set_handler(address handler);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  static void add(methodHandle method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
};