Skip to content

Commit

Permalink
Showing 9 changed files with 115 additions and 10 deletions.
12 changes: 12 additions & 0 deletions machine/builtin/trie.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "alloc.hpp"

#include "builtin/trie.hpp"

namespace rubinius {
uintptr_t Trie::fields_offset;

void Trie::bootstrap(STATE) {
Trie* trie = ALLOCA(Trie);
fields_offset = (uintptr_t)&(trie->field) - (uintptr_t)trie;
}
}
42 changes: 42 additions & 0 deletions machine/builtin/trie.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef RBX_BUILTIN_TRIE_HPP
#define RBX_BUILTIN_TRIE_HPP

#include "memory.hpp"

#include "builtin/object.hpp"

namespace rubinius {
class Trie : public DataHeader {
public:
const static object_type type = TrieType;
static uintptr_t fields_offset;

attr_field(full_size, native_int);
attr_field(bitmap, native_int);

Object* field[0];

public:
native_int num_fields() const {
return (full_size() - fields_offset) / sizeof(Object*);
}

static void bootstrap(STATE);

class Info : public TypeInfo {
public:
Info(object_type type)
: TypeInfo(type)
{
allow_user_allocate = false;
}

virtual void mark(Object* obj, memory::ObjectMark& mark) {}
virtual void auto_mark(Object* obj, memory::ObjectMark& mark) {}
virtual void show(STATE, Object* self, int level) {}
virtual void show_simple(STATE, Object* self, int level) {}
virtual size_t object_size(const ObjectHeader* object) { return sizeof(Trie); }
};
};
}
#endif
7 changes: 5 additions & 2 deletions machine/codegen/field_extract.rb
Original file line number Diff line number Diff line change
@@ -808,7 +808,8 @@ def initialize
"Float" => :Float,
"Bignum" => :Bignum,
"Hash" => :Hash,
"Channel" => :Channel
"Channel" => :Channel,
"DataHeader" => :DataHeader,
}

end
@@ -840,7 +841,9 @@ def parse_stream(f)

while l = f.gets
next unless m = class_pattern.match(l)
if m[2] != "Object" and m[2] != "ObjectHeader"
if m[2] == "DataHeader"
cpp = CPPClass.new(m[1])
elsif m[2] != "Object" and m[2] != "ObjectHeader"
# We've found a class definition that doesn't extend Object.
# If we recognize the superclass, make a new CPPClass instance
# for this class definition.
2 changes: 2 additions & 0 deletions machine/ontology.cpp
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@
#include "builtin/thread.hpp"
#include "builtin/time.hpp"
#include "builtin/stat.hpp"
#include "builtin/trie.hpp"
#include "builtin/tuple.hpp"
#include "builtin/autoload.hpp"
#include "builtin/proc.hpp"
@@ -266,6 +267,7 @@ namespace rubinius {
JIT::bootstrap(state);
CodeDB::bootstrap(state);
Diagnostics::bootstrap(state);
Trie::bootstrap(state);
}

// @todo document all the sections of bootstrap_ontology
4 changes: 4 additions & 0 deletions machine/oop.cpp
Original file line number Diff line number Diff line change
@@ -26,6 +26,10 @@ namespace rubinius {
nw.flags64);
}

size_t DataHeader::slow_size_in_bytes(VM* vm) const {
return vm->memory()->type_info[type_id()]->object_size(this);
}

bool ObjectHeader::set_inflated_header(STATE, uint32_t ih_index, HeaderWord orig) {

if(orig.f.meaning == eAuxWordInflated) return false;
36 changes: 36 additions & 0 deletions machine/oop.hpp
Original file line number Diff line number Diff line change
@@ -280,6 +280,42 @@ Object* const cUndef = reinterpret_cast<Object*>(0x22L);
private:
};

class DataHeader {
HeaderWord header;
void* __body__[0];

public:

ObjectFlags flags() const {
return header.f;
}

object_type type_id() const {
return flags().obj_type;
}

/* It's the slow case, should be called only if there's no cached
* instance size. */
size_t slow_size_in_bytes(VM* vm) const;

size_t size_in_bytes(VM* vm) const {
size_t size = TypeInfo::instance_sizes[type_id()];
if(size != 0) {
return size;
} else {
return slow_size_in_bytes(vm);
}
}

size_t body_in_bytes(VM* state) const {
return size_in_bytes(state) - sizeof(DataHeader);
}

void** pointer_to_body() {
return __body__;
}
};

class ObjectHeader {
private:
HeaderWord header;
6 changes: 0 additions & 6 deletions machine/type_info.cpp
Original file line number Diff line number Diff line change
@@ -48,12 +48,6 @@ namespace rubinius {
auto_mark(obj, mark);
}

size_t TypeInfo::object_size(const ObjectHeader* obj) {
abort();
// Must be implemented, if goes here
return 0;
}

void TypeInfo::class_info(STATE, const Object* self, bool newline) {
std::cout << const_cast<Object*>(self)->to_s(state, true)->c_str(state);
if(newline) std::cout << std::endl;
15 changes: 13 additions & 2 deletions machine/type_info.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef RBX_VM_TYPE_INFO_HPP
#define RBX_VM_TYPE_INFO_HPP

#include <stdlib.h>
#include <map>
#include <stdexcept>
#include <vector>
@@ -15,6 +16,7 @@ namespace rubinius {
class Class;
class Object;
class Memory;
class DataHeader;
class ObjectHeader;

namespace memory {
@@ -94,9 +96,18 @@ namespace rubinius {
virtual void populate_slot_locations() { }

/**
* Slow case, should be called only if instance_size is zero
* Objects whose size is static generate a entry in the types data
* structure for that size, which is accessed directly via the data
* structure instead of via a method call. Objects whose size is defined
* at runtime must implement this method.
*/
virtual size_t object_size(const ObjectHeader * obj);
virtual size_t object_size(const ObjectHeader* obj) {
::abort();
}

virtual size_t object_size(const DataHeader* obj) {
::abort();
}

/**
* Currently prints the same output as show_simple. Is specialized by
1 change: 1 addition & 0 deletions rakelib/vm.rake
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ field_extract_headers = %w[
machine/builtin/jit.hpp
machine/builtin/code_db.hpp
machine/builtin/diagnostics.hpp
machine/builtin/trie.hpp
]

transcoders_src_dir = File.expand_path "../../vendor/oniguruma/enc/trans", __FILE__

0 comments on commit 43c3611

Please sign in to comment.