Path: blob/master/runtime/bcutil/ROMClassStringInternManager.cpp
5985 views
/*******************************************************************************1* Copyright (c) 2001, 2014 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* ROMClassStringInternManager.cpp23*24*/2526#include "ROMClassStringInternManager.hpp"27#include "ROMClassBuilder.hpp"28#include "SRPKeyProducer.hpp"29#include "SRPOffsetTable.hpp"3031#include "ut_j9bcu.h"32#include "bcutil_api.h"3334ROMClassStringInternManager::ROMClassStringInternManager(35ROMClassCreationContext *context,36StringInternTable *stringInternTable,37SRPOffsetTable *srpOffsetTable,38SRPKeyProducer *srpKeyProducer,39U_8 *baseAddress,40U_8 *endAddress,41bool isSharedROMClass,42bool hasStringTableLock) :43_context(context),44_stringInternTable(stringInternTable),45_srpOffsetTable(srpOffsetTable),46_srpKeyProducer(srpKeyProducer),47_baseAddress(IDATA(baseAddress)),48_endAddress(IDATA(endAddress)),49_hasStringTableLock(hasStringTableLock),50_isSharedROMClass(isSharedROMClass)51{52}5354/**55* This function visits the passed UTF8 if it is in any string intern table.56* By visiting meaning that it marks the node as used and57* marks the corresponding index SRP Offset table as interned58* if it is found in shared or local string intern table.59*60* @param cpIndex Index in SRP Offset table61* @param utfLength The length of the UTF8 string62* @param utf8Data A pointer to the start of the UTF8 string.63* @param sharedCacheSRPRangeInfo Tells whether shared cache(s) are accessible by rom class. Possible values are:64* 1: (SC_COMPLETELY_OUT_OF_THE_SRP_RANGE) Shared cache is out of the SRP range65* 2: (SC_COMPLETELY_IN_THE_SRP_RANGE) Shared cache is in the SRP range66* 3: (SC_PARTIALLY_IN_THE_SRP_RANGE) Part of shared cache is in the SRP range, part of it is not.67* @return void68*69*/70void71ROMClassStringInternManager::visitUTF8(U_16 cpIndex, U_16 utf8Length, U_8 *utf8Data, SharedCacheRangeInfo sharedCacheSRPRangeInfo)72{73if ( !isInterningEnabled() ) {74return;75}7677J9SharedInvariantInternTable *sharedTable = NULL;7879/* If we don't have the cross-process mutex, it's not safe to search the shared tree */80if (_hasStringTableLock) {81sharedTable = _context->sharedStringInternTable();82}8384J9InternSearchInfo searchInfo;8586searchInfo.stringData = utf8Data;87searchInfo.stringLength = utf8Length;88searchInfo.classloader = (_isSharedROMClass ? _context->javaVM()->systemClassLoader : _context->classLoader());89searchInfo.romClassBaseAddr = (U_8 *)_baseAddress;90searchInfo.romClassEndAddr = (U_8 *)_endAddress;91searchInfo.sharedCacheSRPRangeInfo = sharedCacheSRPRangeInfo;9293J9InternSearchResult result;94if (_stringInternTable->findUtf8(&searchInfo, sharedTable, _isSharedROMClass, &result)) {95IDATA internedString = IDATA(result.utf8);96_stringInternTable->markNodeAsUsed(&result, sharedTable);97_srpOffsetTable->setInternedAt(_srpKeyProducer->mapCfrConstantPoolIndexToKey(cpIndex), (U_8 *)internedString);98}99}100101/**102* This function is used to add the given UTF8 into one of the string intern tables.103* It is added into shared string intern table if it is in the shared cache and104* if there is an empty spot in shared string intern table.105* In all other cases, it is added to local string intern table.106* @param string Given UTF8107* @return void108*109*/110void111ROMClassStringInternManager::internString(J9UTF8 *string)112{113if ( !isInterningEnabled() ) {114return;115}116117J9SharedInvariantInternTable *sharedTable = NULL;118119/* If we don't have the cross-process mutex, it's not safe to search the shared tree */120if (_hasStringTableLock && _isSharedROMClass) {121sharedTable = _context->sharedStringInternTable();122}123124/* Local tree nodes that point to shared string data must125* have their 'classloader' field set to the system classloader. This126* is to allow various asserts to pass when running127* -Xshareclasses:verifyInternTree, and also to maintain the same128* intern tree sorting as in the past.129*/130J9ClassLoader *classLoader = (_isSharedROMClass ? _context->javaVM()->systemClassLoader : _context->classLoader());131_stringInternTable->internUtf8(string, classLoader, _isSharedROMClass, sharedTable);132}133134135136