Skip to content

Conversation

rvansa
Copy link
Collaborator

@rvansa rvansa commented Sep 30, 2025

Right now the logic checking if CPU features used before checkpoint match current CPU features is in VM code. VM stores and retrieves CPU features through C/R API's user_data extension. This is convenient when we have a single image that can be either accepted or rejected, but does not offer the flexibility for C/R engine to select the best image for current execution environment.

The goal of this issue is to move to a declarative API that will express the requirements using more abstract means, labels (for CPU architecture) and bitmaps (for CPU features).


Progress

  • Change must not contain extraneous whitespace

Issue

  • JDK-8368929: [CRaC] Move CPUFeatures check to C/R engine (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/crac.git pull/266/head:pull/266
$ git checkout pull/266

Update a local copy of the PR:
$ git checkout pull/266
$ git pull https://git.openjdk.org/crac.git pull/266/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 266

View PR using the GUI difftool:
$ git pr show -t 266

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/crac/pull/266.diff

Using Webrev

Link to Webrev Comment

@rvansa rvansa requested a review from TimPushkin September 30, 2025 13:17
@rvansa
Copy link
Collaborator Author

rvansa commented Sep 30, 2025

@jankratochvil Please give this a review, since you've authored most of the modified code.

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 30, 2025

👋 Welcome back rvansa! A progress list of the required criteria for merging this PR into crac will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 30, 2025

@rvansa This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8368929: [CRaC] Move CPUFeatures check to C/R engine

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 1 new commit pushed to the crac branch:

  • 5abb5da: 8368570: [CRaC] Improve JdwpTransportTest

Please see this link for an up-to-date comparison between the source branch of this pull request and the crac branch.
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.

➡️ To integrate this PR with the above commit message to the crac branch, type /integrate in a new comment.

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 30, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 30, 2025

Webrevs

Comment on lines +80 to +85
#define RESTORE_ERROR_UNKNOWN -1 // generic error
#define RESTORE_ERROR_NOT_FOUND -2 // image location does not contain an image
#define RESTORE_ERROR_NO_ACCESS -3 // image cannot be accessed/retrieved (permissions or I/O issue)
#define RESTORE_ERROR_INVALID -4 // image is not suitable (e.g. corruption or wrong architecture)
#define RESTORE_ERROR_MEMORY -5 // memory allocation failure during restore
#define RESTORE_ERROR_PROCINFO -6 // the process cannot fetch information about itself
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot it be an enum?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API already defines return value as int, we don't want to change that part.

Copy link
Collaborator

@TimPushkin TimPushkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding crexec changes, I wonder if it would be easier for us to use the C++ stdlib fully (std::vector, std::unordered_map) catching all exceptions...

Comment on lines +615 to +617
static constexpr size_t print_buffer_length() {
return MAX_CPU_FEATURES;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe by the time the corresponding printing function is used the resource area is already initialized. It thus should be possible to make it allocate a resource array internally instead of making the callers use this to allocate on stack. Or there can be two functions: one that uses a provided buffer and its wrapper that allocates a resource array.

}

T& add(T&& item) {
Node *node = new(std::nothrow) Node();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should do a null check after this

Comment on lines +38 to +42
Node *_head;
Node *_tail;
size_t _size;
public:
LinkedList(): _head(nullptr), _tail(nullptr), _size(0) {}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Node *_head;
Node *_tail;
size_t _size;
public:
LinkedList(): _head(nullptr), _tail(nullptr), _size(0) {}
Node *_head = nullptr;
Node *_tail = nullptr;
size_t _size = 0;
public:

}
}

size_t size() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
size_t size() {
size_t size() const {

Comment on lines +68 to +74
template<typename Func> void foreach(Func f) const {
Node *node = _head;
while (node) {
f(node->_item);
node = node->_next;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't insist but implementing an std::iterator does not seem too cumbersome and would allow to use the normal for loop

Comment on lines +144 to +146
while (fgets(line, sizeof(line), f)) {
char *eq = strchr(line, '=');
char *nl = strchr(eq + 1, '\n');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe parsing will be broken if = is encountered in the tag name itself. Same for \n although that is less likely.

if (f == nullptr) {
return errno == ENOENT ? RESTORE_ERROR_NOT_FOUND : RESTORE_ERROR_NO_ACCESS;
}
char line[strlen(BITMAP_PREFIX) + _max_name_length + 1 + _max_value_length + 2];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR MSVC does not support arrays of non-constexpr size

Comment on lines +155 to +160
tags.add({
.type = LABEL,
.name = strdup(line + strlen(LABEL_PREFIX)),
.data = strdup(eq + 1),
.data_length = (size_t) (nl - eq),
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error checking here and below (add, strdup, malloc)

Comment on lines 141 to +142
&user_data_extension.header,
&image_constraints_extension.header,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we replace the direct use of user data with this new extension it should be a bit more efficient to put the new extension above the old one

Comment on lines +834 to 837
int error = conf->image_constraints().validate(conf->argv()[ARGV_IMAGE_LOCATION]);
if (error) {
return error;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: let's move this before initializing restore_data_str as this is a part of argument validation while restore_data_str and below is preparation for exec-ing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

3 participants