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

Integrate deoptimisation into guard failures. #460

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

ptersilie
Copy link
Contributor

Until now we've simply crashed when we encountered a guard failure. This
PR integrates the previously added stackmap parser into our guard
failures so we can read out the live variables at that point. This is
another step towards proper stopgapping, though until we have a stopgap
interpreter we only print out the live variables we've found.

c_tests/run.rs Outdated
@@ -103,6 +103,8 @@ fn mk_compiler(exe: &Path, src: &Path, opt: &str, extra_objs: &[PathBuf]) -> Com
"-Wall",
// Enable LTO with lld.
"-fuse-ld=lld",
// Don't remove frame pointers as we'll need them for guard failures.
"-fno-omit-frame-pointer",
Copy link
Contributor

Choose a reason for hiding this comment

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

So we couldn't address from the stack pointer? I guess it complicates things a lot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I remember correctly this is needed so we can get the return address with __builtin_return_address(0).

Copy link
Contributor

Choose a reason for hiding this comment

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

Before we turn frame pointers off (which, AIUI, can have a big effect on optimisations), we should see if there's another way of doing this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like there's a RA register on x64 which supposedly contains the return address. Let me see if that works.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's the first I've heard of this. Got a link?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, so fno-omit-frame-pointer stores the return address in the RA register. With fomit-frame-pointer this register can be used as general purpose register, which explains why this may have a performance implication. So we may have to read the return address from the stack manually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4cd89ad

c_tests/tests/ptr_global.c Outdated Show resolved Hide resolved
ykcapi/src/lib.rs Outdated Show resolved Hide resolved
ykcapi/src/lib.rs Outdated Show resolved Hide resolved
ykcapi/yk.h Outdated Show resolved Hide resolved
ykcapi/yk.h Outdated Show resolved Hide resolved
ykllvmwrap/src/memman.cc Outdated Show resolved Hide resolved
@ptersilie
Copy link
Contributor Author

Think that's all comments addressed. Should we squash and then wait for @ltratt to have a look?

@vext01
Copy link
Contributor

vext01 commented Jan 5, 2022

@ltratt is bound to have queries and comments. I think we should let him have at least a quick look.

@ptersilie
Copy link
Contributor Author

Yes, I just thought it's less distracting for him if we squash away the already addressed stuff first.

addr: *const usize,
}

impl Registers {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the functions in here, especially as they're unsafe, need doc strings (even if short ones).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a8383f5

}
}

fn get(&self, id: u16) -> usize {
Copy link
Contributor

Choose a reason for hiding this comment

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

Presumably this function (and maybe others?) should be #[cfg(target_arch = "x86_64")].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a8383f5

for l in locs {
match l {
SMLocation::Register(reg, size) => {
eprintln!("Register: {} ({} {})", registers.get(*reg), reg, size);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add FIXMEs before all of these printlns so that they're more likely to be removed sooner rather than later. As you know, I am allergic to debug prints, which are like zombies: they don't die unless extra effort is put into killing them!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in a8383f5

ykcapi/src/lib.rs Show resolved Hide resolved
ykcapi/yk.h Outdated
@@ -48,4 +48,43 @@ YkLocation yk_location_new(void);
// will occur.
void yk_location_drop(YkLocation);

void yk_stopgap(void *addr, uintptr_t size, uintptr_t retaddr, void *rsp);

void __llvm_deoptimize(void* addr, uintptr_t size) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be #[cfg(target_arch = "x86_64")]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0a14653.

ykcapi/yk.h Outdated Show resolved Hide resolved
ykllvmwrap/src/jitmodbuilder.cc Outdated Show resolved Hide resolved
ykllvmwrap/src/jitmodbuilder.cc Outdated Show resolved Hide resolved
// Allocate space for compiled trace address, stackmap address, and stackmap
// size (plus padding).
// FIXME This is a temporary hack until the redesigned hot location is up.
uintptr_t *ptr = (uintptr_t *) malloc(32);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's at least make this malloc(sizeof(uintptr_t) * 3).

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume that the other 8 bytes are the padding the comment mentions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about the padding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, seems like padding isn't needed for malloc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f5ca58d.

yktrace/src/lib.rs Show resolved Hide resolved
@ltratt
Copy link
Contributor

ltratt commented Jan 5, 2022

It's the ID of the register according the the ABI for the platform.

Ah, let's reference that PDF then! Also it's probably worth clearing up why we have both off and id. I think I can guess why, but it's not 100% clear to me.

@ptersilie
Copy link
Contributor Author

It's the ID of the register according the the ABI for the platform.

Ah, let's reference that PDF then! Also it's probably worth clearing up why we have both off and id. I think I can guess why, but it's not 100% clear to me.

The doc string for Registers already mentions the DWARF numbering, but I can try and make it more clear.

@ptersilie
Copy link
Contributor Author

Try e793efb and 8bb62ce

@ptersilie
Copy link
Contributor Author

With @vext01's help found a way to keep omit-frame-pointer and get the return address and previous frame pointer via a different route.

Ready for re-review I think.

ykcapi/yk.h Outdated Show resolved Hide resolved
ykcapi/yk.h Outdated Show resolved Hide resolved
@ltratt
Copy link
Contributor

ltratt commented Jan 6, 2022

I have no comments beyond @vext01's comments.

@ltratt
Copy link
Contributor

ltratt commented Jan 6, 2022

As and when @vext01 is happy, please squash.

@ptersilie
Copy link
Contributor Author

Just 3 more commits for you to review @ltratt and we are ready.

ykcapi/yk.h Outdated Show resolved Hide resolved
@ltratt
Copy link
Contributor

ltratt commented Jan 6, 2022

Please squash.

@ptersilie
Copy link
Contributor Author

Okay to squash?

ykcapi/src/lib.rs Outdated Show resolved Hide resolved
ykcapi/src/lib.rs Outdated Show resolved Hide resolved
ykcapi/src/lib.rs Outdated Show resolved Hide resolved
@ptersilie
Copy link
Contributor Author

Ready for re-review.

@vext01
Copy link
Contributor

vext01 commented Jan 7, 2022

LGTM.

@vext01
Copy link
Contributor

vext01 commented Jan 7, 2022

You need to resolve merge conflicts.

@ptersilie
Copy link
Contributor Author

Squashed and rebased.

@ltratt
Copy link
Contributor

ltratt commented Jan 7, 2022

bors r=

@ltratt
Copy link
Contributor

ltratt commented Jan 7, 2022

bors r+

bors bot added a commit that referenced this pull request Jan 7, 2022
460: Integrate deoptimisation into guard failures. r=ltratt a=ptersilie



Co-authored-by: Lukas Diekmann <lukas.diekmann@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 7, 2022

Build failed:

@ptersilie
Copy link
Contributor Author

Huh, this is odd. The tests succeed if I run them manually. Investigating.

@ptersilie
Copy link
Contributor Author

The failing tests are release tests. Could it be that we don't set the debug printing flag in release mode?

@ptersilie
Copy link
Contributor Author

This should fix it.

@ltratt
Copy link
Contributor

ltratt commented Jan 7, 2022

Please squash.

@ptersilie
Copy link
Contributor Author

Squashed!

@ltratt
Copy link
Contributor

ltratt commented Jan 7, 2022

bors r+

bors bot added a commit that referenced this pull request Jan 7, 2022
460: Integrate deoptimisation into guard failures. r=ltratt a=ptersilie



Co-authored-by: Lukas Diekmann <lukas.diekmann@gmail.com>
@bors
Copy link
Contributor

bors bot commented Jan 7, 2022

Build failed:

@ptersilie
Copy link
Contributor Author

ptersilie commented Jan 7, 2022

Of course I only checked the rust formatting, not the C formatting. Sorry. Ok to squash?

@ltratt
Copy link
Contributor

ltratt commented Jan 7, 2022

Please squash.

Until now we've simply crashed when we encountered a guard failure. This
commit integrates the previously added stackmap parser into our guard
failures so we can read out the live variables at that point. This is
another step towards proper stopgapping, though until we have a stopgap
interpreter we only print out the live variables we've found.
@ptersilie
Copy link
Contributor Author

Squashed.

@ltratt
Copy link
Contributor

ltratt commented Jan 7, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Jan 7, 2022

Build succeeded:

@bors bors bot merged commit e36c537 into ykjit:master Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants