hotspot/src/share/vm/prims/jvmtiEnvBase.cpp
changeset 46271 979ebd346ecf
parent 37480 291ee208fb72
child 46329 53ccc37bda19
equal deleted inserted replaced
46270:2e7898927798 46271:979ebd346ecf
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   596 
   596 
   597 
   597 
   598 jclass
   598 jclass
   599 JvmtiEnvBase::get_jni_class_non_null(Klass* k) {
   599 JvmtiEnvBase::get_jni_class_non_null(Klass* k) {
   600   assert(k != NULL, "k != NULL");
   600   assert(k != NULL, "k != NULL");
   601   return (jclass)jni_reference(k->java_mirror());
   601   Thread *thread = Thread::current();
       
   602   return (jclass)jni_reference(Handle(thread, k->java_mirror()));
   602 }
   603 }
   603 
   604 
   604 //
   605 //
   605 // Field Information
   606 // Field Information
   606 //
   607 //
   691 
   692 
   692   if (obj == NULL) {
   693   if (obj == NULL) {
   693     *monitor_ptr = NULL;
   694     *monitor_ptr = NULL;
   694   } else {
   695   } else {
   695     HandleMark hm;
   696     HandleMark hm;
   696     Handle     hobj(obj);
   697     Handle     hobj(Thread::current(), obj);
   697     *monitor_ptr = jni_reference(calling_thread, hobj);
   698     *monitor_ptr = jni_reference(calling_thread, hobj);
   698   }
   699   }
   699   return JVMTI_ERROR_NONE;
   700   return JVMTI_ERROR_NONE;
   700 }
   701 }
   701 
   702 
   811     jvmtiMonitorStackDepthInfo *jmsdi;
   812     jvmtiMonitorStackDepthInfo *jmsdi;
   812     err = allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
   813     err = allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
   813     if (err != JVMTI_ERROR_NONE) {
   814     if (err != JVMTI_ERROR_NONE) {
   814         return err;
   815         return err;
   815     }
   816     }
   816     Handle hobj(obj);
   817     Handle hobj(Thread::current(), obj);
   817     jmsdi->monitor = jni_reference(calling_thread, hobj);
   818     jmsdi->monitor = jni_reference(calling_thread, hobj);
   818     jmsdi->stack_depth = stack_depth;
   819     jmsdi->stack_depth = stack_depth;
   819     owned_monitors_list->append(jmsdi);
   820     owned_monitors_list->append(jmsdi);
   820   }
   821   }
   821 
   822 
   951 jvmtiError
   952 jvmtiError
   952 JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
   953 JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
   953   HandleMark hm;
   954   HandleMark hm;
   954   Handle hobj;
   955   Handle hobj;
   955 
   956 
       
   957   Thread* current_thread = Thread::current();
   956   bool at_safepoint = SafepointSynchronize::is_at_safepoint();
   958   bool at_safepoint = SafepointSynchronize::is_at_safepoint();
   957 
   959 
   958   // Check arguments
   960   // Check arguments
   959   {
   961   {
   960     oop mirror = JNIHandles::resolve_external_guard(object);
   962     oop mirror = JNIHandles::resolve_external_guard(object);
   961     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
   963     NULL_CHECK(mirror, JVMTI_ERROR_INVALID_OBJECT);
   962     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
   964     NULL_CHECK(info_ptr, JVMTI_ERROR_NULL_POINTER);
   963 
   965 
   964     hobj = Handle(mirror);
   966     hobj = Handle(current_thread, mirror);
   965   }
   967   }
   966 
   968 
   967   JavaThread *owning_thread = NULL;
   969   JavaThread *owning_thread = NULL;
   968   ObjectMonitor *mon = NULL;
   970   ObjectMonitor *mon = NULL;
   969   jvmtiMonitorUsage ret = {
   971   jvmtiMonitorUsage ret = {
  1025           // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
  1027           // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which
  1026           // will retry the call via a VM_GetObjectMonitorUsage VM op.
  1028           // will retry the call via a VM_GetObjectMonitorUsage VM op.
  1027           return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
  1029           return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
  1028         }
  1030         }
  1029         HandleMark hm;
  1031         HandleMark hm;
  1030         Handle     th(owning_thread->threadObj());
  1032         Handle     th(current_thread, owning_thread->threadObj());
  1031         ret.owner = (jthread)jni_reference(calling_thread, th);
  1033         ret.owner = (jthread)jni_reference(calling_thread, th);
  1032       }
  1034       }
  1033       // implied else: no owner
  1035       // implied else: no owner
  1034     }
  1036     }
  1035 
  1037 
  1108             }
  1110             }
  1109             deallocate((unsigned char*)ret.waiters);
  1111             deallocate((unsigned char*)ret.waiters);
  1110             deallocate((unsigned char*)ret.notify_waiters);
  1112             deallocate((unsigned char*)ret.notify_waiters);
  1111             return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
  1113             return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
  1112           }
  1114           }
  1113           Handle th(pending_thread->threadObj());
  1115           Handle th(current_thread, pending_thread->threadObj());
  1114           ret.waiters[i] = (jthread)jni_reference(calling_thread, th);
  1116           ret.waiters[i] = (jthread)jni_reference(calling_thread, th);
  1115         }
  1117         }
  1116       }
  1118       }
  1117       if (nWait > 0) {
  1119       if (nWait > 0) {
  1118         // we have threads in Object.wait()
  1120         // we have threads in Object.wait()
  1128           if (t != NULL && t->is_Java_thread()) {
  1130           if (t != NULL && t->is_Java_thread()) {
  1129             JavaThread *wjava_thread = (JavaThread *)t;
  1131             JavaThread *wjava_thread = (JavaThread *)t;
  1130             // If the thread was found on the ObjectWaiter list, then
  1132             // If the thread was found on the ObjectWaiter list, then
  1131             // it has not been notified. This thread can't change the
  1133             // it has not been notified. This thread can't change the
  1132             // state of the monitor so it doesn't need to be suspended.
  1134             // state of the monitor so it doesn't need to be suspended.
  1133             Handle th(wjava_thread->threadObj());
  1135             Handle th(current_thread, wjava_thread->threadObj());
  1134             ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th);
  1136             ret.waiters[offset + j] = (jthread)jni_reference(calling_thread, th);
  1135             ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th);
  1137             ret.notify_waiters[j++] = (jthread)jni_reference(calling_thread, th);
  1136           }
  1138           }
  1137           waiter = mon->next_waiter(waiter);
  1139           waiter = mon->next_waiter(waiter);
  1138         }
  1140         }
  1360   }
  1362   }
  1361 
  1363 
  1362   // Check that the jobject class matches the return type signature.
  1364   // Check that the jobject class matches the return type signature.
  1363   jobject jobj = value.l;
  1365   jobject jobj = value.l;
  1364   if (tos == atos && jobj != NULL) { // NULL reference is allowed
  1366   if (tos == atos && jobj != NULL) { // NULL reference is allowed
  1365     Handle ob_h = Handle(current_thread, JNIHandles::resolve_external_guard(jobj));
  1367     Handle ob_h(current_thread, JNIHandles::resolve_external_guard(jobj));
  1366     NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
  1368     NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
  1367     KlassHandle ob_kh = KlassHandle(current_thread, ob_h()->klass());
  1369     KlassHandle ob_kh = KlassHandle(current_thread, ob_h()->klass());
  1368     NULL_CHECK(ob_kh, JVMTI_ERROR_INVALID_OBJECT);
  1370     NULL_CHECK(ob_kh, JVMTI_ERROR_INVALID_OBJECT);
  1369 
  1371 
  1370     // Method return type signature.
  1372     // Method return type signature.
  1423     OSThread* osThread = java_thread->osthread();
  1425     OSThread* osThread = java_thread->osthread();
  1424     if (osThread->get_state() == MONITOR_WAIT) {
  1426     if (osThread->get_state() == MONITOR_WAIT) {
  1425       return JVMTI_ERROR_OPAQUE_FRAME;
  1427       return JVMTI_ERROR_OPAQUE_FRAME;
  1426     }
  1428     }
  1427   }
  1429   }
  1428   Handle ret_ob_h = Handle();
  1430   Handle ret_ob_h;
  1429   jvmtiError err = check_top_frame(current_thread, java_thread, value, tos, &ret_ob_h);
  1431   jvmtiError err = check_top_frame(current_thread, java_thread, value, tos, &ret_ob_h);
  1430   if (err != JVMTI_ERROR_NONE) {
  1432   if (err != JVMTI_ERROR_NONE) {
  1431     return err;
  1433     return err;
  1432   }
  1434   }
  1433   assert(tos != atos || value.l == NULL || ret_ob_h() != NULL,
  1435   assert(tos != atos || value.l == NULL || ret_ob_h() != NULL,
  1477       err = _env->allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
  1479       err = _env->allocate(sizeof(jvmtiMonitorStackDepthInfo), (unsigned char **)&jmsdi);
  1478       if (err != JVMTI_ERROR_NONE) {
  1480       if (err != JVMTI_ERROR_NONE) {
  1479         _error = err;
  1481         _error = err;
  1480         return;
  1482         return;
  1481       }
  1483       }
  1482       Handle hobj(obj);
  1484       Handle hobj(Thread::current(), obj);
  1483       jmsdi->monitor = _env->jni_reference(_calling_thread, hobj);
  1485       jmsdi->monitor = _env->jni_reference(_calling_thread, hobj);
  1484       // stack depth is unknown for this monitor.
  1486       // stack depth is unknown for this monitor.
  1485       jmsdi->stack_depth = -1;
  1487       jmsdi->stack_depth = -1;
  1486       _owned_monitors_list->append(jmsdi);
  1488       _owned_monitors_list->append(jmsdi);
  1487     }
  1489     }