src/hotspot/share/interpreter/bytecodeStream.hpp
author ccheung
Fri, 09 Mar 2018 13:36:39 -0800
changeset 49372 3bb8b00832d0
parent 47216 71c04702a3d5
child 49480 d7df2dd501ce
permissions -rw-r--r--
8196626: [Graal] runtime/appcds/UseAppCDS.java crashes with "VM thread using lock Heap_lock (not allowed to block on)" Summary: print a message and abort CDS dumping when the allocation of metaspace has failed Reviewed-by: iklam, mseledtsov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
39712
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
     2
 * Copyright (c) 1997, 2016, 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: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
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: 3261
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: 5702
diff changeset
    25
#ifndef SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    26
#define SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    28
#include "interpreter/bytecode.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    29
#include "memory/allocation.hpp"
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8107
diff changeset
    30
#include "oops/method.hpp"
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8107
diff changeset
    31
#include "runtime/handles.inline.hpp"
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 13728
diff changeset
    32
#include "utilities/bytes.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// A BytecodeStream is used for fast iteration over the bytecodes
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 8107
diff changeset
    35
// of a Method*.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// Usage:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// BytecodeStream s(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// Bytecodes::Code c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// while ((c = s.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//   ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    44
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// A RawBytecodeStream is a simple version of BytecodeStream.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// It is used ONLY when we know the bytecodes haven't been rewritten
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    47
// yet, such as in the rewriter or the verifier.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    49
// Here is the common base class for both RawBytecodeStream and BytecodeStream:
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    50
class BaseBytecodeStream: StackObj {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // stream buffer
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  methodHandle    _method;                       // read from method directly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // reading position
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int             _bci;                          // bci if current bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  int             _next_bci;                     // bci of next bytecode
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  int             _end_bci;                      // bci after the current iteration interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // last bytecode read
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    61
  Bytecodes::Code _raw_code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
  bool            _is_wide;
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    63
  bool            _is_raw;                       // false in 'cooked' BytecodeStream
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    64
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    65
  // Construction
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25715
diff changeset
    66
  BaseBytecodeStream(const methodHandle& method) : _method(method) {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    67
    set_interval(0, _method->code_size());
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    68
    _is_raw = false;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    69
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // Iteration control
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  void set_interval(int beg_bci, int end_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // iterate over the interval [beg_bci, end_bci)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    assert(0 <= beg_bci && beg_bci <= method()->code_size(), "illegal beg_bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    assert(0 <= end_bci && end_bci <= method()->code_size(), "illegal end_bci");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // setup of iteration pointers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    _bci      = beg_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    _next_bci = beg_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    _end_bci  = end_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  void set_start   (int beg_bci) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    set_interval(beg_bci, _method->code_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    86
  bool is_raw() const { return _is_raw; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    87
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    88
  // Stream attributes
35194
7151995ee79e 8144256: compiler/uncommontrap/TestStackBangRbp.java crashes VM on Solaris
coleenp
parents: 33593
diff changeset
    89
  const methodHandle& method() const             { return _method; }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    90
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    91
  int             bci() const                    { return _bci; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    92
  int             next_bci() const               { return _next_bci; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    93
  int             end_bci() const                { return _end_bci; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    94
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    95
  Bytecodes::Code raw_code() const               { return _raw_code; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    96
  bool            is_wide() const                { return _is_wide; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    97
  int             instruction_size() const       { return (_next_bci - _bci); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    98
  bool            is_last_bytecode() const       { return _next_bci >= _end_bci; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
    99
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   100
  address         bcp() const                    { return method()->code_base() + _bci; }
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   101
  Bytecode        bytecode() const               { return Bytecode(_method(), bcp()); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   102
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   103
  // State changes
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   104
  void            set_next_bci(int bci)          { assert(0 <= bci && bci <= method()->code_size(), "illegal bci"); _next_bci = bci; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   105
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   106
  // Bytecode-specific attributes
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   107
  int             dest() const                   { return bci() + bytecode().get_offset_s2(raw_code()); }
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   108
  int             dest_w() const                 { return bci() + bytecode().get_offset_s4(raw_code()); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   109
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   110
  // One-byte indices.
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   111
  int             get_index_u1() const           { assert_raw_index_size(1); return *(jubyte*)(bcp()+1); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   112
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   113
 protected:
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   114
  void assert_raw_index_size(int size) const NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   115
  void assert_raw_stream(bool want_raw) const NOT_DEBUG_RETURN;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   116
};
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   117
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   118
class RawBytecodeStream: public BaseBytecodeStream {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   119
 public:
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   120
  // Construction
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25715
diff changeset
   121
  RawBytecodeStream(const methodHandle& method) : BaseBytecodeStream(method) {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   122
    _is_raw = true;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   123
  }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   124
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   125
 public:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  // Iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Use raw_next() rather than next() for faster method reference
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  Bytecodes::Code raw_next() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    Bytecodes::Code code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    // set reading position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
    _bci = _next_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    assert(!is_last_bytecode(), "caller should check is_last_bytecode()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   134
    address bcp = this->bcp();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    code        = Bytecodes::code_or_bp_at(bcp);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    // set next bytecode position
39712
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   138
    int len = Bytecodes::length_for(code);
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   139
    if (len > 0 && (_bci <= _end_bci - len)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
      assert(code != Bytecodes::_wide && code != Bytecodes::_tableswitch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
             && code != Bytecodes::_lookupswitch, "can't be special bytecode");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      _is_wide = false;
39712
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   143
      _next_bci += len;
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   144
      if (_next_bci <= _bci) { // Check for integer overflow
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   145
        code = Bytecodes::_illegal;
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   146
      }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   147
      _raw_code = code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      return code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      return raw_next_special(code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  Bytecodes::Code raw_next_special(Bytecodes::Code code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   155
  // Unsigned indices, widening, with no swapping of bytes
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   156
  int             get_index() const          { return (is_wide()) ? get_index_u2_raw(bcp() + 2) : get_index_u1(); }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   157
  // Get an unsigned 2-byte index, with no swapping of bytes.
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   158
  int             get_index_u2() const       { assert(!is_wide(), ""); return get_index_u2_raw(bcp() + 1);  }
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   159
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   160
 private:
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   161
  int get_index_u2_raw(address p) const {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   162
    assert_raw_index_size(2); assert_raw_stream(true);
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   163
    return Bytes::get_Java_u2(p);
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   164
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// In BytecodeStream, non-java bytecodes will be translated into the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// corresponding java bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   170
class BytecodeStream: public BaseBytecodeStream {
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   171
  Bytecodes::Code _code;
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   172
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  // Construction
33593
60764a78fa5c 8140274: methodHandles and constantPoolHandles should be passed as const references
coleenp
parents: 25715
diff changeset
   175
  BytecodeStream(const methodHandle& method) : BaseBytecodeStream(method) { }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // Iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  Bytecodes::Code next() {
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   179
    Bytecodes::Code raw_code, code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    // set reading position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    _bci = _next_bci;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    if (is_last_bytecode()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
      // indicate end of bytecode stream
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   184
      raw_code = code = Bytecodes::_illegal;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      // get bytecode
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   187
      address bcp = this->bcp();
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   188
      raw_code = Bytecodes::code_at(_method(), bcp);
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   189
      code = Bytecodes::java_code(raw_code);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
      // set next bytecode position
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      // note that we cannot advance before having the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      // tty bytecode otherwise the stepping is wrong!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
      // (carefull: length_for(...) must be used first!)
39712
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   195
      int len = Bytecodes::length_for(code);
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   196
      if (len == 0) len = Bytecodes::length_at(_method(), bcp);
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   197
      if (len <= 0 || (_bci > _end_bci - len) || (_bci - len >= _next_bci)) {
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   198
        raw_code = code = Bytecodes::_illegal;
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   199
      } else {
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   200
        _next_bci  += len;
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   201
        assert(_bci < _next_bci, "length must be > 0");
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   202
        // set attributes
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   203
        _is_wide      = false;
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   204
        // check for special (uncommon) cases
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   205
        if (code == Bytecodes::_wide) {
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   206
          raw_code = (Bytecodes::Code)bcp[1];
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   207
          code = raw_code;  // wide BCs are always Java-normal
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   208
          _is_wide = true;
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   209
        }
dccb9af07ee1 8152479: Coded byte streams
hseigel
parents: 35194
diff changeset
   210
        assert(Bytecodes::is_java_code(code), "sanity check");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   213
    _raw_code = raw_code;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
    _code = code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
    return _code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  bool            is_active_breakpoint() const   { return Bytecodes::is_active_breakpoint_at(bcp()); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   219
  Bytecodes::Code code() const                   { return _code; }
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   220
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   221
  // Unsigned indices, widening
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   222
  int             get_index() const              { return is_wide() ? bytecode().get_index_u2(raw_code(), true) : get_index_u1(); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   223
  // Get an unsigned 2-byte index, swapping the bytes if necessary.
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   224
  int             get_index_u2() const           { assert_raw_stream(false);
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   225
                                                   return bytecode().get_index_u2(raw_code(), false); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   226
  // Get an unsigned 2-byte index in native order.
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   227
  int             get_index_u2_cpcache() const   { assert_raw_stream(false);
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   228
                                                   return bytecode().get_index_u2_cpcache(raw_code()); }
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   229
  int             get_index_u4() const           { assert_raw_stream(false);
7913
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   230
                                                   return bytecode().get_index_u4(raw_code()); }
dd096a83bdbb 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 7397
diff changeset
   231
  bool            has_index_u4() const           { return bytecode().has_index_u4(raw_code()); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
   233
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
   234
#endif // SHARE_VM_INTERPRETER_BYTECODESTREAM_HPP