bytecodeStream.cpp 2.6 KB
Newer Older
D
duke 已提交
1
/*
V
vkempik 已提交
2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
D
duke 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
19 20 21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
D
duke 已提交
22 23 24
 *
 */

25 26 27
#include "precompiled.hpp"
#include "interpreter/bytecodeStream.hpp"
#include "interpreter/bytecodes.hpp"
D
duke 已提交
28 29 30 31

Bytecodes::Code RawBytecodeStream::raw_next_special(Bytecodes::Code code) {
  assert(!is_last_bytecode(), "should have been checked");
  // set next bytecode position
32 33
  address bcp = RawBytecodeStream::bcp();
  address end = method()->code_base() + end_bci();
V
vkempik 已提交
34 35 36
  int len = Bytecodes::raw_special_length_at(bcp, end);
  // Very large tableswitch or lookupswitch size can cause _next_bci to overflow.
  if (len <= 0 || (_bci > _end_bci - len) || (_bci - len >= _next_bci)) {
D
duke 已提交
37 38
    code = Bytecodes::_illegal;
  } else {
V
vkempik 已提交
39
    _next_bci += len;
D
duke 已提交
40 41 42 43
    // set attributes
    _is_wide = false;
    // check for special (uncommon) cases
    if (code == Bytecodes::_wide) {
44 45 46 47 48 49
      if (bcp + 1 >= end) {
        code = Bytecodes::_illegal;
      } else {
        code = (Bytecodes::Code)bcp[1];
        _is_wide = true;
      }
D
duke 已提交
50 51
    }
  }
52
  _raw_code = code;
D
duke 已提交
53 54
  return code;
}
55 56 57 58 59 60 61

#ifdef ASSERT
void BaseBytecodeStream::assert_raw_index_size(int size) const {
  if (raw_code() == Bytecodes::_invokedynamic && is_raw()) {
    // in raw mode, pretend indy is "bJJ__"
    assert(size == 2, "raw invokedynamic instruction has 2-byte index only");
  } else {
62
    bytecode().assert_index_size(size, raw_code(), is_wide());
63 64 65 66 67 68 69 70 71 72 73
  }
}

void BaseBytecodeStream::assert_raw_stream(bool want_raw) const {
  if (want_raw) {
    assert( is_raw(), "this function only works on raw streams");
  } else {
    assert(!is_raw(), "this function only works on non-raw streams");
  }
}
#endif //ASSERT