Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/runtime/flags/jvmFlagLookup.hpp
40957 views
1
/*
2
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
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
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_RUNTIME_FLAGS_JVMFLAGLOOKUP_HPP
26
#define SHARE_RUNTIME_FLAGS_JVMFLAGLOOKUP_HPP
27
28
#include "runtime/globals_extension.hpp"
29
#include "runtime/flags/jvmFlag.hpp"
30
31
// This is a hashtable that maps from (const char*) to (JVMFlag*) to speed up
32
// the processing of JVM command-line arguments at runtime.
33
//
34
// With constexpr, this table is generated at C++ compile time so there's
35
// no set up cost at runtime.
36
class JVMFlagLookup {
37
static constexpr int NUM_BUCKETS = 277;
38
short _buckets[NUM_BUCKETS];
39
short _table[NUM_JVMFlagsEnum];
40
u2 _hashes[NUM_JVMFlagsEnum];
41
42
// Cannot use strlen() -- it's not constexpr.
43
static constexpr size_t string_len(const char* s) {
44
size_t len = 0;
45
while (*s != 0) {
46
len++;
47
s++;
48
}
49
return len;
50
}
51
52
// This is executed at build-time only, so it doesn't matter if we walk
53
// the string twice.
54
static constexpr unsigned int hash_code(const char* s) {
55
return hash_code(s, string_len(s));
56
}
57
58
static constexpr unsigned int hash_code(const char* s, size_t len) {
59
unsigned int h = 0;
60
while (len -- > 0) {
61
h = 31*h + (unsigned int) *s;
62
s++;
63
}
64
return h;
65
}
66
67
JVMFlag* find_impl(const char* flag_name, size_t length) const;
68
69
public:
70
constexpr JVMFlagLookup();
71
static JVMFlag* find(const char* flag_name, size_t length);
72
};
73
74
#endif // SHARE_RUNTIME_FLAGS_JVMFLAGLOOKUP_HPP
75
76