Path: blob/master/runtime/gc_base/JavaObjectAllocationModel.hpp
5991 views
1/*******************************************************************************2* Copyright (c) 1991, 2018 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* 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-exception21*******************************************************************************/2223#if !defined(JAVAOBJECTALLOCATIONMODEL_HPP_)24#define JAVAOBJECTALLOCATIONMODEL_HPP_2526#include "j9.h"27#include "j9cfg.h"28#include "objectdescription.h"29#include "modron.h"3031#include "AllocateInitialization.hpp"32#include "ObjectAccessBarrier.hpp"3334/**35* Class definition for the Java object allocation model.36*/37class MM_JavaObjectAllocationModel : public MM_AllocateInitialization38{39/*40* Member data and types41*/42public:43/**44* Define object allocation categories. These are represented in MM_AllocateInitialization45* objects and are used in GC_ObjectModel::initializeAllocation() to determine how to46* initialize the header of a newly allocated object.47*/48enum {49allocation_category_mixed50, allocation_category_indexable51};5253protected:54J9Class *_class;5556private:5758/*59* Member functions60*/61private:6263MMINLINE J9Class *getClass() { return J9_CURRENT_CLASS(_class); }6465protected:6667public:6869/**70* Initializer.71*/72MMINLINE omrobjectptr_t73initializeJavaObject(MM_EnvironmentBase *env, void *allocatedBytes)74{75omrobjectptr_t objectPtr = (omrobjectptr_t)allocatedBytes;7677if (NULL != objectPtr) {78/* Initialize class pointer in object header -- preserve flags set by base class */79MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);80extensions->objectModel.setObjectClass(objectPtr, getClass());8182/* This might set the remembered bit in the header flags ... */83J9VMThread *vmThread = (J9VMThread *)env->getOmrVMThread()->_language_vmthread;84extensions->accessBarrier->recentlyAllocatedObject(vmThread, objectPtr);85}8687return objectPtr;88}8990/**91* Constructor.92*/93MM_JavaObjectAllocationModel(MM_EnvironmentBase *env,94J9Class *clazz,95uintptr_t allocationCategory,96uintptr_t requiredSizeInBytes,97uintptr_t allocateObjectFlags = 098)99: MM_AllocateInitialization(env, allocationCategory, requiredSizeInBytes, allocateObjectFlags)100, _class(clazz)101{}102};103#endif /* JAVAOBJECTALLOCATIONMODEL_HPP_ */104105106