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

Harness hook #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions jikesrvm/rvm/src/org/jikesrvm/VMExt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jikesrvm;

import org.jikesrvm.scheduler.RVMThread;
import org.vmmagic.pragma.Entrypoint;

public class VMExt {
@Entrypoint
public static int enterVM() {
RVMThread cur = RVMThread.getCurrentThread();
int old = cur.getExecStatus();
cur.setExecStatus(RVMThread.IN_JAVA);
return old;
}

@Entrypoint
public static void leaveVM(int status) {
RVMThread cur = RVMThread.getCurrentThread();
cur.setExecStatus(status);
}
}
4 changes: 4 additions & 0 deletions jikesrvm/rvm/src/org/jikesrvm/runtime/Entrypoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class Entrypoints {
"(Lorg/jikesrvm/scheduler/RVMThread;Lorg/vmmagic/unboxed/Address;ZZ)V");
public static final NormalMethod scanBootImageMethod =
getMethod(org.jikesrvm.mm.mminterface.RustScanning.class, "scanBootImage", "(Lorg/vmmagic/unboxed/Address;)V");
public static final NormalMethod enterVMMethod =
getMethod(org.jikesrvm.VMExt.class, "enterVM", "()I");
public static final NormalMethod leaveVMMethod =
getMethod(org.jikesrvm.VMExt.class, "leaveVM", "(I)V");

// The usual causes for getField/Method() to fail are:
// 1. you misspelled the class name, member name, or member signature
Expand Down
20 changes: 16 additions & 4 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,25 @@ pub extern "C" fn add_phantom_candidate(reff: ObjectReference, referent: ObjectR
}

#[no_mangle]
pub extern "C" fn harness_begin(tls: OpaquePointer) {
memory_manager::harness_begin(&SINGLETON, tls)
pub extern "C" fn harness_begin(id: usize) {
unsafe {
let thread_from_id = VMCollection::thread_from_id(id);
Copy link
Member

Choose a reason for hiding this comment

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

How does the application know thread IDs, which are internal to the VM

Copy link
Member Author

Choose a reason for hiding this comment

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

It's the ID from Thread.getId(), which is an application level ID.

Copy link
Member

Choose a reason for hiding this comment

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

Umm, the application level thread ID Thread.getID() is the same as RVMThread.getCurrentThread().getJavaLangThread().getId().
But VMCollection::thread_from_id expects VMThread.getCurrentThread().threadSlot.
Is there any guarantee/code/documentation that suggests they are the same?

let tls = OpaquePointer::from_address(thread_from_id);
let st = JikesRVM::enter_vm(tls);
memory_manager::harness_begin(&SINGLETON, tls);
JikesRVM::leave_vm(tls, st);
}
}

#[no_mangle]
pub extern "C" fn harness_end(tls: OpaquePointer) {
memory_manager::harness_end(&SINGLETON)
pub extern "C" fn harness_end(id: usize) {
unsafe {
let thread_from_id = VMCollection::thread_from_id(id);
let tls = OpaquePointer::from_address(thread_from_id);
let st = JikesRVM::enter_vm(tls);
memory_manager::harness_end(&SINGLETON);
JikesRVM::leave_vm(tls, st);
}
}

#[no_mangle]
Expand Down
13 changes: 13 additions & 0 deletions mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate lazy_static;
extern crate log;

use mmtk::util::address::Address;
use mmtk::util::OpaquePointer;
use mmtk::TraceLocal;
use mmtk::vm::VMBinding;
use mmtk::MMTK;
Expand Down Expand Up @@ -77,6 +78,18 @@ impl JikesRVM {
jtoc_call!(TEST3_METHOD_OFFSET, BOOT_THREAD, input1, input2, input3, input4)
}
}

pub fn enter_vm(tls: OpaquePointer) -> i32 {
unsafe {
jtoc_call!(ENTER_VM_METHOD_OFFSET, tls) as i32
}
}

pub fn leave_vm(tls: OpaquePointer, status: i32) {
unsafe {
jtoc_call!(LEAVE_VM_METHOD_OFFSET, tls, status);
}
}
}

lazy_static! {
Expand Down
2 changes: 1 addition & 1 deletion repos/jikesrvm