Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/ReferenceObjectBuffer.cpp
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
#include "j9.h"
24
#include "j9cfg.h"
25
#include "ModronAssertions.h"
26
27
#include "ReferenceObjectBuffer.hpp"
28
29
#include "EnvironmentBase.hpp"
30
#include "GCExtensions.hpp"
31
#include "HeapRegionDescriptor.hpp"
32
#include "HeapRegionManager.hpp"
33
#include "ObjectAccessBarrier.hpp"
34
#include "ReferenceObjectList.hpp"
35
36
MM_ReferenceObjectBuffer::MM_ReferenceObjectBuffer(UDATA maxObjectCount)
37
: MM_BaseVirtual()
38
, _maxObjectCount(maxObjectCount)
39
{
40
_typeId = __FUNCTION__;
41
reset();
42
}
43
44
void
45
MM_ReferenceObjectBuffer::kill(MM_EnvironmentBase *env)
46
{
47
tearDown(env);
48
env->getForge()->free(this);
49
}
50
51
void
52
MM_ReferenceObjectBuffer::reset()
53
{
54
_head = NULL;
55
_tail = NULL;
56
_region = NULL;
57
_referenceObjectType = 0;
58
/* set object count to appear full so that we force initialization on the next add */
59
_objectCount = _maxObjectCount;
60
}
61
62
void
63
MM_ReferenceObjectBuffer::flush(MM_EnvironmentBase* env)
64
{
65
if (NULL != _head) {
66
flushImpl(env);
67
reset();
68
}
69
}
70
71
UDATA
72
MM_ReferenceObjectBuffer::getReferenceObjectType(MM_EnvironmentBase* env, j9object_t object)
73
{
74
return J9CLASS_FLAGS(J9GC_J9OBJECT_CLAZZ(object, env)) & J9AccClassReferenceMask;
75
}
76
77
void
78
MM_ReferenceObjectBuffer::add(MM_EnvironmentBase* env, j9object_t object)
79
{
80
MM_GCExtensions *extensions = MM_GCExtensions::getExtensions(env);
81
82
if ( (_objectCount < _maxObjectCount) && _region->isAddressInRegion(object) && (getReferenceObjectType(env, object) == _referenceObjectType)) {
83
/* object is permitted in this buffer */
84
Assert_MM_true(NULL != _head);
85
Assert_MM_true(NULL != _tail);
86
87
extensions->accessBarrier->setReferenceLink(object, _head);
88
_head = object;
89
_objectCount += 1;
90
} else {
91
MM_HeapRegionDescriptor *region = _region;
92
93
/* flush the buffer and start fresh */
94
flush(env);
95
96
extensions->accessBarrier->setReferenceLink(object, NULL);
97
_head = object;
98
_tail = object;
99
_objectCount = 1;
100
if (NULL == region || !region->isAddressInRegion(object)) {
101
/* record the type of object and the region which contains this object. Other objects will be permitted in the buffer if they match */
102
MM_HeapRegionManager *regionManager = extensions->getHeap()->getHeapRegionManager();
103
region = regionManager->regionDescriptorForAddress(object);
104
Assert_MM_true(NULL != region);
105
}
106
_region = region;
107
_referenceObjectType = getReferenceObjectType(env, object);
108
109
}
110
}
111
112
113