Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/gc_base/OwnableSynchronizerObjectBuffer.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
#include "ModronAssertions.h"
27
28
#include "OwnableSynchronizerObjectBuffer.hpp"
29
30
#include "EnvironmentBase.hpp"
31
#include "GCExtensions.hpp"
32
#include "HeapRegionDescriptor.hpp"
33
#include "HeapRegionManager.hpp"
34
#include "ObjectAccessBarrier.hpp"
35
36
MM_OwnableSynchronizerObjectBuffer::MM_OwnableSynchronizerObjectBuffer(MM_GCExtensions *extensions, UDATA maxObjectCount)
37
: MM_BaseVirtual()
38
, _maxObjectCount(maxObjectCount)
39
, _extensions(extensions)
40
{
41
_typeId = __FUNCTION__;
42
reset();
43
}
44
45
void
46
MM_OwnableSynchronizerObjectBuffer::kill(MM_EnvironmentBase *env)
47
{
48
tearDown(env);
49
env->getForge()->free(this);
50
}
51
52
void
53
MM_OwnableSynchronizerObjectBuffer::reset()
54
{
55
_head = NULL;
56
_tail = NULL;
57
_region = NULL;
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_OwnableSynchronizerObjectBuffer::flush(MM_EnvironmentBase* env)
64
{
65
if (NULL != _head) {
66
/* call the virtual flush implementation function */
67
flushImpl(env);
68
reset();
69
}
70
}
71
72
void
73
MM_OwnableSynchronizerObjectBuffer::add(MM_EnvironmentBase* env, j9object_t object)
74
{
75
Assert_MM_true(object != _head);
76
Assert_MM_true(object != _tail);
77
78
if ( (_objectCount < _maxObjectCount) && _region->isAddressInRegion(object) ) {
79
/* object is permitted in this buffer */
80
Assert_MM_true(NULL != _head);
81
Assert_MM_true(NULL != _tail);
82
83
_extensions->accessBarrier->setOwnableSynchronizerLink(object, _head);
84
_head = object;
85
_objectCount += 1;
86
} else {
87
MM_HeapRegionDescriptor *region = _region;
88
89
/* flush the buffer and start fresh */
90
flush(env);
91
_extensions->accessBarrier->setOwnableSynchronizerLink(object, NULL);
92
_head = object;
93
_tail = object;
94
_objectCount = 1;
95
if (NULL == region || !region->isAddressInRegion(object)) {
96
/* record the region which contains this object. Other objects will be permitted in the buffer if they are in the same region */
97
MM_HeapRegionManager *regionManager = _extensions->getHeap()->getHeapRegionManager();
98
region = regionManager->regionDescriptorForAddress(object);
99
100
Assert_GC_true_with_message(env, NULL != region, "Attempt to access ownable synchronizer object located outside of heap (stack allocated?) %p\n", object);
101
}
102
_region = region;
103
}
104
Assert_MM_true(_region->isAddressInRegion(object));
105
}
106
107
/*
108
* temporary place holder implementation - just delegate to the old fragment code.
109
*/
110
void
111
MM_OwnableSynchronizerObjectBuffer::flushImpl(MM_EnvironmentBase* env)
112
{
113
Assert_MM_unreachable();
114
}
115
116