< prev index next > src/jdk.jdwp.agent/share/native/libjdwp/commonRef.c
Print this page
/*
- * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* deleted and the weak ref inside may be reused (these may happen in
* either order). Using the sequence number
* as the object id prevents ambiguity in the object id when the weak ref
* is reused. The RefNode* is stored with the object as it's JVMTI Tag.
*
+ * References to value objects are always strong.
+ *
* The ref member is changed from weak to strong when
* gc of the object is to be prevented.
* Whether or not it is strong, it is never exported from this module.
*
* A reference count of each jobject is also maintained here. It tracks
/* Returns true if this is a strong reference, meaning that either or both of
isPinAll and isCommonPin are true. */
static jboolean
isStrong(RefNode* node)
{
- return node->isPinAll || node->isCommonPin;
+ return node->isValueObject || node->isPinAll || node->isCommonPin;
}
/* Create a fresh RefNode structure, create a weak ref and tag the object */
static RefNode *
createNode(JNIEnv *env, jobject ref)
{
RefNode *node;
jobject strongOrWeakRef;
jvmtiError error;
jboolean pinAll = gdata->pinAllCount != 0;
+ jboolean isValueObject;
/* Could allocate RefNode's in blocks, not sure it would help much */
node = (RefNode*)jvmtiAllocate((int)sizeof(RefNode));
if (node == NULL) {
return NULL;
}
- if (pinAll) {
+ isValueObject = JNI_FUNC_PTR(env,IsValueObject)(env, ref);
+
+ if (pinAll || isValueObject) {
/* Create strong reference to make sure we have a reference */
strongOrWeakRef = JNI_FUNC_PTR(env,NewGlobalRef)(env, ref);
} else {
/* Create weak reference to make sure we have a reference */
strongOrWeakRef = JNI_FUNC_PTR(env,NewWeakGlobalRef)(env, ref);
}
/* Fill in RefNode */
node->ref = strongOrWeakRef;
node->count = 1;
+ node->isValueObject = isValueObject;
node->isPinAll = pinAll;
node->isCommonPin = JNI_FALSE;
node->seqNum = newSeqNum();
/* Count RefNode's created */
/* Change a RefNode to have a weak reference */
static jweak
weakenNode(JNIEnv *env, RefNode *node, jboolean isUnpinAll)
{
- jboolean willStillBeStrong = (node->isPinAll && !isUnpinAll) || (node->isCommonPin && isUnpinAll);
+ jboolean willStillBeStrong = node->isValueObject || (node->isPinAll && !isUnpinAll) || (node->isCommonPin && isUnpinAll);
// If the node is strong, but the reason(s) for it being strong
// will no longer exist, then weaken it.
if (isStrong(node) && !willStillBeStrong) {
jweak weakRef;
< prev index next >