hotspot/src/share/vm/interpreter/bytecode.cpp
author twisti
Mon, 04 Jan 2010 18:38:08 +0100
changeset 4564 55dfb20908d0
parent 3261 c7d5aae8d3f7
child 5688 9052dc91ea67
child 5547 f4b087cbb361
permissions -rw-r--r--
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164) Summary: During the work for 6829187 we have fixed a number of basic bugs which are logically grouped with 6815692 and 6858164 but which must be reviewed and pushed separately. Reviewed-by: kvn, never
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
3261
c7d5aae8d3f7 6862919: Update copyright year
xdono
parents: 2570
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
#include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
#include "incls/_bytecode.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Implementation of Bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// Should eventually get rid of these functions and use ThisRelativeObj methods instead
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
void Bytecode::set_code(Bytecodes::Code code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  Bytecodes::check(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  *addr_at(0) = u_char(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
bool Bytecode::check_must_rewrite() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  assert(Bytecodes::can_rewrite(code()), "post-check only");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  // Some codes are conditionally rewriting.  Look closely at them.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  switch (code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  case Bytecodes::_aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    // Even if RewriteFrequentPairs is turned on,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    // the _aload_0 code might delay its rewrite until
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // a following _getfield rewrites itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    return false;  // the rewrite is not done by the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  case Bytecodes::_new:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    // (Could actually look at the class here, but the profit would be small.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    return false;  // the rewrite is not always done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  // No other special cases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
// Implementation of Bytecode_tableupswitch
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
int Bytecode_tableswitch::dest_offset_at(int i) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  address x = aligned_addr_at(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  int x2 = aligned_offset(1 + (3 + i)*jintSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  int val = java_signed_word_at(x2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
// Implementation of Bytecode_invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
void Bytecode_invoke::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  Bytecodes::Code bc = adjusted_invoke_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  assert(is_valid(), "check invoke");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
symbolOop Bytecode_invoke::signature() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  constantPoolOop constants = method()->constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  return constants->signature_ref_at(index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
symbolOop Bytecode_invoke::name() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  constantPoolOop constants = method()->constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  return constants->name_ref_at(index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
BasicType Bytecode_invoke::result_type(Thread *thread) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  symbolHandle sh(thread, signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  ResultTypeFinder rts(sh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  rts.iterate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  return rts.type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
methodHandle Bytecode_invoke::static_target(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  methodHandle m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  KlassHandle resolved_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  constantPoolHandle constants(THREAD, _method->constants());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   105
  if (adjusted_invoke_code() == Bytecodes::_invokedynamic) {
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   106
    LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   107
  } else if (adjusted_invoke_code() != Bytecodes::_invokeinterface) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  return m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
int Bytecode_invoke::index() const {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   117
  // Note:  Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4,
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   118
  // at the same time it allocates per-call-site CP cache entries.
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   119
  if (has_giant_index())
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   120
    return Bytes::get_native_u4(bcp() + 1);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   121
  else
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   122
    return Bytes::get_Java_u2(bcp() + 1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// Implementation of Bytecode_static
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
void Bytecode_static::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
BasicType Bytecode_static::result_type(methodOop method) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  int index = java_hwrd_at(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  constantPoolOop constants = method->constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  symbolOop field_type = constants->signature_ref_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  BasicType basic_type = FieldType::basic_type(field_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  return basic_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
// Implementation of Bytecode_field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
void Bytecode_field::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
         stdc == Bytecodes::_putfield  || stdc == Bytecodes::_getfield, "check field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
bool Bytecode_field::is_static() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
int Bytecode_field::index() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  return java_hwrd_at(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
// Implementation of Bytecodes loac constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
int Bytecode_loadconstant::index() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
//------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
void Bytecode_lookupswitch::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  switch (Bytecodes::java_code(code())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
      { int i = number_of_pairs() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        while (i-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
          assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
      fatal("not a lookupswitch bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
void Bytecode_tableswitch::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  switch (Bytecodes::java_code(code())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    case Bytecodes::_tableswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      { int lo = low_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        int hi = high_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        assert (hi >= lo, "incorrect hi/lo values in tableswitch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        int i  = hi - lo - 1 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
        while (i-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
          // no special check needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
      fatal("not a tableswitch bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
#endif