Path: blob/master/src/hotspot/share/services/diagnosticArgument.hpp
41144 views
/*1* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_SERVICES_DIAGNOSTICARGUMENT_HPP25#define SHARE_SERVICES_DIAGNOSTICARGUMENT_HPP2627#include "classfile/vmSymbols.hpp"28#include "memory/allocation.hpp"29#include "runtime/os.hpp"30#include "runtime/thread.hpp"31#include "utilities/exceptions.hpp"3233class StringArrayArgument : public CHeapObj<mtInternal> {34private:35GrowableArray<char*>* _array;36public:37StringArrayArgument();38~StringArrayArgument();3940void add(const char* str, size_t len);4142GrowableArray<char*>* array() {43return _array;44}45};4647class NanoTimeArgument {48public:49jlong _nanotime;50jlong _time;51char _unit[3];52};5354class MemorySizeArgument {55public:56u8 _size;57u8 _val;58char _multiplier;59};6061class GenDCmdArgument : public ResourceObj {62protected:63GenDCmdArgument* _next;64const char* const _name;65const char* const _description;66const char* const _type;67const char* const _default_string;68bool _is_set;69const bool _is_mandatory;70bool _allow_multiple;71GenDCmdArgument(const char* name, const char* description, const char* type,72const char* default_string, bool mandatory)73: _next(NULL), _name(name), _description(description), _type(type),74_default_string(default_string), _is_set(false), _is_mandatory(mandatory),75_allow_multiple(false) {}76public:77const char* name() const { return _name; }78const char* description() const { return _description; }79const char* type() const { return _type; }80const char* default_string() const { return _default_string; }81bool is_set() const { return _is_set; }82void set_is_set(bool b) { _is_set = b; }83bool allow_multiple() const { return _allow_multiple; }84bool is_mandatory() const { return _is_mandatory; }85bool has_value() const { return _is_set || _default_string != NULL; }86bool has_default() const { return _default_string != NULL; }87void read_value(const char* str, size_t len, TRAPS);88virtual void parse_value(const char* str, size_t len, TRAPS) = 0;89virtual void init_value(TRAPS) = 0;90virtual void reset(TRAPS) = 0;91virtual void cleanup() = 0;92virtual void value_as_str(char* buf, size_t len) const = 0;93void set_next(GenDCmdArgument* arg) {94_next = arg;95}96GenDCmdArgument* next() {97return _next;98}99100void to_string(jlong l, char* buf, size_t len) const;101void to_string(bool b, char* buf, size_t len) const;102void to_string(char* c, char* buf, size_t len) const;103void to_string(NanoTimeArgument n, char* buf, size_t len) const;104void to_string(MemorySizeArgument f, char* buf, size_t len) const;105void to_string(StringArrayArgument* s, char* buf, size_t len) const;106};107108template <class ArgType> class DCmdArgument: public GenDCmdArgument {109private:110ArgType _value;111public:112DCmdArgument(const char* name, const char* description, const char* type,113bool mandatory) :114GenDCmdArgument(name, description, type, NULL, mandatory) { }115DCmdArgument(const char* name, const char* description, const char* type,116bool mandatory, const char* defaultvalue) :117GenDCmdArgument(name, description, type, defaultvalue, mandatory)118{ }119~DCmdArgument() { destroy_value(); }120ArgType value() const { return _value;}121void set_value(ArgType v) { _value = v; }122void reset(TRAPS) {123destroy_value();124init_value(CHECK);125_is_set = false;126}127void cleanup() {128destroy_value();129}130void parse_value(const char* str, size_t len, TRAPS);131void init_value(TRAPS);132void destroy_value();133void value_as_str(char *buf, size_t len) const { to_string(_value, buf, len);}134};135136#endif // SHARE_SERVICES_DIAGNOSTICARGUMENT_HPP137138139