< prev index next >

src/share/vm/services/attachListener.hpp

Print this page
rev 8847 : 8140482: Various minor code improvements (runtime)
Reviewed-by: dholmes, coleenp, sspitsyn, dsamersoff


  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 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP
  26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/debug.hpp"
  30 #include "utilities/ostream.hpp"
  31 #include "utilities/macros.hpp"

  32 
  33 // The AttachListener thread services a queue of operations that are enqueued
  34 // by client tools. Each operation is identified by a name and has up to 3
  35 // arguments. The operation name is mapped to a function which performs the
  36 // operation. The function is called with an outputStream which is can use to
  37 // write any result data (for examples the properties command serializes
  38 // properties names and values to the output stream). When the function
  39 // complets the result value and any result data is returned to the client
  40 // tool.
  41 
  42 class AttachOperation;
  43 
  44 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out);
  45 
  46 struct AttachOperationFunctionInfo {
  47   const char* name;
  48   AttachOperationFunction func;
  49 };
  50 
  51 class AttachListener: AllStatic {


 104  public:
 105   enum {
 106     name_length_max = 16,       // maximum length of  name
 107     arg_length_max = 1024,      // maximum length of argument
 108     arg_count_max = 3           // maximum number of arguments
 109   };
 110 
 111   // name of special operation that can be enqueued when all
 112   // clients detach
 113   static char* detachall_operation_name() { return (char*)"detachall"; }
 114 
 115  private:
 116   char _name[name_length_max+1];
 117   char _arg[arg_count_max][arg_length_max+1];
 118 
 119  public:
 120   const char* name() const                      { return _name; }
 121 
 122   // set the operation name
 123   void set_name(char* name) {
 124     assert(strlen(name) <= name_length_max, "exceeds maximum name length");
 125     strcpy(_name, name);

 126   }
 127 
 128   // get an argument value
 129   const char* arg(int i) const {
 130     assert(i>=0 && i<arg_count_max, "invalid argument index");
 131     return _arg[i];
 132   }
 133 
 134   // set an argument value
 135   void set_arg(int i, char* arg) {
 136     assert(i>=0 && i<arg_count_max, "invalid argument index");
 137     if (arg == NULL) {
 138       _arg[i][0] = '\0';
 139     } else {
 140       assert(strlen(arg) <= arg_length_max, "exceeds maximum argument length");
 141       strcpy(_arg[i], arg);

 142     }
 143   }
 144 
 145   // create an operation of a given name
 146   AttachOperation(char* name) {
 147     set_name(name);
 148     for (int i=0; i<arg_count_max; i++) {
 149       set_arg(i, NULL);
 150     }
 151   }
 152 
 153   // complete operation by sending result code and any result data to the client
 154   virtual void complete(jint result, bufferedStream* result_stream) = 0;
 155 };
 156 #endif // INCLUDE_SERVICES
 157 
 158 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP


  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 #ifndef SHARE_VM_SERVICES_ATTACHLISTENER_HPP
  26 #define SHARE_VM_SERVICES_ATTACHLISTENER_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "utilities/debug.hpp"
  30 #include "utilities/ostream.hpp"
  31 #include "utilities/macros.hpp"
  32 #include "utilities/globalDefinitions.hpp"
  33 
  34 // The AttachListener thread services a queue of operations that are enqueued
  35 // by client tools. Each operation is identified by a name and has up to 3
  36 // arguments. The operation name is mapped to a function which performs the
  37 // operation. The function is called with an outputStream which is can use to
  38 // write any result data (for examples the properties command serializes
  39 // properties names and values to the output stream). When the function
  40 // complets the result value and any result data is returned to the client
  41 // tool.
  42 
  43 class AttachOperation;
  44 
  45 typedef jint (*AttachOperationFunction)(AttachOperation* op, outputStream* out);
  46 
  47 struct AttachOperationFunctionInfo {
  48   const char* name;
  49   AttachOperationFunction func;
  50 };
  51 
  52 class AttachListener: AllStatic {


 105  public:
 106   enum {
 107     name_length_max = 16,       // maximum length of  name
 108     arg_length_max = 1024,      // maximum length of argument
 109     arg_count_max = 3           // maximum number of arguments
 110   };
 111 
 112   // name of special operation that can be enqueued when all
 113   // clients detach
 114   static char* detachall_operation_name() { return (char*)"detachall"; }
 115 
 116  private:
 117   char _name[name_length_max+1];
 118   char _arg[arg_count_max][arg_length_max+1];
 119 
 120  public:
 121   const char* name() const                      { return _name; }
 122 
 123   // set the operation name
 124   void set_name(char* name) {
 125     size_t len = strlen(name);
 126     assert(len <= name_length_max, "exceeds maximum name length");
 127     memcpy(_name, name, MIN2(len + 1, (size_t)name_length_max));
 128   }
 129 
 130   // get an argument value
 131   const char* arg(int i) const {
 132     assert(i>=0 && i<arg_count_max, "invalid argument index");
 133     return _arg[i];
 134   }
 135 
 136   // set an argument value
 137   void set_arg(int i, char* arg) {
 138     assert(i>=0 && i<arg_count_max, "invalid argument index");
 139     if (arg == NULL) {
 140       _arg[i][0] = '\0';
 141     } else {
 142       size_t len = strlen(arg);
 143       assert(len <= arg_length_max, "exceeds maximum argument length");
 144       memcpy(_arg[i], arg, MIN2(len + 1, (size_t)arg_length_max));
 145     }
 146   }
 147 
 148   // create an operation of a given name
 149   AttachOperation(char* name) {
 150     set_name(name);
 151     for (int i=0; i<arg_count_max; i++) {
 152       set_arg(i, NULL);
 153     }
 154   }
 155 
 156   // complete operation by sending result code and any result data to the client
 157   virtual void complete(jint result, bufferedStream* result_stream) = 0;
 158 };
 159 #endif // INCLUDE_SERVICES
 160 
 161 #endif // SHARE_VM_SERVICES_ATTACHLISTENER_HPP
< prev index next >