Path: blob/master/runtime/bcutil/ROMClassBuilder.hpp
5985 views
/*******************************************************************************1* Copyright (c) 2001, 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/*23* ROMClassBuilder.hpp24*25*/2627#ifndef ROMCLASSBUILDER_HPP_28#define ROMCLASSBUILDER_HPP_2930/* @ddr_namespace: default */31#include "j9comp.h"32#include "j9.h"33#include "j2sever.h"3435#include "BuildResult.hpp"36#include "ClassFileParser.hpp" /* included to obtain definition of VerifyClassFunction */37#include "StringInternTable.hpp"3839#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)40#define MAX_INTERFACE_INJECTION 141typedef struct InterfaceInjectionInfo {42J9UTF8 *interfaces[MAX_INTERFACE_INJECTION];43U_16 numOfInterfaces;44} InterfaceInjectionInfo;45#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */4647class BufferManager;48class ClassFileOracle;49class ConstantPoolMap;50class ROMClassCreationContext;51class ROMClassStringInternManager;52class ROMClassWriter;53class SRPOffsetTable;54class SRPKeyProducer;5556class ROMClassBuilder57{58public:59static ROMClassBuilder *getROMClassBuilder(J9PortLibrary *portLibrary, J9JavaVM *vm);6061ROMClassBuilder(J9JavaVM *javaVM, J9PortLibrary *portLibrary, UDATA maxStringInternTableSize, U_8 * verifyExcludeAttribute, VerifyClassFunction verifyClassFunction);62~ROMClassBuilder();6364bool isOK() { return _stringInternTable.isOK(); }6566/**67* Returns the current class file buffer - setting it to NULL in the ROMClassBuilder,68* thereby transferring its ownership to the caller. The caller is responsible for69* freeing the buffer using the port library.70*/71U_8 * releaseClassFileBuffer();7273BuildResult buildROMClass(ROMClassCreationContext *context);7475protected:76void *operator new(size_t size, void *memoryPtr) { return memoryPtr; };7778private:7980/*81* Cursor Tags are used to identify what82* type of data is being written.83* These values must be linear from 0 as the max84* is used inside SRPOffsetTable to create an array.85*/86enum CursorTag87{88// Generic/main ROMClass data89RC_TAG = 0,90/* The header structure J9MethodDebugInfo and91* the J9LineNumber table are stored in this section */92LINE_NUMBER_TAG = 1,93// J9VariableInfo Table94VARIABLE_INFO_TAG = 2,95// UTF8s section of the ROMClass96UTF8_TAG = 3,97// 'Original' or intermediate class file bytes98INTERMEDIATE_TAG = 4,99//100MAX_TAG = INTERMEDIATE_TAG101};102103/*104* A helper structure to pass around the predicted and105* updated size of various parts of the ROMClass.106*/107struct SizeInformation108{109UDATA rcWithOutUTF8sSize;110UDATA lineNumberSize;111UDATA variableInfoSize;112UDATA utf8sSize;113UDATA rawClassDataSize;114};115116/* NOTE: Be sure to update J9DbgROMClassBuilder in j9nonbuilder.h when changing the state variables below. */117J9JavaVM *_javaVM;118J9PortLibrary * _portLibrary;119U_8 * _verifyExcludeAttribute;120VerifyClassFunction _verifyClassFunction;121UDATA _classFileParserBufferSize;122UDATA _bufferManagerSize;123U_8 *_classFileBuffer;124U_8 *_anonClassNameBuffer;125UDATA _anonClassNameBufferSize;126U_8 *_bufferManagerBuffer;127StringInternTable _stringInternTable;128#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)129InterfaceInjectionInfo _interfaceInjectionInfo;130#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */131132BuildResult handleAnonClassName(J9CfrClassFile *classfile, bool *isLambda, ROMClassCreationContext *context);133#if defined(J9VM_OPT_VALHALLA_VALUE_TYPES)134BuildResult injectInterfaces(ClassFileOracle *classFileOracle);135#endif /* J9VM_OPT_VALHALLA_VALUE_TYPES */136U_32 computeExtraModifiers(ClassFileOracle *classFileOracle, ROMClassCreationContext *context);137U_32 computeOptionalFlags(ClassFileOracle *classFileOracle, ROMClassCreationContext *context);138BuildResult prepareAndLaydown( BufferManager *bufferManager, ClassFileParser *classFileParser, ROMClassCreationContext *context );139void checkDebugInfoCompression(J9ROMClass *romClass, ClassFileOracle classFileOracle, SRPKeyProducer *srpKeyProducer, ConstantPoolMap *constantPoolMap, SRPOffsetTable *srpOffsetTable);140U_32 finishPrepareAndLaydown(141U_8 *romClassBuffer,142U_8 *lineNumberBuffer,143U_8 *variableInfoBuffer,144SizeInformation *sizeInformation,145U_32 modifiers,146U_32 extraModifiers,147U_32 optionalFlags,148bool sharingROMClass,149bool hasStringTableLock,150ClassFileOracle *classFileOracle,151SRPOffsetTable *srpOffsetTable,152SRPKeyProducer *srpKeyProducer,153ROMClassWriter *romClassWriter,154ROMClassCreationContext *context,155ConstantPoolMap *constantPoolMap);156157void layDownROMClass(158ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, U_32 romSize, U_32 modifiers, U_32 extraModifiers, U_32 optionalFlags,159ROMClassStringInternManager *internManager, ROMClassCreationContext *context, SizeInformation *sizeInformation);160161bool compareROMClassForEquality(U_8 *romClass, bool romClassIsShared,162ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, SRPKeyProducer *srpKeyProducer, ClassFileOracle *classFileOracle,163U_32 modifiers, U_32 extraModifiers, U_32 optionalFlags, ROMClassCreationContext * context, U_32 sizeToCompareForLambda, bool isLambda);164SharedCacheRangeInfo getSharedCacheSRPRangeInfo(void *address);165void getSizeInfo(ROMClassCreationContext *context, ROMClassWriter *romClassWriter, SRPOffsetTable *srpOffsetTable, bool *countDebugDataOutOfLine, SizeInformation *sizeInformation);166};167168#endif /* ROMCLASSBUILDER_HPP_ */169170171