diff --git a/runtime/lib/math.cc b/runtime/lib/math.cc index 94662e6b9ed..f4b4626b436 100644 --- a/runtime/lib/math.cc +++ b/runtime/lib/math.cc @@ -110,9 +110,9 @@ DEFINE_NATIVE_ENTRY(Random_nextState, 1) { } -RawTypedData* CreateRandomState(Isolate* isolate, uint64_t seed) { +RawTypedData* CreateRandomState(Zone* zone, uint64_t seed) { const TypedData& result = TypedData::Handle( - isolate, TypedData::New(kTypedDataUint32ArrayCid, 2)); + zone, TypedData::New(kTypedDataUint32ArrayCid, 2)); result.SetUint32(0, static_cast(seed)); result.SetUint32(result.ElementSizeInBytes(), static_cast(seed >> 32)); @@ -187,7 +187,7 @@ DEFINE_NATIVE_ENTRY(Random_setupSeed, 1) { if (seed == 0) { seed = 0x5a17; } - return CreateRandomState(isolate, seed); + return CreateRandomState(zone, seed); } @@ -195,7 +195,7 @@ DEFINE_NATIVE_ENTRY(Random_initialSeed, 0) { Random* rnd = isolate->random(); uint64_t seed = rnd->NextUInt32(); seed |= (static_cast(rnd->NextUInt32()) << 32); - return CreateRandomState(isolate, seed); + return CreateRandomState(zone, seed); } } // namespace dart diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc index 8e80debb09d..7edb1c0f779 100644 --- a/runtime/lib/mirrors.cc +++ b/runtime/lib/mirrors.cc @@ -580,10 +580,11 @@ static RawInstance* CreateTypeMirror(const AbstractType& type) { static RawInstance* CreateIsolateMirror() { - Isolate* isolate = Isolate::Current(); + Thread* thread = Thread::Current(); + Isolate* isolate = thread->isolate(); const String& debug_name = String::Handle(String::New(isolate->name())); - const Library& root_library = - Library::Handle(isolate, isolate->object_store()->root_library()); + const Library& root_library = Library::Handle(thread->zone(), + isolate->object_store()->root_library()); const Instance& root_library_mirror = Instance::Handle(CreateLibraryMirror(root_library)); @@ -796,13 +797,13 @@ static RawAbstractType* InstantiateType(const AbstractType& type, DEFINE_NATIVE_ENTRY(MirrorSystem_libraries, 0) { const GrowableObjectArray& libraries = GrowableObjectArray::Handle( - isolate, isolate->object_store()->libraries()); + zone, isolate->object_store()->libraries()); const intptr_t num_libraries = libraries.Length(); const GrowableObjectArray& library_mirrors = GrowableObjectArray::Handle( - isolate, GrowableObjectArray::New(num_libraries)); - Library& library = Library::Handle(isolate); - Instance& library_mirror = Instance::Handle(isolate); + zone, GrowableObjectArray::New(num_libraries)); + Library& library = Library::Handle(zone); + Instance& library_mirror = Instance::Handle(zone); for (int i = 0; i < num_libraries; i++) { library ^= libraries.At(i); diff --git a/runtime/lib/vmservice.cc b/runtime/lib/vmservice.cc index 29581b45750..9a2cb2a7f45 100644 --- a/runtime/lib/vmservice.cc +++ b/runtime/lib/vmservice.cc @@ -25,10 +25,10 @@ static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { class RegisterRunningIsolatesVisitor : public IsolateVisitor { public: - explicit RegisterRunningIsolatesVisitor(Isolate* service_isolate) + explicit RegisterRunningIsolatesVisitor(Thread* thread) : IsolateVisitor(), - register_function_(Function::Handle(service_isolate)), - service_isolate_(service_isolate) { + register_function_(Function::Handle(thread->zone())), + service_isolate_(thread->isolate()) { ASSERT(ServiceIsolate::IsServiceIsolate(Isolate::Current())); // Get library. const String& library_url = Symbols::DartVMService(); @@ -63,7 +63,7 @@ class RegisterRunningIsolatesVisitor : public IsolateVisitor { args.SetAt(0, port_int); args.SetAt(1, send_port); args.SetAt(2, name); - Object& r = Object::Handle(service_isolate_); + Object& r = Object::Handle(service_isolate_->current_zone()); r = DartEntry::InvokeFunction(register_function_, args); if (FLAG_trace_service) { OS::Print("vm-service: Isolate %s %" Pd64 " registered.\n", @@ -115,7 +115,7 @@ DEFINE_NATIVE_ENTRY(VMService_OnStart, 0) { ServiceIsolate::BootVmServiceLibrary(); // Register running isolates with service. - RegisterRunningIsolatesVisitor register_isolates(isolate); + RegisterRunningIsolatesVisitor register_isolates(thread); if (FLAG_trace_service) { OS::Print("vm-service: Registering running isolates.\n"); } diff --git a/runtime/vm/benchmark_test.cc b/runtime/vm/benchmark_test.cc index 900a689a3d8..9fcb4d00fdc 100644 --- a/runtime/vm/benchmark_test.cc +++ b/runtime/vm/benchmark_test.cc @@ -41,7 +41,7 @@ BENCHMARK(CorelibCompileAll) { bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); Timer timer(true, "Compile all of Core lib benchmark"); timer.Start(); - const Error& error = Error::Handle(benchmark->isolate(), + const Error& error = Error::Handle(benchmark->isolate()->current_zone(), Library::CompileAll()); if (!error.IsNull()) { OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s", @@ -61,7 +61,7 @@ BENCHMARK(CorelibCompilerStats) { stats->EnableBenchmark(); Timer timer(true, "Compiler stats compiling all of Core lib"); timer.Start(); - const Error& error = Error::Handle(benchmark->isolate(), + const Error& error = Error::Handle(benchmark->isolate()->current_zone(), Library::CompileAll()); if (!error.IsNull()) { OS::PrintErr("Unexpected error in CorelibCompileAll benchmark:\n%s", diff --git a/runtime/vm/class_finalizer.cc b/runtime/vm/class_finalizer.cc index 763885088a0..4d8178bc672 100644 --- a/runtime/vm/class_finalizer.cc +++ b/runtime/vm/class_finalizer.cc @@ -120,7 +120,8 @@ bool ClassFinalizer::ProcessPendingClasses() { ASSERT(isolate != NULL); HANDLESCOPE(thread); ObjectStore* object_store = isolate->object_store(); - const Error& error = Error::Handle(isolate, object_store->sticky_error()); + const Error& error = + Error::Handle(thread->zone(), object_store->sticky_error()); if (!error.IsNull()) { return false; } @@ -562,15 +563,15 @@ void ClassFinalizer::FinalizeTypeParameters( void ClassFinalizer::CheckRecursiveType(const Class& cls, const Type& type, PendingTypes* pending_types) { - Isolate* isolate = Isolate::Current(); + Zone* zone = Thread::Current()->zone(); if (FLAG_trace_type_finalization) { THR_Print("Checking recursive type '%s': %s\n", String::Handle(type.Name()).ToCString(), type.ToCString()); } - const Class& type_cls = Class::Handle(isolate, type.type_class()); + const Class& type_cls = Class::Handle(zone, type.type_class()); const TypeArguments& arguments = - TypeArguments::Handle(isolate, type.arguments()); + TypeArguments::Handle(zone, type.arguments()); // A type can only be recursive via its type arguments. ASSERT(!arguments.IsNull()); const intptr_t num_type_args = arguments.Length(); @@ -589,7 +590,7 @@ void ClassFinalizer::CheckRecursiveType(const Class& cls, // The type parameters are not instantiated. Verify that there is no other // type pending finalization with the same type class, but different // uninstantiated type parameters. - TypeArguments& pending_arguments = TypeArguments::Handle(isolate); + TypeArguments& pending_arguments = TypeArguments::Handle(zone); const intptr_t num_pending_types = pending_types->length(); for (intptr_t i = num_pending_types - 1; i >= 0; i--) { const Type& pending_type = Type::Cast(pending_types->At(i)); @@ -607,7 +608,7 @@ void ClassFinalizer::CheckRecursiveType(const Class& cls, !pending_arguments.IsSubvectorInstantiated(first_type_param, num_type_params)) { // Reject the non-contractive recursive type. - const String& type_name = String::Handle(isolate, type.Name()); + const String& type_name = String::Handle(zone, type.Name()); ReportError(cls, type.token_pos(), "illegal recursive type '%s'", type_name.ToCString()); } @@ -1573,14 +1574,15 @@ void ClassFinalizer::ResolveAndFinalizeMemberTypes(const Class& cls) { // bound BT on T of M is applied to T of S&M. See comments below. void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { ASSERT(mixin_app_class.type_parameters() == TypeArguments::null()); - Isolate* isolate = Isolate::Current(); - const AbstractType& super_type = AbstractType::Handle(isolate, + Thread* thread = Thread::Current(); + Zone* zone = thread->zone(); + const AbstractType& super_type = AbstractType::Handle(zone, mixin_app_class.super_type()); ASSERT(super_type.IsResolved()); - const Class& super_class = Class::Handle(isolate, super_type.type_class()); + const Class& super_class = Class::Handle(zone, super_type.type_class()); const intptr_t num_super_type_params = super_class.NumTypeParameters(); - const Type& mixin_type = Type::Handle(isolate, mixin_app_class.mixin()); - const Class& mixin_class = Class::Handle(isolate, mixin_type.type_class()); + const Type& mixin_type = Type::Handle(zone, mixin_app_class.mixin()); + const Class& mixin_class = Class::Handle(zone, mixin_type.type_class()); const intptr_t num_mixin_type_params = mixin_class.NumTypeParameters(); // The mixin type (in raw form) should have been added to the interfaces @@ -1593,14 +1595,14 @@ void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { // If both the super type and the mixin type are non generic, the mixin // application class is non generic as well and we can skip type parameter // cloning. - TypeArguments& instantiator = TypeArguments::Handle(isolate); + TypeArguments& instantiator = TypeArguments::Handle(zone); if ((num_super_type_params + num_mixin_type_params) > 0) { // If the last ampersand in the name of the mixin application class is // doubled, the same type parameters can propagate the type arguments to // the super type and to the mixin type. bool share_type_params = false; if (num_super_type_params == num_mixin_type_params) { - const String& name = String::Handle(isolate, mixin_app_class.Name()); + const String& name = String::Handle(zone, mixin_app_class.Name()); for (intptr_t i = name.Length() - 1; i > 0; --i) { if (name.CharAt(i) == '&') { if (name.CharAt(i - 1) == '&') { @@ -1611,13 +1613,13 @@ void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { } } - const TypeArguments& cloned_type_params = TypeArguments::Handle(isolate, + const TypeArguments& cloned_type_params = TypeArguments::Handle(zone, TypeArguments::New((share_type_params ? 0 : num_super_type_params) + num_mixin_type_params)); - TypeParameter& param = TypeParameter::Handle(isolate); - TypeParameter& cloned_param = TypeParameter::Handle(isolate); - String& param_name = String::Handle(isolate); - AbstractType& param_bound = AbstractType::Handle(isolate); + TypeParameter& param = TypeParameter::Handle(zone); + TypeParameter& cloned_param = TypeParameter::Handle(zone); + String& param_name = String::Handle(zone); + AbstractType& param_bound = AbstractType::Handle(zone); intptr_t cloned_index = 0; // First, clone the super class type parameters. Rename them so that @@ -1625,8 +1627,8 @@ void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { // class and the mixin class. if (!share_type_params && (num_super_type_params > 0)) { const TypeArguments& super_type_params = - TypeArguments::Handle(isolate, super_class.type_parameters()); - const TypeArguments& super_type_args = TypeArguments::Handle(isolate, + TypeArguments::Handle(zone, super_class.type_parameters()); + const TypeArguments& super_type_args = TypeArguments::Handle(zone, TypeArguments::New(num_super_type_params)); // The cloned super class type parameters do not need to repeat their // bounds, since the bound checks will be performed at the super class @@ -1636,7 +1638,7 @@ void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { // the super class of its mixin. Note also that the other mixin // application will only mixin the last mixin type listed in the first // mixin application it is mixing in. - param_bound = isolate->object_store()->object_type(); + param_bound = thread->isolate()->object_store()->object_type(); for (intptr_t i = 0; i < num_super_type_params; i++) { param ^= super_type_params.TypeAt(i); param_name = param.name(); @@ -1665,10 +1667,10 @@ void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { // with that name. We also retain the type parameter bounds. if (num_mixin_type_params > 0) { const TypeArguments& mixin_params = - TypeArguments::Handle(isolate, mixin_class.type_parameters()); + TypeArguments::Handle(zone, mixin_class.type_parameters()); const intptr_t offset = mixin_class.NumTypeArguments() - mixin_class.NumTypeParameters(); - const TypeArguments& mixin_type_args = TypeArguments::Handle(isolate, + const TypeArguments& mixin_type_args = TypeArguments::Handle(zone, TypeArguments::New(num_mixin_type_params)); instantiator ^= TypeArguments::New(offset + num_mixin_type_params); bool has_uninstantiated_bounds = false; @@ -1700,7 +1702,7 @@ void ClassFinalizer::CloneMixinAppTypeParameters(const Class& mixin_app_class) { // is not a problem since they will get finalized shortly as the mixin // application class gets finalized. if (has_uninstantiated_bounds) { - Error& bound_error = Error::Handle(isolate); + Error& bound_error = Error::Handle(zone); for (intptr_t i = 0; i < num_mixin_type_params; i++) { param ^= mixin_type_args.TypeAt(i); param_bound = param.bound(); @@ -1821,13 +1823,13 @@ void ClassFinalizer::ApplyMixinAppAlias(const Class& mixin_app_class, // If this mixin alias is aliasing another mixin alias, another class // will be inserted via recursion. No need to check here. // The mixin type may or may not be finalized yet. - Isolate* isolate = Isolate::Current(); - AbstractType& super_type = AbstractType::Handle(isolate, + Zone* zone = Thread::Current()->zone(); + AbstractType& super_type = AbstractType::Handle(zone, mixin_app_class.super_type()); - const Type& mixin_type = Type::Handle(isolate, mixin_app_class.mixin()); - const Class& mixin_class = Class::Handle(isolate, mixin_type.type_class()); + const Type& mixin_type = Type::Handle(zone, mixin_app_class.mixin()); + const Class& mixin_class = Class::Handle(zone, mixin_type.type_class()); ASSERT(mixin_class.is_mixin_app_alias()); - const Class& aliased_mixin_app_class = Class::Handle(isolate, + const Class& aliased_mixin_app_class = Class::Handle(zone, mixin_class.SuperClass()); // Note that the super class of aliased_mixin_app_class can itself be a // mixin application class (this happens if the alias is mixing more than one @@ -1835,19 +1837,19 @@ void ClassFinalizer::ApplyMixinAppAlias(const Class& mixin_app_class, // super class of this inserted class, we apply the composition rules of the // spec and only mixin the members of aliased_mixin_app_class, not those of // its super class. In other words, we only mixin the last mixin of the alias. - const Type& aliased_mixin_type = Type::Handle(isolate, + const Type& aliased_mixin_type = Type::Handle(zone, aliased_mixin_app_class.mixin()); // The name of the inserted mixin application class is the name of mixin // class name with a backtick added. - String& inserted_class_name = String::Handle(isolate, mixin_app_class.Name()); + String& inserted_class_name = String::Handle(zone, mixin_app_class.Name()); inserted_class_name = String::Concat(inserted_class_name, Symbols::Backtick()); - const Library& library = Library::Handle(isolate, mixin_app_class.library()); - Class& inserted_class = Class::Handle(isolate, + const Library& library = Library::Handle(zone, mixin_app_class.library()); + Class& inserted_class = Class::Handle(zone, library.LookupLocalClass(inserted_class_name)); if (inserted_class.IsNull()) { inserted_class_name = Symbols::New(inserted_class_name); - const Script& script = Script::Handle(isolate, mixin_app_class.script()); + const Script& script = Script::Handle(zone, mixin_app_class.script()); inserted_class = Class::New( inserted_class_name, script, mixin_app_class.token_pos()); inserted_class.set_is_synthesized_class(); @@ -1872,8 +1874,8 @@ void ClassFinalizer::ApplyMixinAppAlias(const Class& mixin_app_class, // After FinalizeTypesInClass, if the mixin type and interface type are // generic, their type arguments will refer to the type parameters of // inserted_class. - const Type& inserted_class_mixin_type = Type::Handle(isolate, - Type::New(Class::Handle(isolate, aliased_mixin_type.type_class()), + const Type& inserted_class_mixin_type = Type::Handle(zone, + Type::New(Class::Handle(zone, aliased_mixin_type.type_class()), Object::null_type_arguments(), aliased_mixin_type.token_pos())); inserted_class.set_mixin(inserted_class_mixin_type); @@ -1904,33 +1906,33 @@ void ClassFinalizer::ApplyMixinAppAlias(const Class& mixin_app_class, // It is important that the type parameters of the mixin application class // are not finalized yet, because new type parameters may have been added // to the super class. - const Class& super_class = Class::Handle(isolate, super_type.type_class()); + const Class& super_class = Class::Handle(zone, super_type.type_class()); ASSERT(mixin_app_class.SuperClass() == super_class.raw()); // Will change. const intptr_t num_super_type_params = super_class.NumTypeParameters(); - AbstractType& type = AbstractType::Handle(isolate); + AbstractType& type = AbstractType::Handle(zone); // The instantiator is mapping finalized type parameters of mixin_class to // unfinalized type parameters of mixin_app_class. ASSERT(aliased_mixin_type.IsFinalized()); - const Class& aliased_mixin_type_class = Class::Handle(isolate, + const Class& aliased_mixin_type_class = Class::Handle(zone, aliased_mixin_type.type_class()); const intptr_t num_aliased_mixin_type_params = aliased_mixin_type_class.NumTypeParameters(); ASSERT(inserted_class.NumTypeParameters() == (num_super_type_params + num_aliased_mixin_type_params)); const AbstractType& mixin_class_super_type = - AbstractType::Handle(isolate, mixin_class.super_type()); + AbstractType::Handle(zone, mixin_class.super_type()); ASSERT(mixin_class_super_type.IsFinalized()); // The aliased_mixin_type may be raw. const TypeArguments& mixin_class_super_type_args = - TypeArguments::Handle(isolate, mixin_class_super_type.arguments()); - TypeArguments& new_mixin_type_args = TypeArguments::Handle(isolate); + TypeArguments::Handle(zone, mixin_class_super_type.arguments()); + TypeArguments& new_mixin_type_args = TypeArguments::Handle(zone); if ((num_aliased_mixin_type_params > 0) && !mixin_class_super_type_args.IsNull()) { new_mixin_type_args = TypeArguments::New(num_aliased_mixin_type_params); - AbstractType& bounded_type = AbstractType::Handle(isolate); - AbstractType& upper_bound = AbstractType::Handle(isolate); - TypeParameter& type_parameter = TypeParameter::Handle(isolate); - Error& bound_error = Error::Handle(isolate); + AbstractType& bounded_type = AbstractType::Handle(zone); + AbstractType& upper_bound = AbstractType::Handle(zone); + TypeParameter& type_parameter = TypeParameter::Handle(zone); + Error& bound_error = Error::Handle(zone); const intptr_t offset = mixin_class_super_type_args.Length() - num_aliased_mixin_type_params; for (intptr_t i = 0; i < num_aliased_mixin_type_params; i++) { @@ -1960,12 +1962,12 @@ void ClassFinalizer::ApplyMixinAppAlias(const Class& mixin_app_class, new_mixin_type_args.SetTypeAt(i, type); } } - TypeArguments& new_super_type_args = TypeArguments::Handle(isolate); + TypeArguments& new_super_type_args = TypeArguments::Handle(zone); if ((num_super_type_params + num_aliased_mixin_type_params) > 0) { new_super_type_args = TypeArguments::New(num_super_type_params + num_aliased_mixin_type_params); const TypeArguments& type_params = - TypeArguments::Handle(isolate, mixin_app_class.type_parameters()); + TypeArguments::Handle(zone, mixin_app_class.type_parameters()); for (intptr_t i = 0; i < num_super_type_params; i++) { type = type_params.TypeAt(i); new_super_type_args.SetTypeAt(i, type); @@ -1995,7 +1997,7 @@ void ClassFinalizer::ApplyMixinAppAlias(const Class& mixin_app_class, String::Handle(inserted_class.Name()).ToCString(), TypeArguments::Handle( inserted_class.type_parameters()).ToCString(), - String::Handle(isolate, super_type.Name()).ToCString(), + String::Handle(zone, super_type.Name()).ToCString(), num_super_type_params + num_aliased_mixin_type_params, super_type.ToCString(), String::Handle(mixin_app_class.Name()).ToCString(), @@ -2627,27 +2629,27 @@ RawType* ClassFinalizer::ResolveMixinAppType( const MixinAppType& mixin_app_type) { // Lookup or create mixin application classes in the library of cls // and resolve super type and mixin types. - Isolate* isolate = Isolate::Current(); - const Library& library = Library::Handle(isolate, cls.library()); + Zone* zone = Thread::Current()->zone(); + const Library& library = Library::Handle(zone, cls.library()); ASSERT(!library.IsNull()); - const Script& script = Script::Handle(isolate, cls.script()); + const Script& script = Script::Handle(zone, cls.script()); ASSERT(!script.IsNull()); const GrowableObjectArray& type_args = - GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); + GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); AbstractType& mixin_super_type = - AbstractType::Handle(isolate, mixin_app_type.super_type()); + AbstractType::Handle(zone, mixin_app_type.super_type()); ResolveType(cls, mixin_super_type); ASSERT(mixin_super_type.HasResolvedTypeClass()); // Even if malformed. // The super type may have a BoundedType as type argument, but cannot be // a BoundedType itself. CollectTypeArguments(cls, Type::Cast(mixin_super_type), type_args); - AbstractType& mixin_type = AbstractType::Handle(isolate); - Class& mixin_type_class = Class::Handle(isolate); - Class& mixin_app_class = Class::Handle(isolate); - String& mixin_app_class_name = String::Handle(isolate); - String& mixin_type_class_name = String::Handle(isolate); - AbstractType& super_type_arg = AbstractType::Handle(isolate); - AbstractType& mixin_type_arg = AbstractType::Handle(isolate); + AbstractType& mixin_type = AbstractType::Handle(zone); + Class& mixin_type_class = Class::Handle(zone); + Class& mixin_app_class = Class::Handle(zone); + String& mixin_app_class_name = String::Handle(zone); + String& mixin_type_class_name = String::Handle(zone); + AbstractType& super_type_arg = AbstractType::Handle(zone); + AbstractType& mixin_type_arg = AbstractType::Handle(zone); const intptr_t depth = mixin_app_type.Depth(); for (intptr_t i = 0; i < depth; i++) { mixin_type = mixin_app_type.MixinTypeAt(i); @@ -2702,7 +2704,7 @@ RawType* ClassFinalizer::ResolveMixinAppType( mixin_type.token_pos()); mixin_app_class.set_super_type(mixin_super_type); mixin_type_class = mixin_type.type_class(); - const Type& generic_mixin_type = Type::Handle(isolate, + const Type& generic_mixin_type = Type::Handle(zone, Type::New(mixin_type_class, Object::null_type_arguments(), mixin_type.token_pos())); @@ -2710,7 +2712,7 @@ RawType* ClassFinalizer::ResolveMixinAppType( // Add the mixin type to the list of interfaces that the mixin application // class implements. This is necessary so that cycle check work at // compile time (type arguments are ignored by that check). - const Array& interfaces = Array::Handle(isolate, Array::New(1)); + const Array& interfaces = Array::Handle(zone, Array::New(1)); interfaces.SetAt(0, generic_mixin_type); ASSERT(mixin_app_class.interfaces() == Object::empty_array().raw()); mixin_app_class.set_interfaces(interfaces); @@ -2732,10 +2734,10 @@ RawType* ClassFinalizer::ResolveMixinAppType( Object::null_type_arguments(), mixin_type.token_pos()); } - TypeArguments& mixin_app_args = TypeArguments::Handle(isolate); + TypeArguments& mixin_app_args = TypeArguments::Handle(zone); if (type_args.Length() > 0) { mixin_app_args = TypeArguments::New(type_args.Length()); - AbstractType& type_arg = AbstractType::Handle(isolate); + AbstractType& type_arg = AbstractType::Handle(zone); for (intptr_t i = 0; i < type_args.Length(); i++) { type_arg ^= type_args.At(i); mixin_app_args.SetTypeAt(i, type_arg); @@ -2771,12 +2773,12 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( if (FLAG_trace_class_finalization) { THR_Print("Resolving super and interfaces: %s\n", cls.ToCString()); } - Isolate* isolate = Isolate::Current(); + Zone* zone = Thread::Current()->zone(); const intptr_t cls_index = cls.id(); for (intptr_t i = 0; i < visited->length(); i++) { if ((*visited)[i] == cls_index) { // We have already visited class 'cls'. We found a cycle. - const String& class_name = String::Handle(isolate, cls.Name()); + const String& class_name = String::Handle(zone, cls.Name()); ReportError(cls, cls.token_pos(), "cyclic reference found for class '%s'", class_name.ToCString()); @@ -2785,8 +2787,8 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( // If the class/interface has no explicit super class/interfaces // and is not a mixin application, we are done. - AbstractType& super_type = AbstractType::Handle(isolate, cls.super_type()); - Array& super_interfaces = Array::Handle(isolate, cls.interfaces()); + AbstractType& super_type = AbstractType::Handle(zone, cls.super_type()); + Array& super_interfaces = Array::Handle(zone, cls.interfaces()); if ((super_type.IsNull() || super_type.IsObjectType()) && (super_interfaces.Length() == 0)) { cls.set_is_cycle_free(); @@ -2809,32 +2811,32 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( // Resolve and check the super type and interfaces of cls. visited->Add(cls_index); - AbstractType& interface = AbstractType::Handle(isolate); - Class& interface_class = Class::Handle(isolate); + AbstractType& interface = AbstractType::Handle(zone); + Class& interface_class = Class::Handle(zone); // Resolve super type. Failures lead to a longjmp. ResolveType(cls, super_type); if (super_type.IsMalformedOrMalbounded()) { - ReportError(Error::Handle(isolate, super_type.error())); + ReportError(Error::Handle(zone, super_type.error())); } if (super_type.IsDynamicType()) { ReportError(cls, cls.token_pos(), "class '%s' may not extend 'dynamic'", - String::Handle(isolate, cls.Name()).ToCString()); + String::Handle(zone, cls.Name()).ToCString()); } interface_class = super_type.type_class(); if (interface_class.IsSignatureClass()) { ReportError(cls, cls.token_pos(), "class '%s' may not extend function type alias '%s'", - String::Handle(isolate, cls.Name()).ToCString(), - String::Handle(isolate, + String::Handle(zone, cls.Name()).ToCString(), + String::Handle(zone, super_type.UserVisibleName()).ToCString()); } if (interface_class.is_enum_class()) { ReportError(cls, cls.token_pos(), "class '%s' may not extend enum '%s'", - String::Handle(isolate, cls.Name()).ToCString(), - String::Handle(isolate, interface_class.Name()).ToCString()); + String::Handle(zone, cls.Name()).ToCString(), + String::Handle(zone, interface_class.Name()).ToCString()); } // If cls belongs to core lib or to core lib's implementation, restrictions @@ -2879,11 +2881,11 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( } } if (is_error) { - const String& interface_name = String::Handle(isolate, + const String& interface_name = String::Handle(zone, interface_class.Name()); ReportError(cls, cls.token_pos(), "'%s' is not allowed to extend '%s'", - String::Handle(isolate, cls.Name()).ToCString(), + String::Handle(zone, cls.Name()).ToCString(), interface_name.ToCString()); } } @@ -2897,7 +2899,7 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( ASSERT(!interface.IsTypeParameter()); // Should be detected by parser. // A malbounded interface is only reported when involved in a type test. if (interface.IsMalformed()) { - ReportError(Error::Handle(isolate, interface.error())); + ReportError(Error::Handle(zone, interface.error())); } if (interface.IsDynamicType()) { ReportError(cls, cls.token_pos(), @@ -2905,14 +2907,14 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( } interface_class = interface.type_class(); if (interface_class.IsSignatureClass()) { - const String& interface_name = String::Handle(isolate, + const String& interface_name = String::Handle(zone, interface_class.Name()); ReportError(cls, cls.token_pos(), "function type alias '%s' may not be used as interface", interface_name.ToCString()); } if (interface_class.is_enum_class()) { - const String& interface_name = String::Handle(isolate, + const String& interface_name = String::Handle(zone, interface_class.Name()); ReportError(cls, cls.token_pos(), "enum '%s' may not be used as interface", @@ -2928,7 +2930,7 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( interface.IsDoubleType() || interface.IsStringType() || interface.IsDynamicType()) { - const String& interface_name = String::Handle(isolate, + const String& interface_name = String::Handle(zone, interface_class.Name()); if (cls.IsMixinApplication()) { ReportError(cls, cls.token_pos(), @@ -2937,7 +2939,7 @@ void ClassFinalizer::ResolveSuperTypeAndInterfaces( } else { ReportError(cls, cls.token_pos(), "'%s' is not allowed to extend or implement '%s'", - String::Handle(isolate, cls.Name()).ToCString(), + String::Handle(zone, cls.Name()).ToCString(), interface_name.ToCString()); } } diff --git a/runtime/vm/class_finalizer_test.cc b/runtime/vm/class_finalizer_test.cc index 648ab6edf29..828ecacad04 100644 --- a/runtime/vm/class_finalizer_test.cc +++ b/runtime/vm/class_finalizer_test.cc @@ -23,10 +23,11 @@ static RawClass* CreateTestClass(const char* name) { TEST_CASE(ClassFinalizer) { - Isolate* isolate = Isolate::Current(); + Zone* zone = thread->zone(); + Isolate* isolate = thread->isolate(); ObjectStore* object_store = isolate->object_store(); const GrowableObjectArray& pending_classes = - GrowableObjectArray::Handle(isolate, object_store->pending_classes()); + GrowableObjectArray::Handle(zone, object_store->pending_classes()); GrowableArray classes_1; classes_1.Add(&Class::Handle(CreateTestClass("BMW"))); pending_classes.Add(*classes_1[0]); @@ -53,10 +54,11 @@ TEST_CASE(ClassFinalizer) { TEST_CASE(ClassFinalize_Cycles) { - Isolate* isolate = Isolate::Current(); + Zone* zone = thread->zone(); + Isolate* isolate = thread->isolate(); ObjectStore* object_store = isolate->object_store(); const GrowableObjectArray& pending_classes = - GrowableObjectArray::Handle(isolate, object_store->pending_classes()); + GrowableObjectArray::Handle(zone, object_store->pending_classes()); GrowableArray classes; classes.Add(&Class::Handle(CreateTestClass("Jungfrau"))); pending_classes.Add(*classes[0]); @@ -78,10 +80,11 @@ static RawLibrary* NewLib(const char* url_chars) { TEST_CASE(ClassFinalize_Resolve) { - Isolate* isolate = Isolate::Current(); + Zone* zone = thread->zone(); + Isolate* isolate = thread->isolate(); ObjectStore* object_store = isolate->object_store(); const GrowableObjectArray& pending_classes = - GrowableObjectArray::Handle(isolate, object_store->pending_classes()); + GrowableObjectArray::Handle(zone, object_store->pending_classes()); Class& rhb = Class::Handle(CreateTestClass("RhB")); pending_classes.Add(rhb); Class& sbb = Class::Handle(CreateTestClass("SBB")); diff --git a/runtime/vm/code_generator.cc b/runtime/vm/code_generator.cc index 5179b4a5f39..d640955a2e4 100644 --- a/runtime/vm/code_generator.cc +++ b/runtime/vm/code_generator.cc @@ -278,7 +278,7 @@ DEFINE_RUNTIME_ENTRY(CloneContext, 1) { const Context& ctx = Context::CheckedHandle(arguments.ArgAt(0)); Context& cloned_ctx = Context::Handle(Context::New(ctx.num_variables())); cloned_ctx.set_parent(Context::Handle(ctx.parent())); - Object& inst = Object::Handle(isolate); + Object& inst = Object::Handle(zone); for (int i = 0; i < ctx.num_variables(); i++) { inst = ctx.At(i); cloned_ctx.SetAt(i, inst); @@ -1456,7 +1456,7 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { ASSERT(isolate->background_compiler() != NULL); isolate->background_compiler()->CompileOptimized(function); // Continue in the same code. - arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); + arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); return; } if (FLAG_trace_compiler) { @@ -1466,14 +1466,14 @@ DEFINE_RUNTIME_ENTRY(OptimizeInvokedFunction, 1) { } } const Error& error = Error::Handle( - isolate, Compiler::CompileOptimizedFunction(thread, function)); + zone, Compiler::CompileOptimizedFunction(thread, function)); if (!error.IsNull()) { Exceptions::PropagateError(error); } - const Code& optimized_code = Code::Handle(isolate, function.CurrentCode()); + const Code& optimized_code = Code::Handle(zone, function.CurrentCode()); ASSERT(!optimized_code.IsNull()); } - arguments.SetReturn(Code::Handle(isolate, function.CurrentCode())); + arguments.SetReturn(Code::Handle(zone, function.CurrentCode())); } @@ -1493,16 +1493,16 @@ DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { UNREACHABLE(); } ASSERT(frame->IsDartFrame()); - const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); + const Code& caller_code = Code::Handle(zone, frame->LookupDartCode()); ASSERT(caller_code.is_optimized()); const Function& target_function = Function::Handle( - isolate, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); + zone, caller_code.GetStaticCallTargetFunctionAt(frame->pc())); const Code& target_code = Code::Handle( - isolate, caller_code.GetStaticCallTargetCodeAt(frame->pc())); + zone, caller_code.GetStaticCallTargetCodeAt(frame->pc())); ASSERT(!target_code.IsNull()); if (!target_function.HasCode()) { const Error& error = Error::Handle( - isolate, Compiler::CompileFunction(thread, target_function)); + zone, Compiler::CompileFunction(thread, target_function)); if (!error.IsNull()) { Exceptions::PropagateError(error); } @@ -1511,7 +1511,7 @@ DEFINE_RUNTIME_ENTRY(FixCallersTarget, 0) { ASSERT(target_function.raw() == target_code.function()); const Code& current_target_code = Code::Handle( - isolate, target_function.CurrentCode()); + zone, target_function.CurrentCode()); CodePatcher::PatchStaticCallAt(frame->pc(), caller_code, current_target_code); @@ -1543,13 +1543,13 @@ DEFINE_RUNTIME_ENTRY(FixAllocationStubTarget, 0) { UNREACHABLE(); } ASSERT(frame->IsDartFrame()); - const Code& caller_code = Code::Handle(isolate, frame->LookupDartCode()); + const Code& caller_code = Code::Handle(zone, frame->LookupDartCode()); ASSERT(!caller_code.IsNull()); const Code& stub = Code::Handle( CodePatcher::GetStaticCallTargetAt(frame->pc(), caller_code)); Class& alloc_class = Class::ZoneHandle(zone); alloc_class ^= stub.owner(); - Code& alloc_stub = Code::Handle(isolate, alloc_class.allocation_stub()); + Code& alloc_stub = Code::Handle(zone, alloc_class.allocation_stub()); if (alloc_stub.IsNull()) { alloc_stub = StubCode::GetAllocationStubForClass(alloc_class); ASSERT(!alloc_stub.IsDisabled()); diff --git a/runtime/vm/compiler.cc b/runtime/vm/compiler.cc index 666a47b2739..f93657b97e1 100644 --- a/runtime/vm/compiler.cc +++ b/runtime/vm/compiler.cc @@ -215,10 +215,10 @@ static void AddRelatedClassesToList( const Class& cls, GrowableHandlePtrArray* parse_list, GrowableHandlePtrArray* patch_list) { - Isolate* isolate = Isolate::Current(); - Class& parse_class = Class::Handle(isolate); - AbstractType& interface_type = Type::Handle(isolate); - Array& interfaces = Array::Handle(isolate); + Zone* zone = Thread::Current()->zone(); + Class& parse_class = Class::Handle(zone); + AbstractType& interface_type = Type::Handle(zone); + Array& interfaces = Array::Handle(zone); // Add all the interfaces implemented by the class that have not been // already parsed to the parse list. Mark the interface as parsed so that @@ -281,8 +281,9 @@ RawError* Compiler::CompileClass(const Class& cls) { ClassFinalizer::FinalizeClass(cls); return Error::null(); } else { - Isolate* isolate = Isolate::Current(); - Error& error = Error::Handle(isolate); + Thread* thread = Thread::Current(); + Isolate* isolate = thread->isolate(); + Error& error = Error::Handle(thread->zone()); error = isolate->object_store()->sticky_error(); isolate->object_store()->clear_sticky_error(); return error.raw(); @@ -365,7 +366,7 @@ RawError* Compiler::CompileClass(const Class& cls) { parse_class.reset_is_marked_for_parsing(); } } - Error& error = Error::Handle(isolate); + Error& error = Error::Handle(zone.GetZone()); error = isolate->object_store()->sticky_error(); isolate->object_store()->clear_sticky_error(); return error.raw(); @@ -1552,8 +1553,8 @@ void BackgroundCompiler::EnsureInit(Isolate* isolate) { if (isolate->background_compiler() == NULL) { BackgroundCompiler* task = new BackgroundCompiler(isolate); isolate->set_background_compiler(task); - isolate->set_background_compilation_queue( - GrowableObjectArray::Handle(isolate, GrowableObjectArray::New())); + isolate->set_background_compilation_queue(GrowableObjectArray::Handle( + isolate->current_zone(), GrowableObjectArray::New())); start_task = true; } } diff --git a/runtime/vm/compiler_test.cc b/runtime/vm/compiler_test.cc index f6431d26849..19e495385d8 100644 --- a/runtime/vm/compiler_test.cc +++ b/runtime/vm/compiler_test.cc @@ -183,8 +183,8 @@ TEST_CASE(RegenerateAllocStubs) { lib_handle.LookupClass(String::Handle(Symbols::New("A")))); EXPECT(!cls.IsNull()); - Isolate* isolate = Isolate::Current(); - const Code& stub = Code::Handle(isolate, + Zone* zone = thread->zone(); + const Code& stub = Code::Handle(zone, StubCode::GetAllocationStubForClass(cls)); Class& owner = Class::Handle(); owner ^= stub.owner(); diff --git a/runtime/vm/constant_propagator.cc b/runtime/vm/constant_propagator.cc index 6ccc307e2ee..61c09a610ea 100644 --- a/runtime/vm/constant_propagator.cc +++ b/runtime/vm/constant_propagator.cc @@ -431,7 +431,7 @@ void ConstantPropagator::VisitIfThenElse(IfThenElseInstr* instr) { ASSERT(value.IsBool()); bool result = Bool::Cast(value).value(); SetValue(instr, - Smi::Handle(I, Smi::New( + Smi::Handle(Z, Smi::New( result ? instr->if_true() : instr->if_false()))); } } @@ -521,9 +521,9 @@ void ConstantPropagator::VisitTestSmi(TestSmiInstr* instr) { !left.IsBigint() && !right.IsBigint()) { const bool result = CompareIntegers( instr->kind(), - Integer::Handle(I, Integer::Cast(left).BitOp(Token::kBIT_AND, + Integer::Handle(Z, Integer::Cast(left).BitOp(Token::kBIT_AND, Integer::Cast(right))), - Smi::Handle(I, Smi::New(0))); + Smi::Handle(Z, Smi::New(0))); SetValue(instr, result ? Bool::True() : Bool::False()); } else { SetValue(instr, non_constant_); @@ -662,14 +662,14 @@ void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) { if (array_obj.IsString()) { const String& str = String::Cast(array_obj); if (str.Length() > index) { - SetValue(instr, Smi::Handle(I, + SetValue(instr, Smi::Handle(Z, Smi::New(static_cast(str.CharAt(index))))); return; } } else if (array_obj.IsArray()) { const Array& a = Array::Cast(array_obj); if ((a.Length() > index) && a.IsImmutable()) { - Instance& result = Instance::Handle(I); + Instance& result = Instance::Handle(Z); result ^= a.At(index); SetValue(instr, result); return; @@ -706,7 +706,7 @@ void ConstantPropagator::VisitInitStaticField(InitStaticFieldInstr* instr) { void ConstantPropagator::VisitLoadStaticField(LoadStaticFieldInstr* instr) { const Field& field = instr->StaticField(); ASSERT(field.is_static()); - Instance& obj = Instance::Handle(I, field.StaticValue()); + Instance& obj = Instance::Handle(Z, field.StaticValue()); if (field.is_final() && (obj.raw() != Object::sentinel().raw()) && (obj.raw() != Object::transition_sentinel().raw())) { if (obj.IsSmi() || obj.IsOld()) { @@ -924,7 +924,7 @@ void ConstantPropagator::VisitBinaryIntegerOp(BinaryIntegerOpInstr* binary_op) { const Integer& left_int = Integer::Cast(left); const Integer& right_int = Integer::Cast(right); const Integer& result = - Integer::Handle(I, binary_op->Evaluate(left_int, right_int)); + Integer::Handle(Z, binary_op->Evaluate(left_int, right_int)); if (!result.IsNull()) { SetValue(binary_op, Integer::ZoneHandle(Z, result.raw())); return; @@ -983,7 +983,7 @@ void ConstantPropagator::VisitUnaryIntegerOp(UnaryIntegerOpInstr* unary_op) { if (IsConstant(value) && value.IsInteger()) { const Integer& value_int = Integer::Cast(value); const Integer& result = - Integer::Handle(I, unary_op->Evaluate(value_int)); + Integer::Handle(Z, unary_op->Evaluate(value_int)); if (!result.IsNull()) { SetValue(unary_op, Integer::ZoneHandle(Z, result.raw())); return; @@ -1018,7 +1018,7 @@ void ConstantPropagator::VisitUnaryDoubleOp(UnaryDoubleOpInstr* instr) { void ConstantPropagator::VisitSmiToDouble(SmiToDoubleInstr* instr) { const Object& value = instr->value()->definition()->constant_value(); if (IsConstant(value) && value.IsInteger()) { - SetValue(instr, Double::Handle(I, + SetValue(instr, Double::Handle(Z, Double::New(Integer::Cast(value).AsDoubleValue(), Heap::kOld))); } else if (!IsUnknown(value)) { SetValue(instr, non_constant_); @@ -1029,7 +1029,7 @@ void ConstantPropagator::VisitSmiToDouble(SmiToDoubleInstr* instr) { void ConstantPropagator::VisitMintToDouble(MintToDoubleInstr* instr) { const Object& value = instr->value()->definition()->constant_value(); if (IsConstant(value) && value.IsInteger()) { - SetValue(instr, Double::Handle(I, + SetValue(instr, Double::Handle(Z, Double::New(Integer::Cast(value).AsDoubleValue(), Heap::kOld))); } else if (!IsUnknown(value)) { SetValue(instr, non_constant_); @@ -1040,7 +1040,7 @@ void ConstantPropagator::VisitMintToDouble(MintToDoubleInstr* instr) { void ConstantPropagator::VisitInt32ToDouble(Int32ToDoubleInstr* instr) { const Object& value = instr->value()->definition()->constant_value(); if (IsConstant(value) && value.IsInteger()) { - SetValue(instr, Double::Handle(I, + SetValue(instr, Double::Handle(Z, Double::New(Integer::Cast(value).AsDoubleValue(), Heap::kOld))); } else if (!IsUnknown(value)) { SetValue(instr, non_constant_); diff --git a/runtime/vm/dart_entry.cc b/runtime/vm/dart_entry.cc index 82055bb7b89..c0a0ef9afb2 100644 --- a/runtime/vm/dart_entry.cc +++ b/runtime/vm/dart_entry.cc @@ -229,9 +229,10 @@ RawObject* DartEntry::InvokeNoSuchMethod(const Instance& receiver, if (function.IsNull()) { ASSERT(!FLAG_lazy_dispatchers); // If noSuchMethod(invocation) is not found, call Object::noSuchMethod. - Isolate* isolate = Isolate::Current(); + Thread* thread = Thread::Current(); function ^= Resolver::ResolveDynamicForReceiverClass( - Class::Handle(isolate, isolate->object_store()->object_class()), + Class::Handle(thread->zone(), + thread->isolate()->object_store()->object_class()), Symbols::NoSuchMethod(), args_desc); } @@ -483,10 +484,9 @@ RawObject* DartLibraryCalls::Equals(const Instance& left, RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) { - Isolate* isolate = Isolate::Current(); - Function& function = - Function::Handle(isolate, - isolate->object_store()->lookup_port_handler()); + Thread* thread = Thread::Current(); + Function& function = Function::Handle(thread->zone(), + thread->isolate()->object_store()->lookup_port_handler()); const int kNumArguments = 1; if (function.IsNull()) { Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); @@ -501,7 +501,7 @@ RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) { kNumArguments, Object::empty_array()); ASSERT(!function.IsNull()); - isolate->object_store()->set_lookup_port_handler(function); + thread->isolate()->object_store()->set_lookup_port_handler(function); } const Array& args = Array::Handle(Array::New(kNumArguments)); args.SetAt(0, Integer::Handle(Integer::New(port_id))); @@ -513,16 +513,18 @@ RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) { RawObject* DartLibraryCalls::HandleMessage(const Object& handler, const Instance& message) { - Isolate* isolate = Isolate::Current(); - Function& function = Function::Handle(isolate, + Thread* thread = Thread::Current(); + Zone* zone = thread->zone(); + Isolate* isolate = thread->isolate(); + Function& function = Function::Handle(zone, isolate->object_store()->handle_message_function()); const int kNumArguments = 2; if (function.IsNull()) { - Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); + Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); ASSERT(!isolate_lib.IsNull()); - const String& class_name = String::Handle(isolate, + const String& class_name = String::Handle(zone, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); - const String& function_name = String::Handle(isolate, + const String& function_name = String::Handle(zone, isolate_lib.PrivateName(Symbols::_handleMessage())); function = Resolver::ResolveStatic(isolate_lib, class_name, @@ -532,7 +534,7 @@ RawObject* DartLibraryCalls::HandleMessage(const Object& handler, ASSERT(!function.IsNull()); isolate->object_store()->set_handle_message_function(function); } - const Array& args = Array::Handle(isolate, Array::New(kNumArguments)); + const Array& args = Array::Handle(zone, Array::New(kNumArguments)); args.SetAt(0, handler); args.SetAt(1, message); if (isolate->debugger()->IsStepping()) { @@ -541,7 +543,7 @@ RawObject* DartLibraryCalls::HandleMessage(const Object& handler, // at the first location the user is interested in. isolate->debugger()->SetSingleStep(); } - const Object& result = Object::Handle(isolate, + const Object& result = Object::Handle(zone, DartEntry::InvokeFunction(function, args)); ASSERT(result.IsNull() || result.IsError()); return result.raw(); @@ -549,13 +551,13 @@ RawObject* DartLibraryCalls::HandleMessage(const Object& handler, RawObject* DartLibraryCalls::DrainMicrotaskQueue() { - Isolate* isolate = Isolate::Current(); - Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); + Zone* zone = Thread::Current()->zone(); + Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); ASSERT(!isolate_lib.IsNull()); - Function& function = Function::Handle(isolate, + Function& function = Function::Handle(zone, isolate_lib.LookupFunctionAllowPrivate( Symbols::_runPendingImmediateCallback())); - const Object& result = Object::Handle(isolate, + const Object& result = Object::Handle(zone, DartEntry::InvokeFunction(function, Object::empty_array())); ASSERT(result.IsNull() || result.IsError()); return result.raw(); diff --git a/runtime/vm/debugger.cc b/runtime/vm/debugger.cc index 231ea4c61ae..a92b4d52380 100644 --- a/runtime/vm/debugger.cc +++ b/runtime/vm/debugger.cc @@ -310,8 +310,8 @@ void Debugger::InvokeEventHandler(DebuggerEvent* event) { if (ServiceNeedsDebuggerEvent(event->type()) && event->IsPauseEvent()) { // If we were paused, notify the service that we have resumed. - const Error& error = - Error::Handle(isolate_, isolate_->object_store()->sticky_error()); + const Error& error = Error::Handle(zone(), + isolate_->object_store()->sticky_error()); ASSERT(error.IsNull() || error.IsUnwindError()); // Only send a resume event when the isolate is not unwinding. @@ -365,7 +365,7 @@ RawError* Debugger::SignalIsolateInterrupted() { // If any error occurred while in the debug message loop, return it here. const Error& error = - Error::Handle(isolate_, isolate_->object_store()->sticky_error()); + Error::Handle(zone(), isolate_->object_store()->sticky_error()); ASSERT(error.IsNull() || error.IsUnwindError()); isolate_->object_store()->clear_sticky_error(); return error.raw(); @@ -474,7 +474,7 @@ bool Debugger::HasBreakpoint(const Function& func) { // is a user-defined breakpoint that falls into the token // range of the function. This may be a false positive: the breakpoint // might be inside a local closure. - Script& script = Script::Handle(isolate_); + Script& script = Script::Handle(zone()); BreakpointLocation* sbpt = breakpoint_locations_; while (sbpt != NULL) { script = sbpt->script(); @@ -1432,11 +1432,11 @@ ActivationFrame* Debugger::CollectDartFrame(Isolate* isolate, } -RawArray* Debugger::DeoptimizeToArray(Isolate* isolate, +RawArray* Debugger::DeoptimizeToArray(Thread* thread, StackFrame* frame, const Code& code) { ASSERT(code.is_optimized()); - + Isolate* isolate = thread->isolate(); // Create the DeoptContext for this deoptimization. DeoptContext* deopt_context = new DeoptContext(frame, code, @@ -1448,7 +1448,7 @@ RawArray* Debugger::DeoptimizeToArray(Isolate* isolate, deopt_context->FillDestFrame(); deopt_context->MaterializeDeferredObjects(); - const Array& dest_frame = Array::Handle(isolate, + const Array& dest_frame = Array::Handle(thread->zone(), deopt_context->DestFrameAsArray()); isolate->set_deopt_context(NULL); @@ -1459,12 +1459,14 @@ RawArray* Debugger::DeoptimizeToArray(Isolate* isolate, DebuggerStackTrace* Debugger::CollectStackTrace() { - Isolate* isolate = Isolate::Current(); + Thread* thread = Thread::Current(); + Zone* zone = thread->zone(); + Isolate* isolate = thread->isolate(); DebuggerStackTrace* stack_trace = new DebuggerStackTrace(8); StackFrameIterator iterator(false); - Code& code = Code::Handle(isolate); - Code& inlined_code = Code::Handle(isolate); - Array& deopt_frame = Array::Handle(isolate); + Code& code = Code::Handle(zone); + Code& inlined_code = Code::Handle(zone); + Array& deopt_frame = Array::Handle(zone); for (StackFrame* frame = iterator.NextFrame(); frame != NULL; @@ -1477,14 +1479,14 @@ DebuggerStackTrace* Debugger::CollectStackTrace() { if (frame->IsDartFrame()) { code = frame->LookupDartCode(); if (code.is_optimized() && !Compiler::always_optimize()) { - deopt_frame = DeoptimizeToArray(isolate, frame, code); + deopt_frame = DeoptimizeToArray(thread, frame, code); for (InlinedFunctionsIterator it(code, frame->pc()); !it.Done(); it.Advance()) { inlined_code = it.code(); if (FLAG_trace_debugger_stacktrace) { const Function& function = - Function::Handle(isolate, inlined_code.function()); + Function::Handle(zone, inlined_code.function()); ASSERT(!function.IsNull()); OS::PrintErr("CollectStackTrace: visiting inlined function: %s\n", function.ToFullyQualifiedCString()); @@ -1517,7 +1519,7 @@ ActivationFrame* Debugger::TopDartFrame() const { while ((frame != NULL) && !frame->IsDartFrame()) { frame = iterator.NextFrame(); } - Code& code = Code::Handle(isolate_, frame->LookupDartCode()); + Code& code = Code::Handle(zone(), frame->LookupDartCode()); ActivationFrame* activation = new ActivationFrame(frame->pc(), frame->fp(), frame->sp(), code, Object::null_array(), 0); @@ -1864,10 +1866,11 @@ void Debugger::FindCompiledFunctions(const Script& script, intptr_t start_pos, intptr_t end_pos, GrowableObjectArray* function_list) { - Class& cls = Class::Handle(isolate_); - Array& functions = Array::Handle(isolate_); - GrowableObjectArray& closures = GrowableObjectArray::Handle(isolate_); - Function& function = Function::Handle(isolate_); + Zone* zn = zone(); + Class& cls = Class::Handle(zn); + Array& functions = Array::Handle(zn); + GrowableObjectArray& closures = GrowableObjectArray::Handle(zn); + Function& function = Function::Handle(zn); const ClassTable& class_table = *isolate_->class_table(); const intptr_t num_classes = class_table.NumCids(); @@ -1947,12 +1950,13 @@ static void SelectBestFit(Function* best_fit, Function* func) { RawFunction* Debugger::FindBestFit(const Script& script, intptr_t token_pos) { - Class& cls = Class::Handle(isolate_); - Array& functions = Array::Handle(isolate_); - GrowableObjectArray& closures = GrowableObjectArray::Handle(isolate_); - Function& function = Function::Handle(isolate_); - Function& best_fit = Function::Handle(isolate_); - Error& error = Error::Handle(isolate_); + Zone* zn = zone(); + Class& cls = Class::Handle(zn); + Array& functions = Array::Handle(zn); + GrowableObjectArray& closures = GrowableObjectArray::Handle(zn); + Function& function = Function::Handle(zn); + Function& best_fit = Function::Handle(zn); + Error& error = Error::Handle(zn); const ClassTable& class_table = *isolate_->class_table(); const intptr_t num_classes = class_table.NumCids(); @@ -2011,7 +2015,7 @@ BreakpointLocation* Debugger::SetBreakpoint(const Script& script, intptr_t last_token_pos, intptr_t requested_line, intptr_t requested_column) { - Function& func = Function::Handle(isolate_); + Function& func = Function::Handle(zone()); func = FindBestFit(script, token_pos); if (func.IsNull()) { return NULL; @@ -2203,12 +2207,12 @@ BreakpointLocation* Debugger::BreakpointLocationAtLineCol( const String& script_url, intptr_t line_number, intptr_t column_number) { - Library& lib = Library::Handle(isolate_); - Script& script = Script::Handle(isolate_); + Library& lib = Library::Handle(zone()); + Script& script = Script::Handle(zone()); const GrowableObjectArray& libs = GrowableObjectArray::Handle(isolate_->object_store()->libraries()); const GrowableObjectArray& scripts = - GrowableObjectArray::Handle(isolate_, GrowableObjectArray::New()); + GrowableObjectArray::Handle(zone(), GrowableObjectArray::New()); for (intptr_t i = 0; i < libs.Length(); i++) { lib ^= libs.At(i); script = lib.LookupScript(script_url); @@ -2398,10 +2402,10 @@ void Debugger::CollectLibraryFields(const GrowableObjectArray& field_list, const String& prefix, bool include_private_fields) { DictionaryIterator it(lib); - Object& entry = Object::Handle(isolate_); - Field& field = Field::Handle(isolate_); - String& field_name = String::Handle(isolate_); - PassiveObject& field_value = PassiveObject::Handle(isolate_); + Object& entry = Object::Handle(isolate_->current_zone()); + Field& field = Field::Handle(zone()); + String& field_name = String::Handle(zone()); + PassiveObject& field_value = PassiveObject::Handle(isolate_->current_zone()); while (it.HasNext()) { entry = it.GetNext(); if (entry.IsField()) { @@ -2434,7 +2438,7 @@ void Debugger::CollectLibraryFields(const GrowableObjectArray& field_list, RawArray* Debugger::GetLibraryFields(const Library& lib) { const GrowableObjectArray& field_list = GrowableObjectArray::Handle(GrowableObjectArray::New(8)); - CollectLibraryFields(field_list, lib, String::Handle(isolate_), true); + CollectLibraryFields(field_list, lib, String::Handle(zone()), true); return Array::MakeArray(field_list); } @@ -2442,16 +2446,16 @@ RawArray* Debugger::GetLibraryFields(const Library& lib) { RawArray* Debugger::GetGlobalFields(const Library& lib) { const GrowableObjectArray& field_list = GrowableObjectArray::Handle(GrowableObjectArray::New(8)); - String& prefix_name = String::Handle(isolate_); + String& prefix_name = String::Handle(zone()); CollectLibraryFields(field_list, lib, prefix_name, true); - Library& imported = Library::Handle(isolate_); + Library& imported = Library::Handle(zone()); intptr_t num_imports = lib.num_imports(); for (intptr_t i = 0; i < num_imports; i++) { imported = lib.ImportLibraryAt(i); ASSERT(!imported.IsNull()); CollectLibraryFields(field_list, imported, prefix_name, false); } - LibraryPrefix& prefix = LibraryPrefix::Handle(isolate_); + LibraryPrefix& prefix = LibraryPrefix::Handle(zone()); LibraryPrefixIterator it(lib); while (it.HasNext()) { prefix = it.GetNext(); @@ -2660,7 +2664,7 @@ RawError* Debugger::DebuggerStepCallback() { // If any error occurred while in the debug message loop, return it here. const Error& error = - Error::Handle(isolate_, isolate_->object_store()->sticky_error()); + Error::Handle(zone(), isolate_->object_store()->sticky_error()); isolate_->object_store()->clear_sticky_error(); return error.raw(); } @@ -2749,7 +2753,7 @@ RawError* Debugger::SignalBpReached() { // If any error occurred while in the debug message loop, return it here. const Error& error = - Error::Handle(isolate_, isolate_->object_store()->sticky_error()); + Error::Handle(zone(), isolate_->object_store()->sticky_error()); isolate_->object_store()->clear_sticky_error(); return error.raw(); } @@ -2806,7 +2810,7 @@ void Debugger::NotifyIsolateCreated() { // the given token position. RawFunction* Debugger::FindInnermostClosure(const Function& function, intptr_t token_pos) { - const Class& owner = Class::Handle(isolate_, function.Owner()); + const Class& owner = Class::Handle(zone(), function.Owner()); if (owner.closures() == GrowableObjectArray::null()) { return Function::null(); } @@ -2814,12 +2818,12 @@ RawFunction* Debugger::FindInnermostClosure(const Function& function, // script as the outer function. We could have closures originating // in mixin classes whose source code is contained in a different // script. - const Script& outer_origin = Script::Handle(isolate_, function.script()); + const Script& outer_origin = Script::Handle(zone(), function.script()); const GrowableObjectArray& closures = - GrowableObjectArray::Handle(isolate_, owner.closures()); + GrowableObjectArray::Handle(zone(), owner.closures()); const intptr_t num_closures = closures.Length(); - Function& closure = Function::Handle(isolate_); - Function& best_fit = Function::Handle(isolate_); + Function& closure = Function::Handle(zone()); + Function& best_fit = Function::Handle(zone()); for (intptr_t i = 0; i < num_closures; i++) { closure ^= closures.At(i); if ((function.token_pos() < closure.token_pos()) && @@ -2847,13 +2851,13 @@ void Debugger::NotifyCompilation(const Function& func) { } // Iterate over all source breakpoints to check whether breakpoints // need to be set in the newly compiled function. - Script& script = Script::Handle(isolate_); + Script& script = Script::Handle(zone()); for (BreakpointLocation* loc = breakpoint_locations_; loc != NULL; loc = loc->next()) { script = loc->script(); if (FunctionContains(func, script, loc->token_pos())) { - Function& inner_function = Function::Handle(isolate_); + Function& inner_function = Function::Handle(zone()); inner_function = FindInnermostClosure(func, loc->token_pos()); if (!inner_function.IsNull()) { // The local function of a function we just compiled cannot @@ -2934,9 +2938,10 @@ void Debugger::NotifyDoneLoading() { // Common, fast path. return; } - Library& lib = Library::Handle(isolate_); - Script& script = Script::Handle(isolate_); - String& url = String::Handle(isolate_); + Zone* zn = zone(); + Library& lib = Library::Handle(zn); + Script& script = Script::Handle(zn); + String& url = String::Handle(zn); BreakpointLocation* loc = latent_locations_; BreakpointLocation* prev_loc = NULL; const GrowableObjectArray& libs = @@ -3209,7 +3214,7 @@ BreakpointLocation* Debugger::GetLatentBreakpoint(const String& url, intptr_t line, intptr_t column) { BreakpointLocation* bpt = latent_locations_; - String& bpt_url = String::Handle(isolate_); + String& bpt_url = String::Handle(zone()); while (bpt != NULL) { bpt_url = bpt->url(); if (bpt_url.Equals(url) && diff --git a/runtime/vm/debugger.h b/runtime/vm/debugger.h index 7c4cb8a3436..a9d05472811 100644 --- a/runtime/vm/debugger.h +++ b/runtime/vm/debugger.h @@ -626,7 +626,7 @@ class Debugger { const Code& code, const Array& deopt_frame, intptr_t deopt_frame_offset); - static RawArray* DeoptimizeToArray(Isolate* isolate, + static RawArray* DeoptimizeToArray(Thread* thread, StackFrame* frame, const Code& code); static DebuggerStackTrace* CollectStackTrace(); @@ -650,6 +650,8 @@ class Debugger { void HandleSteppingRequest(DebuggerStackTrace* stack_trace); + Zone* zone() const { return isolate_->current_zone(); } + Isolate* isolate_; Dart_Port isolate_id_; // A unique ID for the isolate in the debugger. bool initialized_; diff --git a/runtime/vm/exceptions.cc b/runtime/vm/exceptions.cc index 8230ac7f8a4..d5d4b3938b2 100644 --- a/runtime/vm/exceptions.cc +++ b/runtime/vm/exceptions.cc @@ -37,11 +37,11 @@ class StacktraceBuilder : public ValueObject { class RegularStacktraceBuilder : public StacktraceBuilder { public: - explicit RegularStacktraceBuilder(Isolate* isolate) + explicit RegularStacktraceBuilder(Zone* zone) : code_list_( - GrowableObjectArray::Handle(isolate, GrowableObjectArray::New())), + GrowableObjectArray::Handle(zone, GrowableObjectArray::New())), pc_offset_list_( - GrowableObjectArray::Handle(isolate, GrowableObjectArray::New())) { } + GrowableObjectArray::Handle(zone, GrowableObjectArray::New())) { } ~RegularStacktraceBuilder() { } const GrowableObjectArray& code_list() const { return code_list_; } @@ -111,7 +111,7 @@ void PreallocatedStacktraceBuilder::AddFrame(const Code& code, } -static void BuildStackTrace(Isolate* isolate, StacktraceBuilder* builder) { +static void BuildStackTrace(StacktraceBuilder* builder) { StackFrameIterator frames(StackFrameIterator::kDontValidateFrames); StackFrame* frame = frames.NextFrame(); ASSERT(frame != NULL); // We expect to find a dart invocation frame. @@ -247,18 +247,20 @@ static RawField* LookupStacktraceField(const Instance& instance) { // 'class Error' is not a predefined class. return Field::null(); } - Isolate* isolate = Isolate::Current(); - Class& error_class = Class::Handle(isolate, + Thread* thread = Thread::Current(); + Zone* zone = thread->zone(); + Isolate* isolate = thread->isolate(); + Class& error_class = Class::Handle(zone, isolate->object_store()->error_class()); if (error_class.IsNull()) { - const Library& core_lib = Library::Handle(isolate, Library::CoreLibrary()); + const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); error_class = core_lib.LookupClass(Symbols::Error()); ASSERT(!error_class.IsNull()); isolate->object_store()->set_error_class(error_class); } // If instance class extends 'class Error' return '_stackTrace' field. - Class& test_class = Class::Handle(isolate, instance.clazz()); - AbstractType& type = AbstractType::Handle(isolate, AbstractType::null()); + Class& test_class = Class::Handle(zone, instance.clazz()); + AbstractType& type = AbstractType::Handle(zone, AbstractType::null()); while (true) { if (test_class.raw() == error_class.raw()) { return error_class.LookupInstanceField(Symbols::_stackTrace()); @@ -273,14 +275,14 @@ static RawField* LookupStacktraceField(const Instance& instance) { RawStacktrace* Exceptions::CurrentStacktrace() { - Isolate* isolate = Isolate::Current(); - RegularStacktraceBuilder frame_builder(isolate); - BuildStackTrace(isolate, &frame_builder); + Zone* zone = Thread::Current()->zone(); + RegularStacktraceBuilder frame_builder(zone); + BuildStackTrace(&frame_builder); // Create arrays for code and pc_offset tuples of each frame. - const Array& full_code_array = Array::Handle(isolate, + const Array& full_code_array = Array::Handle(zone, Array::MakeArray(frame_builder.code_list())); - const Array& full_pc_offset_array = Array::Handle(isolate, + const Array& full_pc_offset_array = Array::Handle(zone, Array::MakeArray(frame_builder.pc_offset_list())); const Stacktrace& full_stacktrace = Stacktrace::Handle( Stacktrace::New(full_code_array, full_pc_offset_array)); @@ -292,9 +294,10 @@ static void ThrowExceptionHelper(Thread* thread, const Instance& incoming_exception, const Instance& existing_stacktrace, const bool is_rethrow) { + Zone* zone = thread->zone(); Isolate* isolate = thread->isolate(); bool use_preallocated_stacktrace = false; - Instance& exception = Instance::Handle(isolate, incoming_exception.raw()); + Instance& exception = Instance::Handle(zone, incoming_exception.raw()); if (exception.IsNull()) { exception ^= Exceptions::Create(Exceptions::kNullThrown, Object::empty_array()); @@ -305,7 +308,7 @@ static void ThrowExceptionHelper(Thread* thread, uword handler_pc = 0; uword handler_sp = 0; uword handler_fp = 0; - Instance& stacktrace = Instance::Handle(isolate); + Instance& stacktrace = Instance::Handle(zone); bool handler_exists = false; bool handler_needs_stacktrace = false; if (use_preallocated_stacktrace) { @@ -317,13 +320,13 @@ static void ThrowExceptionHelper(Thread* thread, &handler_fp, &handler_needs_stacktrace); if (handler_needs_stacktrace) { - BuildStackTrace(isolate, &frame_builder); + BuildStackTrace(&frame_builder); } } else { // Get stacktrace field of class Error. This is needed to determine whether // we have a subclass of Error which carries around its stack trace. const Field& stacktrace_field = - Field::Handle(isolate, LookupStacktraceField(exception)); + Field::Handle(zone, LookupStacktraceField(exception)); // Find the exception handler and determine if the handler needs a // stacktrace. @@ -379,7 +382,7 @@ static void ThrowExceptionHelper(Thread* thread, // dart invocation sequence above it, print diagnostics and terminate // the isolate etc.). const UnhandledException& unhandled_exception = UnhandledException::Handle( - isolate, UnhandledException::New(exception, stacktrace)); + zone, UnhandledException::New(exception, stacktrace)); stacktrace = Stacktrace::null(); JumpToExceptionHandler(thread, handler_pc, @@ -485,7 +488,8 @@ void Exceptions::Throw(Thread* thread, const Instance& exception) { isolate->debugger()->SignalExceptionThrown(exception); } // Null object is a valid exception object. - ThrowExceptionHelper(thread, exception, Stacktrace::Handle(isolate), false); + ThrowExceptionHelper(thread, exception, + Stacktrace::Handle(thread->zone()), false); } void Exceptions::ReThrow(Thread* thread, @@ -499,13 +503,14 @@ void Exceptions::ReThrow(Thread* thread, void Exceptions::PropagateError(const Error& error) { Thread* thread = Thread::Current(); Isolate* isolate = thread->isolate(); + Zone* zone = thread->zone(); ASSERT(isolate->top_exit_frame_info() != 0); if (error.IsUnhandledException()) { // If the error object represents an unhandled exception, then // rethrow the exception in the normal fashion. const UnhandledException& uhe = UnhandledException::Cast(error); - const Instance& exc = Instance::Handle(isolate, uhe.exception()); - const Instance& stk = Instance::Handle(isolate, uhe.stacktrace()); + const Instance& exc = Instance::Handle(zone, uhe.exception()); + const Instance& stk = Instance::Handle(zone, uhe.stacktrace()); Exceptions::ReThrow(thread, exc, stk); } else { // Return to the invocation stub and return this error object. The @@ -516,7 +521,7 @@ void Exceptions::PropagateError(const Error& error) { uword handler_fp = 0; FindErrorHandler(&handler_pc, &handler_sp, &handler_fp); JumpToExceptionHandler(thread, handler_pc, handler_sp, handler_fp, error, - Stacktrace::Handle(isolate)); // Null stacktrace. + Stacktrace::Handle(zone)); // Null stacktrace. } UNREACHABLE(); } @@ -524,8 +529,8 @@ void Exceptions::PropagateError(const Error& error) { void Exceptions::ThrowByType(ExceptionType type, const Array& arguments) { Thread* thread = Thread::Current(); - Isolate* isolate = thread->isolate(); - const Object& result = Object::Handle(isolate, Create(type, arguments)); + const Object& result = + Object::Handle(thread->zone(), Create(type, arguments)); if (result.IsError()) { // We got an error while constructing the exception object. // Propagate the error instead of throwing the exception. @@ -541,7 +546,7 @@ void Exceptions::ThrowOOM() { Thread* thread = Thread::Current(); Isolate* isolate = thread->isolate(); const Instance& oom = Instance::Handle( - isolate, isolate->object_store()->out_of_memory()); + thread->zone(), isolate->object_store()->out_of_memory()); Throw(thread, oom); } @@ -550,7 +555,7 @@ void Exceptions::ThrowStackOverflow() { Thread* thread = Thread::Current(); Isolate* isolate = thread->isolate(); const Instance& stack_overflow = Instance::Handle( - isolate, isolate->object_store()->stack_overflow()); + thread->zone(), isolate->object_store()->stack_overflow()); Throw(thread, stack_overflow); }