annotate src/share/vm/interpreter/bytecode.hpp @ 2142:8012aa3ccede

4926272: methodOopDesc::method_from_bcp is unsafe Reviewed-by: coleenp, jrose, kvn, dcubed
author never
date Thu, 13 Jan 2011 22:15:41 -0800
parents f95d63e2154a
children 3582bf76420e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1138
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
25 #ifndef SHARE_VM_INTERPRETER_BYTECODE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
26 #define SHARE_VM_INTERPRETER_BYTECODE_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
28 #include "interpreter/bytecodes.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
29 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
30 #include "oops/methodOop.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
31 #ifdef TARGET_ARCH_x86
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
32 # include "bytes_x86.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
33 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
34 #ifdef TARGET_ARCH_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
35 # include "bytes_sparc.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
36 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
37 #ifdef TARGET_ARCH_zero
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
38 # include "bytes_zero.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
39 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
40
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
41 class ciBytecodeStream;
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
42
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
43 // The base class for different kinds of bytecode abstractions.
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
44 // Provides the primitive operations to manipulate code relative
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
45 // to the bcp.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
46
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
47 class Bytecode: public StackObj {
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
48 protected:
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
49 const address _bcp;
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
50 const Bytecodes::Code _code;
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
51
0
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Address computation
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
53 address addr_at (int offset) const { return (address)_bcp + offset; }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
54 u_char byte_at(int offset) const { return *addr_at(offset); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
55 address aligned_addr_at (int offset) const { return (address)round_to((intptr_t)addr_at(offset), jintSize); }
a61af66fc99e Initial load
duke
parents:
diff changeset
56 int aligned_offset (int offset) const { return aligned_addr_at(offset) - addr_at(0); }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
58 // Word access:
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
59 int get_Java_u2_at (int offset) const { return Bytes::get_Java_u2(addr_at(offset)); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
60 int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
61 int get_native_u2_at (int offset) const { return Bytes::get_native_u2(addr_at(offset)); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
62 int get_native_u4_at (int offset) const { return Bytes::get_native_u4(addr_at(offset)); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
65 Bytecode(methodOop method, address bcp): _bcp(bcp), _code(Bytecodes::code_at(method, addr_at(0))) {
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
66 assert(method != NULL, "this form requires a valid methodOop");
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
67 }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
68 // Defined in ciStreams.hpp
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
69 inline Bytecode(const ciBytecodeStream* stream, address bcp = NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
70
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
71 // Attributes
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
72 address bcp() const { return _bcp; }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
73 int instruction_size() const { return Bytecodes::length_for_code_at(_code, bcp()); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
74
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
75 Bytecodes::Code code() const { return _code; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
76 Bytecodes::Code java_code() const { return Bytecodes::java_code(code()); }
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
77
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
78 // Static functions for parsing bytecodes in place.
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
79 int get_index_u1(Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
80 assert_same_format_as(bc); assert_index_size(1, bc);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
81 return *(jubyte*)addr_at(1);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
82 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
83 int get_index_u2(Bytecodes::Code bc, bool is_wide = false) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
84 assert_same_format_as(bc, is_wide); assert_index_size(2, bc, is_wide);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
85 address p = addr_at(is_wide ? 2 : 1);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
86 if (can_use_native_byte_order(bc, is_wide))
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
87 return Bytes::get_native_u2(p);
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
88 else return Bytes::get_Java_u2(p);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
89 }
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
90 int get_index_u1_cpcache(Bytecodes::Code bc) const {
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
91 assert_same_format_as(bc); assert_index_size(1, bc);
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
92 return *(jubyte*)addr_at(1) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
93 }
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
94 int get_index_u2_cpcache(Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
95 assert_same_format_as(bc); assert_index_size(2, bc); assert_native_index(bc);
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
96 return Bytes::get_native_u2(addr_at(1)) + constantPoolOopDesc::CPCACHE_INDEX_TAG;
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
97 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
98 int get_index_u4(Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
99 assert_same_format_as(bc); assert_index_size(4, bc);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
100 assert(can_use_native_byte_order(bc), "");
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
101 return Bytes::get_native_u4(addr_at(1));
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
102 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
103 bool has_index_u4(Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
104 return bc == Bytecodes::_invokedynamic;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
105 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
106
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
107 int get_offset_s2(Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
108 assert_same_format_as(bc); assert_offset_size(2, bc);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
109 return (jshort) Bytes::get_Java_u2(addr_at(1));
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
110 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
111 int get_offset_s4(Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
112 assert_same_format_as(bc); assert_offset_size(4, bc);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
113 return (jint) Bytes::get_Java_u4(addr_at(1));
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
114 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
115
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
116 int get_constant_u1(int offset, Bytecodes::Code bc) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
117 assert_same_format_as(bc); assert_constant_size(1, offset, bc);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
118 return *(jbyte*)addr_at(offset);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
119 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
120 int get_constant_u2(int offset, Bytecodes::Code bc, bool is_wide = false) const {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
121 assert_same_format_as(bc, is_wide); assert_constant_size(2, offset, bc, is_wide);
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
122 return (jshort) Bytes::get_Java_u2(addr_at(offset));
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
123 }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
124
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
125 // These are used locally and also from bytecode streams.
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
126 void assert_same_format_as(Bytecodes::Code testbc, bool is_wide = false) const NOT_DEBUG_RETURN;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
127 static void assert_index_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
128 static void assert_offset_size(int required_size, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
129 static void assert_constant_size(int required_size, int where, Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
130 static void assert_native_index(Bytecodes::Code bc, bool is_wide = false) NOT_DEBUG_RETURN;
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
131 static bool can_use_native_byte_order(Bytecodes::Code bc, bool is_wide = false) {
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
132 return (!Bytes::is_Java_byte_ordering_different() || Bytecodes::native_byte_order(bc /*, is_wide*/));
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
133 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 };
a61af66fc99e Initial load
duke
parents:
diff changeset
135
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // Abstractions for lookupswitch bytecode
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
138 class LookupswitchPair VALUE_OBJ_CLASS_SPEC {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
139 private:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
140 const address _bcp;
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
141
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
142 address addr_at (int offset) const { return _bcp + offset; }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
143 int get_Java_u4_at (int offset) const { return Bytes::get_Java_u4(addr_at(offset)); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
146 LookupswitchPair(address bcp): _bcp(bcp) {}
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
147 int match() const { return get_Java_u4_at(0 * jintSize); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
148 int offset() const { return get_Java_u4_at(1 * jintSize); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
149 };
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 class Bytecode_lookupswitch: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
153 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
154 Bytecode_lookupswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
155 // Defined in ciStreams.hpp
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
156 inline Bytecode_lookupswitch(const ciBytecodeStream* stream);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
157 void verify() const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Attributes
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
160 int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
161 int number_of_pairs() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
162 LookupswitchPair pair_at(int i) const {
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
163 assert(0 <= i && i < number_of_pairs(), "pair index out of bounds");
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
164 return LookupswitchPair(aligned_addr_at(1 + (1 + i)*2*jintSize));
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
165 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166 };
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 class Bytecode_tableswitch: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
170 Bytecode_tableswitch(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
171 // Defined in ciStreams.hpp
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
172 inline Bytecode_tableswitch(const ciBytecodeStream* stream);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
173 void verify() const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
174
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // Attributes
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
176 int default_offset() const { return get_Java_u4_at(aligned_offset(1 + 0*jintSize)); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
177 int low_key() const { return get_Java_u4_at(aligned_offset(1 + 1*jintSize)); }
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
178 int high_key() const { return get_Java_u4_at(aligned_offset(1 + 2*jintSize)); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
179 int dest_offset_at(int i) const;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 int length() { return high_key()-low_key()+1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 };
a61af66fc99e Initial load
duke
parents:
diff changeset
182
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
183 // Common code for decoding invokes and field references.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
184
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
185 class Bytecode_member_ref: public Bytecode {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
186 protected:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
187 const methodHandle _method; // method containing the bytecode
0
a61af66fc99e Initial load
duke
parents:
diff changeset
188
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
189 Bytecode_member_ref(methodHandle method, int bci) : Bytecode(method(), method()->bcp_from(bci)), _method(method) {}
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
190
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
191 methodHandle method() const { return _method; }
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
192
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
193 public:
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
194 int index() const; // cache index (loaded from instruction)
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
195 int pool_index() const; // constant pool index
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
196 symbolOop name() const; // returns the name of the method or field
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
197 symbolOop signature() const; // returns the signature of the method or field
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
198
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
199 BasicType result_type(Thread* thread) const; // returns the result type of the getfield or invoke
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
200 };
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
201
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
202 // Abstraction for invoke_{virtual, static, interface, special}
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
203
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
204 class Bytecode_invoke: public Bytecode_member_ref {
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
205 protected:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
206 // Constructor that skips verification
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
207 Bytecode_invoke(methodHandle method, int bci, bool unused) : Bytecode_member_ref(method, bci) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
210 Bytecode_invoke(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
211 void verify() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 // Attributes
a61af66fc99e Initial load
duke
parents:
diff changeset
214 methodHandle static_target(TRAPS); // "specified" method (from constant pool)
a61af66fc99e Initial load
duke
parents:
diff changeset
215
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // Testers
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
217 bool is_invokeinterface() const { return java_code() == Bytecodes::_invokeinterface; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
218 bool is_invokevirtual() const { return java_code() == Bytecodes::_invokevirtual; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
219 bool is_invokestatic() const { return java_code() == Bytecodes::_invokestatic; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
220 bool is_invokespecial() const { return java_code() == Bytecodes::_invokespecial; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
221 bool is_invokedynamic() const { return java_code() == Bytecodes::_invokedynamic; }
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
222
1138
dd57230ba8fe 6893268: additional dynamic language related optimizations in C2
twisti
parents: 1135
diff changeset
223 bool has_receiver() const { return !is_invokestatic() && !is_invokedynamic(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 bool is_valid() const { return is_invokeinterface() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
226 is_invokevirtual() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
227 is_invokestatic() ||
1135
e66fd840cb6b 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 844
diff changeset
228 is_invokespecial() ||
e66fd840cb6b 6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents: 844
diff changeset
229 is_invokedynamic(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
230
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
231 // Helper to skip verification. Used is_valid() to check if the result is really an invoke
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
232 inline friend Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
233 };
a61af66fc99e Initial load
duke
parents:
diff changeset
234
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
235 inline Bytecode_invoke Bytecode_invoke_check(methodHandle method, int bci) {
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
236 return Bytecode_invoke(method, bci, false);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
237 }
a61af66fc99e Initial load
duke
parents:
diff changeset
238
a61af66fc99e Initial load
duke
parents:
diff changeset
239
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
240 // Abstraction for all field accesses (put/get field/static)
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
241 class Bytecode_field: public Bytecode_member_ref {
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
242 public:
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
243 Bytecode_field(methodHandle method, int bci) : Bytecode_member_ref(method, bci) { verify(); }
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
244
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
245 // Testers
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
246 bool is_getfield() const { return java_code() == Bytecodes::_getfield; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
247 bool is_putfield() const { return java_code() == Bytecodes::_putfield; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
248 bool is_getstatic() const { return java_code() == Bytecodes::_getstatic; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
249 bool is_putstatic() const { return java_code() == Bytecodes::_putstatic; }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
250
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
251 bool is_getter() const { return is_getfield() || is_getstatic(); }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
252 bool is_static() const { return is_getstatic() || is_putstatic(); }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
253
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
254 bool is_valid() const { return is_getfield() ||
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
255 is_putfield() ||
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
256 is_getstatic() ||
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
257 is_putstatic(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
258 void verify() const;
a61af66fc99e Initial load
duke
parents:
diff changeset
259 };
a61af66fc99e Initial load
duke
parents:
diff changeset
260
a61af66fc99e Initial load
duke
parents:
diff changeset
261 // Abstraction for checkcast
a61af66fc99e Initial load
duke
parents:
diff changeset
262 class Bytecode_checkcast: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
264 Bytecode_checkcast(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
265 void verify() const { assert(Bytecodes::java_code(code()) == Bytecodes::_checkcast, "check checkcast"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
266
a61af66fc99e Initial load
duke
parents:
diff changeset
267 // Returns index
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
268 long index() const { return get_index_u2(Bytecodes::_checkcast); };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
269 };
a61af66fc99e Initial load
duke
parents:
diff changeset
270
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // Abstraction for instanceof
a61af66fc99e Initial load
duke
parents:
diff changeset
272 class Bytecode_instanceof: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
274 Bytecode_instanceof(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
275 void verify() const { assert(code() == Bytecodes::_instanceof, "check instanceof"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // Returns index
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
278 long index() const { return get_index_u2(Bytecodes::_instanceof); };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
279 };
a61af66fc99e Initial load
duke
parents:
diff changeset
280
a61af66fc99e Initial load
duke
parents:
diff changeset
281 class Bytecode_new: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
282 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
283 Bytecode_new(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
284 void verify() const { assert(java_code() == Bytecodes::_new, "check new"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
285
a61af66fc99e Initial load
duke
parents:
diff changeset
286 // Returns index
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
287 long index() const { return get_index_u2(Bytecodes::_new); };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
288 };
a61af66fc99e Initial load
duke
parents:
diff changeset
289
a61af66fc99e Initial load
duke
parents:
diff changeset
290 class Bytecode_multianewarray: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
291 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
292 Bytecode_multianewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
293 void verify() const { assert(java_code() == Bytecodes::_multianewarray, "check new"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // Returns index
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
296 long index() const { return get_index_u2(Bytecodes::_multianewarray); };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
297 };
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 class Bytecode_anewarray: public Bytecode {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
301 Bytecode_anewarray(methodOop method, address bcp): Bytecode(method, bcp) { verify(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
302 void verify() const { assert(java_code() == Bytecodes::_anewarray, "check anewarray"); }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 // Returns index
1565
ab102d5d923e 6939207: refactor constant pool index processing
jrose
parents: 1138
diff changeset
305 long index() const { return get_index_u2(Bytecodes::_anewarray); };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
306 };
a61af66fc99e Initial load
duke
parents:
diff changeset
307
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // Abstraction for ldc, ldc_w and ldc2_w
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
309 class Bytecode_loadconstant: public Bytecode {
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
310 private:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
311 const methodHandle _method;
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
312
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
313 int raw_index() const;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
314
0
a61af66fc99e Initial load
duke
parents:
diff changeset
315 public:
2142
8012aa3ccede 4926272: methodOopDesc::method_from_bcp is unsafe
never
parents: 1972
diff changeset
316 Bytecode_loadconstant(methodHandle method, int bci): Bytecode(method(), method->bcp_from(bci)), _method(method) { verify(); }
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
317
0
a61af66fc99e Initial load
duke
parents:
diff changeset
318 void verify() const {
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
319 assert(_method.not_null(), "must supply method");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
320 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
321 assert(stdc == Bytecodes::_ldc ||
a61af66fc99e Initial load
duke
parents:
diff changeset
322 stdc == Bytecodes::_ldc_w ||
a61af66fc99e Initial load
duke
parents:
diff changeset
323 stdc == Bytecodes::_ldc2_w, "load constant");
a61af66fc99e Initial load
duke
parents:
diff changeset
324 }
a61af66fc99e Initial load
duke
parents:
diff changeset
325
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
326 // Only non-standard bytecodes (fast_aldc) have CP cache indexes.
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
327 bool has_cache_index() const { return code() >= Bytecodes::number_of_java_codes; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
328
1602
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
329 int pool_index() const; // index into constant pool
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
330 int cache_index() const { // index into CP cache (or -1 if none)
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
331 return has_cache_index() ? raw_index() : -1;
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
332 }
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
333
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
334 BasicType result_type() const; // returns the result type of the ldc
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
335
136b78722a08 6939203: JSR 292 needs method handle constants
jrose
parents: 1579
diff changeset
336 oop resolve_constant(TRAPS) const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
337 };
a61af66fc99e Initial load
duke
parents:
diff changeset
338
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1602
diff changeset
339 #endif // SHARE_VM_INTERPRETER_BYTECODE_HPP