Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/env/J2IThunk.hpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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-exception
21
*******************************************************************************/
22
23
#ifndef TR_J2ITHUNK_INCL
24
#define TR_J2ITHUNK_INCL
25
26
#include "infra/Array.hpp"
27
#include "env/TRMemory.hpp"
28
#include "env/IO.hpp"
29
30
class TR_J2IThunkTable;
31
namespace TR { class CodeGenerator; }
32
namespace TR { class Monitor; }
33
34
class TR_J2IThunk
35
{
36
int16_t _totalSize;
37
int16_t _codeSize;
38
39
public:
40
41
static TR_J2IThunk *allocate(int16_t codeSize, char *signature, TR::CodeGenerator *cg, TR_J2IThunkTable *thunkTable);
42
43
static TR_J2IThunk *get(uint8_t *entryPoint)
44
{ return ((TR_J2IThunk*)entryPoint)-1; }
45
46
int16_t totalSize() { return _totalSize; }
47
int16_t codeSize() { return _codeSize; }
48
uint8_t *entryPoint() { return (uint8_t*)(this+1); }
49
char *terseSignature() { return (char*)(entryPoint() + codeSize()); }
50
};
51
52
class TR_J2IThunkTable
53
{
54
enum TypeChars
55
{
56
TC_VOID,
57
TC_INT,
58
TC_LONG,
59
TC_FLOAT,
60
TC_DOUBLE,
61
TC_REFERENCE,
62
63
NUM_TYPE_CHARS
64
};
65
66
static int32_t typeCharIndex(char typeChar)
67
{
68
switch (typeChar)
69
{
70
case 'V': return TC_VOID;
71
case 'I': return TC_INT;
72
case 'J': return TC_LONG;
73
case 'F': return TC_FLOAT;
74
case 'D': return TC_DOUBLE;
75
case 'L':
76
case 'Q': return TC_REFERENCE;
77
default:
78
TR_ASSERT(0, "Unknown type char '%c'", typeChar);
79
return -1;
80
}
81
}
82
83
struct Node
84
{
85
typedef int32_t ChildIndex; // sad -- how many nodes are there really going to be in this array? uint8_t would suffice for some workloads!
86
87
TR_J2IThunk *_thunk;
88
ChildIndex _children[NUM_TYPE_CHARS];
89
90
Node *get(char *terseSignature, TR_PersistentArray<Node> &nodeArray, bool createIfMissing);
91
92
void dumpTo(TR_FrontEnd *fe, TR::FILE *file, TR_PersistentArray<Node> &nodeArray, int indent);
93
};
94
95
private: // Fields
96
97
char *_name;
98
TR::Monitor *_monitor;
99
TR_PersistentArray<Node> _nodes;
100
101
public: // API
102
103
// FUN FACT: signature strings don't need to be null-terminated. This class
104
// can always tell where the end is from the Java signature string format,
105
// and does not rely on null-termination.
106
107
TR_J2IThunk *findThunk(char *signature, TR_FrontEnd *frontend, bool isForCurrentRun=false); // may return NULL
108
TR_J2IThunk *getThunk (char *signature, TR_FrontEnd *frontend, bool isForCurrentRun=false); // same as findThunk but asserts !NULL
109
110
// Note: the 'isForCurrentRun' flag is meant for AOT-aware code.
111
// If you don't know what this should be, you probably want to use its default value.
112
//
113
void addThunk(TR_J2IThunk *thunk, TR_FrontEnd *fe, bool isForCurrentRun=false);
114
115
char terseTypeChar(char *type);
116
int16_t terseSignatureLength(char *signature);
117
void getTerseSignature(char *buf, int16_t bufLength, char *signature);
118
119
TR_J2IThunkTable(TR_PersistentMemory *m, char *name);
120
TR_PERSISTENT_ALLOC(TR_Memory::JSR292)
121
122
void dumpTo(TR_FrontEnd *fe, TR::FILE *file);
123
124
private:
125
126
Node *root() { return &_nodes[0]; }
127
TR_J2IThunk *findThunkFromTerseSignature(char *terseSignature, TR_FrontEnd *frontend, bool isForCurrentRun);
128
};
129
130
#endif
131
132