< prev index next >

src/hotspot/share/services/diagnosticFramework.hpp

Print this page
rev 50538 : [mq]: jcmd-cleanups

@@ -73,23 +73,19 @@
 // Iterator class taking a character string in input and returning a CmdLine
 // instance for each command line. The argument delimiter has to be specified.
 class DCmdIter : public StackObj {
   friend class DCmd;
 private:
-  const char* _str;
-  char        _delim;
-  size_t      _len;
+  const char* const _str;
+  const char        _delim;
+  const size_t      _len;
   size_t      _cursor;
 public:
 
-  DCmdIter(const char* str, char delim) {
-    _str = str;
-    _delim = delim;
-    _len = strlen(str);
-    _cursor = 0;
-  }
-  bool has_next() { return _cursor < _len; }
+  DCmdIter(const char* str, char delim)
+   : _str(str), _delim(delim), _len(::strlen(str)), _cursor(0) {}
+  bool has_next() const { return _cursor < _len; }
   CmdLine next() {
     assert(_cursor <= _len, "Cannot iterate more");
     size_t n = _cursor;
     while (n < _len && _str[n] != _delim) n++;
     CmdLine line(&(_str[_cursor]), n - _cursor, false);

@@ -100,30 +96,27 @@
   }
 };
 
 // Iterator class to iterate over diagnostic command arguments
 class DCmdArgIter : public ResourceObj {
-  const char* _buffer;
-  size_t      _len;
+  const char* const _buffer;
+  const size_t      _len;
   size_t      _cursor;
   const char* _key_addr;
   size_t      _key_len;
   const char* _value_addr;
   size_t      _value_len;
-  char        _delim;
+  const char  _delim;
 public:
-  DCmdArgIter(const char* buf, size_t len, char delim) {
-    _buffer = buf;
-    _len = len;
-    _delim = delim;
-    _cursor = 0;
-  }
+  DCmdArgIter(const char* buf, size_t len, char delim)
+    : _buffer(buf), _len(len), _delim(delim), _cursor(0) {}
+
   bool next(TRAPS);
-  const char* key_addr() { return _key_addr; }
-  size_t key_length() { return _key_len; }
-  const char* value_addr() { return _value_addr; }
-  size_t value_length() { return _value_len; }
+  const char* key_addr() const { return _key_addr; }
+  size_t key_length() const { return _key_len; }
+  const char* value_addr() const { return _value_addr; }
+  size_t value_length() const { return _value_len; }
 };
 
 // A DCmdInfo instance provides a description of a diagnostic command. It is
 // used to export the description to the JMX interface of the framework.
 class DCmdInfo : public ResourceObj {

@@ -161,47 +154,28 @@
 // A DCmdArgumentInfo instance provides a description of a diagnostic command
 // argument. It is used to export the description to the JMX interface of the
 // framework.
 class DCmdArgumentInfo : public ResourceObj {
 protected:
-  const char* _name;            /* Option/Argument name*/
-  const char* _description;     /* Short description */
-  const char* _type;            /* Type: STRING, BOOLEAN, etc. */
-  const char* _default_string;  /* Default value in a parsable string */
-  bool        _mandatory;       /* True if the option/argument is mandatory */
-  bool        _option;          /* True if it is an option, false if it is an argument */
+  const char* const _name;            /* Option/Argument name*/
+  const char* const _description;     /* Short description */
+  const char* const _type;            /* Type: STRING, BOOLEAN, etc. */
+  const char* const _default_string;  /* Default value in a parsable string */
+  const bool        _mandatory;       /* True if the option/argument is mandatory */
+  const bool        _option;          /* True if it is an option, false if it is an argument */
                                 /* (see diagnosticFramework.hpp for option/argument definitions) */
-  bool        _multiple;        /* True is the option can be specified several time */
-  int         _position;        /* Expected position for this argument (this field is */
+  const bool        _multiple;        /* True is the option can be specified several time */
+  const int         _position;        /* Expected position for this argument (this field is */
                                 /* meaningless for options) */
 public:
   DCmdArgumentInfo(const char* name, const char* description, const char* type,
                    const char* default_string, bool mandatory, bool option,
-                   bool multiple) {
-    this->_name = name;
-    this->_description = description;
-    this->_type = type;
-    this->_default_string = default_string;
-    this->_option = option;
-    this->_mandatory = mandatory;
-    this->_option = option;
-    this->_multiple = multiple;
-    this->_position = -1;
-  }
-  DCmdArgumentInfo(const char* name, const char* description, const char* type,
-                   const char* default_string, bool mandatory, bool option,
-                   bool multiple, int position) {
-    this->_name = name;
-    this->_description = description;
-    this->_type = type;
-    this->_default_string = default_string;
-    this->_option = option;
-    this->_mandatory = mandatory;
-    this->_option = option;
-    this->_multiple = multiple;
-    this->_position = position;
-  }
+                   bool multiple, int position = -1)
+    : _name(name), _description(description), _type(type)
+    , _default_string(default_string), _mandatory(mandatory)
+    , _option(option), _multiple(multiple), _position(-1) {}
+
   const char* name() const { return _name; }
   const char* description() const { return _description; }
   const char* type() const { return _type; }
   const char* default_string() const { return _default_string; }
   bool is_mandatory() const { return _mandatory; }

@@ -231,29 +205,25 @@
 // is 0, argumentB's position is 1 and argumentC's position is 2.
 class DCmdParser {
 private:
   GenDCmdArgument* _options;
   GenDCmdArgument* _arguments_list;
-  char             _delim;
 public:
-  DCmdParser() {
-    _options = NULL;
-    _arguments_list = NULL;
-    _delim = ' ';
-  }
+  DCmdParser()
+   : _options(NULL), _arguments_list(NULL) {}
   void add_dcmd_option(GenDCmdArgument* arg);
   void add_dcmd_argument(GenDCmdArgument* arg);
   GenDCmdArgument* lookup_dcmd_option(const char* name, size_t len);
-  GenDCmdArgument* arguments_list() { return _arguments_list; };
+  GenDCmdArgument* arguments_list() const { return _arguments_list; };
   void check(TRAPS);
   void parse(CmdLine* line, char delim, TRAPS);
-  void print_help(outputStream* out, const char* cmd_name);
+  void print_help(outputStream* out, const char* cmd_name) const;
   void reset(TRAPS);
   void cleanup();
-  int num_arguments();
-  GrowableArray<const char*>* argument_name_array();
-  GrowableArray<DCmdArgumentInfo*>* argument_info_array();
+  int num_arguments() const;
+  GrowableArray<const char*>* argument_name_array() const;
+  GrowableArray<DCmdArgumentInfo*>* argument_info_array() const;
 };
 
 // The DCmd class is the parent class of all diagnostic commands
 // Diagnostic command instances should not be instantiated directly but
 // created using the associated factory. The factory can be retrieved with

@@ -268,17 +238,15 @@
 // each diagnostic command instance. In case of a C-heap allocated diagnostic
 // command instance, the DCmdMark must be created in the context of the last
 // thread that will access the instance.
 class DCmd : public ResourceObj {
 protected:
-  outputStream* _output;
-  bool          _is_heap_allocated;
+  outputStream* const _output;
+  const bool          _is_heap_allocated;
 public:
-  DCmd(outputStream* output, bool heap_allocated) {
-    _output = output;
-    _is_heap_allocated = heap_allocated;
-  }
+  DCmd(outputStream* output, bool heap_allocated)
+   : _output(output), _is_heap_allocated(heap_allocated) {}
 
   static const char* name() { return "No Name";}
   static const char* description() { return "No Help";}
   static const char* disabled_message() { return "Diagnostic command currently disabled"; }
   // The impact() method returns a description of the intrusiveness of the diagnostic

@@ -304,13 +272,13 @@
   static const JavaPermission permission() {
     JavaPermission p = {NULL, NULL, NULL};
     return p;
   }
   static int num_arguments() { return 0; }
-  outputStream* output() { return _output; }
-  bool is_heap_allocated()  { return _is_heap_allocated; }
-  virtual void print_help(const char* name) {
+  outputStream* output() const { return _output; }
+  bool is_heap_allocated() const { return _is_heap_allocated; }
+  virtual void print_help(const char* name) const {
     output()->print_cr("Syntax: %s", name);
   }
   virtual void parse(CmdLine* line, char delim, TRAPS) {
     DCmdArgIter iter(line->args_addr(), line->args_len(), delim);
     bool has_arg = iter.next(CHECK);

@@ -322,15 +290,15 @@
   virtual void execute(DCmdSource source, TRAPS) { }
   virtual void reset(TRAPS) { }
   virtual void cleanup() { }
 
   // support for the JMX interface
-  virtual GrowableArray<const char*>* argument_name_array() {
+  virtual GrowableArray<const char*>* argument_name_array() const {
     GrowableArray<const char*>* array = new GrowableArray<const char*>(0);
     return array;
   }
-  virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() {
+  virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() const {
     GrowableArray<DCmdArgumentInfo*>* array = new GrowableArray<DCmdArgumentInfo*>(0);
     return array;
   }
 
   // main method to invoke the framework

@@ -351,19 +319,19 @@
   static int num_arguments() { return 0; }
   virtual void parse(CmdLine *line, char delim, TRAPS);
   virtual void execute(DCmdSource source, TRAPS) { }
   virtual void reset(TRAPS);
   virtual void cleanup();
-  virtual void print_help(const char* name);
-  virtual GrowableArray<const char*>* argument_name_array();
-  virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array();
+  virtual void print_help(const char* name) const;
+  virtual GrowableArray<const char*>* argument_name_array() const;
+  virtual GrowableArray<DCmdArgumentInfo*>* argument_info_array() const;
 };
 
 class DCmdMark : public StackObj {
-  DCmd* _ref;
+  DCmd* const _ref;
 public:
-  DCmdMark(DCmd* cmd) { _ref = cmd; }
+  DCmdMark(DCmd* cmd) : _ref(cmd) {}
   ~DCmdMark() {
     if (_ref != NULL) {
       _ref->cleanup();
       if (_ref->is_heap_allocated()) {
         delete _ref;

@@ -386,35 +354,27 @@
   // diagnostic commands
   DCmdFactory*        _next;
   // When disabled, a diagnostic command cannot be executed. Any attempt to
   // execute it will result in the printing of the disabled message without
   // instantiating the command.
-  bool                _enabled;
+  const bool          _enabled;
   // When hidden, a diagnostic command doesn't appear in the list of commands
   // provided by the 'help' command.
-  bool                _hidden;
-  uint32_t            _export_flags;
-  int                 _num_arguments;
+  const bool          _hidden;
+  const uint32_t      _export_flags;
+  const int           _num_arguments;
   static DCmdFactory* _DCmdFactoryList;
 public:
-  DCmdFactory(int num_arguments, uint32_t flags, bool enabled, bool hidden) {
-    _next = NULL;
-    _enabled = enabled;
-    _hidden = hidden;
-    _export_flags = flags;
-    _num_arguments = num_arguments;
-  }
+  DCmdFactory(int num_arguments, uint32_t flags, bool enabled, bool hidden)
+    : _num_arguments(num_arguments), _enabled(enabled), _hidden(hidden)
+    , _export_flags(flags), _next(NULL) {}
   bool is_enabled() const { return _enabled; }
-  void set_enabled(bool b) { _enabled = b; }
   bool is_hidden() const { return _hidden; }
-  void set_hidden(bool b) { _hidden = b; }
-  uint32_t export_flags() { return _export_flags; }
-  void set_export_flags(uint32_t f) { _export_flags = f; }
-  int num_arguments() { return _num_arguments; }
-  DCmdFactory* next() { return _next; }
-  virtual DCmd* create_Cheap_instance(outputStream* output) = 0;
-  virtual DCmd* create_resource_instance(outputStream* output) = 0;
+  uint32_t export_flags() const { return _export_flags; }
+  int num_arguments() const { return _num_arguments; }
+  DCmdFactory* next() const { return _next; }
+  virtual DCmd* create_resource_instance(outputStream* output) const = 0;
   virtual const char* name() const = 0;
   virtual const char* description() const = 0;
   virtual const char* impact() const = 0;
   virtual const JavaPermission permission() const = 0;
   virtual const char* disabled_message() const = 0;

@@ -422,12 +382,10 @@
   // Once registered, a diagnostic command must not be unregistered.
   // To prevent a diagnostic command from being executed, just set the
   // enabled flag to false.
   static int register_DCmdFactory(DCmdFactory* factory);
   static DCmdFactory* factory(DCmdSource source, const char* cmd, size_t len);
-  // Returns a C-heap allocated diagnostic command for the given command line
-  static DCmd* create_global_DCmd(DCmdSource source, CmdLine &line, outputStream* out, TRAPS);
   // Returns a resourceArea allocated diagnostic command for the given command line
   static DCmd* create_local_DCmd(DCmdSource source, CmdLine &line, outputStream* out, TRAPS);
   static GrowableArray<const char*>* DCmd_list(DCmdSource source);
   static GrowableArray<DCmdInfo*>* DCmdInfo_list(DCmdSource source);
 

@@ -447,16 +405,12 @@
 // where this template is used to create and register factories.
 template <class DCmdClass> class DCmdFactoryImpl : public DCmdFactory {
 public:
   DCmdFactoryImpl(uint32_t flags, bool enabled, bool hidden) :
     DCmdFactory(DCmdClass::num_arguments(), flags, enabled, hidden) { }
-  // Returns a C-heap allocated instance
-  virtual DCmd* create_Cheap_instance(outputStream* output) {
-    return new (ResourceObj::C_HEAP, mtInternal) DCmdClass(output, true);
-  }
   // Returns a resourceArea allocated instance
-  virtual DCmd* create_resource_instance(outputStream* output) {
+  virtual DCmd* create_resource_instance(outputStream* output) const {
     return new DCmdClass(output, false);
   }
   virtual const char* name() const {
     return DCmdClass::name();
   }
< prev index next >