2012-07-24 00:01:50 +00:00
|
|
|
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "vm/symbols.h"
|
|
|
|
|
2019-04-22 20:15:43 +00:00
|
|
|
#include "platform/unicode.h"
|
2012-12-10 18:24:34 +00:00
|
|
|
#include "vm/handles.h"
|
2014-07-29 22:47:56 +00:00
|
|
|
#include "vm/hash_table.h"
|
2012-07-24 00:01:50 +00:00
|
|
|
#include "vm/isolate.h"
|
|
|
|
#include "vm/object.h"
|
|
|
|
#include "vm/object_store.h"
|
|
|
|
#include "vm/raw_object.h"
|
2016-05-03 00:07:31 +00:00
|
|
|
#include "vm/reusable_handles.h"
|
2012-08-08 19:46:23 +00:00
|
|
|
#include "vm/snapshot_ids.h"
|
2019-02-08 17:16:26 +00:00
|
|
|
#include "vm/type_table.h"
|
2012-07-24 00:01:50 +00:00
|
|
|
#include "vm/visitor.h"
|
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
|
2013-01-02 19:31:59 +00:00
|
|
|
RawString* Symbols::predefined_[Symbols::kNumberOfOneCharCodeSymbols];
|
|
|
|
String* Symbols::symbol_handles_[Symbols::kMaxPredefinedId];
|
2012-07-25 20:31:26 +00:00
|
|
|
|
|
|
|
static const char* names[] = {
|
2016-11-08 21:54:47 +00:00
|
|
|
// clang-format off
|
2012-07-25 20:31:26 +00:00
|
|
|
NULL,
|
2016-11-08 21:54:47 +00:00
|
|
|
#define DEFINE_SYMBOL_LITERAL(symbol, literal) literal,
|
|
|
|
PREDEFINED_SYMBOLS_LIST(DEFINE_SYMBOL_LITERAL)
|
2012-07-25 20:31:26 +00:00
|
|
|
#undef DEFINE_SYMBOL_LITERAL
|
2016-04-11 23:28:29 +00:00
|
|
|
"", // matches kTokenTableStart.
|
2016-11-08 21:54:47 +00:00
|
|
|
#define DEFINE_TOKEN_SYMBOL_INDEX(t, s, p, a) s,
|
2016-04-11 23:28:29 +00:00
|
|
|
DART_TOKEN_LIST(DEFINE_TOKEN_SYMBOL_INDEX)
|
|
|
|
DART_KEYWORD_LIST(DEFINE_TOKEN_SYMBOL_INDEX)
|
|
|
|
#undef DEFINE_TOKEN_SYMBOL_INDEX
|
2016-11-08 21:54:47 +00:00
|
|
|
// clang-format on
|
2012-07-25 20:31:26 +00:00
|
|
|
};
|
2012-07-24 00:01:50 +00:00
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
RawString* StringFrom(const uint8_t* data, intptr_t len, Heap::Space space) {
|
|
|
|
return String::FromLatin1(data, len, space);
|
|
|
|
}
|
2016-11-08 21:54:47 +00:00
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
RawString* StringFrom(const uint16_t* data, intptr_t len, Heap::Space space) {
|
|
|
|
return String::FromUTF16(data, len, space);
|
|
|
|
}
|
2016-11-08 21:54:47 +00:00
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
RawString* StringFrom(const int32_t* data, intptr_t len, Heap::Space space) {
|
|
|
|
return String::FromUTF32(data, len, space);
|
|
|
|
}
|
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
template <typename CharType>
|
2014-07-29 22:47:56 +00:00
|
|
|
class CharArray {
|
|
|
|
public:
|
2016-11-08 21:54:47 +00:00
|
|
|
CharArray(const CharType* data, intptr_t len) : data_(data), len_(len) {
|
2014-07-29 22:47:56 +00:00
|
|
|
hash_ = String::Hash(data, len);
|
|
|
|
}
|
|
|
|
RawString* ToSymbol() const {
|
|
|
|
String& result = String::Handle(StringFrom(data_, len_, Heap::kOld));
|
|
|
|
result.SetCanonical();
|
|
|
|
result.SetHash(hash_);
|
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
bool Equals(const String& other) const {
|
2016-04-12 22:03:24 +00:00
|
|
|
ASSERT(other.HasHash());
|
|
|
|
if (other.Hash() != hash_) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-29 22:47:56 +00:00
|
|
|
return other.Equals(data_, len_);
|
|
|
|
}
|
|
|
|
intptr_t Hash() const { return hash_; }
|
2016-11-08 21:54:47 +00:00
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
private:
|
|
|
|
const CharType* data_;
|
|
|
|
intptr_t len_;
|
|
|
|
intptr_t hash_;
|
|
|
|
};
|
|
|
|
typedef CharArray<uint8_t> Latin1Array;
|
|
|
|
typedef CharArray<uint16_t> UTF16Array;
|
|
|
|
typedef CharArray<int32_t> UTF32Array;
|
|
|
|
|
|
|
|
class StringSlice {
|
|
|
|
public:
|
|
|
|
StringSlice(const String& str, intptr_t begin_index, intptr_t length)
|
|
|
|
: str_(str), begin_index_(begin_index), len_(length) {
|
|
|
|
hash_ = is_all() ? str.Hash() : String::Hash(str, begin_index, length);
|
|
|
|
}
|
|
|
|
RawString* ToSymbol() const;
|
|
|
|
bool Equals(const String& other) const {
|
2016-04-12 22:03:24 +00:00
|
|
|
ASSERT(other.HasHash());
|
|
|
|
if (other.Hash() != hash_) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-29 22:47:56 +00:00
|
|
|
return other.Equals(str_, begin_index_, len_);
|
|
|
|
}
|
|
|
|
intptr_t Hash() const { return hash_; }
|
2016-11-08 21:54:47 +00:00
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
private:
|
|
|
|
bool is_all() const { return begin_index_ == 0 && len_ == str_.Length(); }
|
|
|
|
const String& str_;
|
|
|
|
intptr_t begin_index_;
|
|
|
|
intptr_t len_;
|
|
|
|
intptr_t hash_;
|
|
|
|
};
|
|
|
|
|
|
|
|
RawString* StringSlice::ToSymbol() const {
|
|
|
|
if (is_all() && str_.IsOld()) {
|
|
|
|
str_.SetCanonical();
|
|
|
|
return str_.raw();
|
|
|
|
} else {
|
2016-11-08 21:54:47 +00:00
|
|
|
String& result =
|
|
|
|
String::Handle(String::SubString(str_, begin_index_, len_, Heap::kOld));
|
2014-07-29 22:47:56 +00:00
|
|
|
result.SetCanonical();
|
|
|
|
result.SetHash(hash_);
|
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 23:04:52 +00:00
|
|
|
class ConcatString {
|
|
|
|
public:
|
|
|
|
ConcatString(const String& str1, const String& str2)
|
|
|
|
: str1_(str1), str2_(str2), hash_(String::HashConcat(str1, str2)) {}
|
|
|
|
RawString* ToSymbol() const;
|
|
|
|
bool Equals(const String& other) const {
|
2016-04-12 22:03:24 +00:00
|
|
|
ASSERT(other.HasHash());
|
|
|
|
if (other.Hash() != hash_) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-08-04 23:04:52 +00:00
|
|
|
return other.EqualsConcat(str1_, str2_);
|
|
|
|
}
|
|
|
|
intptr_t Hash() const { return hash_; }
|
2016-11-08 21:54:47 +00:00
|
|
|
|
2014-08-04 23:04:52 +00:00
|
|
|
private:
|
|
|
|
const String& str1_;
|
|
|
|
const String& str2_;
|
|
|
|
intptr_t hash_;
|
|
|
|
};
|
|
|
|
|
|
|
|
RawString* ConcatString::ToSymbol() const {
|
|
|
|
String& result = String::Handle(String::Concat(str1_, str2_, Heap::kOld));
|
|
|
|
result.SetCanonical();
|
|
|
|
result.SetHash(hash_);
|
|
|
|
return result.raw();
|
|
|
|
}
|
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
class SymbolTraits {
|
|
|
|
public:
|
2016-04-12 20:38:08 +00:00
|
|
|
static const char* Name() { return "SymbolTraits"; }
|
2016-04-13 16:08:52 +00:00
|
|
|
static bool ReportStats() { return false; }
|
2016-04-12 20:38:08 +00:00
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
static bool IsMatch(const Object& a, const Object& b) {
|
2016-04-12 05:05:43 +00:00
|
|
|
const String& a_str = String::Cast(a);
|
|
|
|
const String& b_str = String::Cast(b);
|
|
|
|
ASSERT(a_str.HasHash());
|
|
|
|
ASSERT(b_str.HasHash());
|
2016-04-12 22:03:24 +00:00
|
|
|
if (a_str.Hash() != b_str.Hash()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
intptr_t a_len = a_str.Length();
|
|
|
|
if (a_len != b_str.Length()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Use a comparison which does not consider the state of the canonical bit.
|
|
|
|
return a_str.Equals(b_str, 0, a_len);
|
2014-07-29 22:47:56 +00:00
|
|
|
}
|
2016-11-08 21:54:47 +00:00
|
|
|
template <typename CharType>
|
2014-07-29 22:47:56 +00:00
|
|
|
static bool IsMatch(const CharArray<CharType>& array, const Object& obj) {
|
|
|
|
return array.Equals(String::Cast(obj));
|
|
|
|
}
|
|
|
|
static bool IsMatch(const StringSlice& slice, const Object& obj) {
|
|
|
|
return slice.Equals(String::Cast(obj));
|
|
|
|
}
|
2014-08-04 23:04:52 +00:00
|
|
|
static bool IsMatch(const ConcatString& concat, const Object& obj) {
|
|
|
|
return concat.Equals(String::Cast(obj));
|
|
|
|
}
|
2016-11-08 21:54:47 +00:00
|
|
|
static uword Hash(const Object& key) { return String::Cast(key).Hash(); }
|
|
|
|
template <typename CharType>
|
2014-07-29 22:47:56 +00:00
|
|
|
static uword Hash(const CharArray<CharType>& array) {
|
|
|
|
return array.Hash();
|
|
|
|
}
|
2016-11-08 21:54:47 +00:00
|
|
|
static uword Hash(const StringSlice& slice) { return slice.Hash(); }
|
|
|
|
static uword Hash(const ConcatString& concat) { return concat.Hash(); }
|
|
|
|
template <typename CharType>
|
2014-07-29 22:47:56 +00:00
|
|
|
static RawObject* NewKey(const CharArray<CharType>& array) {
|
|
|
|
return array.ToSymbol();
|
|
|
|
}
|
|
|
|
static RawObject* NewKey(const StringSlice& slice) {
|
|
|
|
return slice.ToSymbol();
|
|
|
|
}
|
2014-08-04 23:04:52 +00:00
|
|
|
static RawObject* NewKey(const ConcatString& concat) {
|
|
|
|
return concat.ToSymbol();
|
|
|
|
}
|
2014-07-29 22:47:56 +00:00
|
|
|
};
|
|
|
|
typedef UnorderedHashSet<SymbolTraits> SymbolTable;
|
|
|
|
|
2015-05-14 20:14:37 +00:00
|
|
|
const char* Symbols::Name(SymbolId symbol) {
|
|
|
|
ASSERT((symbol > kIllegal) && (symbol < kNullCharId));
|
|
|
|
return names[symbol];
|
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
const String& Symbols::Token(Token::Kind token) {
|
|
|
|
const int tok_index = token;
|
|
|
|
ASSERT((0 <= tok_index) && (tok_index < Token::kNumTokens));
|
|
|
|
// First keyword symbol is in symbol_handles_[kTokenTableStart + 1].
|
|
|
|
const intptr_t token_id = Symbols::kTokenTableStart + 1 + tok_index;
|
|
|
|
ASSERT(symbol_handles_[token_id] != NULL);
|
|
|
|
return *symbol_handles_[token_id];
|
2015-05-14 20:14:37 +00:00
|
|
|
}
|
|
|
|
|
2018-09-28 23:18:59 +00:00
|
|
|
void Symbols::Init(Isolate* vm_isolate) {
|
2015-05-14 20:14:37 +00:00
|
|
|
// Should only be run by the vm isolate.
|
|
|
|
ASSERT(Isolate::Current() == Dart::vm_isolate());
|
|
|
|
ASSERT(vm_isolate == Dart::vm_isolate());
|
2015-08-19 16:35:01 +00:00
|
|
|
Zone* zone = Thread::Current()->zone();
|
2015-05-14 20:14:37 +00:00
|
|
|
|
|
|
|
// Create and setup a symbol table in the vm isolate.
|
|
|
|
SetupSymbolTable(vm_isolate);
|
|
|
|
|
|
|
|
// Create all predefined symbols.
|
|
|
|
ASSERT((sizeof(names) / sizeof(const char*)) == Symbols::kNullCharId);
|
|
|
|
|
2015-08-19 16:35:01 +00:00
|
|
|
SymbolTable table(zone, vm_isolate->object_store()->symbol_table());
|
2015-05-14 20:14:37 +00:00
|
|
|
|
|
|
|
// First set up all the predefined string symbols.
|
|
|
|
// Create symbols for language keywords. Some keywords are equal to
|
|
|
|
// symbols we already created, so use New() instead of Add() to ensure
|
|
|
|
// that the symbols are canonicalized.
|
|
|
|
for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
|
|
|
|
String* str = String::ReadOnlyHandle();
|
|
|
|
*str = OneByteString::New(names[i], Heap::kOld);
|
|
|
|
str->Hash();
|
2016-04-12 22:03:24 +00:00
|
|
|
*str ^= table.InsertOrGet(*str);
|
2016-04-12 05:05:43 +00:00
|
|
|
str->SetCanonical(); // Make canonical once entered.
|
2015-05-14 20:14:37 +00:00
|
|
|
symbol_handles_[i] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add Latin1 characters as Symbols, so that Symbols::FromCharCode is fast.
|
|
|
|
for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) {
|
|
|
|
intptr_t idx = (kNullCharId + c);
|
|
|
|
ASSERT(idx < kMaxPredefinedId);
|
|
|
|
ASSERT(Utf::IsLatin1(c));
|
|
|
|
uint8_t ch = static_cast<uint8_t>(c);
|
|
|
|
String* str = String::ReadOnlyHandle();
|
|
|
|
*str = OneByteString::New(&ch, 1, Heap::kOld);
|
|
|
|
str->Hash();
|
2016-04-12 22:03:24 +00:00
|
|
|
*str ^= table.InsertOrGet(*str);
|
2016-04-12 05:05:43 +00:00
|
|
|
ASSERT(predefined_[c] == NULL);
|
|
|
|
str->SetCanonical(); // Make canonical once entered.
|
2015-05-14 20:14:37 +00:00
|
|
|
predefined_[c] = str->raw();
|
|
|
|
symbol_handles_[idx] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_isolate->object_store()->set_symbol_table(table.Release());
|
|
|
|
}
|
|
|
|
|
2018-09-28 23:18:59 +00:00
|
|
|
void Symbols::InitFromSnapshot(Isolate* vm_isolate) {
|
2015-05-14 20:14:37 +00:00
|
|
|
// Should only be run by the vm isolate.
|
|
|
|
ASSERT(Isolate::Current() == Dart::vm_isolate());
|
|
|
|
ASSERT(vm_isolate == Dart::vm_isolate());
|
2015-08-19 16:35:01 +00:00
|
|
|
Zone* zone = Thread::Current()->zone();
|
2015-05-14 20:14:37 +00:00
|
|
|
|
2015-08-19 16:35:01 +00:00
|
|
|
SymbolTable table(zone, vm_isolate->object_store()->symbol_table());
|
2015-05-14 20:14:37 +00:00
|
|
|
|
|
|
|
// Lookup all the predefined string symbols and language keyword symbols
|
|
|
|
// and cache them in the read only handles for fast access.
|
|
|
|
for (intptr_t i = 1; i < Symbols::kNullCharId; i++) {
|
|
|
|
String* str = String::ReadOnlyHandle();
|
|
|
|
const unsigned char* name =
|
|
|
|
reinterpret_cast<const unsigned char*>(names[i]);
|
|
|
|
*str ^= table.GetOrNull(Latin1Array(name, strlen(names[i])));
|
|
|
|
ASSERT(!str->IsNull());
|
|
|
|
ASSERT(str->HasHash());
|
|
|
|
ASSERT(str->IsCanonical());
|
|
|
|
symbol_handles_[i] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup Latin1 character Symbols and cache them in read only handles,
|
|
|
|
// so that Symbols::FromCharCode is fast.
|
|
|
|
for (intptr_t c = 0; c < kNumberOfOneCharCodeSymbols; c++) {
|
|
|
|
intptr_t idx = (kNullCharId + c);
|
|
|
|
ASSERT(idx < kMaxPredefinedId);
|
|
|
|
ASSERT(Utf::IsLatin1(c));
|
|
|
|
uint8_t ch = static_cast<uint8_t>(c);
|
|
|
|
String* str = String::ReadOnlyHandle();
|
|
|
|
*str ^= table.GetOrNull(Latin1Array(&ch, 1));
|
|
|
|
ASSERT(!str->IsNull());
|
|
|
|
ASSERT(str->HasHash());
|
|
|
|
ASSERT(str->IsCanonical());
|
|
|
|
predefined_[c] = str->raw();
|
|
|
|
symbol_handles_[idx] = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
vm_isolate->object_store()->set_symbol_table(table.Release());
|
|
|
|
}
|
|
|
|
|
2012-07-24 00:01:50 +00:00
|
|
|
void Symbols::SetupSymbolTable(Isolate* isolate) {
|
|
|
|
ASSERT(isolate != NULL);
|
|
|
|
|
|
|
|
// Setup the symbol table used within the String class.
|
2016-11-08 21:54:47 +00:00
|
|
|
const intptr_t initial_size = (isolate == Dart::vm_isolate())
|
|
|
|
? kInitialVMIsolateSymtabSize
|
|
|
|
: kInitialSymtabSize;
|
2014-07-29 22:47:56 +00:00
|
|
|
Array& array =
|
|
|
|
Array::Handle(HashTables::New<SymbolTable>(initial_size, Heap::kOld));
|
2012-07-24 00:01:50 +00:00
|
|
|
isolate->object_store()->set_symbol_table(array);
|
|
|
|
}
|
|
|
|
|
2019-02-08 17:16:26 +00:00
|
|
|
void Symbols::Compact() {
|
|
|
|
Thread* thread = Thread::Current();
|
|
|
|
ASSERT(thread->isolate() != Dart::vm_isolate());
|
|
|
|
HANDLESCOPE(thread);
|
|
|
|
Zone* zone = thread->zone();
|
|
|
|
ObjectStore* object_store = thread->isolate()->object_store();
|
2016-05-10 17:13:33 +00:00
|
|
|
|
2019-02-08 17:16:26 +00:00
|
|
|
// 1. Drop the tables and do a full garbage collection.
|
|
|
|
object_store->set_symbol_table(Object::empty_array());
|
|
|
|
object_store->set_canonical_types(Object::empty_array());
|
|
|
|
object_store->set_canonical_type_arguments(Object::empty_array());
|
|
|
|
thread->heap()->CollectAllGarbage();
|
2016-01-28 18:23:14 +00:00
|
|
|
|
2019-02-08 17:16:26 +00:00
|
|
|
// 2. Walk the heap to find surviving canonical objects.
|
2016-01-28 18:23:14 +00:00
|
|
|
GrowableArray<String*> symbols;
|
2019-02-08 17:16:26 +00:00
|
|
|
GrowableArray<class Type*> types;
|
|
|
|
GrowableArray<class TypeArguments*> type_args;
|
2016-01-28 18:23:14 +00:00
|
|
|
class SymbolCollector : public ObjectVisitor {
|
|
|
|
public:
|
2019-02-08 17:16:26 +00:00
|
|
|
SymbolCollector(Thread* thread,
|
|
|
|
GrowableArray<String*>* symbols,
|
|
|
|
GrowableArray<class Type*>* types,
|
|
|
|
GrowableArray<class TypeArguments*>* type_args)
|
|
|
|
: symbols_(symbols),
|
|
|
|
types_(types),
|
|
|
|
type_args_(type_args),
|
|
|
|
zone_(thread->zone()) {}
|
2016-01-28 18:23:14 +00:00
|
|
|
|
|
|
|
void VisitObject(RawObject* obj) {
|
2019-02-08 17:16:26 +00:00
|
|
|
if (obj->IsCanonical()) {
|
|
|
|
if (obj->IsStringInstance()) {
|
|
|
|
symbols_->Add(&String::Handle(zone_, String::RawCast(obj)));
|
|
|
|
} else if (obj->IsType()) {
|
|
|
|
types_->Add(&Type::Handle(zone_, Type::RawCast(obj)));
|
|
|
|
} else if (obj->IsTypeArguments()) {
|
|
|
|
type_args_->Add(
|
|
|
|
&TypeArguments::Handle(zone_, TypeArguments::RawCast(obj)));
|
|
|
|
}
|
2016-01-28 18:23:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
GrowableArray<String*>* symbols_;
|
2019-02-08 17:16:26 +00:00
|
|
|
GrowableArray<class Type*>* types_;
|
|
|
|
GrowableArray<class TypeArguments*>* type_args_;
|
2016-01-28 18:23:14 +00:00
|
|
|
Zone* zone_;
|
|
|
|
};
|
|
|
|
|
2017-08-08 00:51:21 +00:00
|
|
|
{
|
|
|
|
HeapIterationScope iteration(thread);
|
2019-02-08 17:16:26 +00:00
|
|
|
SymbolCollector visitor(thread, &symbols, &types, &type_args);
|
2017-08-08 00:51:21 +00:00
|
|
|
iteration.IterateObjects(&visitor);
|
|
|
|
}
|
2016-01-28 18:23:14 +00:00
|
|
|
|
2019-02-08 17:16:26 +00:00
|
|
|
// 3. Build new tables from the surviving canonical objects.
|
|
|
|
{
|
|
|
|
Array& array = Array::Handle(
|
|
|
|
zone,
|
|
|
|
HashTables::New<SymbolTable>(symbols.length() * 4 / 3, Heap::kOld));
|
|
|
|
SymbolTable table(zone, array.raw());
|
|
|
|
for (intptr_t i = 0; i < symbols.length(); i++) {
|
|
|
|
String& symbol = *symbols[i];
|
|
|
|
ASSERT(symbol.IsString());
|
|
|
|
ASSERT(symbol.IsCanonical());
|
|
|
|
bool present = table.Insert(symbol);
|
|
|
|
ASSERT(!present);
|
|
|
|
}
|
|
|
|
object_store->set_symbol_table(table.Release());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Array& array = Array::Handle(zone, HashTables::New<CanonicalTypeSet>(
|
|
|
|
types.length() * 4 / 3, Heap::kOld));
|
|
|
|
CanonicalTypeSet table(zone, array.raw());
|
|
|
|
for (intptr_t i = 0; i < types.length(); i++) {
|
|
|
|
class Type& type = *types[i];
|
|
|
|
ASSERT(type.IsType());
|
|
|
|
ASSERT(type.IsCanonical());
|
|
|
|
bool present = table.Insert(type);
|
|
|
|
ASSERT(!present);
|
|
|
|
}
|
|
|
|
object_store->set_canonical_types(table.Release());
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Array& array =
|
|
|
|
Array::Handle(zone, HashTables::New<CanonicalTypeArgumentsSet>(
|
|
|
|
type_args.length() * 4 / 3, Heap::kOld));
|
|
|
|
CanonicalTypeArgumentsSet table(zone, array.raw());
|
|
|
|
for (intptr_t i = 0; i < type_args.length(); i++) {
|
|
|
|
class TypeArguments& type_arg = *type_args[i];
|
|
|
|
ASSERT(type_arg.IsTypeArguments());
|
|
|
|
ASSERT(type_arg.IsCanonical());
|
|
|
|
bool present = table.Insert(type_arg);
|
|
|
|
ASSERT(!present);
|
|
|
|
}
|
|
|
|
object_store->set_canonical_type_arguments(table.Release());
|
2016-01-28 18:23:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 22:47:56 +00:00
|
|
|
void Symbols::GetStats(Isolate* isolate, intptr_t* size, intptr_t* capacity) {
|
2012-07-25 23:41:53 +00:00
|
|
|
ASSERT(isolate != NULL);
|
2015-08-19 16:35:01 +00:00
|
|
|
SymbolTable table(isolate->object_store()->symbol_table());
|
2014-07-29 22:47:56 +00:00
|
|
|
*size = table.NumOccupied();
|
|
|
|
*capacity = table.NumEntries();
|
|
|
|
table.Release();
|
2012-07-25 23:41:53 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::New(Thread* thread, const char* cstr, intptr_t len) {
|
2014-05-13 23:09:22 +00:00
|
|
|
ASSERT((cstr != NULL) && (len >= 0));
|
2012-12-04 22:18:12 +00:00
|
|
|
const uint8_t* utf8_array = reinterpret_cast<const uint8_t*>(cstr);
|
2016-04-11 23:28:29 +00:00
|
|
|
return Symbols::FromUTF8(thread, utf8_array, len);
|
2012-12-04 22:18:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromUTF8(Thread* thread,
|
|
|
|
const uint8_t* utf8_array,
|
|
|
|
intptr_t array_len) {
|
2012-12-04 22:18:12 +00:00
|
|
|
if (array_len == 0 || utf8_array == NULL) {
|
2016-04-11 23:28:29 +00:00
|
|
|
return FromLatin1(thread, reinterpret_cast<uint8_t*>(NULL), 0);
|
2012-12-04 22:18:12 +00:00
|
|
|
}
|
2012-10-31 17:56:46 +00:00
|
|
|
Utf8::Type type;
|
2012-12-04 22:18:12 +00:00
|
|
|
intptr_t len = Utf8::CodeUnitCount(utf8_array, array_len, &type);
|
|
|
|
ASSERT(len != 0);
|
2016-04-11 23:28:29 +00:00
|
|
|
Zone* zone = thread->zone();
|
2012-11-16 00:13:18 +00:00
|
|
|
if (type == Utf8::kLatin1) {
|
2012-08-03 21:51:44 +00:00
|
|
|
uint8_t* characters = zone->Alloc<uint8_t>(len);
|
2018-12-19 22:04:45 +00:00
|
|
|
if (!Utf8::DecodeToLatin1(utf8_array, array_len, characters, len)) {
|
|
|
|
Utf8::ReportInvalidByte(utf8_array, array_len, len);
|
|
|
|
return String::null();
|
|
|
|
}
|
2016-04-11 23:28:29 +00:00
|
|
|
return FromLatin1(thread, characters, len);
|
2012-07-24 00:01:50 +00:00
|
|
|
}
|
2012-11-20 02:37:21 +00:00
|
|
|
ASSERT((type == Utf8::kBMP) || (type == Utf8::kSupplementary));
|
2012-10-31 17:56:46 +00:00
|
|
|
uint16_t* characters = zone->Alloc<uint16_t>(len);
|
2018-12-19 22:04:45 +00:00
|
|
|
if (!Utf8::DecodeToUTF16(utf8_array, array_len, characters, len)) {
|
|
|
|
Utf8::ReportInvalidByte(utf8_array, array_len, len);
|
|
|
|
return String::null();
|
|
|
|
}
|
2016-04-11 23:28:29 +00:00
|
|
|
return FromUTF16(thread, characters, len);
|
2012-12-04 22:18:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromLatin1(Thread* thread,
|
|
|
|
const uint8_t* latin1_array,
|
|
|
|
intptr_t len) {
|
|
|
|
return NewSymbol(thread, Latin1Array(latin1_array, len));
|
2012-12-04 22:18:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromUTF16(Thread* thread,
|
|
|
|
const uint16_t* utf16_array,
|
|
|
|
intptr_t len) {
|
|
|
|
return NewSymbol(thread, UTF16Array(utf16_array, len));
|
2012-12-04 22:18:12 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromUTF32(Thread* thread,
|
|
|
|
const int32_t* utf32_array,
|
|
|
|
intptr_t len) {
|
|
|
|
return NewSymbol(thread, UTF32Array(utf32_array, len));
|
2012-07-24 00:01:50 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromConcat(Thread* thread,
|
|
|
|
const String& str1,
|
|
|
|
const String& str2) {
|
2015-08-20 22:13:06 +00:00
|
|
|
if (str1.Length() == 0) {
|
2016-04-11 23:28:29 +00:00
|
|
|
return New(thread, str2);
|
2015-08-20 22:13:06 +00:00
|
|
|
} else if (str2.Length() == 0) {
|
2016-04-11 23:28:29 +00:00
|
|
|
return New(thread, str1);
|
2015-08-20 22:13:06 +00:00
|
|
|
} else {
|
2016-04-11 23:28:29 +00:00
|
|
|
return NewSymbol(thread, ConcatString(str1, str2));
|
2015-08-20 22:13:06 +00:00
|
|
|
}
|
2014-08-04 23:04:52 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromGet(Thread* thread, const String& str) {
|
|
|
|
return FromConcat(thread, GetterPrefix(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
RawString* Symbols::FromSet(Thread* thread, const String& str) {
|
|
|
|
return FromConcat(thread, SetterPrefix(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
RawString* Symbols::FromDot(Thread* thread, const String& str) {
|
|
|
|
return FromConcat(thread, str, Dot());
|
|
|
|
}
|
|
|
|
|
2015-08-26 20:30:55 +00:00
|
|
|
// TODO(srdjan): If this becomes performance critical code, consider looking
|
2015-09-02 18:25:19 +00:00
|
|
|
// up symbol from hash of pieces instead of concatenating them first into
|
|
|
|
// a string.
|
2016-11-08 21:54:47 +00:00
|
|
|
RawString* Symbols::FromConcatAll(
|
|
|
|
Thread* thread,
|
2015-08-31 16:24:00 +00:00
|
|
|
const GrowableHandlePtrArray<const String>& strs) {
|
2015-09-01 17:30:03 +00:00
|
|
|
const intptr_t strs_length = strs.length();
|
|
|
|
GrowableArray<intptr_t> lengths(strs_length);
|
|
|
|
|
2015-08-26 20:30:55 +00:00
|
|
|
intptr_t len_sum = 0;
|
2015-09-02 18:25:19 +00:00
|
|
|
const intptr_t kOneByteChar = 1;
|
|
|
|
intptr_t char_size = kOneByteChar;
|
|
|
|
|
2015-09-01 17:30:03 +00:00
|
|
|
for (intptr_t i = 0; i < strs_length; i++) {
|
|
|
|
const String& str = strs[i];
|
|
|
|
const intptr_t str_len = str.Length();
|
|
|
|
if ((String::kMaxElements - len_sum) < str_len) {
|
|
|
|
Exceptions::ThrowOOM();
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
len_sum += str_len;
|
|
|
|
lengths.Add(str_len);
|
2015-09-02 18:25:19 +00:00
|
|
|
char_size = Utils::Maximum(char_size, str.CharSize());
|
2015-08-26 20:30:55 +00:00
|
|
|
}
|
2015-09-02 18:25:19 +00:00
|
|
|
const bool is_one_byte_string = char_size == kOneByteChar;
|
2015-08-26 20:30:55 +00:00
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
Zone* zone = thread->zone();
|
2015-09-01 17:30:03 +00:00
|
|
|
if (is_one_byte_string) {
|
|
|
|
uint8_t* buffer = zone->Alloc<uint8_t>(len_sum);
|
|
|
|
const uint8_t* const orig_buffer = buffer;
|
|
|
|
for (intptr_t i = 0; i < strs_length; i++) {
|
|
|
|
NoSafepointScope no_safepoint;
|
|
|
|
intptr_t str_len = lengths[i];
|
2015-09-03 06:22:16 +00:00
|
|
|
if (str_len > 0) {
|
|
|
|
const String& str = strs[i];
|
|
|
|
ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
|
2016-11-08 21:54:47 +00:00
|
|
|
const uint8_t* src_p = str.IsOneByteString()
|
2017-10-23 10:43:59 +00:00
|
|
|
? OneByteString::DataStart(str)
|
|
|
|
: ExternalOneByteString::DataStart(str);
|
2015-09-03 06:22:16 +00:00
|
|
|
memmove(buffer, src_p, str_len);
|
|
|
|
buffer += str_len;
|
|
|
|
}
|
2015-09-01 17:30:03 +00:00
|
|
|
}
|
|
|
|
ASSERT(len_sum == buffer - orig_buffer);
|
2016-04-11 23:28:29 +00:00
|
|
|
return Symbols::FromLatin1(thread, orig_buffer, len_sum);
|
2015-09-01 17:30:03 +00:00
|
|
|
} else {
|
|
|
|
uint16_t* buffer = zone->Alloc<uint16_t>(len_sum);
|
|
|
|
const uint16_t* const orig_buffer = buffer;
|
|
|
|
for (intptr_t i = 0; i < strs_length; i++) {
|
|
|
|
NoSafepointScope no_safepoint;
|
|
|
|
intptr_t str_len = lengths[i];
|
2015-09-03 06:22:16 +00:00
|
|
|
if (str_len > 0) {
|
|
|
|
const String& str = strs[i];
|
|
|
|
if (str.IsTwoByteString()) {
|
2017-10-23 10:43:59 +00:00
|
|
|
memmove(buffer, TwoByteString::DataStart(str), str_len * 2);
|
2015-09-03 06:22:16 +00:00
|
|
|
} else if (str.IsExternalTwoByteString()) {
|
2017-10-23 10:43:59 +00:00
|
|
|
memmove(buffer, ExternalTwoByteString::DataStart(str), str_len * 2);
|
2015-09-03 06:22:16 +00:00
|
|
|
} else {
|
|
|
|
// One-byte to two-byte string copy.
|
|
|
|
ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
|
2016-11-08 21:54:47 +00:00
|
|
|
const uint8_t* src_p = str.IsOneByteString()
|
2017-10-23 10:43:59 +00:00
|
|
|
? OneByteString::DataStart(str)
|
|
|
|
: ExternalOneByteString::DataStart(str);
|
2015-09-03 06:22:16 +00:00
|
|
|
for (int n = 0; n < str_len; n++) {
|
|
|
|
buffer[n] = src_p[n];
|
|
|
|
}
|
2015-09-01 17:30:03 +00:00
|
|
|
}
|
2015-09-03 06:22:16 +00:00
|
|
|
buffer += str_len;
|
2015-09-01 17:30:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT(len_sum == buffer - orig_buffer);
|
2016-04-11 23:28:29 +00:00
|
|
|
return Symbols::FromUTF16(thread, orig_buffer, len_sum);
|
2015-08-26 20:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 23:04:52 +00:00
|
|
|
// StringType can be StringSlice, ConcatString, or {Latin1,UTF16,UTF32}Array.
|
2016-11-08 21:54:47 +00:00
|
|
|
template <typename StringType>
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::NewSymbol(Thread* thread, const StringType& str) {
|
2016-05-03 00:07:31 +00:00
|
|
|
REUSABLE_OBJECT_HANDLESCOPE(thread);
|
|
|
|
REUSABLE_SMI_HANDLESCOPE(thread);
|
|
|
|
REUSABLE_ARRAY_HANDLESCOPE(thread);
|
|
|
|
String& symbol = String::Handle(thread->zone());
|
|
|
|
dart::Object& key = thread->ObjectHandle();
|
|
|
|
Smi& value = thread->SmiHandle();
|
|
|
|
Array& data = thread->ArrayHandle();
|
2014-07-29 22:47:56 +00:00
|
|
|
{
|
2014-07-31 19:50:23 +00:00
|
|
|
Isolate* vm_isolate = Dart::vm_isolate();
|
2019-05-01 00:04:44 +00:00
|
|
|
data = vm_isolate->object_store()->symbol_table();
|
2016-05-03 00:07:31 +00:00
|
|
|
SymbolTable table(&key, &value, &data);
|
2014-07-29 22:47:56 +00:00
|
|
|
symbol ^= table.GetOrNull(str);
|
|
|
|
table.Release();
|
|
|
|
}
|
2012-07-24 00:01:50 +00:00
|
|
|
if (symbol.IsNull()) {
|
2016-04-11 23:28:29 +00:00
|
|
|
Isolate* isolate = thread->isolate();
|
2016-02-20 00:03:52 +00:00
|
|
|
SafepointMutexLocker ml(isolate->symbols_mutex());
|
2019-05-01 00:04:44 +00:00
|
|
|
data = isolate->object_store()->symbol_table();
|
2016-05-03 00:07:31 +00:00
|
|
|
SymbolTable table(&key, &value, &data);
|
2014-07-29 22:47:56 +00:00
|
|
|
symbol ^= table.InsertNewOrGet(str);
|
2014-07-31 19:50:23 +00:00
|
|
|
isolate->object_store()->set_symbol_table(table.Release());
|
2012-07-24 00:01:50 +00:00
|
|
|
}
|
|
|
|
ASSERT(symbol.IsSymbol());
|
2014-08-14 21:17:40 +00:00
|
|
|
ASSERT(symbol.HasHash());
|
2012-07-24 00:01:50 +00:00
|
|
|
return symbol.raw();
|
|
|
|
}
|
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
template <typename StringType>
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::Lookup(Thread* thread, const StringType& str) {
|
2016-05-03 00:07:31 +00:00
|
|
|
REUSABLE_OBJECT_HANDLESCOPE(thread);
|
|
|
|
REUSABLE_SMI_HANDLESCOPE(thread);
|
|
|
|
REUSABLE_ARRAY_HANDLESCOPE(thread);
|
|
|
|
String& symbol = String::Handle(thread->zone());
|
|
|
|
dart::Object& key = thread->ObjectHandle();
|
|
|
|
Smi& value = thread->SmiHandle();
|
|
|
|
Array& data = thread->ArrayHandle();
|
2015-09-03 21:09:34 +00:00
|
|
|
{
|
|
|
|
Isolate* vm_isolate = Dart::vm_isolate();
|
2019-05-01 00:04:44 +00:00
|
|
|
data = vm_isolate->object_store()->symbol_table();
|
2016-05-03 00:07:31 +00:00
|
|
|
SymbolTable table(&key, &value, &data);
|
2015-09-03 21:09:34 +00:00
|
|
|
symbol ^= table.GetOrNull(str);
|
|
|
|
table.Release();
|
|
|
|
}
|
|
|
|
if (symbol.IsNull()) {
|
2016-05-03 00:07:31 +00:00
|
|
|
Isolate* isolate = thread->isolate();
|
2016-02-20 00:03:52 +00:00
|
|
|
SafepointMutexLocker ml(isolate->symbols_mutex());
|
2019-05-01 00:04:44 +00:00
|
|
|
data = isolate->object_store()->symbol_table();
|
2016-05-03 00:07:31 +00:00
|
|
|
SymbolTable table(&key, &value, &data);
|
2015-09-03 21:09:34 +00:00
|
|
|
symbol ^= table.GetOrNull(str);
|
|
|
|
table.Release();
|
|
|
|
}
|
|
|
|
ASSERT(symbol.IsNull() || symbol.IsSymbol());
|
|
|
|
ASSERT(symbol.IsNull() || symbol.HasHash());
|
|
|
|
return symbol.raw();
|
|
|
|
}
|
|
|
|
|
2016-11-08 21:54:47 +00:00
|
|
|
RawString* Symbols::LookupFromConcat(Thread* thread,
|
|
|
|
const String& str1,
|
|
|
|
const String& str2) {
|
2015-09-03 21:09:34 +00:00
|
|
|
if (str1.Length() == 0) {
|
2016-04-11 23:28:29 +00:00
|
|
|
return Lookup(thread, str2);
|
2015-09-03 21:09:34 +00:00
|
|
|
} else if (str2.Length() == 0) {
|
2016-04-11 23:28:29 +00:00
|
|
|
return Lookup(thread, str1);
|
2015-09-03 21:09:34 +00:00
|
|
|
} else {
|
2016-04-11 23:28:29 +00:00
|
|
|
return Lookup(thread, ConcatString(str1, str2));
|
2015-09-03 21:09:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::LookupFromGet(Thread* thread, const String& str) {
|
|
|
|
return LookupFromConcat(thread, GetterPrefix(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
RawString* Symbols::LookupFromSet(Thread* thread, const String& str) {
|
|
|
|
return LookupFromConcat(thread, SetterPrefix(), str);
|
|
|
|
}
|
|
|
|
|
|
|
|
RawString* Symbols::LookupFromDot(Thread* thread, const String& str) {
|
|
|
|
return LookupFromConcat(thread, str, Dot());
|
|
|
|
}
|
|
|
|
|
|
|
|
RawString* Symbols::New(Thread* thread, const String& str) {
|
2012-07-24 00:01:50 +00:00
|
|
|
if (str.IsSymbol()) {
|
|
|
|
return str.raw();
|
|
|
|
}
|
2016-04-11 23:28:29 +00:00
|
|
|
return New(thread, str, 0, str.Length());
|
2012-07-24 00:01:50 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::New(Thread* thread,
|
|
|
|
const String& str,
|
|
|
|
intptr_t begin_index,
|
|
|
|
intptr_t len) {
|
|
|
|
return NewSymbol(thread, StringSlice(str, begin_index, len));
|
2012-07-24 00:01:50 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::NewFormatted(Thread* thread, const char* format, ...) {
|
2015-09-04 17:59:28 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* result = NewFormattedV(thread, format, args);
|
2015-09-04 17:59:28 +00:00
|
|
|
NoSafepointScope no_safepoint;
|
|
|
|
va_end(args);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::NewFormattedV(Thread* thread,
|
|
|
|
const char* format,
|
|
|
|
va_list args) {
|
2015-09-04 17:59:28 +00:00
|
|
|
va_list args_copy;
|
|
|
|
va_copy(args_copy, args);
|
2018-03-01 02:07:46 +00:00
|
|
|
intptr_t len = Utils::VSNPrint(NULL, 0, format, args_copy);
|
2015-09-04 17:59:28 +00:00
|
|
|
va_end(args_copy);
|
|
|
|
|
|
|
|
Zone* zone = Thread::Current()->zone();
|
|
|
|
char* buffer = zone->Alloc<char>(len + 1);
|
2018-03-01 02:07:46 +00:00
|
|
|
Utils::VSNPrint(buffer, (len + 1), format, args);
|
2015-09-04 17:59:28 +00:00
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
return Symbols::New(thread, buffer);
|
2015-09-04 17:59:28 +00:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:28:29 +00:00
|
|
|
RawString* Symbols::FromCharCode(Thread* thread, int32_t char_code) {
|
2012-11-19 16:06:19 +00:00
|
|
|
if (char_code > kMaxOneCharCodeSymbol) {
|
2016-04-11 23:28:29 +00:00
|
|
|
return FromUTF32(thread, &char_code, 1);
|
2012-11-19 16:06:19 +00:00
|
|
|
}
|
2013-01-02 19:31:59 +00:00
|
|
|
return predefined_[char_code];
|
2012-11-19 16:06:19 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 18:49:24 +00:00
|
|
|
void Symbols::DumpStats(Isolate* isolate) {
|
|
|
|
intptr_t size = -1;
|
|
|
|
intptr_t capacity = -1;
|
|
|
|
// First dump VM symbol table stats.
|
|
|
|
GetStats(Dart::vm_isolate(), &size, &capacity);
|
2018-06-13 19:51:40 +00:00
|
|
|
OS::PrintErr("VM Isolate: Number of symbols : %" Pd "\n", size);
|
|
|
|
OS::PrintErr("VM Isolate: Symbol table capacity : %" Pd "\n", capacity);
|
2017-01-19 18:49:24 +00:00
|
|
|
// Now dump regular isolate symbol table stats.
|
|
|
|
GetStats(isolate, &size, &capacity);
|
2018-06-13 19:51:40 +00:00
|
|
|
OS::PrintErr("Isolate: Number of symbols : %" Pd "\n", size);
|
|
|
|
OS::PrintErr("Isolate: Symbol table capacity : %" Pd "\n", capacity);
|
2017-01-19 18:49:24 +00:00
|
|
|
// TODO(koda): Consider recording growth and collision stats in HashTable,
|
|
|
|
// in DEBUG mode.
|
2012-07-24 00:01:50 +00:00
|
|
|
}
|
|
|
|
|
2018-11-19 19:03:38 +00:00
|
|
|
void Symbols::DumpTable(Isolate* isolate) {
|
|
|
|
OS::PrintErr("symbols:\n");
|
|
|
|
SymbolTable table(isolate->object_store()->symbol_table());
|
|
|
|
table.Dump();
|
|
|
|
table.Release();
|
|
|
|
}
|
|
|
|
|
2016-05-10 17:13:33 +00:00
|
|
|
intptr_t Symbols::LookupPredefinedSymbol(RawObject* obj) {
|
2013-01-02 19:31:59 +00:00
|
|
|
for (intptr_t i = 1; i < Symbols::kMaxPredefinedId; i++) {
|
|
|
|
if (symbol_handles_[i]->raw() == obj) {
|
2012-08-08 19:46:23 +00:00
|
|
|
return (i + kMaxPredefinedObjectIds);
|
2012-08-06 21:56:39 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-08 19:46:23 +00:00
|
|
|
return kInvalidIndex;
|
2012-08-06 21:56:39 +00:00
|
|
|
}
|
|
|
|
|
2016-05-10 17:13:33 +00:00
|
|
|
RawObject* Symbols::GetPredefinedSymbol(intptr_t object_id) {
|
|
|
|
ASSERT(IsPredefinedSymbolId(object_id));
|
2012-08-08 19:46:23 +00:00
|
|
|
intptr_t i = (object_id - kMaxPredefinedObjectIds);
|
2013-01-02 19:31:59 +00:00
|
|
|
if ((i > kIllegal) && (i < Symbols::kMaxPredefinedId)) {
|
|
|
|
return symbol_handles_[i]->raw();
|
|
|
|
}
|
|
|
|
return Object::null();
|
2012-08-06 21:56:39 +00:00
|
|
|
}
|
|
|
|
|
2012-07-24 00:01:50 +00:00
|
|
|
} // namespace dart
|