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

src: introduce Constant class #303

Closed
wants to merge 1 commit into from

Conversation

mmarchini
Copy link
Contributor

Same idea as CheckedType: instead of relying on the default value for
constants to determine if they were loaded correctly or not (default
value usually was -1), have a class which will have information about
the loaded constant. This can help us:

  • Check if a constant was properly loaded before using it (otherwise
    we'd get into undefined behavior, and there are a lot of places
    where this happens.
  • Check if a constant value was loaded or if we're looking at the
    default value.
  • Explicitly define a constant as optional (constants which are not
    relevant except for specific V8 versions).

This will help us improve reliability and debugability of llnode.

@codecov-io
Copy link

codecov-io commented Oct 1, 2019

Codecov Report

Merging #303 into master will decrease coverage by 1.41%.
The diff coverage is 70.58%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #303      +/-   ##
=========================================
- Coverage   79.02%   77.6%   -1.42%     
=========================================
  Files          33      33              
  Lines        4247    4260      +13     
=========================================
- Hits         3356    3306      -50     
- Misses        891     954      +63
Impacted Files Coverage Δ
src/llv8.h 80.95% <ø> (-2.39%) ⬇️
src/llv8-constants.h 98.48% <ø> (-1.52%) ⬇️
src/error.h 75% <0%> (-10.72%) ⬇️
src/llv8-constants.cc 82.05% <100%> (-1.02%) ⬇️
src/llv8-inl.h 86.66% <100%> (-6.25%) ⬇️
src/constants.cc 72.72% <65.78%> (-8.63%) ⬇️
src/constants.h 77.77% <83.33%> (+11.11%) ⬆️
src/llv8.cc 70.22% <0%> (-2.75%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec01604...ae4e13e. Read the comment docs.

@mmarchini
Copy link
Contributor Author

I'll update the commit message later, but the main reason I started to work on this was to reduce noise from LookupConstant and LoadConstant debug messages. We don't want to see a message if a constant wasn't loaded but the replacement constant was (we were seeing two messages for the same constant in this case). The reduced noise from this PR helped me a lot while working on #255 (PR for that will come after this one lands).

@mmarchini mmarchini force-pushed the constant-class branch 3 times, most recently from b324582 to d819d66 Compare October 3, 2019 22:44
@mmarchini
Copy link
Contributor Author

cc @nodejs/llnode

@mmarchini mmarchini added author ready PRs that have at least one approvals, no pending requests for changes, and a CI started. priority labels Oct 7, 2019
@mmarchini
Copy link
Contributor Author

Ping @nodejs/llnode. This is the main blocker for the patches I have to fix inspection of Node.js v12 core dumps/processes.

(I can rewrite those patches in the old way if this Constant class is not something we want, but from experience the code looks cleaner and easier to debug with this patch)

@mmarchini
Copy link
Contributor Author

Ping @nodejs/llnode @nodejs/diagnostics @nodejs/post-mortem

Copy link
Member

@joyeecheung joyeecheung left a comment

Choose a reason for hiding this comment

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

Can we use a real Constant class with enums instead of std::pair<int64_t, bool>? IMO this is harder to read especially for newcomers.

@mmarchini
Copy link
Contributor Author

Ah, yes, that makes a lot more sense. I'll update the PR once I get a chance (probably later this week). Thank you for the suggestion :)

@mmarchini
Copy link
Contributor Author

  • Changed LookupConstant to return a Constant object instead of std::pair<int64_t, bool>
  • Added a ConstantStatus to replace bool loaded_ and bool valid_
  • Added a comment explaining how the Constant class should be interpreted and used
  • Moved Constant constructors to protected and friended Constants to prevent misuse of the class (it should only be used to load constants).

As before, I kept the original LoadRawConstant and LoadConstant signatures unchanged to avoid a major refactor of llv8-constants.cc in a single PR.

Same idea as CheckedType: instead of relying on the default value for
constants to determine if they were loaded correctly or not (default
value usually was -1), have a class which will have information about
the loaded constant. This can help us:

  - Check if a constant was properly loaded before using it (otherwise
    we'd get into undefined behavior, and there are a lot of places
    where this happens.
  - Check if a constant value was loaded or if we're looking at the
    default value.
  - Explicitly define a constant as optional (constants which are not
    relevant except for specific V8 versions).

This will help us improve reliability and debugability of llnode.
mmarchini added a commit that referenced this pull request Nov 8, 2019
Same idea as CheckedType: instead of relying on the default value for
constants to determine if they were loaded correctly or not (default
value usually was -1), have a class which will have information about
the loaded constant. This can help us:

  - Check if a constant was properly loaded before using it (otherwise
    we'd get into undefined behavior, and there are a lot of places
    where this happens.
  - Check if a constant value was loaded or if we're looking at the
    default value.
  - Explicitly define a constant as optional (constants which are not
    relevant except for specific V8 versions).

This will help us improve reliability and debugability of llnode.

PR-URL: #303
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@mmarchini
Copy link
Contributor Author

Landed in 2afd59e

@mmarchini mmarchini closed this Nov 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approvals, no pending requests for changes, and a CI started.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants