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