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 void jdk_internal_vm_StackChunk::set_bottom(HeapWord* chunk, int value) {
119   // Used by StackChunkAllocator before the Object has been finished,
120   // so don't cast too oop and use int_field_put in this function.
121   assert(_bottom_offset != 0, "must be set");
122   *(int*)(((char*)chunk) + _bottom_offset) = (int)value;
123 }
124 
125 inline int jdk_internal_vm_StackChunk::sp(oop chunk) {
126   return chunk->int_field_relaxed(_sp_offset);
127 }
128 
129 inline void jdk_internal_vm_StackChunk::set_sp(oop chunk, int value) {
130   chunk->int_field_put_relaxed(_sp_offset, value);
131 }
132 
133 inline void jdk_internal_vm_StackChunk::set_sp(HeapWord* chunk, int value) {
134   // Used by StackChunkAllocator before the Object has been finished,
135   // so don't cast too oop and use int_field_put in this function.
136   assert(_sp_offset != 0, "must be set");
137   *(int*)(((char*)chunk) + _sp_offset) = (int)value;
138 }
139 
140 inline address jdk_internal_vm_StackChunk::pc(oop chunk) {
141   return chunk->address_field(_pc_offset);
142 }
143 
144 inline void jdk_internal_vm_StackChunk::set_pc(oop chunk, address value) {
145   chunk->address_field_put(_pc_offset, value);
146 }
147 
148 inline int jdk_internal_vm_StackChunk::bottom(oop chunk) {
149   return chunk->int_field(_bottom_offset);
150 }
151 
152 inline void jdk_internal_vm_StackChunk::set_bottom(oop chunk, int value) {
153   chunk->int_field_put(_bottom_offset, value);
154 }
155 
156 inline uint8_t jdk_internal_vm_StackChunk::flags(oop chunk) {
157   return Atomic::load(chunk->field_addr<uint8_t>(_flags_offset));
158 }
159 
160 inline void jdk_internal_vm_StackChunk::set_flags(oop chunk, uint8_t value) {
161   Atomic::store(chunk->field_addr<uint8_t>(_flags_offset), value);
162 }
163 
164 inline uint8_t jdk_internal_vm_StackChunk::flags_acquire(oop chunk) {
165   return Atomic::load_acquire(chunk->field_addr<uint8_t>(_flags_offset));
166 }
167 
168 inline void jdk_internal_vm_StackChunk::release_set_flags(oop chunk, uint8_t value) {
169   Atomic::release_store(chunk->field_addr<uint8_t>(_flags_offset), value);
170 }
171 
172 inline bool jdk_internal_vm_StackChunk::try_set_flags(oop chunk, uint8_t expected_value, uint8_t new_value) {
173   return Atomic::cmpxchg(chunk->field_addr<uint8_t>(_flags_offset), expected_value, new_value) == expected_value;
174 }
175 
176 inline int jdk_internal_vm_StackChunk::maxThawingSize(oop chunk) {
177   return chunk->int_field(_maxThawingSize_offset);
178 }
179 
180 inline void jdk_internal_vm_StackChunk::set_maxThawingSize(oop chunk, int value) {
181 #ifdef ASSERT
182   jint old = maxThawingSize(chunk);
183   log_develop_trace(continuations)("%s max_size: %d -> %d", value >= old ? "add" : "sub", old, value);
184 #endif
185   chunk->int_field_put(_maxThawingSize_offset, value);
186 }
187 
188 inline uint8_t jdk_internal_vm_StackChunk::lockStackSize(oop chunk) {
189   return Atomic::load(chunk->field_addr<uint8_t>(_lockStackSize_offset));
190 }
191 
192 inline void jdk_internal_vm_StackChunk::set_lockStackSize(oop chunk, uint8_t value) {
193   Atomic::store(chunk->field_addr<uint8_t>(_lockStackSize_offset), value);
194 }
195 
196 inline address jdk_internal_vm_StackChunk::objectWaiter(oop chunk) {
197   return chunk->address_field(_objectWaiter_offset);
198 }
199 
200 inline void jdk_internal_vm_StackChunk::set_objectWaiter(oop chunk, address value) {
201   chunk->address_field_put(_objectWaiter_offset, value);
202 }
203 
204 #endif // SHARE_RUNTIME_CONTINUATIONJAVACLASSES_INLINE_HPP