hotspot/src/share/vm/services/diagnosticArgument.hpp
author zgu
Thu, 28 Jun 2012 17:03:16 -0400
changeset 13195 be27e1b6a4b9
parent 12262 fb3b9fede660
child 27880 afb974a04396
permissions -rw-r--r--
6995781: Native Memory Tracking (Phase 1) 7151532: DCmd for hotspot native memory tracking Summary: Implementation of native memory tracking phase 1, which tracks VM native memory usage, and related DCmd Reviewed-by: acorn, coleenp, fparain
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     1
/*
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     4
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     7
 * published by the Free Software Foundation.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     8
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    13
 * accompanied this code).
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    14
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    18
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    21
 * questions.
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    22
 *
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    23
 */
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    24
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    25
#ifndef SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    26
#define SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    27
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    28
#include "classfile/vmSymbols.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    29
#include "memory/allocation.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    30
#include "runtime/os.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    31
#include "runtime/thread.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    32
#include "utilities/exceptions.hpp"
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    33
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12262
diff changeset
    34
class StringArrayArgument : public CHeapObj<mtInternal> {
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    35
private:
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    36
  GrowableArray<char*>* _array;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    37
public:
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    38
  StringArrayArgument() {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12262
diff changeset
    39
    _array = new(ResourceObj::C_HEAP, mtInternal)GrowableArray<char *>(32, true);
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    40
    assert(_array != NULL, "Sanity check");
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    41
  }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    42
  void add(const char* str, size_t len) {
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    43
    if (str != NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12262
diff changeset
    44
      char* ptr = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    45
      strncpy(ptr, str, len);
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    46
      ptr[len] = 0;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    47
      _array->append(ptr);
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    48
    }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    49
  }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    50
  GrowableArray<char*>* array() {
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    51
    return _array;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    52
  }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    53
  ~StringArrayArgument() {
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    54
    for (int i=0; i<_array->length(); i++) {
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    55
      if(_array->at(i) != NULL) { // Safety check
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 12262
diff changeset
    56
        FREE_C_HEAP_ARRAY(char, _array->at(i), mtInternal);
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    57
      }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    58
    }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    59
    delete _array;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    60
  }
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    61
};
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    62
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    63
class NanoTimeArgument {
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    64
public:
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    65
  jlong _nanotime;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    66
  jlong _time;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    67
  char _unit[3];
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    68
};
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    69
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    70
class MemorySizeArgument {
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    71
public:
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    72
  u8 _size;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    73
  u8 _val;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    74
  char _multiplier;
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    75
};
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    76
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    77
class GenDCmdArgument : public ResourceObj {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    78
protected:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    79
  GenDCmdArgument* _next;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    80
  const char*      _name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    81
  const char*      _description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    82
  const char*      _type;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    83
  const char*      _default_string;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    84
  bool             _is_set;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    85
  bool             _is_mandatory;
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    86
  bool             _allow_multiple;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    87
  GenDCmdArgument(const char* name, const char* description, const char* type,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    88
                  const char* default_string, bool mandatory) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    89
    _name = name;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    90
    _description = description;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    91
    _type = type;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    92
    _default_string = default_string;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    93
    _is_mandatory = mandatory;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    94
    _is_set = false;
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
    95
    _allow_multiple = false;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    96
  };
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    97
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    98
  const char* name() { return _name; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
    99
  const char* description() { return _description; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   100
  const char* type() { return _type; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   101
  const char* default_string() { return _default_string; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   102
  bool is_set() { return _is_set; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   103
  void set_is_set(bool b) { _is_set = b; }
11776
519643dbbefb 7145243: Need additional specializations for argument parsing framework
fparain
parents: 11209
diff changeset
   104
  bool allow_multiple() { return _allow_multiple; }
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   105
  bool is_mandatory() { return _is_mandatory; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   106
  bool has_value() { return _is_set || _default_string != NULL; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   107
  bool has_default() { return _default_string != NULL; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   108
  void read_value(const char* str, size_t len, TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   109
  virtual void parse_value(const char* str, size_t len, TRAPS) = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   110
  virtual void init_value(TRAPS) = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   111
  virtual void reset(TRAPS) = 0;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   112
  virtual void cleanup() = 0;
12262
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   113
  virtual void value_as_str(char* buf, size_t len) = 0;
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   114
  void set_next(GenDCmdArgument* arg) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   115
    _next = arg;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   116
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   117
  GenDCmdArgument* next() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   118
    return _next;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   119
  }
12262
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   120
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   121
  void to_string(jlong l, char* buf, size_t len);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   122
  void to_string(bool b, char* buf, size_t len);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   123
  void to_string(char* c, char* buf, size_t len);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   124
  void to_string(NanoTimeArgument n, char* buf, size_t len);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   125
  void to_string(MemorySizeArgument f, char* buf, size_t len);
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   126
  void to_string(StringArrayArgument* s, char* buf, size_t len);
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   127
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   128
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   129
template <class ArgType> class DCmdArgument: public GenDCmdArgument {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   130
private:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   131
  ArgType _value;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   132
public:
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   133
  DCmdArgument(const char* name, const char* description, const char* type,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   134
               bool mandatory) :
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   135
               GenDCmdArgument(name, description, type, NULL, mandatory) { }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   136
  DCmdArgument(const char* name, const char* description, const char* type,
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   137
               bool mandatory, const char* defaultvalue) :
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   138
               GenDCmdArgument(name, description, type, defaultvalue, mandatory)
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   139
               { }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   140
  ~DCmdArgument() { destroy_value(); }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   141
  ArgType value() { return _value;}
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   142
  void set_value(ArgType v) { _value = v; }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   143
  void reset(TRAPS) {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   144
    destroy_value();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   145
    init_value(CHECK);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   146
    _is_set = false;
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   147
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   148
  void cleanup() {
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   149
    destroy_value();
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   150
  }
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   151
  void parse_value(const char* str, size_t len, TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   152
  void init_value(TRAPS);
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   153
  void destroy_value();
12262
fb3b9fede660 7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents: 11776
diff changeset
   154
  void value_as_str(char *buf, size_t len) { return to_string(_value, buf, len);}
11209
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   155
};
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   156
110525ac80b0 7104647: Adding a diagnostic command framework
fparain
parents:
diff changeset
   157
#endif  /* SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP */