1 /*
2 * Copyright (c) 2022, 2023, 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 *
23 */
24
25 #ifndef CPU_X86_CONTINUATIONHELPER_X86_INLINE_HPP
26 #define CPU_X86_CONTINUATIONHELPER_X86_INLINE_HPP
27
28 #include "runtime/continuationHelper.hpp"
29
30 #include "runtime/continuationEntry.inline.hpp"
31 #include "runtime/frame.inline.hpp"
32 #include "runtime/registerMap.hpp"
33 #include "utilities/macros.hpp"
34
35 template<typename FKind>
36 static inline intptr_t** link_address(const frame& f) {
37 assert(FKind::is_instance(f), "");
38 return FKind::interpreted
39 ? (intptr_t**)(f.fp() + frame::link_offset)
40 : (intptr_t**)(f.unextended_sp() + f.cb()->frame_size() - frame::sender_sp_offset);
41 }
42
43 inline int ContinuationHelper::frame_align_words(int size) {
44 #ifdef _LP64
45 return size & 1;
46 #else
47 return 0;
48 #endif
49 }
50
51 inline intptr_t* ContinuationHelper::frame_align_pointer(intptr_t* sp) {
52 #ifdef _LP64
53 sp = align_down(sp, frame::frame_alignment);
54 #endif
55 return sp;
56 }
57
58 template<typename FKind>
59 inline void ContinuationHelper::update_register_map(const frame& f, RegisterMap* map) {
60 frame::update_map_with_saved_link(map, link_address<FKind>(f));
61 }
62
63 inline void ContinuationHelper::update_register_map_with_callee(const frame& f, RegisterMap* map) {
64 frame::update_map_with_saved_link(map, ContinuationHelper::Frame::callee_link_address(f));
65 }
66
67 inline void ContinuationHelper::push_pd(const frame& f) {
68 *(intptr_t**)(f.sp() - frame::sender_sp_offset) = f.fp();
69 }
70
71 inline void ContinuationHelper::set_anchor_to_entry_pd(JavaFrameAnchor* anchor, ContinuationEntry* entry) {
72 anchor->set_last_Java_fp(entry->entry_fp());
73 }
74
75 #ifdef ASSERT
76 inline void ContinuationHelper::set_anchor_pd(JavaFrameAnchor* anchor, intptr_t* sp) {
77 intptr_t* fp = *(intptr_t**)(sp - frame::sender_sp_offset);
78 anchor->set_last_Java_fp(fp);
79 }
80
81 inline bool ContinuationHelper::Frame::assert_frame_laid_out(frame f) {
82 intptr_t* sp = f.sp();
83 address pc = *(address*)(sp - frame::sender_sp_ret_address_offset());
84 intptr_t* fp = *(intptr_t**)(sp - frame::sender_sp_offset);
85 assert(f.raw_pc() == pc, "f.ra_pc: " INTPTR_FORMAT " actual: " INTPTR_FORMAT, p2i(f.raw_pc()), p2i(pc));
86 assert(f.fp() == fp, "f.fp: " INTPTR_FORMAT " actual: " INTPTR_FORMAT, p2i(f.fp()), p2i(fp));
87 return f.raw_pc() == pc && f.fp() == fp;
88 }
89 #endif
90
91 inline intptr_t** ContinuationHelper::Frame::callee_link_address(const frame& f) {
92 return (intptr_t**)(f.sp() - frame::sender_sp_offset);
93 }
94
95 inline address* ContinuationHelper::Frame::return_pc_address(const frame& f) {
96 return (address*)(f.real_fp() - 1);
97 }
98
99 inline address* ContinuationHelper::InterpretedFrame::return_pc_address(const frame& f) {
100 return (address*)(f.fp() + frame::return_addr_offset);
|
1 /*
2 * Copyright (c) 2022, 2024, 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 *
23 */
24
25 #ifndef CPU_X86_CONTINUATIONHELPER_X86_INLINE_HPP
26 #define CPU_X86_CONTINUATIONHELPER_X86_INLINE_HPP
27
28 #include "runtime/continuationHelper.hpp"
29
30 #include "runtime/continuationEntry.inline.hpp"
31 #include "runtime/frame.inline.hpp"
32 #include "runtime/registerMap.hpp"
33 #include "utilities/macros.hpp"
34
35 template<typename FKind>
36 static inline intptr_t** link_address(const frame& f) {
37 assert(FKind::is_instance(f), "");
38 return FKind::interpreted
39 ? (intptr_t**)(f.fp() + frame::link_offset)
40 : (intptr_t**)(f.unextended_sp() + f.cb()->frame_size() - frame::sender_sp_offset);
41 }
42
43 static inline void patch_return_pc_with_preempt_stub(frame& f) {
44 if (f.is_runtime_frame()) {
45 // Patch the pc of the now old last Java frame (we already set the anchor to enterSpecial)
46 // so that when target goes back to Java it will actually return to the preempt cleanup stub.
47 intptr_t* sp = f.sp();
48 sp[-1] = (intptr_t)StubRoutines::cont_preempt_stub();
49 } else {
50 // The target will check for preemption once it returns to the interpreter
51 // or the native wrapper code and will manually jump to the preempt stub.
52 JavaThread *thread = JavaThread::current();
53 thread->set_preempt_alternate_return(StubRoutines::cont_preempt_stub());
54 }
55 }
56
57 inline int ContinuationHelper::frame_align_words(int size) {
58 #ifdef _LP64
59 return size & 1;
60 #else
61 return 0;
62 #endif
63 }
64
65 inline intptr_t* ContinuationHelper::frame_align_pointer(intptr_t* sp) {
66 #ifdef _LP64
67 sp = align_down(sp, frame::frame_alignment);
68 #endif
69 return sp;
70 }
71
72 template<typename FKind>
73 inline void ContinuationHelper::update_register_map(const frame& f, RegisterMap* map) {
74 frame::update_map_with_saved_link(map, link_address<FKind>(f));
75 }
76
77 inline void ContinuationHelper::update_register_map_with_callee(const frame& f, RegisterMap* map) {
78 frame::update_map_with_saved_link(map, ContinuationHelper::Frame::callee_link_address(f));
79 }
80
81 inline void ContinuationHelper::push_pd(const frame& f) {
82 *(intptr_t**)(f.sp() - frame::sender_sp_offset) = f.fp();
83 }
84
85 inline void ContinuationHelper::set_anchor_to_entry_pd(JavaFrameAnchor* anchor, ContinuationEntry* entry) {
86 anchor->set_last_Java_fp(entry->entry_fp());
87 }
88
89 inline void ContinuationHelper::set_anchor_pd(JavaFrameAnchor* anchor, intptr_t* sp) {
90 intptr_t* fp = *(intptr_t**)(sp - frame::sender_sp_offset);
91 anchor->set_last_Java_fp(fp);
92 }
93
94 #ifdef ASSERT
95 inline bool ContinuationHelper::Frame::assert_frame_laid_out(frame f) {
96 intptr_t* sp = f.sp();
97 address pc = *(address*)(sp - frame::sender_sp_ret_address_offset());
98 intptr_t* fp = *(intptr_t**)(sp - frame::sender_sp_offset);
99 assert(f.raw_pc() == pc, "f.ra_pc: " INTPTR_FORMAT " actual: " INTPTR_FORMAT, p2i(f.raw_pc()), p2i(pc));
100 assert(f.fp() == fp, "f.fp: " INTPTR_FORMAT " actual: " INTPTR_FORMAT, p2i(f.fp()), p2i(fp));
101 return f.raw_pc() == pc && f.fp() == fp;
102 }
103 #endif
104
105 inline intptr_t** ContinuationHelper::Frame::callee_link_address(const frame& f) {
106 return (intptr_t**)(f.sp() - frame::sender_sp_offset);
107 }
108
109 inline address* ContinuationHelper::Frame::return_pc_address(const frame& f) {
110 return (address*)(f.real_fp() - 1);
111 }
112
113 inline address* ContinuationHelper::InterpretedFrame::return_pc_address(const frame& f) {
114 return (address*)(f.fp() + frame::return_addr_offset);
|