Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_vlhgc/CopyScanCacheChunkVLHGCInHeap.cpp
5986 views
1
2
/*******************************************************************************
3
* Copyright (c) 1991, 2014 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* 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
22
*******************************************************************************/
23
24
#include "j9.h"
25
#include "j9cfg.h"
26
27
#include "CopyScanCacheVLHGC.hpp"
28
#include "CopyScanCacheChunkVLHGCInHeap.hpp"
29
30
31
UDATA
32
MM_CopyScanCacheChunkVLHGCInHeap::numberOfCachesInChunk(MM_EnvironmentVLHGC *env)
33
{
34
UDATA tlhMinimumSize = MM_GCExtensions::getExtensions(env)->tlhMinimumSize;
35
UDATA sizeToAllocate = sizeof(MM_CopyScanCacheChunkVLHGCInHeap);
36
UDATA numberOfCaches = 1;
37
38
if (sizeToAllocate < tlhMinimumSize) {
39
/* calculate number of caches to just barely exceed tlhMinimumSize */
40
numberOfCaches = ((tlhMinimumSize - sizeToAllocate) / sizeof(MM_CopyScanCacheVLHGC)) + 1;
41
}
42
return numberOfCaches;
43
}
44
45
UDATA
46
MM_CopyScanCacheChunkVLHGCInHeap::bytesRequiredToAllocateChunkInHeap(MM_EnvironmentVLHGC *env)
47
{
48
UDATA sizeToAllocate = sizeof(MM_CopyScanCacheChunkVLHGCInHeap);
49
UDATA numberOfCaches = numberOfCachesInChunk(env);
50
51
/* total size required to allocate */
52
sizeToAllocate += numberOfCaches * sizeof(MM_CopyScanCacheVLHGC);
53
/* this is going to be allocated on the heap so ensure that the chunk we are allocating is adjusted for heap alignment (since object consumed sizes already have this requirement) */
54
sizeToAllocate = MM_Math::roundToCeiling(env->getObjectAlignmentInBytes(), sizeToAllocate);
55
return sizeToAllocate;
56
}
57
58
MM_CopyScanCacheChunkVLHGCInHeap *
59
MM_CopyScanCacheChunkVLHGCInHeap::newInstance(MM_EnvironmentVLHGC *env, void *buffer, UDATA bufferLengthInBytes, MM_CopyScanCacheVLHGC **nextCacheAddr, MM_CopyScanCacheChunkVLHGC *nextChunk)
60
{
61
/* make sure that the memory extent is exactly the right size to allocate an instance of the receiver */
62
Assert_MM_true(bytesRequiredToAllocateChunkInHeap(env) == bufferLengthInBytes);
63
MM_CopyScanCacheChunkVLHGCInHeap *chunk = (MM_CopyScanCacheChunkVLHGCInHeap *)buffer;
64
new(chunk) MM_CopyScanCacheChunkVLHGCInHeap();
65
if (!chunk->initialize(env, numberOfCachesInChunk(env), nextCacheAddr, nextChunk)) {
66
chunk->tearDown(env);
67
chunk = NULL;
68
}
69
return chunk;
70
}
71
72
bool
73
MM_CopyScanCacheChunkVLHGCInHeap::initialize(MM_EnvironmentVLHGC *env, UDATA cacheEntryCount, MM_CopyScanCacheVLHGC **nextCacheAddr, MM_CopyScanCacheChunkVLHGC *nextChunk)
74
{
75
bool success = MM_CopyScanCacheChunkVLHGC::initialize(env, cacheEntryCount, nextCacheAddr, nextChunk);
76
if (success) {
77
MM_CopyScanCacheVLHGC *structureArrayBase = getBase();
78
for (UDATA i = 0; i < cacheEntryCount; i++) {
79
structureArrayBase[i].flags |= J9VM_MODRON_SCAVENGER_CACHE_TYPE_HEAP;
80
}
81
}
82
return success;
83
}
84
85
void
86
MM_CopyScanCacheChunkVLHGCInHeap::kill(MM_EnvironmentVLHGC *env)
87
{
88
tearDown(env);
89
/* the receiver's memory was allocated for it in memory which does not require cleanup */
90
}
91
92