< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page


   1 /*
   2  * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 630                                                  jvf = jvf->java_sender()) {
 631     GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 632     if (!mons->is_empty()) {
 633       for (int i = 0; i < mons->length(); i++) {
 634         MonitorInfo *mi = mons->at(i);
 635         if (mi->owner_is_scalar_replaced()) continue;
 636 
 637         // see if owner of the monitor is our object
 638         if (mi->owner() != NULL && mi->owner() == hobj()) {
 639           ret++;
 640         }
 641       }
 642     }
 643   }
 644   return ret;
 645 }
 646 
 647 
 648 
 649 jvmtiError
 650 JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) {
 651 #ifdef ASSERT
 652   uint32_t debug_bits = 0;
 653 #endif
 654   assert((SafepointSynchronize::is_at_safepoint() ||
 655           java_thread->is_thread_fully_suspended(false, &debug_bits)),
 656          "at safepoint or target thread is suspended");
 657   oop obj = NULL;
 658   ObjectMonitor *mon = java_thread->current_waiting_monitor();
 659   if (mon == NULL) {
 660     // thread is not doing an Object.wait() call
 661     mon = java_thread->current_pending_monitor();
 662     if (mon != NULL) {
 663       // The thread is trying to enter() an ObjectMonitor.
 664       obj = (oop)mon->object();
 665       assert(obj != NULL, "ObjectMonitor should have a valid object!");
 666     }
 667     // implied else: no contended ObjectMonitor
 668   } else {
 669     // thread is doing an Object.wait() call
 670     obj = (oop)mon->object();
 671     assert(obj != NULL, "Object.wait() should have an object");
 672   }
 673 
 674   if (obj == NULL) {
 675     *monitor_ptr = NULL;
 676   } else {
 677     HandleMark hm;
 678     Handle     hobj(Thread::current(), obj);
 679     *monitor_ptr = jni_reference(calling_thread, hobj);

 680   }
 681   return JVMTI_ERROR_NONE;
 682 }
 683 
 684 
 685 jvmtiError
 686 JvmtiEnvBase::get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
 687                                  GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
 688   jvmtiError err = JVMTI_ERROR_NONE;
 689 #ifdef ASSERT
 690   uint32_t debug_bits = 0;
 691 #endif
 692   assert((SafepointSynchronize::is_at_safepoint() ||
 693           java_thread->is_thread_fully_suspended(false, &debug_bits)),
 694          "at safepoint or target thread is suspended");
 695 
 696   if (java_thread->has_last_Java_frame()) {
 697     ResourceMark rm;
 698     HandleMark   hm;
 699     RegisterMap  reg_map(java_thread);
 700 
 701     int depth = 0;
 702     for (javaVFrame *jvf = java_thread->last_java_vframe(&reg_map); jvf != NULL;
 703          jvf = jvf->java_sender()) {
 704       if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) {  // check for stack too deep
 705         // add locked objects for this frame into list
 706         err = get_locked_objects_in_frame(calling_thread, java_thread, jvf, owned_monitors_list, depth-1);
 707         if (err != JVMTI_ERROR_NONE) {
 708           return err;
 709         }
 710       }
 711     }
 712   }
 713 
 714   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
 715   JvmtiMonitorClosure jmc(java_thread, calling_thread, owned_monitors_list, this);
 716   ObjectSynchronizer::monitors_iterate(&jmc);
 717   err = jmc.error();
 718 
 719   return err;
 720 }
 721 
 722 // Save JNI local handles for any objects that this frame owns.
 723 jvmtiError
 724 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
 725                                  javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) {
 726   jvmtiError err = JVMTI_ERROR_NONE;
 727   ResourceMark rm;
 728 
 729   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 730   if (mons->is_empty()) {
 731     return err;  // this javaVFrame holds no monitors
 732   }
 733 
 734   HandleMark hm;
 735   oop wait_obj = NULL;


1525   if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
1526     _state->update_for_pop_top_frame();
1527   } else {
1528     _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1529   }
1530 }
1531 
1532 void
1533 VM_SetFramePop::doit() {
1534   JavaThread* jt = _state->get_thread();
1535   ThreadsListHandle tlh;
1536   if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
1537     int frame_number = _state->count_frames() - _depth;
1538     _state->env_thread_state((JvmtiEnvBase*)_env)->set_frame_pop(frame_number);
1539   } else {
1540     _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1541   }
1542 }
1543 
1544 void
1545 VM_GetOwnedMonitorInfo::doit() {
1546   _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1547   ThreadsListHandle tlh;
1548   if (_java_thread != NULL && tlh.includes(_java_thread)
1549       && !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) {
1550     _result = ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread,
1551                                                           _owned_monitors_list);
1552   }
1553 }
1554 
1555 void
1556 VM_GetCurrentContendedMonitor::doit() {
1557   _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1558   ThreadsListHandle tlh;
1559   if (_java_thread != NULL && tlh.includes(_java_thread)
1560       && !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) {
1561     _result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor(_calling_thread,_java_thread,_owned_monitor_ptr);
1562   }
1563 }
1564 
1565 void
1566 VM_GetStackTrace::doit() {
1567   _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1568   ThreadsListHandle tlh;
1569   if (_java_thread != NULL && tlh.includes(_java_thread)
1570       && !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) {
1571     _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread,
1572                                                       _start_depth, _max_count,
1573                                                       _frame_buffer, _count_ptr);
1574   }
1575 }
1576 
1577 void
1578 VM_GetFrameCount::doit() {
1579   _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1580   JavaThread* jt = _state->get_thread();
1581   ThreadsListHandle tlh;
1582   if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
   1 /*
   2  * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 630                                                  jvf = jvf->java_sender()) {
 631     GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 632     if (!mons->is_empty()) {
 633       for (int i = 0; i < mons->length(); i++) {
 634         MonitorInfo *mi = mons->at(i);
 635         if (mi->owner_is_scalar_replaced()) continue;
 636 
 637         // see if owner of the monitor is our object
 638         if (mi->owner() != NULL && mi->owner() == hobj()) {
 639           ret++;
 640         }
 641       }
 642     }
 643   }
 644   return ret;
 645 }
 646 
 647 
 648 
 649 jvmtiError
 650 JvmtiEnvBase::get_current_contended_monitor(JavaThread *java_thread, jobject *monitor_ptr) {
 651   assert(!Thread::current()->is_VM_thread() &&
 652          (Thread::current() == java_thread ||
 653           Thread::current() == java_thread->active_handshaker()),
 654          "call by myself or at direct handshake");


 655   oop obj = NULL;
 656   ObjectMonitor *mon = java_thread->current_waiting_monitor();
 657   if (mon == NULL) {
 658     // thread is not doing an Object.wait() call
 659     mon = java_thread->current_pending_monitor();
 660     if (mon != NULL) {
 661       // The thread is trying to enter() an ObjectMonitor.
 662       obj = (oop)mon->object();
 663       assert(obj != NULL, "ObjectMonitor should have a valid object!");
 664     }
 665     // implied else: no contended ObjectMonitor
 666   } else {
 667     // thread is doing an Object.wait() call
 668     obj = (oop)mon->object();
 669     assert(obj != NULL, "Object.wait() should have an object");
 670   }
 671 
 672   if (obj == NULL) {
 673     *monitor_ptr = NULL;
 674   } else {
 675     HandleMark hm;
 676     JavaThread *current_jt = reinterpret_cast<JavaThread *>(JavaThread::current());
 677     Handle     hobj(current_jt, obj);
 678     *monitor_ptr = jni_reference(current_jt, hobj);
 679   }
 680   return JVMTI_ERROR_NONE;
 681 }
 682 
 683 
 684 jvmtiError
 685 JvmtiEnvBase::get_owned_monitors(JavaThread* java_thread,
 686                                  GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
 687   jvmtiError err = JVMTI_ERROR_NONE;
 688   assert(!Thread::current()->is_VM_thread() &&
 689          (Thread::current() == java_thread ||
 690           Thread::current() == java_thread->active_handshaker()),
 691          "call by myself or at direct handshake");


 692 
 693   if (java_thread->has_last_Java_frame()) {
 694     ResourceMark rm;
 695     HandleMark   hm;
 696     RegisterMap  reg_map(java_thread);
 697 
 698     int depth = 0;
 699     for (javaVFrame *jvf = java_thread->last_java_vframe(&reg_map); jvf != NULL;
 700          jvf = jvf->java_sender()) {
 701       if (MaxJavaStackTraceDepth == 0 || depth++ < MaxJavaStackTraceDepth) {  // check for stack too deep
 702         // add locked objects for this frame into list
 703         err = get_locked_objects_in_frame(JavaThread::current(), java_thread, jvf, owned_monitors_list, depth-1);
 704         if (err != JVMTI_ERROR_NONE) {
 705           return err;
 706         }
 707       }
 708     }
 709   }
 710 
 711   // Get off stack monitors. (e.g. acquired via jni MonitorEnter).
 712   JvmtiMonitorClosure jmc(java_thread, JavaThread::current(), owned_monitors_list, this);
 713   ObjectSynchronizer::monitors_iterate(&jmc);
 714   err = jmc.error();
 715 
 716   return err;
 717 }
 718 
 719 // Save JNI local handles for any objects that this frame owns.
 720 jvmtiError
 721 JvmtiEnvBase::get_locked_objects_in_frame(JavaThread* calling_thread, JavaThread* java_thread,
 722                                  javaVFrame *jvf, GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list, jint stack_depth) {
 723   jvmtiError err = JVMTI_ERROR_NONE;
 724   ResourceMark rm;
 725 
 726   GrowableArray<MonitorInfo*>* mons = jvf->monitors();
 727   if (mons->is_empty()) {
 728     return err;  // this javaVFrame holds no monitors
 729   }
 730 
 731   HandleMark hm;
 732   oop wait_obj = NULL;


1522   if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
1523     _state->update_for_pop_top_frame();
1524   } else {
1525     _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1526   }
1527 }
1528 
1529 void
1530 VM_SetFramePop::doit() {
1531   JavaThread* jt = _state->get_thread();
1532   ThreadsListHandle tlh;
1533   if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
1534     int frame_number = _state->count_frames() - _depth;
1535     _state->env_thread_state((JvmtiEnvBase*)_env)->set_frame_pop(frame_number);
1536   } else {
1537     _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1538   }
1539 }
1540 
1541 void
1542 GetOwnedMonitorInfoClosure::do_thread(Thread *target) {
1543   _result = ((JvmtiEnvBase *)_env)->get_owned_monitors((JavaThread *)target, _owned_monitors_list);






1544 }
1545 
1546 void
1547 GetCurrentContendedMonitorClosure::do_thread(Thread *target) {
1548   _result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor((JavaThread *)target, _owned_monitor_ptr);





1549 }
1550 
1551 void
1552 VM_GetStackTrace::doit() {
1553   _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1554   ThreadsListHandle tlh;
1555   if (_java_thread != NULL && tlh.includes(_java_thread)
1556       && !_java_thread->is_exiting() && _java_thread->threadObj() != NULL) {
1557     _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread,
1558                                                       _start_depth, _max_count,
1559                                                       _frame_buffer, _count_ptr);
1560   }
1561 }
1562 
1563 void
1564 VM_GetFrameCount::doit() {
1565   _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
1566   JavaThread* jt = _state->get_thread();
1567   ThreadsListHandle tlh;
1568   if (jt != NULL && tlh.includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
< prev index next >