Path: blob/master/runtime/gc_base/IndexableObjectAllocationModel.hpp
5986 views
1/*******************************************************************************2* Copyright (c) 1991, 2020 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(INDEXABLEOBJECTALLOCATIONMODEL_HPP_)24#define INDEXABLEOBJECTALLOCATIONMODEL_HPP_2526#include "j9.h"27#include "j9cfg.h"28#include "modron.h"29#include "objectdescription.h"30#include "ModronAssertions.h"3132#include "ArrayletObjectModel.hpp"33#include "JavaObjectAllocationModel.hpp"34#include "MemorySpace.hpp"3536/**37* Class definition for the array object allocation model.38*/39class MM_IndexableObjectAllocationModel : public MM_JavaObjectAllocationModel40{41/*42* Member data and types43*/44private:45const uint32_t _numberOfIndexedFields;46const uintptr_t _dataSize;47const GC_ArrayletObjectModel::ArrayLayout _layout;48const bool _alignSpineDataSection;49const uintptr_t _numberOfArraylets;5051protected:5253public:5455/*56* Member functions57*/58private:59/**60* For contiguous arraylet all data is subsumed into the spine.61* @return initialized arraylet spine with its arraylet pointers initialized.62*/63MMINLINE J9IndexableObject *layoutContiguousArraylet(MM_EnvironmentBase *env, J9IndexableObject *spine);6465/**66* For non-contiguous arraylet (i.e. discontiguous and hybrid), perform separate allocations67* for spine and leaf data. The spine and attached leaves may move as each leaf is allocated68* is GC is allowed. The final location of the spine is returned.69* @return initialized arraylet spine with its arraylet pointers initialized.70*/71MMINLINE J9IndexableObject *layoutDiscontiguousArraylet(MM_EnvironmentBase *env, J9IndexableObject *spine);7273protected:7475public:76MM_IndexableObjectAllocationModel(MM_EnvironmentBase *env,77J9Class *clazz,78uint32_t numberOfIndexedFields,79uintptr_t allocateObjectFlags = 080)81: MM_JavaObjectAllocationModel(env, clazz, allocation_category_indexable,820, allocateObjectFlags | OMR_GC_ALLOCATE_OBJECT_INDEXABLE)83, _numberOfIndexedFields(numberOfIndexedFields)84, _dataSize(env->getExtensions()->indexableObjectModel.getDataSizeInBytes(_class, _numberOfIndexedFields))85, _layout(env->getExtensions()->indexableObjectModel.getArrayletLayout(_class, _dataSize,86_allocateDescription.getMemorySpace()->getDefaultMemorySubSpace()->largestDesirableArraySpine()))87, _alignSpineDataSection(env->getExtensions()->indexableObjectModel.shouldAlignSpineDataSection(_class))88, _numberOfArraylets(env->getExtensions()->indexableObjectModel.numArraylets(_dataSize))89{90/* check for overflow of _dataSize in indexableObjectModel.getDataSizeInBytes() */91if (J9_MAXIMUM_INDEXABLE_DATA_SIZE < _dataSize) {92J9VMThread *vmThread = (J9VMThread *)env->getLanguageVMThread();93switch (J9GC_CLASS_SHAPE(_class)) {94case OBJECT_HEADER_SHAPE_BYTES:95break;96case OBJECT_HEADER_SHAPE_WORDS:97Trc_MM_ShortArrayAllocationFailedDueToOverflow(vmThread, _numberOfIndexedFields);98break;99case OBJECT_HEADER_SHAPE_LONGS:100Trc_MM_IntArrayAllocationFailedDueToOverflow(vmThread, _numberOfIndexedFields);101break;102case OBJECT_HEADER_SHAPE_DOUBLES:103Trc_MM_DoubleArrayAllocationFailedDueToOverflow(vmThread, _numberOfIndexedFields);104break;105case OBJECT_HEADER_SHAPE_POINTERS:106Trc_MM_ObjectArrayAllocationFailedDueToOverflow(vmThread, _numberOfIndexedFields);107break;108default:109Assert_MM_unreachable();110break;111}112setAllocatable(false);113}114}115116117MMINLINE uint32_t getNumberOfIndexedFields() { return _numberOfIndexedFields; }118119MMINLINE uintptr_t getNumberOfArraylets() { return _numberOfArraylets; }120121/**122* Allocation description and layout initialization.123*/124bool initializeAllocateDescription(MM_EnvironmentBase *env);125126#if defined(J9VM_GC_ENABLE_DOUBLE_MAP)127/**128* For non-contiguous arraylets (discontiguous arraylets, hybrid not allowed129* when double map is enabled), double maps the arraylet leaves to a contiguous130* region outside the heap, making a discontiguous arraylet look contiguous.131* Double map is enabled by default, if one wants to disable it, manually pass132* command line option -Xgc:disableArrayletDoubleMapping; however, if the133* system supports huge pages then double map will be disabled. That's because134* double map does support huge pages yet. If one still wants to enable double135* map in such systems, one must manually force the application to use the136* small system page size137*138* @param env thread GC Environment139* @param objectPtr indexable object spine140* @return the contiguous address pointer141*/142void *doubleMapArraylets(MM_EnvironmentBase *env, J9Object *objectPtr, void *preferredAddress);143#endif /* J9VM_GC_ENABLE_DOUBLE_MAP */144145/**146* Initializer.147*/148omrobjectptr_t initializeIndexableObject(MM_EnvironmentBase *env, void *allocatedBytes);149};150151#endif /* INDEXABLEOBJECTALLOCATIONMODEL_HPP_ */152153154