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

Introduce JikesRVM-specific object accessor types #177

Merged
merged 34 commits into from
Sep 3, 2024

Conversation

wks
Copy link
Collaborator

@wks wks commented Aug 28, 2024

The main purpose of this PR is make a clear distinction between the ObjectReference type in JikesRVM and the ObjectReference type in mmtk-core.

This PR introduced JikesObj, a Rust type that represents the JikesRVM-level ObjectReference. It needs an explicit conversion to convert to/from the MMTk-level ObjectReference types.

The interface between mmtk-core and the mmtk-jikesrvm binding is refactored to do fewer things with the MMTk-level ObjectReference.

  • Trait methods that pass ObjectReference to the binding, notably the methods in ObjectModel, now simply convert the MMTk-level ObjectReference to JikesObj, and then call methods of JikesObj.
  • Concrete methods for accessing object headers, fields, and layout information are now implemented by JikesObj (and other wrapper types including TIB and RVMType).
  • The JikesRVMSlot trait now does the conversion between JikesObj and the MMTk-level ObjectReference when loading or storing a slot.

This allows us to change the definition of the MMTk-level ObjectReference in the future, while concrete methods of JikesObj still use offset constants relative to the JikesRVM-level ObjectReference which will not change.

The interface between the Rust part and the Java part of the binding are refactored to involve JikesObj only.

  • API functions in api.rs accept JikesObj parameters from JikesRVM and return JikeObj to JikesRVM where JikesRVM uses the JikesRVM-level ObjectReference.
  • We wrap all JTOC calls into strongly-typed Rust functions, and make the weakly-typed jtoc_call! macro private to the wrappers.

In this way, we ensure none of the API functions or JTOC calls leak the MMTk-level ObjectReference values to JikesRVM, or accidentally interpret a JikesRVM-level ObjectReference as an MMTk-level ObjectReference.

We also do some obvious refactoring that makes the code more readable.:

  • Encapsulated many field-loading statements in the form of (addr + XXXX_OFFSET)::load<T>() into dedicated methods.
  • Encapsulated the code for determining the overhead of hash fields into a function JikesObj::hashcode_overhead and simplified many methods that depend on that.
  • Renaming "edge" to "slot" in RustScanThread.java.

And obvious bug fixes:

  • The call to DO_REFERENCE_PROCESSING_HELPER_SCAN_METHOD_OFFSET used to erroneously interpret 0 as true. This has been fixed by relying on the conversion trait.
  • scan_boot_image_sanity used to declare an immutable array and let unsafe jtoc_call! code modify it. The array is now defined as mutable.

Related issues and PRs:

wks added 4 commits September 2, 2024 16:45
This will ensure we don't accidentally use the weakly-typed macros in
other modules except `jikesrvm_calls` itself.
@wks wks marked this pull request as ready for review September 2, 2024 10:35
@wks
Copy link
Collaborator Author

wks commented Sep 2, 2024

The other PR #179 demonstrates that we can modify MMTk-level ObjectReference to point to JavaHeader and it works.

I have marked this PR as ready for reviewing.

@wks wks requested a review from qinsoon September 2, 2024 10:38
Copy link
Member

@qinsoon qinsoon left a comment

Choose a reason for hiding this comment

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

LGTM. We should run benchmarks, or keep an eye on the perf CI. The frequent cast between JikesObj and ObjectReference with unwrap() may have overheads.

mmtk/src/api.rs Outdated
bytes: usize,
allocator: AllocationSemantics,
) {
memory_manager::post_alloc::<JikesRVM>(unsafe { &mut *mutator }, refer, bytes, allocator)
debug_assert!(!refer.is_null());
Copy link
Member

Choose a reason for hiding this comment

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

The null check seems unnecessary. There is always try_into/from afterwards, which will fail if you have a null reference.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I removed all debug_assert!(!jikes_obj.is_null()); from API functions if the JikesObj parameter is converted to ObjectReference using try_from or try_into.

`ObjectReference::try_from(jikes_obj)` already performs null check, so
we don't need an additional debug_assert for that.
@wks
Copy link
Collaborator Author

wks commented Sep 3, 2024

I can't use moma machines for now. I ran lusearch in DaCapo 2006 locally, with RFastAdaptiveSemiSpace, and see no obvious performance difference.

@wks wks merged commit 7efbc5c into mmtk:master Sep 3, 2024
3 checks passed
wks added a commit that referenced this pull request Sep 3, 2024
This PR changes the definition of MMTk-level `ObjectReference` for the
JikesRVM binding so that it now points to the JavaHeader, and is
different from the JikesRVM-level `ObjectReference` (a.k.a. `JikesObj`).
This will guarantee that the MMTk-level ObjectReference is always inside
an object.

Note that this PR does not involve a change in mmtk-core. It changes
`ObjectModel::IN_OBJECT_ADDRESS_OFFSET` to 0 so that the "in-object
address" is identical to the raw address of `ObjectReference`. It
demonstrates the JikesRVM binding can work well with MMTk-level
`ObjectReference` being different from JikesRVM-level `ObjectReference`.

Related issues and PRs.
-   This PR is based on #177
- This PR is the 2nd step of
#178
- It will ultimately allow mmtk/mmtk-core#1170
to be implemented.
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.

2 participants