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 SHARE_VM_RUNTIME_CONTINUATIONENTRY_HPP 26 #define SHARE_VM_RUNTIME_CONTINUATIONENTRY_HPP 27 28 #include "oops/oop.hpp" 29 #include "oops/oopsHierarchy.hpp" 30 #include "runtime/continuation.hpp" 31 #include "utilities/sizes.hpp" 32 33 #include CPU_HEADER(continuationEntry) 34 35 class JavaThread; 36 class nmethod; 37 class OopMap; 38 class RegisterMap; 39 40 // Metadata stored in the continuation entry frame 41 class ContinuationEntry { 42 ContinuationEntryPD _pd; 43 #ifdef ASSERT 44 private: 45 static const int COOKIE_VALUE = 0x1234; 46 int cookie; 47 48 public: 49 static int cookie_value() { return COOKIE_VALUE; } 50 static ByteSize cookie_offset() { return byte_offset_of(ContinuationEntry, cookie); } 51 52 void verify_cookie() { 53 assert(cookie == COOKIE_VALUE, "Bad cookie: %#x, expected: %#x", cookie, COOKIE_VALUE); 54 } 55 #endif 56 57 public: 58 static int _return_pc_offset; // friend gen_continuation_enter 59 static void set_enter_code(nmethod* nm, int interpreted_entry_offset); 60 static bool is_interpreted_call(address call_address); 61 62 private: 63 static address _return_pc; 64 static nmethod* _enter_special; 65 static int _interpreted_entry_offset; 66 67 private: 68 ContinuationEntry* _parent; 69 oopDesc* _cont; 70 oopDesc* _chunk; 71 int _flags; 72 // Size in words of the stack arguments of the bottom frame on stack if compiled 0 otherwise. 73 // The caller (if there is one) is the still frozen top frame in the StackChunk. 74 int _argsize; 75 intptr_t* _parent_cont_fastpath; 76 #ifdef _LP64 77 int64_t _parent_held_monitor_count; 78 #else 79 int32_t _parent_held_monitor_count; 80 #endif 81 uint _pin_count; 82 83 public: 84 static ByteSize parent_offset() { return byte_offset_of(ContinuationEntry, _parent); } 85 static ByteSize cont_offset() { return byte_offset_of(ContinuationEntry, _cont); } 86 static ByteSize chunk_offset() { return byte_offset_of(ContinuationEntry, _chunk); } 87 static ByteSize flags_offset() { return byte_offset_of(ContinuationEntry, _flags); } 88 static ByteSize argsize_offset() { return byte_offset_of(ContinuationEntry, _argsize); } 89 static ByteSize pin_count_offset(){ return byte_offset_of(ContinuationEntry, _pin_count); } 90 static ByteSize parent_cont_fastpath_offset() { return byte_offset_of(ContinuationEntry, _parent_cont_fastpath); } 91 static ByteSize parent_held_monitor_count_offset() { return byte_offset_of(ContinuationEntry, _parent_held_monitor_count); } 92 93 public: 94 static size_t size() { return align_up((int)sizeof(ContinuationEntry), 2*wordSize); } 95 96 ContinuationEntry* parent() const { return _parent; } 97 int64_t parent_held_monitor_count() const { return (int64_t)_parent_held_monitor_count; } 98 99 static address entry_pc() { return _return_pc; } 100 intptr_t* entry_sp() const { return (intptr_t*)this; } 101 intptr_t* entry_fp() const; 102 103 static address compiled_entry(); 104 static address interpreted_entry(); 105 106 int argsize() const { return _argsize; } 107 void set_argsize(int value) { _argsize = value; } 108 109 bool is_pinned() { return _pin_count > 0; } 110 bool pin() { 111 if (_pin_count == UINT_MAX) return false; 112 _pin_count++; 113 return true; 114 } 115 bool unpin() { 116 if (_pin_count == 0) return false; 117 _pin_count--; 118 return true; 119 } 120 121 intptr_t* parent_cont_fastpath() const { return _parent_cont_fastpath; } 122 void set_parent_cont_fastpath(intptr_t* x) { _parent_cont_fastpath = x; } 123 124 static ContinuationEntry* from_frame(const frame& f); 125 frame to_frame() const; 126 void update_register_map(RegisterMap* map) const; 127 void flush_stack_processing(JavaThread* thread) const; 128 129 inline intptr_t* bottom_sender_sp() const; 130 inline oop cont_oop(const JavaThread* thread) const; 131 inline oop scope(const JavaThread* thread) const; 132 inline static oop cont_oop_or_null(const ContinuationEntry* ce, const JavaThread* thread); 133 134 oop* cont_addr() { return (oop*)&_cont; } 135 oop* chunk_addr() { return (oop*)&_chunk; } 136 137 bool is_virtual_thread() const { return _flags != 0; } 138 139 #ifndef PRODUCT 140 void describe(FrameValues& values, int frame_no) const; 141 #endif 142 143 #ifdef ASSERT 144 static bool assert_entry_frame_laid_out(JavaThread* thread); 145 #endif 146 }; 147 148 #endif // SHARE_VM_RUNTIME_CONTINUATIONENTRY_HPP