Path: blob/master/runtime/compiler/control/JITServerHelpers.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2019, 2022 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#ifndef JITSERVER_HELPERS_H23#define JITSERVER_HELPERS_H2425#include "net/MessageTypes.hpp"26#include "runtime/JITClientSession.hpp"272829class JITServerHelpers30{31public:32enum ClassInfoDataType33{34CLASSINFO_ROMCLASS_MODIFIERS,35CLASSINFO_ROMCLASS_EXTRAMODIFIERS,36CLASSINFO_BASE_COMPONENT_CLASS,37CLASSINFO_NUMBER_DIMENSIONS,38CLASSINFO_PARENT_CLASS,39CLASSINFO_INTERFACE_CLASS,40CLASSINFO_CLASS_HAS_FINAL_FIELDS,41CLASSINFO_CLASS_DEPTH_AND_FLAGS,42CLASSINFO_CLASS_INITIALIZED,43CLASSINFO_BYTE_OFFSET_TO_LOCKWORD,44CLASSINFO_LEAF_COMPONENT_CLASS,45CLASSINFO_CLASS_LOADER,46CLASSINFO_HOST_CLASS,47CLASSINFO_COMPONENT_CLASS,48CLASSINFO_ARRAY_CLASS,49CLASSINFO_TOTAL_INSTANCE_SIZE,50CLASSINFO_CLASS_OF_STATIC_CACHE,51CLASSINFO_REMOTE_ROM_CLASS,52CLASSINFO_CLASS_FLAGS,53CLASSINFO_METHODS_OF_CLASS,54CLASSINFO_CONSTANT_POOL,55CLASSINFO_CLASS_CHAIN_OFFSET_IDENTIFYING_LOADER,56CLASSINFO_ARRAY_ELEMENT_SIZE,57};5859// NOTE: when adding new elements to this tuple, add them to the end,60// to not mess with the established order.61using ClassInfoTuple = std::tuple62<63std::string, // 0: _packedROMClass64J9Method *, // 1: _methodsOfClass65TR_OpaqueClassBlock *, // 2: _baseComponentClass66int32_t, // 3: _numDimensions67TR_OpaqueClassBlock *, // 4: _parentClass68std::vector<TR_OpaqueClassBlock *>,// 5: _tmpInterfaces69std::vector<uint8_t>, // 6: _methodTracingInfo70bool, // 7: _classHasFinalFields71uintptr_t, // 8: _classDepthAndFlags72bool, // 9: _classInitialized73uint32_t, // 10: _byteOffsetToLockword74TR_OpaqueClassBlock *, // 11: _leafComponentClass75void *, // 12: _classLoader76TR_OpaqueClassBlock *, // 13: _hostClass77TR_OpaqueClassBlock *, // 14: _componentClass78TR_OpaqueClassBlock *, // 15: _arrayClass79uintptr_t, // 16: _totalInstanceSize80J9ROMClass *, // 17: _remoteRomClass81uintptr_t, // 18: _constantPool82uintptr_t, // 19: _classFlags83uintptr_t, // 20: _classChainOffsetIdentifyingLoader84std::vector<J9ROMMethod *>, // 21: _origROMMethods85std::string, // 22: _classNameIdentifyingLoader86int32_t // 23: _arrayElementSize87>;8889// Packs a ROMClass to be transferred to the server.90// The result is allocated from the stack region of trMemory (as well as temporary data91// structures used for packing). This function should be used with TR::StackMemoryRegion.92// If passed non-zero expectedSize, and it doesn't match the resulting packedSize93// (which is returned to the caller by reference), this function returns NULL.94static J9ROMClass *packROMClass(J9ROMClass *romClass, TR_Memory *trMemory, size_t &packedSize, size_t expectedSize = 0);9596static ClassInfoTuple packRemoteROMClassInfo(J9Class *clazz, J9VMThread *vmThread, TR_Memory *trMemory, bool serializeClass);97static void freeRemoteROMClass(J9ROMClass *romClass, TR_PersistentMemory *persistentMemory);98static J9ROMClass *cacheRemoteROMClassOrFreeIt(ClientSessionData *clientSessionData, J9Class *clazz,99J9ROMClass *romClass, const ClassInfoTuple &classInfoTuple);100static ClientSessionData::ClassInfo &cacheRemoteROMClass(ClientSessionData *clientSessionData, J9Class *clazz,101J9ROMClass *romClass, const ClassInfoTuple &classInfoTuple);102static J9ROMClass *getRemoteROMClassIfCached(ClientSessionData *clientSessionData, J9Class *clazz);103static J9ROMClass *getRemoteROMClass(J9Class *clazz, JITServer::ServerStream *stream,104TR_PersistentMemory *persistentMemory, ClassInfoTuple &classInfoTuple);105static J9ROMClass *romClassFromString(const std::string &romClassStr, TR_PersistentMemory *persistentMemory);106static bool getAndCacheRAMClassInfo(J9Class *clazz, ClientSessionData *clientSessionData,107JITServer::ServerStream *stream, ClassInfoDataType dataType, void *data);108static bool getAndCacheRAMClassInfo(J9Class *clazz, ClientSessionData *clientSessionData,109JITServer::ServerStream *stream, ClassInfoDataType dataType1, void *data1,110ClassInfoDataType dataType2, void *data2);111static J9ROMMethod *romMethodOfRamMethod(J9Method* method);112113static void insertIntoOOSequenceEntryList(ClientSessionData *clientData, TR_MethodToBeCompiled *entry);114115static uintptr_t getRemoteClassDepthAndFlagsWhenROMClassNotCached(J9Class *clazz, ClientSessionData *clientSessionData,116JITServer::ServerStream *stream);117118// Functions used for allowing the client to compile locally when server is unavailable.119// Should be used only on the client side.120static void postStreamFailure(OMRPortLibrary *portLibrary, TR::CompilationInfo *compInfo);121static bool shouldRetryConnection(OMRPortLibrary *portLibrary);122static void postStreamConnectionSuccess();123static bool isServerAvailable() { return _serverAvailable; }124125static void printJITServerMsgStats(J9JITConfig *, TR::CompilationInfo *);126static void printJITServerCHTableStats(J9JITConfig *, TR::CompilationInfo *);127static void printJITServerCacheStats(J9JITConfig *, TR::CompilationInfo *);128129static uint32_t serverMsgTypeCount[JITServer::MessageType_MAXTYPE];130131static bool isAddressInROMClass(const void *address, const J9ROMClass *romClass);132133static uintptr_t walkReferenceChainWithOffsets(TR_J9VM *fe, const std::vector<uintptr_t> &listOfOffsets, uintptr_t receiver);134135// Called by the client as part of preparing the compilation request and handling the SharedCache_rememberClass message136// when AOT cache is enabled. Returns the list of RAMClasses in the class chain for clazz and populates uncachedRAMClasses137// and uncachedClassInfos with the classes (and their data) that the client has not yet sent to the server.138static std::vector<J9Class *>139getRAMClassChain(J9Class *clazz, size_t numClasses, J9VMThread *vmThread, TR_Memory *trMemory, TR::CompilationInfo *compInfo,140std::vector<J9Class *> &uncachedRAMClasses, std::vector<ClassInfoTuple> &uncachedClassInfos);141142static void cacheRemoteROMClassBatch(ClientSessionData *clientData, const std::vector<J9Class *> &ramClasses,143const std::vector<ClassInfoTuple> &classInfoTuples);144145private:146static void getROMClassData(const ClientSessionData::ClassInfo &classInfo, ClassInfoDataType dataType, void *data);147148static TR::Monitor *getClientStreamMonitor()149{150if (!_clientStreamMonitor)151_clientStreamMonitor = TR::Monitor::create("clientStreamMonitor");152return _clientStreamMonitor;153}154155static uint64_t _waitTimeMs;156static uint64_t _nextConnectionRetryTime;157static bool _serverAvailable;158static TR::Monitor * _clientStreamMonitor;159}; // class JITServerHelpers160161#endif // defined(JITSERVER_HELPERS_H)162163164