Path: blob/master/runtime/gc_base/MixedObjectAllocationModel.hpp
5986 views
/*******************************************************************************1* Copyright (c) 1991, 2019 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#if !defined(MIXEDOBJECTALLOCATIONMODEL_HPP_)23#define MIXEDOBJECTALLOCATIONMODEL_HPP_2425#include "j9.h"26#include "j9cfg.h"27#include "modron.h"2829#include "JavaObjectAllocationModel.hpp"3031/**32* Class definition for the mixed object allocation model.33*/34class MM_MixedObjectAllocationModel : public MM_JavaObjectAllocationModel35{36/*37* Member data and types38*/39private:4041protected:4243public:4445/*46* Member functions47*/48private:49/**50* Calculate the total allocation size in bytes required to represent a Java object (or array) given51* the number of bytes required to hold the instance data (without header or hash code). This adds52* on the size in bytes of the53*/54static uintptr_t55calculateRequiredSize(MM_EnvironmentBase *env, J9Class *clazz, uintptr_t allocateFlags)56{57/* Calculate the size in bytes required for the object being allocated */58uintptr_t const objectHeaderSize = J9GC_OBJECT_HEADER_SIZE(env);59uintptr_t sizeInBytesRequired = clazz->totalInstanceSize + objectHeaderSize;6061#if defined (J9VM_GC_MODRON_COMPACTION) || defined (J9VM_GC_GENERATIONAL)62if (OMR_GC_ALLOCATE_OBJECT_HASHED == (OMR_GC_ALLOCATE_OBJECT_HASHED & allocateFlags)) {63if (sizeInBytesRequired == env->getExtensions()->mixedObjectModel.getHashcodeOffset(clazz)) {64/* Add extra uintptr_t for hash */65sizeInBytesRequired += sizeof(uintptr_t);66}67}68#endif /* defined (J9VM_GC_MODRON_COMPACTION) || defined (J9VM_GC_GENERATIONAL) */6970return env->getExtensions()->objectModel.adjustSizeInBytes(sizeInBytesRequired);71}7273protected:7475public:76/**77* Constructor.78*/79MM_MixedObjectAllocationModel(MM_EnvironmentBase *env, J9Class *clazz, uintptr_t allocateObjectFlags = 0)80: MM_JavaObjectAllocationModel(env, clazz, allocation_category_mixed,81calculateRequiredSize(env, clazz, allocateObjectFlags),82allocateObjectFlags)83{}8485/**86* Vet the allocation description and set the _isAllocatable flag to false if not viable.87*88* @param[in] env the environment for the calling thread89* @return false if the allocation cannot proceed90*/91MMINLINE bool92initializeAllocateDescription(MM_EnvironmentBase *env)93{94#if defined(OMR_GC_VLHGC)95if (isAllocatable() && env->getExtensions()->isVLHGC()) {96/* CMVC 170688: Ensure that we don't try to allocate an object which will overflow the region97* if it ever grows (easier to handle this case in the allocator than to special-case the98* collectors to know how to avoid this case) Currently, we only grow by a hashcode slot99* which is 4-bytes but will increase our size by the granule of alignment.100*/101uintptr_t objectSizeAfterGrowing = getAllocateDescription()->getBytesRequested() + env->getObjectAlignmentInBytes();102if (objectSizeAfterGrowing > env->getExtensions()->regionSize) {103setAllocatable(false);104}105}106#endif /* defined(OMR_GC_VLHGC) */107108return isAllocatable();109}110111/**112* Initializer.113*/114MMINLINE omrobjectptr_t115initializeMixedObject(MM_EnvironmentBase *env, void *allocatedBytes)116{117/* Initialize object header */118omrobjectptr_t objectPtr = initializeJavaObject(env, allocatedBytes);119120/* Initialize hashcode slot */121if (getAllocateDescription()->getPreHashFlag()) {122env->getExtensions()->objectModel.initializeHashSlot((J9JavaVM*)env->getLanguageVM(), objectPtr);123}124125return objectPtr;126}127};128#endif /* MIXEDOBJECTALLOCATIONMODEL_HPP_ */129130131