Permalink
Browse files

Renamed VMMethod to MachineCode.

This was a difficult name choice but it is consistent with CompiledCode
and (not yet used) SourceCode. The CompiledCode is an abstraction of
computation that is the focal point around which much revolves. MachineCode
is a representation of computation specialized for our (virtual) machine.

While there is possible ambiguity against the idea of JIT'd machine code,
our MachineCode is a proper data structure, not just the format of bits
resulting from the JIT compilation process. Also, our MachineCode is properly
scoped differently than any such class/concept in LLVM (or more generally,
the JIT).

Regarding naming of instances of MachineCode, the following rationale is used:

* parameters/variables have been named 'mcode' since the use of the variable
  is elaborated by the surrounding code (ie making ambiguity less an issue)
  and long variable names can sometimes make code unweildy.
* attributes/fields/accessors have been name 'machine_code' because they have
  less context to disambiguate.
  • Loading branch information...
1 parent 91f3cd2 commit 6fce2f693b62bc8b11e2f42711237c45346a98fd @brixen brixen committed Aug 28, 2012
Showing with 532 additions and 531 deletions.
  1. +2 −2 rakelib/instruction_parser.rb
  2. +1 −1 vm/builtin/access_variable.hpp
  3. +39 −39 vm/builtin/block_environment.cpp
  4. +3 −3 vm/builtin/block_environment.hpp
  5. +55 −55 vm/builtin/compiledcode.cpp
  6. +5 −5 vm/builtin/compiledcode.hpp
  7. +1 −1 vm/builtin/executable.cpp
  8. +1 −1 vm/builtin/executable.hpp
  9. +2 −2 vm/builtin/location.cpp
  10. +1 −1 vm/builtin/proc.cpp
  11. +7 −7 vm/builtin/system.cpp
  12. +1 −1 vm/bytecode_verification.cpp
  13. +2 −2 vm/call_frame.hpp
  14. +4 −4 vm/drivers/jit-test.cpp
  15. +1 −1 vm/gc/code_manager.hpp
  16. +1 −1 vm/gc/gc.cpp
  17. +6 −6 vm/inline_cache.hpp
  18. +22 −22 vm/instructions.cpp
  19. +10 −10 vm/instructions.def
  20. +1 −1 vm/instructions.hpp
  21. +4 −4 vm/instructions_util.hpp
  22. +3 −3 vm/instruments/rbxti.cpp
  23. +2 −2 vm/llvm/background_compile_request.hpp
  24. +8 −8 vm/llvm/cfg.hpp
  25. +7 −7 vm/llvm/control_flow.hpp
  26. +21 −21 vm/llvm/inline.cpp
  27. +2 −2 vm/llvm/inline.hpp
  28. +2 −2 vm/llvm/inline_block.cpp
  29. +5 −5 vm/llvm/inline_block.hpp
  30. +38 −38 vm/llvm/inline_policy.hpp
  31. +9 −9 vm/llvm/jit_block.cpp
  32. +9 −9 vm/llvm/jit_builder.cpp
  33. +2 −2 vm/llvm/jit_builder.hpp
  34. +6 −6 vm/llvm/jit_compiler.cpp
  35. +3 −3 vm/llvm/jit_compiler.hpp
  36. +1 −1 vm/llvm/jit_context.cpp
  37. +8 −8 vm/llvm/jit_inline_block.cpp
  38. +5 −5 vm/llvm/jit_inline_method.cpp
  39. +31 −30 vm/llvm/jit_method.cpp
  40. +12 −12 vm/llvm/jit_operations.hpp
  41. +22 −22 vm/llvm/jit_util.cpp
  42. +15 −15 vm/llvm/jit_visit.hpp
  43. +2 −2 vm/llvm/method_info.cpp
  44. +2 −2 vm/llvm/method_info.hpp
  45. +7 −7 vm/llvm/opcode_iter.hpp
  46. +37 −37 vm/llvm/state.cpp
  47. +67 −67 vm/{vmmethod.cpp → machine_code.cpp}
  48. +16 −16 vm/{vmmethod.hpp → machine_code.hpp}
  49. +1 −1 vm/objectmemory.hpp
  50. +1 −1 vm/primitives.hpp
  51. +4 −4 vm/stack_variables.cpp
  52. +14 −14 vm/test/{test_vmmethod.hpp → test_machine_code.hpp}
  53. +1 −1 vm/vm.cpp
@@ -659,9 +659,9 @@ def opcode_width
def opcode_prototype
name = opcode_name
indent = " " * (name.size + 9)
- prototype = "Object* #{name}(rubinius::VM* state, rubinius::VMMethod* vmm,
+ prototype = "Object* #{name}(rubinius::VM* state, rubinius::MachineCode* code,
@arjen

arjen Sep 3, 2012

Should

rubinius::MachineCode* code

be

rubinius::MachineCode* mcode

?

#{indent}rubinius::InterpreterCallFrame* const call_frame,
-#{indent}rubinius::VMMethod::InterpreterState& is"
+#{indent}rubinius::MachineCode::InterpreterState& is"
unless @arguments.empty?
prototype << ",\n#{indent}"
@@ -7,7 +7,7 @@
namespace rubinius {
class InstructionSequence;
- class VMMethod;
+ class MachineCode;
class ConstantScope;
class AccessVariable : public Executable {
@@ -52,29 +52,29 @@ namespace rubinius {
return env;
}
- VMMethod* BlockEnvironment::vmmethod(STATE, GCToken gct) {
+ MachineCode* BlockEnvironment::machine_code(STATE, GCToken gct) {
return code_->internalize(state, gct);
}
Object* BlockEnvironment::invoke(STATE, CallFrame* previous,
BlockEnvironment* env, Arguments& args,
BlockInvocation& invocation)
{
- VMMethod* vmm = env->code_->backend_method();
+ MachineCode* mcode = env->code_->machine_code();
- if(!vmm) {
+ if(!mcode) {
OnStack<2> os(state, env, args.argument_container_location());
GCTokenImpl gct;
- vmm = env->vmmethod(state, gct);
+ mcode = env->machine_code(state, gct);
- if(!vmm) {
+ if(!mcode) {
Exception::internal_error(state, previous, "invalid bytecode method");
return 0;
}
}
#ifdef ENABLE_LLVM
- if(executor ptr = vmm->unspecialized) {
+ if(executor ptr = mcode->unspecialized) {
return (*((BlockExecutor)ptr))(state, previous, env, args, invocation);
}
#endif
@@ -86,16 +86,16 @@ namespace rubinius {
class GenericArguments {
public:
static bool call(STATE, CallFrame* call_frame,
- VMMethod* vmm, StackVariables* scope,
+ MachineCode* mcode, StackVariables* scope,
Arguments& args, int flags)
{
- const bool has_splat = (vmm->splat_position >= 0);
+ const bool has_splat = (mcode->splat_position >= 0);
native_int total_args = args.total();
// expecting 0, got 0.
- if(vmm->total_args == 0 && total_args == 0) {
+ if(mcode->total_args == 0 && total_args == 0) {
if(has_splat) {
- scope->set_local(vmm->splat_position, Array::create(state, 0));
+ scope->set_local(mcode->splat_position, Array::create(state, 0));
}
return true;
@@ -119,9 +119,9 @@ namespace rubinius {
* the block's arguments.
*/
if(total_args == 1
- && (vmm->required_args > 1
- || (vmm->required_args == 1
- && (has_splat || vmm->splat_position < -2)))) {
+ && (mcode->required_args > 1
+ || (mcode->required_args == 1
+ && (has_splat || mcode->splat_position < -2)))) {
Object* obj = args.get_argument(0);
Array* ary = 0;
@@ -136,7 +136,7 @@ namespace rubinius {
}
if(ary) {
- if(vmm->splat_position == -4 && vmm->required_args == 1) {
+ if(mcode->splat_position == -4 && mcode->required_args == 1) {
args.use_argument(ary);
} else {
args.use_array(ary);
@@ -145,19 +145,19 @@ namespace rubinius {
}
}
- const native_int P = vmm->post_args;
- const native_int R = vmm->required_args;
+ const native_int P = mcode->post_args;
+ const native_int R = mcode->required_args;
// M is for mandatory
const native_int M = R - P;
const native_int T = args.total();
// DT is for declared total
- const native_int DT = vmm->total_args;
+ const native_int DT = mcode->total_args;
const native_int O = DT - R;
// HS is for has splat
- const native_int HS = vmm->splat_position >= 0 ? 1 : 0;
+ const native_int HS = mcode->splat_position >= 0 ? 1 : 0;
// CT is for clamped total
const native_int CT = HS ? T : MIN(T, DT);
@@ -243,7 +243,7 @@ namespace rubinius {
ary = Array::create(state, 0);
}
- scope->set_local(vmm->splat_position, ary);
+ scope->set_local(mcode->splat_position, ary);
}
return true;
@@ -259,39 +259,39 @@ namespace rubinius {
BlockEnvironment* env, Arguments& args,
BlockInvocation& invocation)
{
- // Don't use env->vmmethod() because it might lock and the work should already
- // be done.
- VMMethod* const vmm = env->code_->backend_method();
+ // Don't use env->machine_code() because it might lock and the work should
+ // already be done.
+ MachineCode* const mcode = env->code_->machine_code();
- if(!vmm) {
+ if(!mcode) {
Exception::internal_error(state, previous, "invalid bytecode method");
return 0;
}
#ifdef ENABLE_LLVM
- if(vmm->call_count >= 0) {
- if(vmm->call_count >= state->shared().config.jit_call_til_compile) {
+ if(mcode->call_count >= 0) {
+ if(mcode->call_count >= state->shared().config.jit_call_til_compile) {
LLVMState* ls = LLVMState::get(state);
ls->compile_soon(state, env->code(), env, true);
} else {
- vmm->call_count++;
+ mcode->call_count++;
}
}
#endif
- StackVariables* scope = ALLOCA_STACKVARIABLES(vmm->number_of_locals);
+ StackVariables* scope = ALLOCA_STACKVARIABLES(mcode->number_of_locals);
Module* mod = invocation.module;
if(!mod) mod = env->module();
scope->initialize(invocation.self, env->top_scope_->block(),
- mod, vmm->number_of_locals);
+ mod, mcode->number_of_locals);
scope->set_parent(env->scope_);
- InterpreterCallFrame* frame = ALLOCA_CALLFRAME(vmm->stack_size);
+ InterpreterCallFrame* frame = ALLOCA_CALLFRAME(mcode->stack_size);
- frame->prepare(vmm->stack_size);
+ frame->prepare(mcode->stack_size);
frame->previous = previous;
frame->constant_scope_ = invocation.constant_scope;
@@ -307,7 +307,7 @@ namespace rubinius {
// TODO: this is a quick hack to process block arguments in 1.9.
if(!LANGUAGE_18_ENABLED(state)) {
- if(!GenericArguments::call(state, frame, vmm, scope, args, invocation.flags)) {
+ if(!GenericArguments::call(state, frame, mcode, scope, args, invocation.flags)) {
return NULL;
}
}
@@ -333,12 +333,12 @@ namespace rubinius {
}
tooling::BlockEntry method(state, env, mod);
- return (*vmm->run)(state, vmm, frame);
+ return (*mcode->run)(state, mcode, frame);
} else {
- return (*vmm->run)(state, vmm, frame);
+ return (*mcode->run)(state, mcode, frame);
}
#else
- return (*vmm->run)(state, vmm, frame);
+ return (*mcode->run)(state, mcode, frame);
#endif
}
@@ -396,20 +396,20 @@ namespace rubinius {
BlockEnvironment* BlockEnvironment::under_call_frame(STATE, GCToken gct,
- CompiledCode* cm, VMMethod* caller,
+ CompiledCode* cm, MachineCode* caller,
CallFrame* call_frame)
{
OnStack<1> os(state, cm);
state->set_call_frame(call_frame);
- VMMethod* vmm = cm->internalize(state, gct);
- if(!vmm) {
+ MachineCode* mcode = cm->internalize(state, gct);
+ if(!mcode) {
Exception::internal_error(state, call_frame, "invalid bytecode method");
return 0;
}
- vmm->set_parent(caller);
+ mcode->set_parent(caller);
BlockEnvironment* be = state->new_object<BlockEnvironment>(G(blokenv));
be->scope(state, call_frame->promote_scope(state));
@@ -444,7 +444,7 @@ namespace rubinius {
return cNil;
}
- target->cm->backend_method()->set_no_inline();
+ target->cm->machine_code()->set_no_inline();
if(target->scope) {
return target->scope->block();
@@ -9,7 +9,7 @@ namespace rubinius {
class CompiledCode;
class VariableScope;
struct CallFrame;
- class VMMethod;
+ class MachineCode;
class VMExecutable;
class BlockEnvironment;
@@ -52,7 +52,7 @@ namespace rubinius {
/* interface */
static void init(STATE);
- VMMethod* vmmethod(STATE, GCToken gct);
+ MachineCode* machine_code(STATE, GCToken gct);
// Rubinius.primitive :blockenvironment_allocate
static BlockEnvironment* allocate(STATE);
@@ -62,7 +62,7 @@ namespace rubinius {
BlockInvocation& invocation);
static BlockEnvironment* under_call_frame(STATE, GCToken gct, CompiledCode* cm,
- VMMethod* caller, CallFrame* call_frame);
+ MachineCode* caller, CallFrame* call_frame);
static Object* execute_interpreter(STATE, CallFrame* previous,
BlockEnvironment* env, Arguments& args,
Oops, something went wrong.

2 comments on commit 6fce2f6

Member

ryoqun replied Sep 1, 2012

Hi, I think these renames are really great as well as those in the next commit.

As software projects grow, the code base gets uglier as modifications pile up. So, I have a strong belief that regular cleaning is a must. However, many projects don't practice it due to lack of man power, inevitable large change, overly-worried incompatibility, etc...

I'm really happy Rubinius isn't one of those projects. That's one of my reason why I love Rubinius out of all other Ruby implementations. Without doubt, Rubinius got more readable by this commit and the next one.

Thanks for great work!

Owner

brixen replied Sep 2, 2012

Thank you @ryoqun. We have always strived to keep the code in Rubinius and RubySpec as clean as possible. It inevitably gets messy and we have more cleaning to do, but the importance of clean code for correctness and comprehension cannot be overestimated.

Please sign in to comment.