Mercurial > hg > truffle
annotate src/share/vm/interpreter/bytecode.cpp @ 1574:1eb493f33423
6957080: MethodComparator needs stress testing
Summary: Add a stress-test flag for running MethodComparator over many inputs. Fix bugs that crop up.
Reviewed-by: kvn
author | jrose |
---|---|
date | Sat, 29 May 2010 19:22:32 -0700 |
parents | ab102d5d923e |
children | e9ff18c4ace7 |
rev | line source |
---|---|
0 | 1 /* |
1565 | 2 * Copyright 1997-2010 Sun Microsystems, Inc. All Rights Reserved. |
0 | 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_bytecode.cpp.incl" | |
27 | |
28 // Implementation of Bytecode | |
29 | |
1565 | 30 bool Bytecode::check_must_rewrite(Bytecodes::Code code) const { |
31 assert(Bytecodes::can_rewrite(code), "post-check only"); | |
0 | 32 |
33 // Some codes are conditionally rewriting. Look closely at them. | |
1565 | 34 switch (code) { |
0 | 35 case Bytecodes::_aload_0: |
36 // Even if RewriteFrequentPairs is turned on, | |
37 // the _aload_0 code might delay its rewrite until | |
38 // a following _getfield rewrites itself. | |
39 return false; | |
40 | |
41 case Bytecodes::_lookupswitch: | |
42 return false; // the rewrite is not done by the interpreter | |
43 | |
44 case Bytecodes::_new: | |
45 // (Could actually look at the class here, but the profit would be small.) | |
46 return false; // the rewrite is not always done | |
47 } | |
48 | |
49 // No other special cases. | |
50 return true; | |
51 } | |
52 | |
53 | |
1565 | 54 #ifdef ASSERT |
55 | |
56 void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const { | |
57 Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0)); | |
58 if (thisbc == Bytecodes::_breakpoint) return; // let the assertion fail silently | |
59 if (is_wide) { | |
60 assert(thisbc == Bytecodes::_wide, "expected a wide instruction"); | |
61 thisbc = Bytecodes::cast(byte_at(1)); | |
62 if (thisbc == Bytecodes::_breakpoint) return; | |
63 } | |
64 int thisflags = Bytecodes::flags(testbc, is_wide) & Bytecodes::_all_fmt_bits; | |
65 int testflags = Bytecodes::flags(thisbc, is_wide) & Bytecodes::_all_fmt_bits; | |
66 if (thisflags != testflags) | |
67 tty->print_cr("assert_same_format_as(%d) failed on bc=%d%s; %d != %d", | |
68 (int)testbc, (int)thisbc, (is_wide?"/wide":""), testflags, thisflags); | |
69 assert(thisflags == testflags, "expected format"); | |
70 } | |
71 | |
72 void Bytecode::assert_index_size(int size, Bytecodes::Code bc, bool is_wide) { | |
73 int have_fmt = (Bytecodes::flags(bc, is_wide) | |
74 & (Bytecodes::_fmt_has_u2 | Bytecodes::_fmt_has_u4 | | |
75 Bytecodes::_fmt_not_simple | | |
76 // Not an offset field: | |
77 Bytecodes::_fmt_has_o)); | |
78 int need_fmt = -1; | |
79 switch (size) { | |
80 case 1: need_fmt = 0; break; | |
81 case 2: need_fmt = Bytecodes::_fmt_has_u2; break; | |
82 case 4: need_fmt = Bytecodes::_fmt_has_u4; break; | |
83 } | |
84 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; | |
85 if (have_fmt != need_fmt) { | |
86 tty->print_cr("assert_index_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt); | |
87 assert(have_fmt == need_fmt, "assert_index_size"); | |
88 } | |
89 } | |
90 | |
91 void Bytecode::assert_offset_size(int size, Bytecodes::Code bc, bool is_wide) { | |
92 int have_fmt = Bytecodes::flags(bc, is_wide) & Bytecodes::_all_fmt_bits; | |
93 int need_fmt = -1; | |
94 switch (size) { | |
95 case 2: need_fmt = Bytecodes::_fmt_bo2; break; | |
96 case 4: need_fmt = Bytecodes::_fmt_bo4; break; | |
97 } | |
98 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; | |
99 if (have_fmt != need_fmt) { | |
100 tty->print_cr("assert_offset_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt); | |
101 assert(have_fmt == need_fmt, "assert_offset_size"); | |
102 } | |
103 } | |
104 | |
105 void Bytecode::assert_constant_size(int size, int where, Bytecodes::Code bc, bool is_wide) { | |
106 int have_fmt = Bytecodes::flags(bc, is_wide) & (Bytecodes::_all_fmt_bits | |
107 // Ignore any 'i' field (for iinc): | |
108 & ~Bytecodes::_fmt_has_i); | |
109 int need_fmt = -1; | |
110 switch (size) { | |
111 case 1: need_fmt = Bytecodes::_fmt_bc; break; | |
112 case 2: need_fmt = Bytecodes::_fmt_bc | Bytecodes::_fmt_has_u2; break; | |
113 } | |
114 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; | |
115 int length = is_wide ? Bytecodes::wide_length_for(bc) : Bytecodes::length_for(bc); | |
116 if (have_fmt != need_fmt || where + size != length) { | |
117 tty->print_cr("assert_constant_size %d @%d: bc=%d%s %d != %d", size, where, bc, (is_wide?"/wide":""), have_fmt, need_fmt); | |
118 } | |
119 assert(have_fmt == need_fmt, "assert_constant_size"); | |
120 assert(where + size == length, "assert_constant_size oob"); | |
121 } | |
122 | |
123 void Bytecode::assert_native_index(Bytecodes::Code bc, bool is_wide) { | |
124 assert((Bytecodes::flags(bc, is_wide) & Bytecodes::_fmt_has_nbo) != 0, "native index"); | |
125 } | |
126 | |
127 #endif //ASSERT | |
0 | 128 |
129 // Implementation of Bytecode_tableupswitch | |
130 | |
131 int Bytecode_tableswitch::dest_offset_at(int i) const { | |
1565 | 132 return get_Java_u4_at(aligned_offset(1 + (3 + i)*jintSize)); |
0 | 133 } |
134 | |
135 | |
136 // Implementation of Bytecode_invoke | |
137 | |
138 void Bytecode_invoke::verify() const { | |
139 Bytecodes::Code bc = adjusted_invoke_code(); | |
140 assert(is_valid(), "check invoke"); | |
1565 | 141 assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter"); |
0 | 142 } |
143 | |
144 | |
145 symbolOop Bytecode_invoke::signature() const { | |
146 constantPoolOop constants = method()->constants(); | |
147 return constants->signature_ref_at(index()); | |
148 } | |
149 | |
150 | |
151 symbolOop Bytecode_invoke::name() const { | |
152 constantPoolOop constants = method()->constants(); | |
153 return constants->name_ref_at(index()); | |
154 } | |
155 | |
156 | |
157 BasicType Bytecode_invoke::result_type(Thread *thread) const { | |
158 symbolHandle sh(thread, signature()); | |
159 ResultTypeFinder rts(sh); | |
160 rts.iterate(); | |
161 return rts.type(); | |
162 } | |
163 | |
164 | |
165 methodHandle Bytecode_invoke::static_target(TRAPS) { | |
166 methodHandle m; | |
167 KlassHandle resolved_klass; | |
168 constantPoolHandle constants(THREAD, _method->constants()); | |
169 | |
1135
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
844
diff
changeset
|
170 if (adjusted_invoke_code() == Bytecodes::_invokedynamic) { |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
844
diff
changeset
|
171 LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
e66fd840cb6b
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
twisti
parents:
844
diff
changeset
|
172 } else if (adjusted_invoke_code() != Bytecodes::_invokeinterface) { |
0 | 173 LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
174 } else { | |
175 LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); | |
176 } | |
177 return m; | |
178 } | |
179 | |
180 | |
181 int Bytecode_invoke::index() const { | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
182 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
183 // at the same time it allocates per-call-site CP cache entries. |
1565 | 184 Bytecodes::Code stdc = Bytecodes::java_code(code()); |
185 Bytecode* invoke = Bytecode_at(bcp()); | |
186 if (invoke->has_index_u4(stdc)) | |
187 return invoke->get_index_u4(stdc); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
0
diff
changeset
|
188 else |
1565 | 189 return invoke->get_index_u2_cpcache(stdc); |
0 | 190 } |
191 | |
192 | |
193 // Implementation of Bytecode_field | |
194 | |
195 void Bytecode_field::verify() const { | |
196 Bytecodes::Code stdc = Bytecodes::java_code(code()); | |
197 assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic || | |
198 stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field"); | |
199 } | |
200 | |
201 | |
202 bool Bytecode_field::is_static() const { | |
203 Bytecodes::Code stdc = Bytecodes::java_code(code()); | |
204 return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic; | |
205 } | |
206 | |
207 | |
208 int Bytecode_field::index() const { | |
1565 | 209 Bytecode* invoke = Bytecode_at(bcp()); |
210 return invoke->get_index_u2_cpcache(Bytecodes::_getfield); | |
0 | 211 } |
212 | |
213 | |
214 // Implementation of Bytecodes loac constant | |
215 | |
216 int Bytecode_loadconstant::index() const { | |
217 Bytecodes::Code stdc = Bytecodes::java_code(code()); | |
1574 | 218 if (stdc != Bytecodes::_wide) { |
219 if (Bytecodes::java_code(stdc) == Bytecodes::_ldc) | |
220 return get_index_u1(stdc); | |
221 else | |
222 return get_index_u2(stdc, false); | |
223 } | |
224 stdc = Bytecodes::code_at(addr_at(1)); | |
225 return get_index_u2(stdc, true); | |
0 | 226 } |
227 | |
228 //------------------------------------------------------------------------------ | |
229 // Non-product code | |
230 | |
231 #ifndef PRODUCT | |
232 | |
233 void Bytecode_lookupswitch::verify() const { | |
234 switch (Bytecodes::java_code(code())) { | |
235 case Bytecodes::_lookupswitch: | |
236 { int i = number_of_pairs() - 1; | |
237 while (i-- > 0) { | |
238 assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries"); | |
239 } | |
240 } | |
241 break; | |
242 default: | |
243 fatal("not a lookupswitch bytecode"); | |
244 } | |
245 } | |
246 | |
247 void Bytecode_tableswitch::verify() const { | |
248 switch (Bytecodes::java_code(code())) { | |
249 case Bytecodes::_tableswitch: | |
250 { int lo = low_key(); | |
251 int hi = high_key(); | |
252 assert (hi >= lo, "incorrect hi/lo values in tableswitch"); | |
253 int i = hi - lo - 1 ; | |
254 while (i-- > 0) { | |
255 // no special check needed | |
256 } | |
257 } | |
258 break; | |
259 default: | |
260 fatal("not a tableswitch bytecode"); | |
261 } | |
262 } | |
263 | |
264 #endif |