Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/MixedObjectAllocationModel.hpp
5986 views
1
/*******************************************************************************
2
* Copyright (c) 1991, 2019 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
#if !defined(MIXEDOBJECTALLOCATIONMODEL_HPP_)
24
#define MIXEDOBJECTALLOCATIONMODEL_HPP_
25
26
#include "j9.h"
27
#include "j9cfg.h"
28
#include "modron.h"
29
30
#include "JavaObjectAllocationModel.hpp"
31
32
/**
33
* Class definition for the mixed object allocation model.
34
*/
35
class MM_MixedObjectAllocationModel : public MM_JavaObjectAllocationModel
36
{
37
/*
38
* Member data and types
39
*/
40
private:
41
42
protected:
43
44
public:
45
46
/*
47
* Member functions
48
*/
49
private:
50
/**
51
* Calculate the total allocation size in bytes required to represent a Java object (or array) given
52
* the number of bytes required to hold the instance data (without header or hash code). This adds
53
* on the size in bytes of the
54
*/
55
static uintptr_t
56
calculateRequiredSize(MM_EnvironmentBase *env, J9Class *clazz, uintptr_t allocateFlags)
57
{
58
/* Calculate the size in bytes required for the object being allocated */
59
uintptr_t const objectHeaderSize = J9GC_OBJECT_HEADER_SIZE(env);
60
uintptr_t sizeInBytesRequired = clazz->totalInstanceSize + objectHeaderSize;
61
62
#if defined (J9VM_GC_MODRON_COMPACTION) || defined (J9VM_GC_GENERATIONAL)
63
if (OMR_GC_ALLOCATE_OBJECT_HASHED == (OMR_GC_ALLOCATE_OBJECT_HASHED & allocateFlags)) {
64
if (sizeInBytesRequired == env->getExtensions()->mixedObjectModel.getHashcodeOffset(clazz)) {
65
/* Add extra uintptr_t for hash */
66
sizeInBytesRequired += sizeof(uintptr_t);
67
}
68
}
69
#endif /* defined (J9VM_GC_MODRON_COMPACTION) || defined (J9VM_GC_GENERATIONAL) */
70
71
return env->getExtensions()->objectModel.adjustSizeInBytes(sizeInBytesRequired);
72
}
73
74
protected:
75
76
public:
77
/**
78
* Constructor.
79
*/
80
MM_MixedObjectAllocationModel(MM_EnvironmentBase *env, J9Class *clazz, uintptr_t allocateObjectFlags = 0)
81
: MM_JavaObjectAllocationModel(env, clazz, allocation_category_mixed,
82
calculateRequiredSize(env, clazz, allocateObjectFlags),
83
allocateObjectFlags)
84
{}
85
86
/**
87
* Vet the allocation description and set the _isAllocatable flag to false if not viable.
88
*
89
* @param[in] env the environment for the calling thread
90
* @return false if the allocation cannot proceed
91
*/
92
MMINLINE bool
93
initializeAllocateDescription(MM_EnvironmentBase *env)
94
{
95
#if defined(OMR_GC_VLHGC)
96
if (isAllocatable() && env->getExtensions()->isVLHGC()) {
97
/* CMVC 170688: Ensure that we don't try to allocate an object which will overflow the region
98
* if it ever grows (easier to handle this case in the allocator than to special-case the
99
* collectors to know how to avoid this case) Currently, we only grow by a hashcode slot
100
* which is 4-bytes but will increase our size by the granule of alignment.
101
*/
102
uintptr_t objectSizeAfterGrowing = getAllocateDescription()->getBytesRequested() + env->getObjectAlignmentInBytes();
103
if (objectSizeAfterGrowing > env->getExtensions()->regionSize) {
104
setAllocatable(false);
105
}
106
}
107
#endif /* defined(OMR_GC_VLHGC) */
108
109
return isAllocatable();
110
}
111
112
/**
113
* Initializer.
114
*/
115
MMINLINE omrobjectptr_t
116
initializeMixedObject(MM_EnvironmentBase *env, void *allocatedBytes)
117
{
118
/* Initialize object header */
119
omrobjectptr_t objectPtr = initializeJavaObject(env, allocatedBytes);
120
121
/* Initialize hashcode slot */
122
if (getAllocateDescription()->getPreHashFlag()) {
123
env->getExtensions()->objectModel.initializeHashSlot((J9JavaVM*)env->getLanguageVM(), objectPtr);
124
}
125
126
return objectPtr;
127
}
128
};
129
#endif /* MIXEDOBJECTALLOCATIONMODEL_HPP_ */
130
131