comparison src/share/vm/services/diagnosticArgument.hpp @ 4932:f1cb6f9cfe21

7145243: Need additional specializations for argument parsing framework Reviewed-by: acorn, fparain Contributed-by: nils.loodin@oracle.com
author fparain
date Wed, 15 Feb 2012 12:17:30 -0800
parents 3b688d6ff3d0
children 51612f0c0a79
comparison
equal deleted inserted replaced
4931:64fc5ac1b770 4932:f1cb6f9cfe21
1 /* 1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
29 #include "memory/allocation.hpp" 29 #include "memory/allocation.hpp"
30 #include "runtime/os.hpp" 30 #include "runtime/os.hpp"
31 #include "runtime/thread.hpp" 31 #include "runtime/thread.hpp"
32 #include "utilities/exceptions.hpp" 32 #include "utilities/exceptions.hpp"
33 33
34 class StringArrayArgument : public CHeapObj {
35 private:
36 GrowableArray<char*>* _array;
37 public:
38 StringArrayArgument() {
39 _array = new(ResourceObj::C_HEAP)GrowableArray<char *>(32, true);
40 assert(_array != NULL, "Sanity check");
41 }
42 void add(const char* str, size_t len) {
43 if (str != NULL) {
44 char* ptr = NEW_C_HEAP_ARRAY(char, len+1);
45 strncpy(ptr, str, len);
46 ptr[len] = 0;
47 _array->append(ptr);
48 }
49 }
50 GrowableArray<char*>* array() {
51 return _array;
52 }
53 ~StringArrayArgument() {
54 for (int i=0; i<_array->length(); i++) {
55 if(_array->at(i) != NULL) { // Safety check
56 FREE_C_HEAP_ARRAY(char, _array->at(i));
57 }
58 }
59 delete _array;
60 }
61 };
62
63 class NanoTimeArgument {
64 public:
65 jlong _nanotime;
66 jlong _time;
67 char _unit[3];
68 };
69
70 class MemorySizeArgument {
71 public:
72 u8 _size;
73 u8 _val;
74 char _multiplier;
75 };
76
34 class GenDCmdArgument : public ResourceObj { 77 class GenDCmdArgument : public ResourceObj {
35 protected: 78 protected:
36 GenDCmdArgument* _next; 79 GenDCmdArgument* _next;
37 const char* _name; 80 const char* _name;
38 const char* _description; 81 const char* _description;
39 const char* _type; 82 const char* _type;
40 const char* _default_string; 83 const char* _default_string;
41 bool _is_set; 84 bool _is_set;
42 bool _is_mandatory; 85 bool _is_mandatory;
86 bool _allow_multiple;
43 GenDCmdArgument(const char* name, const char* description, const char* type, 87 GenDCmdArgument(const char* name, const char* description, const char* type,
44 const char* default_string, bool mandatory) { 88 const char* default_string, bool mandatory) {
45 _name = name; 89 _name = name;
46 _description = description; 90 _description = description;
47 _type = type; 91 _type = type;
48 _default_string = default_string; 92 _default_string = default_string;
49 _is_mandatory = mandatory; 93 _is_mandatory = mandatory;
50 _is_set = false; 94 _is_set = false;
95 _allow_multiple = false;
51 }; 96 };
52 public: 97 public:
53 const char* name() { return _name; } 98 const char* name() { return _name; }
54 const char* description() { return _description; } 99 const char* description() { return _description; }
55 const char* type() { return _type; } 100 const char* type() { return _type; }
56 const char* default_string() { return _default_string; } 101 const char* default_string() { return _default_string; }
57 bool is_set() { return _is_set; } 102 bool is_set() { return _is_set; }
58 void set_is_set(bool b) { _is_set = b; } 103 void set_is_set(bool b) { _is_set = b; }
104 bool allow_multiple() { return _allow_multiple; }
59 bool is_mandatory() { return _is_mandatory; } 105 bool is_mandatory() { return _is_mandatory; }
60 bool has_value() { return _is_set || _default_string != NULL; } 106 bool has_value() { return _is_set || _default_string != NULL; }
61 bool has_default() { return _default_string != NULL; } 107 bool has_default() { return _default_string != NULL; }
62 void read_value(const char* str, size_t len, TRAPS); 108 void read_value(const char* str, size_t len, TRAPS);
63 virtual void parse_value(const char* str, size_t len, TRAPS) = 0; 109 virtual void parse_value(const char* str, size_t len, TRAPS) = 0;