Path: blob/master/runtime/gc_base/ClassModel.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 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* @file24* @ingroup GC_Base25*/2627#if !defined(CLASSMODEL_HPP_)28#define CLASSMODEL_HPP_2930#include "j9.h"31#include "j9cfg.h"32#include "j9consts.h"33#include "modron.h"3435#include "Bits.hpp"3637/**38* Provides information for a given class.39* @ingroup GC_Base40*/41class GC_ClassModel42{43public:44#if !defined(J9VM_OPT_FRAGMENT_RAM_CLASSES)45/**46* Returns the size of a class, in bytes.47* @param clazzPtr Pointer to the class whose size is required48* @return Size of class in bytes49*/50MMINLINE static UDATA getSizeInBytes(J9Class *clazzPtr)51{52return clazzPtr->size;53}5455/**56* Returns the size of a class, in slots.57* @param clazzPtr Pointer to the class whose size is required58* @return Size of class in slots59*/60MMINLINE static UDATA getSizeInSlots(J9Class *clazzPtr)61{62return MM_Bits::convertBytesToSlots(getSizeInBytes(clazzPtr));63}64#endif6566/**67* Returns the depth of a class.68* @param clazzPtr Pointer to the class whose depth is required69* @return Depth of class70*/71MMINLINE static UDATA getClassDepth(J9Class *clazzPtr)72{73return J9CLASS_DEPTH(clazzPtr);74}7576/**77* Returns the superclass of a class.78* @param clazzPtr Pointer to the class whose superclass is required79* @return superclass of class80*/81MMINLINE static J9Class *getSuperclass(J9Class *clazzPtr)82{83UDATA classDepth = J9CLASS_DEPTH(clazzPtr);84return clazzPtr->superclasses[classDepth - 1];85}8687/**88* Returns TRUE if the class is an array class, FALSE otherwise.89* @param clazzPtr Pointer to the class90* @return TRUE if the class is an array class, FALSE otherwise91*/92MMINLINE static bool usesSharedITable(J9JavaVM *javaVM, J9Class *clazzPtr)93{94return (clazzPtr->romClass->modifiers & J9AccClassArray) && (clazzPtr != javaVM->booleanArrayClass);95}9697/**98* Returns the size, in bytes, of an instance of a class.99* @param clazzPtr Pointer to the class whose instance size is required100* @return The size of and instance of the class in bytes101*/102MMINLINE static UDATA getInstanceSizeInBytes(J9Class *clazzPtr)103{104return clazzPtr->totalInstanceSize;105}106107/**108* Calculate the number of object slots in the class.109* @param[in] clazz Pointer to the class110* @param[in] vm The J9JavaVM111* @return number of object slots.112*/113MMINLINE static UDATA114getNumberOfObjectSlots(J9Class *clazz, J9JavaVM *vm)115{116UDATA totalInstanceSize = clazz->totalInstanceSize;117IDATA scanLimit = (IDATA) (totalInstanceSize / J9JAVAVM_REFERENCE_SIZE(vm));118UDATA tempDescription = (UDATA)clazz->instanceDescription;119120UDATA slotCount = 0;121if (scanLimit > 0) {122if (tempDescription & 1) {123/* immediate */124UDATA description = (tempDescription >> 1);125slotCount = MM_Bits::populationCount(description);126} else {127UDATA *descriptionPtr = (UDATA *) tempDescription;128while (scanLimit > 0) {129UDATA description = *descriptionPtr;130descriptionPtr += 1;131slotCount += MM_Bits::populationCount(description);132scanLimit = scanLimit - J9_OBJECT_DESCRIPTION_SIZE;133}134}135}136return slotCount;137}138};139140#endif /* CLASSMODEL_HPP_ */141142143