1 /* 2 * Copyright (c) 1997, 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 SHARE_RUNTIME_CONTINUATIONJAVACLASSES_INLINE_HPP 26 #define SHARE_RUNTIME_CONTINUATIONJAVACLASSES_INLINE_HPP 27 28 #include "runtime/continuationJavaClasses.hpp" 29 30 #include "logging/log.hpp" 31 #include "oops/access.inline.hpp" 32 #include "oops/oop.inline.hpp" 33 #include "oops/stackChunkOop.inline.hpp" 34 #include "runtime/atomic.hpp" 35 36 inline oop jdk_internal_vm_Continuation::scope(oop continuation) { 37 return continuation->obj_field(_scope_offset); 38 } 39 40 inline oop jdk_internal_vm_Continuation::parent(oop continuation) { 41 return continuation->obj_field(_parent_offset); 42 } 43 44 inline stackChunkOop jdk_internal_vm_Continuation::tail(oop continuation) { 45 return stackChunkOopDesc::cast(continuation->obj_field(_tail_offset)); 46 } 47 48 inline void jdk_internal_vm_Continuation::set_tail(oop continuation, stackChunkOop value) { 49 continuation->obj_field_put(_tail_offset, value); 50 } 51 52 inline bool jdk_internal_vm_Continuation::done(oop continuation) { 53 return continuation->bool_field(_done_offset); 54 } 55 56 inline bool jdk_internal_vm_Continuation::is_preempted(oop continuation) { 57 return continuation->bool_field(_preempted_offset); 58 } 59 60 inline void jdk_internal_vm_Continuation::set_preempted(oop continuation, bool value) { 61 continuation->bool_field_put(_preempted_offset, (jboolean)value); 62 } 63 64 // ---------------------------------------------------------------------- 65 66 inline oop jdk_internal_vm_StackChunk::parent(oop chunk) { 67 return chunk->obj_field(_parent_offset); 68 } 69 70 inline void jdk_internal_vm_StackChunk::set_parent(oop chunk, oop value) { 71 chunk->obj_field_put(_parent_offset, value); 72 } 73 74 template<typename P> 75 inline void jdk_internal_vm_StackChunk::set_parent_raw(oop chunk, oop value) { 76 RawAccess<>::oop_store(chunk->field_addr<P>(_parent_offset), value); 77 } 78 79 template<DecoratorSet decorators> 80 inline void jdk_internal_vm_StackChunk::set_parent_access(oop chunk, oop value) { 81 chunk->obj_field_put_access<decorators>(_parent_offset, value); 82 } 83 84 inline oop jdk_internal_vm_StackChunk::cont(oop chunk) { 85 return chunk->obj_field(_cont_offset); 86 } 87 88 template<typename P> 89 inline oop jdk_internal_vm_StackChunk::cont_raw(oop chunk) { 90 return (oop)RawAccess<>::oop_load(chunk->field_addr<P>(_cont_offset)); 91 } 92 93 inline void jdk_internal_vm_StackChunk::set_cont(oop chunk, oop value) { 94 chunk->obj_field_put(_cont_offset, value); 95 } 96 97 template<typename P> 98 inline void jdk_internal_vm_StackChunk::set_cont_raw(oop chunk, oop value) { 99 RawAccess<>::oop_store(chunk->field_addr<P>(_cont_offset), value); 100 } 101 102 template<DecoratorSet decorators> 103 inline void jdk_internal_vm_StackChunk::set_cont_access(oop chunk, oop value) { 104 chunk->obj_field_put_access<decorators>(_cont_offset, value); 105 } 106 107 inline int jdk_internal_vm_StackChunk::size(oop chunk) { 108 return chunk->int_field(_size_offset); 109 } 110 111 inline void jdk_internal_vm_StackChunk::set_size(HeapWord* chunk, int value) { 112 // Used by StackChunkAllocator before the Object has been finished, 113 // so don't cast too oop and use int_field_put in this function. 114 assert(_size_offset != 0, "must be set"); 115 *(int*)(((char*)chunk) + _size_offset) = (int)value; 116 } 117 118 inline int jdk_internal_vm_StackChunk::sp(oop chunk) { 119 return chunk->int_field(_sp_offset); 120 } 121 122 inline void jdk_internal_vm_StackChunk::set_sp(oop chunk, int value) { 123 chunk->int_field_put(_sp_offset, value); 124 } 125 126 inline void jdk_internal_vm_StackChunk::set_sp(HeapWord* chunk, int value) { 127 // Used by StackChunkAllocator before the Object has been finished, 128 // so don't cast too oop and use int_field_put in this function. 129 assert(_sp_offset != 0, "must be set"); 130 *(int*)(((char*)chunk) + _sp_offset) = (int)value; 131 } 132 133 inline address jdk_internal_vm_StackChunk::pc(oop chunk) { 134 return chunk->address_field(_pc_offset); 135 } 136 137 inline void jdk_internal_vm_StackChunk::set_pc(oop chunk, address value) { 138 chunk->address_field_put(_pc_offset, value); 139 } 140 141 inline int jdk_internal_vm_StackChunk::argsize(oop chunk) { 142 return chunk->int_field(_argsize_offset); 143 } 144 145 inline void jdk_internal_vm_StackChunk::set_argsize(oop chunk, int value) { 146 chunk->int_field_put(_argsize_offset, value); 147 } 148 149 inline uint8_t jdk_internal_vm_StackChunk::flags(oop chunk) { 150 return Atomic::load(chunk->field_addr<uint8_t>(_flags_offset)); 151 } 152 153 inline void jdk_internal_vm_StackChunk::set_flags(oop chunk, uint8_t value) { 154 Atomic::store(chunk->field_addr<uint8_t>(_flags_offset), value); 155 } 156 157 inline uint8_t jdk_internal_vm_StackChunk::flags_acquire(oop chunk) { 158 return Atomic::load_acquire(chunk->field_addr<uint8_t>(_flags_offset)); 159 } 160 161 inline void jdk_internal_vm_StackChunk::release_set_flags(oop chunk, uint8_t value) { 162 Atomic::release_store(chunk->field_addr<uint8_t>(_flags_offset), value); 163 } 164 165 inline bool jdk_internal_vm_StackChunk::try_set_flags(oop chunk, uint8_t expected_value, uint8_t new_value) { 166 return Atomic::cmpxchg(chunk->field_addr<uint8_t>(_flags_offset), expected_value, new_value) == expected_value; 167 } 168 169 inline int jdk_internal_vm_StackChunk::maxThawingSize(oop chunk) { 170 return chunk->int_field(_maxThawingSize_offset); 171 } 172 173 inline void jdk_internal_vm_StackChunk::set_maxThawingSize(oop chunk, int value) { 174 #ifdef ASSERT 175 jint old = maxThawingSize(chunk); 176 log_develop_trace(continuations)("%s max_size: %d -> %d", value >= old ? "add" : "sub", old, value); 177 #endif 178 chunk->int_field_put(_maxThawingSize_offset, value); 179 } 180 181 #endif // SHARE_RUNTIME_CONTINUATIONJAVACLASSES_INLINE_HPP