Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagLookup.cpp
40957 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "runtime/flags/jvmFlag.hpp"26#include "runtime/flags/jvmFlagLookup.hpp"27#include "utilities/defaultStream.hpp"2829#define DO_FLAG(type, name,...) DO_HASH(FLAG_MEMBER_ENUM(name), XSTR(name))3031#define DO_HASH(flag_enum, flag_name) { \32unsigned int hash = hash_code(flag_name); \33int bucket_index = (int)(hash % NUM_BUCKETS); \34_hashes[flag_enum] = (u2)(hash); \35_table[flag_enum] = _buckets[bucket_index]; \36_buckets[bucket_index] = (short)flag_enum; \37}3839constexpr JVMFlagLookup::JVMFlagLookup() : _buckets(), _table(), _hashes() {40for (int i = 0; i < NUM_BUCKETS; i++) {41_buckets[i] = -1;42}4344ALL_FLAGS(DO_FLAG,45DO_FLAG,46DO_FLAG,47DO_FLAG,48DO_FLAG,49IGNORE_RANGE,50IGNORE_CONSTRAINT)51}5253constexpr JVMFlagLookup _flag_lookup_table;5455JVMFlag* JVMFlagLookup::find_impl(const char* name, size_t length) const {56unsigned int hash = hash_code(name, length);57int bucket_index = (int)(hash % NUM_BUCKETS);58for (int flag_enum = _buckets[bucket_index]; flag_enum >= 0; ) {59if (_hashes[flag_enum] == (u2)hash) {60JVMFlag* flag = JVMFlag::flags + flag_enum;61if (strncmp(name, flag->name(), length) == 0) {62// We know flag->name() has at least <length> bytes.63// Make sure it has exactly <length> bytes64if (flag->name()[length] == 0) {65return flag;66}67}68}69flag_enum = (int)_table[flag_enum];70}7172return NULL;73}7475JVMFlag* JVMFlagLookup::find(const char* name, size_t length) {76return _flag_lookup_table.find_impl(name, length);77}787980