Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/SRPOffsetTable.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2016 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
* SRPOffsetTable.cpp
24
*/
25
26
#include "SRPOffsetTable.hpp"
27
28
#include "BufferManager.hpp"
29
#include "ROMClassCreationContext.hpp"
30
#include "ROMClassVerbosePhase.hpp"
31
#include "SRPKeyProducer.hpp"
32
#include "ut_j9bcu.h"
33
34
SRPOffsetTable::SRPOffsetTable(SRPKeyProducer *srpKeyProducer, BufferManager *bufferManager, UDATA maxTag, ROMClassCreationContext *context) :
35
_maxKey( srpKeyProducer->getMaxKey() ),
36
_maxTag( maxTag ),
37
_table( NULL ),
38
_baseAddresses( NULL ),
39
_bufferManager( bufferManager ),
40
_buildResult( OutOfMemory )
41
{
42
ROMClassVerbosePhase v(context, SRPOffsetTableCreation, &_buildResult);
43
44
_table = (Entry *) _bufferManager->alloc( sizeof(Entry) * (_maxKey + 1) );
45
if ( NULL == _table ) {
46
return;
47
}
48
49
_baseAddresses = (U_8 **) _bufferManager->alloc( sizeof(U_8 *) * (_maxTag + 1) );
50
if ( NULL == _baseAddresses ) {
51
_bufferManager->free(_table);
52
_table = NULL;
53
return;
54
}
55
56
memset( _table, 0, sizeof(Entry) * (_maxKey + 1) );
57
memset( _baseAddresses, 0, sizeof(U_8 *) * (_maxTag + 1) );
58
59
_buildResult = OK;
60
}
61
62
SRPOffsetTable::~SRPOffsetTable()
63
{
64
_bufferManager->free( _table );
65
_bufferManager->free( _baseAddresses );
66
}
67
68
void
69
SRPOffsetTable::insert(UDATA key, UDATA offset, UDATA tag)
70
{
71
Trc_BCU_Assert_NotGreaterThan( key, _maxKey );
72
Trc_BCU_Assert_NotGreaterThan( tag, _maxTag );
73
74
if (0 == key) {
75
Trc_BCU_Assert_ShouldNeverHappen();
76
}
77
78
Trc_BCU_Assert_Equals(false, _table[ key ].interned);
79
80
_table[ key ].offset = offset;
81
_table[ key ].tag = tag;
82
_table[ key ].marked = true;
83
}
84
85
UDATA
86
SRPOffsetTable::get(UDATA key)
87
{
88
Trc_BCU_Assert_NotGreaterThan( key, _maxKey );
89
90
return _table[ key ].offset;
91
}
92
93
J9SRP
94
SRPOffsetTable::computeSRP(UDATA key, J9SRP *srpAddr)
95
{
96
Trc_BCU_Assert_NotGreaterThan( key, _maxKey );
97
98
if ( _table[ key ].marked ) {
99
return J9SRP(_baseAddresses[ _table[ key ].tag ] + _table[key].offset - (U_8 *)srpAddr);
100
} else if (_table[ key ].interned) {
101
return J9SRP(IDATA(_table[ key ].offset) - IDATA(srpAddr));
102
}
103
return 0;
104
}
105
106
J9WSRP
107
SRPOffsetTable::computeWSRP(UDATA key, J9WSRP *wsrpAddr)
108
{
109
Trc_BCU_Assert_NotGreaterThan( key, _maxKey );
110
111
if ( _table[ key ].marked ) {
112
return J9WSRP(_baseAddresses[ _table[ key ].tag ] + _table[key].offset - (U_8 *)wsrpAddr);
113
} else if (_table[ key ].interned) {
114
return J9WSRP(IDATA(_table[ key ].offset) - IDATA(wsrpAddr));
115
}
116
return 0;
117
}
118
119
bool
120
SRPOffsetTable::isNotNull(UDATA key)
121
{
122
return _table[ key ].marked || _table[ key ].interned;
123
}
124
125
bool
126
SRPOffsetTable::isInterned(UDATA key)
127
{
128
return _table[ key ].interned;
129
}
130
131
void
132
SRPOffsetTable::setInternedAt(UDATA key, U_8 *address)
133
{
134
_table[key].interned = true;
135
_table[key].marked = false;
136
_table[key].offset = UDATA(address);
137
}
138
139
void
140
SRPOffsetTable::setBaseAddressForTag(UDATA tag, U_8 *address)
141
{
142
Trc_BCU_Assert_NotGreaterThan( tag, _maxTag );
143
144
_baseAddresses[ tag ] = address;
145
}
146
147
U_8 *
148
SRPOffsetTable::getBaseAddressForTag(UDATA tag)
149
{
150
Trc_BCU_Assert_NotGreaterThan( tag, _maxTag );
151
152
return _baseAddresses[ tag ];
153
}
154
155
void
156
SRPOffsetTable::clear()
157
{
158
memset( _table, 0, sizeof(Entry) * (_maxKey + 1) );
159
}
160
161