Mercurial > hg > truffle
comparison src/share/vm/prims/jvmtiEnv.cpp @ 609:ea20d7ce26b0
6800721: 3/4 JavaThread::jvmti_thread_state() and JvmtiThreadState::state_for() robustness
Summary: Check for NULL return values from jvmti_thread_state() and state_for() and return a JVM TI error code as appropriate.
Reviewed-by: coleenp, swamyv
author | dcubed |
---|---|
date | Mon, 02 Mar 2009 14:00:23 -0700 |
parents | a61af66fc99e |
children | dcb15a6f342d 4ce7240d622c |
comparison
equal
deleted
inserted
replaced
608:0386097d43d8 | 609:ea20d7ce26b0 |
---|---|
97 // leaving state unset same as data set to NULL | 97 // leaving state unset same as data set to NULL |
98 return JVMTI_ERROR_NONE; | 98 return JVMTI_ERROR_NONE; |
99 } | 99 } |
100 // otherwise, create the state | 100 // otherwise, create the state |
101 state = JvmtiThreadState::state_for(java_thread); | 101 state = JvmtiThreadState::state_for(java_thread); |
102 if (state == NULL) { | |
103 return JVMTI_ERROR_THREAD_NOT_ALIVE; | |
104 } | |
102 } | 105 } |
103 state->env_thread_state(this)->set_agent_thread_local_storage_data((void*)data); | 106 state->env_thread_state(this)->set_agent_thread_local_storage_data((void*)data); |
104 return JVMTI_ERROR_NONE; | 107 return JVMTI_ERROR_NONE; |
105 } /* end SetThreadLocalStorage */ | 108 } /* end SetThreadLocalStorage */ |
106 | 109 |
1306 JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) { | 1309 JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) { |
1307 jvmtiError err = JVMTI_ERROR_NONE; | 1310 jvmtiError err = JVMTI_ERROR_NONE; |
1308 | 1311 |
1309 // retrieve or create JvmtiThreadState. | 1312 // retrieve or create JvmtiThreadState. |
1310 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | 1313 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); |
1314 if (state == NULL) { | |
1315 return JVMTI_ERROR_THREAD_NOT_ALIVE; | |
1316 } | |
1311 uint32_t debug_bits = 0; | 1317 uint32_t debug_bits = 0; |
1312 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { | 1318 if (is_thread_fully_suspended(java_thread, true, &debug_bits)) { |
1313 err = get_frame_count(state, count_ptr); | 1319 err = get_frame_count(state, count_ptr); |
1314 } else { | 1320 } else { |
1315 // get java stack frame count at safepoint. | 1321 // get java stack frame count at safepoint. |
1326 jvmtiError | 1332 jvmtiError |
1327 JvmtiEnv::PopFrame(JavaThread* java_thread) { | 1333 JvmtiEnv::PopFrame(JavaThread* java_thread) { |
1328 JavaThread* current_thread = JavaThread::current(); | 1334 JavaThread* current_thread = JavaThread::current(); |
1329 HandleMark hm(current_thread); | 1335 HandleMark hm(current_thread); |
1330 uint32_t debug_bits = 0; | 1336 uint32_t debug_bits = 0; |
1337 | |
1338 // retrieve or create the state | |
1339 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | |
1340 if (state == NULL) { | |
1341 return JVMTI_ERROR_THREAD_NOT_ALIVE; | |
1342 } | |
1331 | 1343 |
1332 // Check if java_thread is fully suspended | 1344 // Check if java_thread is fully suspended |
1333 if (!is_thread_fully_suspended(java_thread, true /* wait for suspend completion */, &debug_bits)) { | 1345 if (!is_thread_fully_suspended(java_thread, true /* wait for suspend completion */, &debug_bits)) { |
1334 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; | 1346 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; |
1335 } | 1347 } |
1397 // (see call_VM_base() in assembler_<cpu>.cpp). | 1409 // (see call_VM_base() in assembler_<cpu>.cpp). |
1398 | 1410 |
1399 // It's fine to update the thread state here because no JVMTI events | 1411 // It's fine to update the thread state here because no JVMTI events |
1400 // shall be posted for this PopFrame. | 1412 // shall be posted for this PopFrame. |
1401 | 1413 |
1402 // retreive or create the state | |
1403 JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread); | |
1404 | |
1405 state->update_for_pop_top_frame(); | 1414 state->update_for_pop_top_frame(); |
1406 java_thread->set_popframe_condition(JavaThread::popframe_pending_bit); | 1415 java_thread->set_popframe_condition(JavaThread::popframe_pending_bit); |
1407 // Set pending step flag for this popframe and it is cleared when next | 1416 // Set pending step flag for this popframe and it is cleared when next |
1408 // step event is posted. | 1417 // step event is posted. |
1409 state->set_pending_step_for_popframe(); | 1418 state->set_pending_step_for_popframe(); |
1443 jvmtiError | 1452 jvmtiError |
1444 JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) { | 1453 JvmtiEnv::NotifyFramePop(JavaThread* java_thread, jint depth) { |
1445 ResourceMark rm; | 1454 ResourceMark rm; |
1446 uint32_t debug_bits = 0; | 1455 uint32_t debug_bits = 0; |
1447 | 1456 |
1457 JvmtiThreadState *state = JvmtiThreadState::state_for(java_thread); | |
1458 if (state == NULL) { | |
1459 return JVMTI_ERROR_THREAD_NOT_ALIVE; | |
1460 } | |
1461 | |
1448 if (!JvmtiEnv::is_thread_fully_suspended(java_thread, true, &debug_bits)) { | 1462 if (!JvmtiEnv::is_thread_fully_suspended(java_thread, true, &debug_bits)) { |
1449 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; | 1463 return JVMTI_ERROR_THREAD_NOT_SUSPENDED; |
1450 } | 1464 } |
1451 | 1465 |
1452 if (TraceJVMTICalls) { | 1466 if (TraceJVMTICalls) { |
1462 return JVMTI_ERROR_OPAQUE_FRAME; | 1476 return JVMTI_ERROR_OPAQUE_FRAME; |
1463 } | 1477 } |
1464 | 1478 |
1465 assert(vf->frame_pointer() != NULL, "frame pointer mustn't be NULL"); | 1479 assert(vf->frame_pointer() != NULL, "frame pointer mustn't be NULL"); |
1466 | 1480 |
1467 JvmtiThreadState *state = JvmtiThreadState::state_for(java_thread); | |
1468 int frame_number = state->count_frames() - depth; | 1481 int frame_number = state->count_frames() - depth; |
1469 state->env_thread_state(this)->set_frame_pop(frame_number); | 1482 state->env_thread_state(this)->set_frame_pop(frame_number); |
1470 | 1483 |
1471 return JVMTI_ERROR_NONE; | 1484 return JVMTI_ERROR_NONE; |
1472 } /* end NotifyFramePop */ | 1485 } /* end NotifyFramePop */ |