< prev index next >

src/hotspot/share/services/diagnosticArgument.cpp

Print this page
rev 50556 : [mq]: jcmd-cleanups


  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    */
  62 
  63   if (is_set() && !allow_multiple()) {
  64     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
  65             "Duplicates in diagnostic command arguments\n");
  66   }
  67   parse_value(str, len, CHECK);
  68   set_is_set(true);
  69 }
  70 
  71 void GenDCmdArgument::to_string(jlong l, char* buf, size_t len) {
  72   jio_snprintf(buf, len, INT64_FORMAT, l);
  73 }
  74 
  75 void GenDCmdArgument::to_string(bool b, char* buf, size_t len) {
  76   jio_snprintf(buf, len, b ? "true" : "false");
  77 }
  78 
  79 void GenDCmdArgument::to_string(NanoTimeArgument n, char* buf, size_t len) {
  80   jio_snprintf(buf, len, INT64_FORMAT, n._nanotime);
  81 }
  82 
  83 void GenDCmdArgument::to_string(MemorySizeArgument m, char* buf, size_t len) {
  84   jio_snprintf(buf, len, INT64_FORMAT, m._size);
  85 }
  86 
  87 void GenDCmdArgument::to_string(char* c, char* buf, size_t len) {
  88   jio_snprintf(buf, len, "%s", (c != NULL) ? c : "");
  89 }
  90 
  91 void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) {
  92   int length = f->array()->length();
  93   size_t written = 0;
  94   buf[0] = 0;
  95   for (int i = 0; i < length; i++) {
  96     char* next_str = f->array()->at(i);
  97     size_t next_size = strlen(next_str);
  98     //Check if there's room left to write next element
  99     if (written + next_size > len) {
 100       return;
 101     }
 102     //Actually write element
 103     strcat(buf, next_str);
 104     written += next_size;
 105     //Check if there's room left for the comma
 106     if (i < length-1 && len - written > 0) {
 107       strcat(buf, ",");
 108     }
 109   }
 110 }
 111 




  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    */
  62 
  63   if (is_set() && !allow_multiple()) {
  64     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
  65             "Duplicates in diagnostic command arguments\n");
  66   }
  67   parse_value(str, len, CHECK);
  68   set_is_set(true);
  69 }
  70 
  71 void GenDCmdArgument::to_string(jlong l, char* buf, size_t len) const {
  72   jio_snprintf(buf, len, INT64_FORMAT, l);
  73 }
  74 
  75 void GenDCmdArgument::to_string(bool b, char* buf, size_t len) const {
  76   jio_snprintf(buf, len, b ? "true" : "false");
  77 }
  78 
  79 void GenDCmdArgument::to_string(NanoTimeArgument n, char* buf, size_t len) const {
  80   jio_snprintf(buf, len, INT64_FORMAT, n._nanotime);
  81 }
  82 
  83 void GenDCmdArgument::to_string(MemorySizeArgument m, char* buf, size_t len) const {
  84   jio_snprintf(buf, len, INT64_FORMAT, m._size);
  85 }
  86 
  87 void GenDCmdArgument::to_string(char* c, char* buf, size_t len) const {
  88   jio_snprintf(buf, len, "%s", (c != NULL) ? c : "");
  89 }
  90 
  91 void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) const {
  92   int length = f->array()->length();
  93   size_t written = 0;
  94   buf[0] = 0;
  95   for (int i = 0; i < length; i++) {
  96     char* next_str = f->array()->at(i);
  97     size_t next_size = strlen(next_str);
  98     //Check if there's room left to write next element
  99     if (written + next_size > len) {
 100       return;
 101     }
 102     //Actually write element
 103     strcat(buf, next_str);
 104     written += next_size;
 105     //Check if there's room left for the comma
 106     if (i < length-1 && len - written > 0) {
 107       strcat(buf, ",");
 108     }
 109   }
 110 }
 111 


< prev index next >