1 /*
   2  * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "interpreter/bytecodeStream.hpp"
  27 #include "interpreter/bytecodes.hpp"
  28 
  29 Bytecodes::Code RawBytecodeStream::raw_next_special(Bytecodes::Code code) {
  30   assert(!is_last_bytecode(), "should have been checked");
  31   // set next bytecode position
  32   address bcp = RawBytecodeStream::bcp();
  33   address end = method()->code_base() + end_bci();
  34   int len = Bytecodes::raw_special_length_at(bcp, end);
  35   // Very large tableswitch or lookupswitch size can cause _next_bci to overflow.
  36   if (len <= 0 || (_bci > _end_bci - len) || (_bci - len >= _next_bci)) {
  37     code = Bytecodes::_illegal;
  38   } else {
  39     _next_bci += len;
  40     // set attributes
  41     _is_wide = false;
  42     // check for special (uncommon) cases
  43     if (code == Bytecodes::_wide) {
  44       if (bcp + 1 >= end) {
  45         code = Bytecodes::_illegal;
  46       } else {
  47         code = (Bytecodes::Code)bcp[1];
  48         _is_wide = true;
  49       }
  50     }
  51   }
  52   _raw_code = code;
  53   return code;
  54 }
  55 
  56 #ifdef ASSERT
  57 void BaseBytecodeStream::assert_raw_index_size(int size) const {
  58   if (raw_code() == Bytecodes::_invokedynamic && is_raw()) {
  59     // in raw mode, pretend indy is "bJJ__"
  60     assert(size == 2, "raw invokedynamic instruction has 2-byte index only");
  61   } else {
  62     bytecode().assert_index_size(size, raw_code(), is_wide());
  63   }
  64 }
  65 
  66 void BaseBytecodeStream::assert_raw_stream(bool want_raw) const {
  67   if (want_raw) {
  68     assert( is_raw(), "this function only works on raw streams");
  69   } else {
  70     assert(!is_raw(), "this function only works on non-raw streams");
  71   }
  72 }
  73 #endif //ASSERT