Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_glue_java/ObjectModelDelegate.cpp
5990 views
1
/*******************************************************************************
2
* Copyright (c) 2017, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* 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 and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
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-exception
21
*******************************************************************************/
22
23
#include "AllocateInitialization.hpp"
24
#include "EnvironmentBase.hpp"
25
#include "IndexableObjectAllocationModel.hpp"
26
#include "MixedObjectAllocationModel.hpp"
27
#include "ObjectModel.hpp"
28
29
omrobjectptr_t
30
GC_ObjectModelDelegate::initializeAllocation(MM_EnvironmentBase *env, void *allocatedBytes, MM_AllocateInitialization *allocateInitialization)
31
{
32
omrobjectptr_t objectPtr = NULL;
33
34
switch (allocateInitialization->getAllocationCategory()) {
35
case MM_JavaObjectAllocationModel::allocation_category_mixed: {
36
MM_MixedObjectAllocationModel *mixedObjectAllocationModel = (MM_MixedObjectAllocationModel *)allocateInitialization;
37
objectPtr = mixedObjectAllocationModel->initializeMixedObject(env, allocatedBytes);
38
break;
39
}
40
case MM_JavaObjectAllocationModel::allocation_category_indexable: {
41
MM_IndexableObjectAllocationModel *indexableObjectAllocationModel = (MM_IndexableObjectAllocationModel *)allocateInitialization;
42
objectPtr = (omrobjectptr_t)indexableObjectAllocationModel->initializeIndexableObject(env, allocatedBytes);
43
break;
44
}
45
default:
46
Assert_MM_unreachable();
47
break;
48
}
49
50
return objectPtr;
51
}
52
53
#if defined(OMR_GC_MODRON_SCAVENGER)
54
void
55
GC_ObjectModelDelegate::calculateObjectDetailsForCopy(MM_EnvironmentBase *env, MM_ForwardedHeader *forwardedHeader, uintptr_t *objectCopySizeInBytes, uintptr_t *reservedObjectSizeInBytes, uintptr_t *hotFieldAlignmentDescriptor)
56
{
57
/* 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.
58
* the class pointer passed into this routine is guaranteed to have been checked
59
*/
60
GC_ObjectModel *objectModel = &env->getExtensions()->objectModel;
61
J9Class* clazz = objectModel->getPreservedClass(forwardedHeader);
62
uintptr_t actualObjectCopySizeInBytes = 0;
63
uintptr_t hashcodeOffset = 0;
64
65
if (objectModel->isIndexable(clazz)) {
66
*objectCopySizeInBytes = env->getExtensions()->indexableObjectModel.calculateObjectSizeAndHashcode(forwardedHeader, &hashcodeOffset);
67
} else {
68
*objectCopySizeInBytes = clazz->totalInstanceSize + J9GC_OBJECT_HEADER_SIZE(env->getExtensions());
69
hashcodeOffset = env->getExtensions()->mixedObjectModel.getHashcodeOffset(clazz);
70
}
71
72
/* IF the object has been hashed and has not been moved, then we need generate hash from the old address */
73
uintptr_t forwardedHeaderPreservedFlags = objectModel->getPreservedFlags(forwardedHeader);
74
75
if (hashcodeOffset == *objectCopySizeInBytes) {
76
if (objectModel->hasBeenMoved(forwardedHeaderPreservedFlags)) {
77
*objectCopySizeInBytes += sizeof(uintptr_t);
78
} else if (objectModel->hasBeenHashed(forwardedHeaderPreservedFlags)) {
79
actualObjectCopySizeInBytes += sizeof(uintptr_t);
80
}
81
}
82
actualObjectCopySizeInBytes += *objectCopySizeInBytes;
83
*reservedObjectSizeInBytes = objectModel->adjustSizeInBytes(actualObjectCopySizeInBytes);
84
*hotFieldAlignmentDescriptor = clazz->instanceHotFieldDescription;
85
}
86
#endif /* defined(OMR_GC_MODRON_SCAVENGER) */
87
88