< prev index next >

src/hotspot/share/services/diagnosticArgument.cpp

Print this page

 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 "jvm.h"
 27 #include "memory/allocation.inline.hpp"
 28 #include "memory/resourceArea.hpp"
 29 #include "runtime/thread.hpp"
 30 #include "services/diagnosticArgument.hpp"
 31 
 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++) {
 39     if(_array->at(i) != NULL) { // Safety check
 40       FREE_C_HEAP_ARRAY(char, _array->at(i));
 41     }
 42   }
 43   delete _array;
 44 }
 45 
 46 void StringArrayArgument::add(const char* str, size_t len) {
 47   if (str != NULL) {
 48     char* ptr = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
 49     strncpy(ptr, str, len);
 50     ptr[len] = 0;
 51     _array->append(ptr);
 52   }
 53 }
 54 
 55 void GenDCmdArgument::read_value(const char* str, size_t len, TRAPS) {
 56   /* NOTE:Some argument types doesn't require a value,
 57    * for instance boolean arguments: "enableFeatureX". is
 58    * equivalent to "enableFeatureX=true". In these cases,
 59    * str will be null. This is perfectly valid.
 60    * All argument types must perform null checks on str.
 61    */

180     _value = NULL;
181   } else {
182     _value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
183     int n = os::snprintf(_value, len + 1, "%.*s", (int)len, str);
184     assert((size_t)n <= len, "Unexpected number of characters in string");
185   }
186 }
187 
188 template <> void DCmdArgument<char*>::init_value(TRAPS) {
189   if (has_default() && _default_string != NULL) {
190     this->parse_value(_default_string, strlen(_default_string), THREAD);
191     if (HAS_PENDING_EXCEPTION) {
192      fatal("Default string must be parsable");
193     }
194   } else {
195     set_value(NULL);
196   }
197 }
198 
199 template <> void DCmdArgument<char*>::destroy_value() {
200   if (_value != NULL) {
201     FREE_C_HEAP_ARRAY(char, _value);
202     set_value(NULL);
203   }
204 }
205 
206 template <> void DCmdArgument<NanoTimeArgument>::parse_value(const char* str,
207                                                  size_t len, TRAPS) {
208   if (str == NULL) {
209     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
210               "Integer parsing error nanotime value: syntax error, value is null\n");
211   }
212 
213   int argc = sscanf(str, JLONG_FORMAT, &_value._time);
214   if (argc != 1) {
215     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
216               "Integer parsing error nanotime value: syntax error\n");
217   }
218   size_t idx = 0;
219   while(idx < len && isdigit(str[idx])) {
220     idx++;
221   }
222   if (idx == len) {
223     // only accept missing unit if the value is 0

 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 "jvm.h"
 27 #include "memory/allocation.inline.hpp"
 28 #include "memory/resourceArea.hpp"
 29 #include "runtime/thread.hpp"
 30 #include "services/diagnosticArgument.hpp"
 31 
 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++) {
 39     FREE_C_HEAP_ARRAY(char, _array->at(i));


 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 
 53 void GenDCmdArgument::read_value(const char* str, size_t len, TRAPS) {
 54   /* NOTE:Some argument types doesn't require a value,
 55    * for instance boolean arguments: "enableFeatureX". is
 56    * equivalent to "enableFeatureX=true". In these cases,
 57    * str will be null. This is perfectly valid.
 58    * All argument types must perform null checks on str.
 59    */

178     _value = NULL;
179   } else {
180     _value = NEW_C_HEAP_ARRAY(char, len + 1, mtInternal);
181     int n = os::snprintf(_value, len + 1, "%.*s", (int)len, str);
182     assert((size_t)n <= len, "Unexpected number of characters in string");
183   }
184 }
185 
186 template <> void DCmdArgument<char*>::init_value(TRAPS) {
187   if (has_default() && _default_string != NULL) {
188     this->parse_value(_default_string, strlen(_default_string), THREAD);
189     if (HAS_PENDING_EXCEPTION) {
190      fatal("Default string must be parsable");
191     }
192   } else {
193     set_value(NULL);
194   }
195 }
196 
197 template <> void DCmdArgument<char*>::destroy_value() {
198   FREE_C_HEAP_ARRAY(char, _value);
199   set_value(NULL);


200 }
201 
202 template <> void DCmdArgument<NanoTimeArgument>::parse_value(const char* str,
203                                                  size_t len, TRAPS) {
204   if (str == NULL) {
205     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
206               "Integer parsing error nanotime value: syntax error, value is null\n");
207   }
208 
209   int argc = sscanf(str, JLONG_FORMAT, &_value._time);
210   if (argc != 1) {
211     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
212               "Integer parsing error nanotime value: syntax error\n");
213   }
214   size_t idx = 0;
215   while(idx < len && isdigit(str[idx])) {
216     idx++;
217   }
218   if (idx == len) {
219     // only accept missing unit if the value is 0
< prev index next >