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