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 #ifndef SHARE_RUNTIME_SHAREDRUNTIME_HPP
26 #define SHARE_RUNTIME_SHAREDRUNTIME_HPP
27
28 #include "code/codeBlob.hpp"
29 #include "code/vmreg.hpp"
30 #include "interpreter/linkResolver.hpp"
31 #include "memory/allStatic.hpp"
32 #include "memory/resourceArea.hpp"
33 #include "utilities/macros.hpp"
34
35 class AdapterHandlerEntry;
36 class AdapterFingerPrint;
37 class vframeStream;
38
39 // Runtime is the base class for various runtime interfaces
40 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
41 // shared functionality such as exception forwarding (C++ to
42 // Java exceptions), locking/unlocking mechanisms, statistical
43 // information, etc.
44
45 class SharedRuntime: AllStatic {
46 friend class VMStructs;
47
48 private:
49 // Shared stub locations
50
51 static RuntimeStub* _wrong_method_blob;
52 static RuntimeStub* _wrong_method_abstract_blob;
53 static RuntimeStub* _ic_miss_blob;
54 static RuntimeStub* _resolve_opt_virtual_call_blob;
55 static RuntimeStub* _resolve_virtual_call_blob;
56 static RuntimeStub* _resolve_static_call_blob;
57
324 // on top of the stack.
325 // The caller (or one of its callers) must use a ResourceMark
326 // in order to correctly free the result.
327 //
328 static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
329
330 // Fill in the "X cannot be cast to a Y" message for ClassCastException
331 //
332 // @param caster_klass the class of the object we are casting
333 // @param target_klass the target klass attempt
334 // @return the dynamically allocated exception message (must be freed
335 // by the caller using a resource mark)
336 //
337 // This version does not require access the frame, so it can be called
338 // from interpreted code
339 // The caller (or one of it's callers) must use a ResourceMark
340 // in order to correctly free the result.
341 //
342 static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = nullptr);
343
344 // Resolves a call site- may patch in the destination of the call into the
345 // compiled code.
346 static methodHandle resolve_helper(bool is_virtual, bool is_optimized, TRAPS);
347
348 private:
349 // deopt blob
350 static void generate_deopt_blob(void);
351
352 static bool handle_ic_miss_helper_internal(Handle receiver, nmethod* caller_nm, const frame& caller_frame,
353 methodHandle callee_method, Bytecodes::Code bc, CallInfo& call_info,
354 bool& needs_ic_stub_refill, TRAPS);
355
356 public:
357 static DeoptimizationBlob* deopt_blob(void) { return _deopt_blob; }
358
359 // Resets a call-site in compiled code so it will get resolved again.
360 static methodHandle reresolve_call_site(TRAPS);
361
362 // In the code prolog, if the klass comparison fails, the inline cache
363 // misses and the call site is patched to megamorphic
364 static methodHandle handle_ic_miss_helper(TRAPS);
365
366 // Find the method that called us.
367 static methodHandle find_callee_method(TRAPS);
368
369 static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
370
371 static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
372
373 // Issue UL warning for unlocked JNI monitor on virtual thread termination
374 static void log_jni_monitor_still_held();
375
376 private:
377 static Handle find_callee_info(Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
378 static Handle find_callee_info_helper(vframeStream& vfst, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
379
380 static Method* extract_attached_method(vframeStream& vfst);
381
382 #if defined(X86) && defined(COMPILER1)
383 // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available.
384 static void inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result);
385 #endif // X86 && COMPILER1
386
387 public:
388
389 // Read the array of BasicTypes from a Java signature, and compute where
390 // compiled Java code would like to put the results. Values in reg_lo and
391 // reg_hi refer to 4-byte quantities. Values less than SharedInfo::stack0 are
392 // registers, those above refer to 4-byte stack slots. All stack slots are
393 // based off of the window top. SharedInfo::stack0 refers to the first usable
394 // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word
395 // 4-bytes higher.
396 // return value is the maximum number of VMReg stack slots the convention will use.
397 static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
398
399 static void check_member_name_argument_is_last_argument(const methodHandle& method,
400 const BasicType* sig_bt,
401 const VMRegPair* regs) NOT_DEBUG_RETURN;
402
403 // Ditto except for calling C
404 //
405 // C argument in register AND stack slot.
406 // Some architectures require that an argument must be passed in a register
407 // AND in a stack slot. These architectures provide a second VMRegPair array
408 // to be filled by the c_calling_convention method. On other architectures,
409 // null is being passed as the second VMRegPair array, so arguments are either
410 // passed in a register OR in a stack slot.
411 static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed);
412
413 static int vector_calling_convention(VMRegPair *regs,
414 uint num_bits,
415 uint total_args_passed);
416
417 // Generate I2C and C2I adapters. These adapters are simple argument marshalling
424 // by the time we reach the blob there is compiled code available. This allows
425 // the blob to pass the incoming stack pointer (the sender sp) in a known
426 // location for the interpreter to record. This is used by the frame code
427 // to correct the sender code to match up with the stack pointer when the
428 // thread left the compiled code. In addition it allows the interpreter
429 // to remove the space the c2i adapter allocated to do its argument conversion.
430
431 // Although a c2i blob will always run interpreted even if compiled code is
432 // present if we see that compiled code is present the compiled call site
433 // will be patched/re-resolved so that later calls will run compiled.
434
435 // Additionally a c2i blob need to have a unverified entry because it can be reached
436 // in situations where the call site is an inlined cache site and may go megamorphic.
437
438 // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
439 // that the interpreter before it does any call dispatch will record the current
440 // stack pointer in the interpreter frame. On return it will restore the stack
441 // pointer as needed. This means the i2c adapter code doesn't need any special
442 // handshaking path with compiled code to keep the stack walking correct.
443
444 static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *_masm,
445 int total_args_passed,
446 int max_arg,
447 const BasicType *sig_bt,
448 const VMRegPair *regs,
449 AdapterFingerPrint* fingerprint);
450
451 static void gen_i2c_adapter(MacroAssembler *_masm,
452 int total_args_passed,
453 int comp_args_on_stack,
454 const BasicType *sig_bt,
455 const VMRegPair *regs);
456
457 // OSR support
458
459 // OSR_migration_begin will extract the jvm state from an interpreter
460 // frame (locals, monitors) and store the data in a piece of C heap
461 // storage. This then allows the interpreter frame to be removed from the
462 // stack and the OSR nmethod to be called. That method is called with a
463 // pointer to the C heap storage. This pointer is the return value from
464 // OSR_migration_begin.
465
466 static intptr_t* OSR_migration_begin(JavaThread *thread);
467
468 // OSR_migration_end is a trivial routine. It is called after the compiled
469 // method has extracted the jvm state from the C heap that OSR_migration_begin
470 // created. It's entire job is to simply free this storage.
471 static void OSR_migration_end(intptr_t* buf);
472
473 // Convert a sig into a calling convention register layout
474 // and find interesting things about it.
503 //
504 // The wrapper may contain special-case code if the given method
505 // is a compiled method handle adapter, such as _invokeBasic, _linkToVirtual, etc.
506 static nmethod* generate_native_wrapper(MacroAssembler* masm,
507 const methodHandle& method,
508 int compile_id,
509 BasicType* sig_bt,
510 VMRegPair* regs,
511 BasicType ret_type);
512
513 // A compiled caller has just called the interpreter, but compiled code
514 // exists. Patch the caller so he no longer calls into the interpreter.
515 static void fixup_callers_callsite(Method* moop, address ret_pc);
516 static bool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
517
518 // Slow-path Locking and Unlocking
519 static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
520 static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
521
522 // Resolving of calls
523 static address get_resolved_entry (JavaThread* current, methodHandle callee_method);
524 static address resolve_static_call_C (JavaThread* current);
525 static address resolve_virtual_call_C (JavaThread* current);
526 static address resolve_opt_virtual_call_C(JavaThread* current);
527
528 // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.)
529 static void slow_arraycopy_C(oopDesc* src, jint src_pos,
530 oopDesc* dest, jint dest_pos,
531 jint length, JavaThread* thread);
532
533 // handle ic miss with caller being compiled code
534 // wrong method handling (inline cache misses)
535 static address handle_wrong_method(JavaThread* current);
536 static address handle_wrong_method_abstract(JavaThread* current);
537 static address handle_wrong_method_ic_miss(JavaThread* current);
538
539 static address handle_unsafe_access(JavaThread* thread, address next_pc);
540
541 #ifndef PRODUCT
542
543 // Collect and print inline cache miss statistics
544 private:
545 enum { maxICmiss_count = 100 };
546 static int _ICmiss_index; // length of IC miss histogram
547 static int _ICmiss_count[maxICmiss_count]; // miss counts
548 static address _ICmiss_at[maxICmiss_count]; // miss addresses
549 static void trace_ic_miss(address at);
550
551 public:
552 static uint _ic_miss_ctr; // total # of IC misses
553 static uint _wrong_method_ctr;
554 static uint _resolve_static_ctr;
555 static uint _resolve_virtual_ctr;
556 static uint _resolve_opt_virtual_ctr;
557 static uint _implicit_null_throws;
558 static uint _implicit_div0_throws;
559
560 static uint _jbyte_array_copy_ctr; // Slow-path byte array copy
629 // Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been
630 // setup. Compiled frames are fixed-size and the args are likely not in the
631 // right place. Hence all the args will likely be copied into the
632 // interpreter's frame, forcing that frame to grow. The compiled frame's
633 // outgoing stack args will be dead after the copy.
634 //
635 // Native wrappers, like adapters, marshal arguments. Unlike adapters they
636 // also perform an official frame push & pop. They have a call to the native
637 // routine in their middles and end in a return (instead of ending in a jump).
638 // The native wrappers are stored in real nmethods instead of the BufferBlobs
639 // used by the adapters. The code generation happens here because it's very
640 // similar to what the adapters have to do.
641
642 class AdapterHandlerEntry : public CHeapObj<mtCode> {
643 friend class AdapterHandlerLibrary;
644
645 private:
646 AdapterFingerPrint* _fingerprint;
647 address _i2c_entry;
648 address _c2i_entry;
649 address _c2i_unverified_entry;
650 address _c2i_no_clinit_check_entry;
651
652 #ifdef ASSERT
653 // Captures code and signature used to generate this adapter when
654 // verifying adapter equivalence.
655 unsigned char* _saved_code;
656 int _saved_code_length;
657 #endif
658
659 AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
660 address c2i_unverified_entry,
661 address c2i_no_clinit_check_entry) :
662 _fingerprint(fingerprint),
663 _i2c_entry(i2c_entry),
664 _c2i_entry(c2i_entry),
665 _c2i_unverified_entry(c2i_unverified_entry),
666 _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry)
667 #ifdef ASSERT
668 , _saved_code_length(0)
669 #endif
670 { }
671
672 ~AdapterHandlerEntry();
673
674 public:
675 address get_i2c_entry() const { return _i2c_entry; }
676 address get_c2i_entry() const { return _c2i_entry; }
677 address get_c2i_unverified_entry() const { return _c2i_unverified_entry; }
678 address get_c2i_no_clinit_check_entry() const { return _c2i_no_clinit_check_entry; }
679
680 address base_address();
681 void relocate(address new_base);
682
683 AdapterFingerPrint* fingerprint() const { return _fingerprint; }
684
685 #ifdef ASSERT
686 // Used to verify that code generated for shared adapters is equivalent
687 void save_code (unsigned char* code, int length);
688 bool compare_code(AdapterHandlerEntry* other);
689 #endif
690
691 //virtual void print_on(outputStream* st) const; DO NOT USE
692 void print_adapter_on(outputStream* st) const;
693 };
694
695 class AdapterHandlerLibrary: public AllStatic {
696 friend class SharedRuntime;
697 private:
698 static BufferBlob* _buffer; // the temporary code buffer in CodeCache
699 static AdapterHandlerEntry* _abstract_method_handler;
700 static AdapterHandlerEntry* _no_arg_handler;
701 static AdapterHandlerEntry* _int_arg_handler;
702 static AdapterHandlerEntry* _obj_arg_handler;
703 static AdapterHandlerEntry* _obj_int_arg_handler;
704 static AdapterHandlerEntry* _obj_obj_arg_handler;
705
706 static BufferBlob* buffer_blob();
707 static void initialize();
708 static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
709 int total_args_passed,
710 BasicType* sig_bt,
711 bool allocate_code_blob);
712 static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
713 public:
714
715 static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
716 address i2c_entry,
717 address c2i_entry,
718 address c2i_unverified_entry,
719 address c2i_no_clinit_check_entry = nullptr);
720 static void create_native_wrapper(const methodHandle& method);
721 static AdapterHandlerEntry* get_adapter(const methodHandle& method);
722
723 static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
724 static void print_handler_on(outputStream* st, const CodeBlob* b);
725 static bool contains(const CodeBlob* b);
726 #ifndef PRODUCT
727 static void print_statistics();
728 #endif // PRODUCT
729
730 };
731
732 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
|
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 #ifndef SHARE_RUNTIME_SHAREDRUNTIME_HPP
26 #define SHARE_RUNTIME_SHAREDRUNTIME_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "code/codeBlob.hpp"
30 #include "code/vmreg.hpp"
31 #include "interpreter/linkResolver.hpp"
32 #include "memory/allStatic.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "runtime/signature.hpp"
35 #include "utilities/macros.hpp"
36
37 class AdapterHandlerEntry;
38 class AdapterFingerPrint;
39 class vframeStream;
40 class SigEntry;
41
42 // Runtime is the base class for various runtime interfaces
43 // (InterpreterRuntime, CompilerRuntime, etc.). It provides
44 // shared functionality such as exception forwarding (C++ to
45 // Java exceptions), locking/unlocking mechanisms, statistical
46 // information, etc.
47
48 class SharedRuntime: AllStatic {
49 friend class VMStructs;
50
51 private:
52 // Shared stub locations
53
54 static RuntimeStub* _wrong_method_blob;
55 static RuntimeStub* _wrong_method_abstract_blob;
56 static RuntimeStub* _ic_miss_blob;
57 static RuntimeStub* _resolve_opt_virtual_call_blob;
58 static RuntimeStub* _resolve_virtual_call_blob;
59 static RuntimeStub* _resolve_static_call_blob;
60
327 // on top of the stack.
328 // The caller (or one of its callers) must use a ResourceMark
329 // in order to correctly free the result.
330 //
331 static char* generate_class_cast_message(JavaThread* thr, Klass* caster_klass);
332
333 // Fill in the "X cannot be cast to a Y" message for ClassCastException
334 //
335 // @param caster_klass the class of the object we are casting
336 // @param target_klass the target klass attempt
337 // @return the dynamically allocated exception message (must be freed
338 // by the caller using a resource mark)
339 //
340 // This version does not require access the frame, so it can be called
341 // from interpreted code
342 // The caller (or one of it's callers) must use a ResourceMark
343 // in order to correctly free the result.
344 //
345 static char* generate_class_cast_message(Klass* caster_klass, Klass* target_klass, Symbol* target_klass_name = nullptr);
346
347 static char* generate_identity_exception_message(JavaThread* thr, Klass* klass);
348
349 // Resolves a call site- may patch in the destination of the call into the
350 // compiled code.
351 static methodHandle resolve_helper(bool is_virtual, bool is_optimized, bool& caller_is_c1, TRAPS);
352
353 private:
354 // deopt blob
355 static void generate_deopt_blob(void);
356
357 static bool handle_ic_miss_helper_internal(Handle receiver, nmethod* caller_nm, const frame& caller_frame,
358 methodHandle callee_method, Bytecodes::Code bc, CallInfo& call_info,
359 bool& needs_ic_stub_refill, bool& is_optimized, bool caller_is_c1, TRAPS);
360
361 public:
362 static DeoptimizationBlob* deopt_blob(void) { return _deopt_blob; }
363
364 // Resets a call-site in compiled code so it will get resolved again.
365 static methodHandle reresolve_call_site(bool& is_static_call, bool& is_optimized, bool& caller_is_c1, TRAPS);
366
367 // In the code prolog, if the klass comparison fails, the inline cache
368 // misses and the call site is patched to megamorphic
369 static methodHandle handle_ic_miss_helper(bool& is_optimized, bool& caller_is_c1, TRAPS);
370
371 // Find the method that called us.
372 static methodHandle find_callee_method(bool is_optimized, bool& caller_is_c1, TRAPS);
373
374 static void monitor_enter_helper(oopDesc* obj, BasicLock* lock, JavaThread* thread);
375
376 static void monitor_exit_helper(oopDesc* obj, BasicLock* lock, JavaThread* current);
377
378 // Issue UL warning for unlocked JNI monitor on virtual thread termination
379 static void log_jni_monitor_still_held();
380
381 private:
382 static Handle find_callee_info(Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
383 static Handle find_callee_info_helper(vframeStream& vfst, Bytecodes::Code& bc, CallInfo& callinfo, TRAPS);
384
385 static Method* extract_attached_method(vframeStream& vfst);
386
387 #if defined(X86) && defined(COMPILER1)
388 // For Object.hashCode, System.identityHashCode try to pull hashCode from object header if available.
389 static void inline_check_hashcode_from_object_header(MacroAssembler* masm, const methodHandle& method, Register obj_reg, Register result);
390 #endif // X86 && COMPILER1
391
392 public:
393
394 // Read the array of BasicTypes from a Java signature, and compute where
395 // compiled Java code would like to put the results. Values in reg_lo and
396 // reg_hi refer to 4-byte quantities. Values less than SharedInfo::stack0 are
397 // registers, those above refer to 4-byte stack slots. All stack slots are
398 // based off of the window top. SharedInfo::stack0 refers to the first usable
399 // slot in the bottom of the frame. SharedInfo::stack0+1 refers to the memory word
400 // 4-bytes higher.
401 // return value is the maximum number of VMReg stack slots the convention will use.
402 static int java_calling_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
403 static int java_calling_convention(const GrowableArray<SigEntry>* sig, VMRegPair* regs) {
404 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sig->length());
405 int total_args_passed = SigEntry::fill_sig_bt(sig, sig_bt);
406 return java_calling_convention(sig_bt, regs, total_args_passed);
407 }
408 static int java_return_convention(const BasicType* sig_bt, VMRegPair* regs, int total_args_passed);
409 static const uint java_return_convention_max_int;
410 static const uint java_return_convention_max_float;
411
412 static void check_member_name_argument_is_last_argument(const methodHandle& method,
413 const BasicType* sig_bt,
414 const VMRegPair* regs) NOT_DEBUG_RETURN;
415
416 // Ditto except for calling C
417 //
418 // C argument in register AND stack slot.
419 // Some architectures require that an argument must be passed in a register
420 // AND in a stack slot. These architectures provide a second VMRegPair array
421 // to be filled by the c_calling_convention method. On other architectures,
422 // null is being passed as the second VMRegPair array, so arguments are either
423 // passed in a register OR in a stack slot.
424 static int c_calling_convention(const BasicType *sig_bt, VMRegPair *regs, int total_args_passed);
425
426 static int vector_calling_convention(VMRegPair *regs,
427 uint num_bits,
428 uint total_args_passed);
429
430 // Generate I2C and C2I adapters. These adapters are simple argument marshalling
437 // by the time we reach the blob there is compiled code available. This allows
438 // the blob to pass the incoming stack pointer (the sender sp) in a known
439 // location for the interpreter to record. This is used by the frame code
440 // to correct the sender code to match up with the stack pointer when the
441 // thread left the compiled code. In addition it allows the interpreter
442 // to remove the space the c2i adapter allocated to do its argument conversion.
443
444 // Although a c2i blob will always run interpreted even if compiled code is
445 // present if we see that compiled code is present the compiled call site
446 // will be patched/re-resolved so that later calls will run compiled.
447
448 // Additionally a c2i blob need to have a unverified entry because it can be reached
449 // in situations where the call site is an inlined cache site and may go megamorphic.
450
451 // A i2c adapter is simpler than the c2i adapter. This is because it is assumed
452 // that the interpreter before it does any call dispatch will record the current
453 // stack pointer in the interpreter frame. On return it will restore the stack
454 // pointer as needed. This means the i2c adapter code doesn't need any special
455 // handshaking path with compiled code to keep the stack walking correct.
456
457 static AdapterHandlerEntry* generate_i2c2i_adapters(MacroAssembler *masm,
458 int comp_args_on_stack,
459 const GrowableArray<SigEntry>* sig,
460 const VMRegPair* regs,
461 const GrowableArray<SigEntry>* sig_cc,
462 const VMRegPair* regs_cc,
463 const GrowableArray<SigEntry>* sig_cc_ro,
464 const VMRegPair* regs_cc_ro,
465 AdapterFingerPrint* fingerprint,
466 AdapterBlob*& new_adapter,
467 bool allocate_code_blob);
468
469 static void gen_i2c_adapter(MacroAssembler *_masm,
470 int comp_args_on_stack,
471 const GrowableArray<SigEntry>* sig,
472 const VMRegPair *regs);
473
474 // OSR support
475
476 // OSR_migration_begin will extract the jvm state from an interpreter
477 // frame (locals, monitors) and store the data in a piece of C heap
478 // storage. This then allows the interpreter frame to be removed from the
479 // stack and the OSR nmethod to be called. That method is called with a
480 // pointer to the C heap storage. This pointer is the return value from
481 // OSR_migration_begin.
482
483 static intptr_t* OSR_migration_begin(JavaThread *thread);
484
485 // OSR_migration_end is a trivial routine. It is called after the compiled
486 // method has extracted the jvm state from the C heap that OSR_migration_begin
487 // created. It's entire job is to simply free this storage.
488 static void OSR_migration_end(intptr_t* buf);
489
490 // Convert a sig into a calling convention register layout
491 // and find interesting things about it.
520 //
521 // The wrapper may contain special-case code if the given method
522 // is a compiled method handle adapter, such as _invokeBasic, _linkToVirtual, etc.
523 static nmethod* generate_native_wrapper(MacroAssembler* masm,
524 const methodHandle& method,
525 int compile_id,
526 BasicType* sig_bt,
527 VMRegPair* regs,
528 BasicType ret_type);
529
530 // A compiled caller has just called the interpreter, but compiled code
531 // exists. Patch the caller so he no longer calls into the interpreter.
532 static void fixup_callers_callsite(Method* moop, address ret_pc);
533 static bool should_fixup_call_destination(address destination, address entry_point, address caller_pc, Method* moop, CodeBlob* cb);
534
535 // Slow-path Locking and Unlocking
536 static void complete_monitor_locking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
537 static void complete_monitor_unlocking_C(oopDesc* obj, BasicLock* lock, JavaThread* current);
538
539 // Resolving of calls
540 static address get_resolved_entry (JavaThread* current, methodHandle callee_method,
541 bool is_static_call, bool is_optimized, bool caller_is_c1);
542 static address resolve_static_call_C (JavaThread* current);
543 static address resolve_virtual_call_C (JavaThread* current);
544 static address resolve_opt_virtual_call_C(JavaThread* current);
545
546 static void load_inline_type_fields_in_regs(JavaThread* current, oopDesc* res);
547 static void store_inline_type_fields_to_buf(JavaThread* current, intptr_t res);
548
549 // arraycopy, the non-leaf version. (See StubRoutines for all the leaf calls.)
550 static void slow_arraycopy_C(oopDesc* src, jint src_pos,
551 oopDesc* dest, jint dest_pos,
552 jint length, JavaThread* thread);
553
554 // handle ic miss with caller being compiled code
555 // wrong method handling (inline cache misses)
556 static address handle_wrong_method(JavaThread* current);
557 static address handle_wrong_method_abstract(JavaThread* current);
558 static address handle_wrong_method_ic_miss(JavaThread* current);
559 static void allocate_inline_types(JavaThread* current, Method* callee, bool allocate_receiver);
560 static oop allocate_inline_types_impl(JavaThread* current, methodHandle callee, bool allocate_receiver, TRAPS);
561
562 static address handle_unsafe_access(JavaThread* thread, address next_pc);
563
564 static BufferedInlineTypeBlob* generate_buffered_inline_type_adapter(const InlineKlass* vk);
565 #ifndef PRODUCT
566
567 // Collect and print inline cache miss statistics
568 private:
569 enum { maxICmiss_count = 100 };
570 static int _ICmiss_index; // length of IC miss histogram
571 static int _ICmiss_count[maxICmiss_count]; // miss counts
572 static address _ICmiss_at[maxICmiss_count]; // miss addresses
573 static void trace_ic_miss(address at);
574
575 public:
576 static uint _ic_miss_ctr; // total # of IC misses
577 static uint _wrong_method_ctr;
578 static uint _resolve_static_ctr;
579 static uint _resolve_virtual_ctr;
580 static uint _resolve_opt_virtual_ctr;
581 static uint _implicit_null_throws;
582 static uint _implicit_div0_throws;
583
584 static uint _jbyte_array_copy_ctr; // Slow-path byte array copy
653 // Rmethod->_i2i_entry. On entry, the interpreted frame has not yet been
654 // setup. Compiled frames are fixed-size and the args are likely not in the
655 // right place. Hence all the args will likely be copied into the
656 // interpreter's frame, forcing that frame to grow. The compiled frame's
657 // outgoing stack args will be dead after the copy.
658 //
659 // Native wrappers, like adapters, marshal arguments. Unlike adapters they
660 // also perform an official frame push & pop. They have a call to the native
661 // routine in their middles and end in a return (instead of ending in a jump).
662 // The native wrappers are stored in real nmethods instead of the BufferBlobs
663 // used by the adapters. The code generation happens here because it's very
664 // similar to what the adapters have to do.
665
666 class AdapterHandlerEntry : public CHeapObj<mtCode> {
667 friend class AdapterHandlerLibrary;
668
669 private:
670 AdapterFingerPrint* _fingerprint;
671 address _i2c_entry;
672 address _c2i_entry;
673 address _c2i_inline_entry;
674 address _c2i_inline_ro_entry;
675 address _c2i_unverified_entry;
676 address _c2i_unverified_inline_entry;
677 address _c2i_no_clinit_check_entry;
678
679 // Support for scalarized inline type calling convention
680 const GrowableArray<SigEntry>* _sig_cc;
681
682 #ifdef ASSERT
683 // Captures code and signature used to generate this adapter when
684 // verifying adapter equivalence.
685 unsigned char* _saved_code;
686 int _saved_code_length;
687 #endif
688
689 AdapterHandlerEntry(AdapterFingerPrint* fingerprint, address i2c_entry, address c2i_entry,
690 address c2i_inline_entry, address c2i_inline_ro_entry,
691 address c2i_unverified_entry, address c2i_unverified_inline_entry,
692 address c2i_no_clinit_check_entry) :
693 _fingerprint(fingerprint),
694 _i2c_entry(i2c_entry),
695 _c2i_entry(c2i_entry),
696 _c2i_inline_entry(c2i_inline_entry),
697 _c2i_inline_ro_entry(c2i_inline_ro_entry),
698 _c2i_unverified_entry(c2i_unverified_entry),
699 _c2i_unverified_inline_entry(c2i_unverified_inline_entry),
700 _c2i_no_clinit_check_entry(c2i_no_clinit_check_entry),
701 _sig_cc(nullptr)
702 #ifdef ASSERT
703 , _saved_code_length(0)
704 #endif
705 { }
706
707 ~AdapterHandlerEntry();
708
709 public:
710 address get_i2c_entry() const { return _i2c_entry; }
711 address get_c2i_entry() const { return _c2i_entry; }
712 address get_c2i_inline_entry() const { return _c2i_inline_entry; }
713 address get_c2i_inline_ro_entry() const { return _c2i_inline_ro_entry; }
714 address get_c2i_unverified_entry() const { return _c2i_unverified_entry; }
715 address get_c2i_unverified_inline_entry() const { return _c2i_unverified_inline_entry; }
716 address get_c2i_no_clinit_check_entry() const { return _c2i_no_clinit_check_entry; }
717
718 address base_address();
719 void relocate(address new_base);
720
721 // Support for scalarized inline type calling convention
722 void set_sig_cc(const GrowableArray<SigEntry>* sig) { _sig_cc = sig; }
723 const GrowableArray<SigEntry>* get_sig_cc() const { return _sig_cc; }
724
725 AdapterFingerPrint* fingerprint() const { return _fingerprint; }
726
727 #ifdef ASSERT
728 // Used to verify that code generated for shared adapters is equivalent
729 void save_code (unsigned char* code, int length);
730 bool compare_code(AdapterHandlerEntry* other);
731 #endif
732
733 //virtual void print_on(outputStream* st) const; DO NOT USE
734 void print_adapter_on(outputStream* st) const;
735 };
736
737 class CompiledEntrySignature;
738
739 class AdapterHandlerLibrary: public AllStatic {
740 friend class SharedRuntime;
741 private:
742 static BufferBlob* _buffer; // the temporary code buffer in CodeCache
743 static AdapterHandlerEntry* _abstract_method_handler;
744 static AdapterHandlerEntry* _no_arg_handler;
745 static AdapterHandlerEntry* _int_arg_handler;
746 static AdapterHandlerEntry* _obj_arg_handler;
747 static AdapterHandlerEntry* _obj_int_arg_handler;
748 static AdapterHandlerEntry* _obj_obj_arg_handler;
749
750 static BufferBlob* buffer_blob();
751 static void initialize();
752 static AdapterHandlerEntry* create_adapter(AdapterBlob*& new_adapter,
753 CompiledEntrySignature& ces,
754 bool allocate_code_blob);
755 static AdapterHandlerEntry* get_simple_adapter(const methodHandle& method);
756 public:
757
758 static AdapterHandlerEntry* new_entry(AdapterFingerPrint* fingerprint,
759 address i2c_entry, address c2i_entry, address c2i_inline_entry, address c2i_inline_ro_entry,
760 address c2i_unverified_entry, address c2i_unverified_inline_entry, address c2i_no_clinit_check_entry = nullptr);
761 static void create_native_wrapper(const methodHandle& method);
762 static AdapterHandlerEntry* get_adapter(const methodHandle& method);
763
764 static void print_handler(const CodeBlob* b) { print_handler_on(tty, b); }
765 static void print_handler_on(outputStream* st, const CodeBlob* b);
766 static bool contains(const CodeBlob* b);
767 #ifndef PRODUCT
768 static void print_statistics();
769 #endif // PRODUCT
770
771 };
772
773 // Utility class for computing the calling convention of the 3 types
774 // of compiled method entries:
775 // Method::_from_compiled_entry - sig_cc
776 // Method::_from_compiled_inline_ro_entry - sig_cc_ro
777 // Method::_from_compiled_inline_entry - sig
778 class CompiledEntrySignature : public StackObj {
779 Method* _method;
780 int _num_inline_args;
781 bool _has_inline_recv;
782 GrowableArray<SigEntry>* _sig;
783 GrowableArray<SigEntry>* _sig_cc;
784 GrowableArray<SigEntry>* _sig_cc_ro;
785 VMRegPair* _regs;
786 VMRegPair* _regs_cc;
787 VMRegPair* _regs_cc_ro;
788
789 int _args_on_stack;
790 int _args_on_stack_cc;
791 int _args_on_stack_cc_ro;
792
793 bool _c1_needs_stack_repair;
794 bool _c2_needs_stack_repair;
795
796 GrowableArray<Method*>* _supers;
797
798 public:
799 Method* method() const { return _method; }
800
801 // Used by Method::_from_compiled_inline_entry
802 GrowableArray<SigEntry>* sig() const { return _sig; }
803
804 // Used by Method::_from_compiled_entry
805 GrowableArray<SigEntry>* sig_cc() const { return _sig_cc; }
806
807 // Used by Method::_from_compiled_inline_ro_entry
808 GrowableArray<SigEntry>* sig_cc_ro() const { return _sig_cc_ro; }
809
810 VMRegPair* regs() const { return _regs; }
811 VMRegPair* regs_cc() const { return _regs_cc; }
812 VMRegPair* regs_cc_ro() const { return _regs_cc_ro; }
813
814 int args_on_stack() const { return _args_on_stack; }
815 int args_on_stack_cc() const { return _args_on_stack_cc; }
816 int args_on_stack_cc_ro() const { return _args_on_stack_cc_ro; }
817
818 int num_inline_args() const { return _num_inline_args; }
819 bool has_inline_recv() const { return _has_inline_recv; }
820
821 bool has_scalarized_args() const { return _sig != _sig_cc; }
822 bool c1_needs_stack_repair() const { return _c1_needs_stack_repair; }
823 bool c2_needs_stack_repair() const { return _c2_needs_stack_repair; }
824 CodeOffsets::Entries c1_inline_ro_entry_type() const;
825
826 GrowableArray<Method*>* get_supers();
827
828 CompiledEntrySignature(Method* method = nullptr);
829 void compute_calling_conventions(bool init = true);
830 };
831
832 #endif // SHARE_RUNTIME_SHAREDRUNTIME_HPP
|