Mercurial > hg > graal-compiler
annotate src/share/vm/services/diagnosticArgument.cpp @ 7046:b6a8f2d23057
VM support for deferred reads and writes: ScopeDesc, DebugInfo, DebugInfoRecorder
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Tue, 27 Nov 2012 13:43:04 +0100 |
parents | d2a62e0f25eb |
children | 79f492f184d0 203f64878aab |
rev | line source |
---|---|
4133 | 1 /* |
4849
520830f632e7
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
4133
diff
changeset
|
2 * Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved. |
4133 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #include "precompiled.hpp" | |
26 #include "memory/allocation.inline.hpp" | |
27 #include "runtime/thread.hpp" | |
28 #include "services/diagnosticArgument.hpp" | |
29 | |
30 void GenDCmdArgument::read_value(const char* str, size_t len, TRAPS) { | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
31 /* NOTE:Some argument types doesn't require a value, |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
32 * for instance boolean arguments: "enableFeatureX". is |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
33 * equivalent to "enableFeatureX=true". In these cases, |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
34 * str will be null. This is perfectly valid. |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
35 * All argument types must perform null checks on str. |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
36 */ |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
37 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
38 if (is_set() && !allow_multiple()) { |
4133 | 39 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
40 "Duplicates in diagnostic command arguments\n"); |
4133 | 41 } |
42 parse_value(str, len, CHECK); | |
43 set_is_set(true); | |
44 } | |
45 | |
5978
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
46 void GenDCmdArgument::to_string(jlong l, char* buf, size_t len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
47 jio_snprintf(buf, len, INT64_FORMAT, l); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
48 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
49 |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
50 void GenDCmdArgument::to_string(bool b, char* buf, size_t len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
51 jio_snprintf(buf, len, b ? "true" : "false"); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
52 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
53 |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
54 void GenDCmdArgument::to_string(NanoTimeArgument n, char* buf, size_t len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
55 jio_snprintf(buf, len, INT64_FORMAT, n._nanotime); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
56 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
57 |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
58 void GenDCmdArgument::to_string(MemorySizeArgument m, char* buf, size_t len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
59 jio_snprintf(buf, len, INT64_FORMAT, m._size); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
60 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
61 |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
62 void GenDCmdArgument::to_string(char* c, char* buf, size_t len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
63 jio_snprintf(buf, len, "%s", c); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
64 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
65 |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
66 void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
67 int length = f->array()->length(); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
68 size_t written = 0; |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
69 buf[0] = 0; |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
70 for (int i = 0; i < length; i++) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
71 char* next_str = f->array()->at(i); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
72 size_t next_size = strlen(next_str); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
73 //Check if there's room left to write next element |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
74 if (written + next_size > len) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
75 return; |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
76 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
77 //Actually write element |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
78 strcat(buf, next_str); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
79 written += next_size; |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
80 //Check if there's room left for the comma |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
81 if (i < length-1 && len - written > 0) { |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
82 strcat(buf, ","); |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
83 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
84 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
85 } |
51612f0c0a79
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
4932
diff
changeset
|
86 |
4133 | 87 template <> void DCmdArgument<jlong>::parse_value(const char* str, |
88 size_t len, TRAPS) { | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
89 if (str == NULL || sscanf(str, INT64_FORMAT, &_value) != 1) { |
4133 | 90 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
91 "Integer parsing error in diagnostic command arguments\n"); |
4133 | 92 } |
93 } | |
94 | |
95 template <> void DCmdArgument<jlong>::init_value(TRAPS) { | |
96 if (has_default()) { | |
97 this->parse_value(_default_string, strlen(_default_string), THREAD); | |
98 if (HAS_PENDING_EXCEPTION) { | |
99 fatal("Default string must be parsable"); | |
100 } | |
101 } else { | |
102 set_value(0); | |
103 } | |
104 } | |
105 | |
106 template <> void DCmdArgument<jlong>::destroy_value() { } | |
107 | |
108 template <> void DCmdArgument<bool>::parse_value(const char* str, | |
109 size_t len, TRAPS) { | |
4849
520830f632e7
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
4133
diff
changeset
|
110 // len is the length of the current token starting at str |
4133 | 111 if (len == 0) { |
112 set_value(true); | |
113 } else { | |
4849
520830f632e7
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
4133
diff
changeset
|
114 if (len == strlen("true") && strncasecmp(str, "true", len) == 0) { |
4133 | 115 set_value(true); |
4849
520830f632e7
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
4133
diff
changeset
|
116 } else if (len == strlen("false") && strncasecmp(str, "false", len) == 0) { |
4133 | 117 set_value(false); |
118 } else { | |
119 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), | |
120 "Boolean parsing error in diagnostic command arguments"); | |
121 } | |
122 } | |
123 } | |
124 | |
125 template <> void DCmdArgument<bool>::init_value(TRAPS) { | |
126 if (has_default()) { | |
127 this->parse_value(_default_string, strlen(_default_string), THREAD); | |
128 if (HAS_PENDING_EXCEPTION) { | |
129 fatal("Default string must be parsable"); | |
130 } | |
131 } else { | |
132 set_value(false); | |
133 } | |
134 } | |
135 | |
136 template <> void DCmdArgument<bool>::destroy_value() { } | |
137 | |
138 template <> void DCmdArgument<char*>::parse_value(const char* str, | |
139 size_t len, TRAPS) { | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
140 if (str == NULL) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
141 _value = NULL; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
142 } else { |
6197 | 143 _value = NEW_C_HEAP_ARRAY(char, len+1, mtInternal); |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
144 strncpy(_value, str, len); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
145 _value[len] = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
146 } |
4133 | 147 } |
148 | |
149 template <> void DCmdArgument<char*>::init_value(TRAPS) { | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
150 if (has_default() && _default_string != NULL) { |
4133 | 151 this->parse_value(_default_string, strlen(_default_string), THREAD); |
152 if (HAS_PENDING_EXCEPTION) { | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
153 fatal("Default string must be parsable"); |
4133 | 154 } |
155 } else { | |
156 set_value(NULL); | |
157 } | |
158 } | |
159 | |
160 template <> void DCmdArgument<char*>::destroy_value() { | |
161 if (_value != NULL) { | |
6197 | 162 FREE_C_HEAP_ARRAY(char, _value, mtInternal); |
4133 | 163 set_value(NULL); |
164 } | |
165 } | |
4932
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
166 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
167 template <> void DCmdArgument<NanoTimeArgument>::parse_value(const char* str, |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
168 size_t len, TRAPS) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
169 if (str == NULL) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
170 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
171 "Integer parsing error nanotime value: syntax error"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
172 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
173 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
174 int argc = sscanf(str, INT64_FORMAT , &_value._time); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
175 if (argc != 1) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
176 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
177 "Integer parsing error nanotime value: syntax error"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
178 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
179 size_t idx = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
180 while(idx < len && isdigit(str[idx])) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
181 idx++; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
182 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
183 if (idx == len) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
184 // only accept missing unit if the value is 0 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
185 if (_value._time != 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
186 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
187 "Integer parsing error nanotime value: unit required"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
188 } else { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
189 _value._nanotime = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
190 strcpy(_value._unit, "ns"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
191 return; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
192 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
193 } else if(len - idx > 2) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
194 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
195 "Integer parsing error nanotime value: illegal unit"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
196 } else { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
197 strncpy(_value._unit, &str[idx], len - idx); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
198 /*Write an extra null termination. This is safe because _value._unit |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
199 * is declared as char[3], and length is checked to be not larger than |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
200 * two above. Also, this is necessary, since length might be 1, and the |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
201 * default value already in the string is ns, which is two chars. |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
202 */ |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
203 _value._unit[len-idx] = '\0'; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
204 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
205 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
206 if (strcmp(_value._unit, "ns") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
207 _value._nanotime = _value._time; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
208 } else if (strcmp(_value._unit, "us") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
209 _value._nanotime = _value._time * 1000; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
210 } else if (strcmp(_value._unit, "ms") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
211 _value._nanotime = _value._time * 1000 * 1000; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
212 } else if (strcmp(_value._unit, "s") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
213 _value._nanotime = _value._time * 1000 * 1000 * 1000; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
214 } else if (strcmp(_value._unit, "m") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
215 _value._nanotime = _value._time * 60 * 1000 * 1000 * 1000; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
216 } else if (strcmp(_value._unit, "h") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
217 _value._nanotime = _value._time * 60 * 60 * 1000 * 1000 * 1000; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
218 } else if (strcmp(_value._unit, "d") == 0) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
219 _value._nanotime = _value._time * 24 * 60 * 60 * 1000 * 1000 * 1000; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
220 } else { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
221 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
222 "Integer parsing error nanotime value: illegal unit"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
223 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
224 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
225 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
226 template <> void DCmdArgument<NanoTimeArgument>::init_value(TRAPS) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
227 if (has_default()) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
228 this->parse_value(_default_string, strlen(_default_string), THREAD); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
229 if (HAS_PENDING_EXCEPTION) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
230 fatal("Default string must be parsable"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
231 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
232 } else { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
233 _value._time = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
234 _value._nanotime = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
235 strcmp(_value._unit, "ns"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
236 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
237 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
238 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
239 template <> void DCmdArgument<NanoTimeArgument>::destroy_value() { } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
240 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
241 // WARNING StringArrayArgument can only be used as an option, it cannot be |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
242 // used as an argument with the DCmdParser |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
243 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
244 template <> void DCmdArgument<StringArrayArgument*>::parse_value(const char* str, |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
245 size_t len, TRAPS) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
246 _value->add(str,len); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
247 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
248 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
249 template <> void DCmdArgument<StringArrayArgument*>::init_value(TRAPS) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
250 _value = new StringArrayArgument(); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
251 _allow_multiple = true; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
252 if (has_default()) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
253 fatal("StringArrayArgument cannot have default value"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
254 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
255 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
256 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
257 template <> void DCmdArgument<StringArrayArgument*>::destroy_value() { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
258 if (_value != NULL) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
259 delete _value; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
260 set_value(NULL); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
261 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
262 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
263 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
264 template <> void DCmdArgument<MemorySizeArgument>::parse_value(const char* str, |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
265 size_t len, TRAPS) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
266 if (str == NULL) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
267 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
268 "Integer parsing error nanotime value: syntax error"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
269 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
270 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
271 if (*str == '-') { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
272 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
273 "Parsing error memory size value: negative values not allowed"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
274 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
275 int res = sscanf(str, UINT64_FORMAT "%c", &_value._val, &_value._multiplier); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
276 if (res == 2) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
277 switch (_value._multiplier) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
278 case 'k': case 'K': |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
279 _value._size = _value._val * 1024; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
280 break; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
281 case 'm': case 'M': |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
282 _value._size = _value._val * 1024 * 1024; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
283 break; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
284 case 'g': case 'G': |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
285 _value._size = _value._val * 1024 * 1024 * 1024; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
286 break; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
287 default: |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
288 _value._size = _value._val; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
289 _value._multiplier = ' '; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
290 //default case should be to break with no error, since user |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
291 //can write size in bytes, or might have a delimiter and next arg |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
292 break; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
293 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
294 } else if (res == 1) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
295 _value._size = _value._val; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
296 } else { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
297 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
298 "Parsing error memory size value: invalid value"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
299 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
300 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
301 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
302 template <> void DCmdArgument<MemorySizeArgument>::init_value(TRAPS) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
303 if (has_default()) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
304 this->parse_value(_default_string, strlen(_default_string), THREAD); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
305 if (HAS_PENDING_EXCEPTION) { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
306 fatal("Default string must be parsable"); |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
307 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
308 } else { |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
309 _value._size = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
310 _value._val = 0; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
311 _value._multiplier = ' '; |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
312 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
313 } |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
314 |
f1cb6f9cfe21
7145243: Need additional specializations for argument parsing framework
fparain
parents:
4849
diff
changeset
|
315 template <> void DCmdArgument<MemorySizeArgument>::destroy_value() { } |