author | neliasso |
Thu, 25 Feb 2016 10:44:19 +0100 | |
changeset 36322 | 218528915a61 |
parent 31592 | 43f48e165466 |
child 39413 | 47b4126187e1 |
permissions | -rw-r--r-- |
11209 | 1 |
/* |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
20061
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
11209 | 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" |
|
18025 | 27 |
#include "memory/resourceArea.hpp" |
11209 | 28 |
#include "runtime/thread.hpp" |
29 |
#include "services/diagnosticArgument.hpp" |
|
30 |
||
31 |
void GenDCmdArgument::read_value(const char* str, size_t len, TRAPS) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
32 |
/* NOTE:Some argument types doesn't require a value, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
33 |
* for instance boolean arguments: "enableFeatureX". is |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
34 |
* equivalent to "enableFeatureX=true". In these cases, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
35 |
* str will be null. This is perfectly valid. |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
36 |
* All argument types must perform null checks on str. |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
37 |
*/ |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
38 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
39 |
if (is_set() && !allow_multiple()) { |
11209 | 40 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
41 |
"Duplicates in diagnostic command arguments\n"); |
11209 | 42 |
} |
43 |
parse_value(str, len, CHECK); |
|
44 |
set_is_set(true); |
|
45 |
} |
|
46 |
||
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
47 |
void GenDCmdArgument::to_string(jlong l, char* buf, size_t len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
48 |
jio_snprintf(buf, len, INT64_FORMAT, l); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
49 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
50 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
51 |
void GenDCmdArgument::to_string(bool b, char* buf, size_t len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
52 |
jio_snprintf(buf, len, b ? "true" : "false"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
53 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
54 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
55 |
void GenDCmdArgument::to_string(NanoTimeArgument n, char* buf, size_t len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
56 |
jio_snprintf(buf, len, INT64_FORMAT, n._nanotime); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
57 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
58 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
59 |
void GenDCmdArgument::to_string(MemorySizeArgument m, char* buf, size_t len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
60 |
jio_snprintf(buf, len, INT64_FORMAT, m._size); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
61 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
62 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
63 |
void GenDCmdArgument::to_string(char* c, char* buf, size_t len) { |
20061 | 64 |
jio_snprintf(buf, len, "%s", (c != NULL) ? c : ""); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
65 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
66 |
|
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
67 |
void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
68 |
int length = f->array()->length(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
69 |
size_t written = 0; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
70 |
buf[0] = 0; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
71 |
for (int i = 0; i < length; i++) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
72 |
char* next_str = f->array()->at(i); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
73 |
size_t next_size = strlen(next_str); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
74 |
//Check if there's room left to write next element |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
75 |
if (written + next_size > len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
76 |
return; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
77 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
78 |
//Actually write element |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
79 |
strcat(buf, next_str); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
80 |
written += next_size; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
81 |
//Check if there's room left for the comma |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
82 |
if (i < length-1 && len - written > 0) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
83 |
strcat(buf, ","); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
84 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
85 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
86 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
87 |
|
11209 | 88 |
template <> void DCmdArgument<jlong>::parse_value(const char* str, |
89 |
size_t len, TRAPS) { |
|
18025 | 90 |
int scanned = -1; |
91 |
if (str == NULL |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
27880
diff
changeset
|
92 |
|| sscanf(str, JLONG_FORMAT "%n", &_value, &scanned) != 1 |
18025 | 93 |
|| (size_t)scanned != len) |
94 |
{ |
|
95 |
ResourceMark rm; |
|
96 |
||
97 |
char* buf = NEW_RESOURCE_ARRAY(char, len + 1); |
|
98 |
strncpy(buf, str, len); |
|
99 |
buf[len] = '\0'; |
|
100 |
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), |
|
101 |
"Integer parsing error in command argument '%s'. Could not parse: %s.", _name, buf); |
|
11209 | 102 |
} |
103 |
} |
|
104 |
||
105 |
template <> void DCmdArgument<jlong>::init_value(TRAPS) { |
|
106 |
if (has_default()) { |
|
107 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
|
108 |
if (HAS_PENDING_EXCEPTION) { |
|
18025 | 109 |
fatal("Default string must be parseable"); |
11209 | 110 |
} |
111 |
} else { |
|
112 |
set_value(0); |
|
113 |
} |
|
114 |
} |
|
115 |
||
116 |
template <> void DCmdArgument<jlong>::destroy_value() { } |
|
117 |
||
118 |
template <> void DCmdArgument<bool>::parse_value(const char* str, |
|
119 |
size_t len, TRAPS) { |
|
11596
3b9802e6c6a2
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
11209
diff
changeset
|
120 |
// len is the length of the current token starting at str |
11209 | 121 |
if (len == 0) { |
122 |
set_value(true); |
|
123 |
} else { |
|
11596
3b9802e6c6a2
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
11209
diff
changeset
|
124 |
if (len == strlen("true") && strncasecmp(str, "true", len) == 0) { |
11209 | 125 |
set_value(true); |
11596
3b9802e6c6a2
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
11209
diff
changeset
|
126 |
} else if (len == strlen("false") && strncasecmp(str, "false", len) == 0) { |
11209 | 127 |
set_value(false); |
128 |
} else { |
|
18025 | 129 |
ResourceMark rm; |
130 |
||
131 |
char* buf = NEW_RESOURCE_ARRAY(char, len + 1); |
|
132 |
strncpy(buf, str, len); |
|
133 |
buf[len] = '\0'; |
|
134 |
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), |
|
135 |
"Boolean parsing error in command argument '%s'. Could not parse: %s.", _name, buf); |
|
11209 | 136 |
} |
137 |
} |
|
138 |
} |
|
139 |
||
140 |
template <> void DCmdArgument<bool>::init_value(TRAPS) { |
|
141 |
if (has_default()) { |
|
142 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
|
143 |
if (HAS_PENDING_EXCEPTION) { |
|
144 |
fatal("Default string must be parsable"); |
|
145 |
} |
|
146 |
} else { |
|
147 |
set_value(false); |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
template <> void DCmdArgument<bool>::destroy_value() { } |
|
152 |
||
153 |
template <> void DCmdArgument<char*>::parse_value(const char* str, |
|
154 |
size_t len, TRAPS) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
155 |
if (str == NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
156 |
_value = NULL; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
157 |
} else { |
13195 | 158 |
_value = NEW_C_HEAP_ARRAY(char, len+1, mtInternal); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
159 |
strncpy(_value, str, len); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
160 |
_value[len] = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
161 |
} |
11209 | 162 |
} |
163 |
||
164 |
template <> void DCmdArgument<char*>::init_value(TRAPS) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
165 |
if (has_default() && _default_string != NULL) { |
11209 | 166 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
167 |
if (HAS_PENDING_EXCEPTION) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
168 |
fatal("Default string must be parsable"); |
11209 | 169 |
} |
170 |
} else { |
|
171 |
set_value(NULL); |
|
172 |
} |
|
173 |
} |
|
174 |
||
175 |
template <> void DCmdArgument<char*>::destroy_value() { |
|
176 |
if (_value != NULL) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
20061
diff
changeset
|
177 |
FREE_C_HEAP_ARRAY(char, _value); |
11209 | 178 |
set_value(NULL); |
179 |
} |
|
180 |
} |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
181 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
182 |
template <> void DCmdArgument<NanoTimeArgument>::parse_value(const char* str, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
183 |
size_t len, TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
184 |
if (str == NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
185 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
18025 | 186 |
"Integer parsing error nanotime value: syntax error, value is null"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
187 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
188 |
|
15228
e92acc84ade3
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
13195
diff
changeset
|
189 |
int argc = sscanf(str, JLONG_FORMAT, &_value._time); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
190 |
if (argc != 1) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
191 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
192 |
"Integer parsing error nanotime value: syntax error"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
193 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
194 |
size_t idx = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
195 |
while(idx < len && isdigit(str[idx])) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
196 |
idx++; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
197 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
198 |
if (idx == len) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
199 |
// only accept missing unit if the value is 0 |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
200 |
if (_value._time != 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
201 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
202 |
"Integer parsing error nanotime value: unit required"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
203 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
204 |
_value._nanotime = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
205 |
strcpy(_value._unit, "ns"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
206 |
return; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
207 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
208 |
} else if(len - idx > 2) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
209 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
210 |
"Integer parsing error nanotime value: illegal unit"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
211 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
212 |
strncpy(_value._unit, &str[idx], len - idx); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
213 |
/*Write an extra null termination. This is safe because _value._unit |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
214 |
* is declared as char[3], and length is checked to be not larger than |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
215 |
* two above. Also, this is necessary, since length might be 1, and the |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
216 |
* default value already in the string is ns, which is two chars. |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
217 |
*/ |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
218 |
_value._unit[len-idx] = '\0'; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
219 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
220 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
221 |
if (strcmp(_value._unit, "ns") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
222 |
_value._nanotime = _value._time; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
223 |
} else if (strcmp(_value._unit, "us") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
224 |
_value._nanotime = _value._time * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
225 |
} else if (strcmp(_value._unit, "ms") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
226 |
_value._nanotime = _value._time * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
227 |
} else if (strcmp(_value._unit, "s") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
228 |
_value._nanotime = _value._time * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
229 |
} else if (strcmp(_value._unit, "m") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
230 |
_value._nanotime = _value._time * 60 * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
231 |
} else if (strcmp(_value._unit, "h") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
232 |
_value._nanotime = _value._time * 60 * 60 * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
233 |
} else if (strcmp(_value._unit, "d") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
234 |
_value._nanotime = _value._time * 24 * 60 * 60 * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
235 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
236 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
237 |
"Integer parsing error nanotime value: illegal unit"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
238 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
239 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
240 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
241 |
template <> void DCmdArgument<NanoTimeArgument>::init_value(TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
242 |
if (has_default()) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
243 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
244 |
if (HAS_PENDING_EXCEPTION) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
245 |
fatal("Default string must be parsable"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
246 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
247 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
248 |
_value._time = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
249 |
_value._nanotime = 0; |
18073
f02460441ddc
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents:
18025
diff
changeset
|
250 |
strcpy(_value._unit, "ns"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
251 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
252 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
253 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
254 |
template <> void DCmdArgument<NanoTimeArgument>::destroy_value() { } |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
255 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
256 |
// WARNING StringArrayArgument can only be used as an option, it cannot be |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
257 |
// used as an argument with the DCmdParser |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
258 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
259 |
template <> void DCmdArgument<StringArrayArgument*>::parse_value(const char* str, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
260 |
size_t len, TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
261 |
_value->add(str,len); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
262 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
263 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
264 |
template <> void DCmdArgument<StringArrayArgument*>::init_value(TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
265 |
_value = new StringArrayArgument(); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
266 |
_allow_multiple = true; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
267 |
if (has_default()) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
268 |
fatal("StringArrayArgument cannot have default value"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
269 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
270 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
271 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
272 |
template <> void DCmdArgument<StringArrayArgument*>::destroy_value() { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
273 |
if (_value != NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
274 |
delete _value; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
275 |
set_value(NULL); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
276 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
277 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
278 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
279 |
template <> void DCmdArgument<MemorySizeArgument>::parse_value(const char* str, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
280 |
size_t len, TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
281 |
if (str == NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
282 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
283 |
"Integer parsing error nanotime value: syntax error"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
284 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
285 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
286 |
if (*str == '-') { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
287 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
288 |
"Parsing error memory size value: negative values not allowed"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
289 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
290 |
int res = sscanf(str, UINT64_FORMAT "%c", &_value._val, &_value._multiplier); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
291 |
if (res == 2) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
292 |
switch (_value._multiplier) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
293 |
case 'k': case 'K': |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
294 |
_value._size = _value._val * 1024; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
295 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
296 |
case 'm': case 'M': |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
297 |
_value._size = _value._val * 1024 * 1024; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
298 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
299 |
case 'g': case 'G': |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
300 |
_value._size = _value._val * 1024 * 1024 * 1024; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
301 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
302 |
default: |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
303 |
_value._size = _value._val; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
304 |
_value._multiplier = ' '; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
305 |
//default case should be to break with no error, since user |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
306 |
//can write size in bytes, or might have a delimiter and next arg |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
307 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
308 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
309 |
} else if (res == 1) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
310 |
_value._size = _value._val; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
311 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
312 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
313 |
"Parsing error memory size value: invalid value"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
314 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
315 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
316 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
317 |
template <> void DCmdArgument<MemorySizeArgument>::init_value(TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
318 |
if (has_default()) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
319 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
320 |
if (HAS_PENDING_EXCEPTION) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
321 |
fatal("Default string must be parsable"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
322 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
323 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
324 |
_value._size = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
325 |
_value._val = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
326 |
_value._multiplier = ' '; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
327 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
328 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
329 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
330 |
template <> void DCmdArgument<MemorySizeArgument>::destroy_value() { } |