RFR: 8271569: Clean up the use of CDS constants and field offsets [v7]

Ioi Lam iklam at openjdk.java.net
Wed Sep 15 00:00:12 UTC 2021


On Tue, 14 Sep 2021 22:47:53 GMT, Yumin Qi <minqi at openjdk.org> wrote:

>> The problem is here in cdsConstants.hpp
>> 
>> 
>> #include "memory/allStatic.hpp"
>> typedef struct {
>>   const char* _name;
>>   size_t _value;
>> } CDSConst;
>> 
>> 
>> globalDefinitions.hpp should be included here for the declaration of `size_t`.
>
> Yes, but it still failed for non-pch since cds.h is before cdsConstants.hpp. size_t in cds.h is not defined yet. Should I add it to cds.h?

This is a bit complicated. The file is src/hotspot/share/include/cds.h, and the HotSpot convention for including files in this directory usually drops the "include/" part. E.g.,


#include "jvm.h"


But this will put `#include "cds.h"` at the very beginning of all includes, so it doesn't take up `size_t` which is indirectly declared later via globalDefinitions.hpp.

However, header files in src/hotspot/share/ may be included by C/C++ files outside of HotSpot. As a result, these headers cannot include other HotSpot headers. I.e., you cannot put `#include "utilities/globalDefinitions.hpp"` in cds.h, because cds.h is included by src/jdk.hotspot.agent/share/native/libsaproc/ps_core_common.c.

I think one compromise is to add `#include <stddefs.h>` in cds.h. Since cds.h can be included by C source code, we cannot use `#include <cstddef>` which is a C++ thing.  `<stddefs.h>` is part of ANSI C standard and we already include it inside share/utilities/debug.hpp, so we can safely assume that it exists for all compilers that can build HotSpot.

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

PR: https://git.openjdk.java.net/jdk/pull/5450


More information about the hotspot-runtime-dev mailing list