Skip to content
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

8265465: jcmd VM.cds should keep already dumped archive when exception happens #3886

Closed
wants to merge 5 commits into from

Conversation

yminqi
Copy link
Contributor

@yminqi yminqi commented May 5, 2021

Hi, Please review
When using jcmd to dump shared archive, if the archive name exists, it will be deleted first. If exception happens during dumping process, there is no new archive created. This PR changes to first dump the archive with a temporary file name. With successful dump, the temporary file will be rename to its given name. This way the old archive will not be touched on exception.
The newly added test case skipped testing on Windows since File operation result is not same as on Linux.

Tests: tier1,tier2,tier3,tier4

Thanks
Yumin


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8265465: jcmd VM.cds should keep already dumped archive when exception happens

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3886/head:pull/3886
$ git checkout pull/3886

Update a local copy of the PR:
$ git checkout pull/3886
$ git pull https://git.openjdk.java.net/jdk pull/3886/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3886

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3886.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 5, 2021

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

@openjdk openjdk bot added the rfr label May 5, 2021
@openjdk
Copy link

openjdk bot commented May 5, 2021

@yminqi The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-runtime

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot-runtime core-libs labels May 5, 2021
@mlbridge
Copy link

mlbridge bot commented May 5, 2021

Webrevs

fileArchive.delete();
}
String tempFileName = getArchiveFileName(archiveFileName);
File tempArchiveFile = new File(tempFileName);
Copy link
Member

@iklam iklam May 5, 2021

Choose a reason for hiding this comment

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

I think the logic is too complicated. We can always write the archive to a temp file, and then rename it to the actual file. Also, to be consistent with the other variables, it should be tempArchiveFileName

String tempArchiveFileName = archiveFileName + ".tmp";

Copy link
Contributor Author

@yminqi yminqi May 5, 2021

Choose a reason for hiding this comment

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

getArchiveFileName also operates on create/delete temp file, so if that fails, throw exception back to caller. Do you think the logic should be kept?

Copy link
Member

@iklam iklam May 5, 2021

Choose a reason for hiding this comment

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

How about:

File tempArchiveFile = new File(tempArchiveFileName);
tempArchiveFile.createNewFile(); // will throw exception if we cannot write to the directory.
tempArchiveFile.delete();


public static void main(String... args) throws Exception {
if (Platform.isWindows()) {
// ON windows, File operation resulted difference from other OS.
Copy link
Member

@iklam iklam May 5, 2021

Choose a reason for hiding this comment

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

Could you explain what the differences are?

Copy link
Contributor Author

@yminqi yminqi May 5, 2021

Choose a reason for hiding this comment

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

Will add detail explanation.

* @build JCmdTestLingeredApp JCmdTestFileSecurity
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
* @run main/othervm/timeout=480 -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JCmdTestFileSecurity
*/
Copy link
Member

@iklam iklam May 5, 2021

Choose a reason for hiding this comment

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

"Security" is usually used for Java language security. I think it's better to call this test JCmdTestFileSafety.

Copy link
Contributor Author

@yminqi yminqi May 5, 2021

Choose a reason for hiding this comment

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

Sure.

String localFileName = "MyStaticDump.jsa";
test(localFileName, pid, noBoot, EXPECT_PASS);
File targetFile = CDSTestUtils.getOutputDirAsFile();
targetFile.setWritable(false);
Copy link
Member

@iklam iklam May 5, 2021

Choose a reason for hiding this comment

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

getOutputDirAsFile returns the current directory. Other test code may write to this directory. I think it's better to specify:

localFileName = "subdir" + File.separator() + "MyStaticDump.jsa";

and set subdir to be non-writeable.

Also, the local variable should be targetDir instead of targetFile.

Copy link
Contributor Author

@yminqi yminqi May 5, 2021

Choose a reason for hiding this comment

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

Will try this, not sure if the subdir and the file can be created with current code. May be some extra code needed.
Thanks for the review!

@openjdk openjdk bot removed the rfr label May 6, 2021
@openjdk openjdk bot added the rfr label May 6, 2021
iklam
iklam approved these changes May 6, 2021
Copy link
Member

@iklam iklam left a comment

The latest version LGTM

// Set target dir not writable, do dynamic dump
print2ln(test_count++ + " Set target dir not writable, do dynamic dump");
setKeepArchive(true);
outputDirFile.setWritable(true);
Copy link
Member

@calvinccheung calvinccheung May 6, 2021

Choose a reason for hiding this comment

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

Should the comment be // Set target dir writable ... ? (since you're setting the dir to writable at line 78)

Copy link
Contributor Author

@yminqi yminqi May 7, 2021

Choose a reason for hiding this comment

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

The comment is for the testing item --- that is consistent with println contents.
The first set 'true' is for get the archive and keep the archive, the real test is after set it to 'false', the test will fail and we check the previous archive still available.

Copy link
Member

@calvinccheung calvinccheung May 7, 2021

Choose a reason for hiding this comment

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

I see.

// cannot dynamically dump twice, restart
app = createLingeredApp("-cp", allJars, "-XX:+RecordDynamicDumpInfo");
pid = app.getPid();
outputDirFile.setWritable(false);
test(localFileName, pid, noBoot, EXPECT_FAIL);
outputDirFile.setWritable(true);
Copy link
Member

@calvinccheung calvinccheung May 7, 2021

Choose a reason for hiding this comment

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

Would the test fail without setting the dir not writable at line 87?

Copy link
Contributor Author

@yminqi yminqi May 7, 2021

Choose a reason for hiding this comment

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

See reply above.

Copy link
Member

@calvinccheung calvinccheung left a comment

I have 2 questions on the test.

@yminqi
Copy link
Contributor Author

yminqi commented May 7, 2021

/integrate

@yminqi
Copy link
Contributor Author

yminqi commented May 7, 2021

@iklam @calvinccheung Thanks for review!

@openjdk
Copy link

openjdk bot commented May 7, 2021

@yminqi This PR has not yet been marked as ready for integration.

@yminqi
Copy link
Contributor Author

yminqi commented May 7, 2021

/label remove core-libs

@openjdk openjdk bot removed the core-libs label May 7, 2021
@openjdk
Copy link

openjdk bot commented May 7, 2021

@yminqi
The core-libs label was successfully removed.

@yminqi yminqi changed the title 8265465: jcmd VM.cds should keep already dumped archive when exceptions happens 8265465: jcmd VM.cds should keep already dumped archive when exception happens May 7, 2021
@openjdk
Copy link

openjdk bot commented May 7, 2021

@yminqi 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:

8265465: jcmd VM.cds should keep already dumped archive when exception happens

Reviewed-by: iklam, ccheung

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 24 new commits pushed to the master branch:

  • 66191ff: 8266193: BasicJMapTest does not include testHistoParallel methods
  • 36e5ad6: 8263236: runtime/os/TestTracePageSizes.java fails on old kernels
  • 0ca86da: 8266002: vmTestbase/nsk/jvmti/ClassPrepare/classprep001 should skip events for unexpected classes
  • 52f1db6: 8262002: java/lang/instrument/VerifyLocalVariableTableOnRetransformTest.sh failed with "TestCaseScaffoldException: DummyClassWithLVT did not match .class file"
  • 04f7112: 8266293: Key protection using PBEWithMD5AndDES fails with "java.security.InvalidAlgorithmParameterException: Salt must be 8 bytes long"
  • a90b33a: 8266573: Make sure blackholes are tagged for all JVMCI paths
  • 2dcbedf: 8266044: Nested class summary should show kind of class or interface
  • e840597: 8266460: java.io tests fail on null stream with upgraded jtreg/TestNG
  • fcedfc8: 8266579: Update test/jdk/java/lang/ProcessHandle/PermissionTest.java & test/jdk/java/sql/testng/util/TestPolicy.java
  • c665dba: 8266561: Remove Compile::_save_argument_registers
  • ... and 14 more: https://git.openjdk.java.net/jdk/compare/6018336fc5e93675482b92df76594712c238adda...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label May 7, 2021
@yminqi
Copy link
Contributor Author

yminqi commented May 7, 2021

/integrate

@openjdk openjdk bot closed this May 7, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels May 7, 2021
@openjdk
Copy link

openjdk bot commented May 7, 2021

@yminqi Since your change was applied there have been 24 commits pushed to the master branch:

  • 66191ff: 8266193: BasicJMapTest does not include testHistoParallel methods
  • 36e5ad6: 8263236: runtime/os/TestTracePageSizes.java fails on old kernels
  • 0ca86da: 8266002: vmTestbase/nsk/jvmti/ClassPrepare/classprep001 should skip events for unexpected classes
  • 52f1db6: 8262002: java/lang/instrument/VerifyLocalVariableTableOnRetransformTest.sh failed with "TestCaseScaffoldException: DummyClassWithLVT did not match .class file"
  • 04f7112: 8266293: Key protection using PBEWithMD5AndDES fails with "java.security.InvalidAlgorithmParameterException: Salt must be 8 bytes long"
  • a90b33a: 8266573: Make sure blackholes are tagged for all JVMCI paths
  • 2dcbedf: 8266044: Nested class summary should show kind of class or interface
  • e840597: 8266460: java.io tests fail on null stream with upgraded jtreg/TestNG
  • fcedfc8: 8266579: Update test/jdk/java/lang/ProcessHandle/PermissionTest.java & test/jdk/java/sql/testng/util/TestPolicy.java
  • c665dba: 8266561: Remove Compile::_save_argument_registers
  • ... and 14 more: https://git.openjdk.java.net/jdk/compare/6018336fc5e93675482b92df76594712c238adda...master

Your commit was automatically rebased without conflicts.

Pushed as commit 43ad24f.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@yminqi yminqi deleted the jdk-8265465 branch May 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime integrated
3 participants