Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/StringInternTable.hpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2017 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
/*
24
* StringInternTable.hpp
25
*/
26
27
#ifndef STRINGINTERNTABLE_HPP_
28
#define STRINGINTERNTABLE_HPP_
29
30
/* @ddr_namespace: default */
31
#include "j9.h"
32
33
struct J9InternHashTableEntry;
34
35
/**
36
*
37
* Shared cache(s) can be SC_COMPLETELY_OUT_OF_THE_SRP_RANGE if and only if all start and end addresses
38
* of shared cache(s) are out of the range of a specific address in the memory.
39
* Shared cache(s) can be SC_COMPLETELY_IN_THE_SRP_RANGE if and only if all start and end addresses
40
* of shared cache(s) are in the range of a specific address in the memory.
41
* In all other cases, shared cache(s) are SC_PARTIALLY_IN_THE_SRP_RANGE.
42
* In this case, range check between start and end addressed of shared cache(s) results in
43
* combination of SC_COMPLETELY_OUT_OF_THE_SRP_RANGE and SC_COMPLETELY_IN_THE_SRP_RANGE.
44
* That is the reason why these values are bitwise, all the range check results between start/end addresses of shared cache(s)
45
* and a specific memory address are ORed.
46
*
47
*/
48
enum SharedCacheRangeInfo
49
{
50
SC_NO_RANGE_INFO = 0,
51
SC_COMPLETELY_OUT_OF_THE_SRP_RANGE = 1,
52
SC_COMPLETELY_IN_THE_SRP_RANGE = 2,
53
SC_PARTIALLY_IN_THE_SRP_RANGE = 3
54
};
55
56
typedef struct J9InternSearchResult {
57
J9UTF8 *utf8;
58
void *node;
59
bool isSharedNode;
60
} J9InternSearchResult;
61
62
typedef struct J9InternSearchInfo {
63
struct J9ClassLoader* classloader;
64
U_8* stringData;
65
UDATA stringLength;
66
U_8* romClassBaseAddr;
67
U_8* romClassEndAddr;
68
SharedCacheRangeInfo sharedCacheSRPRangeInfo;
69
} J9InternSearchInfo;
70
71
class StringInternTable
72
{
73
public:
74
StringInternTable(J9JavaVM *vm, J9PortLibrary *portLibrary, UDATA maximumNodeCount);
75
~StringInternTable();
76
77
J9JavaVM *javaVM() const { return _vm; }
78
79
bool isOK() const { return (0 == _maximumNodeCount) || (NULL != _internHashTable); }
80
81
bool findUtf8(J9InternSearchInfo *searchInfo, J9SharedInvariantInternTable *sharedInternTable, bool requiresSharedUtf8, J9InternSearchResult *result);
82
83
void markNodeAsUsed(J9InternSearchResult *result, J9SharedInvariantInternTable *sharedInternTable);
84
85
void internUtf8(J9UTF8 *utf8, J9ClassLoader *classLoader, bool fromSharedROMClass = false, J9SharedInvariantInternTable *sharedInternTable = NULL);
86
87
void removeLocalNodesWithDeadClassLoaders();
88
89
J9InternHashTableEntry * getLRUHead() const { return _headNode; }
90
91
bool verify(const char *file, IDATA line) const;
92
93
#if defined(J9VM_ENV_DATA64)
94
/**
95
* This function checks whether two given addresses are in the SRP range to each other or not.
96
* This check is done only for 64 bit environments.
97
* @param addr1 First given address.
98
* @param addr2 Second given address.
99
* @return true if two addresses are in the SRP range to each other,
100
* @return false; otherwise.
101
*
102
*/
103
static bool
104
areAddressesInSRPRange(void *addr1, void *addr2)
105
{
106
UDATA rangeCheck = (addr1 > addr2) ? (UDATA)addr1 - (UDATA)addr2 : (UDATA)addr2 - (UDATA)addr1;
107
if (0x7FFFFFFF < rangeCheck) {
108
return false;
109
}
110
return true;
111
};
112
#endif
113
114
private:
115
116
/* NOTE: Be sure to update J9DbgStringInternTable when changing the state variables below. */
117
J9JavaVM *_vm;
118
J9PortLibrary *_portLibrary;
119
J9HashTable *_internHashTable;
120
J9InternHashTableEntry *_headNode;
121
J9InternHashTableEntry *_tailNode;
122
UDATA _nodeCount;
123
UDATA _maximumNodeCount;
124
125
J9InternHashTableEntry * insertLocalNode(J9InternHashTableEntry *node, bool promoteIfExistingFound);
126
void deleteLocalNode(J9InternHashTableEntry *node);
127
128
void promoteNodeToHead(J9InternHashTableEntry *node);
129
void removeNodeFromList(J9InternHashTableEntry *node);
130
131
bool verifyNode(J9InternHashTableEntry *node, const char *file, IDATA line) const;
132
133
#if defined(J9VM_OPT_SHARED_CLASSES)
134
135
J9SharedInternSRPHashTableEntry * insertSharedNode(J9SharedInvariantInternTable *table, J9UTF8 *utf8, U_16 internWeight, U_16 flags, bool promoteIfExistingFound);
136
137
void deleteSharedNode(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *node);
138
void removeSharedNodeFromList(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *sharedNode);
139
140
UDATA getRequiredBytesForUTF8Length(U_16 length);
141
void updateLocalNodeWeight(J9InternHashTableEntry *node);
142
void updateSharedNodeWeight(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *sharedNode);
143
144
bool testNodePromotionWeight(J9SharedInvariantInternTable *table, J9InternHashTableEntry *node, J9SharedInternSRPHashTableEntry *sharedNodeToDisplace);
145
146
void swapLocalNodeWithTailSharedNode(J9InternHashTableEntry *node, J9SharedInvariantInternTable *table);
147
void promoteSharedNodeToHead(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *node);
148
149
#endif /* J9VM_OPT_SHARED_CLASSES */
150
};
151
152
#endif /* STRINGINTERNTABLE_HPP_ */
153
154