Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions ddprof-lib/src/main/cpp/vmStructs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,17 +808,22 @@ int NMethod::findScopeOffset(const void *pc) {
}

int ScopeDesc::readInt() {
unsigned char c = *_stream++;
unsigned int n = c - _unsigned5_base;
if (c >= 192) {
for (int shift = 6;; shift += 6) {
c = *_stream++;
n += (c - _unsigned5_base) << shift;
if (c < 192 || shift >= 24)
break;
unsigned char c = *_stream++;
if (c < _unsigned5_base) {
return 0;
}
}
return n;
unsigned int n = c - _unsigned5_base;
if (c >= 192) {
for (int shift = 6; ; shift += 6) {
c = *_stream++;
if (c < _unsigned5_base) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is this not an indication of a race condition and we should retry the read ?
The previous byte indicated we were expecting something, so having 0 here is unexpected.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

reads of NMethods are generally racy - we're reading them from a process-wide codecache which can change even when the sampled thread is halted in a signal handler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The more valid fix would then be to bail out.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems that the problem is rather insidious - the _unsigned5_base is set up depending on the JVM version but that is subtly broken for Java 8 - see #136

I am going to fix that problem first and if that does not stop the asan errors we can revisit this later.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems that after #142 we are not getting to shifting a negative value.
I would keep this PR open for ~1 week to be sure the problem is fixed and then close it.

break;
}
n += (c - _unsigned5_base) << shift;
if (c < 192 || shift >= 24) break;
}
}
return n;
}

bool VMStructs::isSafeToWalk(uintptr_t pc) {
Expand Down