Path: blob/master/runtime/compiler/ras/kca_offsets_generator.cpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2020 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/*23* This file is used to write a header file that can be used with KCA so24* that it knows the offset information required to correctly work with this25* JVM.26*27* How to modify:28*29* If a field has been removed - Set the "#define" to be 0, KCA will have to30* be modified so that it does not use that offset for the particular release31* but the #define has to be in the generated file!32*33* In general, the output header file from this code must generate the same34* number of "#define" lines using the same names in all JIT releases.35*/3637#include "j9.h"38#include "j9cfg.h"39#include "control/Options.hpp"40#include "control/OptionsUtil.hpp"41#include "control/Options_inlines.hpp"42#include "control/Recompilation.hpp"43#include "control/RecompilationInfo.hpp"44#include "env/PersistentInfo.hpp"45#include "omrformatconsts.h"46#include <stdio.h>474849char *50J9::Options::kcaOffsets(char *option, void *, TR::OptionTable *entry)51{52char szFileName[40];53char szCMPRSS[8];54char szRT[4];5556#if defined(OMR_GC_COMPRESSED_POINTERS)57strcpy( szCMPRSS, "_CMPRSS" );58#else59szCMPRSS[0]='\0';60#endif6162szRT[0]='\0';6364// The generated file looks like this: kca_offsets_gen_R#_#[_CMPRSS][_RT].h65sprintf( szFileName, "kca_offsets_gen_R%d_%d%s%s.h", EsVersionMajor, EsVersionMinor, szCMPRSS, szRT );66TR_ASSERT( strlen(szFileName)<40, "szFileName array needs to be increased" );6768auto file = fopen( szFileName, "wt" );69if( file )70{71fprintf( file, "/*Automatically Generated Header*/\n\n" );72fprintf( file, "/*File name: %s*/\n\n", szFileName );7374fprintf( file, "#define J9METHOD_BYTECODES (%" OMR_PRIuSIZE ")\n", offsetof(J9Method,bytecodes) );75fprintf( file, "#define J9METHOD_CONSTANTPOOL (%" OMR_PRIuSIZE ")\n", offsetof(J9Method,constantPool) );76fprintf( file, "#define J9METHOD_EXTRA (%" OMR_PRIuSIZE ")\n", offsetof(J9Method,extra) );7778fprintf( file, "#define J9CLASSLOADER_OBJ (%" OMR_PRIuSIZE ")\n", offsetof(J9ClassLoader,classLoaderObject) );7980// There should be a better way to do this???81#if EsVersionMajor == 2 && EsVersionMinor <= 3082fprintf( file, "#define CONSTANTPOOL_ALIGNMENT (8)\n" );83#else84fprintf( file, "#define CONSTANTPOOL_ALIGNMENT (16)\n" );85#endif868788fprintf( file, "#define J9OBJECT_J9CLASS (%" OMR_PRIuSIZE ")\n", offsetof(J9IndexableObjectContiguous,clazz) );89#if !defined(J9VM_INTERP_FLAGS_IN_CLASS_SLOT)90fprintf( file, "#define J9OBJECT_FLAGS (%" OMR_PRIuSIZE ")\n", offsetof(J9IndexableObjectContiguous,flags) );91#else92fprintf( file, "#define J9OBJECT_FLAGS (0) // Does not exist!\n" );93#endif94fprintf( file, "#define J9OBJECT_MONITOR (0) // Does not exist!\n" );95fprintf( file, "#define J9OBJECT_ARRAY_SIZE (%" OMR_PRIuSIZE ")\n", offsetof(J9IndexableObjectContiguous,size) );9697fprintf( file, "#define METADATA_CLASSNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,className) );98fprintf( file, "#define METADATA_METHODNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,methodName) );99fprintf( file, "#define METADATA_SIGNATURE (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,methodSignature) );100fprintf( file, "#define METADATA_CONSTANTPOOL (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,constantPool) );101fprintf( file, "#define METADATA_J9METHOD (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,ramMethod) );102fprintf( file, "#define METADATA_STARTPC (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,startPC) );103fprintf( file, "#define METADATA_ENDWARMPC (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,endWarmPC) );104fprintf( file, "#define METADATA_COLDSTART (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,startColdPC) );105fprintf( file, "#define METADATA_COLDEND (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,endPC) );106fprintf( file, "#define METADATA_FRAMESIZE (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,totalFrameSize) );107fprintf( file, "#define METADATA_NUM_EXC_RANGES (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,numExcptionRanges) );108fprintf( file, "#define METADATA_INLINEDCALLS (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,inlinedCalls) );109fprintf( file, "#define METADATA_BODYINFO (%" OMR_PRIuSIZE ")\n", offsetof(J9JITExceptionTable,bodyInfo) );110fprintf( file, "#define METADATA_SIZE (%" OMR_PRIuSIZE ")\n", sizeof(J9JITExceptionTable) );111112fprintf( file, "#define J9CLASS_J9ROMCLASS (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,romClass) );113fprintf( file, "#define J9CLASS_SUPERCLASSES (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,superclasses) );114fprintf( file, "#define J9CLASS_CLASSDEPTHANDFLAGS (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,classDepthAndFlags) );115fprintf( file, "#define J9CLASS_CLASSLOADER (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,classLoader) );116#if EsVersionMajor == 2 && EsVersionMinor <= 30117fprintf( file, "#define J9CLASS_CLASSOBJECT (0)\n" ); // Not used by KCA for 22/23118#else119fprintf( file, "#define J9CLASS_CLASSOBJECT (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,classObject) );120#endif121fprintf( file, "#define J9CLASS_J9METHODS (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,ramMethods) );122fprintf( file, "#define J9CLASS_INSTANCESIZE (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,totalInstanceSize) );123fprintf( file, "#define J9CLASS_SUBCLASSLINK (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,subclassTraversalLink) );124fprintf( file, "#define J9CLASS_ITABLE (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,iTable) );125fprintf( file, "#define J9CLASS_VFT (%" OMR_PRIuSIZE ")\n", sizeof(J9Class) );126fprintf( file, "#define J9CLASS_LOCKOFFSET (%" OMR_PRIuSIZE ")\n", offsetof(J9Class,lockOffset) );127128fprintf( file, "#define J9ARRAYCLASS_ARRAYTYPE (%" OMR_PRIuSIZE ")\n", offsetof(J9ArrayClass,arrayClass) );129fprintf( file, "#define J9ARRAYCLASS_COMPTYPE (%" OMR_PRIuSIZE ")\n", offsetof(J9ArrayClass,componentType) );130131fprintf( file, "#define J9ROMCLASS_CLASSNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,className) );132fprintf( file, "#define J9ROMCLASS_SUPERCLASSNAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,superclassName) );133fprintf( file, "#define J9ROMCLASS_MODIFIERS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,modifiers) );134fprintf( file, "#define J9ROMCLASS_ROMMETHODCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romMethodCount) );135fprintf( file, "#define J9ROMCLASS_ROMMETHODS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romMethods) );136fprintf( file, "#define J9ROMCLASS_ROMFIELDCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romFieldCount) );137fprintf( file, "#define J9ROMCLASS_ROMFIELDS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romFields) );138fprintf( file, "#define J9ROMCLASS_RAMCPCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,ramConstantPoolCount) );139fprintf( file, "#define J9ROMCLASS_ROMCPCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMClass,romConstantPoolCount) );140141fprintf( file, "#define J9ROMMETHOD_NAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,nameAndSignature) + offsetof(J9ROMNameAndSignature,name) );142fprintf( file, "#define J9ROMMETHOD_SIGNATURE (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,nameAndSignature) + offsetof(J9ROMNameAndSignature,signature) );143fprintf( file, "#define J9ROMMETHOD_MODIFIERS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,modifiers) );144#if EsVersionMajor == 2 && EsVersionMinor <= 30145fprintf( file, "#define J9ROMMETHOD_BC_SIZELOW (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSlots) );146fprintf( file, "#define J9ROMMETHOD_BC_SIZEHIGH (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSlotsHigh) );147#else148fprintf( file, "#define J9ROMMETHOD_BC_SIZELOW (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSizeLow) );149fprintf( file, "#define J9ROMMETHOD_BC_SIZEHIGH (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,bytecodeSizeHigh) );150#endif151fprintf( file, "#define J9ROMMETHOD_MAXSTACK (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,maxStack) );152fprintf( file, "#define J9ROMMETHOD_ARGCOUNT (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMMethod,argCount) );153154fprintf( file, "#define J9ROMFIELDSHAPE_NAME (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMFieldShape,nameAndSignature) + offsetof(J9ROMNameAndSignature,name) );155fprintf( file, "#define J9ROMFIELDSHAPE_SIGNATURE (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMFieldShape,nameAndSignature) + offsetof(J9ROMNameAndSignature,signature) );156fprintf( file, "#define J9ROMFIELDSHAPE_MODIFIERS (%" OMR_PRIuSIZE ")\n", offsetof(J9ROMFieldShape,modifiers) );157fprintf( file, "#define J9ROMFIELDSHAPE_VALUE (%" OMR_PRIuSIZE ")\n", sizeof(J9ROMFieldShape) );158159fprintf( file, "#define J9METHOD_SIZE (%" OMR_PRIuSIZE ")\n", sizeof(J9Method) );160fprintf( file, "#define BYTECODES_J9ROMMETHOD (-%" OMR_PRIdSIZE ")\n", sizeof(J9ROMMethod) );161162fprintf( file, "#define J9VMRAS_VM (%" OMR_PRIuSIZE ")\n", offsetof(J9RAS,vm) );163fprintf( file, "#define J9VMRAS_CRASHINFO (%" OMR_PRIuSIZE ")\n", offsetof(J9RAS,crashInfo) );164165fprintf( file, "#define CRASHINFO_FAILINGTHREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9RASCrashInfo,failingThread) );166fprintf( file, "#define CRASHINFO_GPINFO (%" OMR_PRIuSIZE ")\n", offsetof(J9RASCrashInfo,gpInfo) );167168fprintf( file, "#define VM_MAIN_THREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,mainThread) );169fprintf( file, "#define VM_JITCONFIG (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,jitConfig) );170fprintf( file, "#define VM_BOOLARRAYCLASS (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,booleanArrayClass) );171fprintf( file, "#define VM_CMPRSS_DISPLACEMENT (%" OMR_PRIuSIZE ")\n", (size_t)0 );172#if defined(OMR_GC_COMPRESSED_POINTERS)173fprintf( file, "#define VM_CMPRSS_SHIFT (%" OMR_PRIuSIZE ")\n", offsetof(J9JavaVM,compressedPointersShift) );174#else175fprintf( file, "#define VM_CMPRSS_SHIFT (%" OMR_PRIuSIZE ")\n", (size_t)0 );176#endif177178fprintf( file, "#define JITCONFIG_JITARTIFACTS (%" OMR_PRIuSIZE ")\n", offsetof(J9JITConfig,translationArtifacts) );179fprintf( file, "#define JITCONFIG_COMPILING (%" OMR_PRIuSIZE ")\n", (size_t)0 );180fprintf( file, "#define JITCONFIG_PSEUDOTOC (%" OMR_PRIuSIZE ")\n", offsetof(J9JITConfig,pseudoTOC) );181182fprintf( file, "#define J9AVLTREE_ROOTNODE (%" OMR_PRIuSIZE ")\n", offsetof(J9AVLTree,rootNode) );183184fprintf( file, "#define J9VMTHREAD_COMPILING (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,jitMethodToBeCompiled) );185fprintf( file, "#define J9VMTHREAD_VM (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,javaVM) );186fprintf( file, "#define J9VMTHREAD_ARG0EA (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,arg0EA) );187fprintf( file, "#define J9VMTHREAD_BYTECODES (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,bytecodes) );188fprintf( file, "#define J9VMTHREAD_SP (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,sp) );189fprintf( file, "#define J9VMTHREAD_PC (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,pc) );190fprintf( file, "#define J9VMTHREAD_LITERALS (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,literals) );191fprintf( file, "#define J9VMTHREAD_SOF_MARK (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,stackOverflowMark) );192#if defined(J9VM_GC_THREAD_LOCAL_HEAP)193fprintf( file, "#define J9VMTHREAD_HEAP_ALLOC (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,heapAlloc) );194#else195fprintf( file, "#define J9VMTHREAD_HEAP_ALLOC (%" OMR_PRIuSIZE ")\n", (size_t)0 ); // The RealTime JVM does not have this field196#endif197fprintf( file, "#define J9VMTHREAD_THREADOBJ (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,threadObject) );198fprintf( file, "#define J9VMTHREAD_STACKOBJ (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,stackObject) );199fprintf( file, "#define J9VMTHREAD_OSTHREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,osThread) );200fprintf( file, "#define J9VMTHREAD_CUR_EXCEPTION (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,currentException) );201fprintf( file, "#define J9VMTHREAD_NEXT_THREAD (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,linkNext) );202fprintf( file, "#define J9VMTHREAD_ELS (%" OMR_PRIuSIZE ")\n", offsetof(J9VMThread,entryLocalStorage) );203204fprintf( file, "#define OSTHREAD_TID (%" OMR_PRIuSIZE ")\n", offsetof(J9AbstractThread,tid) );205206fprintf( file, "#define J9JITSTACKATLAS_MAPBYTES (%" OMR_PRIuSIZE ")\n", offsetof(J9JITStackAtlas,numberOfMapBytes) );207fprintf( file, "#define BODYINFO_HOTNESS (%" OMR_PRIuSIZE ")\n", offsetof(TR_PersistentJittedBodyInfo,_hotness) );208fprintf( file, "#define PERSISTENTINFO_CHTABLE (%" OMR_PRIuSIZE ")\n", offsetof(TR::PersistentInfo,_persistentCHTable) );209fprintf( file, "#define PERSISTENTCLASS_VISITED (%" OMR_PRIuSIZE ")\n", offsetof(TR_PersistentClassInfo,_visitedStatus) );210211fprintf( file, "#define ELS_OLDELS (%" OMR_PRIuSIZE ")\n", offsetof(J9VMEntryLocalStorage,oldEntryLocalStorage) );212fprintf( file, "#define ELS_I2JSTATE (%" OMR_PRIuSIZE ")\n", offsetof(J9VMEntryLocalStorage,i2jState) );213214fprintf( file, "#define I2JSTATE_RETURNSP (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,returnSP) );215fprintf( file, "#define I2JSTATE_A0 (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,a0) );216fprintf( file, "#define I2JSTATE_J9METHOD (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,literals) );217fprintf( file, "#define I2JSTATE_RETURNPC (%" OMR_PRIuSIZE ")\n", offsetof(J9I2JState,pc) );218219fprintf( file, "#define J9SFJ2IFRAME_RETURNADDR (%" OMR_PRIuSIZE ")\n", offsetof(J9SFJ2IFrame,returnAddress) );220fprintf( file, "#define J9SFJ2IFRAME_RETURNSP (%" OMR_PRIuSIZE ")\n", offsetof(J9SFJ2IFrame,taggedReturnSP) );221222fclose(file);223}224return option;225}226227228