diff src/share/vm/runtime/globals.cpp @ 11173:6b0fd0964b87

Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author Doug Simon <doug.simon@oracle.com>
date Wed, 31 Jul 2013 11:00:54 +0200
parents 5fc51c1ecdeb 6e3634222155
children cefad50507d8
line wrap: on
line diff
--- a/src/share/vm/runtime/globals.cpp	Tue Jul 30 13:03:28 2013 -0700
+++ b/src/share/vm/runtime/globals.cpp	Wed Jul 31 11:00:54 2013 +0200
@@ -76,12 +76,6 @@
       strcmp(kind, "{C2 diagnostic}") == 0 ||
       strcmp(kind, "{ARCH diagnostic}") == 0 ||
       strcmp(kind, "{Shark diagnostic}") == 0) {
-    if (strcmp(name, "EnableInvokeDynamic") == 0 && UnlockExperimentalVMOptions && !UnlockDiagnosticVMOptions) {
-      // transitional logic to allow tests to run until they are changed
-      static int warned;
-      if (++warned == 1)  warning("Use -XX:+UnlockDiagnosticVMOptions before EnableInvokeDynamic flag");
-      return true;
-    }
     return UnlockDiagnosticVMOptions;
   } else if (strcmp(kind, "{experimental}") == 0 ||
              strcmp(kind, "{C2 experimental}") == 0 ||
@@ -300,14 +294,14 @@
 Flag* Flag::flags = flagTable;
 size_t Flag::numFlags = (sizeof(flagTable) / sizeof(Flag));
 
-inline bool str_equal(const char* s, char* q, size_t len) {
+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;
 }
 
 // Search the flag table for a named flag
-Flag* Flag::find_flag(char* name, size_t length, bool allow_locked) {
+Flag* Flag::find_flag(const char* name, size_t length, bool allow_locked) {
   for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
     if (str_equal(current->name, name, length)) {
       // Found a matching entry.  Report locked flags only if allowed.
@@ -325,6 +319,52 @@
   return NULL;
 }
 
+// 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);
+  int total = len1 + (int) len2;
+
+  int hit = 0;
+
+  for (int i = 0; i < len1 -1; ++i) {
+    for (int j = 0; j < (int) len2 -1; ++j) {
+      if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
+        ++hit;
+        break;
+      }
+    }
+  }
+
+  return 2.0f * (float) hit / (float) total;
+}
+
+Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
+  float VMOptionsFuzzyMatchSimilarity = 0.7f;
+  Flag* match = NULL;
+  float score;
+  float max_score = -1;
+
+  for (Flag* current = &flagTable[0]; current->name != NULL; current++) {
+    score = str_similar(current->name, name, length);
+    if (score > max_score) {
+      max_score = score;
+      match = current;
+    }
+  }
+
+  if (!(match->is_unlocked() || match->is_unlocker())) {
+    if (!allow_locked) {
+      return NULL;
+    }
+  }
+
+  if (max_score < VMOptionsFuzzyMatchSimilarity) {
+    return NULL;
+  }
+
+  return match;
+}
+
 // Returns the address of the index'th element
 static Flag* address_of_flag(CommandLineFlagWithType flag) {
   assert((size_t)flag < Flag::numFlags, "bad command line flag index");