Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/compiler/ras/kca_offsets_generator.cpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 2000, 2020 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
/*
24
* This file is used to write a header file that can be used with KCA so
25
* that it knows the offset information required to correctly work with this
26
* JVM.
27
*
28
* How to modify:
29
*
30
* If a field has been removed - Set the "#define" to be 0, KCA will have to
31
* be modified so that it does not use that offset for the particular release
32
* but the #define has to be in the generated file!
33
*
34
* In general, the output header file from this code must generate the same
35
* number of "#define" lines using the same names in all JIT releases.
36
*/
37
38
#include "j9.h"
39
#include "j9cfg.h"
40
#include "control/Options.hpp"
41
#include "control/OptionsUtil.hpp"
42
#include "control/Options_inlines.hpp"
43
#include "control/Recompilation.hpp"
44
#include "control/RecompilationInfo.hpp"
45
#include "env/PersistentInfo.hpp"
46
#include "omrformatconsts.h"
47
#include <stdio.h>
48
49
50
char *
51
J9::Options::kcaOffsets(char *option, void *, TR::OptionTable *entry)
52
{
53
char szFileName[40];
54
char szCMPRSS[8];
55
char szRT[4];
56
57
#if defined(OMR_GC_COMPRESSED_POINTERS)
58
strcpy( szCMPRSS, "_CMPRSS" );
59
#else
60
szCMPRSS[0]='\0';
61
#endif
62
63
szRT[0]='\0';
64
65
// The generated file looks like this: kca_offsets_gen_R#_#[_CMPRSS][_RT].h
66
sprintf( szFileName, "kca_offsets_gen_R%d_%d%s%s.h", EsVersionMajor, EsVersionMinor, szCMPRSS, szRT );
67
TR_ASSERT( strlen(szFileName)<40, "szFileName array needs to be increased" );
68
69
auto file = fopen( szFileName, "wt" );
70
if( file )
71
{
72
fprintf( file, "/*Automatically Generated Header*/\n\n" );
73
fprintf( file, "/*File name: %s*/\n\n", szFileName );
74
75
fprintf( file, "#define J9METHOD_BYTECODES (%" OMR_PRIuSIZE ")\n", offsetof(J9Method,bytecodes) );
76
fprintf( file, "#define J9METHOD_CONSTANTPOOL (%" OMR_PRIuSIZE ")\n", offsetof(J9Method,constantPool) );
77
fprintf( file, "#define J9METHOD_EXTRA (%" OMR_PRIuSIZE ")\n", offsetof(J9Method,extra) );
78
79
fprintf( file, "#define J9CLASSLOADER_OBJ (%" OMR_PRIuSIZE ")\n", offsetof(J9ClassLoader,classLoaderObject) );
80
81
// There should be a better way to do this???
82
#if EsVersionMajor == 2 && EsVersionMinor <= 30
83
fprintf( file, "#define CONSTANTPOOL_ALIGNMENT (8)\n" );
84
#else
85
fprintf( file, "#define CONSTANTPOOL_ALIGNMENT (16)\n" );
86
#endif
87
88
89
fprintf( file, "#define J9OBJECT_J9CLASS (%" OMR_PRIuSIZE ")\n", offsetof(J9IndexableObjectContiguous,clazz) );
90
#if !defined(J9VM_INTERP_FLAGS_IN_CLASS_SLOT)
91
fprintf( file, "#define J9OBJECT_FLAGS (%" OMR_PRIuSIZE ")\n", offsetof(J9IndexableObjectContiguous,flags) );
92
#else
93
fprintf( file, "#define J9OBJECT_FLAGS (0) // Does not exist!\n" );
94
#endif
95
fprintf( file, "#define J9OBJECT_MONITOR (0) // Does not exist!\n" );
96
fprintf( file, "#define J9OBJECT_ARRAY_SIZE (%" OMR_PRIuSIZE ")\n", offsetof(J9IndexableObjectContiguous,size) );
97
98
fprintf( file, "#define METADATA_CLASSNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,className) );
99
fprintf( file, "#define METADATA_METHODNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,methodName) );
100
fprintf( file, "#define METADATA_SIGNATURE (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,methodSignature) );
101
fprintf( file, "#define METADATA_CONSTANTPOOL (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,constantPool) );
102
fprintf( file, "#define METADATA_J9METHOD (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,ramMethod) );
103
fprintf( file, "#define METADATA_STARTPC (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,startPC) );
104
fprintf( file, "#define METADATA_ENDWARMPC (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,endWarmPC) );
105
fprintf( file, "#define METADATA_COLDSTART (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,startColdPC) );
106
fprintf( file, "#define METADATA_COLDEND (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,endPC) );
107
fprintf( file, "#define METADATA_FRAMESIZE (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,totalFrameSize) );
108
fprintf( file, "#define METADATA_NUM_EXC_RANGES (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,numExcptionRanges) );
109
fprintf( file, "#define METADATA_INLINEDCALLS (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,inlinedCalls) );
110
fprintf( file, "#define METADATA_BODYINFO (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,bodyInfo) );
111
fprintf( file, "#define METADATA_SIZE (%" OMR_PRIuSIZE ")\n", sizeof(J9JITExceptionTable) );
112
113
fprintf( file, "#define J9CLASS_J9ROMCLASS (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,romClass) );
114
fprintf( file, "#define J9CLASS_SUPERCLASSES (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,superclasses) );
115
fprintf( file, "#define J9CLASS_CLASSDEPTHANDFLAGS (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,classDepthAndFlags) );
116
fprintf( file, "#define J9CLASS_CLASSLOADER (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,classLoader) );
117
#if EsVersionMajor == 2 && EsVersionMinor <= 30
118
fprintf( file, "#define J9CLASS_CLASSOBJECT (0)\n" ); // Not used by KCA for 22/23
119
#else
120
fprintf( file, "#define J9CLASS_CLASSOBJECT (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,classObject) );
121
#endif
122
fprintf( file, "#define J9CLASS_J9METHODS (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,ramMethods) );
123
fprintf( file, "#define J9CLASS_INSTANCESIZE (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,totalInstanceSize) );
124
fprintf( file, "#define J9CLASS_SUBCLASSLINK (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,subclassTraversalLink) );
125
fprintf( file, "#define J9CLASS_ITABLE (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,iTable) );
126
fprintf( file, "#define J9CLASS_VFT (%" OMR_PRIuSIZE ")\n", sizeof(J9Class) );
127
fprintf( file, "#define J9CLASS_LOCKOFFSET (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,lockOffset) );
128
129
fprintf( file, "#define J9ARRAYCLASS_ARRAYTYPE (%" OMR_PRIuSIZE ")\n", offsetof(J9ArrayClass,arrayClass) );
130
fprintf( file, "#define J9ARRAYCLASS_COMPTYPE (%" OMR_PRIuSIZE ")\n", offsetof(J9ArrayClass,componentType) );
131
132
fprintf( file, "#define J9ROMCLASS_CLASSNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,className) );
133
fprintf( file, "#define J9ROMCLASS_SUPERCLASSNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,superclassName) );
134
fprintf( file, "#define J9ROMCLASS_MODIFIERS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,modifiers) );
135
fprintf( file, "#define J9ROMCLASS_ROMMETHODCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romMethodCount) );
136
fprintf( file, "#define J9ROMCLASS_ROMMETHODS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romMethods) );
137
fprintf( file, "#define J9ROMCLASS_ROMFIELDCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romFieldCount) );
138
fprintf( file, "#define J9ROMCLASS_ROMFIELDS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romFields) );
139
fprintf( file, "#define J9ROMCLASS_RAMCPCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,ramConstantPoolCount) );
140
fprintf( file, "#define J9ROMCLASS_ROMCPCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romConstantPoolCount) );
141
142
fprintf( file, "#define J9ROMMETHOD_NAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,nameAndSignature) + offsetof(J9ROMNameAndSignature,name) );
143
fprintf( file, "#define J9ROMMETHOD_SIGNATURE (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,nameAndSignature) + offsetof(J9ROMNameAndSignature,signature) );
144
fprintf( file, "#define J9ROMMETHOD_MODIFIERS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,modifiers) );
145
#if EsVersionMajor == 2 && EsVersionMinor <= 30
146
fprintf( file, "#define J9ROMMETHOD_BC_SIZELOW (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSlots) );
147
fprintf( file, "#define J9ROMMETHOD_BC_SIZEHIGH (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSlotsHigh) );
148
#else
149
fprintf( file, "#define J9ROMMETHOD_BC_SIZELOW (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSizeLow) );
150
fprintf( file, "#define J9ROMMETHOD_BC_SIZEHIGH (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSizeHigh) );
151
#endif
152
fprintf( file, "#define J9ROMMETHOD_MAXSTACK (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,maxStack) );
153
fprintf( file, "#define J9ROMMETHOD_ARGCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,argCount) );
154
155
fprintf( file, "#define J9ROMFIELDSHAPE_NAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMFieldShape,nameAndSignature) + offsetof(J9ROMNameAndSignature,name) );
156
fprintf( file, "#define J9ROMFIELDSHAPE_SIGNATURE (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMFieldShape,nameAndSignature) + offsetof(J9ROMNameAndSignature,signature) );
157
fprintf( file, "#define J9ROMFIELDSHAPE_MODIFIERS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMFieldShape,modifiers) );
158
fprintf( file, "#define J9ROMFIELDSHAPE_VALUE (%" OMR_PRIuSIZE ")\n", sizeof(J9ROMFieldShape) );
159
160
fprintf( file, "#define J9METHOD_SIZE (%" OMR_PRIuSIZE ")\n", sizeof(J9Method) );
161
fprintf( file, "#define BYTECODES_J9ROMMETHOD (-%" OMR_PRIdSIZE ")\n", sizeof(J9ROMMethod) );
162
163
fprintf( file, "#define J9VMRAS_VM (%" OMR_PRIuSIZE ")\n", offsetof(J9RAS,vm) );
164
fprintf( file, "#define J9VMRAS_CRASHINFO (%" OMR_PRIuSIZE ")\n", offsetof(J9RAS,crashInfo) );
165
166
fprintf( file, "#define CRASHINFO_FAILINGTHREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9RASCrashInfo,failingThread) );
167
fprintf( file, "#define CRASHINFO_GPINFO (%" OMR_PRIuSIZE ")\n", offsetof(J9RASCrashInfo,gpInfo) );
168
169
fprintf( file, "#define VM_MAIN_THREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,mainThread) );
170
fprintf( file, "#define VM_JITCONFIG (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,jitConfig) );
171
fprintf( file, "#define VM_BOOLARRAYCLASS (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,booleanArrayClass) );
172
fprintf( file, "#define VM_CMPRSS_DISPLACEMENT (%" OMR_PRIuSIZE ")\n", (size_t)0 );
173
#if defined(OMR_GC_COMPRESSED_POINTERS)
174
fprintf( file, "#define VM_CMPRSS_SHIFT (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,compressedPointersShift) );
175
#else
176
fprintf( file, "#define VM_CMPRSS_SHIFT (%" OMR_PRIuSIZE ")\n", (size_t)0 );
177
#endif
178
179
fprintf( file, "#define JITCONFIG_JITARTIFACTS (%" OMR_PRIuSIZE ")\n", offsetof(J9JITConfig,translationArtifacts) );
180
fprintf( file, "#define JITCONFIG_COMPILING (%" OMR_PRIuSIZE ")\n", (size_t)0 );
181
fprintf( file, "#define JITCONFIG_PSEUDOTOC (%" OMR_PRIuSIZE ")\n", offsetof(J9JITConfig,pseudoTOC) );
182
183
fprintf( file, "#define J9AVLTREE_ROOTNODE (%" OMR_PRIuSIZE ")\n", offsetof(J9AVLTree,rootNode) );
184
185
fprintf( file, "#define J9VMTHREAD_COMPILING (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,jitMethodToBeCompiled) );
186
fprintf( file, "#define J9VMTHREAD_VM (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,javaVM) );
187
fprintf( file, "#define J9VMTHREAD_ARG0EA (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,arg0EA) );
188
fprintf( file, "#define J9VMTHREAD_BYTECODES (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,bytecodes) );
189
fprintf( file, "#define J9VMTHREAD_SP (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,sp) );
190
fprintf( file, "#define J9VMTHREAD_PC (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,pc) );
191
fprintf( file, "#define J9VMTHREAD_LITERALS (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,literals) );
192
fprintf( file, "#define J9VMTHREAD_SOF_MARK (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,stackOverflowMark) );
193
#if defined(J9VM_GC_THREAD_LOCAL_HEAP)
194
fprintf( file, "#define J9VMTHREAD_HEAP_ALLOC (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,heapAlloc) );
195
#else
196
fprintf( file, "#define J9VMTHREAD_HEAP_ALLOC (%" OMR_PRIuSIZE ")\n", (size_t)0 ); // The RealTime JVM does not have this field
197
#endif
198
fprintf( file, "#define J9VMTHREAD_THREADOBJ (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,threadObject) );
199
fprintf( file, "#define J9VMTHREAD_STACKOBJ (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,stackObject) );
200
fprintf( file, "#define J9VMTHREAD_OSTHREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,osThread) );
201
fprintf( file, "#define J9VMTHREAD_CUR_EXCEPTION (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,currentException) );
202
fprintf( file, "#define J9VMTHREAD_NEXT_THREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,linkNext) );
203
fprintf( file, "#define J9VMTHREAD_ELS (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,entryLocalStorage) );
204
205
fprintf( file, "#define OSTHREAD_TID (%" OMR_PRIuSIZE ")\n", offsetof(J9AbstractThread,tid) );
206
207
fprintf( file, "#define J9JITSTACKATLAS_MAPBYTES (%" OMR_PRIuSIZE ")\n", offsetof(J9JITStackAtlas,numberOfMapBytes) );
208
fprintf( file, "#define BODYINFO_HOTNESS (%" OMR_PRIuSIZE ")\n", offsetof(TR_PersistentJittedBodyInfo,_hotness) );
209
fprintf( file, "#define PERSISTENTINFO_CHTABLE (%" OMR_PRIuSIZE ")\n", offsetof(TR::PersistentInfo,_persistentCHTable) );
210
fprintf( file, "#define PERSISTENTCLASS_VISITED (%" OMR_PRIuSIZE ")\n", offsetof(TR_PersistentClassInfo,_visitedStatus) );
211
212
fprintf( file, "#define ELS_OLDELS (%" OMR_PRIuSIZE ")\n", offsetof(J9VMEntryLocalStorage,oldEntryLocalStorage) );
213
fprintf( file, "#define ELS_I2JSTATE (%" OMR_PRIuSIZE ")\n", offsetof(J9VMEntryLocalStorage,i2jState) );
214
215
fprintf( file, "#define I2JSTATE_RETURNSP (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,returnSP) );
216
fprintf( file, "#define I2JSTATE_A0 (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,a0) );
217
fprintf( file, "#define I2JSTATE_J9METHOD (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,literals) );
218
fprintf( file, "#define I2JSTATE_RETURNPC (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,pc) );
219
220
fprintf( file, "#define J9SFJ2IFRAME_RETURNADDR (%" OMR_PRIuSIZE ")\n", offsetof(J9SFJ2IFrame,returnAddress) );
221
fprintf( file, "#define J9SFJ2IFRAME_RETURNSP (%" OMR_PRIuSIZE ")\n", offsetof(J9SFJ2IFrame,taggedReturnSP) );
222
223
fclose(file);
224
}
225
return option;
226
}
227
228