Mercurial > hg > graal-compiler
annotate src/share/vm/interpreter/templateInterpreter.cpp @ 7066:7d815d842ee0
Merge.
author | Christian Haeubl <haeubl@ssw.jku.at> |
---|---|
date | Fri, 23 Nov 2012 11:50:27 +0100 |
parents | 8c5333c80cfd a3e2f723f2a5 |
children | b8f261ba79c6 |
rev | line source |
---|---|
7066 | 1 /* |
2 * Copyright (c) 1997, 2012, 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/interpreter.hpp" | |
27 #include "interpreter/interpreterGenerator.hpp" | |
28 #include "interpreter/interpreterRuntime.hpp" | |
29 #include "interpreter/templateTable.hpp" | |
30 #include "utilities/machineCodePrinter.hpp" | |
31 | |
32 #ifndef CC_INTERP | |
33 | |
34 # define __ _masm-> | |
35 | |
36 void TemplateInterpreter::initialize() { | |
37 if (_code != NULL) return; | |
38 // assertions | |
39 assert((int)Bytecodes::number_of_codes <= (int)DispatchTable::length, | |
40 "dispatch table too small"); | |
41 | |
42 AbstractInterpreter::initialize(); | |
43 | |
44 TemplateTable::initialize(); | |
45 | |
46 // generate interpreter | |
47 { ResourceMark rm; | |
48 TraceTime timer("Interpreter generation", TraceStartupTime); | |
49 int code_size = InterpreterCodeSize; | |
50 NOT_PRODUCT(code_size *= 4;) // debug uses extra interpreter code space | |
51 _code = new StubQueue(new InterpreterCodeletInterface, code_size, NULL, | |
52 "Interpreter"); | |
53 InterpreterGenerator g(_code); | |
54 if (PrintInterpreter) print(); | |
7062
8c5333c80cfd
increased CompileThreshold to increase reliability of profiling information
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6266
diff
changeset
|
55 if (PrintMachineCodeToFile) { |
8c5333c80cfd
increased CompileThreshold to increase reliability of profiling information
Christian Haeubl <haeubl@ssw.jku.at>
parents:
6266
diff
changeset
|
56 MachineCodePrinter::print(_code); |
7066 | 57 } |
58 } | |
59 | |
60 // initialize dispatch table | |
61 _active_table = _normal_table; | |
62 } | |
63 | |
64 //------------------------------------------------------------------------------------------------------------------------ | |
65 // Implementation of EntryPoint | |
66 | |
67 EntryPoint::EntryPoint() { | |
68 assert(number_of_states == 9, "check the code below"); | |
69 _entry[btos] = NULL; | |
70 _entry[ctos] = NULL; | |
71 _entry[stos] = NULL; | |
72 _entry[atos] = NULL; | |
73 _entry[itos] = NULL; | |
74 _entry[ltos] = NULL; | |
75 _entry[ftos] = NULL; | |
76 _entry[dtos] = NULL; | |
77 _entry[vtos] = NULL; | |
78 } | |
79 | |
80 | |
81 EntryPoint::EntryPoint(address bentry, address centry, address sentry, address aentry, address ientry, address lentry, address fentry, address dentry, address ventry) { | |
82 assert(number_of_states == 9, "check the code below"); | |
83 _entry[btos] = bentry; | |
84 _entry[ctos] = centry; | |
85 _entry[stos] = sentry; | |
86 _entry[atos] = aentry; | |
87 _entry[itos] = ientry; | |
88 _entry[ltos] = lentry; | |
89 _entry[ftos] = fentry; | |
90 _entry[dtos] = dentry; | |
91 _entry[vtos] = ventry; | |
92 } | |
93 | |
94 | |
95 void EntryPoint::set_entry(TosState state, address entry) { | |
96 assert(0 <= state && state < number_of_states, "state out of bounds"); | |
97 _entry[state] = entry; | |
98 } | |
99 | |
100 | |
101 address EntryPoint::entry(TosState state) const { | |
102 assert(0 <= state && state < number_of_states, "state out of bounds"); | |
103 return _entry[state]; | |
104 } | |
105 | |
106 | |
107 void EntryPoint::print() { | |
108 tty->print("["); | |
109 for (int i = 0; i < number_of_states; i++) { | |
110 if (i > 0) tty->print(", "); | |
111 tty->print(INTPTR_FORMAT, _entry[i]); | |
112 } | |
113 tty->print("]"); | |
114 } | |
115 | |
116 | |
117 bool EntryPoint::operator == (const EntryPoint& y) { | |
118 int i = number_of_states; | |
119 while (i-- > 0) { | |
120 if (_entry[i] != y._entry[i]) return false; | |
121 } | |
122 return true; | |
123 } | |
124 | |
125 | |
126 //------------------------------------------------------------------------------------------------------------------------ | |
127 // Implementation of DispatchTable | |
128 | |
129 EntryPoint DispatchTable::entry(int i) const { | |
130 assert(0 <= i && i < length, "index out of bounds"); | |
131 return | |
132 EntryPoint( | |
133 _table[btos][i], | |
134 _table[ctos][i], | |
135 _table[stos][i], | |
136 _table[atos][i], | |
137 _table[itos][i], | |
138 _table[ltos][i], | |
139 _table[ftos][i], | |
140 _table[dtos][i], | |
141 _table[vtos][i] | |
142 ); | |
143 } | |
144 | |
145 | |
146 void DispatchTable::set_entry(int i, EntryPoint& entry) { | |
147 assert(0 <= i && i < length, "index out of bounds"); | |
148 assert(number_of_states == 9, "check the code below"); | |
149 _table[btos][i] = entry.entry(btos); | |
150 _table[ctos][i] = entry.entry(ctos); | |
151 _table[stos][i] = entry.entry(stos); | |
152 _table[atos][i] = entry.entry(atos); | |
153 _table[itos][i] = entry.entry(itos); | |
154 _table[ltos][i] = entry.entry(ltos); | |
155 _table[ftos][i] = entry.entry(ftos); | |
156 _table[dtos][i] = entry.entry(dtos); | |
157 _table[vtos][i] = entry.entry(vtos); | |
158 } | |
159 | |
160 | |
161 bool DispatchTable::operator == (DispatchTable& y) { | |
162 int i = length; | |
163 while (i-- > 0) { | |
164 EntryPoint t = y.entry(i); // for compiler compatibility (BugId 4150096) | |
165 if (!(entry(i) == t)) return false; | |
166 } | |
167 return true; | |
168 } | |
169 | |
170 address TemplateInterpreter::_remove_activation_entry = NULL; | |
171 address TemplateInterpreter::_remove_activation_preserving_args_entry = NULL; | |
172 | |
173 | |
174 address TemplateInterpreter::_throw_ArrayIndexOutOfBoundsException_entry = NULL; | |
175 address TemplateInterpreter::_throw_ArrayStoreException_entry = NULL; | |
176 address TemplateInterpreter::_throw_ArithmeticException_entry = NULL; | |
177 address TemplateInterpreter::_throw_ClassCastException_entry = NULL; | |
178 address TemplateInterpreter::_throw_NullPointerException_entry = NULL; | |
179 address TemplateInterpreter::_throw_StackOverflowError_entry = NULL; | |
180 address TemplateInterpreter::_throw_exception_entry = NULL; | |
181 | |
182 #ifndef PRODUCT | |
183 EntryPoint TemplateInterpreter::_trace_code; | |
184 #endif // !PRODUCT | |
185 EntryPoint TemplateInterpreter::_return_entry[TemplateInterpreter::number_of_return_entries]; | |
186 EntryPoint TemplateInterpreter::_earlyret_entry; | |
187 EntryPoint TemplateInterpreter::_deopt_entry [TemplateInterpreter::number_of_deopt_entries ]; | |
188 EntryPoint TemplateInterpreter::_continuation_entry; | |
189 EntryPoint TemplateInterpreter::_safept_entry; | |
190 | |
191 address TemplateInterpreter::_return_3_addrs_by_index[TemplateInterpreter::number_of_return_addrs]; | |
192 address TemplateInterpreter::_return_5_addrs_by_index[TemplateInterpreter::number_of_return_addrs]; | |
193 | |
194 DispatchTable TemplateInterpreter::_active_table; | |
195 DispatchTable TemplateInterpreter::_normal_table; | |
196 DispatchTable TemplateInterpreter::_safept_table; | |
197 address TemplateInterpreter::_wentry_point[DispatchTable::length]; | |
198 | |
199 TemplateInterpreterGenerator::TemplateInterpreterGenerator(StubQueue* _code): AbstractInterpreterGenerator(_code) { | |
200 _unimplemented_bytecode = NULL; | |
201 _illegal_bytecode_sequence = NULL; | |
202 } | |
203 | |
204 static const BasicType types[Interpreter::number_of_result_handlers] = { | |
205 T_BOOLEAN, | |
206 T_CHAR , | |
207 T_BYTE , | |
208 T_SHORT , | |
209 T_INT , | |
210 T_LONG , | |
211 T_VOID , | |
212 T_FLOAT , | |
213 T_DOUBLE , | |
214 T_OBJECT | |
215 }; | |
216 | |
217 void TemplateInterpreterGenerator::generate_all() { | |
218 AbstractInterpreterGenerator::generate_all(); | |
219 | |
220 { CodeletMark cm(_masm, "error exits"); | |
221 _unimplemented_bytecode = generate_error_exit("unimplemented bytecode"); | |
222 _illegal_bytecode_sequence = generate_error_exit("illegal bytecode sequence - method not verified"); | |
223 } | |
224 | |
225 #ifndef PRODUCT | |
226 if (TraceBytecodes) { | |
227 CodeletMark cm(_masm, "bytecode tracing support"); | |
228 Interpreter::_trace_code = | |
229 EntryPoint( | |
230 generate_trace_code(btos), | |
231 generate_trace_code(ctos), | |
232 generate_trace_code(stos), | |
233 generate_trace_code(atos), | |
234 generate_trace_code(itos), | |
235 generate_trace_code(ltos), | |
236 generate_trace_code(ftos), | |
237 generate_trace_code(dtos), | |
238 generate_trace_code(vtos) | |
239 ); | |
240 } | |
241 #endif // !PRODUCT | |
242 | |
243 { CodeletMark cm(_masm, "return entry points"); | |
244 for (int i = 0; i < Interpreter::number_of_return_entries; i++) { | |
245 Interpreter::_return_entry[i] = | |
246 EntryPoint( | |
247 generate_return_entry_for(itos, i), | |
248 generate_return_entry_for(itos, i), | |
249 generate_return_entry_for(itos, i), | |
250 generate_return_entry_for(atos, i), | |
251 generate_return_entry_for(itos, i), | |
252 generate_return_entry_for(ltos, i), | |
253 generate_return_entry_for(ftos, i), | |
254 generate_return_entry_for(dtos, i), | |
255 generate_return_entry_for(vtos, i) | |
256 ); | |
257 } | |
258 } | |
259 | |
260 { CodeletMark cm(_masm, "earlyret entry points"); | |
261 Interpreter::_earlyret_entry = | |
262 EntryPoint( | |
263 generate_earlyret_entry_for(btos), | |
264 generate_earlyret_entry_for(ctos), | |
265 generate_earlyret_entry_for(stos), | |
266 generate_earlyret_entry_for(atos), | |
267 generate_earlyret_entry_for(itos), | |
268 generate_earlyret_entry_for(ltos), | |
269 generate_earlyret_entry_for(ftos), | |
270 generate_earlyret_entry_for(dtos), | |
271 generate_earlyret_entry_for(vtos) | |
272 ); | |
273 } | |
274 | |
275 { CodeletMark cm(_masm, "deoptimization entry points"); | |
276 for (int i = 0; i < Interpreter::number_of_deopt_entries; i++) { | |
277 Interpreter::_deopt_entry[i] = | |
278 EntryPoint( | |
279 generate_deopt_entry_for(itos, i), | |
280 generate_deopt_entry_for(itos, i), | |
281 generate_deopt_entry_for(itos, i), | |
282 generate_deopt_entry_for(atos, i), | |
283 generate_deopt_entry_for(itos, i), | |
284 generate_deopt_entry_for(ltos, i), | |
285 generate_deopt_entry_for(ftos, i), | |
286 generate_deopt_entry_for(dtos, i), | |
287 generate_deopt_entry_for(vtos, i) | |
288 ); | |
289 } | |
290 } | |
291 | |
292 { CodeletMark cm(_masm, "result handlers for native calls"); | |
293 // The various result converter stublets. | |
294 int is_generated[Interpreter::number_of_result_handlers]; | |
295 memset(is_generated, 0, sizeof(is_generated)); | |
296 | |
297 for (int i = 0; i < Interpreter::number_of_result_handlers; i++) { | |
298 BasicType type = types[i]; | |
299 if (!is_generated[Interpreter::BasicType_as_index(type)]++) { | |
300 Interpreter::_native_abi_to_tosca[Interpreter::BasicType_as_index(type)] = generate_result_handler_for(type); | |
301 } | |
302 } | |
303 } | |
304 | |
305 for (int j = 0; j < number_of_states; j++) { | |
306 const TosState states[] = {btos, ctos, stos, itos, ltos, ftos, dtos, atos, vtos}; | |
307 int index = Interpreter::TosState_as_index(states[j]); | |
308 Interpreter::_return_3_addrs_by_index[index] = Interpreter::return_entry(states[j], 3); | |
309 Interpreter::_return_5_addrs_by_index[index] = Interpreter::return_entry(states[j], 5); | |
310 } | |
311 | |
312 { CodeletMark cm(_masm, "continuation entry points"); | |
313 Interpreter::_continuation_entry = | |
314 EntryPoint( | |
315 generate_continuation_for(btos), | |
316 generate_continuation_for(ctos), | |
317 generate_continuation_for(stos), | |
318 generate_continuation_for(atos), | |
319 generate_continuation_for(itos), | |
320 generate_continuation_for(ltos), | |
321 generate_continuation_for(ftos), | |
322 generate_continuation_for(dtos), | |
323 generate_continuation_for(vtos) | |
324 ); | |
325 } | |
326 | |
327 { CodeletMark cm(_masm, "safepoint entry points"); | |
328 Interpreter::_safept_entry = | |
329 EntryPoint( | |
330 generate_safept_entry_for(btos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
331 generate_safept_entry_for(ctos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
332 generate_safept_entry_for(stos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
333 generate_safept_entry_for(atos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
334 generate_safept_entry_for(itos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
335 generate_safept_entry_for(ltos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
336 generate_safept_entry_for(ftos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
337 generate_safept_entry_for(dtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)), | |
338 generate_safept_entry_for(vtos, CAST_FROM_FN_PTR(address, InterpreterRuntime::at_safepoint)) | |
339 ); | |
340 } | |
341 | |
342 { CodeletMark cm(_masm, "exception handling"); | |
343 // (Note: this is not safepoint safe because thread may return to compiled code) | |
344 generate_throw_exception(); | |
345 } | |
346 | |
347 { CodeletMark cm(_masm, "throw exception entrypoints"); | |
348 Interpreter::_throw_ArrayIndexOutOfBoundsException_entry = generate_ArrayIndexOutOfBounds_handler("java/lang/ArrayIndexOutOfBoundsException"); | |
349 Interpreter::_throw_ArrayStoreException_entry = generate_klass_exception_handler("java/lang/ArrayStoreException" ); | |
350 Interpreter::_throw_ArithmeticException_entry = generate_exception_handler("java/lang/ArithmeticException" , "/ by zero"); | |
351 Interpreter::_throw_ClassCastException_entry = generate_ClassCastException_handler(); | |
352 Interpreter::_throw_NullPointerException_entry = generate_exception_handler("java/lang/NullPointerException" , NULL ); | |
353 Interpreter::_throw_StackOverflowError_entry = generate_StackOverflowError_handler(); | |
354 } | |
355 | |
356 | |
357 | |
358 #define method_entry(kind) \ | |
359 { CodeletMark cm(_masm, "method entry point (kind = " #kind ")"); \ | |
360 Interpreter::_entry_table[Interpreter::kind] = generate_method_entry(Interpreter::kind); \ | |
361 } | |
362 | |
363 // all non-native method kinds | |
364 method_entry(zerolocals) | |
365 method_entry(zerolocals_synchronized) | |
366 method_entry(empty) | |
367 method_entry(accessor) | |
368 method_entry(abstract) | |
369 method_entry(java_lang_math_sin ) | |
370 method_entry(java_lang_math_cos ) | |
371 method_entry(java_lang_math_tan ) | |
372 method_entry(java_lang_math_abs ) | |
373 method_entry(java_lang_math_sqrt ) | |
374 method_entry(java_lang_math_log ) | |
375 method_entry(java_lang_math_log10) | |
376 method_entry(java_lang_math_exp ) | |
377 method_entry(java_lang_math_pow ) | |
378 method_entry(java_lang_ref_reference_get) | |
379 | |
380 initialize_method_handle_entries(); | |
381 | |
382 // all native method kinds (must be one contiguous block) | |
383 Interpreter::_native_entry_begin = Interpreter::code()->code_end(); | |
384 method_entry(native) | |
385 method_entry(native_synchronized) | |
386 Interpreter::_native_entry_end = Interpreter::code()->code_end(); | |
387 | |
388 #undef method_entry | |
389 | |
390 // Bytecodes | |
391 set_entry_points_for_all_bytes(); | |
392 set_safepoints_for_all_bytes(); | |
393 } | |
394 | |
395 //------------------------------------------------------------------------------------------------------------------------ | |
396 | |
397 address TemplateInterpreterGenerator::generate_error_exit(const char* msg) { | |
398 address entry = __ pc(); | |
399 __ stop(msg); | |
400 return entry; | |
401 } | |
402 | |
403 | |
404 //------------------------------------------------------------------------------------------------------------------------ | |
405 | |
406 void TemplateInterpreterGenerator::set_entry_points_for_all_bytes() { | |
407 for (int i = 0; i < DispatchTable::length; i++) { | |
408 Bytecodes::Code code = (Bytecodes::Code)i; | |
409 if (Bytecodes::is_defined(code)) { | |
410 set_entry_points(code); | |
411 } else { | |
412 set_unimplemented(i); | |
413 } | |
414 } | |
415 } | |
416 | |
417 | |
418 void TemplateInterpreterGenerator::set_safepoints_for_all_bytes() { | |
419 for (int i = 0; i < DispatchTable::length; i++) { | |
420 Bytecodes::Code code = (Bytecodes::Code)i; | |
421 if (Bytecodes::is_defined(code)) Interpreter::_safept_table.set_entry(code, Interpreter::_safept_entry); | |
422 } | |
423 } | |
424 | |
425 | |
426 void TemplateInterpreterGenerator::set_unimplemented(int i) { | |
427 address e = _unimplemented_bytecode; | |
428 EntryPoint entry(e, e, e, e, e, e, e, e, e); | |
429 Interpreter::_normal_table.set_entry(i, entry); | |
430 Interpreter::_wentry_point[i] = _unimplemented_bytecode; | |
431 } | |
432 | |
433 | |
434 void TemplateInterpreterGenerator::set_entry_points(Bytecodes::Code code) { | |
435 CodeletMark cm(_masm, Bytecodes::name(code), code); | |
436 // initialize entry points | |
437 assert(_unimplemented_bytecode != NULL, "should have been generated before"); | |
438 assert(_illegal_bytecode_sequence != NULL, "should have been generated before"); | |
439 address bep = _illegal_bytecode_sequence; | |
440 address cep = _illegal_bytecode_sequence; | |
441 address sep = _illegal_bytecode_sequence; | |
442 address aep = _illegal_bytecode_sequence; | |
443 address iep = _illegal_bytecode_sequence; | |
444 address lep = _illegal_bytecode_sequence; | |
445 address fep = _illegal_bytecode_sequence; | |
446 address dep = _illegal_bytecode_sequence; | |
447 address vep = _unimplemented_bytecode; | |
448 address wep = _unimplemented_bytecode; | |
449 // code for short & wide version of bytecode | |
450 if (Bytecodes::is_defined(code)) { | |
451 Template* t = TemplateTable::template_for(code); | |
452 assert(t->is_valid(), "just checking"); | |
453 set_short_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep); | |
454 } | |
455 if (Bytecodes::wide_is_defined(code)) { | |
456 Template* t = TemplateTable::template_for_wide(code); | |
457 assert(t->is_valid(), "just checking"); | |
458 set_wide_entry_point(t, wep); | |
459 } | |
460 // set entry points | |
461 EntryPoint entry(bep, cep, sep, aep, iep, lep, fep, dep, vep); | |
462 Interpreter::_normal_table.set_entry(code, entry); | |
463 Interpreter::_wentry_point[code] = wep; | |
464 } | |
465 | |
466 | |
467 void TemplateInterpreterGenerator::set_wide_entry_point(Template* t, address& wep) { | |
468 assert(t->is_valid(), "template must exist"); | |
469 assert(t->tos_in() == vtos, "only vtos tos_in supported for wide instructions"); | |
470 wep = __ pc(); generate_and_dispatch(t); | |
471 } | |
472 | |
473 | |
474 void TemplateInterpreterGenerator::set_short_entry_points(Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) { | |
475 assert(t->is_valid(), "template must exist"); | |
476 switch (t->tos_in()) { | |
477 case btos: | |
478 case ctos: | |
479 case stos: | |
480 ShouldNotReachHere(); // btos/ctos/stos should use itos. | |
481 break; | |
482 case atos: vep = __ pc(); __ pop(atos); aep = __ pc(); generate_and_dispatch(t); break; | |
483 case itos: vep = __ pc(); __ pop(itos); iep = __ pc(); generate_and_dispatch(t); break; | |
484 case ltos: vep = __ pc(); __ pop(ltos); lep = __ pc(); generate_and_dispatch(t); break; | |
485 case ftos: vep = __ pc(); __ pop(ftos); fep = __ pc(); generate_and_dispatch(t); break; | |
486 case dtos: vep = __ pc(); __ pop(dtos); dep = __ pc(); generate_and_dispatch(t); break; | |
487 case vtos: set_vtos_entry_points(t, bep, cep, sep, aep, iep, lep, fep, dep, vep); break; | |
488 default : ShouldNotReachHere(); break; | |
489 } | |
490 } | |
491 | |
492 | |
493 //------------------------------------------------------------------------------------------------------------------------ | |
494 | |
495 void TemplateInterpreterGenerator::generate_and_dispatch(Template* t, TosState tos_out) { | |
496 if (PrintBytecodeHistogram) histogram_bytecode(t); | |
497 #ifndef PRODUCT | |
498 // debugging code | |
499 if (CountBytecodes || TraceBytecodes || StopInterpreterAt > 0) count_bytecode(); | |
500 if (PrintBytecodePairHistogram) histogram_bytecode_pair(t); | |
501 if (TraceBytecodes) trace_bytecode(t); | |
502 if (StopInterpreterAt > 0) stop_interpreter_at(); | |
503 __ verify_FPU(1, t->tos_in()); | |
504 #endif // !PRODUCT | |
505 int step; | |
506 if (!t->does_dispatch()) { | |
507 step = t->is_wide() ? Bytecodes::wide_length_for(t->bytecode()) : Bytecodes::length_for(t->bytecode()); | |
508 if (tos_out == ilgl) tos_out = t->tos_out(); | |
509 // compute bytecode size | |
510 assert(step > 0, "just checkin'"); | |
511 // setup stuff for dispatching next bytecode | |
512 if (ProfileInterpreter && VerifyDataPointer | |
513 && MethodData::bytecode_has_profile(t->bytecode())) { | |
514 __ verify_method_data_pointer(); | |
515 } | |
516 __ dispatch_prolog(tos_out, step); | |
517 } | |
518 // generate template | |
519 t->generate(_masm); | |
520 // advance | |
521 if (t->does_dispatch()) { | |
522 #ifdef ASSERT | |
523 // make sure execution doesn't go beyond this point if code is broken | |
524 __ should_not_reach_here(); | |
525 #endif // ASSERT | |
526 } else { | |
527 // dispatch to next bytecode | |
528 __ dispatch_epilog(tos_out, step); | |
529 } | |
530 } | |
531 | |
532 //------------------------------------------------------------------------------------------------------------------------ | |
533 // Entry points | |
534 | |
535 address TemplateInterpreter::return_entry(TosState state, int length) { | |
536 guarantee(0 <= length && length < Interpreter::number_of_return_entries, "illegal length"); | |
537 return _return_entry[length].entry(state); | |
538 } | |
539 | |
540 | |
541 address TemplateInterpreter::deopt_entry(TosState state, int length) { | |
542 guarantee(0 <= length && length < Interpreter::number_of_deopt_entries, "illegal length"); | |
543 return _deopt_entry[length].entry(state); | |
544 } | |
545 | |
546 //------------------------------------------------------------------------------------------------------------------------ | |
547 // Suport for invokes | |
548 | |
549 int TemplateInterpreter::TosState_as_index(TosState state) { | |
550 assert( state < number_of_states , "Invalid state in TosState_as_index"); | |
551 assert(0 <= (int)state && (int)state < TemplateInterpreter::number_of_return_addrs, "index out of bounds"); | |
552 return (int)state; | |
553 } | |
554 | |
555 | |
556 //------------------------------------------------------------------------------------------------------------------------ | |
557 // Safepoint suppport | |
558 | |
559 static inline void copy_table(address* from, address* to, int size) { | |
560 // Copy non-overlapping tables. The copy has to occur word wise for MT safety. | |
561 while (size-- > 0) *to++ = *from++; | |
562 } | |
563 | |
564 void TemplateInterpreter::notice_safepoints() { | |
565 if (!_notice_safepoints) { | |
566 // switch to safepoint dispatch table | |
567 _notice_safepoints = true; | |
568 copy_table((address*)&_safept_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address)); | |
569 } | |
570 } | |
571 | |
572 // switch from the dispatch table which notices safepoints back to the | |
573 // normal dispatch table. So that we can notice single stepping points, | |
574 // keep the safepoint dispatch table if we are single stepping in JVMTI. | |
575 // Note that the should_post_single_step test is exactly as fast as the | |
576 // JvmtiExport::_enabled test and covers both cases. | |
577 void TemplateInterpreter::ignore_safepoints() { | |
578 if (_notice_safepoints) { | |
579 if (!JvmtiExport::should_post_single_step()) { | |
580 // switch to normal dispatch table | |
581 _notice_safepoints = false; | |
582 copy_table((address*)&_normal_table, (address*)&_active_table, sizeof(_active_table) / sizeof(address)); | |
583 } | |
584 } | |
585 } | |
586 | |
587 //------------------------------------------------------------------------------------------------------------------------ | |
588 // Deoptimization support | |
589 | |
590 // If deoptimization happens, this function returns the point of next bytecode to continue execution | |
591 address TemplateInterpreter::deopt_continue_after_entry(Method* method, address bcp, int callee_parameters, bool is_top_frame) { | |
592 return AbstractInterpreter::deopt_continue_after_entry(method, bcp, callee_parameters, is_top_frame); | |
593 } | |
594 | |
595 // If deoptimization happens, this function returns the point where the interpreter reexecutes | |
596 // the bytecode. | |
597 // Note: Bytecodes::_athrow (C1 only) and Bytecodes::_return are the special cases | |
598 // that do not return "Interpreter::deopt_entry(vtos, 0)" | |
599 address TemplateInterpreter::deopt_reexecute_entry(Method* method, address bcp) { | |
600 assert(method->contains(bcp), "just checkin'"); | |
601 Bytecodes::Code code = Bytecodes::java_code_at(method, bcp); | |
602 if (code == Bytecodes::_return) { | |
603 // This is used for deopt during registration of finalizers | |
604 // during Object.<init>. We simply need to resume execution at | |
605 // the standard return vtos bytecode to pop the frame normally. | |
606 // reexecuting the real bytecode would cause double registration | |
607 // of the finalizable object. | |
608 return _normal_table.entry(Bytecodes::_return).entry(vtos); | |
609 } else { | |
610 return AbstractInterpreter::deopt_reexecute_entry(method, bcp); | |
611 } | |
612 } | |
613 | |
614 // If deoptimization happens, the interpreter should reexecute this bytecode. | |
615 // This function mainly helps the compilers to set up the reexecute bit. | |
616 bool TemplateInterpreter::bytecode_should_reexecute(Bytecodes::Code code) { | |
617 if (code == Bytecodes::_return) { | |
618 //Yes, we consider Bytecodes::_return as a special case of reexecution | |
619 return true; | |
620 } else { | |
621 return AbstractInterpreter::bytecode_should_reexecute(code); | |
622 } | |
623 } | |
624 | |
625 #endif // !CC_INTERP |