New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8271569: Clean up the use of CDS constants and field offsets #5450
Conversation
/label add hotspot-runtime |
|
@yminqi |
Webrevs
|
Hi Yumin,
There's obviously a lot more going on here than just a simple rename so I think the JBS issue should be changed accordingly.
A few minor comments below.
Thanks,
David
}; | ||
|
||
size_t get_cds_offset(const char* name) { | ||
for (int i = 0; i < (int)(sizeof(cds_offsets)/sizeof(cds_offsets[0])); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just define a size for the array and use that? It isn't really a dynamic/unknown quantity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The array size is known at compile time --- it is not dynamic but we do not need to manually count the size of the array this way. If define a size for the array, we need to count the number of items in the array to define the array size. We may add more items to the array --- just add items and don't need change anything else. Since total array memory size and array component size are known at compile time, so compiler will not generate code to calculate the size. How about this?
const int size = (int)(sizeof(cds_offsets)/sizeof(cds_offsets[0]));
for (int i = 0; i < size; i++) {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always thought that was a hack way of determining an array size, not an approved method. :(
Don't worry just leave it as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have functionality for this in globalDefinitions.hpp:
#define ARRAY_SIZE(array) sizeof(array_size_impl(array))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stefank Thanks --- it saves code size.
src/hotspot/share/cds/filemap.hpp
Outdated
@@ -208,10 +208,11 @@ class FileMapHeader: private CDSFileMapHeaderBase { | |||
// The following fields are all sanity checks for whether this archive | |||
// will function correctly with this JVM and the bootclasspath it's | |||
// invoked with. | |||
public: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again this looks like it should be private with either a public accessor or else a friend declaration for the client code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same reason as above.
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include <cstddef> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not stated in the style guide, but I think most files include the system headers after the HotSpot headers, separated by a blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this even needed now? I don't see it being used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, the layout that I'd like to see is:
#include "precompiled.hpp"
#include "cds.hpp"
...
#include "cds/filemap.hpp"
#include <cstddef>
However, I think the more appropriate change is to include globalDefinitions.hpp instead of explicitly including cstddef.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pre-submit tests failed to build hotspot for linux on arm/ppc/s390 etc after removed. needed for defining size_t. So will add it back at last section of 'include'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Ioi - use stddefs.h in cds.h
}; | ||
|
||
size_t get_cds_offset(const char* name) { | ||
for (int i = 0; i < (int)(sizeof(cds_offsets)/sizeof(cds_offsets[0])); i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have functionality for this in globalDefinitions.hpp:
#define ARRAY_SIZE(array) sizeof(array_size_impl(array))
…made CDSConstants a friend class of accessed classes
{ "static_magic", (int)CDS_ARCHIVE_MAGIC }, | ||
{ "dynamic_magic", (int)CDS_DYNAMIC_ARCHIVE_MAGIC }, | ||
{ "int_size", sizeof(int) }, | ||
{ "CDSFileMapRegion_size", sizeof(CDSFileMapRegion) }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be (int)sizeof(int)
because the type of sizeof(...)
is implementation-defined. See https://en.cppreference.com/w/cpp/types/size_t
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that all almost all (except for 'magic') with size_t, we should use name vs size_t in the struct and get functions, cast when return from vm in whiteBox.cpp.
…om type int to size_t
Hi Yumin,
Updates seem okay to me. One query below.
Thanks,
David
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include <cstddef> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this even needed now? I don't see it being used.
@yminqi This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 66 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.
|
*/ | ||
|
||
#include "precompiled.hpp" | ||
#include <cstddef> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear, the layout that I'd like to see is:
#include "precompiled.hpp"
#include "cds.hpp"
...
#include "cds/filemap.hpp"
#include <cstddef>
However, I think the more appropriate change is to include globalDefinitions.hpp instead of explicitly including cstddef.
friend class VMStructs; | ||
friend class CDSConstants; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to sort the classes alphabetically. CDSConstants should come before VMStructs.
/integrate |
Going to push as commit 9c5441c.
Your commit was automatically rebased without conflicts. |
Changed cdsOffsets.cpp to cdsConstants.cpp, now the offsets and constants are initialized static and searched separately.
The offsets array could not use 'constexpr' since g++ on MacOs and VSC++ on Windows complained reinterpret_cast in 'offset_of' should not be used in constexpr initialization. Changed some field access for forming global list first.
Note with 'git mv' to rename cdsoffset.cpp to cdsConstants.cpp, same for cdsoffsets.hpp to cdsConstants.hpp, due to the contents changed more than 50% so git will not think cdsConstants.cpp is renamed from cdsoffsets.cpp. Instead, it is regarded as a new file.
Tests: ter1-4
Thanks
Yumin
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/5450/head:pull/5450
$ git checkout pull/5450
Update a local copy of the PR:
$ git checkout pull/5450
$ git pull https://git.openjdk.java.net/jdk pull/5450/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 5450
View PR using the GUI difftool:
$ git pr show -t 5450
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/5450.diff