src/share/vm/services/diagnosticArgument.cpp

Print this page
rev 3201 : 7148488: Whitebox tests for the Diagnostic Framework Parser


  26 #include "memory/allocation.inline.hpp"
  27 #include "runtime/thread.hpp"
  28 #include "services/diagnosticArgument.hpp"
  29 
  30 void GenDCmdArgument::read_value(const char* str, size_t len, TRAPS) {
  31   /* NOTE:Some argument types doesn't require a value,
  32    * for instance boolean arguments: "enableFeatureX". is
  33    * equivalent to "enableFeatureX=true". In these cases,
  34    * str will be null. This is perfectly valid.
  35    * All argument types must perform null checks on str.
  36    */
  37 
  38   if (is_set() && !allow_multiple()) {
  39     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
  40             "Duplicates in diagnostic command arguments\n");
  41   }
  42   parse_value(str, len, CHECK);
  43   set_is_set(true);
  44 }
  45 





































  46 template <> void DCmdArgument<jlong>::parse_value(const char* str,
  47                                                   size_t len, TRAPS) {
  48     if (str == NULL || sscanf(str, INT64_FORMAT, &_value) != 1) {
  49     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
  50       "Integer parsing error in diagnostic command arguments\n");
  51   }
  52 }
  53 
  54 template <> void DCmdArgument<jlong>::init_value(TRAPS) {
  55   if (has_default()) {
  56     this->parse_value(_default_string, strlen(_default_string), THREAD);
  57     if (HAS_PENDING_EXCEPTION) {
  58       fatal("Default string must be parsable");
  59     }
  60   } else {
  61     set_value(0);
  62   }
  63 }
  64 
  65 template <> void DCmdArgument<jlong>::destroy_value() { }




  26 #include "memory/allocation.inline.hpp"
  27 #include "runtime/thread.hpp"
  28 #include "services/diagnosticArgument.hpp"
  29 
  30 void GenDCmdArgument::read_value(const char* str, size_t len, TRAPS) {
  31   /* NOTE:Some argument types doesn't require a value,
  32    * for instance boolean arguments: "enableFeatureX". is
  33    * equivalent to "enableFeatureX=true". In these cases,
  34    * str will be null. This is perfectly valid.
  35    * All argument types must perform null checks on str.
  36    */
  37 
  38   if (is_set() && !allow_multiple()) {
  39     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
  40             "Duplicates in diagnostic command arguments\n");
  41   }
  42   parse_value(str, len, CHECK);
  43   set_is_set(true);
  44 }
  45 
  46 void GenDCmdArgument::to_string(jlong l, char* buf, size_t len) {
  47   jio_snprintf(buf, len, INT64_FORMAT, l);
  48 }
  49 
  50 void GenDCmdArgument::to_string(bool b, char* buf, size_t len) {
  51   jio_snprintf(buf, len, b ? "true" : "false");
  52 }
  53 
  54 void GenDCmdArgument::to_string(NanoTimeArgument n, char* buf, size_t len) {
  55   jio_snprintf(buf, len, INT64_FORMAT, n._nanotime);
  56 }
  57 
  58 void GenDCmdArgument::to_string(MemorySizeArgument m, char* buf, size_t len) {
  59   jio_snprintf(buf, len, INT64_FORMAT, m._size);
  60 }
  61 
  62 void GenDCmdArgument::to_string(char* c, char* buf, size_t len) {
  63   jio_snprintf(buf, len, "%s", c);
  64 }
  65 
  66 void GenDCmdArgument::to_string(StringArrayArgument* f, char* buf, size_t len) {
  67   int length = f->array()->length();
  68   size_t written = 0;
  69   buf[0] = 0;
  70   for (int i = 0; i < length; i++) {
  71     char* next_str = f->array()->at(i);
  72     size_t next_size = strlen(next_str);
  73     if (written + next_size > len) {
  74       return;
  75     }
  76     strcat(buf, next_str);
  77     if (i < length-1) {
  78       strcat(buf, ",");
  79     }
  80   }
  81 }
  82 
  83 template <> void DCmdArgument<jlong>::parse_value(const char* str,
  84                                                   size_t len, TRAPS) {
  85     if (str == NULL || sscanf(str, INT64_FORMAT, &_value) != 1) {
  86     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
  87       "Integer parsing error in diagnostic command arguments\n");
  88   }
  89 }
  90 
  91 template <> void DCmdArgument<jlong>::init_value(TRAPS) {
  92   if (has_default()) {
  93     this->parse_value(_default_string, strlen(_default_string), THREAD);
  94     if (HAS_PENDING_EXCEPTION) {
  95       fatal("Default string must be parsable");
  96     }
  97   } else {
  98     set_value(0);
  99   }
 100 }
 101 
 102 template <> void DCmdArgument<jlong>::destroy_value() { }