src/share/vm/services/diagnosticArgument.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

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

mercurial