Path: blob/master/runtime/compiler/env/J2IThunk.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2021 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 TR_J2ITHUNK_INCL23#define TR_J2ITHUNK_INCL2425#include "infra/Array.hpp"26#include "env/TRMemory.hpp"27#include "env/IO.hpp"2829class TR_J2IThunkTable;30namespace TR { class CodeGenerator; }31namespace TR { class Monitor; }3233class TR_J2IThunk34{35int16_t _totalSize;36int16_t _codeSize;3738public:3940static TR_J2IThunk *allocate(int16_t codeSize, char *signature, TR::CodeGenerator *cg, TR_J2IThunkTable *thunkTable);4142static TR_J2IThunk *get(uint8_t *entryPoint)43{ return ((TR_J2IThunk*)entryPoint)-1; }4445int16_t totalSize() { return _totalSize; }46int16_t codeSize() { return _codeSize; }47uint8_t *entryPoint() { return (uint8_t*)(this+1); }48char *terseSignature() { return (char*)(entryPoint() + codeSize()); }49};5051class TR_J2IThunkTable52{53enum TypeChars54{55TC_VOID,56TC_INT,57TC_LONG,58TC_FLOAT,59TC_DOUBLE,60TC_REFERENCE,6162NUM_TYPE_CHARS63};6465static int32_t typeCharIndex(char typeChar)66{67switch (typeChar)68{69case 'V': return TC_VOID;70case 'I': return TC_INT;71case 'J': return TC_LONG;72case 'F': return TC_FLOAT;73case 'D': return TC_DOUBLE;74case 'L':75case 'Q': return TC_REFERENCE;76default:77TR_ASSERT(0, "Unknown type char '%c'", typeChar);78return -1;79}80}8182struct Node83{84typedef int32_t ChildIndex; // sad -- how many nodes are there really going to be in this array? uint8_t would suffice for some workloads!8586TR_J2IThunk *_thunk;87ChildIndex _children[NUM_TYPE_CHARS];8889Node *get(char *terseSignature, TR_PersistentArray<Node> &nodeArray, bool createIfMissing);9091void dumpTo(TR_FrontEnd *fe, TR::FILE *file, TR_PersistentArray<Node> &nodeArray, int indent);92};9394private: // Fields9596char *_name;97TR::Monitor *_monitor;98TR_PersistentArray<Node> _nodes;99100public: // API101102// FUN FACT: signature strings don't need to be null-terminated. This class103// can always tell where the end is from the Java signature string format,104// and does not rely on null-termination.105106TR_J2IThunk *findThunk(char *signature, TR_FrontEnd *frontend, bool isForCurrentRun=false); // may return NULL107TR_J2IThunk *getThunk (char *signature, TR_FrontEnd *frontend, bool isForCurrentRun=false); // same as findThunk but asserts !NULL108109// Note: the 'isForCurrentRun' flag is meant for AOT-aware code.110// If you don't know what this should be, you probably want to use its default value.111//112void addThunk(TR_J2IThunk *thunk, TR_FrontEnd *fe, bool isForCurrentRun=false);113114char terseTypeChar(char *type);115int16_t terseSignatureLength(char *signature);116void getTerseSignature(char *buf, int16_t bufLength, char *signature);117118TR_J2IThunkTable(TR_PersistentMemory *m, char *name);119TR_PERSISTENT_ALLOC(TR_Memory::JSR292)120121void dumpTo(TR_FrontEnd *fe, TR::FILE *file);122123private:124125Node *root() { return &_nodes[0]; }126TR_J2IThunk *findThunkFromTerseSignature(char *terseSignature, TR_FrontEnd *frontend, bool isForCurrentRun);127};128129#endif130131132