8179224: Cache strlen of Flag::_name
authorredestad
Wed, 26 Apr 2017 13:20:23 +0200
changeset 46416 f1ebd584cdf3
parent 46415 7d5a286cdf89
child 46417 1593c061e6af
8179224: Cache strlen of Flag::_name Reviewed-by: dsamersoff, jiangli, iklam, rehn
hotspot/src/share/vm/runtime/globals.cpp
hotspot/src/share/vm/runtime/globals.hpp
--- a/hotspot/src/share/vm/runtime/globals.cpp	Wed Apr 26 10:26:39 2017 +0200
+++ b/hotspot/src/share/vm/runtime/globals.cpp	Wed Apr 26 13:20:23 2017 +0200
@@ -865,16 +865,15 @@
 Flag* Flag::flags = flagTable;
 size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
 
-inline bool str_equal(const char* s, const char* q, size_t len) {
-  // s is null terminated, q is not!
-  if (strlen(s) != (unsigned int) len) return false;
-  return strncmp(s, q, len) == 0;
+inline bool str_equal(const char* s, size_t s_len, const char* q, size_t q_len) {
+  if (s_len != q_len) return false;
+  return memcmp(s, q, q_len) == 0;
 }
 
 // Search the flag table for a named flag
 Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked, bool return_flag) {
   for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
-    if (str_equal(current->_name, name, length)) {
+    if (str_equal(current->_name, current->get_name_length(), name, length)) {
       // Found a matching entry.
       // Don't report notproduct and develop flags in product builds.
       if (current->is_constant_in_binary()) {
@@ -895,6 +894,14 @@
   return NULL;
 }
 
+// Get or compute the flag name length
+size_t Flag::get_name_length() {
+  if (_name_len == 0) {
+    _name_len = strlen(_name);
+  }
+  return _name_len;
+}
+
 // Compute string similarity based on Dice's coefficient
 static float str_similar(const char* str1, const char* str2, size_t len2) {
   int len1 = (int) strlen(str1);
--- a/hotspot/src/share/vm/runtime/globals.hpp	Wed Apr 26 10:26:39 2017 +0200
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Wed Apr 26 13:20:23 2017 +0200
@@ -186,6 +186,7 @@
   void* _addr;
   NOT_PRODUCT(const char* _doc;)
   Flags _flags;
+  size_t _name_len;
 
   // points to all Flags static array
   static Flag* flags;
@@ -247,6 +248,8 @@
   Flags get_origin();
   void set_origin(Flags origin);
 
+  size_t get_name_length();
+
   bool is_default();
   bool is_ergonomic();
   bool is_command_line();