On Sat, 28 Mar 2026 02:24:14 GMT, Yasumasa Suenaga <[email protected]> wrote:

> On the review for [JDK-8380955](https://bugs.openjdk.org/browse/JDK-8380955) 
> (#30443), `Linker` and `FunctionDescriptor` do not need to be value based 
> class because they would not be treated as "value".
> `Linker` is defined as providing a way to look up the canonical layouts 
> associated with the data types used by the ABI. `FunctionDescriptor` 
> represents the signature of a foreign function. They are not "value".
> 
> Actually they and their child (final) classes do not have `@ValueBased`, thus 
> `javac` and `-XX:DiagnoseSyncOnValueBasedClasses` cannot identify if they are 
> used in anti-pattern of value based class. Thus this change does not change 
> behavior, just documentation updates.

@mcimadamore I left the reply for 
https://github.com/openjdk/jdk/pull/30443#issuecomment-4161141979 here.

> For instance, the Linker uses FD as keys in maps

Can you show some example(s)? I checked JDK source with `grep -nr 
FunctionDescriptor * | grep Map`, but I couldn't find out. (I know that might 
not be enough)

I think the class should be labeled "value based class" depending on the use 
case.

In `MemoryLayout`, the user might want to branch the process like `instanceof` 
like following. So it is ok to be labeld "value based class".
(I know we cannot use `==` for value based class, but I use it here for 
explanation because "value based" would be like "value" in the future)

void process(MemoryLayout layout, MemorySegment data) {
  if (layout == LAYOUT_FOR_A) {
    procA(data);
  } else if (layout == LAYOUT_FOR_B) {
    procB(data);
  }
}


In `FunctionDescriptor`, it might be used like in above, but I feel it is 
tricky because the caller have to know return type and argument types when 
calling. I think `MethodHandle` is equivalent with function pointer, and 
`FunctionDescriptor` is equivalent with `typedef` for the function in C. In 
that context, I feel it is no (or rare) use case to treat `FunctionDescriptor` 
as "value".

It is the reason why I proposed to remove "value-based" from 
`FunctionDescriptor`. I agree it can be "value" because it is composed by 
value-based fields, but it is not a result of evaluation for the class.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/30481#issuecomment-4167407320

Reply via email to