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
8257837: Performance regression in heap byte buffer views #1733
Conversation
Add benchmark
|
@mcimadamore The following labels will be automatically applied to this pull request:
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. |
@mcimadamore 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 no new commits pushed to the
|
/integrate |
@mcimadamore Since your change was applied there has been 1 commit pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit 37043b0. |
@@ -1586,7 +1586,8 @@ bool MethodData::profile_unsafe(const methodHandle& m, int bci) { | |||
Bytecode_invoke inv(m , bci); | |||
if (inv.is_invokevirtual()) { | |||
if (inv.klass() == vmSymbols::jdk_internal_misc_Unsafe() || | |||
inv.klass() == vmSymbols::sun_misc_Unsafe()) { | |||
inv.klass() == vmSymbols::sun_misc_Unsafe() || | |||
inv.klass() == vmSymbols::jdk_internal_misc_ScopedMemoryAccess()) { | |||
ResourceMark rm; | |||
char* name = inv.name()->as_C_string(); | |||
if (!strncmp(name, "get", 3) || !strncmp(name, "put", 3)) { |
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.
Pre-existing, but !strncmp(name, "get", 3)
seem a very circumspect way of writing inv->name()->starts_with("get")
- which shouldn't need a ResourceMark
either. Another observation is that inv.klass()
isn't inlined (defined in bytecode.cpp), so introducing a local for inv.klass()
avoids multiple calls. How about this:
if (inv.is_invokevirtual()) {
Symbol* klass = inv.klass();
if (klass == vmSymbols::jdk_internal_misc_Unsafe() ||
klass == vmSymbols::sun_misc_Unsafe() ||
klass == vmSymbols::jdk_internal_misc_ScopedMemoryAccess()) {
Symbol* name = inv.name();
if (name->starts_with("get") || name->starts_with("put")) {
return true;
}
}
}
As a result of the recent integration of the foreign memory access API, some of the buffer implementations now use
ScopedMemoryAccess
instead ofUnsafe
. While this works generally well, there are situations where profile pollution arises, which result in a considerable slowdown. The profile pollution occurs because the same ScopedMemoryAccess method (e.g.getIntUnaligned
) is called with two different buffer kinds (e.g. an off heap buffer where base == null, and an on-heap buffer where base == byte[]). Because of that, unsafe access cannot be optimized, since C2 can't guess what the unsafe base access is.In reality, this problem was already known (and solved) elsewhere: the sun.misc.Unsafe wrapper does basically the same thing that ScopedMemoryAccess does. To make sure that profile pollution does not occur in those cases, argument profiling is enabled for sun.misc.Unsafe as well. This patch adds yet another case for ScopedMemoryAccess.
Here are the benchmark results:
Before:
After
Progress
Issue
Reviewers
Download
$ git fetch https://git.openjdk.java.net/jdk pull/1733/head:pull/1733
$ git checkout pull/1733