Skip to content

Commit 43c3611

Browse files
committedJul 19, 2016
Added start of DataHeader and Trie.
1 parent 29d2571 commit 43c3611

File tree

9 files changed

+115
-10
lines changed

9 files changed

+115
-10
lines changed
 

‎machine/builtin/trie.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "alloc.hpp"
2+
3+
#include "builtin/trie.hpp"
4+
5+
namespace rubinius {
6+
uintptr_t Trie::fields_offset;
7+
8+
void Trie::bootstrap(STATE) {
9+
Trie* trie = ALLOCA(Trie);
10+
fields_offset = (uintptr_t)&(trie->field) - (uintptr_t)trie;
11+
}
12+
}

‎machine/builtin/trie.hpp

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef RBX_BUILTIN_TRIE_HPP
2+
#define RBX_BUILTIN_TRIE_HPP
3+
4+
#include "memory.hpp"
5+
6+
#include "builtin/object.hpp"
7+
8+
namespace rubinius {
9+
class Trie : public DataHeader {
10+
public:
11+
const static object_type type = TrieType;
12+
static uintptr_t fields_offset;
13+
14+
attr_field(full_size, native_int);
15+
attr_field(bitmap, native_int);
16+
17+
Object* field[0];
18+
19+
public:
20+
native_int num_fields() const {
21+
return (full_size() - fields_offset) / sizeof(Object*);
22+
}
23+
24+
static void bootstrap(STATE);
25+
26+
class Info : public TypeInfo {
27+
public:
28+
Info(object_type type)
29+
: TypeInfo(type)
30+
{
31+
allow_user_allocate = false;
32+
}
33+
34+
virtual void mark(Object* obj, memory::ObjectMark& mark) {}
35+
virtual void auto_mark(Object* obj, memory::ObjectMark& mark) {}
36+
virtual void show(STATE, Object* self, int level) {}
37+
virtual void show_simple(STATE, Object* self, int level) {}
38+
virtual size_t object_size(const ObjectHeader* object) { return sizeof(Trie); }
39+
};
40+
};
41+
}
42+
#endif

‎machine/codegen/field_extract.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ def initialize
808808
"Float" => :Float,
809809
"Bignum" => :Bignum,
810810
"Hash" => :Hash,
811-
"Channel" => :Channel
811+
"Channel" => :Channel,
812+
"DataHeader" => :DataHeader,
812813
}
813814

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

841842
while l = f.gets
842843
next unless m = class_pattern.match(l)
843-
if m[2] != "Object" and m[2] != "ObjectHeader"
844+
if m[2] == "DataHeader"
845+
cpp = CPPClass.new(m[1])
846+
elsif m[2] != "Object" and m[2] != "ObjectHeader"
844847
# We've found a class definition that doesn't extend Object.
845848
# If we recognize the superclass, make a new CPPClass instance
846849
# for this class definition.

‎machine/ontology.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "builtin/thread.hpp"
4949
#include "builtin/time.hpp"
5050
#include "builtin/stat.hpp"
51+
#include "builtin/trie.hpp"
5152
#include "builtin/tuple.hpp"
5253
#include "builtin/autoload.hpp"
5354
#include "builtin/proc.hpp"
@@ -266,6 +267,7 @@ namespace rubinius {
266267
JIT::bootstrap(state);
267268
CodeDB::bootstrap(state);
268269
Diagnostics::bootstrap(state);
270+
Trie::bootstrap(state);
269271
}
270272

271273
// @todo document all the sections of bootstrap_ontology

‎machine/oop.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace rubinius {
2626
nw.flags64);
2727
}
2828

29+
size_t DataHeader::slow_size_in_bytes(VM* vm) const {
30+
return vm->memory()->type_info[type_id()]->object_size(this);
31+
}
32+
2933
bool ObjectHeader::set_inflated_header(STATE, uint32_t ih_index, HeaderWord orig) {
3034

3135
if(orig.f.meaning == eAuxWordInflated) return false;

‎machine/oop.hpp

+36
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,42 @@ Object* const cUndef = reinterpret_cast<Object*>(0x22L);
280280
private:
281281
};
282282

283+
class DataHeader {
284+
HeaderWord header;
285+
void* __body__[0];
286+
287+
public:
288+
289+
ObjectFlags flags() const {
290+
return header.f;
291+
}
292+
293+
object_type type_id() const {
294+
return flags().obj_type;
295+
}
296+
297+
/* It's the slow case, should be called only if there's no cached
298+
* instance size. */
299+
size_t slow_size_in_bytes(VM* vm) const;
300+
301+
size_t size_in_bytes(VM* vm) const {
302+
size_t size = TypeInfo::instance_sizes[type_id()];
303+
if(size != 0) {
304+
return size;
305+
} else {
306+
return slow_size_in_bytes(vm);
307+
}
308+
}
309+
310+
size_t body_in_bytes(VM* state) const {
311+
return size_in_bytes(state) - sizeof(DataHeader);
312+
}
313+
314+
void** pointer_to_body() {
315+
return __body__;
316+
}
317+
};
318+
283319
class ObjectHeader {
284320
private:
285321
HeaderWord header;

‎machine/type_info.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,6 @@ namespace rubinius {
4848
auto_mark(obj, mark);
4949
}
5050

51-
size_t TypeInfo::object_size(const ObjectHeader* obj) {
52-
abort();
53-
// Must be implemented, if goes here
54-
return 0;
55-
}
56-
5751
void TypeInfo::class_info(STATE, const Object* self, bool newline) {
5852
std::cout << const_cast<Object*>(self)->to_s(state, true)->c_str(state);
5953
if(newline) std::cout << std::endl;

‎machine/type_info.hpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef RBX_VM_TYPE_INFO_HPP
22
#define RBX_VM_TYPE_INFO_HPP
33

4+
#include <stdlib.h>
45
#include <map>
56
#include <stdexcept>
67
#include <vector>
@@ -15,6 +16,7 @@ namespace rubinius {
1516
class Class;
1617
class Object;
1718
class Memory;
19+
class DataHeader;
1820
class ObjectHeader;
1921

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

9698
/**
97-
* Slow case, should be called only if instance_size is zero
99+
* Objects whose size is static generate a entry in the types data
100+
* structure for that size, which is accessed directly via the data
101+
* structure instead of via a method call. Objects whose size is defined
102+
* at runtime must implement this method.
98103
*/
99-
virtual size_t object_size(const ObjectHeader * obj);
104+
virtual size_t object_size(const ObjectHeader* obj) {
105+
::abort();
106+
}
107+
108+
virtual size_t object_size(const DataHeader* obj) {
109+
::abort();
110+
}
100111

101112
/**
102113
* Currently prints the same output as show_simple. Is specialized by

‎rakelib/vm.rake

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ field_extract_headers = %w[
120120
machine/builtin/jit.hpp
121121
machine/builtin/code_db.hpp
122122
machine/builtin/diagnostics.hpp
123+
machine/builtin/trie.hpp
123124
]
124125

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

0 commit comments

Comments
 (0)
Please sign in to comment.