79 # include "jvm_linux.h"
80 #endif
81 #ifdef TARGET_OS_FAMILY_solaris
82 # include "jvm_solaris.h"
83 #endif
84 #ifdef TARGET_OS_FAMILY_windows
85 # include "jvm_windows.h"
86 #endif
87 #ifdef TARGET_OS_FAMILY_aix
88 # include "jvm_aix.h"
89 #endif
90 #ifdef TARGET_OS_FAMILY_bsd
91 # include "jvm_bsd.h"
92 #endif
93
94 #if INCLUDE_ALL_GCS
95 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
96 #endif // INCLUDE_ALL_GCS
97
98 #include <errno.h>
99
100 #ifndef USDT2
101 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
102 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
103 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
104 #endif /* !USDT2 */
105
106 /*
107 NOTE about use of any ctor or function call that can trigger a safepoint/GC:
108 such ctors and calls MUST NOT come between an oop declaration/init and its
109 usage because if objects are move this may cause various memory stomps, bus
110 errors and segfaults. Here is a cookbook for causing so called "naked oop
111 failures":
112
113 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
114 JVMWrapper("JVM_GetClassDeclaredFields");
115
116 // Object address to be held directly in mirror & not visible to GC
117 oop mirror = JNIHandles::resolve_non_null(ofClass);
118
3144 }
3145 }
3146
3147 if (throw_illegal_thread_state) {
3148 THROW(vmSymbols::java_lang_IllegalThreadStateException());
3149 }
3150
3151 assert(native_thread != NULL, "Starting null thread?");
3152
3153 if (native_thread->osthread() == NULL) {
3154 // No one should hold a reference to the 'native_thread'.
3155 delete native_thread;
3156 if (JvmtiExport::should_post_resource_exhausted()) {
3157 JvmtiExport::post_resource_exhausted(
3158 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
3159 "unable to create new native thread");
3160 }
3161 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
3162 "unable to create new native thread");
3163 }
3164
3165 Thread::start(native_thread);
3166
3167 JVM_END
3168
3169 // JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints
3170 // before the quasi-asynchronous exception is delivered. This is a little obtrusive,
3171 // but is thought to be reliable and simple. In the case, where the receiver is the
3172 // same thread as the sender, no safepoint is needed.
3173 JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable))
3174 JVMWrapper("JVM_StopThread");
3175
3176 oop java_throwable = JNIHandles::resolve(throwable);
3177 if (java_throwable == NULL) {
3178 THROW(vmSymbols::java_lang_NullPointerException());
3179 }
3180 oop java_thread = JNIHandles::resolve_non_null(jthread);
3181 JavaThread* receiver = java_lang_Thread::thread(java_thread);
3182 Events::log_exception(JavaThread::current(),
3183 "JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]",
|
79 # include "jvm_linux.h"
80 #endif
81 #ifdef TARGET_OS_FAMILY_solaris
82 # include "jvm_solaris.h"
83 #endif
84 #ifdef TARGET_OS_FAMILY_windows
85 # include "jvm_windows.h"
86 #endif
87 #ifdef TARGET_OS_FAMILY_aix
88 # include "jvm_aix.h"
89 #endif
90 #ifdef TARGET_OS_FAMILY_bsd
91 # include "jvm_bsd.h"
92 #endif
93
94 #if INCLUDE_ALL_GCS
95 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
96 #endif // INCLUDE_ALL_GCS
97
98 #include <errno.h>
99 #include <jfr/recorder/jfrRecorder.hpp>
100
101 #ifndef USDT2
102 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__begin, long long);
103 HS_DTRACE_PROBE_DECL1(hotspot, thread__sleep__end, int);
104 HS_DTRACE_PROBE_DECL0(hotspot, thread__yield);
105 #endif /* !USDT2 */
106
107 /*
108 NOTE about use of any ctor or function call that can trigger a safepoint/GC:
109 such ctors and calls MUST NOT come between an oop declaration/init and its
110 usage because if objects are move this may cause various memory stomps, bus
111 errors and segfaults. Here is a cookbook for causing so called "naked oop
112 failures":
113
114 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
115 JVMWrapper("JVM_GetClassDeclaredFields");
116
117 // Object address to be held directly in mirror & not visible to GC
118 oop mirror = JNIHandles::resolve_non_null(ofClass);
119
3145 }
3146 }
3147
3148 if (throw_illegal_thread_state) {
3149 THROW(vmSymbols::java_lang_IllegalThreadStateException());
3150 }
3151
3152 assert(native_thread != NULL, "Starting null thread?");
3153
3154 if (native_thread->osthread() == NULL) {
3155 // No one should hold a reference to the 'native_thread'.
3156 delete native_thread;
3157 if (JvmtiExport::should_post_resource_exhausted()) {
3158 JvmtiExport::post_resource_exhausted(
3159 JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
3160 "unable to create new native thread");
3161 }
3162 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
3163 "unable to create new native thread");
3164 }
3165
3166 #if INCLUDE_JFR
3167 if (JfrRecorder::is_recording() && EventThreadStart::is_enabled() &&
3168 EventThreadStart::is_stacktrace_enabled()) {
3169 JfrThreadLocal* tl = native_thread->jfr_thread_local();
3170 // skip Thread.start() and Thread.start0()
3171 tl->set_cached_stack_trace_id(JfrStackTraceRepository::record(thread, 2));
3172 }
3173 #endif
3174
3175 Thread::start(native_thread);
3176
3177 JVM_END
3178
3179 // JVM_Stop is implemented using a VM_Operation, so threads are forced to safepoints
3180 // before the quasi-asynchronous exception is delivered. This is a little obtrusive,
3181 // but is thought to be reliable and simple. In the case, where the receiver is the
3182 // same thread as the sender, no safepoint is needed.
3183 JVM_ENTRY(void, JVM_StopThread(JNIEnv* env, jobject jthread, jobject throwable))
3184 JVMWrapper("JVM_StopThread");
3185
3186 oop java_throwable = JNIHandles::resolve(throwable);
3187 if (java_throwable == NULL) {
3188 THROW(vmSymbols::java_lang_NullPointerException());
3189 }
3190 oop java_thread = JNIHandles::resolve_non_null(jthread);
3191 JavaThread* receiver = java_lang_Thread::thread(java_thread);
3192 Events::log_exception(JavaThread::current(),
3193 "JVM_StopThread thread JavaThread " INTPTR_FORMAT " as oop " INTPTR_FORMAT " [exception " INTPTR_FORMAT "]",
|