1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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 *
40 #include "runtime/stubRoutines.hpp"
41 #include "vmreg_x86.inline.hpp"
42 #ifdef COMPILER1
43 #include "c1/c1_Runtime1.hpp"
44 #include "runtime/vframeArray.hpp"
45 #endif
46
47 #ifdef ASSERT
48 void RegisterMap::check_location_valid() {
49 }
50 #endif
51
52 // Profiling/safepoint support
53
54 bool frame::safe_for_sender(JavaThread *thread) {
55 address sp = (address)_sp;
56 address fp = (address)_fp;
57 address unextended_sp = (address)_unextended_sp;
58
59 // consider stack guards when trying to determine "safe" stack pointers
60 static size_t stack_guard_size = os::uses_stack_guard_pages() ?
61 JavaThread::stack_red_zone_size() + JavaThread::stack_yellow_zone_size() : 0;
62 size_t usable_stack_size = thread->stack_size() - stack_guard_size;
63
64 // sp must be within the usable part of the stack (not in guards)
65 bool sp_safe = (sp < thread->stack_base()) &&
66 (sp >= thread->stack_base() - usable_stack_size);
67
68
69 if (!sp_safe) {
70 return false;
71 }
72
73 // unextended sp must be within the stack and above or equal sp
74 bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&
75 (unextended_sp >= sp);
76
77 if (!unextended_sp_safe) {
78 return false;
79 }
80
81 // an fp must be within the stack and above (but not equal) sp
82 // second evaluation on fp+ is added to handle situation where fp is -1
83 bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
84
85 // We know sp/unextended_sp are safe only fp is questionable here
86
87 // If the current frame is known to the code cache then we can attempt to
88 // to construct the sender and do some validation of it. This goes a long way
89 // toward eliminating issues when we get in frame construction code
536 // method arguments
537 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
538 return false;
539 }
540
541 // validate bci/bcp
542
543 address bcp = interpreter_frame_bcp();
544 if (m->validate_bci_from_bcp(bcp) < 0) {
545 return false;
546 }
547
548 // validate ConstantPoolCache*
549 ConstantPoolCache* cp = *interpreter_frame_cache_addr();
550 if (MetaspaceObj::is_valid(cp) == false) return false;
551
552 // validate locals
553
554 address locals = (address) *interpreter_frame_locals_addr();
555
556 if (locals > thread->stack_base() || locals < (address) fp()) return false;
557
558 // We'd have to be pretty unlucky to be mislead at this point
559 return true;
560 }
561
562 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
563 assert(is_interpreted_frame(), "interpreted frame expected");
564 Method* method = interpreter_frame_method();
565 BasicType type = method->result_type();
566
567 intptr_t* tos_addr;
568 if (method->is_native()) {
569 // Prior to calling into the runtime to report the method_exit the possible
570 // return value is pushed to the native stack. If the result is a jfloat/jdouble
571 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
572 tos_addr = (intptr_t*)sp();
573 if (type == T_FLOAT || type == T_DOUBLE) {
574 // QQQ seems like this code is equivalent on the two platforms
575 #ifdef AMD64
576 // This is times two because we do a push(ltos) after pushing XMM0
|
1 /*
2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
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 *
40 #include "runtime/stubRoutines.hpp"
41 #include "vmreg_x86.inline.hpp"
42 #ifdef COMPILER1
43 #include "c1/c1_Runtime1.hpp"
44 #include "runtime/vframeArray.hpp"
45 #endif
46
47 #ifdef ASSERT
48 void RegisterMap::check_location_valid() {
49 }
50 #endif
51
52 // Profiling/safepoint support
53
54 bool frame::safe_for_sender(JavaThread *thread) {
55 address sp = (address)_sp;
56 address fp = (address)_fp;
57 address unextended_sp = (address)_unextended_sp;
58
59 // consider stack guards when trying to determine "safe" stack pointers
60 // sp must be within the usable part of the stack (not in guards)
61 if (!thread->is_in_usable_stack(sp)) {
62 return false;
63 }
64
65 // unextended sp must be within the stack and above or equal sp
66 bool unextended_sp_safe = (unextended_sp < thread->stack_base()) &&
67 (unextended_sp >= sp);
68
69 if (!unextended_sp_safe) {
70 return false;
71 }
72
73 // an fp must be within the stack and above (but not equal) sp
74 // second evaluation on fp+ is added to handle situation where fp is -1
75 bool fp_safe = (fp < thread->stack_base() && (fp > sp) && (((fp + (return_addr_offset * sizeof(void*))) < thread->stack_base())));
76
77 // We know sp/unextended_sp are safe only fp is questionable here
78
79 // If the current frame is known to the code cache then we can attempt to
80 // to construct the sender and do some validation of it. This goes a long way
81 // toward eliminating issues when we get in frame construction code
528 // method arguments
529 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
530 return false;
531 }
532
533 // validate bci/bcp
534
535 address bcp = interpreter_frame_bcp();
536 if (m->validate_bci_from_bcp(bcp) < 0) {
537 return false;
538 }
539
540 // validate ConstantPoolCache*
541 ConstantPoolCache* cp = *interpreter_frame_cache_addr();
542 if (MetaspaceObj::is_valid(cp) == false) return false;
543
544 // validate locals
545
546 address locals = (address) *interpreter_frame_locals_addr();
547
548 if (locals >= thread->stack_base() || locals < (address) fp()) return false;
549
550 // We'd have to be pretty unlucky to be mislead at this point
551 return true;
552 }
553
554 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
555 assert(is_interpreted_frame(), "interpreted frame expected");
556 Method* method = interpreter_frame_method();
557 BasicType type = method->result_type();
558
559 intptr_t* tos_addr;
560 if (method->is_native()) {
561 // Prior to calling into the runtime to report the method_exit the possible
562 // return value is pushed to the native stack. If the result is a jfloat/jdouble
563 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
564 tos_addr = (intptr_t*)sp();
565 if (type == T_FLOAT || type == T_DOUBLE) {
566 // QQQ seems like this code is equivalent on the two platforms
567 #ifdef AMD64
568 // This is times two because we do a push(ltos) after pushing XMM0
|