< prev index next >

src/hotspot/share/services/diagnosticArgument.cpp

Print this page
rev 50590 : [mq]: jcmd-cleanups
   1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   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  *


  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 


   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   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  *


  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 >