Skip to content

Commit

Permalink
More Metrics cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Jun 28, 2015
1 parent 291c7c7 commit 1132e25
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 66 deletions.
10 changes: 6 additions & 4 deletions vm/builtin/executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ namespace rubinius {
return dis.send(state, call_frame, args);
}

void Executable::add_inliner(ObjectMemory* om, CompiledCode* code) {
if(!inliners_ || inliners_ == (Inliners*)cNil) inliners_ = new Inliners(om);
void Executable::add_inliner(STATE, ObjectMemory* om, CompiledCode* code) {
if(!inliners_ || inliners_ == (Inliners*)cNil) {
inliners_ = new Inliners(state, om);
}
inliners_->inliners().push_back(code);

om->write_barrier(this, code);
Expand Down Expand Up @@ -106,8 +108,8 @@ namespace rubinius {
}
}

Inliners::Inliners(ObjectMemory* om) {
om->add_code_resource(this);
Inliners::Inliners(STATE, ObjectMemory* om) {
om->add_code_resource(state, this);
}

void Inliners::cleanup(STATE, CodeManager* cm) {
Expand Down
4 changes: 2 additions & 2 deletions vm/builtin/executable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace rubinius {
std::vector<CompiledCode*> inliners_;

public:
Inliners(ObjectMemory* om);
Inliners(STATE, ObjectMemory* om);

std::vector<CompiledCode*>& inliners() {
return inliners_;
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace rubinius {

bool resolve_primitive(STATE);

void add_inliner(ObjectMemory* om, CompiledCode* code);
void add_inliner(STATE, ObjectMemory* om, CompiledCode* code);
void clear_inliners(STATE);

class Info : public TypeInfo {
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/native_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ namespace rubinius {
rubinius::bug("ffi_prep_cif failed");
}

state->shared().om->add_code_resource(data);
state->shared().om->add_code_resource(state, data);
this->ffi_data = data;
}

Expand Down
13 changes: 0 additions & 13 deletions vm/gc/mark_sweep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ namespace rubinius {

MarkSweepGC::MarkSweepGC(ObjectMemory *om, Configuration& config)
: GarbageCollector(om)
, allocated_bytes(0)
, allocated_objects(0)
, collection_threshold(config.gc_marksweep_threshold)
, next_collection_bytes(collection_threshold)
, free_entries(true)
, times_collected(0)
, last_freed(0)
{}

MarkSweepGC::~MarkSweepGC() { }
Expand Down Expand Up @@ -70,12 +65,6 @@ namespace rubinius {
void MarkSweepGC::free_object(Object* obj, bool fast) {
if(!fast) {
delete_object(obj);

last_freed++;

object_memory_->state()->metrics().memory.large_objects--;
object_memory_->state()->metrics().memory.large_bytes -=
obj->size_in_bytes(object_memory_->state());
}

obj->set_zone(UnspecifiedZone);
Expand Down Expand Up @@ -124,8 +113,6 @@ namespace rubinius {

timer::StopWatch<timer::microseconds> timer(metrics.gc.large_sweep_us);

last_freed = 0;

// Cleanup all weakrefs seen
clean_weakrefs();

Expand Down
5 changes: 0 additions & 5 deletions vm/gc/mark_sweep.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ namespace rubinius {
public:
/* Data members */
std::list<Object*> entries;
size_t allocated_bytes;
size_t allocated_objects;
int collection_threshold;
int next_collection_bytes;
bool free_entries;
int times_collected;
int last_freed;

/* Prototypes */

Expand Down
6 changes: 4 additions & 2 deletions vm/llvm/inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ namespace rubinius {
}

policy->increase_size(mcode);
meth->add_inliner(ops_.llvm_state()->shared().om, ops_.root_method_info()->method());
meth->add_inliner(ops_.llvm_state()->state(),
ops_.llvm_state()->shared().om, ops_.root_method_info()->method());

inline_generic_method(klass, data, defined_in, code, mcode, hits);
return true;
Expand Down Expand Up @@ -312,7 +313,8 @@ namespace rubinius {
}

remember:
meth->add_inliner(ops_.llvm_state()->shared().om, ops_.root_method_info()->method());
meth->add_inliner(ops_.llvm_state()->state(),
ops_.llvm_state()->shared().om, ops_.root_method_info()->method());

return true;
}
Expand Down
3 changes: 2 additions & 1 deletion vm/llvm/jit_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ namespace jit {
mci_->address(), mci_->size());

// info.method()->set_jit_data(ctx.runtime_data_holder());
ctx_->llvm_state()->shared().om->add_code_resource(ctx_->runtime_data_holder());
ctx_->llvm_state()->shared().om->add_code_resource(
ctx_->llvm_state()->state(), ctx_->runtime_data_holder());
}

return mci_->address();
Expand Down
4 changes: 3 additions & 1 deletion vm/llvm/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ namespace rubinius {
}

void LLVMState::run(STATE) {
state_ = state;

GCTokenImpl gct;
JITCompileRequest* compile_request = nil<JITCompileRequest>();
OnStack<1> os(state, compile_request);
Expand Down Expand Up @@ -392,7 +394,7 @@ namespace rubinius {
}

Symbol* LLVMState::symbol(const std::string& sym) {
return symbols_.lookup(&shared_, sym);
return symbols_.lookup(state(), &shared_, sym);
}

std::string LLVMState::symbol_debug_str(const Symbol* sym) {
Expand Down
6 changes: 6 additions & 0 deletions vm/llvm/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ namespace rubinius {
SymbolTable& symbols_;

SharedState& shared_;
State* state_;

bool include_profiling_;

std::ostream* log_;
Expand Down Expand Up @@ -121,6 +123,10 @@ namespace rubinius {
LLVMState(STATE);
virtual ~LLVMState();

State* state() {
return state_;
}

void add_internal_functions();
void enable(STATE);

Expand Down
2 changes: 1 addition & 1 deletion vm/machine_code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace rubinius {
specializations[i].jit_data = 0;
}

state->shared().om->add_code_resource(this);
state->shared().om->add_code_resource(state, this);
}

MachineCode::~MachineCode() {
Expand Down
1 change: 0 additions & 1 deletion vm/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ namespace rubinius {
slab_refills_fails += data.slab_refills_fails;
data_objects += data.data_objects;
capi_handles += data.capi_handles;
capi_handles += data.capi_handles;
inflated_headers += data.inflated_headers;
}
};
Expand Down
20 changes: 3 additions & 17 deletions vm/object_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,6 @@ namespace rubinius {
}
}

// TODO: Fix API to support proper testing.
void ObjectMemory::debug_marksweep(bool val) {
if(val) {
mark_sweep_->free_entries = false;
} else {
mark_sweep_->free_entries = true;
}
}

bool ObjectMemory::valid_object_p(Object* obj) {
if(obj->young_object_p()) {
return young_->validate_object(obj) == cValid;
Expand Down Expand Up @@ -569,8 +560,6 @@ namespace rubinius {

metrics::MetricsData& metrics = state->vm()->metrics();
metrics.gc.young_count++;
metrics.memory.capi_handles = capi_handles_->size();
metrics.memory.inflated_headers = inflated_headers_->size();

data->global_cache()->prune_young();

Expand Down Expand Up @@ -647,11 +636,6 @@ namespace rubinius {
metrics::MetricsData& metrics = state->vm()->metrics();
metrics.gc.immix_count++;
metrics.gc.large_count++;
metrics.memory.immix_bytes += immix_->bytes_allocated();
metrics.memory.large_bytes += mark_sweep_->allocated_bytes;
metrics.memory.symbols += shared_.symbols.size();
metrics.memory.symbols_bytes += shared_.symbols.bytes_used();
metrics.memory.code_bytes += code_manager_.size();

if(FinalizerThread* hdl = state->shared().finalizer_handler()) {
hdl->finish_collection(state);
Expand Down Expand Up @@ -929,9 +913,11 @@ namespace rubinius {
return mark_sweep_->validate_object(obj);
}

void ObjectMemory::add_code_resource(CodeResource* cr) {
void ObjectMemory::add_code_resource(STATE, CodeResource* cr) {
utilities::thread::SpinLock::LockGuard guard(shared_.code_resource_lock());

state->vm()->metrics().memory.code_bytes += cr->size();

code_manager_.add_resource(cr, &collect_mature_now);
}

Expand Down
3 changes: 1 addition & 2 deletions vm/object_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,9 @@ namespace rubinius {
bool inflate_for_contention(STATE, ObjectHeader* obj);

bool valid_object_p(Object* obj);
void debug_marksweep(bool val);
void add_type_info(TypeInfo* ti);

void add_code_resource(CodeResource* cr);
void add_code_resource(STATE, CodeResource* cr);
void memstats();

void validate_handles(capi::Handles* handles);
Expand Down
2 changes: 2 additions & 0 deletions vm/oop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace rubinius {
new_val.f.aux_word = ih_index;
new_val.f.meaning = eAuxWordInflated;

state->vm()->metrics().memory.inflated_headers++;

// Make sure to include a barrier to the header is all properly initialized
atomic::memory_barrier();
return header.atomic_set(orig, new_val);
Expand Down
27 changes: 17 additions & 10 deletions vm/symbol_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,35 @@ namespace rubinius {
return k;
}

size_t SymbolTable::add(std::string str, int enc) {
bytes_used_ += (str.size() + sizeof(std::string) + sizeof(int) + sizeof(Kind));
size_t SymbolTable::add(STATE, std::string str, int enc) {
size_t bytes = (str.size() + sizeof(std::string) + sizeof(int) + sizeof(Kind));
bytes_used_ += bytes;

strings.push_back(str);
encodings.push_back(enc);
kinds.push_back(eUnknown);

state->vm()->metrics().memory.symbols++;
state->vm()->metrics().memory.symbols_bytes += bytes;

return strings.size() - 1;
}

Symbol* SymbolTable::lookup(STATE, const char* str, size_t length) {
return lookup(str, length, Encoding::eAscii, state->hash_seed());
return lookup(state, str, length, Encoding::eAscii, state->hash_seed());
}

Symbol* SymbolTable::lookup(SharedState* shared, const std::string& str) {
return lookup(str.data(), str.size(), Encoding::eAscii, shared->hash_seed);
Symbol* SymbolTable::lookup(STATE, SharedState* shared, const std::string& str) {
return lookup(state, str.data(), str.size(), Encoding::eAscii, shared->hash_seed);
}

Symbol* SymbolTable::lookup(STATE, const std::string& str) {
return lookup(str.data(), str.size(), Encoding::eAscii, state->hash_seed());
return lookup(state, str.data(), str.size(), Encoding::eAscii, state->hash_seed());
}

Symbol* SymbolTable::lookup(const char* str, size_t length, int enc, uint32_t seed) {
Symbol* SymbolTable::lookup(STATE, const char* str, size_t length,
int enc, uint32_t seed)
{
size_t sym;

hashval hash = String::hash_str((unsigned char*)str, length, seed);
Expand All @@ -115,7 +122,7 @@ namespace rubinius {
utilities::thread::SpinLock::LockGuard guard(lock_);
SymbolMap::iterator entry = symbols.find(hash);
if(entry == symbols.end()) {
sym = add(std::string(str, length), enc);
sym = add(state, std::string(str, length), enc);
SymbolIds v(1, sym);
symbols[hash] = v;
} else {
Expand All @@ -126,7 +133,7 @@ namespace rubinius {

if(!strncmp(s.data(), str, length) && e == enc) return Symbol::from_index(*i);
}
sym = add(std::string(str, length), enc);
sym = add(state, std::string(str, length), enc);
v.push_back(sym);
}
}
Expand All @@ -150,7 +157,7 @@ namespace rubinius {
if(CBOOL(str->ascii_only_p(state))) {
enc = Encoding::eAscii;
}
return lookup(bytes, size, enc, state->hash_seed());
return lookup(state, bytes, size, enc, state->hash_seed());
}

String* SymbolTable::lookup_string(STATE, const Symbol* sym) {
Expand Down
6 changes: 3 additions & 3 deletions vm/symbol_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ namespace rubinius {
return symbols.size();
};

Symbol* lookup(SharedState* shared, const std::string& str);
Symbol* lookup(STATE, SharedState* shared, const std::string& str);
Symbol* lookup(STATE, const std::string& str);
Symbol* lookup(STATE, const char* str, size_t length);
Symbol* lookup(const char* str, size_t length, int enc, uint32_t seed);
Symbol* lookup(STATE, const char* str, size_t length, int enc, uint32_t seed);
Symbol* lookup(STATE, String* str);
String* lookup_string(STATE, const Symbol* sym);

Expand All @@ -94,7 +94,7 @@ namespace rubinius {

Kind kind(STATE, const Symbol* sym);

size_t add(std::string str, int enc);
size_t add(STATE, std::string str, int enc);
Kind detect_kind(STATE, const Symbol* sym);
};
};
Expand Down
2 changes: 0 additions & 2 deletions vm/test/test_object_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ class TestObjectMemory : public CxxTest::TestSuite, public VMTest {
ObjectMemory& om = *state->memory();
Object* mature;

om.debug_marksweep(true);

om.large_object_threshold = 10;

mature = util_new_object(om,20);
Expand Down
2 changes: 1 addition & 1 deletion vm/test/test_symbol_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestSymbolTable : public CxxTest::TestSuite, public VMTest {
}

void test_detect_kind_with_unicode_constant() {
Symbol* sym = symbols->lookup("Pettsonλ", 9, Encoding::eUtf8, 0);
Symbol* sym = symbols->lookup(state, "Pettsonλ", 9, Encoding::eUtf8, 0);
SymbolTable::Kind kind = symbols->detect_kind(state, sym);

TS_ASSERT_EQUALS(kind, SymbolTable::eConstant);
Expand Down

0 comments on commit 1132e25

Please sign in to comment.