| 1 | /* |
| 2 | * Copyright (c) 1997, 2018, 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 | #include "runtime/handles.inline.hpp" |
| 29 | |
| 30 | Bytecodes::Code RawBytecodeStream::raw_next_special(Bytecodes::Code code) { |
| 31 | assert(!is_last_bytecode(), "should have been checked" ); |
| 32 | // set next bytecode position |
| 33 | address bcp = RawBytecodeStream::bcp(); |
| 34 | address end = method()->code_base() + end_bci(); |
| 35 | int len = Bytecodes::raw_special_length_at(bcp, end); |
| 36 | // Very large tableswitch or lookupswitch size can cause _next_bci to overflow. |
| 37 | if (len <= 0 || (_bci > _end_bci - len) || (_bci - len >= _next_bci)) { |
| 38 | code = Bytecodes::_illegal; |
| 39 | } else { |
| 40 | _next_bci += len; |
| 41 | // set attributes |
| 42 | _is_wide = false; |
| 43 | // check for special (uncommon) cases |
| 44 | if (code == Bytecodes::_wide) { |
| 45 | if (bcp + 1 >= end) { |
| 46 | code = Bytecodes::_illegal; |
| 47 | } else { |
| 48 | code = (Bytecodes::Code)bcp[1]; |
| 49 | _is_wide = true; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | _raw_code = code; |
| 54 | return code; |
| 55 | } |
| 56 | |
| 57 | BaseBytecodeStream::BaseBytecodeStream(const methodHandle& method) : _method(method) { |
| 58 | set_interval(0, _method->code_size()); |
| 59 | _is_raw = false; |
| 60 | } |
| 61 | |
| 62 | #ifdef ASSERT |
| 63 | void BaseBytecodeStream::assert_raw_index_size(int size) const { |
| 64 | if (raw_code() == Bytecodes::_invokedynamic && is_raw()) { |
| 65 | // in raw mode, pretend indy is "bJJ__" |
| 66 | assert(size == 2, "raw invokedynamic instruction has 2-byte index only" ); |
| 67 | } else { |
| 68 | bytecode().assert_index_size(size, raw_code(), is_wide()); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | void BaseBytecodeStream::assert_raw_stream(bool want_raw) const { |
| 73 | if (want_raw) { |
| 74 | assert( is_raw(), "this function only works on raw streams" ); |
| 75 | } else { |
| 76 | assert(!is_raw(), "this function only works on non-raw streams" ); |
| 77 | } |
| 78 | } |
| 79 | #endif //ASSERT |
| 80 | |