12#include "eval_intern.h"
20#include "internal/scheduler.h"
21#include "internal/thread.h"
24#include "ruby_atomic.h"
27static ID id_scheduler_close;
34#ifdef FIBER_SCHEDULER_CALL_TIMEOUT_AFTER
35static ID id_timeout_after;
37static ID id_kernel_sleep;
38static ID id_process_wait;
40static ID id_io_read, id_io_pread;
41static ID id_io_write, id_io_pwrite;
43static ID id_io_select;
46static ID id_address_resolve;
48static ID id_blocking_operation_wait;
49static ID id_fiber_interrupt;
51static ID id_fiber_schedule;
54static VALUE rb_cFiberSchedulerBlockingOperation;
55static VALUE rb_cFiberSchedulerInterruptTarget;
64interrupt_target_mark(
void *ptr)
68 rb_gc_mark(target->fiber);
69 rb_gc_mark(target->exception);
73interrupt_target_memsize(
const void *ptr)
79 "Fiber::Scheduler::InterruptTarget",
81 interrupt_target_mark,
83 interrupt_target_memsize,
89get_interrupt_target(
VALUE self)
97interrupt_target_alive_p(
VALUE self)
101 if (!target->active) {
105 return rb_fiber_alive_p(target->fiber);
109interrupt_target_raise(
int argc,
VALUE *argv,
VALUE self)
113 if (!target->active) {
117 return rb_fiber_raise(target->fiber, argc, argv);
121interrupt_target_transfer(
VALUE self)
125 if (!target->active || !
RTEST(rb_fiber_alive_p(target->fiber))) {
129 VALUE exception = target->exception;
130 return rb_fiber_raise(target->fiber, 1, &exception);
134rb_fiber_scheduler_interrupt_target_new(
VALUE fiber,
VALUE exception)
139 target->fiber = fiber;
140 target->exception = exception;
141 target->active =
true;
147rb_fiber_scheduler_interrupt_target_exception(
VALUE self)
151 if (target->active) {
152 return target->exception;
159rb_fiber_scheduler_interrupt_target_invalidate(
VALUE self)
163 target->active =
false;
164 target->fiber =
Qnil;
165 target->exception =
Qnil;
175 RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED,
176 RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_EXECUTING,
177 RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_COMPLETED,
178 RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_CANCELLED
179} rb_fiber_blocking_operation_status_t;
182 void *(*function)(
void *);
196blocking_operation_memsize(
const void *ptr)
202 "Fiber::Scheduler::BlockingOperation",
206 blocking_operation_memsize,
208 0, 0, RUBY_TYPED_THREAD_SAFE_FREE | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
215blocking_operation_alloc(
VALUE klass)
220 blocking_operation->function = NULL;
221 blocking_operation->data = NULL;
222 blocking_operation->unblock_function = NULL;
223 blocking_operation->data2 = NULL;
224 blocking_operation->flags = 0;
225 blocking_operation->state = NULL;
226 blocking_operation->status = RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED;
235get_blocking_operation(
VALUE obj)
239 return blocking_operation;
251blocking_operation_call(
VALUE self)
255 if (blocking_operation->status != RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED) {
256 rb_raise(
rb_eRuntimeError,
"Blocking operation has already been executed!");
259 if (blocking_operation->function == NULL) {
260 rb_raise(
rb_eRuntimeError,
"Blocking operation has no function to execute!");
263 if (blocking_operation->state == NULL) {
268 blocking_operation->status = RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_EXECUTING;
271 blocking_operation->state->result =
rb_nogvl(blocking_operation->function, blocking_operation->data,
272 blocking_operation->unblock_function, blocking_operation->data2,
273 blocking_operation->flags);
274 blocking_operation->state->saved_errno = rb_errno();
277 blocking_operation->status = RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_COMPLETED;
295 return get_blocking_operation(self);
310 if (blocking_operation == NULL) {
314 if (blocking_operation->function == NULL || blocking_operation->state == NULL) {
319 rb_thread_resolve_unblock_function(&blocking_operation->unblock_function, &blocking_operation->data2, GET_THREAD());
322 rb_atomic_t expected = RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED;
323 if (
RUBY_ATOMIC_CAS(blocking_operation->status, expected, RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_EXECUTING) != expected) {
329 blocking_operation->state->result = blocking_operation->function(blocking_operation->data);
330 blocking_operation->state->saved_errno =
errno;
333 expected = RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_EXECUTING;
334 if (
RUBY_ATOMIC_CAS(blocking_operation->status, expected, RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_COMPLETED) == expected) {
339 blocking_operation->state->saved_errno = EINTR;
351rb_fiber_scheduler_blocking_operation_new(
void *(*function)(
void *),
void *data,
355 VALUE self = blocking_operation_alloc(rb_cFiberSchedulerBlockingOperation);
358 blocking_operation->function = function;
359 blocking_operation->data = data;
360 blocking_operation->unblock_function = unblock_function;
361 blocking_operation->data2 = data2;
362 blocking_operation->flags = flags;
363 blocking_operation->state = state;
420Init_Fiber_Scheduler(
void)
429#ifdef FIBER_SCHEDULER_CALL_TIMEOUT_AFTER
446 id_blocking_operation_wait =
rb_intern_const(
"blocking_operation_wait");
455 rb_define_method(rb_cFiberSchedulerBlockingOperation,
"call", blocking_operation_call, 0);
458 rb_gc_register_mark_object(rb_cFiberSchedulerBlockingOperation);
464 rb_define_method(rb_cFiberSchedulerInterruptTarget,
"alive?", interrupt_target_alive_p, 0);
465 rb_define_method(rb_cFiberSchedulerInterruptTarget,
"raise", interrupt_target_raise, -1);
466 rb_define_method(rb_cFiberSchedulerInterruptTarget,
"transfer", interrupt_target_transfer, 0);
467 rb_gc_register_mark_object(rb_cFiberSchedulerInterruptTarget);
470 rb_cFiberScheduler = rb_define_class_under(rb_cFiber,
"Scheduler",
rb_cObject);
481 rb_define_method(rb_cFiberScheduler,
"timeout_after", rb_fiber_scheduler_timeout_after, 3);
500 return thread->scheduler;
504verify_interface(
VALUE scheduler)
507 rb_raise(rb_eArgError,
"Scheduler must implement #block");
511 rb_raise(rb_eArgError,
"Scheduler must implement #unblock");
515 rb_raise(rb_eArgError,
"Scheduler must implement #kernel_sleep");
519 rb_raise(rb_eArgError,
"Scheduler must implement #io_wait");
523 rb_raise(rb_eArgError,
"Scheduler must implement #fiber_interrupt");
528fiber_scheduler_close(
VALUE scheduler)
534fiber_scheduler_close_ensure(
VALUE _thread)
537 thread->scheduler =
Qnil;
550 if (scheduler !=
Qnil) {
551 verify_interface(scheduler);
558 if (thread->scheduler !=
Qnil) {
560 rb_ensure(fiber_scheduler_close, thread->scheduler, fiber_scheduler_close_ensure, (
VALUE)thread);
563 thread->scheduler = scheduler;
565 return thread->scheduler;
569fiber_scheduler_current_for_threadptr(
rb_thread_t *thread)
573 if (thread->blocking == 0) {
574 return thread->scheduler;
585 return fiber_scheduler_current_for_threadptr(GET_THREAD());
591 return fiber_scheduler_current_for_threadptr(rb_thread_ptr(thread));
596 return fiber_scheduler_current_for_threadptr(thread);
623 if (!UNDEF_P(result))
return result;
626 if (!UNDEF_P(result))
return result;
635 return rb_float_new((
double)timeout->tv_sec + (0.000001 * timeout->tv_usec));
655 return rb_funcall(scheduler, id_kernel_sleep, 1, timeout);
661 return rb_funcallv(scheduler, id_kernel_sleep, argc, argv);
675 if (!UNDEF_P(result))
return result;
681#ifdef FIBER_SCHEDULER_CALL_TIMEOUT_AFTER
713 VALUE arguments[] = {
714 timeout, exception, message
721rb_fiber_scheduler_timeout_afterv(
VALUE scheduler,
int argc,
VALUE * argv)
748 VALUE arguments[] = {
772 return rb_funcall(scheduler, id_block, 2, blocker, timeout);
794 enum ruby_tag_type state;
799 int saved_errno =
errno;
803 volatile int saved_interrupt_mask = ec->interrupt_mask;
804 ec->interrupt_mask |= PENDING_INTERRUPT_MASK;
808 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
809 result =
rb_funcall(scheduler, id_unblock, 2, blocker, fiber);
812 rb_vm_rewind_cfp(ec, cfp);
816 ec->interrupt_mask = saved_interrupt_mask;
819 EC_JUMP_TAG(ec, state);
822 RUBY_VM_CHECK_INTS(ec);
849fiber_scheduler_io_wait(
VALUE _argument) {
852 return rb_funcallv(arguments[0], id_io_wait, 3, arguments + 1);
858 VALUE arguments[] = {
859 scheduler, io, events, timeout
862 return rb_thread_io_blocking_operation(io, fiber_scheduler_io_wait, (
VALUE)&arguments);
889 VALUE arguments[] = {
890 readables, writables, exceptables, timeout
928fiber_scheduler_io_read(
VALUE _argument) {
931 return rb_funcallv(arguments[0], id_io_read, 4, arguments + 1);
941 VALUE arguments[] = {
945 return rb_thread_io_blocking_operation(io, fiber_scheduler_io_read, (
VALUE)&arguments);
962fiber_scheduler_io_pread(
VALUE _argument) {
965 return rb_funcallv(arguments[0], id_io_pread, 5, arguments + 1);
975 VALUE arguments[] = {
979 return rb_thread_io_blocking_operation(io, fiber_scheduler_io_pread, (
VALUE)&arguments);
1005fiber_scheduler_io_write(
VALUE _argument) {
1008 return rb_funcallv(arguments[0], id_io_write, 4, arguments + 1);
1018 VALUE arguments[] = {
1022 return rb_thread_io_blocking_operation(io, fiber_scheduler_io_write, (
VALUE)&arguments);
1039fiber_scheduler_io_pwrite(
VALUE _argument) {
1042 return rb_funcallv(arguments[0], id_io_pwrite, 5, arguments + 1);
1054 VALUE arguments[] = {
1058 return rb_thread_io_blocking_operation(io, fiber_scheduler_io_pwrite, (
VALUE)&arguments);
1071fiber_scheduler_io_read_memory(
VALUE _arguments)
1075 return rb_fiber_scheduler_io_read(arguments->scheduler, arguments->io, arguments->buffer, arguments->offset, arguments->length);
1081 VALUE buffer = rb_io_buffer_new_locked(base, size, 0);
1084 .scheduler = scheduler,
1091 return rb_ensure(fiber_scheduler_io_read_memory, (
VALUE)&arguments, rb_io_buffer_free_locked, buffer);
1095fiber_scheduler_io_write_memory(
VALUE _arguments)
1105 VALUE buffer = rb_io_buffer_new_locked((
void*)base, size, RB_IO_BUFFER_READONLY);
1108 .scheduler = scheduler,
1115 return rb_ensure(fiber_scheduler_io_write_memory, (
VALUE)&arguments, rb_io_buffer_free_locked, buffer);
1119fiber_scheduler_io_pread_memory(
VALUE _arguments)
1123 return rb_fiber_scheduler_io_pread(arguments->scheduler, arguments->io, arguments->from, arguments->buffer, arguments->offset, arguments->length);
1129 VALUE buffer = rb_io_buffer_new_locked(base, size, 0);
1132 .scheduler = scheduler,
1140 return rb_ensure(fiber_scheduler_io_pread_memory, (
VALUE)&arguments, rb_io_buffer_free_locked, buffer);
1144fiber_scheduler_io_pwrite_memory(
VALUE _arguments)
1148 return rb_fiber_scheduler_io_pwrite(arguments->scheduler, arguments->io, arguments->from, arguments->buffer, arguments->offset, arguments->length);
1154 VALUE buffer = rb_io_buffer_new_locked((
void*)base, size, RB_IO_BUFFER_READONLY);
1157 .scheduler = scheduler,
1165 return rb_ensure(fiber_scheduler_io_pwrite_memory, (
VALUE)&arguments, rb_io_buffer_free_locked, buffer);
1179 VALUE arguments[] = {io};
1219 VALUE arguments[] = {
1246 if (!
rb_respond_to(scheduler, id_blocking_operation_wait)) {
1251 VALUE blocking_operation = rb_fiber_scheduler_blocking_operation_new(function, data, unblock_function, data2, flags, state);
1253 VALUE result =
rb_funcall(scheduler, id_blocking_operation_wait, 1, blocking_operation);
1260 operation->function = NULL;
1261 operation->state = NULL;
1262 operation->data = NULL;
1263 operation->data2 = NULL;
1264 operation->unblock_function = NULL;
1270 if (current_status == RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED) {
1292 VALUE arguments[] = {
1297 enum ruby_tag_type state;
1301 volatile int saved_interrupt_mask = ec->interrupt_mask;
1302 ec->interrupt_mask |= PENDING_INTERRUPT_MASK;
1306 if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1307 result =
rb_funcallv(scheduler, id_fiber_interrupt, 2, arguments);
1310 rb_vm_rewind_cfp(ec, cfp);
1314 ec->interrupt_mask = saved_interrupt_mask;
1317 EC_JUMP_TAG(ec, state);
1320 RUBY_VM_CHECK_INTS(ec);
1358 if (blocking_operation == NULL) {
1364 switch (current_state) {
1365 case RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_QUEUED:
1367 if (
RUBY_ATOMIC_CAS(blocking_operation->status, current_state, RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_CANCELLED) == current_state) {
1373 case RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_EXECUTING:
1375 if (
RUBY_ATOMIC_CAS(blocking_operation->status, current_state, RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_CANCELLED) != current_state) {
1381 if (unblock_function) {
1383 blocking_operation->unblock_function(blocking_operation->data2);
1388 case RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_COMPLETED:
1389 case RB_FIBER_SCHEDULER_BLOCKING_OPERATION_STATUS_CANCELLED:
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define RUBY_ATOMIC_CAS(var, oldval, newval)
Atomic compare-and-swap.
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
#define RUBY_ATOMIC_LOAD(var)
Atomic load.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
VALUE rb_class_new(VALUE super)
Creates a new, anonymous class.
#define Qundef
Old name of RUBY_Qundef.
#define SIZET2NUM
Old name of RB_SIZE2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_cObject
Object class.
VALUE rb_fiber_scheduler_blocking_operation_wait(VALUE scheduler, void *(*function)(void *), void *data, rb_unblock_function_t *unblock_function, void *data2, int flags, struct rb_fiber_scheduler_blocking_operation_state *state)
Defer the execution of the passed function to the scheduler.
VALUE rb_fiber_scheduler_current(void)
Identical to rb_fiber_scheduler_get(), except it also returns RUBY_Qnil in case of a blocking fiber.
VALUE rb_fiber_scheduler_make_timeout(struct timeval *timeout)
Converts the passed timeout to an expression that rb_fiber_scheduler_block() etc.
VALUE rb_fiber_scheduler_io_wait_readable(VALUE scheduler, VALUE io)
Non-blocking wait until the passed IO is ready for reading.
VALUE rb_fiber_scheduler_kernel_sleepv(VALUE scheduler, int argc, VALUE *argv)
Identical to rb_fiber_scheduler_kernel_sleep(), except it can pass multiple arguments.
VALUE rb_fiber_scheduler_io_wait(VALUE scheduler, VALUE io, VALUE events, VALUE timeout)
Non-blocking version of rb_io_wait().
VALUE rb_fiber_scheduler_io_select(VALUE scheduler, VALUE readables, VALUE writables, VALUE exceptables, VALUE timeout)
Non-blocking version of IO.select.
VALUE rb_fiber_scheduler_io_read(VALUE scheduler, VALUE io, VALUE buffer, size_t offset, size_t length)
Non-blocking read from the passed IO.
int rb_fiber_scheduler_blocking_operation_cancel(rb_fiber_scheduler_blocking_operation_t *blocking_operation)
Cancel a blocking operation.
VALUE rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, rb_off_t from, VALUE buffer, size_t offset, size_t length)
Non-blocking write to the passed IO at the specified offset.
VALUE rb_fiber_scheduler_io_pread_memory(VALUE scheduler, VALUE io, rb_off_t from, void *base, size_t size)
Non-blocking pread from the passed IO using a native buffer.
VALUE rb_fiber_scheduler_io_selectv(VALUE scheduler, int argc, VALUE *argv)
Non-blocking version of IO.select, argv variant.
VALUE rb_fiber_scheduler_process_wait(VALUE scheduler, rb_pid_t pid, int flags)
Non-blocking waitpid.
VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, rb_off_t from, VALUE buffer, size_t offset, size_t length)
Non-blocking read from the passed IO at the specified offset.
VALUE rb_fiber_scheduler_block(VALUE scheduler, VALUE blocker, VALUE timeout)
Non-blocking wait for the passed "blocker", which is for instance Thread.join or Mutex....
VALUE rb_fiber_scheduler_io_read_memory(VALUE scheduler, VALUE io, void *base, size_t size)
Non-blocking read from the passed IO using a native buffer.
int rb_fiber_scheduler_blocking_operation_execute(rb_fiber_scheduler_blocking_operation_t *blocking_operation)
Execute blocking operation from handle (GVL not required).
VALUE rb_fiber_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_t offset, size_t length)
Non-blocking write to the passed IO.
VALUE rb_fiber_scheduler_close(VALUE scheduler)
Closes the passed scheduler object.
rb_fiber_scheduler_blocking_operation_t * rb_fiber_scheduler_blocking_operation_extract(VALUE self)
Extract the blocking operation handle from a BlockingOperationRuby object.
VALUE rb_fiber_scheduler_current_for_thread(VALUE thread)
Identical to rb_fiber_scheduler_current(), except it queries for that of the passed thread value inst...
VALUE rb_fiber_scheduler_kernel_sleep(VALUE scheduler, VALUE duration)
Non-blocking sleep.
VALUE rb_fiber_scheduler_fiber_interrupt(VALUE scheduler, VALUE target, VALUE exception)
Interrupt a target by raising an exception.
VALUE rb_fiber_scheduler_address_resolve(VALUE scheduler, VALUE hostname)
Non-blocking DNS lookup.
VALUE rb_fiber_scheduler_yield(VALUE scheduler)
Yield to the scheduler, to be resumed on the next scheduling cycle.
VALUE rb_fiber_scheduler_io_pwrite_memory(VALUE scheduler, VALUE io, rb_off_t from, const void *base, size_t size)
Non-blocking pwrite to the passed IO using a native buffer.
VALUE rb_fiber_scheduler_set(VALUE scheduler)
Destructively assigns the passed scheduler to that of the current thread that is calling this functio...
VALUE rb_fiber_scheduler_current_for_threadptr(struct rb_thread_struct *thread)
Identical to rb_fiber_scheduler_current_for_thread(), except it expects a threadptr instead of a thre...
VALUE rb_fiber_scheduler_io_wait_writable(VALUE scheduler, VALUE io)
Non-blocking wait until the passed IO is ready for writing.
VALUE rb_fiber_scheduler_io_close(VALUE scheduler, VALUE io)
Non-blocking close the given IO.
VALUE rb_fiber_scheduler_get(void)
Queries the current scheduler of the current thread that is calling this function.
VALUE rb_fiber_scheduler_unblock(VALUE scheduler, VALUE blocker, VALUE fiber)
Wakes up a fiber previously blocked using rb_fiber_scheduler_block().
VALUE rb_fiber_scheduler_io_write_memory(VALUE scheduler, VALUE io, const void *base, size_t size)
Non-blocking write to the passed IO using a native buffer.
VALUE rb_fiber_scheduler_fiber(VALUE scheduler, int argc, VALUE *argv, int kw_splat)
Create and schedule a non-blocking fiber.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_funcall_passing_block_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv_passing_block(), except you can specify how to handle the last element of th...
void rb_unblock_function_t(void *)
This is the type of UBFs.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
VALUE rb_io_timeout(VALUE io)
Get the timeout associated with the specified io object.
@ RUBY_IO_READABLE
IO::READABLE
@ RUBY_IO_WRITABLE
IO::WRITABLE
void * rb_nogvl(void *(*func)(void *), void *data1, rb_unblock_function_t *ubf, void *data2, int flags)
Identical to rb_thread_call_without_gvl(), except it additionally takes "flags" that change the behav...
#define RB_UINT2NUM
Just another name of rb_uint2num_inline.
#define RB_INT2NUM
Just another name of rb_int2num_inline.
#define RB_GC_GUARD(v)
Prevents premature destruction of local objects.
VALUE rb_ensure(type *q, VALUE w, type *e, VALUE r)
An equivalent of ensure clause.
#define OFFT2NUM
Converts a C's off_t into an instance of rb_cInteger.
#define PIDT2NUM
Converts a C's pid_t into an instance of rb_cInteger.
#define RUBY_DEFAULT_FREE
This is a value you can set to RData::dfree.
#define RUBY_TYPED_FREE_IMMEDIATELY
Macros to see if each corresponding flag is defined.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
#define errno
Ractor-aware version of errno.
@ RUBY_Qundef
Represents so-called undef.
#define RTEST
This is an old name of RB_TEST.
This is the struct that holds necessary info for a struct.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.