Skip to content

Commit

Permalink
Added Rubinius.primitive :vm_global_serial
Browse files Browse the repository at this point in the history
This is the read-only version of :vm_inc_global_serial,
returning the current value of the serial without modification.

This is useful for implementing caches in Ruby-space that
are to be invalidated when the global serial is incremented.
(That is, when constants are assigned or included into modules).
jemc committed Apr 18, 2015

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent dfb9c9a commit fb40475
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernel/bootstrap/rubinius.rb
Original file line number Diff line number Diff line change
@@ -19,6 +19,11 @@ def self.extended_modules(obj)
raise PrimitiveFailure, "Rubinius.extended_modules primitive failed"
end

def self.global_serial
Rubinius.primitive :vm_global_serial
raise PrimitiveFailure, "Rubinius.vm_global_serial primitive failed"
end

def self.inc_global_serial
Rubinius.primitive :vm_inc_global_serial
raise PrimitiveFailure, "Rubinius.vm_inc_global_serial primitive failed"
4 changes: 4 additions & 0 deletions vm/builtin/system.cpp
Original file line number Diff line number Diff line change
@@ -1323,6 +1323,10 @@ namespace rubinius {
return RBOOL(obj->kind_of_p(state, mod));
}

Object* System::vm_global_serial(STATE, CallFrame* calling_environment) {
return Fixnum::from(state->shared().global_serial());
}

Object* System::vm_inc_global_serial(STATE, CallFrame* calling_environment) {
if(state->shared().config.serial_debug) {
std::cout << "[Global serial increased from " << state->shared().global_serial() << "]" << std::endl;
4 changes: 4 additions & 0 deletions vm/builtin/system.hpp
Original file line number Diff line number Diff line change
@@ -224,6 +224,10 @@ namespace rubinius {
// Rubinius.primitive+ :vm_object_kind_of
static Object* vm_object_kind_of(STATE, Object* obj, Module* mod);

// Return the internal global serial number, used for caching
// Rubinius.primitive :vm_global_serial
static Object* vm_global_serial(STATE, CallFrame* calling_environment);

// Increment the internal global serial number, used for caching
// Rubinius.primitive :vm_inc_global_serial
static Object* vm_inc_global_serial(STATE, CallFrame* calling_environment);

0 comments on commit fb40475

Please sign in to comment.