Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/ROMClassStringInternManager.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2014 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
* ROMClassStringInternManager.cpp
24
*
25
*/
26
27
#include "ROMClassStringInternManager.hpp"
28
#include "ROMClassBuilder.hpp"
29
#include "SRPKeyProducer.hpp"
30
#include "SRPOffsetTable.hpp"
31
32
#include "ut_j9bcu.h"
33
#include "bcutil_api.h"
34
35
ROMClassStringInternManager::ROMClassStringInternManager(
36
ROMClassCreationContext *context,
37
StringInternTable *stringInternTable,
38
SRPOffsetTable *srpOffsetTable,
39
SRPKeyProducer *srpKeyProducer,
40
U_8 *baseAddress,
41
U_8 *endAddress,
42
bool isSharedROMClass,
43
bool hasStringTableLock) :
44
_context(context),
45
_stringInternTable(stringInternTable),
46
_srpOffsetTable(srpOffsetTable),
47
_srpKeyProducer(srpKeyProducer),
48
_baseAddress(IDATA(baseAddress)),
49
_endAddress(IDATA(endAddress)),
50
_hasStringTableLock(hasStringTableLock),
51
_isSharedROMClass(isSharedROMClass)
52
{
53
}
54
55
/**
56
* This function visits the passed UTF8 if it is in any string intern table.
57
* By visiting meaning that it marks the node as used and
58
* marks the corresponding index SRP Offset table as interned
59
* if it is found in shared or local string intern table.
60
*
61
* @param cpIndex Index in SRP Offset table
62
* @param utfLength The length of the UTF8 string
63
* @param utf8Data A pointer to the start of the UTF8 string.
64
* @param sharedCacheSRPRangeInfo Tells whether shared cache(s) are accessible by rom class. Possible values are:
65
* 1: (SC_COMPLETELY_OUT_OF_THE_SRP_RANGE) Shared cache is out of the SRP range
66
* 2: (SC_COMPLETELY_IN_THE_SRP_RANGE) Shared cache is in the SRP range
67
* 3: (SC_PARTIALLY_IN_THE_SRP_RANGE) Part of shared cache is in the SRP range, part of it is not.
68
* @return void
69
*
70
*/
71
void
72
ROMClassStringInternManager::visitUTF8(U_16 cpIndex, U_16 utf8Length, U_8 *utf8Data, SharedCacheRangeInfo sharedCacheSRPRangeInfo)
73
{
74
if ( !isInterningEnabled() ) {
75
return;
76
}
77
78
J9SharedInvariantInternTable *sharedTable = NULL;
79
80
/* If we don't have the cross-process mutex, it's not safe to search the shared tree */
81
if (_hasStringTableLock) {
82
sharedTable = _context->sharedStringInternTable();
83
}
84
85
J9InternSearchInfo searchInfo;
86
87
searchInfo.stringData = utf8Data;
88
searchInfo.stringLength = utf8Length;
89
searchInfo.classloader = (_isSharedROMClass ? _context->javaVM()->systemClassLoader : _context->classLoader());
90
searchInfo.romClassBaseAddr = (U_8 *)_baseAddress;
91
searchInfo.romClassEndAddr = (U_8 *)_endAddress;
92
searchInfo.sharedCacheSRPRangeInfo = sharedCacheSRPRangeInfo;
93
94
J9InternSearchResult result;
95
if (_stringInternTable->findUtf8(&searchInfo, sharedTable, _isSharedROMClass, &result)) {
96
IDATA internedString = IDATA(result.utf8);
97
_stringInternTable->markNodeAsUsed(&result, sharedTable);
98
_srpOffsetTable->setInternedAt(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cpIndex), (U_8 *)internedString);
99
}
100
}
101
102
/**
103
* This function is used to add the given UTF8 into one of the string intern tables.
104
* It is added into shared string intern table if it is in the shared cache and
105
* if there is an empty spot in shared string intern table.
106
* In all other cases, it is added to local string intern table.
107
* @param string Given UTF8
108
* @return void
109
*
110
*/
111
void
112
ROMClassStringInternManager::internString(J9UTF8 *string)
113
{
114
if ( !isInterningEnabled() ) {
115
return;
116
}
117
118
J9SharedInvariantInternTable *sharedTable = NULL;
119
120
/* If we don't have the cross-process mutex, it's not safe to search the shared tree */
121
if (_hasStringTableLock && _isSharedROMClass) {
122
sharedTable = _context->sharedStringInternTable();
123
}
124
125
/* Local tree nodes that point to shared string data must
126
* have their 'classloader' field set to the system classloader. This
127
* is to allow various asserts to pass when running
128
* -Xshareclasses:verifyInternTree, and also to maintain the same
129
* intern tree sorting as in the past.
130
*/
131
J9ClassLoader *classLoader = (_isSharedROMClass ? _context->javaVM()->systemClassLoader : _context->classLoader());
132
_stringInternTable->internUtf8(string, classLoader, _isSharedROMClass, sharedTable);
133
}
134
135
136