0N/A/*
0N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
873N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
0N/A * questions.
0N/A *
0N/A */
0N/A
3215N/A#ifndef SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP
0N/A#define SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP
0N/A
0N/A#include "classfile/vmSymbols.hpp"
0N/A#include "memory/allocation.hpp"
0N/A#include "runtime/os.hpp"
0N/A#include "runtime/thread.hpp"
0N/A#include "utilities/exceptions.hpp"
0N/A
3012N/Aclass StringArrayArgument : public CHeapObj<mtInternal> {
3012N/Aprivate:
3381N/A GrowableArray<char*>* _array;
3349N/Apublic:
3349N/A StringArrayArgument() {
3012N/A _array = new(ResourceObj::C_HEAP, mtInternal)GrowableArray<char *>(32, true);
1083N/A assert(_array != NULL, "Sanity check");
1083N/A }
1083N/A void add(const char* str, size_t len) {
1083N/A if (str != NULL) {
1083N/A char* ptr = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
1083N/A strncpy(ptr, str, len);
1083N/A ptr[len] = 0;
1083N/A _array->append(ptr);
3090N/A }
3090N/A }
3214N/A GrowableArray<char*>* array() {
3764N/A return _array;
1083N/A }
1083N/A ~StringArrayArgument() {
1083N/A for (int i=0; i<_array->length(); i++) {
1083N/A if(_array->at(i) != NULL) { // Safety check
233N/A FREE_C_HEAP_ARRAY(char, _array->at(i), mtInternal);
712N/A }
1177N/A }
564N/A delete _array;
0N/A }
0N/A};
0N/A
0N/Aclass NanoTimeArgument {
712N/Apublic:
0N/A jlong _nanotime;
0N/A jlong _time;
0N/A char _unit[3];
0N/A};
0N/A
233N/Aclass MemorySizeArgument {
233N/Apublic:
0N/A u8 _size;
0N/A u8 _val;
0N/A char _multiplier;
0N/A};
0N/A
0N/Aclass GenDCmdArgument : public ResourceObj {
0N/Aprotected:
0N/A GenDCmdArgument* _next;
567N/A const char* _name;
567N/A const char* _description;
567N/A const char* _type;
567N/A const char* _default_string;
2046N/A bool _is_set;
2046N/A bool _is_mandatory;
1210N/A bool _allow_multiple;
2033N/A GenDCmdArgument(const char* name, const char* description, const char* type,
712N/A const char* default_string, bool mandatory) {
2033N/A _name = name;
2046N/A _description = description;
712N/A _type = type;
675N/A _default_string = default_string;
675N/A _is_mandatory = mandatory;
712N/A _is_set = false;
675N/A _allow_multiple = false;
567N/A };
0N/Apublic:
422N/A const char* name() { return _name; }
712N/A const char* description() { return _description; }
422N/A const char* type() { return _type; }
0N/A const char* default_string() { return _default_string; }
422N/A bool is_set() { return _is_set; }
0N/A void set_is_set(bool b) { _is_set = b; }
422N/A bool allow_multiple() { return _allow_multiple; }
0N/A bool is_mandatory() { return _is_mandatory; }
0N/A bool has_value() { return _is_set || _default_string != NULL; }
0N/A bool has_default() { return _default_string != NULL; }
0N/A void read_value(const char* str, size_t len, TRAPS);
902N/A virtual void parse_value(const char* str, size_t len, TRAPS) = 0;
902N/A virtual void init_value(TRAPS) = 0;
902N/A virtual void reset(TRAPS) = 0;
902N/A virtual void cleanup() = 0;
0N/A virtual void value_as_str(char* buf, size_t len) = 0;
0N/A void set_next(GenDCmdArgument* arg) {
0N/A _next = arg;
0N/A }
233N/A GenDCmdArgument* next() {
233N/A return _next;
233N/A }
233N/A
730N/A void to_string(jlong l, char* buf, size_t len);
730N/A void to_string(bool b, char* buf, size_t len);
730N/A void to_string(char* c, char* buf, size_t len);
0N/A void to_string(NanoTimeArgument n, char* buf, size_t len);
729N/A void to_string(MemorySizeArgument f, char* buf, size_t len);
729N/A void to_string(StringArrayArgument* s, char* buf, size_t len);
729N/A};
0N/A
0N/Atemplate <class ArgType> class DCmdArgument: public GenDCmdArgument {
0N/Aprivate:
110N/A ArgType _value;
110N/Apublic:
121N/A DCmdArgument(const char* name, const char* description, const char* type,
699N/A bool mandatory) :
0N/A GenDCmdArgument(name, description, type, NULL, mandatory) { }
0N/A DCmdArgument(const char* name, const char* description, const char* type,
1008N/A bool mandatory, const char* defaultvalue) :
1008N/A GenDCmdArgument(name, description, type, defaultvalue, mandatory)
1008N/A { }
1008N/A ~DCmdArgument() { destroy_value(); }
3214N/A ArgType value() { return _value;}
3381N/A void set_value(ArgType v) { _value = v; }
2086N/A void reset(TRAPS) {
3646N/A destroy_value();
3646N/A init_value(CHECK);
3646N/A _is_set = false;
2086N/A }
3646N/A void cleanup() {
1177N/A destroy_value();
3349N/A }
3349N/A void parse_value(const char* str, size_t len, TRAPS);
3349N/A void init_value(TRAPS);
3349N/A void destroy_value();
3349N/A void value_as_str(char *buf, size_t len) { return to_string(_value, buf, len);}
3349N/A};
3381N/A
3381N/A#endif /* SHARE_VM_SERVICES_DIAGNOSTICARGUMENT_HPP */
3349N/A