Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/bcutil/ROMClassSegmentAllocationStrategy.cpp
5985 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2020 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
* ROMClassSegmentAllocationStrategy.cpp
24
*/
25
26
#include "ROMClassSegmentAllocationStrategy.hpp"
27
#include "ut_j9bcu.h"
28
29
U_8*
30
ROMClassSegmentAllocationStrategy::allocate(UDATA bytesRequired)
31
{
32
U_8* result = NULL;
33
34
/* Scan existing segments for one large enough to hold the new ROM class */
35
36
J9MemorySegment* segment = NULL;
37
/* always make a new segment if its an anonClass */
38
bool allocNewSegment = (_classLoader == _javaVM->anonClassLoader);
39
40
if (!allocNewSegment) {
41
J9MemorySegmentList* classSegments = _javaVM->classMemorySegments;
42
#ifdef J9VM_THR_PREEMPTIVE
43
omrthread_monitor_enter(classSegments->segmentMutex);
44
#endif
45
segment = _classLoader->classSegments;
46
47
while (NULL != segment) {
48
if ((segment->type & (MEMORY_TYPE_ROM_CLASS | MEMORY_TYPE_ALLOCATED)) == (MEMORY_TYPE_ROM_CLASS | MEMORY_TYPE_ALLOCATED)) {
49
UDATA romAvailable = segment->heapTop - segment->heapAlloc;
50
51
if (romAvailable >= bytesRequired) {
52
result = segment->heapAlloc;
53
break;
54
}
55
}
56
segment = segment->nextSegmentInClassLoader;
57
}
58
#ifdef J9VM_THR_PREEMPTIVE
59
omrthread_monitor_exit(classSegments->segmentMutex);
60
#endif
61
}
62
63
/* If no segment was found which could hold the new ROM class, allocate a new one */
64
65
if (NULL == result) {
66
UDATA classAllocationIncrement = _javaVM->romClassAllocationIncrement;
67
if (allocNewSegment) {
68
classAllocationIncrement = 0;
69
}
70
segment = _javaVM->internalVMFunctions->allocateClassMemorySegment(_javaVM, bytesRequired, MEMORY_TYPE_DYNAMIC_LOADED_CLASSES, _classLoader, classAllocationIncrement);
71
if (segment != NULL) {
72
result = segment->heapAlloc;
73
}
74
}
75
76
if ( NULL != result ) {
77
segment->heapAlloc += bytesRequired;
78
/*
79
* store a reference to the used segment and bytesRequested
80
* so that heapAlloc can later be adjusted to
81
* the actual amount of memory used in updateFinalROMSize()
82
*/
83
_segment = segment;
84
_bytesRequested = bytesRequired;
85
}
86
87
return result;
88
}
89
90
void
91
ROMClassSegmentAllocationStrategy::updateFinalROMSize(UDATA finalSize)
92
{
93
Trc_BCU_Assert_NotEquals( NULL, _segment );
94
/* this assumes that the appropriate lock is held from allocate() to now */
95
_segment->heapAlloc -= _bytesRequested;
96
_segment->heapAlloc += finalSize;
97
}
98
99