1 /* 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/assembler.hpp" 28 #include "interpreter/bytecodeHistogram.hpp" 29 #include "interpreter/cppInterpreter.hpp" 30 #include "interpreter/cppInterpreterGenerator.hpp" 31 #include "interpreter/interpreter.hpp" 32 #include "interpreter/interpreterRuntime.hpp" 33 #include "oops/arrayOop.hpp" 34 #include "oops/cpCache.inline.hpp" 35 #include "oops/methodData.hpp" 36 #include "oops/method.hpp" 37 #include "oops/oop.inline.hpp" 38 #include "prims/jvmtiExport.hpp" 39 #include "prims/jvmtiThreadState.hpp" 40 #include "runtime/arguments.hpp" 41 #include "runtime/atomic.hpp" 42 #include "runtime/deoptimization.hpp" 43 #include "runtime/frame.inline.hpp" 44 #include "runtime/interfaceSupport.inline.hpp" 45 #include "runtime/jniHandles.inline.hpp" 46 #include "runtime/orderAccess.inline.hpp" 47 #include "runtime/sharedRuntime.hpp" 48 #include "runtime/stubRoutines.hpp" 49 #include "runtime/synchronizer.hpp" 50 #include "runtime/timer.hpp" 51 #include "runtime/vframeArray.hpp" 52 #include "stack_zero.inline.hpp" 53 #include "utilities/debug.hpp" 54 #include "utilities/macros.hpp" 55 56 #ifdef CC_INTERP 57 58 #define fixup_after_potential_safepoint() \ 59 method = istate->method() 60 61 #define CALL_VM_NOCHECK_NOFIX(func) \ 62 thread->set_last_Java_frame(); \ 63 func; \ 64 thread->reset_last_Java_frame(); 65 66 #define CALL_VM_NOCHECK(func) \ 67 CALL_VM_NOCHECK_NOFIX(func) \ 68 fixup_after_potential_safepoint() 69 70 int CppInterpreter::normal_entry(Method* method, intptr_t UNUSED, TRAPS) { 71 JavaThread *thread = (JavaThread *) THREAD; 72 73 // Allocate and initialize our frame. 74 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); 75 thread->push_zero_frame(frame); 76 77 // Execute those bytecodes! 78 main_loop(0, THREAD); 79 80 // No deoptimized frames on the stack 81 return 0; 82 } 83 84 intptr_t narrow(BasicType type, intptr_t result) { 85 // mask integer result to narrower return type. 86 switch (type) { 87 case T_BOOLEAN: 88 return result&1; 89 case T_BYTE: 90 return (intptr_t)(jbyte)result; 91 case T_CHAR: 92 return (intptr_t)(uintptr_t)(jchar)result; 93 case T_SHORT: 94 return (intptr_t)(jshort)result; 95 case T_OBJECT: // nothing to do fall through 96 case T_ARRAY: 97 case T_LONG: 98 case T_INT: 99 case T_FLOAT: 100 case T_DOUBLE: 101 case T_VOID: 102 return result; 103 default : ShouldNotReachHere(); 104 } 105 } 106 107 108 void CppInterpreter::main_loop(int recurse, TRAPS) { 109 JavaThread *thread = (JavaThread *) THREAD; 110 ZeroStack *stack = thread->zero_stack(); 111 112 // If we are entering from a deopt we may need to call 113 // ourself a few times in order to get to our frame. 114 if (recurse) 115 main_loop(recurse - 1, THREAD); 116 117 InterpreterFrame *frame = thread->top_zero_frame()->as_interpreter_frame(); 118 interpreterState istate = frame->interpreter_state(); 119 Method* method = istate->method(); 120 121 intptr_t *result = NULL; 122 int result_slots = 0; 123 124 while (true) { 125 // We can set up the frame anchor with everything we want at 126 // this point as we are thread_in_Java and no safepoints can 127 // occur until we go to vm mode. We do have to clear flags 128 // on return from vm but that is it. 129 thread->set_last_Java_frame(); 130 131 // Call the interpreter 132 if (JvmtiExport::can_post_interpreter_events()) 133 BytecodeInterpreter::runWithChecks(istate); 134 else 135 BytecodeInterpreter::run(istate); 136 fixup_after_potential_safepoint(); 137 138 // Clear the frame anchor 139 thread->reset_last_Java_frame(); 140 141 // Examine the message from the interpreter to decide what to do 142 if (istate->msg() == BytecodeInterpreter::call_method) { 143 Method* callee = istate->callee(); 144 145 // Trim back the stack to put the parameters at the top 146 stack->set_sp(istate->stack() + 1); 147 148 // Make the call 149 Interpreter::invoke_method(callee, istate->callee_entry_point(), THREAD); 150 fixup_after_potential_safepoint(); 151 152 // Convert the result 153 istate->set_stack(stack->sp() - 1); 154 155 // Restore the stack 156 stack->set_sp(istate->stack_limit() + 1); 157 158 // Resume the interpreter 159 istate->set_msg(BytecodeInterpreter::method_resume); 160 } 161 else if (istate->msg() == BytecodeInterpreter::more_monitors) { 162 int monitor_words = frame::interpreter_frame_monitor_size(); 163 164 // Allocate the space 165 stack->overflow_check(monitor_words, THREAD); 166 if (HAS_PENDING_EXCEPTION) 167 break; 168 stack->alloc(monitor_words * wordSize); 169 170 // Move the expression stack contents 171 for (intptr_t *p = istate->stack() + 1; p < istate->stack_base(); p++) 172 *(p - monitor_words) = *p; 173 174 // Move the expression stack pointers 175 istate->set_stack_limit(istate->stack_limit() - monitor_words); 176 istate->set_stack(istate->stack() - monitor_words); 177 istate->set_stack_base(istate->stack_base() - monitor_words); 178 179 // Zero the new monitor so the interpreter can find it. 180 ((BasicObjectLock *) istate->stack_base())->set_obj(NULL); 181 182 // Resume the interpreter 183 istate->set_msg(BytecodeInterpreter::got_monitors); 184 } 185 else if (istate->msg() == BytecodeInterpreter::return_from_method) { 186 // Copy the result into the caller's frame 187 result_slots = type2size[method->result_type()]; 188 assert(result_slots >= 0 && result_slots <= 2, "what?"); 189 result = istate->stack() + result_slots; 190 break; 191 } 192 else if (istate->msg() == BytecodeInterpreter::throwing_exception) { 193 assert(HAS_PENDING_EXCEPTION, "should do"); 194 break; 195 } 196 else if (istate->msg() == BytecodeInterpreter::do_osr) { 197 // Unwind the current frame 198 thread->pop_zero_frame(); 199 200 // Remove any extension of the previous frame 201 int extra_locals = method->max_locals() - method->size_of_parameters(); 202 stack->set_sp(stack->sp() + extra_locals); 203 204 // Jump into the OSR method 205 Interpreter::invoke_osr( 206 method, istate->osr_entry(), istate->osr_buf(), THREAD); 207 return; 208 } 209 else { 210 ShouldNotReachHere(); 211 } 212 } 213 214 // Unwind the current frame 215 thread->pop_zero_frame(); 216 217 // Pop our local variables 218 stack->set_sp(stack->sp() + method->max_locals()); 219 220 // Push our result 221 for (int i = 0; i < result_slots; i++) { 222 // Adjust result to smaller 223 union { 224 intptr_t res; 225 jint res_jint; 226 }; 227 res = result[-i]; 228 if (result_slots == 1) { 229 BasicType t = method->result_type(); 230 if (is_subword_type(t)) { 231 res_jint = (jint)narrow(t, res_jint); 232 } 233 } 234 stack->push(res); 235 } 236 } 237 238 int CppInterpreter::native_entry(Method* method, intptr_t UNUSED, TRAPS) { 239 // Make sure method is native and not abstract 240 assert(method->is_native() && !method->is_abstract(), "should be"); 241 242 JavaThread *thread = (JavaThread *) THREAD; 243 ZeroStack *stack = thread->zero_stack(); 244 245 // Allocate and initialize our frame 246 InterpreterFrame *frame = InterpreterFrame::build(method, CHECK_0); 247 thread->push_zero_frame(frame); 248 interpreterState istate = frame->interpreter_state(); 249 intptr_t *locals = istate->locals(); 250 251 // Update the invocation counter 252 if ((UseCompiler || CountCompiledCalls) && !method->is_synchronized()) { 253 MethodCounters* mcs = method->method_counters(); 254 if (mcs == NULL) { 255 CALL_VM_NOCHECK(mcs = InterpreterRuntime::build_method_counters(thread, method)); 256 if (HAS_PENDING_EXCEPTION) 257 goto unwind_and_return; 258 } 259 InvocationCounter *counter = mcs->invocation_counter(); 260 counter->increment(); 261 if (counter->reached_InvocationLimit(mcs->backedge_counter())) { 262 CALL_VM_NOCHECK( 263 InterpreterRuntime::frequency_counter_overflow(thread, NULL)); 264 if (HAS_PENDING_EXCEPTION) 265 goto unwind_and_return; 266 } 267 } 268 269 // Lock if necessary 270 BasicObjectLock *monitor; 271 monitor = NULL; 272 if (method->is_synchronized()) { 273 monitor = (BasicObjectLock*) istate->stack_base(); 274 oop lockee = monitor->obj(); 275 markOop disp = lockee->mark()->set_unlocked(); 276 277 monitor->lock()->set_displaced_header(disp); 278 if (Atomic::cmpxchg((markOop)monitor, lockee->mark_addr(), disp) != disp) { 279 if (thread->is_lock_owned((address) disp->clear_lock_bits())) { 280 monitor->lock()->set_displaced_header(NULL); 281 } 282 else { 283 CALL_VM_NOCHECK(InterpreterRuntime::monitorenter(thread, monitor)); 284 if (HAS_PENDING_EXCEPTION) 285 goto unwind_and_return; 286 } 287 } 288 } 289 290 // Get the signature handler 291 InterpreterRuntime::SignatureHandler *handler; { 292 address handlerAddr = method->signature_handler(); 293 if (handlerAddr == NULL) { 294 CALL_VM_NOCHECK(InterpreterRuntime::prepare_native_call(thread, method)); 295 if (HAS_PENDING_EXCEPTION) 296 goto unlock_unwind_and_return; 297 298 handlerAddr = method->signature_handler(); 299 assert(handlerAddr != NULL, "eh?"); 300 } 301 if (handlerAddr == (address) InterpreterRuntime::slow_signature_handler) { 302 CALL_VM_NOCHECK(handlerAddr = 303 InterpreterRuntime::slow_signature_handler(thread, method, NULL,NULL)); 304 if (HAS_PENDING_EXCEPTION) 305 goto unlock_unwind_and_return; 306 } 307 handler = \ 308 InterpreterRuntime::SignatureHandler::from_handlerAddr(handlerAddr); 309 } 310 311 // Get the native function entry point 312 address function; 313 function = method->native_function(); 314 assert(function != NULL, "should be set if signature handler is"); 315 316 // Build the argument list 317 stack->overflow_check(handler->argument_count() * 2, THREAD); 318 if (HAS_PENDING_EXCEPTION) 319 goto unlock_unwind_and_return; 320 321 void **arguments; 322 void *mirror; { 323 arguments = 324 (void **) stack->alloc(handler->argument_count() * sizeof(void **)); 325 void **dst = arguments; 326 327 void *env = thread->jni_environment(); 328 *(dst++) = &env; 329 330 if (method->is_static()) { 331 istate->set_oop_temp( 332 method->constants()->pool_holder()->java_mirror()); 333 mirror = istate->oop_temp_addr(); 334 *(dst++) = &mirror; 335 } 336 337 intptr_t *src = locals; 338 for (int i = dst - arguments; i < handler->argument_count(); i++) { 339 ffi_type *type = handler->argument_type(i); 340 if (type == &ffi_type_pointer) { 341 if (*src) { 342 stack->push((intptr_t) src); 343 *(dst++) = stack->sp(); 344 } 345 else { 346 *(dst++) = src; 347 } 348 src--; 349 } 350 else if (type->size == 4) { 351 *(dst++) = src--; 352 } 353 else if (type->size == 8) { 354 src--; 355 *(dst++) = src--; 356 } 357 else { 358 ShouldNotReachHere(); 359 } 360 } 361 } 362 363 // Set up the Java frame anchor 364 thread->set_last_Java_frame(); 365 366 // Change the thread state to _thread_in_native 367 ThreadStateTransition::transition_from_java(thread, _thread_in_native); 368 369 // Make the call 370 intptr_t result[4 - LogBytesPerWord]; 371 ffi_call(handler->cif(), (void (*)()) function, result, arguments); 372 373 // Change the thread state back to _thread_in_Java. 374 // ThreadStateTransition::transition_from_native() cannot be used 375 // here because it does not check for asynchronous exceptions. 376 // We have to manage the transition ourself. 377 thread->set_thread_state(_thread_in_native_trans); 378 379 // Make sure new state is visible in the GC thread 380 InterfaceSupport::serialize_thread_state(thread); 381 382 // Handle safepoint operations, pending suspend requests, 383 // and pending asynchronous exceptions. 384 if (SafepointMechanism::poll(thread) || 385 thread->has_special_condition_for_native_trans()) { 386 JavaThread::check_special_condition_for_native_trans(thread); 387 CHECK_UNHANDLED_OOPS_ONLY(thread->clear_unhandled_oops()); 388 } 389 390 // Finally we can change the thread state to _thread_in_Java. 391 thread->set_thread_state(_thread_in_Java); 392 fixup_after_potential_safepoint(); 393 394 // Clear the frame anchor 395 thread->reset_last_Java_frame(); 396 397 // If the result was an oop then unbox it and store it in 398 // oop_temp where the garbage collector can see it before 399 // we release the handle it might be protected by. 400 if (handler->result_type() == &ffi_type_pointer) { 401 if (result[0] == 0) { 402 istate->set_oop_temp(NULL); 403 } else { 404 jobject handle = reinterpret_cast<jobject>(result[0]); 405 istate->set_oop_temp(JNIHandles::resolve(handle)); 406 } 407 } 408 409 // Reset handle block 410 thread->active_handles()->clear(); 411 412 unlock_unwind_and_return: 413 414 // Unlock if necessary 415 if (monitor) { 416 BasicLock *lock = monitor->lock(); 417 markOop header = lock->displaced_header(); 418 oop rcvr = monitor->obj(); 419 monitor->set_obj(NULL); 420 421 if (header != NULL) { 422 markOop old_header = markOopDesc::encode(lock); 423 if (rcvr->cas_set_mark(header, old_header) != old_header) { 424 monitor->set_obj(rcvr); { 425 HandleMark hm(thread); 426 CALL_VM_NOCHECK(InterpreterRuntime::monitorexit(thread, monitor)); 427 } 428 } 429 } 430 } 431 432 unwind_and_return: 433 434 // Unwind the current activation 435 thread->pop_zero_frame(); 436 437 // Pop our parameters 438 stack->set_sp(stack->sp() + method->size_of_parameters()); 439 440 // Push our result 441 if (!HAS_PENDING_EXCEPTION) { 442 BasicType type = method->result_type(); 443 stack->set_sp(stack->sp() - type2size[type]); 444 445 switch (type) { 446 case T_VOID: 447 break; 448 449 case T_BOOLEAN: 450 #ifndef VM_LITTLE_ENDIAN 451 result[0] <<= (BitsPerWord - BitsPerByte); 452 #endif 453 SET_LOCALS_INT(*(jboolean *) result != 0, 0); 454 break; 455 456 case T_CHAR: 457 #ifndef VM_LITTLE_ENDIAN 458 result[0] <<= (BitsPerWord - BitsPerShort); 459 #endif 460 SET_LOCALS_INT(*(jchar *) result, 0); 461 break; 462 463 case T_BYTE: 464 #ifndef VM_LITTLE_ENDIAN 465 result[0] <<= (BitsPerWord - BitsPerByte); 466 #endif 467 SET_LOCALS_INT(*(jbyte *) result, 0); 468 break; 469 470 case T_SHORT: 471 #ifndef VM_LITTLE_ENDIAN 472 result[0] <<= (BitsPerWord - BitsPerShort); 473 #endif 474 SET_LOCALS_INT(*(jshort *) result, 0); 475 break; 476 477 case T_INT: 478 #ifndef VM_LITTLE_ENDIAN 479 result[0] <<= (BitsPerWord - BitsPerInt); 480 #endif 481 SET_LOCALS_INT(*(jint *) result, 0); 482 break; 483 484 case T_LONG: 485 SET_LOCALS_LONG(*(jlong *) result, 0); 486 break; 487 488 case T_FLOAT: 489 SET_LOCALS_FLOAT(*(jfloat *) result, 0); 490 break; 491 492 case T_DOUBLE: 493 SET_LOCALS_DOUBLE(*(jdouble *) result, 0); 494 break; 495 496 case T_OBJECT: 497 case T_ARRAY: 498 SET_LOCALS_OBJECT(istate->oop_temp(), 0); 499 break; 500 501 default: 502 ShouldNotReachHere(); 503 } 504 } 505 506 // No deoptimized frames on the stack 507 return 0; 508 } 509 510 int CppInterpreter::accessor_entry(Method* method, intptr_t UNUSED, TRAPS) { 511 JavaThread *thread = (JavaThread *) THREAD; 512 ZeroStack *stack = thread->zero_stack(); 513 intptr_t *locals = stack->sp(); 514 515 // Drop into the slow path if we need a safepoint check 516 if (SafepointMechanism::poll(THREAD)) { 517 return normal_entry(method, 0, THREAD); 518 } 519 520 // Load the object pointer and drop into the slow path 521 // if we have a NullPointerException 522 oop object = LOCALS_OBJECT(0); 523 if (object == NULL) { 524 return normal_entry(method, 0, THREAD); 525 } 526 527 // Read the field index from the bytecode, which looks like this: 528 // 0: aload_0 529 // 1: getfield 530 // 2: index 531 // 3: index 532 // 4: ireturn/areturn/freturn/lreturn/dreturn 533 // NB this is not raw bytecode: index is in machine order 534 u1 *code = method->code_base(); 535 assert(code[0] == Bytecodes::_aload_0 && 536 code[1] == Bytecodes::_getfield && 537 (code[4] == Bytecodes::_ireturn || 538 code[4] == Bytecodes::_freturn || 539 code[4] == Bytecodes::_lreturn || 540 code[4] == Bytecodes::_dreturn || 541 code[4] == Bytecodes::_areturn), "should do"); 542 u2 index = Bytes::get_native_u2(&code[2]); 543 544 // Get the entry from the constant pool cache, and drop into 545 // the slow path if it has not been resolved 546 ConstantPoolCache* cache = method->constants()->cache(); 547 ConstantPoolCacheEntry* entry = cache->entry_at(index); 548 if (!entry->is_resolved(Bytecodes::_getfield)) { 549 return normal_entry(method, 0, THREAD); 550 } 551 552 // Get the result and push it onto the stack 553 switch (entry->flag_state()) { 554 case ltos: 555 case dtos: 556 stack->overflow_check(1, CHECK_0); 557 stack->alloc(wordSize); 558 break; 559 } 560 if (entry->is_volatile()) { 561 switch (entry->flag_state()) { 562 case ctos: 563 SET_LOCALS_INT(object->char_field_acquire(entry->f2_as_index()), 0); 564 break; 565 566 case btos: 567 case ztos: 568 SET_LOCALS_INT(object->byte_field_acquire(entry->f2_as_index()), 0); 569 break; 570 571 case stos: 572 SET_LOCALS_INT(object->short_field_acquire(entry->f2_as_index()), 0); 573 break; 574 575 case itos: 576 SET_LOCALS_INT(object->int_field_acquire(entry->f2_as_index()), 0); 577 break; 578 579 case ltos: 580 SET_LOCALS_LONG(object->long_field_acquire(entry->f2_as_index()), 0); 581 break; 582 583 case ftos: 584 SET_LOCALS_FLOAT(object->float_field_acquire(entry->f2_as_index()), 0); 585 break; 586 587 case dtos: 588 SET_LOCALS_DOUBLE(object->double_field_acquire(entry->f2_as_index()), 0); 589 break; 590 591 case atos: 592 SET_LOCALS_OBJECT(object->obj_field_acquire(entry->f2_as_index()), 0); 593 break; 594 595 default: 596 ShouldNotReachHere(); 597 } 598 } 599 else { 600 switch (entry->flag_state()) { 601 case ctos: 602 SET_LOCALS_INT(object->char_field(entry->f2_as_index()), 0); 603 break; 604 605 case btos: 606 case ztos: 607 SET_LOCALS_INT(object->byte_field(entry->f2_as_index()), 0); 608 break; 609 610 case stos: 611 SET_LOCALS_INT(object->short_field(entry->f2_as_index()), 0); 612 break; 613 614 case itos: 615 SET_LOCALS_INT(object->int_field(entry->f2_as_index()), 0); 616 break; 617 618 case ltos: 619 SET_LOCALS_LONG(object->long_field(entry->f2_as_index()), 0); 620 break; 621 622 case ftos: 623 SET_LOCALS_FLOAT(object->float_field(entry->f2_as_index()), 0); 624 break; 625 626 case dtos: 627 SET_LOCALS_DOUBLE(object->double_field(entry->f2_as_index()), 0); 628 break; 629 630 case atos: 631 SET_LOCALS_OBJECT(object->obj_field(entry->f2_as_index()), 0); 632 break; 633 634 default: 635 ShouldNotReachHere(); 636 } 637 } 638 639 // No deoptimized frames on the stack 640 return 0; 641 } 642 643 int CppInterpreter::empty_entry(Method* method, intptr_t UNUSED, TRAPS) { 644 JavaThread *thread = (JavaThread *) THREAD; 645 ZeroStack *stack = thread->zero_stack(); 646 647 // Drop into the slow path if we need a safepoint check 648 if (SafepointMechanism::poll(THREAD)) { 649 return normal_entry(method, 0, THREAD); 650 } 651 652 // Pop our parameters 653 stack->set_sp(stack->sp() + method->size_of_parameters()); 654 655 // No deoptimized frames on the stack 656 return 0; 657 } 658 659 // The new slots will be inserted before slot insert_before. 660 // Slots < insert_before will have the same slot number after the insert. 661 // Slots >= insert_before will become old_slot + num_slots. 662 void CppInterpreter::insert_vmslots(int insert_before, int num_slots, TRAPS) { 663 JavaThread *thread = (JavaThread *) THREAD; 664 ZeroStack *stack = thread->zero_stack(); 665 666 // Allocate the space 667 stack->overflow_check(num_slots, CHECK); 668 stack->alloc(num_slots * wordSize); 669 intptr_t *vmslots = stack->sp(); 670 671 // Shuffle everything up 672 for (int i = 0; i < insert_before; i++) 673 SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i + num_slots), i); 674 } 675 676 void CppInterpreter::remove_vmslots(int first_slot, int num_slots, TRAPS) { 677 JavaThread *thread = (JavaThread *) THREAD; 678 ZeroStack *stack = thread->zero_stack(); 679 intptr_t *vmslots = stack->sp(); 680 681 // Move everything down 682 for (int i = first_slot - 1; i >= 0; i--) 683 SET_VMSLOTS_SLOT(VMSLOTS_SLOT(i), i + num_slots); 684 685 // Deallocate the space 686 stack->set_sp(stack->sp() + num_slots); 687 } 688 689 BasicType CppInterpreter::result_type_of_handle(oop method_handle) { 690 oop method_type = java_lang_invoke_MethodHandle::type(method_handle); 691 oop return_type = java_lang_invoke_MethodType::rtype(method_type); 692 return java_lang_Class::as_BasicType(return_type, (Klass* *) NULL); 693 } 694 695 intptr_t* CppInterpreter::calculate_unwind_sp(ZeroStack* stack, 696 oop method_handle) { 697 oop method_type = java_lang_invoke_MethodHandle::type(method_handle); 698 int argument_slots = java_lang_invoke_MethodType::ptype_slot_count(method_type); 699 700 return stack->sp() + argument_slots; 701 } 702 703 IRT_ENTRY(void, CppInterpreter::throw_exception(JavaThread* thread, 704 Symbol* name, 705 char* message)) 706 THROW_MSG(name, message); 707 IRT_END 708 709 InterpreterFrame *InterpreterFrame::build(Method* const method, TRAPS) { 710 JavaThread *thread = (JavaThread *) THREAD; 711 ZeroStack *stack = thread->zero_stack(); 712 713 // Calculate the size of the frame we'll build, including 714 // any adjustments to the caller's frame that we'll make. 715 int extra_locals = 0; 716 int monitor_words = 0; 717 int stack_words = 0; 718 719 if (!method->is_native()) { 720 extra_locals = method->max_locals() - method->size_of_parameters(); 721 stack_words = method->max_stack(); 722 } 723 if (method->is_synchronized()) { 724 monitor_words = frame::interpreter_frame_monitor_size(); 725 } 726 stack->overflow_check( 727 extra_locals + header_words + monitor_words + stack_words, CHECK_NULL); 728 729 // Adjust the caller's stack frame to accomodate any additional 730 // local variables we have contiguously with our parameters. 731 for (int i = 0; i < extra_locals; i++) 732 stack->push(0); 733 734 intptr_t *locals; 735 if (method->is_native()) 736 locals = stack->sp() + (method->size_of_parameters() - 1); 737 else 738 locals = stack->sp() + (method->max_locals() - 1); 739 740 stack->push(0); // next_frame, filled in later 741 intptr_t *fp = stack->sp(); 742 assert(fp - stack->sp() == next_frame_off, "should be"); 743 744 stack->push(INTERPRETER_FRAME); 745 assert(fp - stack->sp() == frame_type_off, "should be"); 746 747 interpreterState istate = 748 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); 749 assert(fp - stack->sp() == istate_off, "should be"); 750 751 istate->set_locals(locals); 752 istate->set_method(method); 753 istate->set_mirror(method->method_holder()->java_mirror()); 754 istate->set_self_link(istate); 755 istate->set_prev_link(NULL); 756 istate->set_thread(thread); 757 istate->set_bcp(method->is_native() ? NULL : method->code_base()); 758 istate->set_constants(method->constants()->cache()); 759 istate->set_msg(BytecodeInterpreter::method_entry); 760 istate->set_oop_temp(NULL); 761 istate->set_mdx(NULL); 762 istate->set_callee(NULL); 763 764 istate->set_monitor_base((BasicObjectLock *) stack->sp()); 765 if (method->is_synchronized()) { 766 BasicObjectLock *monitor = 767 (BasicObjectLock *) stack->alloc(monitor_words * wordSize); 768 oop object; 769 if (method->is_static()) 770 object = method->constants()->pool_holder()->java_mirror(); 771 else 772 object = (oop) (void*)locals[0]; 773 monitor->set_obj(object); 774 } 775 776 istate->set_stack_base(stack->sp()); 777 istate->set_stack(stack->sp() - 1); 778 if (stack_words) 779 stack->alloc(stack_words * wordSize); 780 istate->set_stack_limit(stack->sp() - 1); 781 782 return (InterpreterFrame *) fp; 783 } 784 785 InterpreterFrame *InterpreterFrame::build(int size, TRAPS) { 786 ZeroStack *stack = ((JavaThread *) THREAD)->zero_stack(); 787 788 int size_in_words = size >> LogBytesPerWord; 789 assert(size_in_words * wordSize == size, "unaligned"); 790 assert(size_in_words >= header_words, "too small"); 791 stack->overflow_check(size_in_words, CHECK_NULL); 792 793 stack->push(0); // next_frame, filled in later 794 intptr_t *fp = stack->sp(); 795 assert(fp - stack->sp() == next_frame_off, "should be"); 796 797 stack->push(INTERPRETER_FRAME); 798 assert(fp - stack->sp() == frame_type_off, "should be"); 799 800 interpreterState istate = 801 (interpreterState) stack->alloc(sizeof(BytecodeInterpreter)); 802 assert(fp - stack->sp() == istate_off, "should be"); 803 istate->set_self_link(NULL); // mark invalid 804 805 stack->alloc((size_in_words - header_words) * wordSize); 806 807 return (InterpreterFrame *) fp; 808 } 809 810 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) { 811 ShouldNotCallThis(); 812 return NULL; 813 } 814 815 address CppInterpreter::deopt_entry(TosState state, int length) { 816 return NULL; 817 } 818 819 // Helper for figuring out if frames are interpreter frames 820 821 bool CppInterpreter::contains(address pc) { 822 return false; // make frame::print_value_on work 823 } 824 #endif // CC_INTERP