[crac] RFR: Fix: arguments supplied to restore are split with whitespace

YizhePKU duke at openjdk.org
Tue Aug 29 11:47:03 UTC 2023


This PR fixes a bug that causes arguments with whitespaces to be split into multiple arguments during restore.

It contains two commits. The first commit is refactor only. It moves all side effects from `CracRestoreParameters` to the call sites, and changes the type of `CracRestoreParameters::args` from a single string to a `GrowableArray` of strings. Serialization code is also cleaned up a bit.

The second commit fixes the bug by introducing a new pseudo property, `-DCRaCJavaMainArgs`, that is set in `JavaMain`. An instance of `JavaMainArgs` (containing `argc` and `argv`) is stored as extra info of the property, which is later extracted in `Arguments::parse_options_for_restore` and passed to `crac::restore`.

Potential issues:

* We use `putenv` to modify environment variables, which expects `char*`. In this PR, I'm `const_cast`ing from `const char*` to `char*`, since I believe `putenv` doesn't actually modify the string. Is that OK? Maybe rewriting with `setenv` would be better?
* `read_growable_array` is implemented by reading byte-at-a-time from the shared memory. Will it be too slow? I could rewrite it to read everything at once (like the original code did), but the current implementation is cute and I kinda want to keep it.

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

Commit messages:
 - Rename property to jdk.internal.crac.mainArgs
 - Add const where it makes sense
 - Fix: restore with arguments now property parses input with whitespace
 - Refactor: remove side effects from CracRestoreParameters

Changes: https://git.openjdk.org/crac/pull/101/files
 Webrev: https://webrevs.openjdk.org/?repo=crac&pr=101&range=00
  Stats: 458 lines in 8 files changed: 234 ins; 164 del; 60 mod
  Patch: https://git.openjdk.org/crac/pull/101.diff
  Fetch: git fetch https://git.openjdk.org/crac.git pull/101/head:pull/101

PR: https://git.openjdk.org/crac/pull/101


More information about the crac-dev mailing list