equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
36 #include "runtime/sharedRuntime.hpp" |
36 #include "runtime/sharedRuntime.hpp" |
37 #include "trace/tracing.hpp" |
37 #include "trace/tracing.hpp" |
38 #include "utilities/defaultStream.hpp" |
38 #include "utilities/defaultStream.hpp" |
39 #include "utilities/macros.hpp" |
39 #include "utilities/macros.hpp" |
40 #include "utilities/ostream.hpp" |
40 #include "utilities/ostream.hpp" |
|
41 #include "utilities/stringUtils.hpp" |
41 #if INCLUDE_ALL_GCS |
42 #if INCLUDE_ALL_GCS |
42 #include "gc/g1/g1_globals.hpp" |
43 #include "gc/g1/g1_globals.hpp" |
43 #endif // INCLUDE_ALL_GCS |
44 #endif // INCLUDE_ALL_GCS |
44 #ifdef COMPILER1 |
45 #ifdef COMPILER1 |
45 #include "c1/c1_globals.hpp" |
46 #include "c1/c1_globals.hpp" |
878 _name_len = strlen(_name); |
879 _name_len = strlen(_name); |
879 } |
880 } |
880 return _name_len; |
881 return _name_len; |
881 } |
882 } |
882 |
883 |
883 // Compute string similarity based on Dice's coefficient |
|
884 static float str_similar(const char* str1, const char* str2, size_t len2) { |
|
885 int len1 = (int) strlen(str1); |
|
886 int total = len1 + (int) len2; |
|
887 |
|
888 int hit = 0; |
|
889 |
|
890 for (int i = 0; i < len1 -1; ++i) { |
|
891 for (int j = 0; j < (int) len2 -1; ++j) { |
|
892 if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) { |
|
893 ++hit; |
|
894 break; |
|
895 } |
|
896 } |
|
897 } |
|
898 |
|
899 return 2.0f * (float) hit / (float) total; |
|
900 } |
|
901 |
|
902 Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) { |
884 Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) { |
903 float VMOptionsFuzzyMatchSimilarity = 0.7f; |
885 float VMOptionsFuzzyMatchSimilarity = 0.7f; |
904 Flag* match = NULL; |
886 Flag* match = NULL; |
905 float score; |
887 float score; |
906 float max_score = -1; |
888 float max_score = -1; |
907 |
889 |
908 for (Flag* current = &flagTable[0]; current->_name != NULL; current++) { |
890 for (Flag* current = &flagTable[0]; current->_name != NULL; current++) { |
909 score = str_similar(current->_name, name, length); |
891 score = StringUtils::similarity(current->_name, strlen(current->_name), name, length); |
910 if (score > max_score) { |
892 if (score > max_score) { |
911 max_score = score; |
893 max_score = score; |
912 match = current; |
894 match = current; |
913 } |
895 } |
914 } |
896 } |