hotspot/src/share/vm/runtime/arguments.cpp
changeset 46367 6e532778cb35
parent 44203 d2d435372329
child 46370 7a0ae73888ff
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Tue Mar 21 11:25:18 2017 -0400
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Thu Apr 06 14:07:21 2017 -0700
@@ -2587,19 +2587,26 @@
 }
 
 bool Arguments::create_numbered_property(const char* prop_base_name, const char* prop_value, unsigned int count) {
-  // Make sure count is < 1,000. Otherwise, memory allocation will be too small.
-  if (count < 1000) {
-    size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + 5;
+  const unsigned int props_count_limit = 1000;
+  const int max_digits = 3;
+  const int extra_symbols_count = 3; // includes '.', '=', '\0'
+
+  // Make sure count is < props_count_limit. Otherwise, memory allocation will be too small.
+  if (count < props_count_limit) {
+    size_t prop_len = strlen(prop_base_name) + strlen(prop_value) + max_digits + extra_symbols_count;
     char* property = AllocateHeap(prop_len, mtArguments);
     int ret = jio_snprintf(property, prop_len, "%s.%d=%s", prop_base_name, count, prop_value);
     if (ret < 0 || ret >= (int)prop_len) {
       FreeHeap(property);
+      jio_fprintf(defaultStream::error_stream(), "Failed to create property %s.%d=%s\n", prop_base_name, count, prop_value);
       return false;
     }
     bool added = add_property(property, UnwriteableProperty, InternalProperty);
     FreeHeap(property);
     return added;
   }
+
+  jio_fprintf(defaultStream::error_stream(), "Property count limit exceeded: %s, limit=%d\n", prop_base_name, props_count_limit);
   return false;
 }