src/os/solaris/vm/attachListener_solaris.cpp

Print this page
rev 6165 : imported patch atoi.diff


  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "runtime/interfaceSupport.hpp"
  27 #include "runtime/os.hpp"
  28 #include "services/attachListener.hpp"
  29 #include "services/dtraceAttacher.hpp"
  30 
  31 #include <door.h>

  32 #include <string.h>
  33 #include <signal.h>
  34 #include <sys/types.h>
  35 #include <sys/socket.h>
  36 #include <sys/stat.h>
  37 
  38 // stropts.h uses STR in stream ioctl defines
  39 #undef STR
  40 #include <stropts.h>
  41 #undef STR
  42 #define STR(a) #a
  43 
  44 // The attach mechanism on Solaris is implemented using the Doors IPC
  45 // mechanism. The first tool to attempt to attach causes the attach
  46 // listener thread to startup. This thread creats a door that is
  47 // associated with a function that enqueues an operation to the attach
  48 // listener. The door is attached to a file in the file system so that
  49 // client (tools) can locate it. To enqueue an operation to the VM the
  50 // client calls through the door which invokes the enqueue function in
  51 // this process. The credentials of the client are checked and if the


 651     }
 652   }
 653   return false;
 654 }
 655 
 656 // if VM aborts then detach/cleanup
 657 void AttachListener::abort() {
 658   listener_cleanup();
 659 }
 660 
 661 void AttachListener::pd_data_dump() {
 662   os::signal_notify(SIGQUIT);
 663 }
 664 
 665 static jint enable_dprobes(AttachOperation* op, outputStream* out) {
 666   const char* probe = op->arg(0);
 667   if (probe == NULL || probe[0] == '\0') {
 668     out->print_cr("No probe specified");
 669     return JNI_ERR;
 670   } else {
 671     int probe_typess = atoi(probe);
 672     if (errno) {

 673       out->print_cr("invalid probe type");
 674       return JNI_ERR;
 675     } else {

 676       DTrace::enable_dprobes(probe_typess);
 677       return JNI_OK;
 678     }
 679   }
 680 }
 681 
 682 // platform specific operations table
 683 static AttachOperationFunctionInfo funcs[] = {
 684   { "enabledprobes", enable_dprobes },
 685   { NULL, NULL }
 686 };
 687 
 688 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* name) {
 689   int i;
 690   for (i = 0; funcs[i].name != NULL; i++) {
 691     if (strcmp(funcs[i].name, name) == 0) {
 692       return &funcs[i];
 693     }
 694   }
 695   return NULL;
 696 }
 697 
 698 // Solaris specific global flag set. Currently, we support only
 699 // changing ExtendedDTraceProbes flag.
 700 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 701   const char* name = op->arg(0);
 702   assert(name != NULL, "flag name should not be null");
 703   bool flag = true;
 704   const char* arg1;
 705   if ((arg1 = op->arg(1)) != NULL) {
 706     flag = (atoi(arg1) != 0);
 707     if (errno) {

 708       out->print_cr("flag value has to be an integer");
 709       return JNI_ERR;
 710     }
 711   }
 712 
 713   if (strcmp(name, "ExtendedDTraceProbes") == 0) {
 714     DTrace::set_extended_dprobes(flag);
 715     return JNI_OK;
 716   }
 717 
 718   if (strcmp(name, "DTraceMonitorProbes") == 0) {
 719     DTrace::set_monitor_dprobes(flag);
 720     return JNI_OK;
 721   }
 722 
 723   out->print_cr("flag '%s' cannot be changed", name);
 724   return JNI_ERR;
 725 }
 726 
 727 void AttachListener::pd_detachall() {


  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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "runtime/interfaceSupport.hpp"
  27 #include "runtime/os.hpp"
  28 #include "services/attachListener.hpp"
  29 #include "services/dtraceAttacher.hpp"
  30 
  31 #include <door.h>
  32 #include <limits.h>
  33 #include <string.h>
  34 #include <signal.h>
  35 #include <sys/types.h>
  36 #include <sys/socket.h>
  37 #include <sys/stat.h>
  38 
  39 // stropts.h uses STR in stream ioctl defines
  40 #undef STR
  41 #include <stropts.h>
  42 #undef STR
  43 #define STR(a) #a
  44 
  45 // The attach mechanism on Solaris is implemented using the Doors IPC
  46 // mechanism. The first tool to attempt to attach causes the attach
  47 // listener thread to startup. This thread creats a door that is
  48 // associated with a function that enqueues an operation to the attach
  49 // listener. The door is attached to a file in the file system so that
  50 // client (tools) can locate it. To enqueue an operation to the VM the
  51 // client calls through the door which invokes the enqueue function in
  52 // this process. The credentials of the client are checked and if the


 652     }
 653   }
 654   return false;
 655 }
 656 
 657 // if VM aborts then detach/cleanup
 658 void AttachListener::abort() {
 659   listener_cleanup();
 660 }
 661 
 662 void AttachListener::pd_data_dump() {
 663   os::signal_notify(SIGQUIT);
 664 }
 665 
 666 static jint enable_dprobes(AttachOperation* op, outputStream* out) {
 667   const char* probe = op->arg(0);
 668   if (probe == NULL || probe[0] == '\0') {
 669     out->print_cr("No probe specified");
 670     return JNI_ERR;
 671   } else {
 672     char *end;
 673     long val = strtol(probe, &end, 10);
 674     if (end == probe || val < 0 || val > INT_MAX) {
 675       out->print_cr("invalid probe type");
 676       return JNI_ERR;
 677     } else {
 678       int probe_typess = (int) val;
 679       DTrace::enable_dprobes(probe_typess);
 680       return JNI_OK;
 681     }
 682   }
 683 }
 684 
 685 // platform specific operations table
 686 static AttachOperationFunctionInfo funcs[] = {
 687   { "enabledprobes", enable_dprobes },
 688   { NULL, NULL }
 689 };
 690 
 691 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* name) {
 692   int i;
 693   for (i = 0; funcs[i].name != NULL; i++) {
 694     if (strcmp(funcs[i].name, name) == 0) {
 695       return &funcs[i];
 696     }
 697   }
 698   return NULL;
 699 }
 700 
 701 // Solaris specific global flag set. Currently, we support only
 702 // changing ExtendedDTraceProbes flag.
 703 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 704   const char* name = op->arg(0);
 705   assert(name != NULL, "flag name should not be null");
 706   bool flag = true;
 707   const char* arg1;
 708   if ((arg1 = op->arg(1)) != NULL) {
 709     char *end;
 710     flag = (strtol(arg1, &end, 10) != 0);
 711     if (arg1 == end) {
 712       out->print_cr("flag value has to be an integer");
 713       return JNI_ERR;
 714     }
 715   }
 716 
 717   if (strcmp(name, "ExtendedDTraceProbes") == 0) {
 718     DTrace::set_extended_dprobes(flag);
 719     return JNI_OK;
 720   }
 721 
 722   if (strcmp(name, "DTraceMonitorProbes") == 0) {
 723     DTrace::set_monitor_dprobes(flag);
 724     return JNI_OK;
 725   }
 726 
 727   out->print_cr("flag '%s' cannot be changed", name);
 728   return JNI_ERR;
 729 }
 730 
 731 void AttachListener::pd_detachall() {