hotspot/src/share/vm/interpreter/rewriter.hpp
author jiangli
Tue, 26 Jun 2012 19:08:44 -0400
changeset 13282 9872915dd78d
parent 9971 d496ecd7b9de
child 13391 30245956af37
permissions -rw-r--r--
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table. Summary: Change constMethodOop::_exception_table to optionally inlined u2 table. Reviewed-by: bdelsart, coleenp, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5702
jrose
parents: 5547 5688
diff changeset
     2
 * Copyright (c) 1998, 2010, 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: 4567
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 4567
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: 4567
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: 6062
diff changeset
    25
#ifndef SHARE_VM_INTERPRETER_REWRITER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    26
#define SHARE_VM_INTERPRETER_REWRITER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    29
#include "runtime/handles.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    30
#include "utilities/growableArray.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// The Rewriter adds caches to the constant pool and rewrites bytecode indices
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// pointing into the constant pool for better interpreter performance.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    35
class Rewriter: public StackObj {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
 private:
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    37
  instanceKlassHandle _klass;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    38
  constantPoolHandle  _pool;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    39
  objArrayHandle      _methods;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    40
  intArray            _cp_map;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    41
  intStack            _cp_cache_map;
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    42
  bool                _have_invoke_dynamic;
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    43
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    44
  void init_cp_map(int length) {
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    45
    _cp_map.initialize(length, -1);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    46
    // Choose an initial value large enough that we don't get frequent
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    47
    // calls to grow().
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    48
    _cp_cache_map.initialize(length / 2);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    49
  }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    50
  int  cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    51
  bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[i] >= 0; }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    52
  int maybe_add_cp_cache_entry(int i) { return has_cp_cache(i) ? _cp_map[i] : add_cp_cache_entry(i); }
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    53
  int add_cp_cache_entry(int cp_index) {
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
    54
    assert((cp_index & _secondary_entry_tag) == 0, "bad tag");
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    55
    assert(_cp_map[cp_index] == -1, "not twice on same cp_index");
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    56
    int cache_index = _cp_cache_map.append(cp_index);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    57
    _cp_map.at_put(cp_index, cache_index);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    58
    assert(cp_entry_to_cp_cache(cp_index) == cache_index, "");
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    59
    return cache_index;
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    60
  }
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
    61
  int add_secondary_cp_cache_entry(int main_cpc_entry) {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
    62
    assert(main_cpc_entry < _cp_cache_map.length(), "must be earlier CP cache entry");
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
    63
    int cache_index = _cp_cache_map.append(main_cpc_entry | _secondary_entry_tag);
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
    64
    return cache_index;
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
    65
  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    66
6062
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    67
  // Access the contents of _cp_cache_map to determine CP cache layout.
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    68
  int cp_cache_entry_pool_index(int cache_index) {
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    69
    int cp_index = _cp_cache_map[cache_index];
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    70
    if ((cp_index & _secondary_entry_tag) != 0)
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    71
      return -1;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    72
    else
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    73
      return cp_index;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    74
  }
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    75
  int cp_cache_secondary_entry_main_index(int cache_index) {
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    76
    int cp_index = _cp_cache_map[cache_index];
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    77
    if ((cp_index & _secondary_entry_tag) == 0)
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    78
      return -1;
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    79
    else
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    80
      return (cp_index - _secondary_entry_tag);
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    81
  }
bab93afe9df7 6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents: 5882
diff changeset
    82
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    83
  // All the work goes in here:
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4429
diff changeset
    84
  Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    85
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    86
  void compute_index_maps();
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    87
  void make_constant_pool_cache(TRAPS);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    88
  void scan_method(methodOop m, bool reverse = false);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    89
  void rewrite_Object_init(methodHandle m, TRAPS);
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    90
  void rewrite_member_reference(address bcp, int offset, bool reverse = false);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    91
  void rewrite_invokedynamic(address bcp, int offset, bool reverse = false);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    92
  void maybe_rewrite_ldc(address bcp, int offset, bool is_wide, bool reverse = false);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    93
  // Revert bytecodes in case of an exception.
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    94
  void restore_bytecodes();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
    96
  static methodHandle rewrite_jsrs(methodHandle m, TRAPS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
 public:
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
    98
  // Driver routine:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  static void rewrite(instanceKlassHandle klass, TRAPS);
4567
7fc02fbe5c7a 6893268: additional dynamic language related optimizations in C2
twisti
parents: 4429
diff changeset
   100
  static void rewrite(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS);
4429
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
   101
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
   102
  enum {
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
   103
    _secondary_entry_tag = nth_bit(30)
d7eb4e2099aa 6858164: invokedynamic code needs some cleanup (post-6655638)
jrose
parents: 3261
diff changeset
   104
  };
9971
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   105
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   106
  // Second pass, not gated by is_rewritten flag
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   107
  static void relocate_and_link(instanceKlassHandle klass, TRAPS);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   108
  // JSR292 version to call with it's own methods.
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   109
  static void relocate_and_link(instanceKlassHandle klass,
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   110
                                objArrayHandle methods, TRAPS);
d496ecd7b9de 7033141: assert(has_cp_cache(i)) failed: oob
coleenp
parents: 7397
diff changeset
   111
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
   113
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6062
diff changeset
   114
#endif // SHARE_VM_INTERPRETER_REWRITER_HPP