Path: blob/master/runtime/compiler/env/J9ClassEnv.hpp
6000 views
/*******************************************************************************1* Copyright (c) 2000, 2022 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#ifndef J9_CLASSENV_INCL23#define J9_CLASSENV_INCL2425/*26* The following #define and typedef must appear before any #includes in this file27*/28#ifndef J9_CLASSENV_CONNECTOR29#define J9_CLASSENV_CONNECTOR30namespace J9 { class ClassEnv; }31namespace J9 { typedef J9::ClassEnv ClassEnvConnector; }32#endif3334#if defined(J9VM_OPT_JITSERVER)35#include <vector>36#endif /* defined(J9VM_OPT_JITSERVER) */37#include "env/jittypes.h"38#include "env/OMRClassEnv.hpp"39#include "infra/Annotations.hpp"40#include "j9.h"4142namespace TR { class SymbolReference; }43namespace TR { class TypeLayout; }44namespace TR { class Region; }45class TR_PersistentClassInfo;46template <typename ListKind> class List;4748namespace J949{5051class OMR_EXTENSIBLE ClassEnv : public OMR::ClassEnvConnector52{53public:5455TR::ClassEnv *self();5657bool classesOnHeap() { return true; }5859bool classObjectsMayBeCollected() { return false; }6061bool romClassObjectsMayBeCollected() { return false; }6263TR_OpaqueClassBlock *getClassFromJavaLangClass(uintptr_t objectPointer);6465J9Class *convertClassOffsetToClassPtr(TR_OpaqueClassBlock *clazzOffset);66TR_OpaqueClassBlock *convertClassPtrToClassOffset(J9Class *clazzPtr);6768uintptr_t classFlagsValue(TR_OpaqueClassBlock * classPointer);69uintptr_t classFlagReservableWordInitValue(TR_OpaqueClassBlock * classPointer);70uintptr_t classDepthOf(TR_OpaqueClassBlock *clazzPointer);71uintptr_t classInstanceSize(TR_OpaqueClassBlock * clazzPointer);7273J9ROMClass *romClassOf(TR_OpaqueClassBlock * clazz);74J9ROMClass *romClassOfSuperClass(TR_OpaqueClassBlock * clazz, size_t index);7576J9ITable *iTableOf(TR_OpaqueClassBlock * clazz);77J9ITable *iTableNext(J9ITable *current);78J9ROMClass *iTableRomClass(J9ITable *current);79#if defined(J9VM_OPT_JITSERVER)80std::vector<TR_OpaqueClassBlock *> getITable(TR_OpaqueClassBlock *clazz);81#endif /* defined(J9VM_OPT_JITSERVER) */8283J9Class **superClassesOf(TR_OpaqueClassBlock * clazz);8485bool isStringClass(TR_OpaqueClassBlock *clazz);8687bool classHasIllegalStaticFinalFieldModification(TR_OpaqueClassBlock * clazzPointer);88bool isAbstractClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazzPointer);89bool isInterfaceClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazzPointer);90bool isConcreteClass(TR::Compilation *comp, TR_OpaqueClassBlock * clazzPointer);91bool isValueTypeClass(TR_OpaqueClassBlock *);92bool isValueTypeClassFlattened(TR_OpaqueClassBlock *clazz);93bool isValueBasedOrValueTypeClass(TR_OpaqueClassBlock *);9495/** \brief96* Returns the size of the flattened array element97*98* \param comp99* The compilation object100*101* \param arrayClass102* The array class that is to be checked103*104* \return105* Size of the flattened array element106*/107int32_t flattenedArrayElementSize(TR::Compilation *comp, TR_OpaqueClassBlock *arrayClass);108109/** \brief110* Checks whether a class implements `IdentityObject`/`IdentityInterface`111*112* \param clazz113* The class that is to be checked114*115* \return116* `true` if the class implements `IdentityObject`/`IdentityInterface`;117* `false` otherwise (that is, if the class could be a value type,118* or some abstract class, interface, or java/lang/Object)119*/120bool classHasIdentity(TR_OpaqueClassBlock *clazz);121122/**123* \brief124* Checks whether instances of the specified class can be trivially initialized by125* "zeroing" their fields.126* In the case of OpenJ9, this tests whether any field is of a value type that has not been127* "flattened" (that is, had the value type's fields inlined into this class). Such a value128* type field must be initialized with the default value of the type.129*130* \param clazz131* The class that is to be checked132*133* \return134* `true` if instances of the specified class can be initialized by zeroing their fields;135* `false` otherwise (that is, if the class has value type fields whose fields have not136* been inlined)137*/138bool isZeroInitializable(TR_OpaqueClassBlock *clazz);139bool isEnumClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazzPointer, TR_ResolvedMethod *method);140bool isPrimitiveClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);141bool isAnonymousClass(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);142bool isPrimitiveArray(TR::Compilation *comp, TR_OpaqueClassBlock *);143bool isReferenceArray(TR::Compilation *comp, TR_OpaqueClassBlock *);144bool isClassArray(TR::Compilation *comp, TR_OpaqueClassBlock *);145bool isClassFinal(TR::Compilation *comp, TR_OpaqueClassBlock *);146bool hasFinalizer(TR::Compilation *comp, TR_OpaqueClassBlock *classPointer);147bool isClassInitialized(TR::Compilation *comp, TR_OpaqueClassBlock *);148bool hasFinalFieldsInClass(TR::Compilation *comp, TR_OpaqueClassBlock *classPointer);149bool sameClassLoaders(TR::Compilation *comp, TR_OpaqueClassBlock *, TR_OpaqueClassBlock *);150bool isString(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);151bool jitStaticsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2);152bool jitFieldsAreSame(TR::Compilation *comp, TR_ResolvedMethod * method1, int32_t cpIndex1, TR_ResolvedMethod * method2, int32_t cpIndex2, int32_t isStatic);153/*154* \brief155* Tells whether a class reference entry in the constant pool represents a value type class.156*157* \param cpContextClass158* The class whose constant pool contains the class reference entry being looked at. In another words,159* it's the class of the method referring to the class reference entry.160*161* \param cpIndex162* The constant pool index of the class reference entry.163*164* \note165* The class reference entry doesn't need to be resolved because the information is encoded in class name string166*/167bool isClassRefValueType(TR::Compilation *comp, TR_OpaqueClassBlock *cpContextClass, int32_t cpIndex);168169/** \brief170* Populates a TypeLayout object.171*172* \param region173* The region used to allocate TypeLayout.174*175* \param opaqueClazz176* Class of the type whose layout needs to be populated.177*178* \return179* Returns a pointer to the TypeLayout object populated.180*/181const TR::TypeLayout* enumerateFields(TR::Region& region, TR_OpaqueClassBlock * clazz, TR::Compilation *comp);182183uintptr_t getArrayElementWidthInBytes(TR::Compilation *comp, TR_OpaqueClassBlock* arrayClass);184185uintptr_t persistentClassPointerFromClassPointer(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);186TR_OpaqueClassBlock *objectClass(TR::Compilation *comp, uintptr_t objectPointer);187TR_OpaqueClassBlock *classFromJavaLangClass(TR::Compilation *comp, uintptr_t objectPointer);188189uint16_t getStringCharacter(TR::Compilation *comp, uintptr_t objectPointer, int32_t index);190bool getStringFieldByName(TR::Compilation *, TR::SymbolReference *stringRef, TR::SymbolReference *fieldRef, void* &pResult);191192using OMR::ClassEnv::classNameChars;193char *classNameChars(TR::Compilation *, TR::SymbolReference *symRef, int32_t & length);194char *classNameChars(TR::Compilation *, TR_OpaqueClassBlock * clazz, int32_t & length);195196char *classSignature_DEPRECATED(TR::Compilation *comp, TR_OpaqueClassBlock * clazz, int32_t & length, TR_Memory *);197char *classSignature(TR::Compilation *comp, TR_OpaqueClassBlock * clazz, TR_Memory *);198199/**200* \brief201* Constructs a class signature char string based on the class name202*203* \param[in] name204* The class name205*206* \param[in,out] len207* The input is the length of the class name. Returns the length of the signature208*209* \param[in] comp210* The compilation object211*212* \param[in] allocKind213* The type of the memory allocation214*215* \param[in] clazz216* The class that the class name belongs to217*218* \return219* A class signature char string220*/221char *classNameToSignature(const char *name, int32_t &len, TR::Compilation *comp, TR_AllocationKind allocKind = stackAlloc, TR_OpaqueClassBlock *clazz = NULL);222223int32_t vTableSlot(TR::Compilation *comp, TR_OpaqueMethodBlock *, TR_OpaqueClassBlock *);224int32_t flagValueForPrimitiveTypeCheck(TR::Compilation *comp);225int32_t flagValueForArrayCheck(TR::Compilation *comp);226int32_t flagValueForFinalizerCheck(TR::Compilation *comp);227228bool isClassSpecialForStackAllocation(TR_OpaqueClassBlock * classPointer);229/**230* Get the virtual function table entry at a specific offset from the class231*232* @param clazz The RAM class pointer to read from233* @param offset An offset into the virtual function table (VFT) of clazz234* @return The entry point of the method at the given offset235*/236intptr_t getVFTEntry(TR::Compilation *comp, TR_OpaqueClassBlock* clazz, int32_t offset);237uint8_t *getROMClassRefName(TR::Compilation *comp, TR_OpaqueClassBlock *clazz, uint32_t cpIndex, int &classRefLen);238J9ROMConstantPoolItem *getROMConstantPool(TR::Compilation *comp, TR_OpaqueClassBlock *clazz);239240/**241* @brief Determine if a list of classes contains less than two concrete classes.242* A class is considered concrete if it is not an interface or an abstract class243* @param subClasses List of subclasses to be checked.244* @return Returns 'true' if the given list of classes contains less than245* 2 concrete classses and false otherwise.246*/247bool containsZeroOrOneConcreteClass(TR::Compilation *comp, List<TR_PersistentClassInfo>* subClasses);248};249250}251252#endif253254255