1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, Red Hat Inc. All rights reserved.
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.
42 #include "vmreg_aarch64.inline.hpp"
43 #ifdef COMPILER1
44 #include "c1/c1_Runtime1.hpp"
45 #include "runtime/vframeArray.hpp"
46 #endif
47
48 #ifdef ASSERT
49 void RegisterMap::check_location_valid() {
50 }
51 #endif
52
53
54 // Profiling/safepoint support
55
56 bool frame::safe_for_sender(JavaThread *thread) {
57 address sp = (address)_sp;
58 address fp = (address)_fp;
59 address unextended_sp = (address)_unextended_sp;
60
61 // consider stack guards when trying to determine "safe" stack pointers
62 static size_t stack_guard_size = os::uses_stack_guard_pages() ?
63 (JavaThread::stack_red_zone_size() + JavaThread::stack_yellow_zone_size()) : 0;
64 size_t usable_stack_size = thread->stack_size() - stack_guard_size;
65
66 // sp must be within the usable part of the stack (not in guards)
67 bool sp_safe = (sp < thread->stack_base()) &&
68 (sp >= thread->stack_base() - usable_stack_size);
69
70
71 if (!sp_safe) {
72 return false;
73 }
74
75 // When we are running interpreted code the machine stack pointer, SP, is
76 // set low enough so that the Java expression stack can grow and shrink
77 // without ever exceeding the machine stack bounds. So, ESP >= SP.
78
79 // When we call out of an interpreted method, SP is incremented so that
80 // the space between SP and ESP is removed. The SP saved in the callee's
81 // frame is the SP *before* this increment. So, when we walk a stack of
82 // interpreter frames the sender's SP saved in a frame might be less than
83 // the SP at the point of call.
84
85 // So unextended sp must be within the stack but we need not to check
86 // that unextended sp >= sp
87
88 bool unextended_sp_safe = (unextended_sp < thread->stack_base());
89
90 if (!unextended_sp_safe) {
91 return false;
549 // method arguments
550 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
551 return false;
552 }
553
554 // validate bci/bcx
555
556 address bcp = interpreter_frame_bcp();
557 if (m->validate_bci_from_bcp(bcp) < 0) {
558 return false;
559 }
560
561 // validate constantPoolCache*
562 ConstantPoolCache* cp = *interpreter_frame_cache_addr();
563 if (MetaspaceObj::is_valid(cp) == false) return false;
564
565 // validate locals
566
567 address locals = (address) *interpreter_frame_locals_addr();
568
569 if (locals > thread->stack_base() || locals < (address) fp()) return false;
570
571 // We'd have to be pretty unlucky to be mislead at this point
572 return true;
573 }
574
575 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
576 assert(is_interpreted_frame(), "interpreted frame expected");
577 Method* method = interpreter_frame_method();
578 BasicType type = method->result_type();
579
580 intptr_t* tos_addr;
581 if (method->is_native()) {
582 // TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0
583 // Prior to calling into the runtime to report the method_exit the possible
584 // return value is pushed to the native stack. If the result is a jfloat/jdouble
585 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
586 tos_addr = (intptr_t*)sp();
587 if (type == T_FLOAT || type == T_DOUBLE) {
588 // This is times two because we do a push(ltos) after pushing XMM0
589 // and that takes two interpreter stack slots.
|
1 /*
2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2014, Red Hat Inc. All rights reserved.
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.
42 #include "vmreg_aarch64.inline.hpp"
43 #ifdef COMPILER1
44 #include "c1/c1_Runtime1.hpp"
45 #include "runtime/vframeArray.hpp"
46 #endif
47
48 #ifdef ASSERT
49 void RegisterMap::check_location_valid() {
50 }
51 #endif
52
53
54 // Profiling/safepoint support
55
56 bool frame::safe_for_sender(JavaThread *thread) {
57 address sp = (address)_sp;
58 address fp = (address)_fp;
59 address unextended_sp = (address)_unextended_sp;
60
61 // consider stack guards when trying to determine "safe" stack pointers
62 // sp must be within the usable part of the stack (not in guards)
63 if (!thread->is_in_usable_stack(sp)) {
64 return false;
65 }
66
67 // When we are running interpreted code the machine stack pointer, SP, is
68 // set low enough so that the Java expression stack can grow and shrink
69 // without ever exceeding the machine stack bounds. So, ESP >= SP.
70
71 // When we call out of an interpreted method, SP is incremented so that
72 // the space between SP and ESP is removed. The SP saved in the callee's
73 // frame is the SP *before* this increment. So, when we walk a stack of
74 // interpreter frames the sender's SP saved in a frame might be less than
75 // the SP at the point of call.
76
77 // So unextended sp must be within the stack but we need not to check
78 // that unextended sp >= sp
79
80 bool unextended_sp_safe = (unextended_sp < thread->stack_base());
81
82 if (!unextended_sp_safe) {
83 return false;
541 // method arguments
542 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
543 return false;
544 }
545
546 // validate bci/bcx
547
548 address bcp = interpreter_frame_bcp();
549 if (m->validate_bci_from_bcp(bcp) < 0) {
550 return false;
551 }
552
553 // validate constantPoolCache*
554 ConstantPoolCache* cp = *interpreter_frame_cache_addr();
555 if (MetaspaceObj::is_valid(cp) == false) return false;
556
557 // validate locals
558
559 address locals = (address) *interpreter_frame_locals_addr();
560
561 if (locals >= thread->stack_base() || locals < (address) fp()) return false;
562
563 // We'd have to be pretty unlucky to be mislead at this point
564 return true;
565 }
566
567 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
568 assert(is_interpreted_frame(), "interpreted frame expected");
569 Method* method = interpreter_frame_method();
570 BasicType type = method->result_type();
571
572 intptr_t* tos_addr;
573 if (method->is_native()) {
574 // TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0
575 // Prior to calling into the runtime to report the method_exit the possible
576 // return value is pushed to the native stack. If the result is a jfloat/jdouble
577 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
578 tos_addr = (intptr_t*)sp();
579 if (type == T_FLOAT || type == T_DOUBLE) {
580 // This is times two because we do a push(ltos) after pushing XMM0
581 // and that takes two interpreter stack slots.
|