author | dcubed |
Wed, 18 Sep 2019 20:49:13 -0400 | |
changeset 58223 | 778fc2dcbdaa |
parent 58084 | cddef3bde924 |
child 58682 | 9f5b92d5a1b2 |
permissions | -rw-r--r-- |
11209 | 1 |
/* |
53882
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
50600
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, 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" |
|
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
26 |
#include "jvm.h" |
11209 | 27 |
#include "memory/allocation.inline.hpp" |
18025 | 28 |
#include "memory/resourceArea.hpp" |
11209 | 29 |
#include "runtime/thread.hpp" |
30 |
#include "services/diagnosticArgument.hpp" |
|
31 |
||
48157 | 32 |
StringArrayArgument::StringArrayArgument() { |
33 |
_array = new(ResourceObj::C_HEAP, mtInternal)GrowableArray<char *>(32, true); |
|
34 |
assert(_array != NULL, "Sanity check"); |
|
35 |
} |
|
36 |
||
37 |
StringArrayArgument::~StringArrayArgument() { |
|
38 |
for (int i=0; i<_array->length(); i++) { |
|
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
53908
diff
changeset
|
39 |
FREE_C_HEAP_ARRAY(char, _array->at(i)); |
48157 | 40 |
} |
41 |
delete _array; |
|
42 |
} |
|
43 |
||
44 |
void StringArrayArgument::add(const char* str, size_t len) { |
|
45 |
if (str != NULL) { |
|
46 |
char* ptr = NEW_C_HEAP_ARRAY(char, len+1, mtInternal); |
|
47 |
strncpy(ptr, str, len); |
|
48 |
ptr[len] = 0; |
|
49 |
_array->append(ptr); |
|
50 |
} |
|
51 |
} |
|
52 |
||
11209 | 53 |
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
|
54 |
/* NOTE:Some argument types doesn't require a value, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
55 |
* for instance boolean arguments: "enableFeatureX". is |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
56 |
* equivalent to "enableFeatureX=true". In these cases, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
57 |
* str will be null. This is perfectly valid. |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
58 |
* All argument types must perform null checks on str. |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
59 |
*/ |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
60 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
61 |
if (is_set() && !allow_multiple()) { |
11209 | 62 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
63 |
"Duplicates in diagnostic command arguments\n"); |
11209 | 64 |
} |
65 |
parse_value(str, len, CHECK); |
|
66 |
set_is_set(true); |
|
67 |
} |
|
68 |
||
50600
8e17fffa0a4b
8204958: Minor cleanups for the diagnostic framework
stuefe
parents:
48157
diff
changeset
|
69 |
void GenDCmdArgument::to_string(jlong l, char* buf, size_t len) const { |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
70 |
jio_snprintf(buf, len, INT64_FORMAT, l); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
71 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
72 |
|
50600
8e17fffa0a4b
8204958: Minor cleanups for the diagnostic framework
stuefe
parents:
48157
diff
changeset
|
73 |
void GenDCmdArgument::to_string(bool b, char* buf, size_t len) const { |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
74 |
jio_snprintf(buf, len, b ? "true" : "false"); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
75 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
76 |
|
50600
8e17fffa0a4b
8204958: Minor cleanups for the diagnostic framework
stuefe
parents:
48157
diff
changeset
|
77 |
void GenDCmdArgument::to_string(NanoTimeArgument n, char* buf, size_t len) const { |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
78 |
jio_snprintf(buf, len, INT64_FORMAT, n._nanotime); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
79 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
80 |
|
50600
8e17fffa0a4b
8204958: Minor cleanups for the diagnostic framework
stuefe
parents:
48157
diff
changeset
|
81 |
void GenDCmdArgument::to_string(MemorySizeArgument m, char* buf, size_t len) const { |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
82 |
jio_snprintf(buf, len, INT64_FORMAT, m._size); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
83 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
84 |
|
50600
8e17fffa0a4b
8204958: Minor cleanups for the diagnostic framework
stuefe
parents:
48157
diff
changeset
|
85 |
void GenDCmdArgument::to_string(char* c, char* buf, size_t len) const { |
20061 | 86 |
jio_snprintf(buf, len, "%s", (c != NULL) ? c : ""); |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
87 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
88 |
|
50600
8e17fffa0a4b
8204958: Minor cleanups for the diagnostic framework
stuefe
parents:
48157
diff
changeset
|
89 |
void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) const { |
12262
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
90 |
int length = f->array()->length(); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
91 |
size_t written = 0; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
92 |
buf[0] = 0; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
93 |
for (int i = 0; i < length; i++) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
94 |
char* next_str = f->array()->at(i); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
95 |
size_t next_size = strlen(next_str); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
96 |
//Check if there's room left to write next element |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
97 |
if (written + next_size > len) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
98 |
return; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
99 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
100 |
//Actually write element |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
101 |
strcat(buf, next_str); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
102 |
written += next_size; |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
103 |
//Check if there's room left for the comma |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
104 |
if (i < length-1 && len - written > 0) { |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
105 |
strcat(buf, ","); |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
106 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
107 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
108 |
} |
fb3b9fede660
7148488: Whitebox tests for the Diagnostic Framework Parser
nloodin
parents:
11776
diff
changeset
|
109 |
|
11209 | 110 |
template <> void DCmdArgument<jlong>::parse_value(const char* str, |
111 |
size_t len, TRAPS) { |
|
18025 | 112 |
int scanned = -1; |
113 |
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
|
114 |
|| sscanf(str, JLONG_FORMAT "%n", &_value, &scanned) != 1 |
18025 | 115 |
|| (size_t)scanned != len) |
116 |
{ |
|
117 |
ResourceMark rm; |
|
118 |
||
119 |
char* buf = NEW_RESOURCE_ARRAY(char, len + 1); |
|
120 |
strncpy(buf, str, len); |
|
121 |
buf[len] = '\0'; |
|
122 |
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), |
|
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
123 |
"Integer parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); |
11209 | 124 |
} |
125 |
} |
|
126 |
||
127 |
template <> void DCmdArgument<jlong>::init_value(TRAPS) { |
|
128 |
if (has_default()) { |
|
129 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
|
130 |
if (HAS_PENDING_EXCEPTION) { |
|
18025 | 131 |
fatal("Default string must be parseable"); |
11209 | 132 |
} |
133 |
} else { |
|
134 |
set_value(0); |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
template <> void DCmdArgument<jlong>::destroy_value() { } |
|
139 |
||
140 |
template <> void DCmdArgument<bool>::parse_value(const char* str, |
|
141 |
size_t len, TRAPS) { |
|
11596
3b9802e6c6a2
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
11209
diff
changeset
|
142 |
// len is the length of the current token starting at str |
11209 | 143 |
if (len == 0) { |
144 |
set_value(true); |
|
145 |
} else { |
|
11596
3b9802e6c6a2
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
11209
diff
changeset
|
146 |
if (len == strlen("true") && strncasecmp(str, "true", len) == 0) { |
11209 | 147 |
set_value(true); |
11596
3b9802e6c6a2
7131346: Parsing of boolean arguments to diagnostic commands is broken
fparain
parents:
11209
diff
changeset
|
148 |
} else if (len == strlen("false") && strncasecmp(str, "false", len) == 0) { |
11209 | 149 |
set_value(false); |
150 |
} else { |
|
18025 | 151 |
ResourceMark rm; |
152 |
||
153 |
char* buf = NEW_RESOURCE_ARRAY(char, len + 1); |
|
154 |
strncpy(buf, str, len); |
|
155 |
buf[len] = '\0'; |
|
156 |
Exceptions::fthrow(THREAD_AND_LOCATION, vmSymbols::java_lang_IllegalArgumentException(), |
|
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
157 |
"Boolean parsing error in command argument '%s'. Could not parse: %s.\n", _name, buf); |
11209 | 158 |
} |
159 |
} |
|
160 |
} |
|
161 |
||
162 |
template <> void DCmdArgument<bool>::init_value(TRAPS) { |
|
163 |
if (has_default()) { |
|
164 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
|
165 |
if (HAS_PENDING_EXCEPTION) { |
|
166 |
fatal("Default string must be parsable"); |
|
167 |
} |
|
168 |
} else { |
|
169 |
set_value(false); |
|
170 |
} |
|
171 |
} |
|
172 |
||
173 |
template <> void DCmdArgument<bool>::destroy_value() { } |
|
174 |
||
175 |
template <> void DCmdArgument<char*>::parse_value(const char* str, |
|
176 |
size_t len, TRAPS) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
177 |
if (str == NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
178 |
_value = NULL; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
179 |
} else { |
53882
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
50600
diff
changeset
|
180 |
_value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal); |
53908
45a23c64d0f6
8219583: Windows build failure after JDK-8214777 (Avoid some GCC 8.X strncpy() errors in HotSpot)
shade
parents:
53882
diff
changeset
|
181 |
int n = os::snprintf(_value, len + 1, "%.*s", (int)len, str); |
53882
ca682d9d8db5
8214777: Avoid some GCC 8.X strncpy() errors in HotSpot
mikael
parents:
50600
diff
changeset
|
182 |
assert((size_t)n <= len, "Unexpected number of characters in string"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
183 |
} |
11209 | 184 |
} |
185 |
||
186 |
template <> void DCmdArgument<char*>::init_value(TRAPS) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
187 |
if (has_default() && _default_string != NULL) { |
11209 | 188 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
189 |
if (HAS_PENDING_EXCEPTION) { |
|
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
190 |
fatal("Default string must be parsable"); |
11209 | 191 |
} |
192 |
} else { |
|
193 |
set_value(NULL); |
|
194 |
} |
|
195 |
} |
|
196 |
||
197 |
template <> void DCmdArgument<char*>::destroy_value() { |
|
58084
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
53908
diff
changeset
|
198 |
FREE_C_HEAP_ARRAY(char, _value); |
cddef3bde924
8230398: Remove NULL checks before FREE_C_HEAP_ARRAY
lkorinth
parents:
53908
diff
changeset
|
199 |
set_value(NULL); |
11209 | 200 |
} |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
201 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
202 |
template <> void DCmdArgument<NanoTimeArgument>::parse_value(const char* str, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
203 |
size_t len, TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
204 |
if (str == NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
205 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
206 |
"Integer parsing error nanotime value: syntax error, value is null\n"); |
11776
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 |
|
15228
e92acc84ade3
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
13195
diff
changeset
|
209 |
int argc = sscanf(str, JLONG_FORMAT, &_value._time); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
210 |
if (argc != 1) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
211 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
212 |
"Integer parsing error nanotime value: syntax error\n"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
213 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
214 |
size_t idx = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
215 |
while(idx < len && isdigit(str[idx])) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
216 |
idx++; |
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 |
if (idx == len) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
219 |
// only accept missing unit if the value is 0 |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
220 |
if (_value._time != 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
221 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
222 |
"Integer parsing error nanotime value: unit required\n"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
223 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
224 |
_value._nanotime = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
225 |
strcpy(_value._unit, "ns"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
226 |
return; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
227 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
228 |
} else if(len - idx > 2) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
229 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
230 |
"Integer parsing error nanotime value: illegal unit\n"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
231 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
232 |
strncpy(_value._unit, &str[idx], len - idx); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
233 |
/*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
|
234 |
* 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
|
235 |
* 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
|
236 |
* 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
|
237 |
*/ |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
238 |
_value._unit[len-idx] = '\0'; |
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 |
if (strcmp(_value._unit, "ns") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
242 |
_value._nanotime = _value._time; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
243 |
} else if (strcmp(_value._unit, "us") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
244 |
_value._nanotime = _value._time * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
245 |
} else if (strcmp(_value._unit, "ms") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
246 |
_value._nanotime = _value._time * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
247 |
} else if (strcmp(_value._unit, "s") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
248 |
_value._nanotime = _value._time * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
249 |
} else if (strcmp(_value._unit, "m") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
250 |
_value._nanotime = _value._time * 60 * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
251 |
} else if (strcmp(_value._unit, "h") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
252 |
_value._nanotime = _value._time * 60 * 60 * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
253 |
} else if (strcmp(_value._unit, "d") == 0) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
254 |
_value._nanotime = _value._time * 24 * 60 * 60 * 1000 * 1000 * 1000; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
255 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
256 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
257 |
"Integer parsing error nanotime value: illegal unit\n"); |
11776
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 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
260 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
261 |
template <> void DCmdArgument<NanoTimeArgument>::init_value(TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
262 |
if (has_default()) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
263 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
264 |
if (HAS_PENDING_EXCEPTION) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
265 |
fatal("Default string must be parsable"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
266 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
267 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
268 |
_value._time = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
269 |
_value._nanotime = 0; |
18073
f02460441ddc
8014431: cleanup warnings indicated by the -Wunused-value compiler option on linux
ccheung
parents:
18025
diff
changeset
|
270 |
strcpy(_value._unit, "ns"); |
11776
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 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
273 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
274 |
template <> void DCmdArgument<NanoTimeArgument>::destroy_value() { } |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
275 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
276 |
// 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
|
277 |
// used as an argument with the DCmdParser |
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<StringArrayArgument*>::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 |
_value->add(str,len); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
282 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
283 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
284 |
template <> void DCmdArgument<StringArrayArgument*>::init_value(TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
285 |
_value = new StringArrayArgument(); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
286 |
_allow_multiple = true; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
287 |
if (has_default()) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
288 |
fatal("StringArrayArgument cannot have default value"); |
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 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
291 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
292 |
template <> void DCmdArgument<StringArrayArgument*>::destroy_value() { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
293 |
if (_value != NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
294 |
delete _value; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
295 |
set_value(NULL); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
296 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
297 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
298 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
299 |
template <> void DCmdArgument<MemorySizeArgument>::parse_value(const char* str, |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
300 |
size_t len, TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
301 |
if (str == NULL) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
302 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
303 |
"Parsing error memory size value: syntax error, value is null\n"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
304 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
305 |
if (*str == '-') { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
306 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
307 |
"Parsing error memory size value: negative values not allowed\n"); |
11776
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 |
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
|
310 |
if (res == 2) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
311 |
switch (_value._multiplier) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
312 |
case 'k': case 'K': |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
313 |
_value._size = _value._val * 1024; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
314 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
315 |
case 'm': case 'M': |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
316 |
_value._size = _value._val * 1024 * 1024; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
317 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
318 |
case 'g': case 'G': |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
319 |
_value._size = _value._val * 1024 * 1024 * 1024; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
320 |
break; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
321 |
default: |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
322 |
_value._size = _value._val; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
323 |
_value._multiplier = ' '; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
324 |
//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
|
325 |
//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
|
326 |
break; |
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 |
} else if (res == 1) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
329 |
_value._size = _value._val; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
330 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
331 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
39964
7e00eb091e5a
8159901: missing newline char in the exception messages in diagnosticArgument.cpp
ccheung
parents:
39413
diff
changeset
|
332 |
"Parsing error memory size value: invalid value\n"); |
11776
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
333 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
334 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
335 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
336 |
template <> void DCmdArgument<MemorySizeArgument>::init_value(TRAPS) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
337 |
if (has_default()) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
338 |
this->parse_value(_default_string, strlen(_default_string), THREAD); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
339 |
if (HAS_PENDING_EXCEPTION) { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
340 |
fatal("Default string must be parsable"); |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
341 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
342 |
} else { |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
343 |
_value._size = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
344 |
_value._val = 0; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
345 |
_value._multiplier = ' '; |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
346 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
347 |
} |
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
348 |
|
519643dbbefb
7145243: Need additional specializations for argument parsing framework
fparain
parents:
11596
diff
changeset
|
349 |
template <> void DCmdArgument<MemorySizeArgument>::destroy_value() { } |