-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathRuntime.hpp
455 lines (387 loc) · 15.8 KB
/
Runtime.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* 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
*******************************************************************************/
#ifndef RUNTIME_INCL
#define RUNTIME_INCL
#include <stdint.h>
#include "env/defines.h"
#include "env/jittypes.h"
#include "env/Processors.hpp"
#include "codegen/LinkageConventionsEnum.hpp"
namespace TR { class Compilation; }
void ia32CodeCacheParameters(int32_t *, void **, int32_t *, int32_t*);
void amd64CodeCacheParameters(int32_t *, void **, int32_t *, int32_t*);
void ppcCodeCacheParameters(int32_t *, void **, int32_t *, int32_t*);
void armCodeCacheParameters(int32_t *, void **, int32_t *, int32_t*);
void s390zLinux64CodeCacheParameters(int32_t *, void **, int32_t *, int32_t*);
uint32_t getPPCCacheLineSize();
extern void setDllSlip(char* codeStart,char* codeEnd,char* dllName, TR::Compilation *);
void initializeJitRuntimeHelperTable(char jvmpi);
// -----------------------------------------------------------------------------
enum TR_CCPreLoadedCode
{
#if !defined(TR_TARGET_S390)
TR_AllocPrefetch = 0,
#if defined(TR_TARGET_POWER)
TR_ObjAlloc,
TR_VariableLenArrayAlloc,
TR_ConstLenArrayAlloc,
TR_writeBarrier,
TR_writeBarrierAndCardMark,
TR_cardMark,
TR_arrayStoreCHK,
#endif // TR_TARGET_POWER
TR_NonZeroAllocPrefetch,
#endif // !defined(TR_TARGET_S390)
TR_numCCPreLoadedCode
};
///////////////////////////////////////////
// TR_LinkageInfo
//
// Non-instantiable Abstract Class
// Cannot have any virtual methods in here
//
///////////////////////////////////////////
class TR_LinkageInfo
{
public:
static TR_LinkageInfo *get(void *startPC) { return (TR_LinkageInfo*)(((uint32_t*)startPC)-1); }
void setCountingMethodBody() { _word |= CountingPrologue; }
void setSamplingMethodBody() { _word |= SamplingPrologue; }
void setHasBeenRecompiled();
void setHasFailedRecompilation();
void setIsBeingRecompiled() { _word |= IsBeingRecompiled; }
void resetIsBeingRecompiled() { _word &= ~IsBeingRecompiled; }
bool isCountingMethodBody() { return (_word & CountingPrologue) != 0; }
bool isSamplingMethodBody() { return (_word & SamplingPrologue) != 0; }
bool isRecompMethodBody() { return (_word & (SamplingPrologue | CountingPrologue)) != 0; }
bool hasBeenRecompiled() { return (_word & HasBeenRecompiled) != 0; }
bool hasFailedRecompilation() { return (_word & HasFailedRecompilation) != 0; }
bool recompilationAttempted() { return hasBeenRecompiled() || hasFailedRecompilation(); }
bool isBeingCompiled() { return (_word & IsBeingRecompiled) != 0; }
inline uint16_t getReservedWord() { return (_word & ReservedMask) >> 16; }
inline void setReservedWord(uint16_t w) { _word |= ((w << 16) & ReservedMask); }
int32_t getJitEntryOffset()
{
#if defined(TR_TARGET_X86) && defined(TR_TARGET_32BIT)
return 0;
#else
return getReservedWord();
#endif
}
enum
{
ReturnInfoMask = 0x0000000F, // bottom 4 bits
// The VM depends on these four bits - word to the wise: don't mess
SamplingPrologue = 0x00000010,
CountingPrologue = 0x00000020,
// NOTE: flags have to be set under the compilation monitor or during compilation process
HasBeenRecompiled = 0x00000040,
HasFailedRecompilation = 0x00000100,
IsBeingRecompiled = 0x00000200,
// RESERVED:
// non-ia32: 0xffff0000 <---- jitEntryOffset
// ia32: 0xffff0000 <---- Recomp/FSD save area
ReservedMask = 0xFFFF0000
};
uint32_t _word;
private:
TR_LinkageInfo() {};
};
/**
* Runtime Helper Table.
*
* \note the value of these enumerators are used to index into
* trampolines
*/
enum TR_RuntimeHelper
{
#define SETVAL(A,G) A = (G),
#include "runtime/Helpers.inc"
#undef SETVAL
#if defined(TR_HOST_X86)
#if defined(TR_HOST_64BIT)
TR_numRuntimeHelpers = TR_AMD64numRuntimeHelpers
#else
TR_numRuntimeHelpers = TR_IA32numRuntimeHelpers
#endif
#elif defined(TR_HOST_POWER)
TR_numRuntimeHelpers = TR_PPCnumRuntimeHelpers
#elif defined(TR_HOST_ARM)
TR_numRuntimeHelpers = TR_ARMnumRuntimeHelpers
#elif defined(TR_HOST_ARM64)
TR_numRuntimeHelpers = TR_ARM64numRuntimeHelpers
#elif defined(TR_HOST_S390)
TR_numRuntimeHelpers = TR_S390numRuntimeHelpers
#elif defined(TR_HOST_RISCV)
TR_numRuntimeHelpers = TR_RISCVnumRuntimeHelpers
#endif
};
class TR_RuntimeHelperTable
{
public:
static const intptrj_t INVALID_FUNCTION_POINTER = 0xdeadb00f;
/**
* \brief
*
* Looks up the given helper table and returns the function pointer if it's a function index.
* For constant number entries, return INVALID_FUNCTION_POINTER.
*/
void* getFunctionPointer(TR_RuntimeHelper h);
/**
* \brief
*
* For helper functions, this API returns the raw entry address. If the runtime
* helper's corresponding linkage is not a function, return the helper as data.
*
*/
void* getFunctionEntryPointOrConst(TR_RuntimeHelper h);
/**
* \brief
*
* Returns the linkage type of the given helper index. The linkage types are set during
* the JIT initilization phase.
*/
TR_LinkageConventions getLinkage(TR_RuntimeHelper h)
{
return h < TR_numRuntimeHelpers ? _linkage[h] : TR_None;
}
/**
* \brief
*
* Sets the address and linkage convention.
*
* Linkage convention is essential when calling a helper
* For example, on X86, there are private linkage, System V ABI, fastcall, cdecl, etc.
*/
void setAddress(TR_RuntimeHelper h, void * a, TR_LinkageConventions lc = TR_Helper)
{
_helpers[h] = a;
_linkage[h] = lc;
}
/**
* \brief
*
* Stores the given pointer as a helper constant.
*/
void setConstant(TR_RuntimeHelper h, void * a)
{
_helpers[h] = a;
_linkage[h] = TR_None;
}
private:
/**
* \brief
* Translate address is to allow converting a C function pointer
* to an address callable by assembly.
*/
void* translateAddress(void* a);
void* _helpers[TR_numRuntimeHelpers];
TR_LinkageConventions _linkage[TR_numRuntimeHelpers];
};
extern TR_RuntimeHelperTable runtimeHelpers;
/**
* \brief
* Returns the value to which the runtime helper index corresponds to.
* The values stored in the helper table are either entry point addresses or constant values, depending on the
* linkage type.
*/
inline void* runtimeHelperValue(TR_RuntimeHelper h) { return runtimeHelpers.getFunctionEntryPointOrConst(h); }
inline TR_LinkageConventions runtimeHelperLinkage(TR_RuntimeHelper h) { return runtimeHelpers.getLinkage(h); }
// -----------------------------------------------------------------------------
#define RELOCATION_TYPE_DESCRIPTION_MASK 15
#define RELOCATION_TYPE_ORDERED_PAIR 32
#define RELOCATION_TYPE_EIP_OFFSET 0x40
#define RELOCATION_TYPE_WIDE_OFFSET 0x80
#define RELOCATION_CROSS_PLATFORM_FLAGS_MASK (RELOCATION_TYPE_EIP_OFFSET | RELOCATION_TYPE_WIDE_OFFSET)
#define RELOCATION_RELOC_FLAGS_MASK (~RELOCATION_CROSS_PLATFORM_FLAGS_MASK)
#define RELOCATION_TYPE_ARRAY_COPY_SUBTYPE 32
#define RELOCATION_TYPE_ARRAY_COPY_TOC 64
// These macros are intended for use when HI_VALUE and LO_VALUE will be recombined after LO_VALUE is sign-extended
// (e.g. when LO_VALUE is used with an instruction that takes a signed 16-bit operand).
// In this case we have to adjust HI_VALUE now so that the original value will be obtained once the two are recombined.
#define HI_VALUE(x) (((x)>>16) + (((x)>>15)&1))
#define LO_VALUE(x) ((int16_t)(x))
/*
* WARNING: If you add a new relocation type, then you need to handle it
* in OMR::AheadOfTimeCompile::dumpRelocationData in OMRAheadOfTimeCompile.cpp
* You also need to a corresponding string to
* _externalRelocationTargetKindNames[TR_NumExternalRelocationKinds]
*/
/*
* Define some internal temporary types for use during compilation which will get converted to actual relocation types later on
* (purposely all capital to differentiate from actual relo types and larger than actual relocation type so we catch any incorrect
* use that treats the temp type as actual relocation type)
*/
enum
{
TR_HEAP_BASE = 100,
TR_HEAP_TOP = 101,
TR_HEAP_BASE_FOR_BARRIER_RANGE = 102,
TR_ACTIVE_CARD_TABLE_BASE = 103,
TR_HEAP_SIZE_FOR_BARRIER_RANGE = 104
};
/* actual relocation types */
typedef enum
{
TR_NoRelocation = -1,
TR_ConstantPool = 0,
TR_HelperAddress = 1,
TR_RelativeMethodAddress = 2,
TR_AbsoluteMethodAddress = 3,
TR_DataAddress = 4,
TR_ClassObject = 5,
TR_MethodObject = 6,
TR_InterfaceObject = 7,
TR_AbsoluteHelperAddress = 8,
TR_FixedSequenceAddress = 9,
TR_FixedSequenceAddress2 = 10,
TR_JNIVirtualTargetAddress = 11,
TR_JNIStaticTargetAddress = 12,
TR_ArrayCopyHelper = 13,
TR_ArrayCopyToc = 14,
TR_BodyInfoAddress = 15,
TR_Thunks = 16,
TR_StaticRamMethodConst = 17,
TR_Trampolines = 18,
TR_PicTrampolines = 19,
TR_CheckMethodEnter = 20,
TR_RamMethod = 21,
TR_RamMethodSequence = 22,
TR_RamMethodSequenceReg = 23,
TR_VerifyClassObjectForAlloc = 24,
TR_ConstantPoolOrderedPair = 25,
TR_AbsoluteMethodAddressOrderedPair = 26,
TR_VerifyRefArrayForAlloc = 27,
TR_J2IThunks = 28,
TR_GlobalValue = 29,
TR_BodyInfoAddressLoad = 30,
TR_ValidateInstanceField = 31,
TR_InlinedStaticMethodWithNopGuard = 32,
TR_InlinedSpecialMethodWithNopGuard = 33,
TR_InlinedVirtualMethodWithNopGuard = 34,
TR_InlinedInterfaceMethodWithNopGuard = 35,
TR_SpecialRamMethodConst = 36,
TR_InlinedHCRMethod = 37,
TR_ValidateStaticField = 38,
TR_ValidateClass = 39,
TR_ClassAddress = 40,
TR_HCR = 41,
TR_ProfiledMethodGuardRelocation = 42,
TR_ProfiledClassGuardRelocation = 43,
TR_HierarchyGuardRelocation = 44,
TR_AbstractGuardRelocation = 45,
TR_ProfiledInlinedMethodRelocation = 46,
TR_MethodPointer = 47,
TR_ClassPointer = 48,
TR_CheckMethodExit = 49,
TR_ValidateArbitraryClass = 50,
TR_EmitClass = 51,
TR_JNISpecialTargetAddress = 52,
TR_VirtualRamMethodConst = 53,
TR_InlinedInterfaceMethod = 54,
TR_InlinedVirtualMethod = 55,
TR_NativeMethodAbsolute = 56,
TR_NativeMethodRelative = 57,
TR_ArbitraryClassAddress = 58,
TR_DebugCounter = 59,
TR_ClassUnloadAssumption = 60, // this should not be used in AOT relocations
TR_J2IVirtualThunkPointer = 61,
TR_InlinedAbstractMethodWithNopGuard = 62,
TR_ValidateRootClass = 63,
TR_ValidateClassByName = 64,
TR_ValidateProfiledClass = 65,
TR_ValidateClassFromCP = 66,
TR_ValidateDefiningClassFromCP = 67,
TR_ValidateStaticClassFromCP = 68,
TR_ValidateClassFromMethod = 69,
TR_ValidateComponentClassFromArrayClass= 70,
TR_ValidateArrayClassFromComponentClass= 71,
TR_ValidateSuperClassFromClass = 72,
TR_ValidateClassInstanceOfClass = 73,
TR_ValidateSystemClassByName = 74,
TR_ValidateClassFromITableIndexCP = 75,
TR_ValidateDeclaringClassFromFieldOrStatic=76,
TR_ValidateClassClass = 77,
TR_ValidateConcreteSubClassFromClass = 78,
TR_ValidateClassChain = 79,
TR_ValidateRomClass = 80,
TR_ValidatePrimitiveClass = 81,
TR_ValidateMethodFromInlinedSite = 82,
TR_ValidateMethodByName = 83,
TR_ValidateMethodFromClass = 84,
TR_ValidateStaticMethodFromCP = 85,
TR_ValidateSpecialMethodFromCP = 86,
TR_ValidateVirtualMethodFromCP = 87,
TR_ValidateVirtualMethodFromOffset = 88,
TR_ValidateInterfaceMethodFromCP = 89,
TR_ValidateMethodFromClassAndSig = 90,
TR_ValidateStackWalkerMaySkipFramesRecord=91,
TR_ValidateArrayClassFromJavaVM = 92,
TR_ValidateClassInfoIsInitialized = 93,
TR_ValidateMethodFromSingleImplementer = 94,
TR_ValidateMethodFromSingleInterfaceImplementer = 95,
TR_ValidateMethodFromSingleAbstractImplementer = 96,
TR_ValidateImproperInterfaceMethodFromCP=97,
TR_SymbolFromManager = 98,
TR_MethodCallAddress = 99,
TR_DiscontiguousSymbolFromManager = 100,
TR_ResolvedTrampolines = 101,
TR_NumExternalRelocationKinds = 102,
TR_ExternalRelocationTargetKindMask = 0xff,
} TR_ExternalRelocationTargetKind;
namespace TR {
enum SymbolType
{
typeOpaque,
typeClass,
typeMethod,
};
}
typedef struct TR_RelocationRecordInformation {
uintptr_t data1;
uintptr_t data2;
uintptr_t data3;
uintptr_t data4;
uintptr_t data5;
} TR_RelocationRecordInformation;
typedef enum
{
orderedPairSequence1 = 1,
orderedPairSequence2 = 2
} TR_OrderedPairSequenceKind;
typedef enum
{
fixedSequence1 = 1,
fixedSequence2 = 2,
fixedSequence3 = 3,
fixedSequence4 = 4,
fixedSequence5 = 5,
fixedSequence6 = 6
} TR_FixedSequenceKind;
// Multi Code Cache Routine for S390 for checking whether an entry point is within reach of a RIL instruction.
// In RIL instruction, the relative address is specified in number of half words.
#define CHECK_32BIT_TRAMPOLINE_RANGE(x,rip) (((intptrj_t)(x) == (intptrj_t)(rip) + ((intptrj_t)((int32_t)(((intptrj_t)(x) - (intptrj_t)(rip))/2)))*2) && (x % 2 == 0))
// Routine to check trampoline range for x86-64
#define IS_32BIT_RIP_JUMP(x,rip) ((intptrj_t)(x) == (intptrj_t)(rip) + (int32_t)((intptrj_t)(x) - (intptrj_t)(rip)))
// Branch limit for PPC and ARM ARM64
#define BRANCH_FORWARD_LIMIT (0x01fffffc)
#define BRANCH_BACKWARD_LIMIT ((int32_t)0xfe000000)
#endif