8152207: Perform array bound checks while getting a length of bytecode instructions
Reviewed-by: hseigel
--- a/hotspot/src/share/vm/interpreter/bytecodes.hpp Fri May 27 05:49:24 2016 -0700
+++ b/hotspot/src/share/vm/interpreter/bytecodes.hpp Fri May 27 09:25:49 2016 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -386,15 +386,16 @@
static Code non_breakpoint_code_at(const Method* method, address bcp);
// Bytecode attributes
- static bool is_defined (int code) { return 0 <= code && code < number_of_codes && flags(code, false) != 0; }
+ static bool is_valid (int code) { return 0 <= code && code < number_of_codes; }
+ static bool is_defined (int code) { return is_valid(code) && flags(code, false) != 0; }
static bool wide_is_defined(int code) { return is_defined(code) && flags(code, true) != 0; }
static const char* name (Code code) { check(code); return _name [code]; }
static BasicType result_type (Code code) { check(code); return _result_type [code]; }
static int depth (Code code) { check(code); return _depth [code]; }
// Note: Length functions must return <=0 for invalid bytecodes.
// Calling check(code) in length functions would throw an unwanted assert.
- static int length_for (Code code) { /*no check*/ return _lengths [code] & 0xF; }
- static int wide_length_for(Code code) { /*no check*/ return _lengths [code] >> 4; }
+ static int length_for (Code code) { return is_valid(code) ? _lengths[code] & 0xF : -1; }
+ static int wide_length_for(Code code) { return is_valid(code) ? _lengths[code] >> 4 : -1; }
static bool can_trap (Code code) { check(code); return has_all_flags(code, _bc_can_trap, false); }
static Code java_code (Code code) { check(code); return _java_code [code]; }
static bool can_rewrite (Code code) { check(code); return has_all_flags(code, _bc_can_rewrite, false); }