Path: blob/master/runtime/bcutil/StringInternTable.hpp
5985 views
/*******************************************************************************1* Copyright (c) 2001, 2017 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*******************************************************************************/2122/*23* StringInternTable.hpp24*/2526#ifndef STRINGINTERNTABLE_HPP_27#define STRINGINTERNTABLE_HPP_2829/* @ddr_namespace: default */30#include "j9.h"3132struct J9InternHashTableEntry;3334/**35*36* Shared cache(s) can be SC_COMPLETELY_OUT_OF_THE_SRP_RANGE if and only if all start and end addresses37* of shared cache(s) are out of the range of a specific address in the memory.38* Shared cache(s) can be SC_COMPLETELY_IN_THE_SRP_RANGE if and only if all start and end addresses39* of shared cache(s) are in the range of a specific address in the memory.40* In all other cases, shared cache(s) are SC_PARTIALLY_IN_THE_SRP_RANGE.41* In this case, range check between start and end addressed of shared cache(s) results in42* combination of SC_COMPLETELY_OUT_OF_THE_SRP_RANGE and SC_COMPLETELY_IN_THE_SRP_RANGE.43* That is the reason why these values are bitwise, all the range check results between start/end addresses of shared cache(s)44* and a specific memory address are ORed.45*46*/47enum SharedCacheRangeInfo48{49SC_NO_RANGE_INFO = 0,50SC_COMPLETELY_OUT_OF_THE_SRP_RANGE = 1,51SC_COMPLETELY_IN_THE_SRP_RANGE = 2,52SC_PARTIALLY_IN_THE_SRP_RANGE = 353};5455typedef struct J9InternSearchResult {56J9UTF8 *utf8;57void *node;58bool isSharedNode;59} J9InternSearchResult;6061typedef struct J9InternSearchInfo {62struct J9ClassLoader* classloader;63U_8* stringData;64UDATA stringLength;65U_8* romClassBaseAddr;66U_8* romClassEndAddr;67SharedCacheRangeInfo sharedCacheSRPRangeInfo;68} J9InternSearchInfo;6970class StringInternTable71{72public:73StringInternTable(J9JavaVM *vm, J9PortLibrary *portLibrary, UDATA maximumNodeCount);74~StringInternTable();7576J9JavaVM *javaVM() const { return _vm; }7778bool isOK() const { return (0 == _maximumNodeCount) || (NULL != _internHashTable); }7980bool findUtf8(J9InternSearchInfo *searchInfo, J9SharedInvariantInternTable *sharedInternTable, bool requiresSharedUtf8, J9InternSearchResult *result);8182void markNodeAsUsed(J9InternSearchResult *result, J9SharedInvariantInternTable *sharedInternTable);8384void internUtf8(J9UTF8 *utf8, J9ClassLoader *classLoader, bool fromSharedROMClass = false, J9SharedInvariantInternTable *sharedInternTable = NULL);8586void removeLocalNodesWithDeadClassLoaders();8788J9InternHashTableEntry * getLRUHead() const { return _headNode; }8990bool verify(const char *file, IDATA line) const;9192#if defined(J9VM_ENV_DATA64)93/**94* This function checks whether two given addresses are in the SRP range to each other or not.95* This check is done only for 64 bit environments.96* @param addr1 First given address.97* @param addr2 Second given address.98* @return true if two addresses are in the SRP range to each other,99* @return false; otherwise.100*101*/102static bool103areAddressesInSRPRange(void *addr1, void *addr2)104{105UDATA rangeCheck = (addr1 > addr2) ? (UDATA)addr1 - (UDATA)addr2 : (UDATA)addr2 - (UDATA)addr1;106if (0x7FFFFFFF < rangeCheck) {107return false;108}109return true;110};111#endif112113private:114115/* NOTE: Be sure to update J9DbgStringInternTable when changing the state variables below. */116J9JavaVM *_vm;117J9PortLibrary *_portLibrary;118J9HashTable *_internHashTable;119J9InternHashTableEntry *_headNode;120J9InternHashTableEntry *_tailNode;121UDATA _nodeCount;122UDATA _maximumNodeCount;123124J9InternHashTableEntry * insertLocalNode(J9InternHashTableEntry *node, bool promoteIfExistingFound);125void deleteLocalNode(J9InternHashTableEntry *node);126127void promoteNodeToHead(J9InternHashTableEntry *node);128void removeNodeFromList(J9InternHashTableEntry *node);129130bool verifyNode(J9InternHashTableEntry *node, const char *file, IDATA line) const;131132#if defined(J9VM_OPT_SHARED_CLASSES)133134J9SharedInternSRPHashTableEntry * insertSharedNode(J9SharedInvariantInternTable *table, J9UTF8 *utf8, U_16 internWeight, U_16 flags, bool promoteIfExistingFound);135136void deleteSharedNode(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *node);137void removeSharedNodeFromList(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *sharedNode);138139UDATA getRequiredBytesForUTF8Length(U_16 length);140void updateLocalNodeWeight(J9InternHashTableEntry *node);141void updateSharedNodeWeight(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *sharedNode);142143bool testNodePromotionWeight(J9SharedInvariantInternTable *table, J9InternHashTableEntry *node, J9SharedInternSRPHashTableEntry *sharedNodeToDisplace);144145void swapLocalNodeWithTailSharedNode(J9InternHashTableEntry *node, J9SharedInvariantInternTable *table);146void promoteSharedNodeToHead(J9SharedInvariantInternTable *table, J9SharedInternSRPHashTableEntry *node);147148#endif /* J9VM_OPT_SHARED_CLASSES */149};150151#endif /* STRINGINTERNTABLE_HPP_ */152153154