Move the Kernel string offsets into the VM's heap.

Copy the Kernel string offsets into a uint32 array in the VM's heap.
This avoids allocating small string objects with new and avoids having
a table of the canonical strings.

Instead of an offset and a size, strings are now represented as
indexes into the string table in the heap.  The start offset of string
N is found at byte offset N*4 because it is a uint32, and the end
offset is found at byte offset (N+1)*4.  The strings themselves are
just integer indexes instead of pointers.

In the stream flow graph builder, string access is all random access.

R=jensj@google.com, vegorov@google.com

Review-Url: https://codereview.chromium.org/2852943003 .
This commit is contained in:
Kevin Millikin 2017-05-02 17:35:50 +02:00
parent 8a9775e8ab
commit 865e0669b2
15 changed files with 273 additions and 336 deletions

View file

@ -367,8 +367,8 @@ static RawError* BootstrapFromKernel(Thread* thread, kernel::Program* program) {
dart_name = library.url();
for (intptr_t j = 0; j < program->libraries().length(); ++j) {
kernel::Library* kernel_library = program->libraries()[j];
kernel::String* uri = kernel_library->import_uri();
const String& kernel_name = reader.DartSymbol(uri);
intptr_t uri_index = kernel_library->import_uri();
const String& kernel_name = reader.DartSymbol(uri_index);
if (kernel_name.Equals(dart_name)) {
reader.ReadLibrary(kernel_library);
library.SetLoaded();

View file

@ -95,8 +95,8 @@ RawError* BootstrapFromKernel(Thread* thread, kernel::Program* program) {
dart_name = library.url();
for (intptr_t j = 0; j < program->libraries().length(); ++j) {
kernel::Library* kernel_library = program->libraries()[j];
kernel::String* uri = kernel_library->import_uri();
const String& kernel_name = reader.DartSymbol(uri);
intptr_t uri_index = kernel_library->import_uri();
const String& kernel_name = reader.DartSymbol(uri_index);
if (kernel_name.Equals(dart_name)) {
reader.ReadLibrary(kernel_library);
library.SetLoaded();

View file

@ -31,7 +31,7 @@ SourceTable::~SourceTable() {
CanonicalName::CanonicalName()
: parent_(NULL), name_(NULL), is_referenced_(false) {}
: parent_(NULL), name_index_(-1), is_referenced_(false) {}
CanonicalName::~CanonicalName() {
@ -46,10 +46,10 @@ CanonicalName* CanonicalName::NewRoot() {
}
CanonicalName* CanonicalName::AddChild(String* name) {
CanonicalName* CanonicalName::AddChild(intptr_t name_index) {
CanonicalName* child = new CanonicalName();
child->parent_ = this;
child->name_ = name;
child->name_index_ = name_index;
children_.Add(child);
return child;
}
@ -1231,7 +1231,7 @@ void FunctionType::VisitChildren(Visitor* visitor) {
VisitList(&type_parameters(), visitor);
VisitList(&positional_parameters(), visitor);
for (int i = 0; i < named_parameters().length(); ++i) {
named_parameters()[i]->second()->AcceptDartTypeVisitor(visitor);
named_parameters()[i]->type()->AcceptDartTypeVisitor(visitor);
}
return_type()->AcceptDartTypeVisitor(visitor);
}

View file

@ -243,66 +243,6 @@ class TypeParameterList : public List<TypeParameter> {
};
template <typename A, typename B>
class Tuple {
public:
static Tuple<A, B>* ReadFrom(Reader* reader);
Tuple(A* a, B* b) : first_(a), second_(b) {}
A* first() { return first_; }
B* second() { return second_; }
private:
Tuple() {}
Ref<A> first_;
Child<B> second_;
DISALLOW_COPY_AND_ASSIGN(Tuple);
};
class String {
public:
// Read a string reference, which is an index into the string table.
static String* ReadFrom(Reader* reader);
// Read a string implementation given its size.
static String* ReadRaw(Reader* reader, intptr_t size);
String(intptr_t offset, int size) : offset_(offset), size_(size) {}
intptr_t offset() { return offset_; }
int size() { return size_; }
bool is_empty() { return size_ == 0; }
private:
intptr_t offset_;
int size_;
DISALLOW_COPY_AND_ASSIGN(String);
};
class StringTable {
public:
void ReadFrom(Reader* reader);
List<String>& strings() { return strings_; }
private:
StringTable() {}
friend class Program;
List<String> strings_;
DISALLOW_COPY_AND_ASSIGN(StringTable);
};
class Source {
public:
~Source();
@ -390,12 +330,12 @@ class CanonicalName {
public:
~CanonicalName();
String* name() { return name_; }
intptr_t name() { return name_index_; }
CanonicalName* parent() { return parent_; }
bool is_referenced() { return is_referenced_; }
void set_referenced(bool referenced) { is_referenced_ = referenced; }
CanonicalName* AddChild(String* string);
CanonicalName* AddChild(intptr_t string_index);
static CanonicalName* NewRoot();
@ -403,7 +343,7 @@ class CanonicalName {
CanonicalName();
CanonicalName* parent_;
String* name_;
intptr_t name_index_;
MallocGrowableArray<CanonicalName*> children_;
bool is_referenced_;
@ -488,9 +428,9 @@ class Library : public LinkedNode {
virtual void AcceptTreeVisitor(TreeVisitor* visitor);
virtual void VisitChildren(Visitor* visitor);
String* import_uri() { return import_uri_; }
intptr_t import_uri() { return import_uri_index_; }
intptr_t source_uri_index() { return source_uri_index_; }
String* name() { return name_; }
intptr_t name() { return name_index_; }
List<Typedef>& typedefs() { return typedefs_; }
List<Class>& classes() { return classes_; }
List<Field>& fields() { return fields_; }
@ -500,13 +440,13 @@ class Library : public LinkedNode {
intptr_t kernel_data_size() { return kernel_data_size_; }
private:
Library() : name_(NULL), kernel_data_(NULL), kernel_data_size_(-1) {}
Library() : name_index_(-1), kernel_data_(NULL), kernel_data_size_(-1) {}
template <typename T>
friend class List;
Ref<String> name_;
Ref<String> import_uri_;
intptr_t name_index_;
intptr_t import_uri_index_;
intptr_t source_uri_index_;
List<Typedef> typedefs_;
List<Class> classes_;
@ -531,7 +471,7 @@ class Typedef : public LinkedNode {
virtual void VisitChildren(Visitor* visitor);
Library* parent() { return parent_; }
String* name() { return name_; }
intptr_t name() { return name_index_; }
intptr_t source_uri_index() { return source_uri_index_; }
TokenPosition position() { return position_; }
TypeParameterList& type_parameters() { return type_parameters_; }
@ -545,7 +485,7 @@ class Typedef : public LinkedNode {
friend class List;
Ref<Library> parent_;
Ref<String> name_;
intptr_t name_index_;
intptr_t source_uri_index_;
TokenPosition position_;
TypeParameterList type_parameters_;
@ -565,7 +505,7 @@ class Class : public LinkedNode {
virtual void AcceptClassVisitor(ClassVisitor* visitor) = 0;
Library* parent() { return parent_; }
String* name() { return name_; }
intptr_t name() { return name_index_; }
intptr_t source_uri_index() { return source_uri_index_; }
bool is_abstract() { return is_abstract_; }
List<Expression>& annotations() { return annotations_; }
@ -585,7 +525,7 @@ class Class : public LinkedNode {
friend class List;
Ref<Library> parent_;
Ref<String> name_;
intptr_t name_index_;
intptr_t source_uri_index_;
bool is_abstract_;
List<Expression> annotations_;
@ -1291,8 +1231,8 @@ class NamedExpression : public TreeNode {
public:
static NamedExpression* ReadFrom(Reader* reader);
NamedExpression(String* name, Expression* expr)
: name_(name), expression_(expr) {}
NamedExpression(intptr_t name_index, Expression* expr)
: name_index_(name_index), expression_(expr) {}
virtual ~NamedExpression();
DEFINE_CASTING_OPERATIONS(NamedExpression);
@ -1300,13 +1240,13 @@ class NamedExpression : public TreeNode {
virtual void AcceptTreeVisitor(TreeVisitor* visitor);
virtual void VisitChildren(Visitor* visitor);
String* name() { return name_; }
intptr_t name() { return name_index_; }
Expression* expression() { return expression_; }
private:
NamedExpression() {}
Ref<String> name_;
intptr_t name_index_;
Child<Expression> expression_;
DISALLOW_COPY_AND_ASSIGN(NamedExpression);
@ -1579,17 +1519,17 @@ class StringLiteral : public BasicLiteral {
virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor);
explicit StringLiteral(String* string) : value_(string) {}
explicit StringLiteral(intptr_t string_index) : value_index_(string_index) {}
virtual ~StringLiteral();
DEFINE_CASTING_OPERATIONS(StringLiteral);
String* value() { return value_; }
intptr_t value() { return value_index_; }
protected:
StringLiteral() {}
Ref<String> value_;
intptr_t value_index_;
private:
DISALLOW_COPY_AND_ASSIGN(StringLiteral);
@ -1602,7 +1542,7 @@ class BigintLiteral : public StringLiteral {
virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor);
explicit BigintLiteral(String* string) : StringLiteral(string) {}
explicit BigintLiteral(intptr_t string_index) : StringLiteral(string_index) {}
virtual ~BigintLiteral();
DEFINE_CASTING_OPERATIONS(BigintLiteral);
@ -1646,12 +1586,12 @@ class DoubleLiteral : public BasicLiteral {
virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor);
String* value() { return value_; }
intptr_t value() { return value_index_; }
private:
DoubleLiteral() {}
Ref<String> value_;
intptr_t value_index_;
DISALLOW_COPY_AND_ASSIGN(DoubleLiteral);
};
@ -1706,12 +1646,12 @@ class SymbolLiteral : public Expression {
virtual void AcceptExpressionVisitor(ExpressionVisitor* visitor);
virtual void VisitChildren(Visitor* visitor);
String* value() { return value_; }
intptr_t value() { return value_index_; }
private:
SymbolLiteral() {}
Ref<String> value_;
intptr_t value_index_;
DISALLOW_COPY_AND_ASSIGN(SymbolLiteral);
};
@ -2619,7 +2559,7 @@ class VariableDeclaration : public Statement {
bool IsConst() { return (flags_ & kFlagConst) == kFlagConst; }
bool IsFinal() { return (flags_ & kFlagFinal) == kFlagFinal; }
String* name() { return name_; }
intptr_t name() { return name_index_; }
DartType* type() { return type_; }
Expression* initializer() { return initializer_; }
TokenPosition equals_position() { return equals_position_; }
@ -2635,7 +2575,7 @@ class VariableDeclaration : public Statement {
friend class List;
word flags_;
Ref<String> name_;
intptr_t name_index_;
Child<DartType> type_;
Child<Expression> initializer_;
TokenPosition equals_position_;
@ -2680,14 +2620,15 @@ class Name : public Node {
virtual void AcceptVisitor(Visitor* visitor);
virtual void VisitChildren(Visitor* visitor);
String* string() { return string_; }
intptr_t string_index() { return string_index_; }
CanonicalName* library() { return library_reference_; }
private:
Name(String* string, CanonicalName* library_reference)
: string_(string), library_reference_(library_reference) {} // NOLINT
Name(intptr_t string_index, CanonicalName* library_reference)
: string_index_(string_index),
library_reference_(library_reference) {} // NOLINT
Ref<String> string_;
intptr_t string_index_;
Ref<CanonicalName> library_reference_; // Library.
DISALLOW_COPY_AND_ASSIGN(Name);
@ -2820,6 +2761,26 @@ class TypedefType : public DartType {
};
class NamedParameter {
public:
static NamedParameter* ReadFrom(Reader* reader);
NamedParameter(intptr_t name_index, DartType* type)
: name_index_(name_index), type_(type) {}
intptr_t name() { return name_index_; }
DartType* type() { return type_; }
private:
NamedParameter() : name_index_(-1) {}
intptr_t name_index_;
Child<DartType> type_;
DISALLOW_COPY_AND_ASSIGN(NamedParameter);
};
class FunctionType : public DartType {
public:
static FunctionType* ReadFrom(Reader* reader);
@ -2835,9 +2796,7 @@ class FunctionType : public DartType {
TypeParameterList& type_parameters() { return type_parameters_; }
int required_parameter_count() { return required_parameter_count_; }
List<DartType>& positional_parameters() { return positional_parameters_; }
List<Tuple<String, DartType> >& named_parameters() {
return named_parameters_;
}
List<NamedParameter>& named_parameters() { return named_parameters_; }
DartType* return_type() { return return_type_; }
private:
@ -2846,7 +2805,7 @@ class FunctionType : public DartType {
TypeParameterList type_parameters_;
int required_parameter_count_;
List<DartType> positional_parameters_;
List<Tuple<String, DartType> > named_parameters_;
List<NamedParameter> named_parameters_;
Child<DartType> return_type_;
DISALLOW_COPY_AND_ASSIGN(FunctionType);
@ -2904,7 +2863,7 @@ class TypeParameter : public TreeNode {
virtual void AcceptTreeVisitor(TreeVisitor* visitor);
virtual void VisitChildren(Visitor* visitor);
String* name() { return name_; }
intptr_t name() { return name_index_; }
DartType* bound() { return bound_; }
private:
@ -2914,7 +2873,7 @@ class TypeParameter : public TreeNode {
friend class List;
friend class TypeParameterList;
Ref<String> name_;
intptr_t name_index_;
Child<DartType> bound_;
DISALLOW_COPY_AND_ASSIGN(TypeParameter);
@ -2932,14 +2891,13 @@ class Program : public TreeNode {
virtual void AcceptTreeVisitor(TreeVisitor* visitor);
virtual void VisitChildren(Visitor* visitor);
StringTable& string_table() { return string_table_; }
SourceTable& source_table() { return source_table_; }
List<Library>& libraries() { return libraries_; }
CanonicalName* main_method() { return main_method_reference_; }
CanonicalName* canonical_name_root() { return canonical_name_root_; }
MallocGrowableArray<MallocGrowableArray<intptr_t>*> valid_token_positions;
MallocGrowableArray<MallocGrowableArray<intptr_t>*> yield_token_positions;
intptr_t string_data_offset() { return string_data_offset_; }
intptr_t string_table_offset() { return string_table_offset_; }
private:
Program() {}
@ -2947,12 +2905,10 @@ class Program : public TreeNode {
Child<CanonicalName> canonical_name_root_;
List<Library> libraries_;
Ref<CanonicalName> main_method_reference_; // Procedure.
StringTable string_table_;
SourceTable source_table_;
// The offset from the start of the binary to the start of the UTF-8 encoded
// string data.
intptr_t string_data_offset_;
// The offset from the start of the binary to the start of the string table.
intptr_t string_table_offset_;
DISALLOW_COPY_AND_ASSIGN(Program);
};
@ -2965,8 +2921,6 @@ class Reference : public AllStatic {
static CanonicalName* ReadClassFrom(Reader* reader, bool allow_null = false);
static CanonicalName* ReadTypedefFrom(Reader* reader);
static String* ReadStringFrom(Reader* reader);
};

View file

@ -87,12 +87,11 @@ void TypeParameterList::ReadFrom(Reader* reader) {
}
template <typename A, typename B>
Tuple<A, B>* Tuple<A, B>::ReadFrom(Reader* reader) {
NamedParameter* NamedParameter::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
A* first = A::ReadFrom(reader);
B* second = B::ReadFrom(reader);
return new Tuple<A, B>(first, second);
intptr_t name_index = reader->ReadUInt();
DartType* type = DartType::ReadFrom(reader);
return new NamedParameter(name_index, type);
}
@ -115,42 +114,6 @@ class VariableDeclarationImpl {
};
String* String::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
return Reference::ReadStringFrom(reader);
}
String* String::ReadRaw(Reader* reader, intptr_t size) {
ASSERT(reader->string_data_offset() >= 0);
String* result =
new String(reader->offset() - reader->string_data_offset(), size);
reader->Consume(size);
return result;
}
void StringTable::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
// Read the table of end offsets.
intptr_t length = reader->ReadUInt();
intptr_t* end_offsets = new intptr_t[length];
for (intptr_t i = 0; i < length; ++i) {
end_offsets[i] = reader->ReadUInt();
}
// Read the UTF-8 encoded strings.
reader->MarkStringDataOffset();
strings_.EnsureInitialized(length);
intptr_t start_offset = 0;
for (intptr_t i = 0; i < length; ++i) {
ASSERT(strings_[i] == NULL);
strings_[i] = String::ReadRaw(reader, end_offsets[i] - start_offset);
start_offset = end_offsets[i];
}
delete[] end_offsets;
}
void SourceTable::ReadFrom(Reader* reader) {
size_ = reader->ReadUInt();
sources_ = new Source[size_];
@ -206,8 +169,8 @@ Library* Library::ReadFrom(Reader* reader) {
kernel_data_size_ = reader->size();
canonical_name_ = reader->ReadCanonicalNameReference();
name_ = Reference::ReadStringFrom(reader);
import_uri_ = canonical_name_->name();
name_index_ = reader->ReadUInt();
import_uri_index_ = canonical_name_->name();
source_uri_index_ = reader->ReadUInt();
reader->set_current_script_id(source_uri_index_);
@ -240,7 +203,7 @@ Typedef* Typedef::ReadFrom(Reader* reader) {
canonical_name_ = reader->ReadCanonicalNameReference();
position_ = reader->ReadPosition(false);
name_ = Reference::ReadStringFrom(reader);
name_index_ = reader->ReadUInt();
source_uri_index_ = reader->ReadUInt();
type_parameters_.ReadFrom(reader);
type_ = DartType::ReadFrom(reader);
@ -255,7 +218,7 @@ Class* Class::ReadFrom(Reader* reader) {
canonical_name_ = reader->ReadCanonicalNameReference();
position_ = reader->ReadPosition(false);
is_abstract_ = reader->ReadBool();
name_ = Reference::ReadStringFrom(reader);
name_index_ = reader->ReadUInt();
source_uri_index_ = reader->ReadUInt();
reader->set_current_script_id(source_uri_index_);
reader->record_token_position(position_);
@ -346,12 +309,6 @@ CanonicalName* Reference::ReadTypedefFrom(Reader* reader) {
}
String* Reference::ReadStringFrom(Reader* reader) {
int index = reader->ReadUInt();
return reader->helper()->program()->string_table().strings()[index];
}
Field* Field::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
kernel_offset_ = reader->offset(); // Notice the ReadTag() below.
@ -719,9 +676,9 @@ Arguments* Arguments::ReadFrom(Reader* reader) {
NamedExpression* NamedExpression::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
String* name = Reference::ReadStringFrom(reader);
intptr_t name_index = reader->ReadUInt();
Expression* expression = Expression::ReadFrom(reader);
return new NamedExpression(name, expression);
return new NamedExpression(name_index, expression);
}
@ -842,7 +799,7 @@ AsExpression* AsExpression::ReadFrom(Reader* reader) {
StringLiteral* StringLiteral::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
intptr_t offset = reader->offset() - 1; // -1 to include tag byte.
StringLiteral* lit = new StringLiteral(Reference::ReadStringFrom(reader));
StringLiteral* lit = new StringLiteral(reader->ReadUInt());
lit->kernel_offset_ = offset;
return lit;
}
@ -851,7 +808,7 @@ StringLiteral* StringLiteral::ReadFrom(Reader* reader) {
BigintLiteral* BigintLiteral::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
intptr_t offset = reader->offset() - 1; // -1 to include tag byte.
BigintLiteral* lit = new BigintLiteral(Reference::ReadStringFrom(reader));
BigintLiteral* lit = new BigintLiteral(reader->ReadUInt());
lit->kernel_offset_ = offset;
return lit;
}
@ -880,7 +837,7 @@ DoubleLiteral* DoubleLiteral::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
DoubleLiteral* literal = new DoubleLiteral();
literal->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
literal->value_ = Reference::ReadStringFrom(reader);
literal->value_index_ = reader->ReadUInt();
return literal;
}
@ -906,7 +863,7 @@ SymbolLiteral* SymbolLiteral::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
SymbolLiteral* lit = new SymbolLiteral();
lit->kernel_offset_ = reader->offset() - 1; // -1 to include tag byte.
lit->value_ = Reference::ReadStringFrom(reader);
lit->value_index_ = reader->ReadUInt();
return lit;
}
@ -1384,7 +1341,7 @@ VariableDeclaration* VariableDeclaration::ReadFromImpl(Reader* reader,
decl->position_ = reader->ReadPosition();
decl->equals_position_ = reader->ReadPosition();
decl->flags_ = reader->ReadFlags();
decl->name_ = Reference::ReadStringFrom(reader);
decl->name_index_ = reader->ReadUInt();
decl->type_ = DartType::ReadFrom(reader);
decl->initializer_ = reader->ReadOptional<Expression>();
@ -1412,12 +1369,13 @@ FunctionDeclaration* FunctionDeclaration::ReadFrom(Reader* reader) {
Name* Name::ReadFrom(Reader* reader) {
String* name = Reference::ReadStringFrom(reader);
if (name->size() >= 1 && reader->CharacterAt(name, 0) == '_') {
intptr_t name_index = reader->ReadUInt();
if ((reader->StringLength(name_index) >= 1) &&
(reader->CharacterAt(name_index, 0) == '_')) {
CanonicalName* library_reference = reader->ReadCanonicalNameReference();
return new Name(name, library_reference);
return new Name(name_index, library_reference);
} else {
return new Name(name, NULL);
return new Name(name_index, NULL);
}
}
@ -1507,7 +1465,7 @@ FunctionType* FunctionType::ReadFrom(Reader* reader) {
type->type_parameters().ReadFrom(reader);
type->required_parameter_count_ = reader->ReadUInt();
type->positional_parameters().ReadFromStatic<DartType>(reader);
type->named_parameters().ReadFromStatic<Tuple<String, DartType> >(reader);
type->named_parameters().ReadFromStatic<NamedParameter>(reader);
type->return_type_ = DartType::ReadFrom(reader);
return type;
}
@ -1549,9 +1507,22 @@ Program* Program::ReadFrom(Reader* reader) {
program->canonical_name_root_ = CanonicalName::NewRoot();
reader->helper()->set_program(program);
program->string_table_.ReadFrom(reader);
program->string_data_offset_ = reader->string_data_offset();
ASSERT(program->string_data_offset_ >= 0);
// Skip the table of string end offsets.
reader->MarkStringTableOffset();
intptr_t length = reader->ReadUInt();
reader->string_offsets_ = new intptr_t[length + 1];
intptr_t offset = 0;
for (intptr_t i = 0; i < length; ++i) {
reader->string_offsets_[i] = offset;
offset = reader->ReadUInt();
}
reader->string_offsets_[length] = offset;
// Skip the UTF-8 encoded strings.
reader->MarkStringDataOffset();
reader->Consume(offset);
program->string_table_offset_ = reader->string_table_offset();
ASSERT(program->string_table_offset_ >= 0);
program->source_table_.ReadFrom(reader);
int canonical_names = reader->ReadUInt();
@ -1565,9 +1536,8 @@ Program* Program::ReadFrom(Reader* reader) {
parent = program->canonical_name_root();
}
ASSERT(parent != NULL);
int name_index = reader->ReadUInt();
String* name = program->string_table().strings()[name_index];
CanonicalName* canonical_name = parent->AddChild(name);
intptr_t name_index = reader->ReadUInt();
CanonicalName* canonical_name = parent->AddChild(name_index);
reader->helper()->SetCanonicalName(i, canonical_name);
}
@ -1613,7 +1583,7 @@ FunctionNode* FunctionNode::ReadFrom(Reader* reader) {
TypeParameter* TypeParameter::ReadFrom(Reader* reader) {
TRACE_READ_OFFSET();
name_ = Reference::ReadStringFrom(reader);
name_index_ = reader->ReadUInt();
bound_ = DartType::ReadFrom(reader);
return this;
}

View file

@ -331,7 +331,14 @@ class ReaderHelper {
class Reader {
public:
Reader(const uint8_t* buffer, intptr_t size)
: buffer_(buffer), size_(size), offset_(0), string_data_offset_(-1) {}
: buffer_(buffer),
size_(size),
offset_(0),
string_table_offset_(-1),
string_data_offset_(-1),
string_offsets_(NULL) {}
~Reader() { delete[] string_offsets_; }
uint32_t ReadUInt32() {
ASSERT(offset_ + 4 <= size_);
@ -504,15 +511,25 @@ class Reader {
const uint8_t* buffer() { return buffer_; }
intptr_t string_table_offset() { return string_table_offset_; }
void MarkStringTableOffset() {
ASSERT(string_table_offset_ == -1);
string_table_offset_ = offset_;
}
intptr_t string_data_offset() { return string_data_offset_; }
void MarkStringDataOffset() {
ASSERT(string_data_offset_ == -1);
string_data_offset_ = offset_;
}
uint8_t CharacterAt(String* str, intptr_t index) {
ASSERT(index < str->size());
return buffer_[string_data_offset_ + str->offset() + index];
intptr_t StringLength(intptr_t string_index) {
return string_offsets_[string_index + 1] - string_offsets_[string_index];
}
uint8_t CharacterAt(intptr_t string_index, intptr_t index) {
ASSERT(index < StringLength(string_index));
return buffer_[string_data_offset_ + string_offsets_[string_index] + index];
}
private:
@ -524,9 +541,17 @@ class Reader {
TokenPosition min_position_;
intptr_t current_script_id_;
// When the binary is deserialized the offset of the start of the string table
// (the length) and the offset of the start of the string data are recorded.
intptr_t string_table_offset_;
intptr_t string_data_offset_;
// The string offsets are decoded to support efficient access to string UTF-8
// encodings.
intptr_t* string_offsets_;
friend class PositionScope;
friend class Program;
};

View file

@ -93,9 +93,10 @@ void StreamingConstantEvaluator::EvaluateStaticGet() {
}
}
void StreamingConstantEvaluator::EvaluateSymbolLiteral() {
int str_index = builder_->ReadUInt();
const dart::String& symbol_value = builder_->DartSymbol(str_index);
const dart::String& symbol_value = H.DartSymbol(str_index);
const dart::Class& symbol_class =
dart::Class::ZoneHandle(Z, I->object_store()->symbol_class());
@ -107,12 +108,14 @@ void StreamingConstantEvaluator::EvaluateSymbolLiteral() {
symbol_class, TypeArguments::Handle(Z), symbol_constructor, symbol_value);
}
void StreamingConstantEvaluator::EvaluateDoubleLiteral() {
int str_index = builder_->ReadUInt();
result_ = dart::Double::New(builder_->DartString(str_index), Heap::kOld);
result_ = dart::Double::New(H.DartString(str_index), Heap::kOld);
result_ = H.Canonicalize(result_);
}
RawObject* StreamingConstantEvaluator::EvaluateConstConstructorCall(
const dart::Class& type_class,
const TypeArguments& type_arguments,
@ -308,26 +311,6 @@ Fragment StreamingFlowGraphBuilder::BuildAt(intptr_t kernel_offset) {
}
intptr_t StreamingFlowGraphBuilder::GetStringOffset(intptr_t index) {
if (string_offsets_ == NULL) {
intptr_t saved_offset = ReaderOffset();
reader_->set_offset(4); // Skip kMagicProgramFile to the string table.
string_offset_count_ = ReadListLength() + 1;
string_offsets_ = new intptr_t[string_offset_count_];
// Build a table of the 0-based string start and end offsets.
string_offsets_[0] = 0;
for (intptr_t i = 1; i < string_offset_count_; ++i) {
string_offsets_[i] = ReadUInt();
}
// Mark the start of the string data to use for decoding strings.
reader_->MarkStringDataOffset();
SetOffset(saved_offset);
}
return string_offsets_[index];
}
CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) {
if (index == 0) return NULL;
--index;
@ -395,8 +378,7 @@ CanonicalName* StreamingFlowGraphBuilder::GetCanonicalName(intptr_t index) {
}
ASSERT(parent != NULL);
intptr_t name_index = ReadUInt();
String* name = KernelString(name_index);
CanonicalName* canonical_name = parent->AddChild(name);
CanonicalName* canonical_name = parent->AddChild(name_index);
canonical_names_[canonical_names_entries_read_] = canonical_name;
}
@ -457,29 +439,6 @@ ParsedFunction* StreamingFlowGraphBuilder::parsed_function() {
}
dart::String& StreamingFlowGraphBuilder::DartSymbol(intptr_t index) {
intptr_t start = GetStringOffset(index);
intptr_t end = GetStringOffset(index + 1);
return H.DartSymbol(reader_->buffer() + reader_->string_data_offset() + start,
end - start);
}
dart::String& StreamingFlowGraphBuilder::DartString(intptr_t index) {
intptr_t start = GetStringOffset(index);
intptr_t end = GetStringOffset(index + 1);
return H.DartString(reader_->buffer() + reader_->string_data_offset() + start,
end - start);
}
String* StreamingFlowGraphBuilder::KernelString(intptr_t index) {
intptr_t start = GetStringOffset(index);
intptr_t end = GetStringOffset(index + 1);
return new String(start, end - start);
}
Fragment StreamingFlowGraphBuilder::DebugStepCheck(TokenPosition position) {
return flow_graph_builder_->DebugStepCheck(position);
}
@ -603,14 +562,14 @@ Fragment StreamingFlowGraphBuilder::BuildRethrow() {
Fragment StreamingFlowGraphBuilder::BuildBigIntLiteral() {
const dart::String& value = DartString(ReadUInt());
const dart::String& value = H.DartString(ReadUInt());
return Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)));
}
Fragment StreamingFlowGraphBuilder::BuildStringLiteral() {
intptr_t str_index = ReadUInt();
return Constant(DartSymbol(str_index));
return Constant(H.DartSymbol(str_index));
}

View file

@ -65,8 +65,6 @@ class StreamingFlowGraphBuilder {
flow_graph_builder->zone_,
&flow_graph_builder->translation_helper_,
&flow_graph_builder->type_translator_),
string_offset_count_(0),
string_offsets_(NULL),
canonical_names_(NULL),
canonical_names_size_(-1),
canonical_names_entries_read_(0),
@ -74,7 +72,6 @@ class StreamingFlowGraphBuilder {
virtual ~StreamingFlowGraphBuilder() {
delete reader_;
delete[] string_offsets_;
// The canonical names themselves are not (yet) deallocated.
delete[] canonical_names_;
}
@ -82,7 +79,6 @@ class StreamingFlowGraphBuilder {
Fragment BuildAt(intptr_t kernel_offset);
private:
intptr_t GetStringOffset(intptr_t index);
CanonicalName* GetCanonicalName(intptr_t index);
intptr_t ReaderOffset();
@ -97,10 +93,6 @@ class StreamingFlowGraphBuilder {
ScopeBuildingResult* scopes();
ParsedFunction* parsed_function();
dart::String& DartSymbol(intptr_t str_index);
dart::String& DartString(intptr_t str_index);
String* KernelString(intptr_t str_index);
Fragment DebugStepCheck(TokenPosition position);
Fragment LoadLocal(LocalVariable* variable);
Fragment PushArgument();
@ -132,19 +124,6 @@ class StreamingFlowGraphBuilder {
kernel::Reader* reader_;
StreamingConstantEvaluator constant_evaluator_;
// We build a table that gives us the start and end offsets of all the strings
// in the binary.
//
// The number of string offsets. Note that this is one more than the number
// of strings in the binary.
intptr_t string_offset_count_;
// An array of offsets of size string_table_size_ + 1, in order to include the
// end offset of the last string. The string with index N consists of the
// UTF-8 encoded bytes stretching from string_table_offsets_[N] (enclusive) to
// string_table_offsets_[N+1] (exclusive).
intptr_t* string_offsets_;
CanonicalName** canonical_names_;
intptr_t canonical_names_size_;
intptr_t canonical_names_entries_read_;

View file

@ -7,6 +7,7 @@
#include <string.h>
#include "vm/dart_api_impl.h"
#include "vm/kernel_binary.h"
#include "vm/longjump.h"
#include "vm/object_store.h"
#include "vm/parser.h"
@ -118,24 +119,32 @@ KernelReader::KernelReader(Program* program)
intptr_t source_file_count = program->source_table().size();
scripts_ = Array::New(source_file_count, Heap::kOld);
// Copy the Kernel strings out of the binary and into the VM's heap. The size
// of the string data can be computed from the offset and size of the last
// string. This relies on the strings occurring in order in the program's
// string table.
List<String>& strings = program->string_table().strings();
String* last_string = strings[strings.length() - 1];
intptr_t size = last_string->offset() + last_string->size();
TypedData& data = TypedData::Handle(
Z, TypedData::New(kTypedDataUint8ArrayCid, size, Heap::kOld));
ASSERT(program->string_data_offset() >= 0);
// We need at least one library to get access to the binary.
ASSERT(program->libraries().length() > 0);
Library* library = program->libraries()[0];
Reader reader(library->kernel_data(), library->kernel_data_size());
// Copy the Kernel string offsets out of the binary and into the VM's heap.
ASSERT(program->string_table_offset() >= 0);
reader.set_offset(program->string_table_offset());
intptr_t count = reader.ReadUInt() + 1;
TypedData& offsets = TypedData::Handle(
Z, TypedData::New(kTypedDataUint32ArrayCid, count, Heap::kOld));
offsets.SetUint32(0, 0);
intptr_t end_offset = 0;
for (intptr_t i = 1; i < count; ++i) {
end_offset = reader.ReadUInt();
offsets.SetUint32(i << 2, end_offset);
}
// Copy the string data out of the binary and into the VM's heap.
TypedData& data = TypedData::Handle(
Z, TypedData::New(kTypedDataUint8ArrayCid, end_offset, Heap::kOld));
{
NoSafepointScope no_safepoint;
memmove(data.DataAddr(0), program->libraries()[0]->kernel_data() +
program->string_data_offset(),
size);
memmove(data.DataAddr(0), reader.buffer() + reader.offset(), end_offset);
}
H.SetStringOffsets(offsets);
H.SetStringData(data);
}
@ -487,12 +496,12 @@ void KernelReader::ReadProcedure(const dart::Library& library,
ConstructorInvocation::Cast(annotation);
CanonicalName* annotation_class = H.EnclosingName(invocation->target());
ASSERT(H.IsClass(annotation_class));
String* class_name = annotation_class->name();
intptr_t class_name_index = annotation_class->name();
// Just compare by name, do not generate the annotation class.
if (!H.StringEquals(class_name, "ExternalName")) continue;
if (!H.StringEquals(class_name_index, "ExternalName")) continue;
ASSERT(H.IsLibrary(annotation_class->parent()));
String* library_name = annotation_class->parent()->name();
if (!H.StringEquals(library_name, "dart:_internal")) continue;
intptr_t library_name_index = annotation_class->parent()->name();
if (!H.StringEquals(library_name_index, "dart:_internal")) continue;
is_external = false;
ASSERT(invocation->arguments()->positional().length() == 1 &&
@ -607,7 +616,7 @@ static RawArray* AsSortedDuplicateFreeArray(
}
}
Script& KernelReader::ScriptAt(intptr_t index, String* import_uri) {
Script& KernelReader::ScriptAt(intptr_t index, intptr_t import_uri) {
Script& script = Script::ZoneHandle(Z);
script ^= scripts_.At(index);
if (script.IsNull()) {
@ -616,14 +625,15 @@ Script& KernelReader::ScriptAt(intptr_t index, String* import_uri) {
intptr_t uri_size = program_->source_table().UriSizeFor(index);
dart::String& uri_string = H.DartString(uri_buffer, uri_size, Heap::kOld);
dart::String& import_uri_string =
import_uri == NULL ? uri_string : H.DartString(import_uri, Heap::kOld);
import_uri == -1 ? uri_string : H.DartString(import_uri, Heap::kOld);
uint8_t* source_buffer = program_->source_table().SourceCodeFor(index);
intptr_t source_size = program_->source_table().SourceCodeSizeFor(index);
dart::String& source_code =
H.DartString(source_buffer, source_size, Heap::kOld);
script = Script::New(import_uri_string, uri_string, source_code,
RawScript::kKernelTag);
script.set_kernel_strings(H.string_data());
script.set_kernel_string_offsets(H.string_offsets());
script.set_kernel_string_data(H.string_data());
scripts_.SetAt(index, script);
// Create line_starts array for the script.

View file

@ -67,11 +67,11 @@ class KernelReader {
void ReadLibrary(Library* kernel_library);
const dart::String& DartSymbol(String* str) {
return translation_helper_.DartSymbol(str);
const dart::String& DartSymbol(intptr_t string_index) {
return translation_helper_.DartSymbol(string_index);
}
uint8_t CharacterAt(String* str, intptr_t index);
uint8_t CharacterAt(intptr_t string_index, intptr_t index);
private:
friend class BuildingTranslationHelper;
@ -92,7 +92,7 @@ class KernelReader {
// Otherwise return klass.
const Object& ClassForScriptAt(const dart::Class& klass,
intptr_t source_uri_index);
Script& ScriptAt(intptr_t source_uri_index, String* import_uri = NULL);
Script& ScriptAt(intptr_t source_uri_index, intptr_t import_uri = -1);
void GenerateFieldAccessors(const dart::Class& klass,
const dart::Field& field,

View file

@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
#include <set>
#include <string>
#include "vm/kernel_to_il.h"
@ -71,7 +70,8 @@ ScopeBuilder::ScopeBuilder(ParsedFunction* parsed_function, TreeNode* node)
name_index_(0),
needs_expr_temp_(false) {
Script& script = Script::Handle(Z, parsed_function->function().script());
H.SetStringData(TypedData::Handle(Z, script.kernel_strings()));
H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
H.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
}
@ -261,7 +261,7 @@ void ScopeBuilder::AddVariable(VariableDeclaration* declaration) {
// In case `declaration->IsConst()` the flow graph building will take care of
// evaluating the constant and setting it via
// `declaration->SetConstantValue()`.
const dart::String& name = declaration->name()->is_empty()
const dart::String& name = (H.StringSize(declaration->name()) == 0)
? GenerateName(":var", name_index_++)
: H.DartSymbol(declaration->name());
LocalVariable* variable =
@ -1043,7 +1043,14 @@ TranslationHelper::TranslationHelper(dart::Thread* thread)
zone_(thread->zone()),
isolate_(thread->isolate()),
allocation_space_(thread->IsMutatorThread() ? Heap::kNew : Heap::kOld),
string_data_(TypedData::Handle(zone_)) {}
string_offsets_(TypedData::Handle(Z)),
string_data_(TypedData::Handle(Z)) {}
void TranslationHelper::SetStringOffsets(const TypedData& string_offsets) {
ASSERT(string_offsets_.IsNull());
string_offsets_ = string_offsets.raw();
}
void TranslationHelper::SetStringData(const TypedData& string_data) {
@ -1052,29 +1059,42 @@ void TranslationHelper::SetStringData(const TypedData& string_data) {
}
uint8_t TranslationHelper::CharacterAt(String* string, intptr_t index) {
ASSERT(index < string->size());
return string_data_.GetUint8(string->offset() + index);
intptr_t TranslationHelper::StringOffset(intptr_t string_index) const {
return string_offsets_.GetUint32(string_index << 2);
}
bool TranslationHelper::StringEquals(String* string, const char* other) {
intptr_t TranslationHelper::StringSize(intptr_t string_index) const {
return StringOffset(string_index + 1) - StringOffset(string_index);
}
uint8_t TranslationHelper::CharacterAt(intptr_t string_index, intptr_t index) {
ASSERT(index < StringSize(string_index));
return string_data_.GetUint8(StringOffset(string_index) + index);
}
bool TranslationHelper::StringEquals(intptr_t string_index, const char* other) {
NoSafepointScope no_safepoint;
intptr_t length = strlen(other);
return (length == string->size()) &&
memcmp(string_data_.DataAddr(string->offset()), other, length) == 0;
return (length == StringSize(string_index)) &&
(memcmp(string_data_.DataAddr(StringOffset(string_index)), other,
length) == 0);
}
bool TranslationHelper::IsAdministrative(CanonicalName* name) {
// Administrative names start with '@'.
return (name->name()->size() > 0) && (CharacterAt(name->name(), 0) == '@');
return (StringSize(name->name()) > 0) &&
(CharacterAt(name->name(), 0) == '@');
}
bool TranslationHelper::IsPrivate(CanonicalName* name) {
// Private names start with '_'.
return (name->name()->size() > 0) && (CharacterAt(name->name(), 0) == '_');
return (StringSize(name->name()) > 0) &&
(CharacterAt(name->name(), 0) == '_');
}
@ -1228,13 +1248,13 @@ const dart::String& TranslationHelper::DartString(const char* content,
}
dart::String& TranslationHelper::DartString(String* content,
dart::String& TranslationHelper::DartString(intptr_t string_index,
Heap::Space space) {
intptr_t length = content->size();
intptr_t length = StringSize(string_index);
uint8_t* buffer = Z->Alloc<uint8_t>(length);
{
NoSafepointScope no_safepoint;
memmove(buffer, string_data_.DataAddr(content->offset()), length);
memmove(buffer, string_data_.DataAddr(StringOffset(string_index)), length);
}
return dart::String::ZoneHandle(
Z, dart::String::FromUTF8(buffer, length, space));
@ -1254,12 +1274,12 @@ const dart::String& TranslationHelper::DartSymbol(const char* content) const {
}
dart::String& TranslationHelper::DartSymbol(String* content) const {
intptr_t length = content->size();
dart::String& TranslationHelper::DartSymbol(intptr_t string_index) const {
intptr_t length = StringSize(string_index);
uint8_t* buffer = Z->Alloc<uint8_t>(length);
{
NoSafepointScope no_safepoint;
memmove(buffer, string_data_.DataAddr(content->offset()), length);
memmove(buffer, string_data_.DataAddr(StringOffset(string_index)), length);
}
return dart::String::ZoneHandle(
Z, dart::Symbols::FromUTF8(thread_, buffer, length));
@ -1307,12 +1327,12 @@ const dart::String& TranslationHelper::DartSetterName(CanonicalName* setter) {
const dart::String& TranslationHelper::DartSetterName(Name* setter_name) {
return DartSetterName(setter_name->library(), setter_name->string());
return DartSetterName(setter_name->library(), setter_name->string_index());
}
const dart::String& TranslationHelper::DartSetterName(CanonicalName* parent,
String* setter) {
intptr_t setter) {
// The names flowing into [setter] are coming from the Kernel file:
// * user-defined setters: `fieldname=`
// * property-set expressions: `fieldname`
@ -1321,19 +1341,18 @@ const dart::String& TranslationHelper::DartSetterName(CanonicalName* parent,
//
// => In order to be consistent, we remove the `=` always and adopt the VM
// conventions.
ASSERT(setter->size() > 0);
intptr_t skip = 0;
if (CharacterAt(setter, setter->size() - 1) == '=') {
skip = 1;
intptr_t size = StringSize(setter);
ASSERT(size > 0);
if (CharacterAt(setter, size - 1) == '=') {
--size;
}
intptr_t length = setter->size() - skip;
uint8_t* buffer = Z->Alloc<uint8_t>(length);
uint8_t* buffer = Z->Alloc<uint8_t>(size);
{
NoSafepointScope no_safepoint;
memmove(buffer, string_data_.DataAddr(setter->offset()), length);
memmove(buffer, string_data_.DataAddr(StringOffset(setter)), size);
}
dart::String& name = dart::String::ZoneHandle(
Z, dart::String::FromUTF8(buffer, length, allocation_space_));
Z, dart::String::FromUTF8(buffer, size, allocation_space_));
ManglePrivateName(parent, &name, false);
name = dart::Field::SetterSymbol(name);
return name;
@ -1346,12 +1365,12 @@ const dart::String& TranslationHelper::DartGetterName(CanonicalName* getter) {
const dart::String& TranslationHelper::DartGetterName(Name* getter_name) {
return DartGetterName(getter_name->library(), getter_name->string());
return DartGetterName(getter_name->library(), getter_name->string_index());
}
const dart::String& TranslationHelper::DartGetterName(CanonicalName* parent,
String* getter) {
intptr_t getter) {
dart::String& name = DartString(getter);
ManglePrivateName(parent, &name, false);
name = dart::Field::GetterSymbol(name);
@ -1360,7 +1379,7 @@ const dart::String& TranslationHelper::DartGetterName(CanonicalName* parent,
const dart::String& TranslationHelper::DartFieldName(Name* kernel_name) {
dart::String& name = DartString(kernel_name->string());
dart::String& name = DartString(kernel_name->string_index());
return ManglePrivateName(kernel_name->library(), &name);
}
@ -1380,12 +1399,12 @@ const dart::String& TranslationHelper::DartMethodName(CanonicalName* method) {
const dart::String& TranslationHelper::DartMethodName(Name* method_name) {
return DartMethodName(method_name->library(), method_name->string());
return DartMethodName(method_name->library(), method_name->string_index());
}
const dart::String& TranslationHelper::DartMethodName(CanonicalName* parent,
String* method) {
intptr_t method) {
dart::String& name = DartString(method);
return ManglePrivateName(parent, &name);
}
@ -2057,10 +2076,8 @@ void ConstantEvaluator::VisitNot(Not* node) {
void ConstantEvaluator::VisitPropertyGet(PropertyGet* node) {
const intptr_t kLengthLen = sizeof("length") - 1;
String* string = node->name()->string();
if ((string->size() == kLengthLen) && H.StringEquals(string, "length")) {
intptr_t string_index = node->name()->string_index();
if (H.StringEquals(string_index, "length")) {
node->receiver()->AcceptExpressionVisitor(this);
if (result_.IsString()) {
const dart::String& str =
@ -2187,7 +2204,8 @@ FlowGraphBuilder::FlowGraphBuilder(
constant_evaluator_(this, zone_, &translation_helper_, &type_translator_),
streaming_flow_graph_builder_(NULL) {
Script& script = Script::Handle(Z, parsed_function->function().script());
H.SetStringData(TypedData::Handle(Z, script.kernel_strings()));
H.SetStringOffsets(TypedData::Handle(Z, script.kernel_string_offsets()));
H.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
}
@ -4682,13 +4700,13 @@ void DartTypeTranslator::VisitFunctionType(FunctionType* node) {
parameter_names.SetAt(pos, H.DartSymbol("noname"));
}
for (intptr_t i = 0; i < named_count; i++, pos++) {
Tuple<String, DartType>* tuple = node->named_parameters()[i];
tuple->second()->AcceptDartTypeVisitor(this);
NamedParameter* parameter = node->named_parameters()[i];
parameter->type()->AcceptDartTypeVisitor(this);
if (result_.IsMalformed()) {
result_ = AbstractType::dynamic_type().raw();
}
parameter_types.SetAt(pos, result_);
parameter_names.SetAt(pos, H.DartSymbol(tuple->first()));
parameter_names.SetAt(pos, H.DartSymbol(parameter->name()));
}
Type& signature_type =
@ -6733,7 +6751,9 @@ RawObject* EvaluateMetadata(const dart::Field& metadata_field) {
TranslationHelper helper(thread);
Script& script = Script::Handle(Z, metadata_field.Script());
helper.SetStringData(TypedData::Handle(Z, script.kernel_strings()));
helper.SetStringOffsets(
TypedData::Handle(Z, script.kernel_string_offsets()));
helper.SetStringData(TypedData::Handle(Z, script.kernel_string_data()));
DartTypeTranslator type_translator(&helper, NULL, true);
ConstantEvaluator constant_evaluator(/* flow_graph_builder = */ NULL, Z,
&helper, &type_translator);

View file

@ -281,10 +281,16 @@ class TranslationHelper {
Heap::Space allocation_space() { return allocation_space_; }
// Access to strings.
const TypedData& string_offsets() { return string_offsets_; }
void SetStringOffsets(const TypedData& string_data);
const TypedData& string_data() { return string_data_; }
void SetStringData(const TypedData& string_data);
uint8_t CharacterAt(String* str, intptr_t index);
bool StringEquals(String* str, const char* other);
intptr_t StringOffset(intptr_t string_index) const;
intptr_t StringSize(intptr_t string_index) const;
uint8_t CharacterAt(intptr_t string_index, intptr_t index);
bool StringEquals(intptr_t string_index, const char* other);
// Predicates on CanonicalNames.
bool IsAdministrative(CanonicalName* name);
@ -312,10 +318,10 @@ class TranslationHelper {
}
const dart::String& DartString(const char* content, Heap::Space space);
dart::String& DartString(String* content) {
return DartString(content, allocation_space_);
dart::String& DartString(intptr_t string_index) {
return DartString(string_index, allocation_space_);
}
dart::String& DartString(String* content, Heap::Space space);
dart::String& DartString(intptr_t string_index, Heap::Space space);
dart::String& DartString(const uint8_t* utf8_array, intptr_t len) {
return DartString(utf8_array, len, allocation_space_);
@ -325,7 +331,7 @@ class TranslationHelper {
Heap::Space space);
const dart::String& DartSymbol(const char* content) const;
dart::String& DartSymbol(String* content) const;
dart::String& DartSymbol(intptr_t string_index) const;
dart::String& DartSymbol(const uint8_t* utf8_array, intptr_t len) const;
const dart::String& DartClassName(CanonicalName* kernel_class);
@ -378,15 +384,16 @@ class TranslationHelper {
dart::String* name_to_modify,
bool symbolize = true);
const dart::String& DartSetterName(CanonicalName* parent, String* setter);
const dart::String& DartGetterName(CanonicalName* parent, String* getter);
const dart::String& DartMethodName(CanonicalName* parent, String* method);
const dart::String& DartSetterName(CanonicalName* parent, intptr_t setter);
const dart::String& DartGetterName(CanonicalName* parent, intptr_t getter);
const dart::String& DartMethodName(CanonicalName* parent, intptr_t method);
Thread* thread_;
Zone* zone_;
Isolate* isolate_;
Heap::Space allocation_space_;
TypedData& string_offsets_;
TypedData& string_data_;
};

View file

@ -9098,8 +9098,13 @@ void Script::set_compile_time_constants(const Array& value) const {
}
void Script::set_kernel_strings(const TypedData& strings) const {
StorePointer(&raw_ptr()->kernel_strings_, strings.raw());
void Script::set_kernel_string_offsets(const TypedData& offsets) const {
StorePointer(&raw_ptr()->kernel_string_offsets_, offsets.raw());
}
void Script::set_kernel_string_data(const TypedData& data) const {
StorePointer(&raw_ptr()->kernel_string_data_, data.raw());
}

View file

@ -3591,8 +3591,15 @@ class Script : public Object {
}
void set_compile_time_constants(const Array& value) const;
RawTypedData* kernel_strings() const { return raw_ptr()->kernel_strings_; }
void set_kernel_strings(const TypedData& strings) const;
RawTypedData* kernel_string_offsets() const {
return raw_ptr()->kernel_string_offsets_;
}
void set_kernel_string_offsets(const TypedData& offsets) const;
RawTypedData* kernel_string_data() const {
return raw_ptr()->kernel_string_data_;
}
void set_kernel_string_data(const TypedData& data) const;
RawTokenStream* tokens() const {
ASSERT(kind() != RawScript::kKernelTag);

View file

@ -1026,7 +1026,8 @@ class RawScript : public RawObject {
RawArray* line_starts_;
RawArray* debug_positions_;
RawArray* yield_positions_;
RawTypedData* kernel_strings_;
RawTypedData* kernel_string_offsets_;
RawTypedData* kernel_string_data_;
RawTokenStream* tokens_;
RawString* source_;
RawObject** to() { return reinterpret_cast<RawObject**>(&ptr()->source_); }