src/hotspot/share/runtime/globals.cpp
branchepsilon-gc-branch
changeset 56276 ee5e58456be5
parent 55934 912c55e702d6
parent 49163 580bb0b85f63
child 56406 e629240491c7
equal deleted inserted replaced
56096:ab47ddc3f427 56276:ee5e58456be5
     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 #include "gc/epsilon/epsilon_globals.hpp"
    44 #include "gc/epsilon/epsilon_globals.hpp"
    44 #endif // INCLUDE_ALL_GCS
    45 #endif // INCLUDE_ALL_GCS
    45 #ifdef COMPILER1
    46 #ifdef COMPILER1
   892     _name_len = strlen(_name);
   893     _name_len = strlen(_name);
   893   }
   894   }
   894   return _name_len;
   895   return _name_len;
   895 }
   896 }
   896 
   897 
   897 // Compute string similarity based on Dice's coefficient
       
   898 static float str_similar(const char* str1, const char* str2, size_t len2) {
       
   899   int len1 = (int) strlen(str1);
       
   900   int total = len1 + (int) len2;
       
   901 
       
   902   int hit = 0;
       
   903 
       
   904   for (int i = 0; i < len1 -1; ++i) {
       
   905     for (int j = 0; j < (int) len2 -1; ++j) {
       
   906       if ((str1[i] == str2[j]) && (str1[i+1] == str2[j+1])) {
       
   907         ++hit;
       
   908         break;
       
   909       }
       
   910     }
       
   911   }
       
   912 
       
   913   return 2.0f * (float) hit / (float) total;
       
   914 }
       
   915 
       
   916 Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
   898 Flag* Flag::fuzzy_match(const char* name, size_t length, bool allow_locked) {
   917   float VMOptionsFuzzyMatchSimilarity = 0.7f;
   899   float VMOptionsFuzzyMatchSimilarity = 0.7f;
   918   Flag* match = NULL;
   900   Flag* match = NULL;
   919   float score;
   901   float score;
   920   float max_score = -1;
   902   float max_score = -1;
   921 
   903 
   922   for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
   904   for (Flag* current = &flagTable[0]; current->_name != NULL; current++) {
   923     score = str_similar(current->_name, name, length);
   905     score = StringUtils::similarity(current->_name, strlen(current->_name), name, length);
   924     if (score > max_score) {
   906     if (score > max_score) {
   925       max_score = score;
   907       max_score = score;
   926       match = current;
   908       match = current;
   927     }
   909     }
   928   }
   910   }