Path: blob/master/runtime/bcutil/SRPOffsetTable.cpp
5985 views
/*******************************************************************************1* Copyright (c) 2001, 2016 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/21/*22* SRPOffsetTable.cpp23*/2425#include "SRPOffsetTable.hpp"2627#include "BufferManager.hpp"28#include "ROMClassCreationContext.hpp"29#include "ROMClassVerbosePhase.hpp"30#include "SRPKeyProducer.hpp"31#include "ut_j9bcu.h"3233SRPOffsetTable::SRPOffsetTable(SRPKeyProducer *srpKeyProducer, BufferManager *bufferManager, UDATA maxTag, ROMClassCreationContext *context) :34_maxKey( srpKeyProducer->getMaxKey() ),35_maxTag( maxTag ),36_table( NULL ),37_baseAddresses( NULL ),38_bufferManager( bufferManager ),39_buildResult( OutOfMemory )40{41ROMClassVerbosePhase v(context, SRPOffsetTableCreation, &_buildResult);4243_table = (Entry *) _bufferManager->alloc( sizeof(Entry) * (_maxKey + 1) );44if ( NULL == _table ) {45return;46}4748_baseAddresses = (U_8 **) _bufferManager->alloc( sizeof(U_8 *) * (_maxTag + 1) );49if ( NULL == _baseAddresses ) {50_bufferManager->free(_table);51_table = NULL;52return;53}5455memset( _table, 0, sizeof(Entry) * (_maxKey + 1) );56memset( _baseAddresses, 0, sizeof(U_8 *) * (_maxTag + 1) );5758_buildResult = OK;59}6061SRPOffsetTable::~SRPOffsetTable()62{63_bufferManager->free( _table );64_bufferManager->free( _baseAddresses );65}6667void68SRPOffsetTable::insert(UDATA key, UDATA offset, UDATA tag)69{70Trc_BCU_Assert_NotGreaterThan( key, _maxKey );71Trc_BCU_Assert_NotGreaterThan( tag, _maxTag );7273if (0 == key) {74Trc_BCU_Assert_ShouldNeverHappen();75}7677Trc_BCU_Assert_Equals(false, _table[ key ].interned);7879_table[ key ].offset = offset;80_table[ key ].tag = tag;81_table[ key ].marked = true;82}8384UDATA85SRPOffsetTable::get(UDATA key)86{87Trc_BCU_Assert_NotGreaterThan( key, _maxKey );8889return _table[ key ].offset;90}9192J9SRP93SRPOffsetTable::computeSRP(UDATA key, J9SRP *srpAddr)94{95Trc_BCU_Assert_NotGreaterThan( key, _maxKey );9697if ( _table[ key ].marked ) {98return J9SRP(_baseAddresses[ _table[ key ].tag ] + _table[key].offset - (U_8 *)srpAddr);99} else if (_table[ key ].interned) {100return J9SRP(IDATA(_table[ key ].offset) - IDATA(srpAddr));101}102return 0;103}104105J9WSRP106SRPOffsetTable::computeWSRP(UDATA key, J9WSRP *wsrpAddr)107{108Trc_BCU_Assert_NotGreaterThan( key, _maxKey );109110if ( _table[ key ].marked ) {111return J9WSRP(_baseAddresses[ _table[ key ].tag ] + _table[key].offset - (U_8 *)wsrpAddr);112} else if (_table[ key ].interned) {113return J9WSRP(IDATA(_table[ key ].offset) - IDATA(wsrpAddr));114}115return 0;116}117118bool119SRPOffsetTable::isNotNull(UDATA key)120{121return _table[ key ].marked || _table[ key ].interned;122}123124bool125SRPOffsetTable::isInterned(UDATA key)126{127return _table[ key ].interned;128}129130void131SRPOffsetTable::setInternedAt(UDATA key, U_8 *address)132{133_table[key].interned = true;134_table[key].marked = false;135_table[key].offset = UDATA(address);136}137138void139SRPOffsetTable::setBaseAddressForTag(UDATA tag, U_8 *address)140{141Trc_BCU_Assert_NotGreaterThan( tag, _maxTag );142143_baseAddresses[ tag ] = address;144}145146U_8 *147SRPOffsetTable::getBaseAddressForTag(UDATA tag)148{149Trc_BCU_Assert_NotGreaterThan( tag, _maxTag );150151return _baseAddresses[ tag ];152}153154void155SRPOffsetTable::clear()156{157memset( _table, 0, sizeof(Entry) * (_maxKey + 1) );158}159160161