495 return false;
496 }
497 }
498 // We aren't allowed to wait for the external suspend to complete
499 // so if the other thread isn't externally suspended we need to
500 // let the caller know.
501 else if (!thr->is_ext_suspend_completed_with_lock(bits)) {
502 return false;
503 }
504 }
505
506 return true;
507 }
508
509
510 // In the fullness of time, all users of the method should instead
511 // directly use allocate, besides being cleaner and faster, this will
512 // mean much better out of memory handling
513 unsigned char *
514 JvmtiEnvBase::jvmtiMalloc(jlong size) {
515 unsigned char* mem;
516 jvmtiError result = allocate(size, &mem);
517 assert(result == JVMTI_ERROR_NONE, "Allocate failed");
518 return mem;
519 }
520
521
522 //
523 // Threads
524 //
525
526 jobject *
527 JvmtiEnvBase::new_jobjectArray(int length, Handle *handles) {
528 if (length == 0) {
529 return NULL;
530 }
531
532 jobject *objArray = (jobject *) jvmtiMalloc(sizeof(jobject) * length);
533 NULL_CHECK(objArray, NULL);
534
535 for (int i=0; i<length; i++) {
1015 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1016 }
1017 HandleMark hm;
1018 Handle th(owning_thread->threadObj());
1019 ret.owner = (jthread)jni_reference(calling_thread, th);
1020 }
1021 // implied else: no owner
1022 }
1023
1024 if (owning_thread != NULL) { // monitor is owned
1025 // The recursions field of a monitor does not reflect recursions
1026 // as lightweight locks before inflating the monitor are not included.
1027 // We have to count the number of recursive monitor entries the hard way.
1028 // We pass a handle to survive any GCs along the way.
1029 ResourceMark rm;
1030 ret.entry_count = count_locked_objects(owning_thread, hobj);
1031 }
1032 // implied else: entry_count == 0
1033 }
1034
1035 jint nWant, nWait;
1036 if (mon != NULL) {
1037 // this object has a heavyweight monitor
1038 nWant = mon->contentions(); // # of threads contending for monitor
1039 nWait = mon->waiters(); // # of threads in Object.wait()
1040 ret.waiter_count = nWant + nWait;
1041 ret.notify_waiter_count = nWait;
1042 } else {
1043 // this object has a lightweight monitor
1044 ret.waiter_count = 0;
1045 ret.notify_waiter_count = 0;
1046 }
1047
1048 // Allocate memory for heavyweight and lightweight monitor.
1049 jvmtiError err;
1050 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
1051 if (err != JVMTI_ERROR_NONE) {
1052 return err;
1053 }
1054 err = allocate(ret.notify_waiter_count * sizeof(jthread *),
1055 (unsigned char**)&ret.notify_waiters);
|
495 return false;
496 }
497 }
498 // We aren't allowed to wait for the external suspend to complete
499 // so if the other thread isn't externally suspended we need to
500 // let the caller know.
501 else if (!thr->is_ext_suspend_completed_with_lock(bits)) {
502 return false;
503 }
504 }
505
506 return true;
507 }
508
509
510 // In the fullness of time, all users of the method should instead
511 // directly use allocate, besides being cleaner and faster, this will
512 // mean much better out of memory handling
513 unsigned char *
514 JvmtiEnvBase::jvmtiMalloc(jlong size) {
515 unsigned char* mem = NULL;
516 jvmtiError result = allocate(size, &mem);
517 assert(result == JVMTI_ERROR_NONE, "Allocate failed");
518 return mem;
519 }
520
521
522 //
523 // Threads
524 //
525
526 jobject *
527 JvmtiEnvBase::new_jobjectArray(int length, Handle *handles) {
528 if (length == 0) {
529 return NULL;
530 }
531
532 jobject *objArray = (jobject *) jvmtiMalloc(sizeof(jobject) * length);
533 NULL_CHECK(objArray, NULL);
534
535 for (int i=0; i<length; i++) {
1015 return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1016 }
1017 HandleMark hm;
1018 Handle th(owning_thread->threadObj());
1019 ret.owner = (jthread)jni_reference(calling_thread, th);
1020 }
1021 // implied else: no owner
1022 }
1023
1024 if (owning_thread != NULL) { // monitor is owned
1025 // The recursions field of a monitor does not reflect recursions
1026 // as lightweight locks before inflating the monitor are not included.
1027 // We have to count the number of recursive monitor entries the hard way.
1028 // We pass a handle to survive any GCs along the way.
1029 ResourceMark rm;
1030 ret.entry_count = count_locked_objects(owning_thread, hobj);
1031 }
1032 // implied else: entry_count == 0
1033 }
1034
1035 jint nWant = 0, nWait = 0;
1036 if (mon != NULL) {
1037 // this object has a heavyweight monitor
1038 nWant = mon->contentions(); // # of threads contending for monitor
1039 nWait = mon->waiters(); // # of threads in Object.wait()
1040 ret.waiter_count = nWant + nWait;
1041 ret.notify_waiter_count = nWait;
1042 } else {
1043 // this object has a lightweight monitor
1044 ret.waiter_count = 0;
1045 ret.notify_waiter_count = 0;
1046 }
1047
1048 // Allocate memory for heavyweight and lightweight monitor.
1049 jvmtiError err;
1050 err = allocate(ret.waiter_count * sizeof(jthread *), (unsigned char**)&ret.waiters);
1051 if (err != JVMTI_ERROR_NONE) {
1052 return err;
1053 }
1054 err = allocate(ret.notify_waiter_count * sizeof(jthread *),
1055 (unsigned char**)&ret.notify_waiters);
|