< prev index next >

src/hotspot/share/classfile/javaClasses.cpp

Print this page

2079   InstanceKlass* k = vmClasses::ThreadGroup_klass();
2080   THREADGROUP_FIELDS_DO(FIELD_COMPUTE_OFFSET);
2081 }
2082 
2083 #if INCLUDE_CDS
2084 void java_lang_ThreadGroup::serialize_offsets(SerializeClosure* f) {
2085   THREADGROUP_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
2086 }
2087 #endif
2088 
2089 
2090 // java_lang_VirtualThread
2091 
2092 int java_lang_VirtualThread::static_vthread_scope_offset;
2093 int java_lang_VirtualThread::_carrierThread_offset;
2094 int java_lang_VirtualThread::_continuation_offset;
2095 int java_lang_VirtualThread::_state_offset;
2096 int java_lang_VirtualThread::_next_offset;
2097 int java_lang_VirtualThread::_onWaitingList_offset;
2098 int java_lang_VirtualThread::_notified_offset;

2099 int java_lang_VirtualThread::_timeout_offset;
2100 int java_lang_VirtualThread::_objectWaiter_offset;
2101 
2102 #define VTHREAD_FIELDS_DO(macro) \
2103   macro(static_vthread_scope_offset,       k, "VTHREAD_SCOPE",      continuationscope_signature, true);  \
2104   macro(_carrierThread_offset,             k, "carrierThread",      thread_signature,            false); \
2105   macro(_continuation_offset,              k, "cont",               continuation_signature,      false); \
2106   macro(_state_offset,                     k, "state",              int_signature,               false); \
2107   macro(_next_offset,                      k, "next",               vthread_signature,           false); \
2108   macro(_onWaitingList_offset,             k, "onWaitingList",      bool_signature,              false); \
2109   macro(_notified_offset,                  k, "notified",           bool_signature,              false); \

2110   macro(_timeout_offset,                   k, "timeout",            long_signature,              false);
2111 
2112 
2113 void java_lang_VirtualThread::compute_offsets() {
2114   InstanceKlass* k = vmClasses::VirtualThread_klass();
2115   VTHREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
2116   VTHREAD_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
2117 }
2118 
2119 bool java_lang_VirtualThread::is_instance(oop obj) {
2120   return obj != nullptr && is_subclass(obj->klass());
2121 }
2122 
2123 oop java_lang_VirtualThread::carrier_thread(oop vthread) {
2124   oop thread = vthread->obj_field(_carrierThread_offset);
2125   return thread;
2126 }
2127 
2128 oop java_lang_VirtualThread::continuation(oop vthread) {
2129   oop cont = vthread->obj_field(_continuation_offset);
2130   return cont;
2131 }
2132 
2133 int java_lang_VirtualThread::state(oop vthread) {
2134   return vthread->int_field_acquire(_state_offset);
2135 }
2136 
2137 void java_lang_VirtualThread::set_state(oop vthread, int state) {
2138   vthread->release_int_field_put(_state_offset, state);
2139 }
2140 
2141 int java_lang_VirtualThread::cmpxchg_state(oop vthread, int old_state, int new_state) {
2142   jint* addr = vthread->field_addr<jint>(_state_offset);
2143   int res = Atomic::cmpxchg(addr, old_state, new_state);
2144   return res;

2159 bool java_lang_VirtualThread::set_onWaitingList(oop vthread, OopHandle& list_head) {
2160   jboolean* addr = vthread->field_addr<jboolean>(_onWaitingList_offset);
2161   jboolean vthread_on_list = Atomic::load(addr);
2162   if (!vthread_on_list) {
2163     vthread_on_list = Atomic::cmpxchg(addr, (jboolean)JNI_FALSE, (jboolean)JNI_TRUE);
2164     if (!vthread_on_list) {
2165       for (;;) {
2166         oop head = list_head.resolve();
2167         java_lang_VirtualThread::set_next(vthread, head);
2168         if (list_head.cmpxchg(head, vthread) == head) return true;
2169       }
2170     }
2171   }
2172   return false; // already on waiting list
2173 }
2174 
2175 void java_lang_VirtualThread::set_notified(oop vthread, jboolean value) {
2176   vthread->bool_field_put_volatile(_notified_offset, value);
2177 }
2178 




2179 jlong java_lang_VirtualThread::timeout(oop vthread) {
2180   return vthread->long_field(_timeout_offset);
2181 }
2182 
2183 void java_lang_VirtualThread::set_timeout(oop vthread, jlong value) {
2184   vthread->long_field_put(_timeout_offset, value);
2185 }
2186 
2187 JavaThreadStatus java_lang_VirtualThread::map_state_to_thread_status(int state) {
2188   JavaThreadStatus status = JavaThreadStatus::NEW;
2189   switch (state & ~SUSPENDED) {
2190     case NEW:
2191       status = JavaThreadStatus::NEW;
2192       break;
2193     case STARTED:
2194     case RUNNING:
2195     case PARKING:
2196     case TIMED_PARKING:
2197     case UNPARKED:
2198     case YIELDING:

2079   InstanceKlass* k = vmClasses::ThreadGroup_klass();
2080   THREADGROUP_FIELDS_DO(FIELD_COMPUTE_OFFSET);
2081 }
2082 
2083 #if INCLUDE_CDS
2084 void java_lang_ThreadGroup::serialize_offsets(SerializeClosure* f) {
2085   THREADGROUP_FIELDS_DO(FIELD_SERIALIZE_OFFSET);
2086 }
2087 #endif
2088 
2089 
2090 // java_lang_VirtualThread
2091 
2092 int java_lang_VirtualThread::static_vthread_scope_offset;
2093 int java_lang_VirtualThread::_carrierThread_offset;
2094 int java_lang_VirtualThread::_continuation_offset;
2095 int java_lang_VirtualThread::_state_offset;
2096 int java_lang_VirtualThread::_next_offset;
2097 int java_lang_VirtualThread::_onWaitingList_offset;
2098 int java_lang_VirtualThread::_notified_offset;
2099 int java_lang_VirtualThread::_interruptible_wait_offset;
2100 int java_lang_VirtualThread::_timeout_offset;
2101 int java_lang_VirtualThread::_objectWaiter_offset;
2102 
2103 #define VTHREAD_FIELDS_DO(macro) \
2104   macro(static_vthread_scope_offset,       k, "VTHREAD_SCOPE",      continuationscope_signature, true);  \
2105   macro(_carrierThread_offset,             k, "carrierThread",      thread_signature,            false); \
2106   macro(_continuation_offset,              k, "cont",               continuation_signature,      false); \
2107   macro(_state_offset,                     k, "state",              int_signature,               false); \
2108   macro(_next_offset,                      k, "next",               vthread_signature,           false); \
2109   macro(_onWaitingList_offset,             k, "onWaitingList",      bool_signature,              false); \
2110   macro(_notified_offset,                  k, "notified",           bool_signature,              false); \
2111   macro(_interruptible_wait_offset,        k, "interruptableWait",  bool_signature,              false); \
2112   macro(_timeout_offset,                   k, "timeout",            long_signature,              false);
2113 
2114 
2115 void java_lang_VirtualThread::compute_offsets() {
2116   InstanceKlass* k = vmClasses::VirtualThread_klass();
2117   VTHREAD_FIELDS_DO(FIELD_COMPUTE_OFFSET);
2118   VTHREAD_INJECTED_FIELDS(INJECTED_FIELD_COMPUTE_OFFSET);
2119 }
2120 
2121 bool java_lang_VirtualThread::is_instance(oop obj) {
2122   return obj != nullptr && is_subclass(obj->klass());
2123 }
2124 
2125 oop java_lang_VirtualThread::carrier_thread(oop vthread) {
2126   oop thread = vthread->obj_field_acquire(_carrierThread_offset);
2127   return thread;
2128 }
2129 
2130 oop java_lang_VirtualThread::continuation(oop vthread) {
2131   oop cont = vthread->obj_field(_continuation_offset);
2132   return cont;
2133 }
2134 
2135 int java_lang_VirtualThread::state(oop vthread) {
2136   return vthread->int_field_acquire(_state_offset);
2137 }
2138 
2139 void java_lang_VirtualThread::set_state(oop vthread, int state) {
2140   vthread->release_int_field_put(_state_offset, state);
2141 }
2142 
2143 int java_lang_VirtualThread::cmpxchg_state(oop vthread, int old_state, int new_state) {
2144   jint* addr = vthread->field_addr<jint>(_state_offset);
2145   int res = Atomic::cmpxchg(addr, old_state, new_state);
2146   return res;

2161 bool java_lang_VirtualThread::set_onWaitingList(oop vthread, OopHandle& list_head) {
2162   jboolean* addr = vthread->field_addr<jboolean>(_onWaitingList_offset);
2163   jboolean vthread_on_list = Atomic::load(addr);
2164   if (!vthread_on_list) {
2165     vthread_on_list = Atomic::cmpxchg(addr, (jboolean)JNI_FALSE, (jboolean)JNI_TRUE);
2166     if (!vthread_on_list) {
2167       for (;;) {
2168         oop head = list_head.resolve();
2169         java_lang_VirtualThread::set_next(vthread, head);
2170         if (list_head.cmpxchg(head, vthread) == head) return true;
2171       }
2172     }
2173   }
2174   return false; // already on waiting list
2175 }
2176 
2177 void java_lang_VirtualThread::set_notified(oop vthread, jboolean value) {
2178   vthread->bool_field_put_volatile(_notified_offset, value);
2179 }
2180 
2181 void java_lang_VirtualThread::set_interruptible_wait(oop vthread, jboolean value) {
2182   vthread->bool_field_put_volatile(_interruptible_wait_offset, value);
2183 }
2184 
2185 jlong java_lang_VirtualThread::timeout(oop vthread) {
2186   return vthread->long_field(_timeout_offset);
2187 }
2188 
2189 void java_lang_VirtualThread::set_timeout(oop vthread, jlong value) {
2190   vthread->long_field_put(_timeout_offset, value);
2191 }
2192 
2193 JavaThreadStatus java_lang_VirtualThread::map_state_to_thread_status(int state) {
2194   JavaThreadStatus status = JavaThreadStatus::NEW;
2195   switch (state & ~SUSPENDED) {
2196     case NEW:
2197       status = JavaThreadStatus::NEW;
2198       break;
2199     case STARTED:
2200     case RUNNING:
2201     case PARKING:
2202     case TIMED_PARKING:
2203     case UNPARKED:
2204     case YIELDING:
< prev index next >