Permalink
Browse files

Setup specific allocators for String

Right now the JIT can't handle super() calls yet. This let to the
allocator for String to never be JIT'ted. For now we use these specific
allocators. In the future we should teach the JIT about super() (at
least for simple cases like this), so we can remove these specifics
then.

Also sets up Character like we setup the other internal VM classes.
  • Loading branch information...
1 parent 7042a04 commit a528390b6c517f2a8424d72a668f5477e448f38d @dbussink dbussink committed Dec 18, 2012
@@ -1,5 +1,18 @@
module Rubinius
class Character < ::String
+
+ def self.__allocate__
+ Rubinius.primitive :character_allocate
+ raise PrimitiveFailure, "Rubinius::Character.allocate primitive failed"
+ end
+
+ def self.allocate
+ chr = __allocate__
+ chr.__data__ = Rubinius::ByteArray.new(1)
+ chr.num_bytes = 0
+ chr
+ end
+
def alphabetical?
Rubinius.primitive :character_alphabetical_p
raise PrimitiveFailure, "Rubinius::Character#alphabetical? primitive failed"
View
@@ -7,8 +7,13 @@
class String
include Comparable
+ def self.__allocate__
+ Rubinius.primitive :string_allocate
+ raise PrimitiveFailure, "String.allocate primitive failed"
+ end
+
def self.allocate
- str = super()
+ str = __allocate__
str.__data__ = Rubinius::ByteArray.new(1)
str.num_bytes = 0
str
@@ -36,7 +41,7 @@ def clone
end
def initialize(arg = undefined)
- replace StringValue(arg) unless arg.equal?(undefined)
+ replace arg unless arg.equal?(undefined)
self
end
View
@@ -15,14 +15,18 @@
namespace rubinius {
void Character::init(STATE) {
- Class* cls = ontology::new_class(state, "Character", G(string), G(rubinius));
- cls->set_object_type(state, CharacterType);
- G(rubinius)->set_const(state, "Character", cls);
+ GO(character).set(ontology::new_class(state, "Character", G(string), G(rubinius)));
+ G(character)->set_object_type(state, CharacterType);
+ }
+
+ Character* Character::allocate(STATE, Object* self) {
+ Character* chr = state->new_object<Character>(G(character));
+ chr->klass(state, as<Class>(self));
+ return chr;
}
Character* Character::create(STATE, native_int size) {
- Class* cls = as<Class>(G(rubinius)->get_const(state, "Character"));
- Character* chr = state->new_object<Character>(cls);
+ Character* chr = state->new_object<Character>(G(character));
chr->num_bytes(state, Fixnum::from(size));
chr->hash_value(state, nil<Fixnum>());
View
@@ -10,6 +10,9 @@ namespace rubinius {
static void init(STATE);
+ // Rubinius.primitive :character_allocate
+ static Character* allocate(STATE, Object* self);
+
static Character* create(STATE, native_int size);
static Character* create(STATE, const char* bytes, native_int size);
static Character* create_from(STATE, String* str, Fixnum* byte);
View
@@ -69,6 +69,12 @@ namespace rubinius {
G(string)->set_object_type(state, StringType);
}
+ String* String::allocate(STATE, Object* self) {
+ String* str = state->new_object<String>(G(string));
+ str->klass(state, as<Class>(self));
+ return str;
+ }
+
/* Creates a String instance with +num_bytes+ == +size+ and
* having a ByteArray with at least (size + 1) bytes.
*/
View
@@ -86,6 +86,9 @@ namespace rubinius {
static void init_hash();
static void init(STATE);
+ // Rubinius.primitive :string_allocate
+ static String* allocate(STATE, Object* self);
+
static String* create(STATE, Fixnum* size);
// Rubinius.primitive :string_from_bytearray
View
@@ -49,7 +49,7 @@ namespace rubinius {
TypedRoot<Class*> compiled_code, tuple, module, basicobject, object, array;
TypedRoot<Class*> klass, methtbl, bytearray;
TypedRoot<Class*> blokenv, bignum, regexp, matchdata;
- TypedRoot<Class*> string, symbol, io;
+ TypedRoot<Class*> string, character, symbol, io;
TypedRoot<Class*> nil_class, true_class, false_class, fixnum_class, undef_class;
TypedRoot<Class*> floatpoint, nmc, list, list_node;
TypedRoot<Class*> channel, thread, constantscope, lookuptable;
@@ -135,6 +135,7 @@ namespace rubinius {
regexp(&roots),
matchdata(&roots),
string(&roots),
+ character(&roots),
symbol(&roots),
io(&roots),
nil_class(&roots),
View
@@ -2095,7 +2095,10 @@ namespace rubinius {
constant(as<Symbol>(literal(name)))
};
- Value* ret = b().CreateCall(func, call_args, "push_const_fast");
+ CallInst* ret = b().CreateCall(func, call_args, "push_const_fast");
+ ret->setOnlyReadsMemory();
+ ret->setDoesNotThrow();
+
check_for_exception(ret);
stack_push(ret);
}

0 comments on commit a528390

Please sign in to comment.