3050 oop jthread = thread->threadObj(); |
3050 oop jthread = thread->threadObj(); |
3051 assert (thread != NULL, "no current thread!"); |
3051 assert (thread != NULL, "no current thread!"); |
3052 return JNIHandles::make_local(env, jthread); |
3052 return JNIHandles::make_local(env, jthread); |
3053 JVM_END |
3053 JVM_END |
3054 |
3054 |
3055 class CountStackFramesTC : public ThreadClosure { |
|
3056 int _count; |
|
3057 bool _suspended; |
|
3058 public: |
|
3059 CountStackFramesTC() : _count(0), _suspended(false) {} |
|
3060 virtual void do_thread(Thread* thread) { |
|
3061 JavaThread* jt = (JavaThread*)thread; |
|
3062 if (!jt->is_external_suspend()) { |
|
3063 // To keep same behavior we fail this operation, |
|
3064 // even if it would work perfectly. |
|
3065 return; |
|
3066 } |
|
3067 _suspended = true; |
|
3068 // Count all java activation, i.e., number of vframes. |
|
3069 for (vframeStream vfst(jt); !vfst.at_end(); vfst.next()) { |
|
3070 // Native frames are not counted. |
|
3071 if (!vfst.method()->is_native()) _count++; |
|
3072 } |
|
3073 } |
|
3074 int count() { return _count; } |
|
3075 int suspended() { return _suspended; } |
|
3076 }; |
|
3077 |
|
3078 JVM_ENTRY(jint, JVM_CountStackFrames(JNIEnv* env, jobject jthread)) |
|
3079 JVMWrapper("JVM_CountStackFrames"); |
|
3080 |
|
3081 ThreadsListHandle tlh(thread); |
|
3082 JavaThread* receiver = NULL; |
|
3083 bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL); |
|
3084 if (is_alive) { |
|
3085 // jthread refers to a live JavaThread. |
|
3086 CountStackFramesTC csf; |
|
3087 Handshake::execute(&csf, receiver); |
|
3088 if (!csf.suspended()) { |
|
3089 THROW_MSG_0(vmSymbols::java_lang_IllegalThreadStateException(), |
|
3090 "this thread is not suspended"); |
|
3091 } |
|
3092 return csf.count(); |
|
3093 } |
|
3094 // Implied else: if JavaThread is not alive simply return a count of 0. |
|
3095 return 0; |
|
3096 JVM_END |
|
3097 |
|
3098 |
|
3099 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread)) |
3055 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread)) |
3100 JVMWrapper("JVM_Interrupt"); |
3056 JVMWrapper("JVM_Interrupt"); |
3101 |
3057 |
3102 ThreadsListHandle tlh(thread); |
3058 ThreadsListHandle tlh(thread); |
3103 JavaThread* receiver = NULL; |
3059 JavaThread* receiver = NULL; |