Path: blob/master/runtime/jcl/common/java_lang_ref_Reference.cpp
6000 views
/*******************************************************************************1* Copyright (c) 1998, 2021 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122#include "jni.h"23#include "jcl.h"24#include "jclglob.h"25#include "jclprots.h"26#include "jcl_internal.h"2728extern "C" {2930/* java.lang.ref.Reference: private native void reprocess(); */31void JNICALL32Java_java_lang_ref_Reference_reprocess(JNIEnv *env, jobject recv)33{34J9VMThread* currentThread = (J9VMThread*)env;35J9JavaVM* vm = currentThread->javaVM;36J9InternalVMFunctions* vmFuncs = vm->internalVMFunctions;37J9MemoryManagerFunctions* mmFuncs = vm->memoryManagerFunctions;38vmFuncs->internalEnterVMFromJNI(currentThread);39j9object_t receiverObject = J9_JNI_UNWRAP_REFERENCE(recv);40/* Under the SATB barrier call getReferent (for metronome or standard SATB CM), this will mark the referent if a cycle is in progress.41* Or reprocess this object if a concurrent GC (incremental cards) is in progress */42mmFuncs->j9gc_objaccess_referenceReprocess(currentThread, receiverObject);43vmFuncs->internalExitVMToJNI(currentThread);44}4546/* java.lang.ref.Reference: static private native boolean waitForReferenceProcessingImpl(); */47jboolean JNICALL48Java_java_lang_ref_Reference_waitForReferenceProcessingImpl(JNIEnv *env, jclass recv)49{50jboolean result = JNI_FALSE;51#if defined(J9VM_GC_FINALIZATION)52J9JavaVM *vm = ((J9VMThread*)env)->javaVM;53J9MemoryManagerFunctions *mmFuncs = vm->memoryManagerFunctions;54if (0 != mmFuncs->j9gc_wait_for_reference_processing(vm)) {55result = JNI_TRUE;56}57#endif58return result;59}6061#if JAVA_SPEC_VERSION >= 1662jboolean JNICALL63Java_java_lang_ref_Reference_refersTo(JNIEnv *env, jobject reference, jobject target)64{65J9VMThread * const currentThread = (J9VMThread *)env;66J9JavaVM * const vm = currentThread->javaVM;67J9InternalVMFunctions * const vmFuncs = vm->internalVMFunctions;68jboolean result = JNI_FALSE;6970vmFuncs->internalEnterVMFromJNI(currentThread);7172if (NULL == reference) {73vmFuncs->setCurrentException(currentThread, J9VMCONSTANTPOOL_JAVALANGNULLPOINTEREXCEPTION, NULL);74} else {75j9object_t j9reference = J9_JNI_UNWRAP_REFERENCE(reference);76j9object_t j9target = (NULL != target) ? J9_JNI_UNWRAP_REFERENCE(target) : NULL;77j9object_t referent = J9VMJAVALANGREFREFERENCE_REFERENT_VM(vm, j9reference);7879if (referent == j9target) {80result = JNI_TRUE;81}82}8384vmFuncs->internalExitVMToJNI(currentThread);8586return result;87}88#endif /* JAVA_SPEC_VERSION >= 16 */8990} /* extern "C" */919293