Files
sdk/runtime/vm/object_store.cc
T
cshapiro@google.com 265e2306f5 Add a weak property type to the virtual machine.
Weak properties are key-value pairs.  The liveness of the key determines
the liveness of the value.  If the key is reachable the value is traced.
However, if the key is unreachable, the value is subject to finalization.

At present, the sole finalization action is clearing the key and value
fields.  However, it is possible to extend this to invoking callbacks or
other techniques, as well as processing values in topological order.

Review URL: https://chromiumcodereview.appspot.com//10832199

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10867 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-17 01:17:39 +00:00

140 lines
4.5 KiB
C++

// Copyright (c) 2011, 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/object_store.h"
#include "vm/exceptions.h"
#include "vm/isolate.h"
#include "vm/object.h"
#include "vm/raw_object.h"
#include "vm/visitor.h"
namespace dart {
ObjectStore::ObjectStore()
: object_class_(Class::null()),
function_interface_(Type::null()),
number_interface_(Type::null()),
int_interface_(Type::null()),
integer_implementation_class_(Class::null()),
smi_class_(Class::null()),
mint_class_(Class::null()),
bigint_class_(Class::null()),
double_interface_(Type::null()),
double_class_(Class::null()),
string_interface_(Type::null()),
one_byte_string_class_(Class::null()),
two_byte_string_class_(Class::null()),
four_byte_string_class_(Class::null()),
external_one_byte_string_class_(Class::null()),
external_two_byte_string_class_(Class::null()),
external_four_byte_string_class_(Class::null()),
bool_interface_(Type::null()),
bool_class_(Class::null()),
list_interface_(Type::null()),
array_class_(Class::null()),
immutable_array_class_(Class::null()),
growable_object_array_class_(Class::null()),
byte_array_interface_(Type::null()),
int8_array_class_(Class::null()),
uint8_array_class_(Class::null()),
int16_array_class_(Class::null()),
uint16_array_class_(Class::null()),
int32_array_class_(Class::null()),
uint32_array_class_(Class::null()),
int64_array_class_(Class::null()),
uint64_array_class_(Class::null()),
float32_array_class_(Class::null()),
float64_array_class_(Class::null()),
external_int8_array_class_(Class::null()),
external_uint8_array_class_(Class::null()),
external_int16_array_class_(Class::null()),
external_uint16_array_class_(Class::null()),
external_int32_array_class_(Class::null()),
external_uint32_array_class_(Class::null()),
external_int64_array_class_(Class::null()),
external_uint64_array_class_(Class::null()),
external_float32_array_class_(Class::null()),
external_float64_array_class_(Class::null()),
stacktrace_class_(Class::null()),
jsregexp_class_(Class::null()),
weak_property_class_(Class::null()),
true_value_(Bool::null()),
false_value_(Bool::null()),
symbol_table_(Array::null()),
canonical_type_arguments_(Array::null()),
core_library_(Library::null()),
core_impl_library_(Library::null()),
math_library_(Library::null()),
isolate_library_(Library::null()),
mirrors_library_(Library::null()),
native_wrappers_library_(Library::null()),
builtin_library_(Library::null()),
root_library_(Library::null()),
libraries_(GrowableObjectArray::null()),
import_map_(Array::null()),
pending_classes_(GrowableObjectArray::null()),
sticky_error_(Error::null()),
empty_context_(Context::null()),
stack_overflow_(Instance::null()),
out_of_memory_(Instance::null()),
keyword_symbols_(Array::null()) {
}
ObjectStore::~ObjectStore() {
}
void ObjectStore::VisitObjectPointers(ObjectPointerVisitor* visitor) {
ASSERT(visitor != NULL);
visitor->VisitPointers(from(), to());
}
void ObjectStore::Init(Isolate* isolate) {
ASSERT(isolate->object_store() == NULL);
ObjectStore* store = new ObjectStore();
isolate->set_object_store(store);
}
bool ObjectStore::PreallocateObjects() {
Isolate* isolate = Isolate::Current();
ASSERT(isolate != NULL && isolate->object_store() == this);
if (this->stack_overflow() != Instance::null() &&
this->out_of_memory() != Instance::null()) {
return true;
}
ASSERT(this->stack_overflow() == Instance::null());
ASSERT(this->out_of_memory() == Instance::null());
GrowableArray<const Object*> args;
Object& result = Object::Handle();
result = Exceptions::Create(Exceptions::kStackOverflow, args);
if (result.IsError()) {
return false;
}
set_stack_overflow(Instance::Cast(result));
result = Exceptions::Create(Exceptions::kOutOfMemory, args);
if (result.IsError()) {
return false;
}
set_out_of_memory(Instance::Cast(result));
return true;
}
void ObjectStore::InitKeywordTable() {
// Set up the keywords symbol array so that we can access it while scanning.
Array& keywords = Array::Handle(keyword_symbols());
ASSERT(keywords.IsNull());
keywords = Array::New(Token::numKeywords, Heap::kOld);
ASSERT(!keywords.IsError() && !keywords.IsNull());
set_keyword_symbols(keywords);
}
} // namespace dart