Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/runtime/jcl/common/java_lang_ref_Reference.cpp
6000 views
1
/*******************************************************************************
2
* Copyright (c) 1998, 2021 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 "jni.h"
24
#include "jcl.h"
25
#include "jclglob.h"
26
#include "jclprots.h"
27
#include "jcl_internal.h"
28
29
extern "C" {
30
31
/* java.lang.ref.Reference: private native void reprocess(); */
32
void JNICALL
33
Java_java_lang_ref_Reference_reprocess(JNIEnv *env, jobject recv)
34
{
35
J9VMThread* currentThread = (J9VMThread*)env;
36
J9JavaVM* vm = currentThread->javaVM;
37
J9InternalVMFunctions* vmFuncs = vm->internalVMFunctions;
38
J9MemoryManagerFunctions* mmFuncs = vm->memoryManagerFunctions;
39
vmFuncs->internalEnterVMFromJNI(currentThread);
40
j9object_t receiverObject = J9_JNI_UNWRAP_REFERENCE(recv);
41
/* Under the SATB barrier call getReferent (for metronome or standard SATB CM), this will mark the referent if a cycle is in progress.
42
* Or reprocess this object if a concurrent GC (incremental cards) is in progress */
43
mmFuncs->j9gc_objaccess_referenceReprocess(currentThread, receiverObject);
44
vmFuncs->internalExitVMToJNI(currentThread);
45
}
46
47
/* java.lang.ref.Reference: static private native boolean waitForReferenceProcessingImpl(); */
48
jboolean JNICALL
49
Java_java_lang_ref_Reference_waitForReferenceProcessingImpl(JNIEnv *env, jclass recv)
50
{
51
jboolean result = JNI_FALSE;
52
#if defined(J9VM_GC_FINALIZATION)
53
J9JavaVM *vm = ((J9VMThread*)env)->javaVM;
54
J9MemoryManagerFunctions *mmFuncs = vm->memoryManagerFunctions;
55
if (0 != mmFuncs->j9gc_wait_for_reference_processing(vm)) {
56
result = JNI_TRUE;
57
}
58
#endif
59
return result;
60
}
61
62
#if JAVA_SPEC_VERSION >= 16
63
jboolean JNICALL
64
Java_java_lang_ref_Reference_refersTo(JNIEnv *env, jobject reference, jobject target)
65
{
66
J9VMThread * const currentThread = (J9VMThread *)env;
67
J9JavaVM * const vm = currentThread->javaVM;
68
J9InternalVMFunctions * const vmFuncs = vm->internalVMFunctions;
69
jboolean result = JNI_FALSE;
70
71
vmFuncs->internalEnterVMFromJNI(currentThread);
72
73
if (NULL == reference) {
74
vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);
75
} else {
76
j9object_t j9reference = J9_JNI_UNWRAP_REFERENCE(reference);
77
j9object_t j9target = (NULL != target) ? J9_JNI_UNWRAP_REFERENCE(target) : NULL;
78
j9object_t referent = J9VMJAVALANGREFREFERENCE_REFERENT_VM(vm, j9reference);
79
80
if (referent == j9target) {
81
result = JNI_TRUE;
82
}
83
}
84
85
vmFuncs->internalExitVMToJNI(currentThread);
86
87
return result;
88
}
89
#endif /* JAVA_SPEC_VERSION >= 16 */
90
91
} /* extern "C" */
92
93