Skip to content
Merged
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
36 changes: 16 additions & 20 deletions doc/language/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ require 'English'

### Exceptions

| Variable | \English | Contains | Initially | Read-Only | Reset By |
|:--------:|:-----------------:|-----------------------------------------|:---------:|:---------:|---------------|
| `$!` | `$ERROR_INFO` | \Exception object or `nil` | `nil` | Yes | Kernel#raise |
| `$@` | `$ERROR_POSITION` | \Array of backtrace positions or `nil` | `nil` | Yes | Kernel#raise |
| Variable | \English | Contains | Initially | Read-Only | Reset By |
|:--------:|:-----------------:|----------------------------------------|:---------:|:---------:|--------------|
| `$!` | `$ERROR_INFO` | \Exception object or `nil` | `nil` | Yes | Kernel#raise |
| `$@` | `$ERROR_POSITION` | \Array of backtrace positions or `nil` | `nil` | Yes | Kernel#raise |

### Pattern Matching

| Variable | \English | Contains | Initially | Read-Only | Reset By |
|:-------------:|:-------------------:|-----------------------------------|:---------:|:---------:|-----------------|
| `$~` | `$LAST_MATCH_INFO` | \MatchData object or `nil` | `nil` | No | Matcher methods |
| `$~` | `$LAST_MATCH_INFO` | \MatchData object or `nil` | `nil` | No | Matcher methods |
| `$&` | `$MATCH` | Matched substring or `nil` | `nil` | No | Matcher methods |
| `` $` `` | `$PRE_MATCH` | Substring left of match or `nil` | `nil` | No | Matcher methods |
| `$'` | `$POST_MATCH` | Substring right of match or `nil` | `nil` | No | Matcher methods |
Expand All @@ -41,15 +41,15 @@ require 'English'

### Streams

| Variable | \English | Contains | Initially | Read-Only | Reset By |
|:---------:|:----------------------------:|:-------------------------------------------:|:---------:|:---------:|----------------------|
| `$stdin` | | Standard input stream | `STDIN` | No | |
| Variable | \English | Contains | Initially | Read-Only | Reset By |
|:---------:|:----------------------------:|---------------------------------------------|:---------:|:---------:|----------------------|
| `$stdin` | | Standard input stream | `STDIN` | No | |
| `$stdout` | | Standard output stream | `STDOUT` | No | |
| `$stderr` | | Standard error stream | `STDERR` | No | |
| `$<` | `$DEFAULT_INPUT` | Default standard input | `ARGF` | Yes | |
| `$>` | `$DEFAULT_OUTPUT` | Default standard output | `STDOUT` | No | |
| `$.` | `$INPUT_LINE_NUMBER`, `$NR` | Input position of most recently read stream | 0 | No | Certain read methods |
| `$_` | `$LAST_READ_LINE` | String from most recently read stream | `nil` | No | Certain read methods |
| `$<` | `$DEFAULT_INPUT` | Default standard input | `ARGF` | Yes | |
| `$>` | `$DEFAULT_OUTPUT` | Default standard output | `STDOUT` | No | |
| `$.` | `$INPUT_LINE_NUMBER`, `$NR` | Input position of most recently read stream | 0 | No | Certain read methods |
| `$_` | `$LAST_READ_LINE` | String from most recently read stream | `nil` | No | Certain read methods |

### Processes

Expand All @@ -64,11 +64,11 @@ require 'English'

### Debugging

| Variable | \English | Contains | Initially | Read-Only | Reset By |
| Variable | \English | Contains | Initially | Read-Only | Reset By |
|:-----------:|:--------:|--------------------------------------------|:----------------------------:|:---------:|----------|
| `$FILENAME` | | Value returned by method `ARGF.filename` | Command-line argument or '-' | Yes | |
| `$DEBUG` | | Whether option `-d` or `--debug` was given | Command-line option | No | |
| `$VERBOSE` | | Whether option `-V` or `-W` was given | Command-line option | No | |
| `$FILENAME` | | Value returned by method `ARGF.filename` | Command-line argument or '-' | Yes | |
| `$DEBUG` | | Whether option `-d` or `--debug` was given | Command-line option | No | |
| `$VERBOSE` | | Whether option `-V` or `-W` was given | Command-line option | No | |

### Other Variables

Expand Down Expand Up @@ -352,10 +352,6 @@ Aliased as `$-v` and `$-w`.

## Other Variables

### `$-a`

Whether command-line option `-a` was given; read-only.

### `$-F`

The default field separator in String#split; must be a String or a
Expand Down
5 changes: 5 additions & 0 deletions gc/mmtk/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ typedef void *MMTk_Address;
typedef void *MMTk_ObjectReference;
typedef void *MMTk_NullableObjectReference;
typedef uint32_t MMTk_AllocationSemantics;

typedef struct MMTk_BumpPointer {
uintptr_t cursor;
uintptr_t limit;
} MMTk_BumpPointer;
"""

[export]
Expand Down
34 changes: 31 additions & 3 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct MMTk_ractor_cache {

MMTk_Mutator *mutator;
bool gc_mutator_p;

MMTk_BumpPointer *bump_pointer;
};

struct MMTk_final_job {
Expand Down Expand Up @@ -447,6 +449,7 @@ rb_gc_impl_ractor_cache_alloc(void *objspace_ptr, void *ractor)
ccan_list_add(&objspace->ractor_caches, &cache->list_node);

cache->mutator = mmtk_bind_mutator(cache);
cache->bump_pointer = mmtk_get_bump_pointer_allocator(cache->mutator);

return cache;
}
Expand Down Expand Up @@ -612,6 +615,24 @@ rb_gc_impl_config_set(void *objspace_ptr, VALUE hash)

// Object allocation

static VALUE
rb_mmtk_alloc_fast_path(struct objspace *objspace, struct MMTk_ractor_cache *ractor_cache, size_t size)
{
MMTk_BumpPointer *bump_pointer = ractor_cache->bump_pointer;
if (bump_pointer == NULL) return 0;

uintptr_t new_cursor = bump_pointer->cursor + size;

if (new_cursor > bump_pointer->limit) {
return 0;
}
else {
VALUE obj = (VALUE)bump_pointer->cursor;
bump_pointer->cursor = new_cursor;
return obj;
}
}

VALUE
rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags, bool wb_protected, size_t alloc_size)
{
Expand All @@ -632,13 +653,20 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags
mmtk_handle_user_collection_request(ractor_cache, false, false);
}

VALUE *alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size + 8, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
alloc_size += sizeof(VALUE);

VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size);
if (!alloc_obj) {
alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
}

alloc_obj++;
alloc_obj[-1] = alloc_size;
alloc_obj[-1] = alloc_size - sizeof(VALUE);
alloc_obj[0] = flags;
alloc_obj[1] = klass;

mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, alloc_size + 8, MMTK_ALLOCATION_SEMANTICS_DEFAULT);
// TODO: implement fast path for mmtk_post_alloc
mmtk_post_alloc(ractor_cache->mutator, (void*)alloc_obj, alloc_size, MMTK_ALLOCATION_SEMANTICS_DEFAULT);

// TODO: only add when object needs obj_free to be called
mmtk_add_obj_free_candidate(alloc_obj);
Expand Down
7 changes: 7 additions & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ typedef void *MMTk_ObjectReference;
typedef void *MMTk_NullableObjectReference;
typedef uint32_t MMTk_AllocationSemantics;

typedef struct MMTk_BumpPointer {
uintptr_t cursor;
uintptr_t limit;
} MMTk_BumpPointer;


#define MMTk_OBJREF_OFFSET 8

Expand Down Expand Up @@ -93,6 +98,8 @@ void mmtk_initialize_collection(MMTk_VMThread tls);

MMTk_Mutator *mmtk_bind_mutator(MMTk_VMMutatorThread tls);

MMTk_BumpPointer *mmtk_get_bump_pointer_allocator(MMTk_Mutator *m);

void mmtk_destroy_mutator(MMTk_Mutator *mutator);

void mmtk_handle_user_collection_request(MMTk_VMMutatorThread tls, bool force, bool exhaustive);
Expand Down
20 changes: 20 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// They are called by C functions and they need to pass raw pointers to Rust.
#![allow(clippy::missing_safety_doc)]

use mmtk::util::alloc::BumpPointer;
use mmtk::util::alloc::ImmixAllocator;
use mmtk::util::options::PlanSelector;
use std::str::FromStr;
use std::sync::atomic::Ordering;
Expand Down Expand Up @@ -174,6 +176,24 @@ pub extern "C" fn mmtk_bind_mutator(tls: VMMutatorThread) -> *mut RubyMutator {
Box::into_raw(memory_manager::bind_mutator(mmtk(), tls))
}

#[no_mangle]
pub unsafe extern "C" fn mmtk_get_bump_pointer_allocator(m: *mut RubyMutator) -> *mut BumpPointer {
match *crate::BINDING.get().unwrap().mmtk.get_options().plan {
PlanSelector::Immix => {
let mutator: &mut Mutator<Ruby> = unsafe { &mut *m };
let allocator =
unsafe { mutator.allocator_mut(mmtk::util::alloc::AllocatorSelector::Immix(0)) };

if let Some(immix_allocator) = allocator.downcast_mut::<ImmixAllocator<Ruby>>() {
&mut immix_allocator.bump_pointer as *mut BumpPointer
} else {
panic!("Failed to get bump pointer allocator");
}
}
_ => std::ptr::null_mut(),
}
}

#[no_mangle]
pub unsafe extern "C" fn mmtk_destroy_mutator(mutator: *mut RubyMutator) {
// notify mmtk-core about destroyed mutator
Expand Down
2 changes: 1 addition & 1 deletion string.c
Original file line number Diff line number Diff line change
Expand Up @@ -12383,7 +12383,7 @@ sym_succ(VALUE sym)
*
* Returns:
*
* - <tt>symbol.to_s <=> other.to_s</tt>, if +other+ is a symbol.
* - <tt>self.to_s <=> other.to_s</tt>, if +other+ is a symbol.
* - +nil+, otherwise.
*
* Examples:
Expand Down