-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix the concurrency semantics for Gc<T>
.
#54
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use std::{env, path::PathBuf, process::Command}; | ||
|
||
use lang_tester::LangTester; | ||
use tempfile::TempDir; | ||
|
||
fn deps_path() -> String { | ||
let mut path = PathBuf::new(); | ||
path.push(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
path.push("target"); | ||
#[cfg(debug_assertions)] | ||
path.push("debug"); | ||
#[cfg(not(debug_assertions))] | ||
path.push("release"); | ||
path.push("deps"); | ||
|
||
path.to_str().unwrap().to_owned() | ||
} | ||
|
||
fn main() { | ||
let rustc = env::var("RUSTGC").expect("RUSTGC environment var not specified"); | ||
// We grab the rlibs from `target/<debug | release>/` but in order | ||
// for them to exist here, they must have been moved from `deps/`. | ||
// Simply running `cargo test` will not do this, instead, we must | ||
// ensure that `cargo build` has been run before running the tests. | ||
|
||
#[cfg(debug_assertions)] | ||
let build_mode = "--debug"; | ||
#[cfg(not(debug_assertions))] | ||
let build_mode = "--release"; | ||
|
||
Command::new("cargo") | ||
.args(&["build", build_mode]) | ||
.env("RUSTC", &rustc.as_str()) | ||
.output() | ||
.expect("Failed to build libs"); | ||
|
||
let tempdir = TempDir::new().unwrap(); | ||
LangTester::new() | ||
.test_dir("gc_tests/tests") | ||
.test_file_filter(|p| p.extension().unwrap().to_str().unwrap() == "rs") | ||
.test_extract(|s| { | ||
Some( | ||
s.lines() | ||
.take_while(|l| l.starts_with("//")) | ||
.map(|l| &l[2..]) | ||
.collect::<Vec<_>>() | ||
.join("\n"), | ||
) | ||
}) | ||
.test_cmds(move |p| { | ||
let mut exe = PathBuf::new(); | ||
exe.push(&tempdir); | ||
exe.push(p.file_stem().unwrap()); | ||
|
||
let mut compiler = Command::new(&rustc); | ||
compiler.args(&[ | ||
"-L", | ||
deps_path().as_str(), | ||
p.to_str().unwrap(), | ||
"-o", | ||
exe.to_str().unwrap(), | ||
]); | ||
|
||
vec![("Compiler", compiler), ("Run-time", Command::new(exe))] | ||
}) | ||
.run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Run-time: | ||
// status: success | ||
#![feature(rustc_private)] | ||
|
||
extern crate libgc; | ||
|
||
use std::alloc::GcAllocator; | ||
use std::{thread, time}; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use libgc::Gc; | ||
|
||
#[global_allocator] | ||
static ALLOCATOR: GcAllocator = GcAllocator; | ||
|
||
struct PanicOnDrop(String); | ||
|
||
impl Drop for PanicOnDrop { | ||
fn drop(&mut self) { | ||
eprintln!("Finalizer called. Object erroneously collected"); | ||
} | ||
|
||
} | ||
|
||
static mut NO_CHILD_EXISTS: AtomicBool = AtomicBool::new(true); | ||
|
||
fn main() { | ||
for _ in 1..10 { | ||
thread::spawn(child); | ||
} | ||
|
||
while(unsafe { NO_CHILD_EXISTS.load(Ordering::SeqCst) }) {}; | ||
|
||
// This should collect no garbage, because the call stacks of each child | ||
// thread should be scanned for roots. | ||
GcAllocator::force_gc(); | ||
|
||
// If there's a problem, a finalizer will print to stderr. Lets wait an | ||
// appropriate amount of time for this to happen. | ||
thread::sleep(time::Duration::from_millis(10)); | ||
} | ||
|
||
fn child() { | ||
unsafe { NO_CHILD_EXISTS.store(false, Ordering::SeqCst)}; | ||
let gc = Gc::new(String::from("Hello world!")); | ||
|
||
// Wait a bit before dying, ensuring that the thread stays alive long enough | ||
// cross the force_gc call. | ||
thread::sleep(time::Duration::from_millis(10)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/cross/across/ (assuming there's nothing to do with anger here :p ). I also wonder if we should make the test more robust by waiting on a mutex / bool or something? The problem is that there's no guarantee that
force_gc
will happen in 10ms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ha, I was actually missing a "to" after enough there. Yeah it's a bit flakey, 17c25c1 should make it less so. It's hard not to have false-negatives with these tests, but if the test does fail, something is certainly wrong.