hotspot/src/share/vm/interpreter/rewriter.cpp
author jrose
Tue, 21 Apr 2009 23:21:04 -0700
changeset 2570 ecc7862946d4
parent 2105 347008ce7984
child 3273 6acf7084b1d3
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
/*
2105
347008ce7984 6814575: Update copyright year
xdono
parents: 2006
diff changeset
     2
 * Copyright 1998-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
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
# include "incls/_rewriter.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    28
// Computes a CPC map (new_index -> original_index) for constant pool entries
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// that are referred to by the interpreter at runtime via the constant pool cache.
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    30
// Also computes a CP map (original_index -> new_index).
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    31
// Marks entries in CP which require additional processing.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    32
void Rewriter::compute_index_maps() {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    33
  const int length  = _pool->length();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    34
  init_cp_map(length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  for (int i = 0; i < length; i++) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    36
    int tag = _pool->tag_at(i).value();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    37
    switch (tag) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    38
      case JVM_CONSTANT_InterfaceMethodref:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
      case JVM_CONSTANT_Fieldref          : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
      case JVM_CONSTANT_Methodref         : // fall through
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    41
        add_cp_cache_entry(i);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    42
        break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    45
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    46
  guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    47
            "all cp cache indexes fit in a u2");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    51
int Rewriter::add_extra_cp_cache_entry(int main_entry) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    52
  // Hack: We put it on the map as an encoded value.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    53
  // The only place that consumes this is ConstantPoolCacheEntry::set_initial_state
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    54
  int encoded = constantPoolCacheOopDesc::encode_secondary_index(main_entry);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    55
  int plain_secondary_index = _cp_cache_map.append(encoded);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    56
  return constantPoolCacheOopDesc::encode_secondary_index(plain_secondary_index);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    57
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    58
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    59
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    60
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    61
// Creates a constant pool cache given a CPC map
2006
f2d2f0f20063 6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents: 1
diff changeset
    62
// This creates the constant pool cache initially in a state
f2d2f0f20063 6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents: 1
diff changeset
    63
// that is unsafe for concurrent GC processing but sets it to
f2d2f0f20063 6792421: assert(_bitMap->isMarked(addr+size-1),inconsistent Printezis mark)
jmasa
parents: 1
diff changeset
    64
// a safe mode before the constant pool cache is returned.
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    65
void Rewriter::make_constant_pool_cache(TRAPS) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    66
  const int length = _cp_cache_map.length();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    67
  constantPoolCacheOop cache =
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    68
      oopFactory::new_constantPoolCache(length, methodOopDesc::IsUnsafeConc, CHECK);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    69
  cache->initialize(_cp_cache_map);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    70
  _pool->set_cache(cache);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
    71
  cache->set_constant_pool(_pool());
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// The new finalization semantics says that registration of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// finalizable objects must be performed on successful return from the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// Object.<init> constructor.  We could implement this trivially if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
// <init> were never rewritten but since JVMTI allows this to occur, a
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
// more complicated solution is required.  A special return bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
// is used only by Object.<init> to signal the finalization
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
// registration point.  Additionally local 0 must be preserved so it's
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
// available to pass to the registration function.  For simplicty we
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
// require that local 0 is never overwritten so it's available as an
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
// argument for registration.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
void Rewriter::rewrite_Object_init(methodHandle method, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  RawBytecodeStream bcs(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  while (!bcs.is_last_bytecode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    Bytecodes::Code opcode = bcs.raw_next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    switch (opcode) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      case Bytecodes::_istore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
      case Bytecodes::_lstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
      case Bytecodes::_fstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
      case Bytecodes::_dstore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      case Bytecodes::_astore:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        if (bcs.get_index() != 0) continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
        // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      case Bytecodes::_istore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      case Bytecodes::_lstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      case Bytecodes::_fstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      case Bytecodes::_dstore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      case Bytecodes::_astore_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
        THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
                  "can't overwrite local 0 in Object.<init>");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   115
// Rewrite a classfile-order CP index into a native-order CPC index.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   116
int Rewriter::rewrite_member_reference(address bcp, int offset) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   117
  address p = bcp + offset;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   118
  int  cp_index    = Bytes::get_Java_u2(p);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   119
  int  cache_index = cp_entry_to_cp_cache(cp_index);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   120
  Bytes::put_native_u2(p, cache_index);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   121
  return cp_index;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   122
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   123
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   124
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   125
void Rewriter::rewrite_invokedynamic(address bcp, int offset, int delete_me) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   126
  address p = bcp + offset;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   127
  assert(p[-1] == Bytecodes::_invokedynamic, "");
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   128
  int cp_index = Bytes::get_Java_u2(p);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   129
  int cpc  = maybe_add_cp_cache_entry(cp_index);  // add lazily
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   130
  int cpc2 = add_extra_cp_cache_entry(cpc);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   131
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   132
  // Replace the trailing four bytes with a CPC index for the dynamic
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   133
  // call site.  Unlike other CPC entries, there is one per bytecode,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   134
  // not just one per distinct CP entry.  In other words, the
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   135
  // CPC-to-CP relation is many-to-one for invokedynamic entries.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   136
  // This means we must use a larger index size than u2 to address
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   137
  // all these entries.  That is the main reason invokedynamic
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   138
  // must have a five-byte instruction format.  (Of course, other JVM
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   139
  // implementations can use the bytes for other purposes.)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   140
  Bytes::put_native_u4(p, cpc2);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   141
  // Note: We use native_u4 format exclusively for 4-byte indexes.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   142
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   143
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   144
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
// Rewrites a method given the index_map information
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   146
void Rewriter::scan_method(methodOop method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  int nof_jsrs = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  bool has_monitor_bytecodes = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    // We cannot tolerate a GC in this block, because we've
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    // cached the bytecodes in 'code_base'. If the methodOop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    // moves, the bytecodes will also move.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    No_Safepoint_Verifier nsv;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    Bytecodes::Code c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    // Bytecodes and their length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    const address code_base = method->code_base();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    const int code_length = method->code_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    int bc_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    for (int bci = 0; bci < code_length; bci += bc_length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      address bcp = code_base + bci;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   165
      int prefix_length = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      c = (Bytecodes::Code)(*bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      // Since we have the code, see if we can get the length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      // directly. Some more complicated bytecodes will report
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      // a length of zero, meaning we need to make another method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      // call to calculate the length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      bc_length = Bytecodes::length_for(c);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
      if (bc_length == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        bc_length = Bytecodes::length_at(bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        // length_at will put us at the bytecode after the one modified
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
        // by 'wide'. We don't currently examine any of the bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        // modified by wide, but in case we do in the future...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        if (c == Bytecodes::_wide) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   180
          prefix_length = 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
          c = (Bytecodes::Code)bcp[1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      assert(bc_length != 0, "impossible bytecode length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
      switch (c) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        case Bytecodes::_lookupswitch   : {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
#ifndef CC_INTERP
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
          Bytecode_lookupswitch* bc = Bytecode_lookupswitch_at(bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
          bc->set_code(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
            bc->number_of_pairs() < BinarySwitchThreshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
            ? Bytecodes::_fast_linearswitch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
            : Bytecodes::_fast_binaryswitch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
          );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        case Bytecodes::_getstatic      : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
        case Bytecodes::_putstatic      : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        case Bytecodes::_getfield       : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
        case Bytecodes::_putfield       : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
        case Bytecodes::_invokevirtual  : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
        case Bytecodes::_invokespecial  : // fall through
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   205
        case Bytecodes::_invokestatic   :
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   206
        case Bytecodes::_invokeinterface:
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   207
          rewrite_member_reference(bcp, prefix_length+1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
          break;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   209
        case Bytecodes::_invokedynamic:
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   210
          rewrite_invokedynamic(bcp, prefix_length+1, int(sizeof"@@@@DELETE ME"));
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   211
          break;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        case Bytecodes::_jsr            : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
        case Bytecodes::_jsr_w          : nof_jsrs++;                   break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        case Bytecodes::_monitorenter   : // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        case Bytecodes::_monitorexit    : has_monitor_bytecodes = true; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // Update access flags
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  if (has_monitor_bytecodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    method->set_has_monitor_bytecodes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // The present of a jsr bytecode implies that the method might potentially
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // have to be rewritten, so we run the oopMapGenerator on the method
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  if (nof_jsrs > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    method->set_has_jsrs();
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   229
    // Second pass will revisit this method.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   230
    assert(method->has_jsrs(), "");
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   231
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   232
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   234
// After constant pool is created, revisit methods containing jsrs.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   235
methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   236
  ResolveOopMapConflicts romc(method);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   237
  methodHandle original_method = method;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   238
  method = romc.do_potential_rewrite(CHECK_(methodHandle()));
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   239
  if (method() != original_method()) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   240
    // Insert invalid bytecode into original methodOop and set
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   241
    // interpreter entrypoint, so that a executing this method
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   242
    // will manifest itself in an easy recognizable form.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   243
    address bcp = original_method->bcp_from(0);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   244
    *bcp = (u1)Bytecodes::_shouldnotreachhere;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   245
    int kind = Interpreter::method_kind(original_method);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   246
    original_method->set_interpreter_kind(kind);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   249
  // Update monitor matching info.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   250
  if (romc.monitor_safe()) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   251
    method->set_guaranteed_monitor_matching();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   252
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  return method;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  ResourceMark rm(THREAD);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   260
  Rewriter     rw(klass, CHECK);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   261
  // (That's all, folks.)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   262
}
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   263
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   264
Rewriter::Rewriter(instanceKlassHandle klass, TRAPS)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   265
  : _klass(klass),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   266
    // gather starting points
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   267
    _pool(   THREAD, klass->constants()),
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   268
    _methods(THREAD, klass->methods())
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   269
{
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   270
  assert(_pool->cache() == NULL, "constant pool cache must not be set yet");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  // determine index maps for methodOop rewriting
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   273
  compute_index_maps();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   275
  if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   276
    int i = _methods->length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
    while (i-- > 0) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   278
      methodOop method = (methodOop)_methods->obj_at(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
      if (method->intrinsic_id() == vmIntrinsics::_Object_init) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        // rewrite the return bytecodes of Object.<init> to register the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
        // object for finalization if needed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
        methodHandle m(THREAD, method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        rewrite_Object_init(m, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   289
  // rewrite methods, in two passes
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   290
  int i, len = _methods->length();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   291
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   292
  for (i = len; --i >= 0; ) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   293
    methodOop method = (methodOop)_methods->obj_at(i);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   294
    scan_method(method);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   295
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   296
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   297
  // allocate constant pool cache, now that we've seen all the bytecodes
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   298
  make_constant_pool_cache(CHECK);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   299
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   300
  for (i = len; --i >= 0; ) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   301
    methodHandle m(THREAD, (methodOop)_methods->obj_at(i));
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   302
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   303
    if (m->has_jsrs()) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   304
      m = rewrite_jsrs(m, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
      // Method might have gotten rewritten.
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   306
      _methods->obj_at_put(i, m());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   308
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   309
    // Set up method entry points for compiler and interpreter.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 2105
diff changeset
   310
    m->link_method(m, CHECK);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
}