< prev index next >

src/share/vm/prims/jvmtiEnv.cpp

Print this page
rev 9067 : 8139040: Fix initializations before ShouldNotReachHere()


3047   }
3048 
3049   delete rmonitor;
3050 
3051   return JVMTI_ERROR_NONE;
3052 } /* end DestroyRawMonitor */
3053 
3054 
3055 // rmonitor - pre-checked for validity
3056 jvmtiError
3057 JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) {
3058   if (Threads::number_of_threads() == 0) {
3059     // No JavaThreads exist so ObjectMonitor enter cannot be
3060     // used, add this raw monitor to the pending list.
3061     // The pending monitors will be actually entered when
3062     // the VM is setup.
3063     // See transition_pending_raw_monitors in create_vm()
3064     // in thread.cpp.
3065     JvmtiPendingMonitors::enter(rmonitor);
3066   } else {
3067     int r;
3068     Thread* thread = Thread::current();
3069 
3070     if (thread->is_Java_thread()) {
3071       JavaThread* current_thread = (JavaThread*)thread;
3072 
3073 #ifdef PROPER_TRANSITIONS
3074       // Not really unknown but ThreadInVMfromNative does more than we want
3075       ThreadInVMfromUnknown __tiv;
3076       {
3077         ThreadBlockInVM __tbivm(current_thread);
3078         r = rmonitor->raw_enter(current_thread);
3079       }
3080 #else
3081       /* Transition to thread_blocked without entering vm state          */
3082       /* This is really evil. Normally you can't undo _thread_blocked    */
3083       /* transitions like this because it would cause us to miss a       */
3084       /* safepoint but since the thread was already in _thread_in_native */
3085       /* the thread is not leaving a safepoint safe state and it will    */
3086       /* block when it tries to return from native. We can't safepoint   */
3087       /* block in here because we could deadlock the vmthread. Blech.    */


3110     if (r != ObjectMonitor::OM_OK) {  // robustness
3111       return JVMTI_ERROR_INTERNAL;
3112     }
3113   }
3114   return JVMTI_ERROR_NONE;
3115 } /* end RawMonitorEnter */
3116 
3117 
3118 // rmonitor - pre-checked for validity
3119 jvmtiError
3120 JvmtiEnv::RawMonitorExit(JvmtiRawMonitor * rmonitor) {
3121   jvmtiError err = JVMTI_ERROR_NONE;
3122 
3123   if (Threads::number_of_threads() == 0) {
3124     // No JavaThreads exist so just remove this monitor from the pending list.
3125     // Bool value from exit is false if rmonitor is not in the list.
3126     if (!JvmtiPendingMonitors::exit(rmonitor)) {
3127       err = JVMTI_ERROR_NOT_MONITOR_OWNER;
3128     }
3129   } else {
3130     int r;
3131     Thread* thread = Thread::current();
3132 
3133     if (thread->is_Java_thread()) {
3134       JavaThread* current_thread = (JavaThread*)thread;
3135 #ifdef PROPER_TRANSITIONS
3136       // Not really unknown but ThreadInVMfromNative does more than we want
3137       ThreadInVMfromUnknown __tiv;
3138 #endif /* PROPER_TRANSITIONS */
3139       r = rmonitor->raw_exit(current_thread);
3140     } else {
3141       if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
3142         r = rmonitor->raw_exit(thread);
3143       } else {
3144         ShouldNotReachHere();
3145       }
3146     }
3147 
3148     if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
3149       err = JVMTI_ERROR_NOT_MONITOR_OWNER;
3150     } else {
3151       assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked");
3152       if (r != ObjectMonitor::OM_OK) {  // robustness
3153         err = JVMTI_ERROR_INTERNAL;
3154       }
3155     }
3156   }
3157   return err;
3158 } /* end RawMonitorExit */
3159 
3160 
3161 // rmonitor - pre-checked for validity
3162 jvmtiError
3163 JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) {
3164   int r;
3165   Thread* thread = Thread::current();
3166 
3167   if (thread->is_Java_thread()) {
3168     JavaThread* current_thread = (JavaThread*)thread;
3169 #ifdef PROPER_TRANSITIONS
3170     // Not really unknown but ThreadInVMfromNative does more than we want
3171     ThreadInVMfromUnknown __tiv;
3172     {
3173       ThreadBlockInVM __tbivm(current_thread);
3174       r = rmonitor->raw_wait(millis, true, current_thread);
3175     }
3176 #else
3177     /* Transition to thread_blocked without entering vm state          */
3178     /* This is really evil. Normally you can't undo _thread_blocked    */
3179     /* transitions like this because it would cause us to miss a       */
3180     /* safepoint but since the thread was already in _thread_in_native */
3181     /* the thread is not leaving a safepoint safe state and it will    */
3182     /* block when it tries to return from native. We can't safepoint   */
3183     /* block in here because we could deadlock the vmthread. Blech.    */
3184 


3203   }
3204 
3205   switch (r) {
3206   case ObjectMonitor::OM_INTERRUPTED:
3207     return JVMTI_ERROR_INTERRUPT;
3208   case ObjectMonitor::OM_ILLEGAL_MONITOR_STATE:
3209     return JVMTI_ERROR_NOT_MONITOR_OWNER;
3210   }
3211   assert(r == ObjectMonitor::OM_OK, "raw_wait should have worked");
3212   if (r != ObjectMonitor::OM_OK) {  // robustness
3213     return JVMTI_ERROR_INTERNAL;
3214   }
3215 
3216   return JVMTI_ERROR_NONE;
3217 } /* end RawMonitorWait */
3218 
3219 
3220 // rmonitor - pre-checked for validity
3221 jvmtiError
3222 JvmtiEnv::RawMonitorNotify(JvmtiRawMonitor * rmonitor) {
3223   int r;
3224   Thread* thread = Thread::current();
3225 
3226   if (thread->is_Java_thread()) {
3227     JavaThread* current_thread = (JavaThread*)thread;
3228     // Not really unknown but ThreadInVMfromNative does more than we want
3229     ThreadInVMfromUnknown __tiv;
3230     r = rmonitor->raw_notify(current_thread);
3231   } else {
3232     if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
3233       r = rmonitor->raw_notify(thread);
3234     } else {
3235       ShouldNotReachHere();
3236     }
3237   }
3238 
3239   if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
3240     return JVMTI_ERROR_NOT_MONITOR_OWNER;
3241   }
3242   assert(r == ObjectMonitor::OM_OK, "raw_notify should have worked");
3243   if (r != ObjectMonitor::OM_OK) {  // robustness
3244     return JVMTI_ERROR_INTERNAL;
3245   }
3246 
3247   return JVMTI_ERROR_NONE;
3248 } /* end RawMonitorNotify */
3249 
3250 
3251 // rmonitor - pre-checked for validity
3252 jvmtiError
3253 JvmtiEnv::RawMonitorNotifyAll(JvmtiRawMonitor * rmonitor) {
3254   int r;
3255   Thread* thread = Thread::current();
3256 
3257   if (thread->is_Java_thread()) {
3258     JavaThread* current_thread = (JavaThread*)thread;
3259     ThreadInVMfromUnknown __tiv;
3260     r = rmonitor->raw_notifyAll(current_thread);
3261   } else {
3262     if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
3263       r = rmonitor->raw_notifyAll(thread);
3264     } else {
3265       ShouldNotReachHere();
3266     }
3267   }
3268 
3269   if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
3270     return JVMTI_ERROR_NOT_MONITOR_OWNER;
3271   }
3272   assert(r == ObjectMonitor::OM_OK, "raw_notifyAll should have worked");
3273   if (r != ObjectMonitor::OM_OK) {  // robustness
3274     return JVMTI_ERROR_INTERNAL;




3047   }
3048 
3049   delete rmonitor;
3050 
3051   return JVMTI_ERROR_NONE;
3052 } /* end DestroyRawMonitor */
3053 
3054 
3055 // rmonitor - pre-checked for validity
3056 jvmtiError
3057 JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) {
3058   if (Threads::number_of_threads() == 0) {
3059     // No JavaThreads exist so ObjectMonitor enter cannot be
3060     // used, add this raw monitor to the pending list.
3061     // The pending monitors will be actually entered when
3062     // the VM is setup.
3063     // See transition_pending_raw_monitors in create_vm()
3064     // in thread.cpp.
3065     JvmtiPendingMonitors::enter(rmonitor);
3066   } else {
3067     int r = 0;
3068     Thread* thread = Thread::current();
3069 
3070     if (thread->is_Java_thread()) {
3071       JavaThread* current_thread = (JavaThread*)thread;
3072 
3073 #ifdef PROPER_TRANSITIONS
3074       // Not really unknown but ThreadInVMfromNative does more than we want
3075       ThreadInVMfromUnknown __tiv;
3076       {
3077         ThreadBlockInVM __tbivm(current_thread);
3078         r = rmonitor->raw_enter(current_thread);
3079       }
3080 #else
3081       /* Transition to thread_blocked without entering vm state          */
3082       /* This is really evil. Normally you can't undo _thread_blocked    */
3083       /* transitions like this because it would cause us to miss a       */
3084       /* safepoint but since the thread was already in _thread_in_native */
3085       /* the thread is not leaving a safepoint safe state and it will    */
3086       /* block when it tries to return from native. We can't safepoint   */
3087       /* block in here because we could deadlock the vmthread. Blech.    */


3110     if (r != ObjectMonitor::OM_OK) {  // robustness
3111       return JVMTI_ERROR_INTERNAL;
3112     }
3113   }
3114   return JVMTI_ERROR_NONE;
3115 } /* end RawMonitorEnter */
3116 
3117 
3118 // rmonitor - pre-checked for validity
3119 jvmtiError
3120 JvmtiEnv::RawMonitorExit(JvmtiRawMonitor * rmonitor) {
3121   jvmtiError err = JVMTI_ERROR_NONE;
3122 
3123   if (Threads::number_of_threads() == 0) {
3124     // No JavaThreads exist so just remove this monitor from the pending list.
3125     // Bool value from exit is false if rmonitor is not in the list.
3126     if (!JvmtiPendingMonitors::exit(rmonitor)) {
3127       err = JVMTI_ERROR_NOT_MONITOR_OWNER;
3128     }
3129   } else {
3130     int r = 0;
3131     Thread* thread = Thread::current();
3132 
3133     if (thread->is_Java_thread()) {
3134       JavaThread* current_thread = (JavaThread*)thread;
3135 #ifdef PROPER_TRANSITIONS
3136       // Not really unknown but ThreadInVMfromNative does more than we want
3137       ThreadInVMfromUnknown __tiv;
3138 #endif /* PROPER_TRANSITIONS */
3139       r = rmonitor->raw_exit(current_thread);
3140     } else {
3141       if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
3142         r = rmonitor->raw_exit(thread);
3143       } else {
3144         ShouldNotReachHere();
3145       }
3146     }
3147 
3148     if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
3149       err = JVMTI_ERROR_NOT_MONITOR_OWNER;
3150     } else {
3151       assert(r == ObjectMonitor::OM_OK, "raw_exit should have worked");
3152       if (r != ObjectMonitor::OM_OK) {  // robustness
3153         err = JVMTI_ERROR_INTERNAL;
3154       }
3155     }
3156   }
3157   return err;
3158 } /* end RawMonitorExit */
3159 
3160 
3161 // rmonitor - pre-checked for validity
3162 jvmtiError
3163 JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) {
3164   int r = 0;
3165   Thread* thread = Thread::current();
3166 
3167   if (thread->is_Java_thread()) {
3168     JavaThread* current_thread = (JavaThread*)thread;
3169 #ifdef PROPER_TRANSITIONS
3170     // Not really unknown but ThreadInVMfromNative does more than we want
3171     ThreadInVMfromUnknown __tiv;
3172     {
3173       ThreadBlockInVM __tbivm(current_thread);
3174       r = rmonitor->raw_wait(millis, true, current_thread);
3175     }
3176 #else
3177     /* Transition to thread_blocked without entering vm state          */
3178     /* This is really evil. Normally you can't undo _thread_blocked    */
3179     /* transitions like this because it would cause us to miss a       */
3180     /* safepoint but since the thread was already in _thread_in_native */
3181     /* the thread is not leaving a safepoint safe state and it will    */
3182     /* block when it tries to return from native. We can't safepoint   */
3183     /* block in here because we could deadlock the vmthread. Blech.    */
3184 


3203   }
3204 
3205   switch (r) {
3206   case ObjectMonitor::OM_INTERRUPTED:
3207     return JVMTI_ERROR_INTERRUPT;
3208   case ObjectMonitor::OM_ILLEGAL_MONITOR_STATE:
3209     return JVMTI_ERROR_NOT_MONITOR_OWNER;
3210   }
3211   assert(r == ObjectMonitor::OM_OK, "raw_wait should have worked");
3212   if (r != ObjectMonitor::OM_OK) {  // robustness
3213     return JVMTI_ERROR_INTERNAL;
3214   }
3215 
3216   return JVMTI_ERROR_NONE;
3217 } /* end RawMonitorWait */
3218 
3219 
3220 // rmonitor - pre-checked for validity
3221 jvmtiError
3222 JvmtiEnv::RawMonitorNotify(JvmtiRawMonitor * rmonitor) {
3223   int r = 0;
3224   Thread* thread = Thread::current();
3225 
3226   if (thread->is_Java_thread()) {
3227     JavaThread* current_thread = (JavaThread*)thread;
3228     // Not really unknown but ThreadInVMfromNative does more than we want
3229     ThreadInVMfromUnknown __tiv;
3230     r = rmonitor->raw_notify(current_thread);
3231   } else {
3232     if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
3233       r = rmonitor->raw_notify(thread);
3234     } else {
3235       ShouldNotReachHere();
3236     }
3237   }
3238 
3239   if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
3240     return JVMTI_ERROR_NOT_MONITOR_OWNER;
3241   }
3242   assert(r == ObjectMonitor::OM_OK, "raw_notify should have worked");
3243   if (r != ObjectMonitor::OM_OK) {  // robustness
3244     return JVMTI_ERROR_INTERNAL;
3245   }
3246 
3247   return JVMTI_ERROR_NONE;
3248 } /* end RawMonitorNotify */
3249 
3250 
3251 // rmonitor - pre-checked for validity
3252 jvmtiError
3253 JvmtiEnv::RawMonitorNotifyAll(JvmtiRawMonitor * rmonitor) {
3254   int r = 0;
3255   Thread* thread = Thread::current();
3256 
3257   if (thread->is_Java_thread()) {
3258     JavaThread* current_thread = (JavaThread*)thread;
3259     ThreadInVMfromUnknown __tiv;
3260     r = rmonitor->raw_notifyAll(current_thread);
3261   } else {
3262     if (thread->is_VM_thread() || thread->is_ConcurrentGC_thread()) {
3263       r = rmonitor->raw_notifyAll(thread);
3264     } else {
3265       ShouldNotReachHere();
3266     }
3267   }
3268 
3269   if (r == ObjectMonitor::OM_ILLEGAL_MONITOR_STATE) {
3270     return JVMTI_ERROR_NOT_MONITOR_OWNER;
3271   }
3272   assert(r == ObjectMonitor::OM_OK, "raw_notifyAll should have worked");
3273   if (r != ObjectMonitor::OM_OK) {  // robustness
3274     return JVMTI_ERROR_INTERNAL;


< prev index next >