8142510: -XX:+PrintFlagsRanges should print default range value for those flags that have constraint and an implicit range.
authorgziemski
Wed, 30 Mar 2016 14:44:27 -0500
changeset 37208 aaf76eb8cfd4
parent 37207 7afe535e1cbf
child 37209 c2920cd096aa
child 37210 6491cf889874
8142510: -XX:+PrintFlagsRanges should print default range value for those flags that have constraint and an implicit range. Summary: Implemented default ranges for flags with constraints and no explicit ranges Reviewed-by: ddmitriev, coleenp
hotspot/src/share/vm/runtime/commandLineFlagConstraintList.cpp
hotspot/src/share/vm/runtime/commandLineFlagConstraintList.hpp
hotspot/src/share/vm/runtime/commandLineFlagRangeList.cpp
hotspot/src/share/vm/runtime/commandLineFlagRangeList.hpp
hotspot/src/share/vm/runtime/globals.cpp
hotspot/src/share/vm/runtime/globals.hpp
--- a/hotspot/src/share/vm/runtime/commandLineFlagConstraintList.cpp	Wed Mar 30 17:25:32 2016 +0300
+++ b/hotspot/src/share/vm/runtime/commandLineFlagConstraintList.cpp	Wed Mar 30 14:44:27 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -290,13 +290,11 @@
 #endif // INCLUDE_ALL_GCS
 }
 
-// Find constraints by name and return only if found constraint's type is equal or lower than current validating type.
-CommandLineFlagConstraint* CommandLineFlagConstraintList::find_if_needs_check(const char* name) {
+CommandLineFlagConstraint* CommandLineFlagConstraintList::find(const char* name) {
   CommandLineFlagConstraint* found = NULL;
   for (int i=0; i<length(); i++) {
     CommandLineFlagConstraint* constraint = at(i);
-    if ((strcmp(constraint->name(), name) == 0) &&
-        (constraint->type() <= _validating_type)) {
+    if (strcmp(constraint->name(), name) == 0) {
       found = constraint;
       break;
     }
@@ -304,6 +302,16 @@
   return found;
 }
 
+// Find constraints by name and return only if found constraint's type is equal or lower than current validating type.
+CommandLineFlagConstraint* CommandLineFlagConstraintList::find_if_needs_check(const char* name) {
+  CommandLineFlagConstraint* found = NULL;
+  CommandLineFlagConstraint* constraint = find(name);
+  if (constraint && (constraint->type() <= _validating_type)) {
+    found = constraint;
+  }
+  return found;
+}
+
 // Check constraints for specific constraint type.
 bool CommandLineFlagConstraintList::check_constraints(CommandLineFlagConstraint::ConstraintType type) {
   guarantee(type > _validating_type, "Constraint check is out of order.");
--- a/hotspot/src/share/vm/runtime/commandLineFlagConstraintList.hpp	Wed Mar 30 17:25:32 2016 +0300
+++ b/hotspot/src/share/vm/runtime/commandLineFlagConstraintList.hpp	Wed Mar 30 14:44:27 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -89,6 +89,7 @@
   static void init();
   static int length() { return (_constraints != NULL) ? _constraints->length() : 0; }
   static CommandLineFlagConstraint* at(int i) { return (_constraints != NULL) ? _constraints->at(i) : NULL; }
+  static CommandLineFlagConstraint* find(const char* name);
   static CommandLineFlagConstraint* find_if_needs_check(const char* name);
   static void add(CommandLineFlagConstraint* constraint) { _constraints->append(constraint); }
   // True if 'AfterErgo' or later constraint functions are validated.
--- a/hotspot/src/share/vm/runtime/commandLineFlagRangeList.cpp	Wed Mar 30 17:25:32 2016 +0300
+++ b/hotspot/src/share/vm/runtime/commandLineFlagRangeList.cpp	Wed Mar 30 14:44:27 2016 -0500
@@ -27,6 +27,7 @@
 #include "classfile/symbolTable.hpp"
 #include "gc/shared/referenceProcessor.hpp"
 #include "runtime/arguments.hpp"
+#include "runtime/commandLineFlagConstraintList.hpp"
 #include "runtime/commandLineFlagRangeList.hpp"
 #include "runtime/os.hpp"
 #include "runtime/task.hpp"
@@ -378,12 +379,18 @@
   return found;
 }
 
-void CommandLineFlagRangeList::print(const char* name, outputStream* st, bool unspecified) {
+void CommandLineFlagRangeList::print(outputStream* st, const char* name, RangeStrFunc default_range_str_func) {
   CommandLineFlagRange* range = CommandLineFlagRangeList::find(name);
   if (range != NULL) {
     range->print(st);
-  } else if (unspecified == true) {
-    st->print("[                           ...                           ]");
+  } else {
+    CommandLineFlagConstraint* constraint = CommandLineFlagConstraintList::find(name);
+    if (constraint != NULL) {
+      assert(default_range_str_func!=NULL, "default_range_str_func must be provided");
+      st->print("%s", default_range_str_func());
+    } else {
+      st->print("[                           ...                           ]");
+    }
   }
 }
 
--- a/hotspot/src/share/vm/runtime/commandLineFlagRangeList.hpp	Wed Mar 30 17:25:32 2016 +0300
+++ b/hotspot/src/share/vm/runtime/commandLineFlagRangeList.hpp	Wed Mar 30 14:44:27 2016 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -71,7 +71,7 @@
   static CommandLineFlagRange* at(int i) { return (_ranges != NULL) ? _ranges->at(i) : NULL; }
   static CommandLineFlagRange* find(const char* name);
   static void add(CommandLineFlagRange* range) { _ranges->append(range); }
-  static void print(const char* name, outputStream* st, bool unspecified = false);
+  static void print(outputStream* st, const char* name, RangeStrFunc default_range_str_func);
   // Check the final values of all flags for ranges.
   static bool check_ranges();
 };
--- a/hotspot/src/share/vm/runtime/globals.cpp	Wed Mar 30 17:25:32 2016 +0300
+++ b/hotspot/src/share/vm/runtime/globals.cpp	Wed Mar 30 14:44:27 2016 -0500
@@ -84,6 +84,56 @@
 
 MATERIALIZE_FLAGS_EXT
 
+#define DEFAULT_RANGE_STR_CHUNK_SIZE 64
+static char* create_range_str(const char *fmt, ...) {
+  static size_t string_length = DEFAULT_RANGE_STR_CHUNK_SIZE;
+  static char* range_string = NEW_C_HEAP_ARRAY(char, string_length, mtLogging);
+
+  int size_needed = 0;
+  do {
+    va_list args;
+    va_start(args, fmt);
+    size_needed = jio_vsnprintf(range_string, string_length, fmt, args);
+    va_end(args);
+
+    if (size_needed < 0) {
+      string_length += DEFAULT_RANGE_STR_CHUNK_SIZE;
+      range_string = REALLOC_C_HEAP_ARRAY(char, range_string, string_length, mtLogging);
+      guarantee(range_string != NULL, "create_range_str string should not be NULL");
+    }
+  } while (size_needed < 0);
+
+  return range_string;
+}
+
+const char* Flag::get_int_default_range_str() {
+  return create_range_str("[ " INT32_FORMAT_W(-25) " ... " INT32_FORMAT_W(25) " ]", INT_MIN, INT_MAX);
+}
+
+const char* Flag::get_uint_default_range_str() {
+  return create_range_str("[ " UINT32_FORMAT_W(-25) " ... " UINT32_FORMAT_W(25) " ]", 0, UINT_MAX);
+}
+
+const char* Flag::get_intx_default_range_str() {
+  return create_range_str("[ " INTX_FORMAT_W(-25) " ... " INTX_FORMAT_W(25) " ]", min_intx, max_intx);
+}
+
+const char* Flag::get_uintx_default_range_str() {
+  return create_range_str("[ " UINTX_FORMAT_W(-25) " ... " UINTX_FORMAT_W(25) " ]", 0, max_uintx);
+}
+
+const char* Flag::get_uint64_t_default_range_str() {
+  return create_range_str("[ " UINT64_FORMAT_W(-25) " ... " UINT64_FORMAT_W(25) " ]", 0, uint64_t(max_juint));
+}
+
+const char* Flag::get_size_t_default_range_str() {
+  return create_range_str("[ " SIZE_FORMAT_W(-25) " ... " SIZE_FORMAT_W(25) " ]", 0, SIZE_MAX);
+}
+
+const char* Flag::get_double_default_range_str() {
+  return create_range_str("[ %-25.3f ... %25.3f ]", DBL_MIN, DBL_MAX);
+}
+
 static bool is_product_build() {
 #ifdef PRODUCT
   return true;
@@ -405,7 +455,25 @@
   } else if (!is_bool() && !is_ccstr()) {
     st->print("%9s %-50s ", _type, _name);
 
-    CommandLineFlagRangeList::print(_name, st, true);
+    RangeStrFunc func = NULL;
+    if (is_int()) {
+      func = Flag::get_int_default_range_str;
+    } else if (is_uint()) {
+      func = Flag::get_uint_default_range_str;
+    } else if (is_intx()) {
+      func = Flag::get_intx_default_range_str;
+    } else if (is_uintx()) {
+      func = Flag::get_uintx_default_range_str;
+    } else if (is_uint64_t()) {
+      func = Flag::get_uint64_t_default_range_str;
+    } else if (is_size_t()) {
+      func = Flag::get_size_t_default_range_str;
+    } else if (is_double()) {
+      func = Flag::get_double_default_range_str;
+    } else {
+      ShouldNotReachHere();
+    }
+    CommandLineFlagRangeList::print(st, _name, func);
 
     st->print(" %-20s", " ");
     print_kind(st);
--- a/hotspot/src/share/vm/runtime/globals.hpp	Wed Mar 30 17:25:32 2016 +0300
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Wed Mar 30 14:44:27 2016 -0500
@@ -224,6 +224,9 @@
 typedef const char* ccstr;
 typedef const char* ccstrlist;   // represents string arguments which accumulate
 
+// function type that will construct default range string
+typedef const char* (*RangeStrFunc)(void);
+
 struct Flag {
   enum Flags {
     // value origin
@@ -305,6 +308,14 @@
   static Flag* find_flag(const char* name, size_t length, bool allow_locked = false, bool return_flag = false);
   static Flag* fuzzy_match(const char* name, size_t length, bool allow_locked = false);
 
+  static const char* get_int_default_range_str();
+  static const char* get_uint_default_range_str();
+  static const char* get_intx_default_range_str();
+  static const char* get_uintx_default_range_str();
+  static const char* get_uint64_t_default_range_str();
+  static const char* get_size_t_default_range_str();
+  static const char* get_double_default_range_str();
+
   void check_writable();
 
   bool is_bool() const;