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.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

> @mcimadamore I left the reply for [#30443 
> (comment)](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)

https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/foreign/abi/AbstractLinker.java#L88

> 
> 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".

I'm not seeing what the problem is here. If you have a function descriptor for 
`(JAVA_INT)->JAVA_LONG` it might be sometimes helpful to compare it (maybe, 
eventually, with `==`) with some other function descriptor. The fact that it 
might not super common for it being used this way doesn't make it less 
value-based.

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

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

Reply via email to