hotspot/src/share/vm/interpreter/bytecode.cpp
author jrose
Sun, 23 May 2010 01:38:26 -0700
changeset 5688 9052dc91ea67
parent 4564 55dfb20908d0
child 5697 0cf7190475ee
permissions -rw-r--r--
6939207: refactor constant pool index processing Summary: Factored cleanup of instruction decode which prepares for enhanced ldc semantics. Reviewed-by: twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
     2
 * Copyright 1997-2010 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
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    30
bool Bytecode::check_must_rewrite(Bytecodes::Code code) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    31
  assert(Bytecodes::can_rewrite(code), "post-check only");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  // Some codes are conditionally rewriting.  Look closely at them.
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    34
  switch (code) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  case Bytecodes::_aload_0:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
    // Even if RewriteFrequentPairs is turned on,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    // the _aload_0 code might delay its rewrite until
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    // a following _getfield rewrites itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    return false;  // the rewrite is not done by the interpreter
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  case Bytecodes::_new:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // (Could actually look at the class here, but the profit would be small.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    return false;  // the rewrite is not always done
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // No other special cases.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    54
#ifdef ASSERT
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    55
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    56
void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    57
  Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    58
  if (thisbc == Bytecodes::_breakpoint)  return;  // let the assertion fail silently
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    59
  if (is_wide) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    60
    assert(thisbc == Bytecodes::_wide, "expected a wide instruction");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    61
    thisbc = Bytecodes::cast(byte_at(1));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    62
    if (thisbc == Bytecodes::_breakpoint)  return;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    63
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    64
  int thisflags = Bytecodes::flags(testbc, is_wide) & Bytecodes::_all_fmt_bits;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    65
  int testflags = Bytecodes::flags(thisbc, is_wide) & Bytecodes::_all_fmt_bits;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    66
  if (thisflags != testflags)
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    67
    tty->print_cr("assert_same_format_as(%d) failed on bc=%d%s; %d != %d",
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    68
                  (int)testbc, (int)thisbc, (is_wide?"/wide":""), testflags, thisflags);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    69
  assert(thisflags == testflags, "expected format");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    70
}
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    71
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    72
void Bytecode::assert_index_size(int size, Bytecodes::Code bc, bool is_wide) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    73
  int have_fmt = (Bytecodes::flags(bc, is_wide)
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    74
                  & (Bytecodes::_fmt_has_u2 | Bytecodes::_fmt_has_u4 |
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    75
                     Bytecodes::_fmt_not_simple |
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    76
                     // Not an offset field:
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    77
                     Bytecodes::_fmt_has_o));
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    78
  int need_fmt = -1;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    79
  switch (size) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    80
  case 1: need_fmt = 0;                      break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    81
  case 2: need_fmt = Bytecodes::_fmt_has_u2; break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    82
  case 4: need_fmt = Bytecodes::_fmt_has_u4; break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    83
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    84
  if (is_wide)  need_fmt |= Bytecodes::_fmt_not_simple;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    85
  if (have_fmt != need_fmt) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    86
    tty->print_cr("assert_index_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    87
    assert(have_fmt == need_fmt, "assert_index_size");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    88
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    89
}
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    90
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    91
void Bytecode::assert_offset_size(int size, Bytecodes::Code bc, bool is_wide) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    92
  int have_fmt = Bytecodes::flags(bc, is_wide) & Bytecodes::_all_fmt_bits;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    93
  int need_fmt = -1;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    94
  switch (size) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    95
  case 2: need_fmt = Bytecodes::_fmt_bo2; break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    96
  case 4: need_fmt = Bytecodes::_fmt_bo4; break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    97
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    98
  if (is_wide)  need_fmt |= Bytecodes::_fmt_not_simple;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
    99
  if (have_fmt != need_fmt) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   100
    tty->print_cr("assert_offset_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   101
    assert(have_fmt == need_fmt, "assert_offset_size");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   102
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   103
}
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   104
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   105
void Bytecode::assert_constant_size(int size, int where, Bytecodes::Code bc, bool is_wide) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   106
  int have_fmt = Bytecodes::flags(bc, is_wide) & (Bytecodes::_all_fmt_bits
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   107
                                                  // Ignore any 'i' field (for iinc):
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   108
                                                  & ~Bytecodes::_fmt_has_i);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   109
  int need_fmt = -1;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   110
  switch (size) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   111
  case 1: need_fmt = Bytecodes::_fmt_bc;                          break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   112
  case 2: need_fmt = Bytecodes::_fmt_bc | Bytecodes::_fmt_has_u2; break;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   113
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   114
  if (is_wide)  need_fmt |= Bytecodes::_fmt_not_simple;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   115
  int length = is_wide ? Bytecodes::wide_length_for(bc) : Bytecodes::length_for(bc);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   116
  if (have_fmt != need_fmt || where + size != length) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   117
    tty->print_cr("assert_constant_size %d @%d: bc=%d%s %d != %d", size, where, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   118
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   119
  assert(have_fmt == need_fmt, "assert_constant_size");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   120
  assert(where + size == length, "assert_constant_size oob");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   121
}
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   122
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   123
void Bytecode::assert_native_index(Bytecodes::Code bc, bool is_wide) {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   124
  assert((Bytecodes::flags(bc, is_wide) & Bytecodes::_fmt_has_nbo) != 0, "native index");
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   125
}
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   126
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   127
#endif //ASSERT
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// Implementation of Bytecode_tableupswitch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
int Bytecode_tableswitch::dest_offset_at(int i) const {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   132
  return get_Java_u4_at(aligned_offset(1 + (3 + i)*jintSize));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
// Implementation of Bytecode_invoke
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
void Bytecode_invoke::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  Bytecodes::Code bc = adjusted_invoke_code();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  assert(is_valid(), "check invoke");
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   141
  assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
symbolOop Bytecode_invoke::signature() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  constantPoolOop constants = method()->constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  return constants->signature_ref_at(index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
symbolOop Bytecode_invoke::name() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  constantPoolOop constants = method()->constants();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  return constants->name_ref_at(index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
BasicType Bytecode_invoke::result_type(Thread *thread) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  symbolHandle sh(thread, signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  ResultTypeFinder rts(sh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  rts.iterate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  return rts.type();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
methodHandle Bytecode_invoke::static_target(TRAPS) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  methodHandle m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  KlassHandle resolved_klass;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  constantPoolHandle constants(THREAD, _method->constants());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
4564
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   170
  if (adjusted_invoke_code() == Bytecodes::_invokedynamic) {
55dfb20908d0 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 3261
diff changeset
   171
    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
   172
  } else if (adjusted_invoke_code() != Bytecodes::_invokeinterface) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
    LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  return m;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
int Bytecode_invoke::index() const {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   182
  // 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
   183
  // at the same time it allocates per-call-site CP cache entries.
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   184
  Bytecodes::Code stdc = Bytecodes::java_code(code());
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   185
  Bytecode* invoke = Bytecode_at(bcp());
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   186
  if (invoke->has_index_u4(stdc))
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   187
    return invoke->get_index_u4(stdc);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   188
  else
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   189
    return invoke->get_index_u2_cpcache(stdc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
// Implementation of Bytecode_field
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
void Bytecode_field::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
         stdc == Bytecodes::_putfield  || stdc == Bytecodes::_getfield, "check field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
bool Bytecode_field::is_static() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  Bytecodes::Code stdc = Bytecodes::java_code(code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
int Bytecode_field::index() const {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   209
  Bytecode* invoke = Bytecode_at(bcp());
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   210
  return invoke->get_index_u2_cpcache(Bytecodes::_getfield);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// Implementation of Bytecodes loac constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
int Bytecode_loadconstant::index() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  Bytecodes::Code stdc = Bytecodes::java_code(code());
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 4564
diff changeset
   218
  return stdc == Bytecodes::_ldc ? get_index_u1(stdc) : get_index_u2(stdc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
//------------------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
// Non-product code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
void Bytecode_lookupswitch::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  switch (Bytecodes::java_code(code())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    case Bytecodes::_lookupswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
      { int i = number_of_pairs() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
        while (i-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
          assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      fatal("not a lookupswitch bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
void Bytecode_tableswitch::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  switch (Bytecodes::java_code(code())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    case Bytecodes::_tableswitch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
      { int lo = low_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
        int hi = high_key();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
        assert (hi >= lo, "incorrect hi/lo values in tableswitch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        int i  = hi - lo - 1 ;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
        while (i-- > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
          // no special check needed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
      fatal("not a tableswitch bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
#endif