Path: blob/master/runtime/gc_glue_java/ObjectModelDelegate.cpp
5990 views
/*******************************************************************************1* Copyright (c) 2017, 2021 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#include "AllocateInitialization.hpp"23#include "EnvironmentBase.hpp"24#include "IndexableObjectAllocationModel.hpp"25#include "MixedObjectAllocationModel.hpp"26#include "ObjectModel.hpp"2728omrobjectptr_t29GC_ObjectModelDelegate::initializeAllocation(MM_EnvironmentBase *env, void *allocatedBytes, MM_AllocateInitialization *allocateInitialization)30{31omrobjectptr_t objectPtr = NULL;3233switch (allocateInitialization->getAllocationCategory()) {34case MM_JavaObjectAllocationModel::allocation_category_mixed: {35MM_MixedObjectAllocationModel *mixedObjectAllocationModel = (MM_MixedObjectAllocationModel *)allocateInitialization;36objectPtr = mixedObjectAllocationModel->initializeMixedObject(env, allocatedBytes);37break;38}39case MM_JavaObjectAllocationModel::allocation_category_indexable: {40MM_IndexableObjectAllocationModel *indexableObjectAllocationModel = (MM_IndexableObjectAllocationModel *)allocateInitialization;41objectPtr = (omrobjectptr_t)indexableObjectAllocationModel->initializeIndexableObject(env, allocatedBytes);42break;43}44default:45Assert_MM_unreachable();46break;47}4849return objectPtr;50}5152#if defined(OMR_GC_MODRON_SCAVENGER)53void54GC_ObjectModelDelegate::calculateObjectDetailsForCopy(MM_EnvironmentBase *env, MM_ForwardedHeader *forwardedHeader, uintptr_t *objectCopySizeInBytes, uintptr_t *reservedObjectSizeInBytes, uintptr_t *hotFieldAlignmentDescriptor)55{56/* NOTE: the size is fetched by hand from the class in the mixed case because a forwarding pointer could have been substituted into the clazz slot.57* the class pointer passed into this routine is guaranteed to have been checked58*/59GC_ObjectModel *objectModel = &env->getExtensions()->objectModel;60J9Class* clazz = objectModel->getPreservedClass(forwardedHeader);61uintptr_t actualObjectCopySizeInBytes = 0;62uintptr_t hashcodeOffset = 0;6364if (objectModel->isIndexable(clazz)) {65*objectCopySizeInBytes = env->getExtensions()->indexableObjectModel.calculateObjectSizeAndHashcode(forwardedHeader, &hashcodeOffset);66} else {67*objectCopySizeInBytes = clazz->totalInstanceSize + J9GC_OBJECT_HEADER_SIZE(env->getExtensions());68hashcodeOffset = env->getExtensions()->mixedObjectModel.getHashcodeOffset(clazz);69}7071/* IF the object has been hashed and has not been moved, then we need generate hash from the old address */72uintptr_t forwardedHeaderPreservedFlags = objectModel->getPreservedFlags(forwardedHeader);7374if (hashcodeOffset == *objectCopySizeInBytes) {75if (objectModel->hasBeenMoved(forwardedHeaderPreservedFlags)) {76*objectCopySizeInBytes += sizeof(uintptr_t);77} else if (objectModel->hasBeenHashed(forwardedHeaderPreservedFlags)) {78actualObjectCopySizeInBytes += sizeof(uintptr_t);79}80}81actualObjectCopySizeInBytes += *objectCopySizeInBytes;82*reservedObjectSizeInBytes = objectModel->adjustSizeInBytes(actualObjectCopySizeInBytes);83*hotFieldAlignmentDescriptor = clazz->instanceHotFieldDescription;84}85#endif /* defined(OMR_GC_MODRON_SCAVENGER) */868788