author | prr |
Mon, 06 Nov 2017 10:11:19 -0800 (2017-11-06) | |
changeset 47717 | 4a00b088902e |
parent 47216 | 71c04702a3d5 |
child 48826 | c4d9d1b08e2e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
43458 | 2 |
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4564
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4564
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4564
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "interpreter/bytecode.hpp" |
|
27 |
#include "interpreter/linkResolver.hpp" |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
28 |
#include "oops/constantPool.hpp" |
7397 | 29 |
#include "oops/oop.inline.hpp" |
30 |
#include "runtime/fieldType.hpp" |
|
31 |
#include "runtime/handles.inline.hpp" |
|
32 |
#include "runtime/safepoint.hpp" |
|
33 |
#include "runtime/signature.hpp" |
|
1 | 34 |
|
35 |
// Implementation of Bytecode |
|
36 |
||
5688 | 37 |
#ifdef ASSERT |
38 |
||
39 |
void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const { |
|
40 |
Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0)); |
|
41 |
if (thisbc == Bytecodes::_breakpoint) return; // let the assertion fail silently |
|
42 |
if (is_wide) { |
|
43 |
assert(thisbc == Bytecodes::_wide, "expected a wide instruction"); |
|
44 |
thisbc = Bytecodes::cast(byte_at(1)); |
|
45 |
if (thisbc == Bytecodes::_breakpoint) return; |
|
46 |
} |
|
47 |
int thisflags = Bytecodes::flags(testbc, is_wide) & Bytecodes::_all_fmt_bits; |
|
48 |
int testflags = Bytecodes::flags(thisbc, is_wide) & Bytecodes::_all_fmt_bits; |
|
49 |
if (thisflags != testflags) |
|
50 |
tty->print_cr("assert_same_format_as(%d) failed on bc=%d%s; %d != %d", |
|
51 |
(int)testbc, (int)thisbc, (is_wide?"/wide":""), testflags, thisflags); |
|
52 |
assert(thisflags == testflags, "expected format"); |
|
53 |
} |
|
54 |
||
55 |
void Bytecode::assert_index_size(int size, Bytecodes::Code bc, bool is_wide) { |
|
56 |
int have_fmt = (Bytecodes::flags(bc, is_wide) |
|
57 |
& (Bytecodes::_fmt_has_u2 | Bytecodes::_fmt_has_u4 | |
|
58 |
Bytecodes::_fmt_not_simple | |
|
59 |
// Not an offset field: |
|
60 |
Bytecodes::_fmt_has_o)); |
|
61 |
int need_fmt = -1; |
|
62 |
switch (size) { |
|
63 |
case 1: need_fmt = 0; break; |
|
64 |
case 2: need_fmt = Bytecodes::_fmt_has_u2; break; |
|
65 |
case 4: need_fmt = Bytecodes::_fmt_has_u4; break; |
|
66 |
} |
|
67 |
if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; |
|
68 |
if (have_fmt != need_fmt) { |
|
69 |
tty->print_cr("assert_index_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt); |
|
70 |
assert(have_fmt == need_fmt, "assert_index_size"); |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
void Bytecode::assert_offset_size(int size, Bytecodes::Code bc, bool is_wide) { |
|
75 |
int have_fmt = Bytecodes::flags(bc, is_wide) & Bytecodes::_all_fmt_bits; |
|
76 |
int need_fmt = -1; |
|
77 |
switch (size) { |
|
78 |
case 2: need_fmt = Bytecodes::_fmt_bo2; break; |
|
79 |
case 4: need_fmt = Bytecodes::_fmt_bo4; break; |
|
80 |
} |
|
81 |
if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; |
|
82 |
if (have_fmt != need_fmt) { |
|
83 |
tty->print_cr("assert_offset_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt); |
|
84 |
assert(have_fmt == need_fmt, "assert_offset_size"); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
void Bytecode::assert_constant_size(int size, int where, Bytecodes::Code bc, bool is_wide) { |
|
89 |
int have_fmt = Bytecodes::flags(bc, is_wide) & (Bytecodes::_all_fmt_bits |
|
90 |
// Ignore any 'i' field (for iinc): |
|
91 |
& ~Bytecodes::_fmt_has_i); |
|
92 |
int need_fmt = -1; |
|
93 |
switch (size) { |
|
94 |
case 1: need_fmt = Bytecodes::_fmt_bc; break; |
|
95 |
case 2: need_fmt = Bytecodes::_fmt_bc | Bytecodes::_fmt_has_u2; break; |
|
96 |
} |
|
97 |
if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; |
|
98 |
int length = is_wide ? Bytecodes::wide_length_for(bc) : Bytecodes::length_for(bc); |
|
99 |
if (have_fmt != need_fmt || where + size != length) { |
|
100 |
tty->print_cr("assert_constant_size %d @%d: bc=%d%s %d != %d", size, where, bc, (is_wide?"/wide":""), have_fmt, need_fmt); |
|
101 |
} |
|
102 |
assert(have_fmt == need_fmt, "assert_constant_size"); |
|
103 |
assert(where + size == length, "assert_constant_size oob"); |
|
104 |
} |
|
105 |
||
106 |
void Bytecode::assert_native_index(Bytecodes::Code bc, bool is_wide) { |
|
107 |
assert((Bytecodes::flags(bc, is_wide) & Bytecodes::_fmt_has_nbo) != 0, "native index"); |
|
108 |
} |
|
109 |
||
110 |
#endif //ASSERT |
|
1 | 111 |
|
112 |
// Implementation of Bytecode_tableupswitch |
|
113 |
||
114 |
int Bytecode_tableswitch::dest_offset_at(int i) const { |
|
43458 | 115 |
return get_aligned_Java_u4_at(1 + (3 + i)*jintSize); |
1 | 116 |
} |
117 |
||
118 |
||
119 |
// Implementation of Bytecode_invoke |
|
120 |
||
121 |
void Bytecode_invoke::verify() const { |
|
122 |
assert(is_valid(), "check invoke"); |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
123 |
assert(cpcache() != NULL, "do not call this from verifier or rewriter"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
124 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
125 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
126 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
127 |
Symbol* Bytecode_member_ref::klass() const { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
128 |
return constants()->klass_ref_at_noresolve(index()); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
129 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
130 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
131 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
132 |
Symbol* Bytecode_member_ref::name() const { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
133 |
return constants()->name_ref_at(index()); |
1 | 134 |
} |
135 |
||
136 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7913
diff
changeset
|
137 |
Symbol* Bytecode_member_ref::signature() const { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
138 |
return constants()->signature_ref_at(index()); |
1 | 139 |
} |
140 |
||
141 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7913
diff
changeset
|
142 |
BasicType Bytecode_member_ref::result_type() const { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7913
diff
changeset
|
143 |
ResultTypeFinder rts(signature()); |
1 | 144 |
rts.iterate(); |
145 |
return rts.type(); |
|
146 |
} |
|
147 |
||
148 |
||
149 |
methodHandle Bytecode_invoke::static_target(TRAPS) { |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
150 |
constantPoolHandle constants(THREAD, this->constants()); |
1 | 151 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
152 |
Bytecodes::Code bc = invoke_code(); |
31019 | 153 |
return LinkResolver::resolve_method_statically(bc, constants, index(), THREAD); |
1 | 154 |
} |
155 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
156 |
Handle Bytecode_invoke::appendix(TRAPS) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
157 |
ConstantPoolCacheEntry* cpce = cpcache_entry(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
158 |
if (cpce->has_appendix()) |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
159 |
return Handle(THREAD, cpce->appendix_if_resolved(constants())); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
160 |
return Handle(); // usual case |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
161 |
} |
1 | 162 |
|
5882 | 163 |
int Bytecode_member_ref::index() const { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
164 |
// Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
165 |
// at the same time it allocates per-call-site CP cache entries. |
5882 | 166 |
Bytecodes::Code rawc = code(); |
7913 | 167 |
if (has_index_u4(rawc)) |
168 |
return get_index_u4(rawc); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
1
diff
changeset
|
169 |
else |
7913 | 170 |
return get_index_u2_cpcache(rawc); |
1 | 171 |
} |
172 |
||
5882 | 173 |
int Bytecode_member_ref::pool_index() const { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
174 |
return cpcache_entry()->constant_pool_index(); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
175 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
176 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
8076
diff
changeset
|
177 |
ConstantPoolCacheEntry* Bytecode_member_ref::cpcache_entry() const { |
5882 | 178 |
int index = this->index(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
179 |
return cpcache()->entry_at(ConstantPool::decode_cpcache_index(index, true)); |
5882 | 180 |
} |
1 | 181 |
|
182 |
// Implementation of Bytecode_field |
|
183 |
||
184 |
void Bytecode_field::verify() const { |
|
5882 | 185 |
assert(is_valid(), "check field"); |
1 | 186 |
} |
187 |
||
188 |
||
5882 | 189 |
// Implementation of Bytecode_loadconstant |
190 |
||
191 |
int Bytecode_loadconstant::raw_index() const { |
|
7913 | 192 |
Bytecodes::Code rawc = code(); |
5882 | 193 |
assert(rawc != Bytecodes::_wide, "verifier prevents this"); |
194 |
if (Bytecodes::java_code(rawc) == Bytecodes::_ldc) |
|
7913 | 195 |
return get_index_u1(rawc); |
5882 | 196 |
else |
7913 | 197 |
return get_index_u2(rawc, false); |
1 | 198 |
} |
199 |
||
5882 | 200 |
int Bytecode_loadconstant::pool_index() const { |
201 |
int index = raw_index(); |
|
202 |
if (has_cache_index()) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
203 |
return _method->constants()->object_to_cp_index(index); |
5882 | 204 |
} |
205 |
return index; |
|
206 |
} |
|
1 | 207 |
|
5882 | 208 |
BasicType Bytecode_loadconstant::result_type() const { |
209 |
int index = pool_index(); |
|
210 |
constantTag tag = _method->constants()->tag_at(index); |
|
211 |
return tag.basic_type(); |
|
212 |
} |
|
213 |
||
214 |
oop Bytecode_loadconstant::resolve_constant(TRAPS) const { |
|
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
43458
diff
changeset
|
215 |
assert(_method != NULL, "must supply method to resolve constant"); |
5882 | 216 |
int index = raw_index(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
217 |
ConstantPool* constants = _method->constants(); |
5882 | 218 |
if (has_cache_index()) { |
219 |
return constants->resolve_cached_constant_at(index, THREAD); |
|
220 |
} else { |
|
221 |
return constants->resolve_constant_at(index, THREAD); |
|
5697 | 222 |
} |
1 | 223 |
} |
224 |
||
225 |
//------------------------------------------------------------------------------ |
|
226 |
// Non-product code |
|
227 |
||
228 |
#ifndef PRODUCT |
|
229 |
||
230 |
void Bytecode_lookupswitch::verify() const { |
|
231 |
switch (Bytecodes::java_code(code())) { |
|
232 |
case Bytecodes::_lookupswitch: |
|
233 |
{ int i = number_of_pairs() - 1; |
|
234 |
while (i-- > 0) { |
|
7913 | 235 |
assert(pair_at(i).match() < pair_at(i+1).match(), "unsorted table entries"); |
1 | 236 |
} |
237 |
} |
|
238 |
break; |
|
239 |
default: |
|
240 |
fatal("not a lookupswitch bytecode"); |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
void Bytecode_tableswitch::verify() const { |
|
245 |
switch (Bytecodes::java_code(code())) { |
|
246 |
case Bytecodes::_tableswitch: |
|
247 |
{ int lo = low_key(); |
|
248 |
int hi = high_key(); |
|
249 |
assert (hi >= lo, "incorrect hi/lo values in tableswitch"); |
|
250 |
int i = hi - lo - 1 ; |
|
251 |
while (i-- > 0) { |
|
252 |
// no special check needed |
|
253 |
} |
|
254 |
} |
|
255 |
break; |
|
256 |
default: |
|
257 |
fatal("not a tableswitch bytecode"); |
|
258 |
} |
|
259 |
} |
|
260 |
||
261 |
#endif |