Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/services/diagnosticArgument.hpp
32285 views
/*1* Copyright (c) 2012, 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_VM_SERVICES_DIAGNOSTICARGUMENT_HPP25#define SHARE_VM_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_array = new(ResourceObj::C_HEAP, mtInternal)GrowableArray<char *>(32, true);39assert(_array != NULL, "Sanity check");40}41void add(const char* str, size_t len) {42if (str != NULL) {43char* ptr = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);44strncpy(ptr, str, len);45ptr[len] = 0;46_array->append(ptr);47}48}49GrowableArray<char*>* array() {50return _array;51}52~StringArrayArgument() {53for (int i=0; i<_array->length(); i++) {54if(_array->at(i) != NULL) { // Safety check55FREE_C_HEAP_ARRAY(char, _array->at(i), mtInternal);56}57}58delete _array;59}60};6162class NanoTimeArgument {63public:64jlong _nanotime;65jlong _time;66char _unit[3];67};6869class MemorySizeArgument {70public:71u8 _size;72u8 _val;73char _multiplier;74};7576class GenDCmdArgument : public ResourceObj {77protected:78GenDCmdArgument* _next;79const char* _name;80const char* _description;81const char* _type;82const char* _default_string;83bool _is_set;84bool _is_mandatory;85bool _allow_multiple;86GenDCmdArgument(const char* name, const char* description, const char* type,87const char* default_string, bool mandatory) {88_name = name;89_description = description;90_type = type;91_default_string = default_string;92_is_mandatory = mandatory;93_is_set = false;94_allow_multiple = false;95};96public:97const char* name() { return _name; }98const char* description() { return _description; }99const char* type() { return _type; }100const char* default_string() { return _default_string; }101bool is_set() { return _is_set; }102void set_is_set(bool b) { _is_set = b; }103bool allow_multiple() { return _allow_multiple; }104bool is_mandatory() { return _is_mandatory; }105bool has_value() { return _is_set || _default_string != NULL; }106bool has_default() { return _default_string != NULL; }107void read_value(const char* str, size_t len, TRAPS);108virtual void parse_value(const char* str, size_t len, TRAPS) = 0;109virtual void init_value(TRAPS) = 0;110virtual void reset(TRAPS) = 0;111virtual void cleanup() = 0;112virtual void value_as_str(char* buf, size_t len) = 0;113void set_next(GenDCmdArgument* arg) {114_next = arg;115}116GenDCmdArgument* next() {117return _next;118}119120void to_string(jlong l, char* buf, size_t len);121void to_string(bool b, char* buf, size_t len);122void to_string(char* c, char* buf, size_t len);123void to_string(NanoTimeArgument n, char* buf, size_t len);124void to_string(MemorySizeArgument f, char* buf, size_t len);125void to_string(StringArrayArgument* s, char* buf, size_t len);126};127128template <class ArgType> class DCmdArgument: public GenDCmdArgument {129private:130ArgType _value;131public:132DCmdArgument(const char* name, const char* description, const char* type,133bool mandatory) :134GenDCmdArgument(name, description, type, NULL, mandatory) { }135DCmdArgument(const char* name, const char* description, const char* type,136bool mandatory, const char* defaultvalue) :137GenDCmdArgument(name, description, type, defaultvalue, mandatory)138{ }139~DCmdArgument() { destroy_value(); }140ArgType value() { return _value;}141void set_value(ArgType v) { _value = v; }142void reset(TRAPS) {143destroy_value();144init_value(CHECK);145_is_set = false;146}147void cleanup() {148destroy_value();149}150void parse_value(const char* str, size_t len, TRAPS);151void init_value(TRAPS);152void destroy_value();153void value_as_str(char *buf, size_t len) { return to_string(_value, buf, len);}154};155156#endif /* SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP */157158159