Permalink
Browse files

Change call protocol to remove Dispatch&. Make IC thread-safe.

  • Loading branch information...
1 parent d474224 commit 45a2de9b1fca0be006d551d08a348e4f0abd3363 Evan Phoenix committed Aug 17, 2010
Showing with 489 additions and 356 deletions.
  1. +24 −10 vm/arguments.hpp
  2. +7 −7 vm/builtin/access_variable.cpp
  3. +3 −3 vm/builtin/access_variable.hpp
  4. +2 −2 vm/builtin/array.cpp
  5. +4 −4 vm/builtin/block_as_method.cpp
  6. +1 −1 vm/builtin/block_as_method.hpp
  7. +4 −4 vm/builtin/block_environment.cpp
  8. +2 −2 vm/builtin/block_environment.hpp
  9. +10 −11 vm/builtin/call_unit.cpp
  10. +5 −5 vm/builtin/call_unit.hpp
  11. +3 −3 vm/builtin/call_unit_adapter.cpp
  12. +1 −1 vm/builtin/call_unit_adapter.hpp
  13. +14 −9 vm/builtin/compiledmethod.cpp
  14. +2 −2 vm/builtin/compiledmethod.hpp
  15. +5 −5 vm/builtin/executable.cpp
  16. +1 −2 vm/builtin/executable.hpp
  17. +3 −3 vm/builtin/nativefunction.cpp
  18. +1 −1 vm/builtin/nativefunction.hpp
  19. +6 −6 vm/builtin/nativemethod.cpp
  20. +1 −1 vm/builtin/nativemethod.hpp
  21. +3 −3 vm/builtin/object.cpp
  22. +1 −1 vm/builtin/object.hpp
  23. +4 −5 vm/builtin/proc.cpp
  24. +2 −2 vm/builtin/proc.hpp
  25. +1 −1 vm/builtin/system.cpp
  26. +2 −2 vm/builtin/thread.cpp
  27. +3 −3 vm/builtin/thunk.cpp
  28. +1 −1 vm/builtin/thunk.hpp
  29. +9 −20 vm/call_frame.hpp
  30. +2 −2 vm/capi/capi.cpp
  31. +17 −15 vm/codegen/field_extract.rb
  32. +2 −3 vm/compiled_file.cpp
  33. +1 −1 vm/dispatch.cpp
  34. +6 −0 vm/environment.cpp
  35. +4 −2 vm/executor.hpp
  36. +0 −10 vm/gc/gc.cpp
  37. +119 −14 vm/inline_cache.cpp
  38. +2 −0 vm/inline_cache.hpp
  39. +24 −22 vm/instructions.def
  40. +9 −9 vm/instruments/profiler.cpp
  41. +3 −3 vm/instruments/profiler.hpp
  42. +2 −0 vm/llvm/jit.cpp
  43. +4 −3 vm/llvm/jit_builder.cpp
  44. +2 −1 vm/llvm/jit_builder.hpp
  45. +13 −13 vm/llvm/jit_method.cpp
  46. +5 −3 vm/llvm/jit_operations.hpp
  47. +23 −19 vm/llvm/jit_util.cpp
  48. +9 −5 vm/llvm/jit_visit.hpp
  49. +6 −5 vm/llvm/offset.hpp
  50. +88 −88 vm/llvm/types.cpp.gen
  51. +2 −0 vm/oop.hpp
  52. +2 −3 vm/primitives.cpp
  53. +1 −1 vm/primitives.hpp
  54. +1 −1 vm/shared_state.hpp
  55. +1 −1 vm/signal.cpp
  56. +6 −2 vm/vm.cpp
  57. +8 −8 vm/vmmethod.cpp
  58. +2 −2 vm/vmmethod.hpp
View
@@ -11,6 +11,7 @@ namespace rubinius {
class GarbageCollector;
class Arguments {
+ Symbol* name_;
Object* recv_;
Object* block_;
@@ -19,45 +20,58 @@ namespace rubinius {
Tuple* argument_container_;
public:
- Arguments(Object* recv, Object* block, uint32_t total, Object** buffer)
- : recv_(recv)
+ Arguments(Symbol* name, Object* recv, Object* block, uint32_t total, Object** buffer)
+ : name_(name)
+ , recv_(recv)
, block_(block)
, total_(total)
, arguments_(buffer)
, argument_container_(0)
{}
- Arguments(Object* recv, uint32_t total, Object** buffer)
- : recv_(recv)
+ Arguments(Symbol* name, Object* recv, uint32_t total, Object** buffer)
+ : name_(name)
+ , recv_(recv)
, block_(Qnil)
, total_(total)
, arguments_(buffer)
, argument_container_(0)
{}
- Arguments(uint32_t total, Object** buffer)
- : recv_(Qnil)
+ Arguments(Symbol* name, uint32_t total, Object** buffer)
+ : name_(name)
+ , recv_(Qnil)
, block_(Qnil)
, total_(total)
, arguments_(buffer)
, argument_container_(0)
{}
- Arguments()
- : recv_(Qnil)
+ Arguments(Symbol* name)
+ : name_(name)
+ , recv_(Qnil)
, block_(Qnil)
, total_(0)
, arguments_(0)
, argument_container_(0)
{}
- Arguments(Array* ary)
- : recv_(Qnil)
+ Arguments(Symbol* name, Array* ary)
+ : name_(name)
+ , recv_(Qnil)
, block_(Qnil)
{
use_array(ary);
}
+ Symbol* name() {
+ return name_;
+ }
+
+ void set_name(Symbol* n) {
+ name_ = n;
+ }
+
Object* recv() {
return recv_;
}
@@ -29,9 +29,9 @@ namespace rubinius {
return av;
}
- Object* AccessVariable::access_read_regular_ivar(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* AccessVariable::access_read_regular_ivar(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
- AccessVariable* access = as<AccessVariable>(msg.method);
+ AccessVariable* access = as<AccessVariable>(exec);
if(unlikely(args.total() != 0)) {
Exception::argument_error(state, 0, args.total());
return NULL;
@@ -47,9 +47,9 @@ namespace rubinius {
return recv->get_table_ivar(state, access->name());
}
- Object* AccessVariable::access_write_regular_ivar(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* AccessVariable::access_write_regular_ivar(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
- AccessVariable* access = as<AccessVariable>(msg.method);
+ AccessVariable* access = as<AccessVariable>(exec);
if(unlikely(args.total() != 1)) {
Exception::argument_error(state, 1, args.total());
return NULL;
@@ -70,11 +70,11 @@ namespace rubinius {
return recv->set_table_ivar(state, access->name(), args.get_argument(0));
}
- /* Run when an AccessVariable is executed. Uses the details in msg.method
+ /* Run when an AccessVariable is executed. Uses the details in exec
* to access instance variables of args.recv() */
- Object* AccessVariable::access_execute(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* AccessVariable::access_execute(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
- AccessVariable* access = as<AccessVariable>(msg.method);
+ AccessVariable* access = as<AccessVariable>(exec);
Object* const self = args.recv();
/* The writer case. */
@@ -29,9 +29,9 @@ namespace rubinius {
static void init(STATE);
// Ruby.primitive :accessvariable_allocate
static AccessVariable* allocate(STATE);
- static Object* access_execute(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
- static Object* access_read_regular_ivar(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
- static Object* access_write_regular_ivar(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
+ static Object* access_execute(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
+ static Object* access_read_regular_ivar(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
+ static Object* access_write_regular_ivar(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
class Info : public Executable::Info {
public:
View
@@ -60,8 +60,8 @@ namespace rubinius {
if(Tuple* tup = try_as<Tuple>(value)) {
return Array::from_tuple(state, tup);
} else if(RTEST(value->respond_to(state, state->symbol("to_ary"), Qtrue))) {
- Arguments args(value, 0, 0);
- Dispatch dis(state->symbol("to_ary"));
+ Arguments args(state->symbol("to_ary"), value, 0, 0);
+ Dispatch dis(args.name());
Object* res = dis.send(state, call_frame, args);
if(!res) return 0;
@@ -19,10 +19,10 @@ namespace rubinius {
return pe;
}
- Object* BlockAsMethod::block_executor(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* BlockAsMethod::block_executor(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args)
{
- BlockAsMethod* bm = as<BlockAsMethod>(msg.method);
+ BlockAsMethod* bm = as<BlockAsMethod>(exec);
int required = bm->block_env()->method()->required_args()->to_native();
@@ -36,7 +36,7 @@ namespace rubinius {
//
if(required > 1 && (size_t)required > args.total()) {
Exception* exc =
- Exception::make_argument_error(state, required, args.total(), msg.name);
+ Exception::make_argument_error(state, required, args.total(), args.name());
exc->locations(state, Location::from_call_stack(state, call_frame));
state->thread_state()->raise_exception(exc);
return NULL;
@@ -46,7 +46,7 @@ namespace rubinius {
bm->block_env()->method()->scope(),
CallFrame::cIsLambda | CallFrame::cBlockAsMethod);
- invocation.module = msg.module;
+ invocation.module = mod;
return bm->block_env()->invoke(state, call_frame,
bm->block_env(), args, invocation);
@@ -20,7 +20,7 @@ namespace rubinius {
static BlockAsMethod* create(STATE, Object* self, BlockEnvironment* be);
static Object* block_executor(STATE, CallFrame* call_frame,
- Dispatch& msg, Arguments& args);
+ Executable* exec, Module* mod, Arguments& args);
class Info : public Executable::Info {
public:
@@ -171,8 +171,8 @@ namespace rubinius {
return invoke(state, call_frame, this, args, invocation);
}
- Object* BlockEnvironment::call_prim(STATE, Executable* exec,
- CallFrame* call_frame, Dispatch& msg, Arguments& args)
+ Object* BlockEnvironment::call_prim(STATE,
+ CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args)
{
return call(state, call_frame, args);
}
@@ -194,8 +194,8 @@ namespace rubinius {
return invoke(state, call_frame, this, args, invocation);
}
- Object* BlockEnvironment::call_under(STATE, Executable* exec,
- CallFrame* call_frame, Dispatch& msg, Arguments& args)
+ Object* BlockEnvironment::call_under(STATE,
+ CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args)
{
if(args.total() < 2) {
Exception* exc =
@@ -74,12 +74,12 @@ namespace rubinius {
Object* call(STATE, CallFrame* call_frame, Arguments& args, int flags=0);
// Ruby.primitive? :block_call
- Object* call_prim(STATE, Executable* exec, CallFrame* call_frame, Dispatch& msg, Arguments& args);
+ Object* call_prim(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
Object* call_on_object(STATE, CallFrame* call_frame, Arguments& args, int flags=0);
// Ruby.primitive? :block_call_under
- Object* call_under(STATE, Executable* exec, CallFrame* call_frame, Dispatch& msg, Arguments& args);
+ Object* call_under(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
BlockEnvironment* dup(STATE);
View
@@ -55,41 +55,40 @@ namespace rubinius {
Object* CallUnit::constant_value_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args)
{
return unit->value();
}
Object* CallUnit::method_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args)
{
- msg.method = unit->executable();
- msg.name = unit->name();
- msg.module = unit->module();
- return unit->executable()->execute(state, call_frame, msg, args);
+ args.set_name(unit->name());
+ return unit->executable()->execute(state, call_frame,
+ unit->executable(), unit->module(), args);
}
Object* CallUnit::test_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args)
{
Object* ret = unit->test_condition()->execute(
- state, call_frame, unit->test_condition(), msg, args);
+ state, call_frame, unit->test_condition(), exec, mod, args);
if(!ret) return ret;
if(RTEST(ret)) {
- return unit->test_then()->execute(state, call_frame, unit->test_then(), msg, args);
+ return unit->test_then()->execute(state, call_frame, unit->test_then(), exec, mod, args);
} else {
- return unit->test_else()->execute(state, call_frame, unit->test_else(), msg, args);
+ return unit->test_else()->execute(state, call_frame, unit->test_else(), exec, mod, args);
}
}
Object* CallUnit::kind_of_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args)
{
Object* obj;
View
@@ -16,7 +16,7 @@ namespace rubinius {
};
typedef Object* (*Execute)(VM*, CallFrame*, CallUnit* unit,
- Dispatch& msg, Arguments& args);
+ Executable* exec, Module* mod, Arguments& args);
private:
Kind kind_;
@@ -59,22 +59,22 @@ namespace rubinius {
static Object* constant_value_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args);
static Object* method_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args);
static Object* test_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args);
static Object* kind_of_executor(STATE, CallFrame* call_frame,
CallUnit* unit,
- Dispatch& msg,
+ Executable* exec, Module* mod,
Arguments& args);
class Info : public TypeInfo {
@@ -18,12 +18,12 @@ namespace rubinius {
return pe;
}
- Object* CallUnitAdapter::adapter_executor(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* CallUnitAdapter::adapter_executor(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args)
{
- CallUnitAdapter* adapter = as<CallUnitAdapter>(msg.method);
+ CallUnitAdapter* adapter = as<CallUnitAdapter>(exec);
CallUnit* unit = adapter->unit_;
- return unit->execute(state, call_frame, unit, msg, args);
+ return unit->execute(state, call_frame, unit, exec, mod, args);
}
}
@@ -21,7 +21,7 @@ namespace rubinius {
static CallUnitAdapter* create(STATE, Object* self, CallUnit* unit);
static Object* adapter_executor(STATE, CallFrame* call_frame,
- Dispatch& msg, Arguments& args);
+ Executable* exec, Module* mod, Arguments& args);
class Info : public Executable::Info {
public:
@@ -110,10 +110,10 @@ namespace rubinius {
return backend_method_;
}
- Object* CompiledMethod::primitive_failed(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* CompiledMethod::primitive_failed(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
- if(try_as<CompiledMethod>(msg.method)) {
- return VMMethod::execute(state, call_frame, msg, args);
+ if(try_as<CompiledMethod>(exec)) {
+ return VMMethod::execute(state, call_frame, exec, mod, args);
}
// TODO fix me to raise an exception
@@ -133,13 +133,18 @@ namespace rubinius {
return this;
}
- Object* CompiledMethod::default_executor(STATE, CallFrame* call_frame, Dispatch& msg,
+ Object* CompiledMethod::default_executor(STATE, CallFrame* call_frame, Executable* exec, Module* mod,
Arguments& args) {
- CompiledMethod* cm = as<CompiledMethod>(msg.method);
- cm->formalize(state, false);
- // Refactor
- cm->backend_method_->find_super_instructions();
- return cm->execute(state, call_frame, msg, args);
+ LockableScopedLock lg(state, &state->shared, __FILE__, __LINE__);
+
+ CompiledMethod* cm = as<CompiledMethod>(exec);
+ if(cm->execute == default_executor) {
+ cm->formalize(state, false);
+ }
+
+ lg.unlock();
+
+ return cm->execute(state, call_frame, exec, mod, args);
}
void CompiledMethod::post_marshal(STATE) {
@@ -80,7 +80,7 @@ namespace rubinius {
// Ruby.primitive :compiledmethod_allocate
static CompiledMethod* create(STATE);
- static Object* primitive_failed(STATE, CallFrame* call_frame, Dispatch& msg, Arguments& args);
+ static Object* primitive_failed(STATE, CallFrame* call_frame, Executable* exec, Module* mod, Arguments& args);
int start_line(STATE);
int start_line();
@@ -91,7 +91,7 @@ namespace rubinius {
VMMethod* formalize(STATE, bool ondemand=true);
void specialize(STATE, TypeInfo* ti);
- static Object* default_executor(STATE, CallFrame*, Dispatch&, Arguments& args);
+ static Object* default_executor(STATE, CallFrame*, Executable* exec, Module* mod, Arguments& args);
// Ruby.primitive :compiledmethod_compile
Object* compile(STATE);
Oops, something went wrong.

0 comments on commit 45a2de9

Please sign in to comment.