JDK-8254364 : Remove leading _ from struct/union declarations in jvmti.h
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: jvmti
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-10-11
  • Updated: 2021-01-18
  • Resolved: 2020-10-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b20Fixed
Related Reports
Relates :  
Description
The generated jvmti.h file uses a leading underscore for struct/union declarations. E.g., 

    struct _jvmtiTimerInfo;
    typedef struct _jvmtiTimerInfo jvmtiTimerInfo;

It's unclear why this was done (probably to work around really old C compilers that didn't like "typedef struct _jvmtiTimerInfo jvmtiTimerInfo;").

However, this style breaks encapsulation when making a forward declaration of the jvmtiTimerInfo type in a source file unrelated to jvmti. I.e., one must assume the knowledge of a non-public type "struct _jvmtiTimerInfo".

We should remove the leading underscore. Hence, we can make forward declarations like this in C++ source code:

    struct jvmtiTimerInfo;

I.e., "we know that there is a public struct named jvmtiTimerInfo and we don't care what its contents are".


Comments
Changeset: c9ca1bb0 Author: Ioi Lam <iklam@openjdk.org> Date: 2020-10-13 05:22:49 +0000 URL: https://git.openjdk.java.net/jdk/commit/c9ca1bb0
13-10-2020

This issue came up in the discussion for JDK-8252526. See https://mail.openjdk.java.net/pipermail/hotspot-runtime-dev/2020-September/041525.html Reviewers agreed that "struct _jvmtiTimerInfo" is not in the public API so there's no need for a CSR for changing its declaration.
11-10-2020