Permalink
Browse files

Remove address specialization for interpreter

This turns out not to be of much gain, since benchmarks show the same
numbers before and after this change (some tiny improvements in certain
places, tiny degrations in others). Because of the added complexity it
does have, we might as well remove it for now and review other
techniques if we want to speed up the interpreter significantly.
  • Loading branch information...
1 parent 0c42833 commit 719696d51a74729a589340d56c66c02ded6dde7e @dbussink dbussink committed Apr 17, 2013
Showing with 29 additions and 70 deletions.
  1. +0 −2 vm/builtin/compiledcode.cpp
  2. +0 −4 vm/call_frame.hpp
  3. +26 −30 vm/instructions.cpp
  4. +3 −6 vm/instructions.def
  5. +0 −15 vm/machine_code.cpp
  6. +0 −13 vm/machine_code.hpp
@@ -427,15 +427,13 @@ namespace rubinius {
size_t index = mcode->inline_cache_offsets()[i];
Object* new_cache = mark.call(reinterpret_cast<Object*>(mcode->opcodes[index + 1]));
mcode->opcodes[index + 1] = reinterpret_cast<intptr_t>(new_cache);
- mcode->update_addresses(index, 1);
mark.just_set(code, new_cache);
}
for(size_t i = 0; i < mcode->constant_cache_count(); i++) {
size_t index = mcode->constant_cache_offsets()[i];
Object* new_cache = mark.call(reinterpret_cast<Object*>(mcode->opcodes[index + 1]));
mcode->opcodes[index + 1] = reinterpret_cast<intptr_t>(new_cache);
- mcode->update_addresses(index, 1);
mark.just_set(code, new_cache);
}
}
View
@@ -224,10 +224,6 @@ namespace rubinius {
return ip_++;
}
- void calculate_ip(void** pos) {
- ip_ = pos - compiled_code->machine_code()->addresses;
- }
-
VariableScope* promote_scope_full(STATE);
VariableScope* promote_scope(STATE) {
View
@@ -82,31 +82,27 @@ Object* MachineCode::interpreter(STATE,
#include "vm/gen/instruction_locations.hpp"
- if(unlikely(state == 0)) {
- MachineCode::instructions = const_cast<void**>(insn_locations);
- return NULL;
- }
-
InterpreterState is;
GCTokenImpl gct;
- register void** ip_ptr = mcode->addresses;
-
- Object** stack_ptr = call_frame->stk - 1;
+ register opcode* ip_ptr = mcode->opcodes;
+ register Object** stack_ptr = call_frame->stk - 1;
UnwindInfoSet unwinds;
continue_to_run:
try {
#undef DISPATCH
-#define DISPATCH goto **ip_ptr++
+#define DISPATCH goto *insn_locations[*ip_ptr++];
#undef next_int
-#define next_int ((opcode)(*ip_ptr++))
+#undef store_ip
+#undef flush_ip
-#define cache_ip(which) ip_ptr = mcode->addresses + which
-#define flush_ip() call_frame->calculate_ip(ip_ptr)
+#define next_int ((opcode)(*ip_ptr++))
+#define store_ip(which) ip_ptr = mcode->opcodes + which
+#define flush_ip() call_frame->set_ip(ip_ptr - mcode->opcodes)
#include "vm/gen/instruction_implementations.hpp"
@@ -140,7 +136,7 @@ Object* MachineCode::interpreter(STATE,
UnwindInfo info = unwinds.pop();
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
goto continue_to_run;
} else {
call_frame->scope->flush_to_heap(state);
@@ -168,7 +164,7 @@ Object* MachineCode::interpreter(STATE,
if(info.for_ensure()) {
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
// Don't reset ep here, we're still handling the return/break.
goto continue_to_run;
@@ -249,11 +245,11 @@ Object* MachineCode::uncommon_interpreter(STATE,
#define DISPATCH goto *insn_locations[stream[call_frame->inc_ip()]];
#undef next_int
-#undef cache_ip
+#undef store_ip
#undef flush_ip
#define next_int ((opcode)(stream[call_frame->inc_ip()]))
-#define cache_ip(which)
+#define store_ip(which) call_frame->set_ip(which)
#define flush_ip()
#include "vm/gen/instruction_implementations.hpp"
@@ -286,7 +282,7 @@ Object* MachineCode::uncommon_interpreter(STATE,
UnwindInfo info = unwinds.pop();
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
goto continue_to_run;
} else {
call_frame->scope->flush_to_heap(state);
@@ -314,7 +310,7 @@ Object* MachineCode::uncommon_interpreter(STATE,
if(info.for_ensure()) {
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
// Don't reset ep here, we're still handling the return/break.
goto continue_to_run;
@@ -394,11 +390,11 @@ Object* MachineCode::debugger_interpreter(STATE,
goto *insn_locations[stream[call_frame->inc_ip()]];
#undef next_int
-#undef cache_ip
+#undef store_ip
#undef flush_ip
#define next_int ((opcode)(stream[call_frame->inc_ip()]))
-#define cache_ip(which)
+#define store_ip(which) call_frame->set_ip(which)
#define flush_ip()
#include "vm/gen/instruction_implementations.hpp"
@@ -432,7 +428,7 @@ Object* MachineCode::debugger_interpreter(STATE,
UnwindInfo info = unwinds.pop();
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
goto continue_to_run;
} else {
call_frame->scope->flush_to_heap(state);
@@ -462,7 +458,7 @@ Object* MachineCode::debugger_interpreter(STATE,
if(info.for_ensure()) {
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
// Don't reset ep here, we're still handling the return/break.
goto continue_to_run;
@@ -527,11 +523,11 @@ Object* MachineCode::debugger_interpreter_continue(STATE,
goto *insn_locations[stream[call_frame->inc_ip()]];
#undef next_int
-#undef cache_ip
+#undef store_ip
#undef flush_ip
#define next_int ((opcode)(stream[call_frame->inc_ip()]))
-#define cache_ip(which)
+#define store_ip(which) call_frame->set_ip(which)
#define flush_ip()
#include "vm/gen/instruction_implementations.hpp"
@@ -564,7 +560,7 @@ Object* MachineCode::debugger_interpreter_continue(STATE,
UnwindInfo info = unwinds.pop();
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
goto continue_to_run;
} else {
call_frame->scope->flush_to_heap(state);
@@ -592,7 +588,7 @@ Object* MachineCode::debugger_interpreter_continue(STATE,
if(info.for_ensure()) {
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
// Don't reset ep here, we're still handling the return/break.
goto continue_to_run;
@@ -658,11 +654,11 @@ Object* MachineCode::tooling_interpreter(STATE,
goto *insn_locations[stream[call_frame->inc_ip()]];
#undef next_int
-#undef cache_ip
+#undef store_ip
#undef flush_ip
#define next_int ((opcode)(stream[call_frame->inc_ip()]))
-#define cache_ip(which)
+#define store_ip(which) call_frame->set_ip(which)
#define flush_ip()
#include "vm/gen/instruction_implementations.hpp"
@@ -696,7 +692,7 @@ Object* MachineCode::tooling_interpreter(STATE,
UnwindInfo info = unwinds.pop();
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
goto continue_to_run;
} else {
call_frame->scope->flush_to_heap(state);
@@ -726,7 +722,7 @@ Object* MachineCode::tooling_interpreter(STATE,
if(info.for_ensure()) {
stack_position(info.stack_depth);
call_frame->set_ip(info.target_ip);
- cache_ip(info.target_ip);
+ store_ip(info.target_ip);
// Don't reset ep here, we're still handling the return/break.
goto continue_to_run;
View
@@ -98,8 +98,7 @@ section "Flow control"
# goto_if_false
instruction goto(location) [ -- ] => branch
- call_frame->set_ip(location);
- cache_ip(location);
+ store_ip(location);
end
# [Description]
@@ -112,8 +111,7 @@ end
instruction goto_if_false(location) [ value -- ] => branch
Object* t1 = stack_pop();
if(!CBOOL(t1)) {
- call_frame->set_ip(location);
- cache_ip(location);
+ store_ip(location);
}
end
@@ -127,8 +125,7 @@ end
instruction goto_if_true(location) [ value -- ] => branch
Object* t1 = stack_pop();
if(CBOOL(t1)) {
- call_frame->set_ip(location);
- cache_ip(location);
+ store_ip(location);
}
end
View
@@ -44,11 +44,7 @@
*/
namespace rubinius {
- void** MachineCode::instructions = 0;
-
void MachineCode::init(STATE) {
- // Seed the instructions table
- interpreter(0, 0, 0);
}
/*
@@ -77,7 +73,6 @@ namespace rubinius {
total = meth->iseq()->opcodes()->num_fields();
opcodes = new opcode[total];
- addresses = new void*[total];
fill_opcodes(state, meth);
stack_size = meth->stack_size()->to_native();
@@ -115,7 +110,6 @@ namespace rubinius {
MachineCode::~MachineCode() {
delete[] opcodes;
- delete[] addresses;
if(inline_cache_offsets_) {
delete[] inline_cache_offsets_;
@@ -157,8 +151,6 @@ namespace rubinius {
break;
}
- update_addresses(index, width - 1);
-
switch(opcodes[index]) {
case InstructionSequence::insn_send_method:
case InstructionSequence::insn_send_stack:
@@ -214,7 +206,6 @@ namespace rubinius {
InvokePrimitive invoker = Primitives::get_invoke_stub(state, name);
opcodes[ip + 1] = reinterpret_cast<intptr_t>(invoker);
- update_addresses(ip, 1);
break;
}
case InstructionSequence::insn_allow_private:
@@ -267,7 +258,6 @@ namespace rubinius {
}
opcodes[ip + 1] = reinterpret_cast<intptr_t>(cache);
- update_addresses(ip, 1);
is_super = false;
allow_private = false;
@@ -295,7 +285,6 @@ namespace rubinius {
constant_cache_offsets_[constant_index] = ip;
constant_index++;
opcodes[ip + 1] = reinterpret_cast<intptr_t>(cache);
- update_addresses(ip, 1);
break;
}
}
@@ -510,8 +499,6 @@ namespace rubinius {
if(it != ti->slots.end()) {
opcodes[i] = InstructionSequence::insn_push_my_offset;
opcodes[i + 1] = ti->slot_locations[it->second];
-
- update_addresses(i, 1);
}
} else if(op == InstructionSequence::insn_set_ivar) {
native_int idx = opcodes[i + 1];
@@ -521,8 +508,6 @@ namespace rubinius {
if(it != ti->slots.end()) {
opcodes[i] = InstructionSequence::insn_store_my_field;
opcodes[i + 1] = it->second;
-
- update_addresses(i, 1);
}
}
View
@@ -29,7 +29,6 @@ namespace rubinius {
class MachineCode : public CodeResource {
public:
- static void** instructions;
enum Flags {
eNoInline = 1 << 0,
@@ -57,7 +56,6 @@ namespace rubinius {
InterpreterRunner run;
opcode* opcodes;
- void** addresses;
std::size_t total;
TypeInfo* type;
@@ -125,17 +123,6 @@ namespace rubinius {
execute_status_ = s;
}
- void update_addresses(int index, int operands=0) {
- addresses[index] = instructions[opcodes[index]];
- switch(operands) {
- case 2:
- addresses[index + 2] = reinterpret_cast<void*>(opcodes[index + 2]);
- // fall through
- case 1:
- addresses[index + 1] = reinterpret_cast<void*>(opcodes[index + 1]);
- }
- }
-
size_t inline_cache_count() {
return number_of_inline_caches_;
}

0 comments on commit 719696d

Please sign in to comment.