comparison src/share/vm/services/diagnosticFramework.cpp @ 6275:957c266d8bc5

Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Tue, 21 Aug 2012 10:39:19 +0200
parents 5a1f452f8f90
children 31a4e55f8c9d
comparison
equal deleted inserted replaced
5891:fd8832ae511d 6275:957c266d8bc5
73 _value_len = 0; 73 _value_len = 0;
74 return false; 74 return false;
75 } 75 }
76 // extracting first item, argument or option name 76 // extracting first item, argument or option name
77 _key_addr = &_buffer[_cursor]; 77 _key_addr = &_buffer[_cursor];
78 bool arg_had_quotes = false;
78 while (_cursor <= _len - 1 && _buffer[_cursor] != '=' && _buffer[_cursor] != _delim) { 79 while (_cursor <= _len - 1 && _buffer[_cursor] != '=' && _buffer[_cursor] != _delim) {
79 // argument can be surrounded by single or double quotes 80 // argument can be surrounded by single or double quotes
80 if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') { 81 if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') {
81 _key_addr++; 82 _key_addr++;
82 char quote = _buffer[_cursor]; 83 char quote = _buffer[_cursor];
84 arg_had_quotes = true;
83 while (_cursor < _len - 1) { 85 while (_cursor < _len - 1) {
84 _cursor++; 86 _cursor++;
85 if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') { 87 if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') {
86 break; 88 break;
87 } 89 }
93 break; 95 break;
94 } 96 }
95 _cursor++; 97 _cursor++;
96 } 98 }
97 _key_len = &_buffer[_cursor] - _key_addr; 99 _key_len = &_buffer[_cursor] - _key_addr;
100 if (arg_had_quotes) {
101 // if the argument was quoted, we need to step past the last quote here
102 _cursor++;
103 }
98 // check if the argument has the <key>=<value> format 104 // check if the argument has the <key>=<value> format
99 if (_cursor <= _len -1 && _buffer[_cursor] == '=') { 105 if (_cursor <= _len -1 && _buffer[_cursor] == '=') {
100 _cursor++; 106 _cursor++;
101 _value_addr = &_buffer[_cursor]; 107 _value_addr = &_buffer[_cursor];
108 bool value_had_quotes = false;
102 // extract the value 109 // extract the value
103 while (_cursor <= _len - 1 && _buffer[_cursor] != _delim) { 110 while (_cursor <= _len - 1 && _buffer[_cursor] != _delim) {
104 // value can be surrounded by simple or double quotes 111 // value can be surrounded by simple or double quotes
105 if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') { 112 if (_buffer[_cursor] == '\"' || _buffer[_cursor] == '\'') {
106 _value_addr++; 113 _value_addr++;
107 char quote = _buffer[_cursor]; 114 char quote = _buffer[_cursor];
115 value_had_quotes = true;
108 while (_cursor < _len - 1) { 116 while (_cursor < _len - 1) {
109 _cursor++; 117 _cursor++;
110 if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') { 118 if (_buffer[_cursor] == quote && _buffer[_cursor - 1] != '\\') {
111 break; 119 break;
112 } 120 }
118 break; 126 break;
119 } 127 }
120 _cursor++; 128 _cursor++;
121 } 129 }
122 _value_len = &_buffer[_cursor] - _value_addr; 130 _value_len = &_buffer[_cursor] - _value_addr;
131 if (value_had_quotes) {
132 // if the value was quoted, we need to step past the last quote here
133 _cursor++;
134 }
123 } else { 135 } else {
124 _value_addr = NULL; 136 _value_addr = NULL;
125 _value_len = 0; 137 _value_len = 0;
126 } 138 }
127 return _key_len != 0; 139 return _key_len != 0;
183 if (next_argument != NULL) { 195 if (next_argument != NULL) {
184 arg = next_argument; 196 arg = next_argument;
185 arg->read_value(iter.key_addr(), iter.key_length(), CHECK); 197 arg->read_value(iter.key_addr(), iter.key_length(), CHECK);
186 next_argument = next_argument->next(); 198 next_argument = next_argument->next();
187 } else { 199 } else {
188 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 200 const size_t buflen = 120;
189 "Unknown argument in diagnostic command"); 201 const size_t argbuflen = 30;
202 char buf[buflen];
203 char argbuf[argbuflen];
204 size_t len = MIN2<size_t>(iter.key_length(), argbuflen - 1);
205
206 strncpy(argbuf, iter.key_addr(), len);
207 argbuf[len] = '\0';
208 jio_snprintf(buf, buflen - 1, "Unknown argument '%s' in diagnostic command.", argbuf);
209
210 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf);
190 } 211 }
191 } 212 }
192 cont = iter.next(CHECK); 213 cont = iter.next(CHECK);
193 } 214 }
194 check(CHECK); 215 check(CHECK);
205 } 226 }
206 return NULL; 227 return NULL;
207 } 228 }
208 229
209 void DCmdParser::check(TRAPS) { 230 void DCmdParser::check(TRAPS) {
231 const size_t buflen = 256;
232 char buf[buflen];
210 GenDCmdArgument* arg = _arguments_list; 233 GenDCmdArgument* arg = _arguments_list;
211 while (arg != NULL) { 234 while (arg != NULL) {
212 if (arg->is_mandatory() && !arg->has_value()) { 235 if (arg->is_mandatory() && !arg->has_value()) {
213 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 236 jio_snprintf(buf, buflen - 1, "The argument '%s' is mandatory.", arg->name());
214 "Missing argument for diagnostic command"); 237 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf);
215 } 238 }
216 arg = arg->next(); 239 arg = arg->next();
217 } 240 }
218 arg = _options; 241 arg = _options;
219 while (arg != NULL) { 242 while (arg != NULL) {
220 if (arg->is_mandatory() && !arg->has_value()) { 243 if (arg->is_mandatory() && !arg->has_value()) {
221 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), 244 jio_snprintf(buf, buflen - 1, "The option '%s' is mandatory.", arg->name());
222 "Missing option for diagnostic command"); 245 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), buf);
223 } 246 }
224 arg = arg->next(); 247 arg = arg->next();
225 } 248 }
226 } 249 }
227 250