577
578 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
579 // rbx, - method
580 // rcx - rcvr (assuming there is one)
581 // top of stack return address of interpreter caller
582 // rsp - sender_sp
583
584 // C++ interpreter only
585 // rsi/r13 - previous interpreter state pointer
586
587 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
588
589 // InterpreterRuntime::frequency_counter_overflow takes one argument
590 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
591 // The call returns the address of the verified entry point for the method or NULL
592 // if the compilation did not complete (either went background or bailed out).
593 __ movptr(rax, (int32_t)false);
594 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
595
596 // for c++ interpreter can rsi really be munged?
597 __ lea(state, Address(rbp, -sizeof(BytecodeInterpreter))); // restore state
598 __ movptr(rbx, Address(state, byte_offset_of(BytecodeInterpreter, _method))); // restore method
599 __ movptr(rdi, Address(state, byte_offset_of(BytecodeInterpreter, _locals))); // get locals pointer
600
601 __ jmp(*do_continue, relocInfo::none);
602
603 }
604
605 void InterpreterGenerator::generate_stack_overflow_check(void) {
606 // see if we've got enough room on the stack for locals plus overhead.
607 // the expression stack grows down incrementally, so the normal guard
608 // page mechanism will work for that.
609 //
610 // Registers live on entry:
611 //
612 // Asm interpreter
613 // rdx: number of additional locals this frame needs (what we must check)
614 // rbx,: methodOop
615
616 // C++ Interpreter
617 // rsi/r13: previous interpreter frame state object
641 // compute rsp as if this were going to be the last frame on
642 // the stack before the red zone
643
644 Label after_frame_check_pop;
645
646 // save rsi == caller's bytecode ptr (c++ previous interp. state)
647 // QQQ problem here?? rsi overload????
648 __ push(state);
649
650 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rsi);
651
652 NOT_LP64(__ get_thread(thread));
653
654 const Address stack_base(thread, Thread::stack_base_offset());
655 const Address stack_size(thread, Thread::stack_size_offset());
656
657 // locals + overhead, in bytes
658 const Address size_of_stack (rbx, methodOopDesc::max_stack_offset());
659 // Always give one monitor to allow us to start interp if sync method.
660 // Any additional monitors need a check when moving the expression stack
661 const one_monitor = frame::interpreter_frame_monitor_size() * wordSize;
662 __ load_unsigned_word(rax, size_of_stack); // get size of expression stack in words
663 __ lea(rax, Address(noreg, rax, Interpreter::stackElementScale(), one_monitor));
664 __ lea(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size));
665
666 #ifdef ASSERT
667 Label stack_base_okay, stack_size_okay;
668 // verify that thread stack base is non-zero
669 __ cmpptr(stack_base, (int32_t)0);
670 __ jcc(Assembler::notEqual, stack_base_okay);
671 __ stop("stack base is zero");
672 __ bind(stack_base_okay);
673 // verify that thread stack size is non-zero
674 __ cmpptr(stack_size, (int32_t)0);
675 __ jcc(Assembler::notEqual, stack_size_okay);
676 __ stop("stack size is zero");
677 __ bind(stack_size_okay);
678 #endif
679
680 // Add stack base to locals and subtract stack size
681 __ addptr(rax, stack_base);
1812
1813
1814 generate_deopt_handling();
1815 __ jmp(call_interpreter);
1816
1817
1818 // Current frame has caught an exception we need to dispatch to the
1819 // handler. We can get here because a native interpreter frame caught
1820 // an exception in which case there is no handler and we must rethrow
1821 // If it is a vanilla interpreted frame the we simply drop into the
1822 // interpreter and let it do the lookup.
1823
1824 Interpreter::_rethrow_exception_entry = __ pc();
1825 // rax: exception
1826 // rdx: return address/pc that threw exception
1827
1828 Label return_with_exception;
1829 Label unwind_and_forward;
1830
1831 // restore state pointer.
1832 __ lea(state, Address(rbp, -sizeof(BytecodeInterpreter)));
1833
1834 __ movptr(rbx, STATE(_method)); // get method
1835 #ifdef _LP64
1836 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
1837 #else
1838 __ movl(rcx, STATE(_thread)); // get thread
1839
1840 // Store exception with interpreter will expect it
1841 __ movptr(Address(rcx, Thread::pending_exception_offset()), rax);
1842 #endif // _LP64
1843
1844 // is current frame vanilla or native?
1845
1846 __ movl(rdx, access_flags);
1847 __ testl(rdx, JVM_ACC_NATIVE);
1848 __ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly
1849
1850 // We drop thru to unwind a native interpreted frame with a pending exception
1851 // We jump here for the initial interpreter frame with exception pending
1852 // We unwind the current acivation and forward it to our caller.
1860 __ pop(rdx);
1861 __ mov(rsp, rcx);
1862 __ push(rdx);
1863 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
1864
1865 // Return point from a call which returns a result in the native abi
1866 // (c1/c2/jni-native). This result must be processed onto the java
1867 // expression stack.
1868 //
1869 // A pending exception may be present in which case there is no result present
1870
1871 Label resume_interpreter;
1872 Label do_float;
1873 Label do_double;
1874 Label done_conv;
1875
1876 address compiled_entry = __ pc();
1877
1878 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
1879 if (UseSSE < 2) {
1880 __ lea(state, Address(rbp, -sizeof(BytecodeInterpreter)));
1881 __ movptr(rbx, STATE(_result._to_call._callee)); // get method just executed
1882 __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
1883 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
1884 __ jcc(Assembler::equal, do_float);
1885 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
1886 __ jcc(Assembler::equal, do_double);
1887 #ifdef COMPILER2
1888 __ empty_FPU_stack();
1889 #endif // COMPILER2
1890 __ jmp(done_conv);
1891
1892 __ bind(do_float);
1893 #ifdef COMPILER2
1894 for (int i = 1; i < 8; i++) {
1895 __ ffree(i);
1896 }
1897 #endif // COMPILER2
1898 __ jmp(done_conv);
1899 __ bind(do_double);
1900 #ifdef COMPILER2
1901 for (int i = 1; i < 8; i++) {
1902 __ ffree(i);
1903 }
1904 #endif // COMPILER2
1905 __ jmp(done_conv);
1906 } else {
1907 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
1911 #if 0
1912 // emit a sentinel we can test for when converting an interpreter
1913 // entry point to a compiled entry point.
1914 __ a_long(Interpreter::return_sentinel);
1915 __ a_long((int)compiled_entry);
1916 #endif
1917
1918 // Return point to interpreter from compiled/native method
1919
1920 InternalAddress return_from_native_method(__ pc());
1921
1922 __ bind(done_conv);
1923
1924
1925 // Result if any is in tosca. The java expression stack is in the state that the
1926 // calling convention left it (i.e. params may or may not be present)
1927 // Copy the result from tosca and place it on java expression stack.
1928
1929 // Restore rsi/r13 as compiled code may not preserve it
1930
1931 __ lea(state, Address(rbp, -sizeof(BytecodeInterpreter)));
1932
1933 // restore stack to what we had when we left (in case i2c extended it)
1934
1935 __ movptr(rsp, STATE(_stack));
1936 __ lea(rsp, Address(rsp, wordSize));
1937
1938 // If there is a pending exception then we don't really have a result to process
1939
1940 #ifdef _LP64
1941 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1942 #else
1943 __ movptr(rcx, STATE(_thread)); // get thread
1944 __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1945 #endif / __LP64
1946 __ jcc(Assembler::notZero, return_with_exception);
1947
1948 // get method just executed
1949 __ movptr(rbx, STATE(_result._to_call._callee));
1950
1951 // callee left args on top of expression stack, remove them
1952 __ load_unsigned_word(rcx, Address(rbx, methodOopDesc::size_of_parameters_offset()));
1953 __ lea(rsp, Address(rsp, rcx, Address::times_ptr));
1954
1955 __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
1956 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
1957 // Address index(noreg, rax, Address::times_ptr);
1958 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
1959 // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
1960 __ call(rcx); // call result converter
1961 __ jmp(resume_interpreter);
1962
1963 // An exception is being caught on return to a vanilla interpreter frame.
1964 // Empty the stack and resume interpreter
1965
|
577
578 // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
579 // rbx, - method
580 // rcx - rcvr (assuming there is one)
581 // top of stack return address of interpreter caller
582 // rsp - sender_sp
583
584 // C++ interpreter only
585 // rsi/r13 - previous interpreter state pointer
586
587 const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
588
589 // InterpreterRuntime::frequency_counter_overflow takes one argument
590 // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
591 // The call returns the address of the verified entry point for the method or NULL
592 // if the compilation did not complete (either went background or bailed out).
593 __ movptr(rax, (int32_t)false);
594 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
595
596 // for c++ interpreter can rsi really be munged?
597 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter))); // restore state
598 __ movptr(rbx, Address(state, byte_offset_of(BytecodeInterpreter, _method))); // restore method
599 __ movptr(rdi, Address(state, byte_offset_of(BytecodeInterpreter, _locals))); // get locals pointer
600
601 __ jmp(*do_continue, relocInfo::none);
602
603 }
604
605 void InterpreterGenerator::generate_stack_overflow_check(void) {
606 // see if we've got enough room on the stack for locals plus overhead.
607 // the expression stack grows down incrementally, so the normal guard
608 // page mechanism will work for that.
609 //
610 // Registers live on entry:
611 //
612 // Asm interpreter
613 // rdx: number of additional locals this frame needs (what we must check)
614 // rbx,: methodOop
615
616 // C++ Interpreter
617 // rsi/r13: previous interpreter frame state object
641 // compute rsp as if this were going to be the last frame on
642 // the stack before the red zone
643
644 Label after_frame_check_pop;
645
646 // save rsi == caller's bytecode ptr (c++ previous interp. state)
647 // QQQ problem here?? rsi overload????
648 __ push(state);
649
650 const Register thread = LP64_ONLY(r15_thread) NOT_LP64(rsi);
651
652 NOT_LP64(__ get_thread(thread));
653
654 const Address stack_base(thread, Thread::stack_base_offset());
655 const Address stack_size(thread, Thread::stack_size_offset());
656
657 // locals + overhead, in bytes
658 const Address size_of_stack (rbx, methodOopDesc::max_stack_offset());
659 // Always give one monitor to allow us to start interp if sync method.
660 // Any additional monitors need a check when moving the expression stack
661 const int one_monitor = frame::interpreter_frame_monitor_size() * wordSize;
662 __ load_unsigned_word(rax, size_of_stack); // get size of expression stack in words
663 __ lea(rax, Address(noreg, rax, Interpreter::stackElementScale(), one_monitor));
664 __ lea(rax, Address(rax, rdx, Interpreter::stackElementScale(), overhead_size));
665
666 #ifdef ASSERT
667 Label stack_base_okay, stack_size_okay;
668 // verify that thread stack base is non-zero
669 __ cmpptr(stack_base, (int32_t)0);
670 __ jcc(Assembler::notEqual, stack_base_okay);
671 __ stop("stack base is zero");
672 __ bind(stack_base_okay);
673 // verify that thread stack size is non-zero
674 __ cmpptr(stack_size, (int32_t)0);
675 __ jcc(Assembler::notEqual, stack_size_okay);
676 __ stop("stack size is zero");
677 __ bind(stack_size_okay);
678 #endif
679
680 // Add stack base to locals and subtract stack size
681 __ addptr(rax, stack_base);
1812
1813
1814 generate_deopt_handling();
1815 __ jmp(call_interpreter);
1816
1817
1818 // Current frame has caught an exception we need to dispatch to the
1819 // handler. We can get here because a native interpreter frame caught
1820 // an exception in which case there is no handler and we must rethrow
1821 // If it is a vanilla interpreted frame the we simply drop into the
1822 // interpreter and let it do the lookup.
1823
1824 Interpreter::_rethrow_exception_entry = __ pc();
1825 // rax: exception
1826 // rdx: return address/pc that threw exception
1827
1828 Label return_with_exception;
1829 Label unwind_and_forward;
1830
1831 // restore state pointer.
1832 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
1833
1834 __ movptr(rbx, STATE(_method)); // get method
1835 #ifdef _LP64
1836 __ movptr(Address(r15_thread, Thread::pending_exception_offset()), rax);
1837 #else
1838 __ movl(rcx, STATE(_thread)); // get thread
1839
1840 // Store exception with interpreter will expect it
1841 __ movptr(Address(rcx, Thread::pending_exception_offset()), rax);
1842 #endif // _LP64
1843
1844 // is current frame vanilla or native?
1845
1846 __ movl(rdx, access_flags);
1847 __ testl(rdx, JVM_ACC_NATIVE);
1848 __ jcc(Assembler::zero, return_with_exception); // vanilla interpreted frame, handle directly
1849
1850 // We drop thru to unwind a native interpreted frame with a pending exception
1851 // We jump here for the initial interpreter frame with exception pending
1852 // We unwind the current acivation and forward it to our caller.
1860 __ pop(rdx);
1861 __ mov(rsp, rcx);
1862 __ push(rdx);
1863 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
1864
1865 // Return point from a call which returns a result in the native abi
1866 // (c1/c2/jni-native). This result must be processed onto the java
1867 // expression stack.
1868 //
1869 // A pending exception may be present in which case there is no result present
1870
1871 Label resume_interpreter;
1872 Label do_float;
1873 Label do_double;
1874 Label done_conv;
1875
1876 address compiled_entry = __ pc();
1877
1878 // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
1879 if (UseSSE < 2) {
1880 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
1881 __ movptr(rbx, STATE(_result._to_call._callee)); // get method just executed
1882 __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
1883 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_FLOAT)); // Result stub address array index
1884 __ jcc(Assembler::equal, do_float);
1885 __ cmpl(rcx, AbstractInterpreter::BasicType_as_index(T_DOUBLE)); // Result stub address array index
1886 __ jcc(Assembler::equal, do_double);
1887 #if !defined(_LP64) || defined(COMPILER1) || !defined(COMPILER2)
1888 __ empty_FPU_stack();
1889 #endif // COMPILER2
1890 __ jmp(done_conv);
1891
1892 __ bind(do_float);
1893 #ifdef COMPILER2
1894 for (int i = 1; i < 8; i++) {
1895 __ ffree(i);
1896 }
1897 #endif // COMPILER2
1898 __ jmp(done_conv);
1899 __ bind(do_double);
1900 #ifdef COMPILER2
1901 for (int i = 1; i < 8; i++) {
1902 __ ffree(i);
1903 }
1904 #endif // COMPILER2
1905 __ jmp(done_conv);
1906 } else {
1907 __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
1911 #if 0
1912 // emit a sentinel we can test for when converting an interpreter
1913 // entry point to a compiled entry point.
1914 __ a_long(Interpreter::return_sentinel);
1915 __ a_long((int)compiled_entry);
1916 #endif
1917
1918 // Return point to interpreter from compiled/native method
1919
1920 InternalAddress return_from_native_method(__ pc());
1921
1922 __ bind(done_conv);
1923
1924
1925 // Result if any is in tosca. The java expression stack is in the state that the
1926 // calling convention left it (i.e. params may or may not be present)
1927 // Copy the result from tosca and place it on java expression stack.
1928
1929 // Restore rsi/r13 as compiled code may not preserve it
1930
1931 __ lea(state, Address(rbp, -(int)sizeof(BytecodeInterpreter)));
1932
1933 // restore stack to what we had when we left (in case i2c extended it)
1934
1935 __ movptr(rsp, STATE(_stack));
1936 __ lea(rsp, Address(rsp, wordSize));
1937
1938 // If there is a pending exception then we don't really have a result to process
1939
1940 #ifdef _LP64
1941 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1942 #else
1943 __ movptr(rcx, STATE(_thread)); // get thread
1944 __ cmpptr(Address(rcx, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1945 #endif // _LP64
1946 __ jcc(Assembler::notZero, return_with_exception);
1947
1948 // get method just executed
1949 __ movptr(rbx, STATE(_result._to_call._callee));
1950
1951 // callee left args on top of expression stack, remove them
1952 __ load_unsigned_word(rcx, Address(rbx, methodOopDesc::size_of_parameters_offset()));
1953 __ lea(rsp, Address(rsp, rcx, Address::times_ptr));
1954
1955 __ movl(rcx, Address(rbx, methodOopDesc::result_index_offset()));
1956 ExternalAddress tosca_to_stack((address)CppInterpreter::_tosca_to_stack);
1957 // Address index(noreg, rax, Address::times_ptr);
1958 __ movptr(rcx, ArrayAddress(tosca_to_stack, Address(noreg, rcx, Address::times_ptr)));
1959 // __ movl(rcx, Address(noreg, rcx, Address::times_ptr, int(AbstractInterpreter::_tosca_to_stack)));
1960 __ call(rcx); // call result converter
1961 __ jmp(resume_interpreter);
1962
1963 // An exception is being caught on return to a vanilla interpreter frame.
1964 // Empty the stack and resume interpreter
1965
|