OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 pending_classes.Add(cls); | 1129 pending_classes.Add(cls); |
1130 | 1130 |
1131 // Pre-register the isolate library so the native class implementations | 1131 // Pre-register the isolate library so the native class implementations |
1132 // can be hooked up before compiling it. | 1132 // can be hooked up before compiling it. |
1133 Library& isolate_lib = | 1133 Library& isolate_lib = |
1134 Library::Handle(isolate, Library::LookupLibrary(Symbols::DartIsolate())); | 1134 Library::Handle(isolate, Library::LookupLibrary(Symbols::DartIsolate())); |
1135 if (isolate_lib.IsNull()) { | 1135 if (isolate_lib.IsNull()) { |
1136 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); | 1136 isolate_lib = Library::NewLibraryHelper(Symbols::DartIsolate(), true); |
1137 isolate_lib.SetLoadRequested(); | 1137 isolate_lib.SetLoadRequested(); |
1138 isolate_lib.Register(); | 1138 isolate_lib.Register(); |
1139 isolate->object_store()->set_bootstrap_library(ObjectStore::kIsolate, | 1139 object_store->set_bootstrap_library(ObjectStore::kIsolate, isolate_lib); |
1140 isolate_lib); | |
1141 } | 1140 } |
1142 ASSERT(!isolate_lib.IsNull()); | 1141 ASSERT(!isolate_lib.IsNull()); |
1143 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); | 1142 ASSERT(isolate_lib.raw() == Library::IsolateLibrary()); |
1144 | 1143 |
1145 cls = Class::New<Capability>(); | 1144 cls = Class::New<Capability>(); |
1146 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); | 1145 RegisterPrivateClass(cls, Symbols::_CapabilityImpl(), isolate_lib); |
1147 pending_classes.Add(cls); | 1146 pending_classes.Add(cls); |
1148 | 1147 |
1149 cls = Class::New<ReceivePort>(); | 1148 cls = Class::New<ReceivePort>(); |
1150 RegisterPrivateClass(cls, Symbols::_RawReceivePortImpl(), isolate_lib); | 1149 RegisterPrivateClass(cls, Symbols::_RawReceivePortImpl(), isolate_lib); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 object_store->set_weak_property_class(cls); | 1251 object_store->set_weak_property_class(cls); |
1253 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); | 1252 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); |
1254 | 1253 |
1255 // Pre-register the mirrors library so we can place the vm class | 1254 // Pre-register the mirrors library so we can place the vm class |
1256 // MirrorReference there rather than the core library. | 1255 // MirrorReference there rather than the core library. |
1257 lib = Library::LookupLibrary(Symbols::DartMirrors()); | 1256 lib = Library::LookupLibrary(Symbols::DartMirrors()); |
1258 if (lib.IsNull()) { | 1257 if (lib.IsNull()) { |
1259 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); | 1258 lib = Library::NewLibraryHelper(Symbols::DartMirrors(), true); |
1260 lib.SetLoadRequested(); | 1259 lib.SetLoadRequested(); |
1261 lib.Register(); | 1260 lib.Register(); |
1262 isolate->object_store()->set_bootstrap_library(ObjectStore::kMirrors, | 1261 object_store->set_bootstrap_library(ObjectStore::kMirrors, lib); |
1263 lib); | |
1264 } | 1262 } |
1265 ASSERT(!lib.IsNull()); | 1263 ASSERT(!lib.IsNull()); |
1266 ASSERT(lib.raw() == Library::MirrorsLibrary()); | 1264 ASSERT(lib.raw() == Library::MirrorsLibrary()); |
1267 | 1265 |
1268 cls = Class::New<MirrorReference>(); | 1266 cls = Class::New<MirrorReference>(); |
1269 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); | 1267 RegisterPrivateClass(cls, Symbols::_MirrorReference(), lib); |
1270 | 1268 |
1271 // Pre-register the collection library so we can place the vm class | 1269 // Pre-register the collection library so we can place the vm class |
1272 // LinkedHashMap there rather than the core library. | 1270 // LinkedHashMap there rather than the core library. |
1273 lib = Library::LookupLibrary(Symbols::DartCollection()); | 1271 lib = Library::LookupLibrary(Symbols::DartCollection()); |
1274 if (lib.IsNull()) { | 1272 if (lib.IsNull()) { |
1275 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); | 1273 lib = Library::NewLibraryHelper(Symbols::DartCollection(), true); |
1276 lib.SetLoadRequested(); | 1274 lib.SetLoadRequested(); |
1277 lib.Register(); | 1275 lib.Register(); |
1278 isolate->object_store()->set_bootstrap_library(ObjectStore::kCollection, | 1276 object_store->set_bootstrap_library(ObjectStore::kCollection, lib); |
1279 lib); | |
1280 } | 1277 } |
1281 ASSERT(!lib.IsNull()); | 1278 ASSERT(!lib.IsNull()); |
1282 ASSERT(lib.raw() == Library::CollectionLibrary()); | 1279 ASSERT(lib.raw() == Library::CollectionLibrary()); |
1283 | 1280 |
1284 cls = Class::New<LinkedHashMap>(); | 1281 cls = Class::New<LinkedHashMap>(); |
1285 object_store->set_linked_hash_map_class(cls); | 1282 object_store->set_linked_hash_map_class(cls); |
1286 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); | 1283 cls.set_type_arguments_field_offset(LinkedHashMap::type_arguments_offset()); |
1287 cls.set_num_type_arguments(2); | 1284 cls.set_num_type_arguments(2); |
1288 cls.set_num_own_type_arguments(2); | 1285 cls.set_num_own_type_arguments(2); |
1289 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); | 1286 RegisterPrivateClass(cls, Symbols::_LinkedHashMap(), lib); |
1290 pending_classes.Add(cls); | 1287 pending_classes.Add(cls); |
1291 | 1288 |
1292 // Pre-register the profiler library so we can place the vm class | 1289 // Pre-register the profiler library so we can place the vm class |
1293 // UserTag there rather than the core library. | 1290 // UserTag there rather than the core library. |
1294 lib = Library::LookupLibrary(Symbols::DartProfiler()); | 1291 lib = Library::LookupLibrary(Symbols::DartProfiler()); |
1295 if (lib.IsNull()) { | 1292 if (lib.IsNull()) { |
1296 lib = Library::NewLibraryHelper(Symbols::DartProfiler(), true); | 1293 lib = Library::NewLibraryHelper(Symbols::DartProfiler(), true); |
1297 lib.SetLoadRequested(); | 1294 lib.SetLoadRequested(); |
1298 lib.Register(); | 1295 lib.Register(); |
1299 isolate->object_store()->set_bootstrap_library(ObjectStore::kProfiler, | 1296 object_store->set_bootstrap_library(ObjectStore::kProfiler, lib); |
1300 lib); | |
1301 } | 1297 } |
1302 ASSERT(!lib.IsNull()); | 1298 ASSERT(!lib.IsNull()); |
1303 ASSERT(lib.raw() == Library::ProfilerLibrary()); | 1299 ASSERT(lib.raw() == Library::ProfilerLibrary()); |
1304 | 1300 |
1305 lib = Library::LookupLibrary(Symbols::DartProfiler()); | 1301 lib = Library::LookupLibrary(Symbols::DartProfiler()); |
1306 ASSERT(!lib.IsNull()); | 1302 ASSERT(!lib.IsNull()); |
1307 cls = Class::New<UserTag>(); | 1303 cls = Class::New<UserTag>(); |
1308 RegisterPrivateClass(cls, Symbols::_UserTag(), lib); | 1304 RegisterPrivateClass(cls, Symbols::_UserTag(), lib); |
1309 pending_classes.Add(cls); | 1305 pending_classes.Add(cls); |
1310 | 1306 |
1311 // Setup some default native field classes which can be extended for | 1307 // Setup some default native field classes which can be extended for |
1312 // specifying native fields in dart classes. | 1308 // specifying native fields in dart classes. |
1313 Library::InitNativeWrappersLibrary(isolate); | 1309 Library::InitNativeWrappersLibrary(isolate); |
1314 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); | 1310 ASSERT(object_store->native_wrappers_library() != Library::null()); |
1315 | 1311 |
1316 // Pre-register the typed_data library so the native class implementations | 1312 // Pre-register the typed_data library so the native class implementations |
1317 // can be hooked up before compiling it. | 1313 // can be hooked up before compiling it. |
1318 lib = Library::LookupLibrary(Symbols::DartTypedData()); | 1314 lib = Library::LookupLibrary(Symbols::DartTypedData()); |
1319 if (lib.IsNull()) { | 1315 if (lib.IsNull()) { |
1320 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); | 1316 lib = Library::NewLibraryHelper(Symbols::DartTypedData(), true); |
1321 lib.SetLoadRequested(); | 1317 lib.SetLoadRequested(); |
1322 lib.Register(); | 1318 lib.Register(); |
1323 isolate->object_store()->set_bootstrap_library(ObjectStore::kTypedData, | 1319 object_store->set_bootstrap_library(ObjectStore::kTypedData, lib); |
1324 lib); | |
1325 } | 1320 } |
1326 ASSERT(!lib.IsNull()); | 1321 ASSERT(!lib.IsNull()); |
1327 ASSERT(lib.raw() == Library::TypedDataLibrary()); | 1322 ASSERT(lib.raw() == Library::TypedDataLibrary()); |
1328 #define REGISTER_TYPED_DATA_CLASS(clazz) \ | 1323 #define REGISTER_TYPED_DATA_CLASS(clazz) \ |
1329 cls = Class::NewTypedDataClass(kTypedData##clazz##Cid); \ | 1324 cls = Class::NewTypedDataClass(kTypedData##clazz##Cid); \ |
1330 RegisterPrivateClass(cls, Symbols::_##clazz(), lib); \ | 1325 RegisterPrivateClass(cls, Symbols::_##clazz(), lib); \ |
1331 | 1326 |
1332 CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS); | 1327 CLASS_LIST_TYPED_DATA(REGISTER_TYPED_DATA_CLASS); |
1333 #undef REGISTER_TYPED_DATA_CLASS | 1328 #undef REGISTER_TYPED_DATA_CLASS |
1334 #define REGISTER_TYPED_DATA_VIEW_CLASS(clazz) \ | 1329 #define REGISTER_TYPED_DATA_VIEW_CLASS(clazz) \ |
(...skipping 3766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5101 void Function::AttachCode(const Code& value) const { | 5096 void Function::AttachCode(const Code& value) const { |
5102 SetInstructions(value); | 5097 SetInstructions(value); |
5103 ASSERT(Function::Handle(value.function()).IsNull() || | 5098 ASSERT(Function::Handle(value.function()).IsNull() || |
5104 (value.function() == this->raw())); | 5099 (value.function() == this->raw())); |
5105 value.set_owner(*this); | 5100 value.set_owner(*this); |
5106 } | 5101 } |
5107 | 5102 |
5108 | 5103 |
5109 bool Function::HasCode() const { | 5104 bool Function::HasCode() const { |
5110 ASSERT(raw_ptr()->instructions_ != Instructions::null()); | 5105 ASSERT(raw_ptr()->instructions_ != Instructions::null()); |
| 5106 StubCode* stub_code = Isolate::Current()->stub_code(); |
5111 return raw_ptr()->instructions_ != | 5107 return raw_ptr()->instructions_ != |
5112 StubCode::LazyCompile_entry()->code()->ptr()->instructions_; | 5108 stub_code->LazyCompile_entry()->code()->ptr()->instructions_; |
5113 } | 5109 } |
5114 | 5110 |
5115 | 5111 |
5116 void Function::ClearCode() const { | 5112 void Function::ClearCode() const { |
5117 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); | 5113 StorePointer(&raw_ptr()->unoptimized_code_, Code::null()); |
| 5114 StubCode* stub_code = Isolate::Current()->stub_code(); |
5118 StorePointer(&raw_ptr()->instructions_, | 5115 StorePointer(&raw_ptr()->instructions_, |
5119 Code::Handle(StubCode::LazyCompile_entry()->code()).instructions()); | 5116 Code::Handle(stub_code->LazyCompile_entry()->code()).instructions()); |
5120 } | 5117 } |
5121 | 5118 |
5122 | 5119 |
5123 void Function::SwitchToUnoptimizedCode() const { | 5120 void Function::SwitchToUnoptimizedCode() const { |
5124 ASSERT(HasOptimizedCode()); | 5121 ASSERT(HasOptimizedCode()); |
5125 const Code& current_code = Code::Handle(CurrentCode()); | 5122 const Code& current_code = Code::Handle(CurrentCode()); |
5126 | 5123 |
5127 if (FLAG_trace_disabling_optimized_code) { | 5124 if (FLAG_trace_disabling_optimized_code) { |
5128 OS::Print("Disabling optimized code: '%s' entry: %#" Px "\n", | 5125 OS::Print("Disabling optimized code: '%s' entry: %#" Px "\n", |
5129 ToFullyQualifiedCString(), | 5126 ToFullyQualifiedCString(), |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6123 result.set_num_fixed_parameters(0); | 6120 result.set_num_fixed_parameters(0); |
6124 result.set_num_optional_parameters(0); | 6121 result.set_num_optional_parameters(0); |
6125 result.set_usage_counter(0); | 6122 result.set_usage_counter(0); |
6126 result.set_deoptimization_counter(0); | 6123 result.set_deoptimization_counter(0); |
6127 result.set_optimized_instruction_count(0); | 6124 result.set_optimized_instruction_count(0); |
6128 result.set_optimized_call_site_count(0); | 6125 result.set_optimized_call_site_count(0); |
6129 result.set_is_optimizable(is_native ? false : true); | 6126 result.set_is_optimizable(is_native ? false : true); |
6130 result.set_is_inlinable(true); | 6127 result.set_is_inlinable(true); |
6131 result.set_allows_hoisting_check_class(true); | 6128 result.set_allows_hoisting_check_class(true); |
6132 result.set_allows_bounds_check_generalization(true); | 6129 result.set_allows_bounds_check_generalization(true); |
6133 result.SetInstructions(Code::Handle(StubCode::LazyCompile_entry()->code())); | 6130 StubCode* stub_code = Isolate::Current()->stub_code(); |
| 6131 result.SetInstructions(Code::Handle(stub_code->LazyCompile_entry()->code())); |
6134 if (kind == RawFunction::kClosureFunction) { | 6132 if (kind == RawFunction::kClosureFunction) { |
6135 const ClosureData& data = ClosureData::Handle(ClosureData::New()); | 6133 const ClosureData& data = ClosureData::Handle(ClosureData::New()); |
6136 result.set_data(data); | 6134 result.set_data(data); |
6137 } | 6135 } |
6138 | 6136 |
6139 return result.raw(); | 6137 return result.raw(); |
6140 } | 6138 } |
6141 | 6139 |
6142 | 6140 |
6143 RawFunction* Function::Clone(const Class& new_owner) const { | 6141 RawFunction* Function::Clone(const Class& new_owner) const { |
(...skipping 6294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12438 } | 12436 } |
12439 Context& result = Context::Handle(); | 12437 Context& result = Context::Handle(); |
12440 { | 12438 { |
12441 RawObject* raw = Object::Allocate(Context::kClassId, | 12439 RawObject* raw = Object::Allocate(Context::kClassId, |
12442 Context::InstanceSize(num_variables), | 12440 Context::InstanceSize(num_variables), |
12443 space); | 12441 space); |
12444 NoGCScope no_gc; | 12442 NoGCScope no_gc; |
12445 result ^= raw; | 12443 result ^= raw; |
12446 result.set_num_variables(num_variables); | 12444 result.set_num_variables(num_variables); |
12447 } | 12445 } |
12448 result.set_isolate(Isolate::Current()); | |
12449 return result.raw(); | 12446 return result.raw(); |
12450 } | 12447 } |
12451 | 12448 |
12452 | 12449 |
12453 const char* Context::ToCString() const { | 12450 const char* Context::ToCString() const { |
12454 if (IsNull()) { | 12451 if (IsNull()) { |
12455 return "Context (Null)"; | 12452 return "Context (Null)"; |
12456 } | 12453 } |
12457 Zone* zone = Isolate::Current()->current_zone(); | 12454 Zone* zone = Isolate::Current()->current_zone(); |
12458 const Context& parent_ctx = Context::Handle(parent()); | 12455 const Context& parent_ctx = Context::Handle(parent()); |
(...skipping 7231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
19690 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; | 19687 intptr_t len = OS::SNPrint(NULL, 0, format, fun_sig, from, fun_desc) + 1; |
19691 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 19688 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
19692 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc); | 19689 OS::SNPrint(chars, len, format, fun_sig, from, fun_desc); |
19693 return chars; | 19690 return chars; |
19694 } | 19691 } |
19695 | 19692 |
19696 | 19693 |
19697 RawInstance* Closure::New(const Function& function, | 19694 RawInstance* Closure::New(const Function& function, |
19698 const Context& context, | 19695 const Context& context, |
19699 Heap::Space space) { | 19696 Heap::Space space) { |
19700 Isolate* isolate = Isolate::Current(); | |
19701 ASSERT(context.isolate() == isolate); | |
19702 | |
19703 const Class& cls = Class::Handle(function.signature_class()); | 19697 const Class& cls = Class::Handle(function.signature_class()); |
19704 ASSERT(cls.instance_size() == Closure::InstanceSize()); | 19698 ASSERT(cls.instance_size() == Closure::InstanceSize()); |
19705 Instance& result = Instance::Handle(); | 19699 Instance& result = Instance::Handle(); |
19706 { | 19700 { |
19707 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); | 19701 RawObject* raw = Object::Allocate(cls.id(), Closure::InstanceSize(), space); |
19708 NoGCScope no_gc; | 19702 NoGCScope no_gc; |
19709 result ^= raw; | 19703 result ^= raw; |
19710 } | 19704 } |
19711 Closure::set_function(result, function); | 19705 Closure::set_function(result, function); |
19712 Closure::set_context(result, context); | 19706 Closure::set_context(result, context); |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20317 return tag_label.ToCString(); | 20311 return tag_label.ToCString(); |
20318 } | 20312 } |
20319 | 20313 |
20320 | 20314 |
20321 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20315 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20322 Instance::PrintJSONImpl(stream, ref); | 20316 Instance::PrintJSONImpl(stream, ref); |
20323 } | 20317 } |
20324 | 20318 |
20325 | 20319 |
20326 } // namespace dart | 20320 } // namespace dart |
OLD | NEW |