Print this page
rev 2161 : [mq]: initial-intrinsification-changes
rev 2163 : [mq]: client_assertion_fauilure
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/zero/vm/cppInterpreter_zero.cpp
+++ new/src/cpu/zero/vm/cppInterpreter_zero.cpp
1 1 /*
2 - * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2 + * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc.
4 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 5 *
6 6 * This code is free software; you can redistribute it and/or modify it
7 7 * under the terms of the GNU General Public License version 2 only, as
8 8 * published by the Free Software Foundation.
9 9 *
10 10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 13 * version 2 for more details (a copy is included in the LICENSE file that
14 14 * accompanied this code).
15 15 *
16 16 * You should have received a copy of the GNU General Public License version
17 17 * 2 along with this work; if not, write to the Free Software Foundation,
18 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 19 *
20 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 21 * or visit www.oracle.com if you need additional information or have any
22 22 * questions.
23 23 *
24 24 */
25 25
26 26 #include "precompiled.hpp"
27 27 #include "asm/assembler.hpp"
28 28 #include "interpreter/bytecodeHistogram.hpp"
29 29 #include "interpreter/cppInterpreter.hpp"
30 30 #include "interpreter/interpreter.hpp"
31 31 #include "interpreter/interpreterGenerator.hpp"
32 32 #include "interpreter/interpreterRuntime.hpp"
33 33 #include "oops/arrayOop.hpp"
34 34 #include "oops/methodDataOop.hpp"
35 35 #include "oops/methodOop.hpp"
36 36 #include "oops/oop.inline.hpp"
37 37 #include "prims/jvmtiExport.hpp"
38 38 #include "prims/jvmtiThreadState.hpp"
39 39 #include "runtime/arguments.hpp"
40 40 #include "runtime/deoptimization.hpp"
41 41 #include "runtime/frame.inline.hpp"
42 42 #include "runtime/interfaceSupport.hpp"
43 43 #include "runtime/sharedRuntime.hpp"
44 44 #include "runtime/stubRoutines.hpp"
45 45 #include "runtime/synchronizer.hpp"
46 46 #include "runtime/timer.hpp"
47 47 #include "runtime/vframeArray.hpp"
48 48 #include "stack_zero.inline.hpp"
49 49 #include "utilities/debug.hpp"
50 50 #ifdef SHARK
51 51 #include "shark/shark_globals.hpp"
52 52 #endif
53 53
54 54 #ifdef CC_INTERP
55 55
56 56 #define fixup_after_potential_safepoint() \
57 57 method = istate->method()
58 58
59 59 #define CALL_VM_NOCHECK(func) \
60 60 thread->set_last_Java_frame(); \
61 61 func; \
62 62 thread->reset_last_Java_frame(); \
63 63 fixup_after_potential_safepoint()
64 64
65 65 int CppInterpreter::normal_entry(methodOop method, intptr_t UNUSED, TRAPS) {
66 66 JavaThread *thread = (JavaThread *) THREAD;
67 67
68 68 // Allocate and initialize our frame.
69 69 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
70 70 thread->push_zero_frame(frame);
71 71
72 72 // Execute those bytecodes!
73 73 main_loop(0, THREAD);
74 74
75 75 // No deoptimized frames on the stack
76 76 return 0;
77 77 }
78 78
79 79 void CppInterpreter::main_loop(int recurse, TRAPS) {
80 80 JavaThread *thread = (JavaThread *) THREAD;
81 81 ZeroStack *stack = thread->zero_stack();
82 82
83 83 // If we are entering from a deopt we may need to call
84 84 // ourself a few times in order to get to our frame.
85 85 if (recurse)
86 86 main_loop(recurse - 1, THREAD);
87 87
88 88 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame();
89 89 interpreterState istate = frame->interpreter_state();
90 90 methodOop method = istate->method();
91 91
92 92 intptr_t *result = NULL;
93 93 int result_slots = 0;
94 94
95 95 while (true) {
96 96 // We can set up the frame anchor with everything we want at
97 97 // this point as we are thread_in_Java and no safepoints can
98 98 // occur until we go to vm mode. We do have to clear flags
99 99 // on return from vm but that is it.
100 100 thread->set_last_Java_frame();
101 101
102 102 // Call the interpreter
103 103 if (JvmtiExport::can_post_interpreter_events())
104 104 BytecodeInterpreter::runWithChecks(istate);
105 105 else
106 106 BytecodeInterpreter::run(istate);
107 107 fixup_after_potential_safepoint();
108 108
109 109 // Clear the frame anchor
110 110 thread->reset_last_Java_frame();
111 111
112 112 // Examine the message from the interpreter to decide what to do
113 113 if (istate->msg() == BytecodeInterpreter::call_method) {
114 114 methodOop callee = istate->callee();
115 115
116 116 // Trim back the stack to put the parameters at the top
117 117 stack->set_sp(istate->stack() + 1);
118 118
119 119 // Make the call
120 120 Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD);
121 121 fixup_after_potential_safepoint();
122 122
123 123 // Convert the result
124 124 istate->set_stack(stack->sp() - 1);
125 125
126 126 // Restore the stack
127 127 stack->set_sp(istate->stack_limit() + 1);
128 128
129 129 // Resume the interpreter
130 130 istate->set_msg(BytecodeInterpreter::method_resume);
131 131 }
132 132 else if (istate->msg() == BytecodeInterpreter::more_monitors) {
133 133 int monitor_words = frame::interpreter_frame_monitor_size();
134 134
135 135 // Allocate the space
136 136 stack->overflow_check(monitor_words, THREAD);
137 137 if (HAS_PENDING_EXCEPTION)
138 138 break;
139 139 stack->alloc(monitor_words * wordSize);
140 140
141 141 // Move the expression stack contents
142 142 for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++)
143 143 *(p - monitor_words) = *p;
144 144
145 145 // Move the expression stack pointers
146 146 istate->set_stack_limit(istate->stack_limit() - monitor_words);
147 147 istate->set_stack(istate->stack() - monitor_words);
148 148 istate->set_stack_base(istate->stack_base() - monitor_words);
149 149
150 150 // Zero the new monitor so the interpreter can find it.
151 151 ((BasicObjectLock *) istate->stack_base())->set_obj(NULL);
152 152
153 153 // Resume the interpreter
154 154 istate->set_msg(BytecodeInterpreter::got_monitors);
155 155 }
156 156 else if (istate->msg() == BytecodeInterpreter::return_from_method) {
157 157 // Copy the result into the caller's frame
158 158 result_slots = type2size[result_type_of(method)];
159 159 assert(result_slots >= 0 && result_slots <= 2, "what?");
160 160 result = istate->stack() + result_slots;
161 161 break;
162 162 }
163 163 else if (istate->msg() == BytecodeInterpreter::throwing_exception) {
164 164 assert(HAS_PENDING_EXCEPTION, "should do");
165 165 break;
166 166 }
167 167 else if (istate->msg() == BytecodeInterpreter::do_osr) {
168 168 // Unwind the current frame
169 169 thread->pop_zero_frame();
170 170
171 171 // Remove any extension of the previous frame
172 172 int extra_locals = method->max_locals() - method->size_of_parameters();
173 173 stack->set_sp(stack->sp() + extra_locals);
174 174
175 175 // Jump into the OSR method
176 176 Interpreter::invoke_osr(
177 177 method, istate->osr_entry(), istate->osr_buf(), THREAD);
178 178 return;
179 179 }
180 180 else {
181 181 ShouldNotReachHere();
182 182 }
183 183 }
184 184
185 185 // Unwind the current frame
186 186 thread->pop_zero_frame();
187 187
188 188 // Pop our local variables
189 189 stack->set_sp(stack->sp() + method->max_locals());
190 190
191 191 // Push our result
192 192 for (int i = 0; i < result_slots; i++)
193 193 stack->push(result[-i]);
194 194 }
195 195
196 196 int CppInterpreter::native_entry(methodOop method, intptr_t UNUSED, TRAPS) {
197 197 // Make sure method is native and not abstract
198 198 assert(method->is_native() && !method->is_abstract(), "should be");
199 199
200 200 JavaThread *thread = (JavaThread *) THREAD;
201 201 ZeroStack *stack = thread->zero_stack();
202 202
203 203 // Allocate and initialize our frame
204 204 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0);
205 205 thread->push_zero_frame(frame);
206 206 interpreterState istate = frame->interpreter_state();
207 207 intptr_t *locals = istate->locals();
208 208
209 209 // Update the invocation counter
210 210 if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) {
211 211 InvocationCounter *counter = method->invocation_counter();
212 212 counter->increment();
213 213 if (counter->reached_InvocationLimit()) {
214 214 CALL_VM_NOCHECK(
215 215 InterpreterRuntime::frequency_counter_overflow(thread, NULL));
216 216 if (HAS_PENDING_EXCEPTION)
217 217 goto unwind_and_return;
218 218 }
219 219 }
220 220
221 221 // Lock if necessary
222 222 BasicObjectLock *monitor;
223 223 monitor = NULL;
224 224 if (method->is_synchronized()) {
225 225 monitor = (BasicObjectLock*) istate->stack_base();
226 226 oop lockee = monitor->obj();
227 227 markOop disp = lockee->mark()->set_unlocked();
228 228
229 229 monitor->lock()->set_displaced_header(disp);
230 230 if (Atomic::cmpxchg_ptr(monitor, lockee->mark_addr(), disp) != disp) {
231 231 if (thread->is_lock_owned((address) disp->clear_lock_bits())) {
232 232 monitor->lock()->set_displaced_header(NULL);
233 233 }
234 234 else {
235 235 CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor));
236 236 if (HAS_PENDING_EXCEPTION)
237 237 goto unwind_and_return;
238 238 }
239 239 }
240 240 }
241 241
242 242 // Get the signature handler
243 243 InterpreterRuntime::SignatureHandler *handler; {
244 244 address handlerAddr = method->signature_handler();
245 245 if (handlerAddr == NULL) {
246 246 CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method));
247 247 if (HAS_PENDING_EXCEPTION)
248 248 goto unlock_unwind_and_return;
249 249
250 250 handlerAddr = method->signature_handler();
251 251 assert(handlerAddr != NULL, "eh?");
252 252 }
253 253 if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) {
254 254 CALL_VM_NOCHECK(handlerAddr =
255 255 InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL));
256 256 if (HAS_PENDING_EXCEPTION)
257 257 goto unlock_unwind_and_return;
258 258 }
259 259 handler = \
260 260 InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr);
261 261 }
262 262
263 263 // Get the native function entry point
264 264 address function;
265 265 function = method->native_function();
266 266 assert(function != NULL, "should be set if signature handler is");
267 267
268 268 // Build the argument list
269 269 stack->overflow_check(handler->argument_count() * 2, THREAD);
270 270 if (HAS_PENDING_EXCEPTION)
271 271 goto unlock_unwind_and_return;
272 272
273 273 void **arguments;
274 274 void *mirror; {
275 275 arguments =
276 276 (void **) stack->alloc(handler->argument_count() * sizeof(void **));
277 277 void **dst = arguments;
278 278
279 279 void *env = thread->jni_environment();
280 280 *(dst++) = &env;
281 281
282 282 if (method->is_static()) {
283 283 istate->set_oop_temp(
284 284 method->constants()->pool_holder()->klass_part()->java_mirror());
285 285 mirror = istate->oop_temp_addr();
286 286 *(dst++) = &mirror;
287 287 }
288 288
289 289 intptr_t *src = locals;
290 290 for (int i = dst - arguments; i < handler->argument_count(); i++) {
291 291 ffi_type *type = handler->argument_type(i);
292 292 if (type == &ffi_type_pointer) {
293 293 if (*src) {
294 294 stack->push((intptr_t) src);
295 295 *(dst++) = stack->sp();
296 296 }
297 297 else {
298 298 *(dst++) = src;
299 299 }
300 300 src--;
301 301 }
302 302 else if (type->size == 4) {
303 303 *(dst++) = src--;
304 304 }
305 305 else if (type->size == 8) {
306 306 src--;
307 307 *(dst++) = src--;
308 308 }
309 309 else {
310 310 ShouldNotReachHere();
311 311 }
312 312 }
313 313 }
314 314
315 315 // Set up the Java frame anchor
316 316 thread->set_last_Java_frame();
317 317
318 318 // Change the thread state to _thread_in_native
319 319 ThreadStateTransition::transition_from_java(thread, _thread_in_native);
320 320
321 321 // Make the call
322 322 intptr_t result[4 - LogBytesPerWord];
323 323 ffi_call(handler->cif(), (void (*)()) function, result, arguments);
324 324
325 325 // Change the thread state back to _thread_in_Java.
326 326 // ThreadStateTransition::transition_from_native() cannot be used
327 327 // here because it does not check for asynchronous exceptions.
328 328 // We have to manage the transition ourself.
329 329 thread->set_thread_state(_thread_in_native_trans);
330 330
331 331 // Make sure new state is visible in the GC thread
332 332 if (os::is_MP()) {
333 333 if (UseMembar) {
334 334 OrderAccess::fence();
335 335 }
336 336 else {
337 337 InterfaceSupport::serialize_memory(thread);
338 338 }
339 339 }
340 340
341 341 // Handle safepoint operations, pending suspend requests,
342 342 // and pending asynchronous exceptions.
343 343 if (SafepointSynchronize::do_call_back() ||
344 344 thread->has_special_condition_for_native_trans()) {
345 345 JavaThread::check_special_condition_for_native_trans(thread);
346 346 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops());
347 347 }
348 348
349 349 // Finally we can change the thread state to _thread_in_Java.
350 350 thread->set_thread_state(_thread_in_Java);
351 351 fixup_after_potential_safepoint();
352 352
353 353 // Clear the frame anchor
354 354 thread->reset_last_Java_frame();
355 355
356 356 // If the result was an oop then unbox it and store it in
357 357 // oop_temp where the garbage collector can see it before
358 358 // we release the handle it might be protected by.
359 359 if (handler->result_type() == &ffi_type_pointer) {
360 360 if (result[0])
361 361 istate->set_oop_temp(*(oop *) result[0]);
362 362 else
363 363 istate->set_oop_temp(NULL);
364 364 }
365 365
366 366 // Reset handle block
367 367 thread->active_handles()->clear();
368 368
369 369 unlock_unwind_and_return:
370 370
371 371 // Unlock if necessary
372 372 if (monitor) {
373 373 BasicLock *lock = monitor->lock();
374 374 markOop header = lock->displaced_header();
375 375 oop rcvr = monitor->obj();
376 376 monitor->set_obj(NULL);
377 377
378 378 if (header != NULL) {
379 379 if (Atomic::cmpxchg_ptr(header, rcvr->mark_addr(), lock) != lock) {
380 380 monitor->set_obj(rcvr); {
381 381 HandleMark hm(thread);
382 382 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor));
383 383 }
384 384 }
385 385 }
386 386 }
387 387
388 388 unwind_and_return:
389 389
390 390 // Unwind the current activation
391 391 thread->pop_zero_frame();
392 392
393 393 // Pop our parameters
394 394 stack->set_sp(stack->sp() + method->size_of_parameters());
395 395
396 396 // Push our result
397 397 if (!HAS_PENDING_EXCEPTION) {
398 398 BasicType type = result_type_of(method);
399 399 stack->set_sp(stack->sp() - type2size[type]);
400 400
401 401 switch (type) {
402 402 case T_VOID:
403 403 break;
404 404
405 405 case T_BOOLEAN:
406 406 #ifndef VM_LITTLE_ENDIAN
407 407 result[0] <<= (BitsPerWord - BitsPerByte);
408 408 #endif
409 409 SET_LOCALS_INT(*(jboolean *) result != 0, 0);
410 410 break;
411 411
412 412 case T_CHAR:
413 413 #ifndef VM_LITTLE_ENDIAN
414 414 result[0] <<= (BitsPerWord - BitsPerShort);
415 415 #endif
416 416 SET_LOCALS_INT(*(jchar *) result, 0);
417 417 break;
418 418
419 419 case T_BYTE:
420 420 #ifndef VM_LITTLE_ENDIAN
421 421 result[0] <<= (BitsPerWord - BitsPerByte);
422 422 #endif
423 423 SET_LOCALS_INT(*(jbyte *) result, 0);
424 424 break;
425 425
426 426 case T_SHORT:
427 427 #ifndef VM_LITTLE_ENDIAN
428 428 result[0] <<= (BitsPerWord - BitsPerShort);
429 429 #endif
430 430 SET_LOCALS_INT(*(jshort *) result, 0);
431 431 break;
432 432
433 433 case T_INT:
434 434 #ifndef VM_LITTLE_ENDIAN
435 435 result[0] <<= (BitsPerWord - BitsPerInt);
436 436 #endif
437 437 SET_LOCALS_INT(*(jint *) result, 0);
438 438 break;
439 439
440 440 case T_LONG:
441 441 SET_LOCALS_LONG(*(jlong *) result, 0);
442 442 break;
443 443
444 444 case T_FLOAT:
445 445 SET_LOCALS_FLOAT(*(jfloat *) result, 0);
446 446 break;
447 447
448 448 case T_DOUBLE:
449 449 SET_LOCALS_DOUBLE(*(jdouble *) result, 0);
450 450 break;
451 451
452 452 case T_OBJECT:
453 453 case T_ARRAY:
454 454 SET_LOCALS_OBJECT(istate->oop_temp(), 0);
455 455 break;
456 456
457 457 default:
458 458 ShouldNotReachHere();
459 459 }
460 460 }
461 461
462 462 // No deoptimized frames on the stack
463 463 return 0;
464 464 }
465 465
466 466 int CppInterpreter::accessor_entry(methodOop method, intptr_t UNUSED, TRAPS) {
467 467 JavaThread *thread = (JavaThread *) THREAD;
468 468 ZeroStack *stack = thread->zero_stack();
469 469 intptr_t *locals = stack->sp();
470 470
471 471 // Drop into the slow path if we need a safepoint check
472 472 if (SafepointSynchronize::do_call_back()) {
473 473 return normal_entry(method, 0, THREAD);
474 474 }
475 475
476 476 // Load the object pointer and drop into the slow path
477 477 // if we have a NullPointerException
478 478 oop object = LOCALS_OBJECT(0);
479 479 if (object == NULL) {
480 480 return normal_entry(method, 0, THREAD);
481 481 }
482 482
483 483 // Read the field index from the bytecode, which looks like this:
484 484 // 0: aload_0
485 485 // 1: getfield
486 486 // 2: index
487 487 // 3: index
488 488 // 4: ireturn/areturn
489 489 // NB this is not raw bytecode: index is in machine order
490 490 u1 *code = method->code_base();
491 491 assert(code[0] == Bytecodes::_aload_0 &&
492 492 code[1] == Bytecodes::_getfield &&
493 493 (code[4] == Bytecodes::_ireturn ||
494 494 code[4] == Bytecodes::_areturn), "should do");
495 495 u2 index = Bytes::get_native_u2(&code[2]);
496 496
497 497 // Get the entry from the constant pool cache, and drop into
498 498 // the slow path if it has not been resolved
499 499 constantPoolCacheOop cache = method->constants()->cache();
500 500 ConstantPoolCacheEntry* entry = cache->entry_at(index);
501 501 if (!entry->is_resolved(Bytecodes::_getfield)) {
502 502 return normal_entry(method, 0, THREAD);
503 503 }
504 504
505 505 // Get the result and push it onto the stack
506 506 switch (entry->flag_state()) {
507 507 case ltos:
508 508 case dtos:
509 509 stack->overflow_check(1, CHECK_0);
510 510 stack->alloc(wordSize);
511 511 break;
512 512 }
513 513 if (entry->is_volatile()) {
514 514 switch (entry->flag_state()) {
515 515 case ctos:
516 516 SET_LOCALS_INT(object->char_field_acquire(entry->f2()), 0);
517 517 break;
518 518
519 519 case btos:
520 520 SET_LOCALS_INT(object->byte_field_acquire(entry->f2()), 0);
521 521 break;
522 522
523 523 case stos:
524 524 SET_LOCALS_INT(object->short_field_acquire(entry->f2()), 0);
525 525 break;
526 526
527 527 case itos:
528 528 SET_LOCALS_INT(object->int_field_acquire(entry->f2()), 0);
529 529 break;
530 530
531 531 case ltos:
532 532 SET_LOCALS_LONG(object->long_field_acquire(entry->f2()), 0);
533 533 break;
534 534
535 535 case ftos:
536 536 SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2()), 0);
537 537 break;
538 538
539 539 case dtos:
540 540 SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2()), 0);
541 541 break;
542 542
543 543 case atos:
544 544 SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2()), 0);
545 545 break;
546 546
547 547 default:
548 548 ShouldNotReachHere();
549 549 }
550 550 }
551 551 else {
552 552 switch (entry->flag_state()) {
553 553 case ctos:
554 554 SET_LOCALS_INT(object->char_field(entry->f2()), 0);
555 555 break;
556 556
557 557 case btos:
558 558 SET_LOCALS_INT(object->byte_field(entry->f2()), 0);
559 559 break;
560 560
561 561 case stos:
562 562 SET_LOCALS_INT(object->short_field(entry->f2()), 0);
563 563 break;
564 564
565 565 case itos:
566 566 SET_LOCALS_INT(object->int_field(entry->f2()), 0);
567 567 break;
568 568
569 569 case ltos:
570 570 SET_LOCALS_LONG(object->long_field(entry->f2()), 0);
571 571 break;
572 572
573 573 case ftos:
574 574 SET_LOCALS_FLOAT(object->float_field(entry->f2()), 0);
575 575 break;
576 576
577 577 case dtos:
578 578 SET_LOCALS_DOUBLE(object->double_field(entry->f2()), 0);
579 579 break;
580 580
581 581 case atos:
582 582 SET_LOCALS_OBJECT(object->obj_field(entry->f2()), 0);
583 583 break;
584 584
585 585 default:
586 586 ShouldNotReachHere();
587 587 }
588 588 }
589 589
590 590 // No deoptimized frames on the stack
591 591 return 0;
592 592 }
593 593
594 594 int CppInterpreter::empty_entry(methodOop method, intptr_t UNUSED, TRAPS) {
595 595 JavaThread *thread = (JavaThread *) THREAD;
596 596 ZeroStack *stack = thread->zero_stack();
597 597
598 598 // Drop into the slow path if we need a safepoint check
599 599 if (SafepointSynchronize::do_call_back()) {
600 600 return normal_entry(method, 0, THREAD);
601 601 }
602 602
603 603 // Pop our parameters
604 604 stack->set_sp(stack->sp() + method->size_of_parameters());
605 605
606 606 // No deoptimized frames on the stack
607 607 return 0;
608 608 }
609 609
610 610 InterpreterFrame *InterpreterFrame::build(const methodOop method, TRAPS) {
611 611 JavaThread *thread = (JavaThread *) THREAD;
612 612 ZeroStack *stack = thread->zero_stack();
613 613
614 614 // Calculate the size of the frame we'll build, including
615 615 // any adjustments to the caller's frame that we'll make.
616 616 int extra_locals = 0;
617 617 int monitor_words = 0;
618 618 int stack_words = 0;
619 619
620 620 if (!method->is_native()) {
621 621 extra_locals = method->max_locals() - method->size_of_parameters();
622 622 stack_words = method->max_stack();
623 623 }
624 624 if (method->is_synchronized()) {
625 625 monitor_words = frame::interpreter_frame_monitor_size();
626 626 }
627 627 stack->overflow_check(
628 628 extra_locals + header_words + monitor_words + stack_words, CHECK_NULL);
629 629
630 630 // Adjust the caller's stack frame to accomodate any additional
631 631 // local variables we have contiguously with our parameters.
632 632 for (int i = 0; i < extra_locals; i++)
633 633 stack->push(0);
634 634
635 635 intptr_t *locals;
636 636 if (method->is_native())
637 637 locals = stack->sp() + (method->size_of_parameters() - 1);
638 638 else
639 639 locals = stack->sp() + (method->max_locals() - 1);
640 640
641 641 stack->push(0); // next_frame, filled in later
642 642 intptr_t *fp = stack->sp();
643 643 assert(fp - stack->sp() == next_frame_off, "should be");
644 644
645 645 stack->push(INTERPRETER_FRAME);
646 646 assert(fp - stack->sp() == frame_type_off, "should be");
647 647
648 648 interpreterState istate =
649 649 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
650 650 assert(fp - stack->sp() == istate_off, "should be");
651 651
652 652 istate->set_locals(locals);
653 653 istate->set_method(method);
654 654 istate->set_self_link(istate);
655 655 istate->set_prev_link(NULL);
656 656 istate->set_thread(thread);
657 657 istate->set_bcp(method->is_native() ? NULL : method->code_base());
658 658 istate->set_constants(method->constants()->cache());
659 659 istate->set_msg(BytecodeInterpreter::method_entry);
660 660 istate->set_oop_temp(NULL);
661 661 istate->set_mdx(NULL);
662 662 istate->set_callee(NULL);
663 663
664 664 istate->set_monitor_base((BasicObjectLock *) stack->sp());
665 665 if (method->is_synchronized()) {
666 666 BasicObjectLock *monitor =
667 667 (BasicObjectLock *) stack->alloc(monitor_words * wordSize);
668 668 oop object;
669 669 if (method->is_static())
670 670 object = method->constants()->pool_holder()->klass_part()->java_mirror();
671 671 else
672 672 object = (oop) locals[0];
673 673 monitor->set_obj(object);
674 674 }
675 675
676 676 istate->set_stack_base(stack->sp());
677 677 istate->set_stack(stack->sp() - 1);
678 678 if (stack_words)
679 679 stack->alloc(stack_words * wordSize);
680 680 istate->set_stack_limit(stack->sp() - 1);
681 681
682 682 return (InterpreterFrame *) fp;
683 683 }
684 684
685 685 int AbstractInterpreter::BasicType_as_index(BasicType type) {
686 686 int i = 0;
687 687 switch (type) {
688 688 case T_BOOLEAN: i = 0; break;
689 689 case T_CHAR : i = 1; break;
690 690 case T_BYTE : i = 2; break;
691 691 case T_SHORT : i = 3; break;
692 692 case T_INT : i = 4; break;
693 693 case T_LONG : i = 5; break;
694 694 case T_VOID : i = 6; break;
695 695 case T_FLOAT : i = 7; break;
696 696 case T_DOUBLE : i = 8; break;
697 697 case T_OBJECT : i = 9; break;
698 698 case T_ARRAY : i = 9; break;
699 699 default : ShouldNotReachHere();
700 700 }
701 701 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
702 702 "index out of bounds");
703 703 return i;
704 704 }
705 705
706 706 BasicType CppInterpreter::result_type_of(methodOop method) {
707 707 BasicType t;
708 708 switch (method->result_index()) {
709 709 case 0 : t = T_BOOLEAN; break;
710 710 case 1 : t = T_CHAR; break;
711 711 case 2 : t = T_BYTE; break;
712 712 case 3 : t = T_SHORT; break;
713 713 case 4 : t = T_INT; break;
714 714 case 5 : t = T_LONG; break;
715 715 case 6 : t = T_VOID; break;
716 716 case 7 : t = T_FLOAT; break;
717 717 case 8 : t = T_DOUBLE; break;
718 718 case 9 : t = T_OBJECT; break;
719 719 default: ShouldNotReachHere();
720 720 }
721 721 assert(AbstractInterpreter::BasicType_as_index(t) == method->result_index(),
722 722 "out of step with AbstractInterpreter::BasicType_as_index");
723 723 return t;
724 724 }
725 725
726 726 address InterpreterGenerator::generate_empty_entry() {
727 727 if (!UseFastEmptyMethods)
728 728 return NULL;
729 729
↓ open down ↓ |
717 lines elided |
↑ open up ↑ |
730 730 return generate_entry((address) CppInterpreter::empty_entry);
731 731 }
732 732
733 733 address InterpreterGenerator::generate_accessor_entry() {
734 734 if (!UseFastAccessorMethods)
735 735 return NULL;
736 736
737 737 return generate_entry((address) CppInterpreter::accessor_entry);
738 738 }
739 739
740 +address InterpreterGenerator::generate_Reference_get_entry(void) {
741 +#ifndef SERIALGC
742 + if (UseG1GC) {
743 + // We need to generate have a routine that generates code to:
744 + // * load the value in the referent field
745 + // * passes that value to the pre-barrier.
746 + //
747 + // In the case of G1 this will record the value of the
748 + // referent in an SATB buffer if marking is active.
749 + // This will cause concurrent marking to mark the referent
750 + // field as live.
751 + Unimplemented();
752 + }
753 +#endif // SERIALGC
754 +
755 + // If G1 is not enabled then attempt to go through the accessor entry point
756 + // Reference.get is an accessor
757 + return generate_accessor_entry();
758 +}
759 +
740 760 address InterpreterGenerator::generate_native_entry(bool synchronized) {
741 761 assert(synchronized == false, "should be");
742 762
743 763 return generate_entry((address) CppInterpreter::native_entry);
744 764 }
745 765
746 766 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
747 767 assert(synchronized == false, "should be");
748 768
749 769 return generate_entry((address) CppInterpreter::normal_entry);
750 770 }
751 771
752 772 address AbstractInterpreterGenerator::generate_method_entry(
753 773 AbstractInterpreter::MethodKind kind) {
754 774 address entry_point = NULL;
755 775
756 776 switch (kind) {
757 777 case Interpreter::zerolocals:
758 778 case Interpreter::zerolocals_synchronized:
759 779 break;
760 780
761 781 case Interpreter::native:
762 782 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
763 783 break;
764 784
765 785 case Interpreter::native_synchronized:
766 786 entry_point = ((InterpreterGenerator*) this)->generate_native_entry(false);
767 787 break;
768 788
769 789 case Interpreter::empty:
770 790 entry_point = ((InterpreterGenerator*) this)->generate_empty_entry();
771 791 break;
772 792
773 793 case Interpreter::accessor:
774 794 entry_point = ((InterpreterGenerator*) this)->generate_accessor_entry();
775 795 break;
776 796
777 797 case Interpreter::abstract:
778 798 entry_point = ((InterpreterGenerator*) this)->generate_abstract_entry();
779 799 break;
780 800
781 801 case Interpreter::method_handle:
782 802 entry_point = ((InterpreterGenerator*) this)->generate_method_handle_entry();
783 803 break;
784 804
↓ open down ↓ |
35 lines elided |
↑ open up ↑ |
785 805 case Interpreter::java_lang_math_sin:
786 806 case Interpreter::java_lang_math_cos:
787 807 case Interpreter::java_lang_math_tan:
788 808 case Interpreter::java_lang_math_abs:
789 809 case Interpreter::java_lang_math_log:
790 810 case Interpreter::java_lang_math_log10:
791 811 case Interpreter::java_lang_math_sqrt:
792 812 entry_point = ((InterpreterGenerator*) this)->generate_math_entry(kind);
793 813 break;
794 814
815 + case Interpreter::java_lang_ref_reference_get:
816 + entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry();
817 + break;
818 +
795 819 default:
796 820 ShouldNotReachHere();
797 821 }
798 822
799 823 if (entry_point == NULL)
800 824 entry_point = ((InterpreterGenerator*) this)->generate_normal_entry(false);
801 825
802 826 return entry_point;
803 827 }
804 828
805 829 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
806 830 : CppInterpreterGenerator(code) {
807 831 generate_all();
808 832 }
809 833
810 834 // Deoptimization helpers
811 835
812 836 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) {
813 837 ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack();
814 838
815 839 int size_in_words = size >> LogBytesPerWord;
816 840 assert(size_in_words * wordSize == size, "unaligned");
817 841 assert(size_in_words >= header_words, "too small");
818 842 stack->overflow_check(size_in_words, CHECK_NULL);
819 843
820 844 stack->push(0); // next_frame, filled in later
821 845 intptr_t *fp = stack->sp();
822 846 assert(fp - stack->sp() == next_frame_off, "should be");
823 847
824 848 stack->push(INTERPRETER_FRAME);
825 849 assert(fp - stack->sp() == frame_type_off, "should be");
826 850
827 851 interpreterState istate =
828 852 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter));
829 853 assert(fp - stack->sp() == istate_off, "should be");
830 854 istate->set_self_link(NULL); // mark invalid
831 855
832 856 stack->alloc((size_in_words - header_words) * wordSize);
833 857
834 858 return (InterpreterFrame *) fp;
835 859 }
836 860
837 861 int AbstractInterpreter::layout_activation(methodOop method,
838 862 int tempcount,
839 863 int popframe_extra_args,
840 864 int moncount,
841 865 int callee_param_count,
842 866 int callee_locals,
843 867 frame* caller,
844 868 frame* interpreter_frame,
845 869 bool is_top_frame) {
846 870 assert(popframe_extra_args == 0, "what to do?");
847 871 assert(!is_top_frame || (!callee_locals && !callee_param_count),
848 872 "top frame should have no caller");
849 873
850 874 // This code must exactly match what InterpreterFrame::build
851 875 // does (the full InterpreterFrame::build, that is, not the
852 876 // one that creates empty frames for the deoptimizer).
853 877 //
854 878 // If interpreter_frame is not NULL then it will be filled in.
855 879 // It's size is determined by a previous call to this method,
856 880 // so it should be correct.
857 881 //
858 882 // Note that tempcount is the current size of the expression
859 883 // stack. For top most frames we will allocate a full sized
860 884 // expression stack and not the trimmed version that non-top
861 885 // frames have.
862 886
863 887 int header_words = InterpreterFrame::header_words;
864 888 int monitor_words = moncount * frame::interpreter_frame_monitor_size();
865 889 int stack_words = is_top_frame ? method->max_stack() : tempcount;
866 890 int callee_extra_locals = callee_locals - callee_param_count;
867 891
868 892 if (interpreter_frame) {
869 893 intptr_t *locals = interpreter_frame->fp() + method->max_locals();
870 894 interpreterState istate = interpreter_frame->get_interpreterState();
871 895 intptr_t *monitor_base = (intptr_t*) istate;
872 896 intptr_t *stack_base = monitor_base - monitor_words;
873 897 intptr_t *stack = stack_base - tempcount - 1;
874 898
875 899 BytecodeInterpreter::layout_interpreterState(istate,
876 900 caller,
877 901 NULL,
878 902 method,
879 903 locals,
880 904 stack,
881 905 stack_base,
882 906 monitor_base,
883 907 NULL,
884 908 is_top_frame);
885 909 }
886 910 return header_words + monitor_words + stack_words + callee_extra_locals;
887 911 }
888 912
889 913 void BytecodeInterpreter::layout_interpreterState(interpreterState istate,
890 914 frame* caller,
891 915 frame* current,
892 916 methodOop method,
893 917 intptr_t* locals,
894 918 intptr_t* stack,
895 919 intptr_t* stack_base,
896 920 intptr_t* monitor_base,
897 921 intptr_t* frame_bottom,
898 922 bool is_top_frame) {
899 923 istate->set_locals(locals);
900 924 istate->set_method(method);
901 925 istate->set_self_link(istate);
902 926 istate->set_prev_link(NULL);
903 927 // thread will be set by a hacky repurposing of frame::patch_pc()
904 928 // bcp will be set by vframeArrayElement::unpack_on_stack()
905 929 istate->set_constants(method->constants()->cache());
906 930 istate->set_msg(BytecodeInterpreter::method_resume);
907 931 istate->set_bcp_advance(0);
908 932 istate->set_oop_temp(NULL);
909 933 istate->set_mdx(NULL);
910 934 if (caller->is_interpreted_frame()) {
911 935 interpreterState prev = caller->get_interpreterState();
912 936 prev->set_callee(method);
913 937 if (*prev->bcp() == Bytecodes::_invokeinterface)
914 938 prev->set_bcp_advance(5);
915 939 else
916 940 prev->set_bcp_advance(3);
917 941 }
918 942 istate->set_callee(NULL);
919 943 istate->set_monitor_base((BasicObjectLock *) monitor_base);
920 944 istate->set_stack_base(stack_base);
921 945 istate->set_stack(stack);
922 946 istate->set_stack_limit(stack_base - method->max_stack() - 1);
923 947 }
924 948
925 949 address CppInterpreter::return_entry(TosState state, int length) {
926 950 ShouldNotCallThis();
927 951 }
928 952
929 953 address CppInterpreter::deopt_entry(TosState state, int length) {
930 954 return NULL;
931 955 }
932 956
933 957 // Helper for (runtime) stack overflow checks
934 958
935 959 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
936 960 return 0;
937 961 }
938 962
939 963 // Helper for figuring out if frames are interpreter frames
940 964
941 965 bool CppInterpreter::contains(address pc) {
942 966 #ifdef PRODUCT
943 967 ShouldNotCallThis();
944 968 #else
945 969 return false; // make frame::print_value_on work
946 970 #endif // !PRODUCT
947 971 }
948 972
949 973 // Result handlers and convertors
950 974
951 975 address CppInterpreterGenerator::generate_result_handler_for(
952 976 BasicType type) {
953 977 assembler()->advance(1);
954 978 return ShouldNotCallThisStub();
955 979 }
956 980
957 981 address CppInterpreterGenerator::generate_tosca_to_stack_converter(
958 982 BasicType type) {
959 983 assembler()->advance(1);
960 984 return ShouldNotCallThisStub();
961 985 }
962 986
963 987 address CppInterpreterGenerator::generate_stack_to_stack_converter(
964 988 BasicType type) {
965 989 assembler()->advance(1);
966 990 return ShouldNotCallThisStub();
967 991 }
968 992
969 993 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(
970 994 BasicType type) {
971 995 assembler()->advance(1);
972 996 return ShouldNotCallThisStub();
973 997 }
974 998
975 999 #endif // CC_INTERP
↓ open down ↓ |
171 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX