Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_modron_startup/gcmspace.cpp
5985 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
24
/**
25
* @file
26
* @ingroup GC_Modron_Startup
27
*/
28
29
#include "j9.h"
30
#include "j9cfg.h"
31
#include "j9protos.h"
32
#include "j9consts.h"
33
#include "modronopt.h"
34
#include "gcmspace.h"
35
36
#include <string.h>
37
38
#include "Configuration.hpp"
39
#if defined(J9VM_GC_REALTIME)
40
#include "EnvironmentRealtime.hpp"
41
#else
42
#include "EnvironmentBase.hpp"
43
#endif /* J9VM_GC_REALTIME */
44
#include "GCExtensions.hpp"
45
#include "Heap.hpp"
46
#include "MemorySpace.hpp"
47
#include "ObjectAllocationInterface.hpp"
48
49
#include "mmhook_internal.h"
50
51
extern "C" {
52
/**
53
* Shim for low level Memory Spaces allocation which only exists to create the correct fake env for internalAllocateMemorySpaceWithMaximumWithEnv.
54
* Provided sizes are already adjusted (aligned etc).
55
* @return the pointer to the list (pool) of memory spaces allocated
56
*/
57
MM_MemorySpace *
58
internalAllocateMemorySpaceWithMaximum(J9JavaVM * javaVM, UDATA minimumSpaceSize, UDATA minimumNewSpaceSize, UDATA initialNewSpaceSize, UDATA maximumNewSpaceSize, UDATA minimumTenureSpaceSize, UDATA initialTenureSpaceSize, UDATA maximumTenureSpaceSize, UDATA memoryMax, UDATA baseAddress, UDATA tenureFlags)
59
{
60
MM_MemorySpace *result = NULL;
61
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
62
if (extensions->isMetronomeGC()) {
63
#if defined(J9VM_GC_REALTIME)
64
MM_EnvironmentRealtime env(javaVM->omrVM);
65
result = internalAllocateMemorySpaceWithMaximumWithEnv(&env, javaVM, minimumSpaceSize, minimumNewSpaceSize, initialNewSpaceSize, maximumNewSpaceSize, minimumTenureSpaceSize, initialTenureSpaceSize, maximumTenureSpaceSize, memoryMax, baseAddress, tenureFlags);
66
#endif /* J9VM_GC_REALTIME */
67
} else {
68
MM_EnvironmentBase env(javaVM->omrVM);
69
result = internalAllocateMemorySpaceWithMaximumWithEnv(&env, javaVM, minimumSpaceSize, minimumNewSpaceSize, initialNewSpaceSize, maximumNewSpaceSize, minimumTenureSpaceSize, initialTenureSpaceSize, maximumTenureSpaceSize, memoryMax, baseAddress, tenureFlags);
70
}
71
return result;
72
}
73
74
/**
75
* Low level Memory Spaces allocation.
76
* Provided sizes are already adjusted (aligned etc).
77
* @return the pointer to the list (pool) of memory spaces allocated
78
*/
79
MM_MemorySpace *
80
internalAllocateMemorySpaceWithMaximumWithEnv(MM_EnvironmentBase *env, J9JavaVM *javaVM, UDATA minimumSpaceSize, UDATA minimumNewSpaceSize, UDATA initialNewSpaceSize, UDATA maximumNewSpaceSize, UDATA minimumTenureSpaceSize, UDATA initialTenureSpaceSize, UDATA maximumTenureSpaceSize, UDATA memoryMax, UDATA baseAddress, UDATA tenureFlags)
81
{
82
MM_MemorySpace *memorySpace = NULL;
83
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(javaVM);
84
MM_Heap *heap = extensions->heap;
85
86
/* create set of parameters and clean them */
87
MM_InitializationParameters parameters;
88
MM_Configuration *configuration = extensions->configuration;
89
90
/*
91
* This function uses goto! All function-scope variables must be declared above
92
* this comment. Failure to do so will cause compile errors on GNU and IBM compilers.
93
*/
94
configuration->prepareParameters(javaVM->omrVM, minimumSpaceSize, minimumNewSpaceSize, initialNewSpaceSize, maximumNewSpaceSize,
95
minimumTenureSpaceSize, initialTenureSpaceSize, maximumTenureSpaceSize,
96
memoryMax, tenureFlags, &parameters);
97
98
memorySpace = configuration->createDefaultMemorySpace(env, heap, &parameters);
99
100
if(NULL == memorySpace) {
101
goto cleanup;
102
}
103
104
if (baseAddress) {
105
if(!memorySpace->inflate(env)) {
106
goto cleanup;
107
}
108
} else {
109
/* TODO: remove this branch, once physical memory is created with new API */
110
/* defer inflation if base address is fixed */
111
if ((MEMORY_TYPE_FIXED & tenureFlags) != MEMORY_TYPE_FIXED) {
112
if(!memorySpace->inflate(env)) {
113
goto cleanup;
114
}
115
}
116
}
117
118
TRIGGER_J9HOOK_MM_PRIVATE_HEAP_NEW(
119
MM_GCExtensions::getExtensions(javaVM)->privateHookInterface,
120
env->getOmrVMThread(),
121
memorySpace);
122
123
if (NULL == heap->getDefaultMemorySpace()) {
124
heap->setDefaultMemorySpace(memorySpace);
125
}
126
127
return memorySpace;
128
129
cleanup:
130
131
/* TODO: Cleanup for the memorySpace class (if necessary) */
132
return NULL;
133
}
134
135
} /* extern "C" */
136
137