| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } else if (value == '\\') { | 413 } else if (value == '\\') { |
| 414 return '\\'; | 414 return '\\'; |
| 415 } else if (value == '$') { | 415 } else if (value == '$') { |
| 416 return '$'; | 416 return '$'; |
| 417 } | 417 } |
| 418 UNREACHABLE(); | 418 UNREACHABLE(); |
| 419 return '\0'; | 419 return '\0'; |
| 420 } | 420 } |
| 421 | 421 |
| 422 | 422 |
| 423 static void DeleteWeakPersistentHandle(Dart_Isolate current_isolate, | |
| 424 Dart_WeakPersistentHandle handle) { | |
| 425 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); | |
| 426 ApiState* state = isolate->api_state(); | |
| 427 ASSERT(state != NULL); | |
| 428 FinalizablePersistentHandle* weak_ref = | |
| 429 reinterpret_cast<FinalizablePersistentHandle*>(handle); | |
| 430 ASSERT(state->IsValidWeakPersistentHandle(handle)); | |
| 431 state->weak_persistent_handles().FreeHandle(weak_ref); | |
| 432 } | |
| 433 | |
| 434 | |
| 435 void Object::InitOnce() { | 423 void Object::InitOnce() { |
| 436 // TODO(iposva): NoGCScope needs to be added here. | 424 // TODO(iposva): NoGCScope needs to be added here. |
| 437 ASSERT(class_class() == null_); | 425 ASSERT(class_class() == null_); |
| 438 // Initialize the static vtable values. | 426 // Initialize the static vtable values. |
| 439 { | 427 { |
| 440 Object fake_object; | 428 Object fake_object; |
| 441 Smi fake_smi; | 429 Smi fake_smi; |
| 442 Object::handle_vtable_ = fake_object.vtable(); | 430 Object::handle_vtable_ = fake_object.vtable(); |
| 443 Smi::handle_vtable_ = fake_smi.vtable(); | 431 Smi::handle_vtable_ = fake_smi.vtable(); |
| 444 } | 432 } |
| (...skipping 6301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6746 RawExternalTypedData* TokenStream::GetStream() const { | 6734 RawExternalTypedData* TokenStream::GetStream() const { |
| 6747 return raw_ptr()->stream_; | 6735 return raw_ptr()->stream_; |
| 6748 } | 6736 } |
| 6749 | 6737 |
| 6750 | 6738 |
| 6751 void TokenStream::SetStream(const ExternalTypedData& value) const { | 6739 void TokenStream::SetStream(const ExternalTypedData& value) const { |
| 6752 StorePointer(&raw_ptr()->stream_, value.raw()); | 6740 StorePointer(&raw_ptr()->stream_, value.raw()); |
| 6753 } | 6741 } |
| 6754 | 6742 |
| 6755 | 6743 |
| 6756 void TokenStream::DataFinalizer(Dart_Isolate isolate, | 6744 void TokenStream::DataFinalizer(void* isolate_callback_data, |
| 6757 Dart_WeakPersistentHandle handle, | 6745 Dart_WeakPersistentHandle handle, |
| 6758 void *peer) { | 6746 void *peer) { |
| 6759 ASSERT(peer != NULL); | 6747 ASSERT(peer != NULL); |
| 6760 ::free(peer); | 6748 ::free(peer); |
| 6761 DeleteWeakPersistentHandle(isolate, handle); | |
| 6762 } | 6749 } |
| 6763 | 6750 |
| 6764 | 6751 |
| 6765 RawString* TokenStream::PrivateKey() const { | 6752 RawString* TokenStream::PrivateKey() const { |
| 6766 return raw_ptr()->private_key_; | 6753 return raw_ptr()->private_key_; |
| 6767 } | 6754 } |
| 6768 | 6755 |
| 6769 | 6756 |
| 6770 void TokenStream::SetPrivateKey(const String& value) const { | 6757 void TokenStream::SetPrivateKey(const String& value) const { |
| 6771 StorePointer(&raw_ptr()->private_key_, value.raw()); | 6758 StorePointer(&raw_ptr()->private_key_, value.raw()); |
| (...skipping 9339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16111 Dart_PeerFinalizer cback) { | 16098 Dart_PeerFinalizer cback) { |
| 16112 ASSERT(!str.IsNull() && str.IsOneByteString()); | 16099 ASSERT(!str.IsNull() && str.IsOneByteString()); |
| 16113 ASSERT(peer != NULL); | 16100 ASSERT(peer != NULL); |
| 16114 ExternalStringData<uint8_t>* ext_data = | 16101 ExternalStringData<uint8_t>* ext_data = |
| 16115 new ExternalStringData<uint8_t>(NULL, peer, cback); | 16102 new ExternalStringData<uint8_t>(NULL, peer, cback); |
| 16116 AddFinalizer(str, ext_data, OneByteString::Finalize); | 16103 AddFinalizer(str, ext_data, OneByteString::Finalize); |
| 16117 Isolate::Current()->heap()->SetPeer(str.raw(), peer); | 16104 Isolate::Current()->heap()->SetPeer(str.raw(), peer); |
| 16118 } | 16105 } |
| 16119 | 16106 |
| 16120 | 16107 |
| 16121 void OneByteString::Finalize(Dart_Isolate isolate, | 16108 void OneByteString::Finalize(void* isolate_callback_data, |
| 16122 Dart_WeakPersistentHandle handle, | 16109 Dart_WeakPersistentHandle handle, |
| 16123 void* peer) { | 16110 void* peer) { |
| 16124 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | 16111 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 16125 DeleteWeakPersistentHandle(isolate, handle); | |
| 16126 } | 16112 } |
| 16127 | 16113 |
| 16128 | 16114 |
| 16129 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { | 16115 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { |
| 16130 intptr_t len = str.Length(); | 16116 intptr_t len = str.Length(); |
| 16131 if (len > 0) { | 16117 if (len > 0) { |
| 16132 intptr_t num_escapes = 0; | 16118 intptr_t num_escapes = 0; |
| 16133 for (intptr_t i = 0; i < len; i++) { | 16119 for (intptr_t i = 0; i < len; i++) { |
| 16134 if (IsSpecialCharacter(*CharAddr(str, i))) { | 16120 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 16135 num_escapes += 1; | 16121 num_escapes += 1; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16287 Dart_PeerFinalizer cback) { | 16273 Dart_PeerFinalizer cback) { |
| 16288 ASSERT(!str.IsNull() && str.IsTwoByteString()); | 16274 ASSERT(!str.IsNull() && str.IsTwoByteString()); |
| 16289 ASSERT(peer != NULL); | 16275 ASSERT(peer != NULL); |
| 16290 ExternalStringData<uint16_t>* ext_data = | 16276 ExternalStringData<uint16_t>* ext_data = |
| 16291 new ExternalStringData<uint16_t>(NULL, peer, cback); | 16277 new ExternalStringData<uint16_t>(NULL, peer, cback); |
| 16292 AddFinalizer(str, ext_data, TwoByteString::Finalize); | 16278 AddFinalizer(str, ext_data, TwoByteString::Finalize); |
| 16293 Isolate::Current()->heap()->SetPeer(str.raw(), peer); | 16279 Isolate::Current()->heap()->SetPeer(str.raw(), peer); |
| 16294 } | 16280 } |
| 16295 | 16281 |
| 16296 | 16282 |
| 16297 void TwoByteString::Finalize(Dart_Isolate isolate, | 16283 void TwoByteString::Finalize(void* isolate_callback_data, |
| 16298 Dart_WeakPersistentHandle handle, | 16284 Dart_WeakPersistentHandle handle, |
| 16299 void* peer) { | 16285 void* peer) { |
| 16300 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 16286 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 16301 DeleteWeakPersistentHandle(isolate, handle); | |
| 16302 } | 16287 } |
| 16303 | 16288 |
| 16304 | 16289 |
| 16305 RawExternalOneByteString* ExternalOneByteString::New( | 16290 RawExternalOneByteString* ExternalOneByteString::New( |
| 16306 const uint8_t* data, | 16291 const uint8_t* data, |
| 16307 intptr_t len, | 16292 intptr_t len, |
| 16308 void* peer, | 16293 void* peer, |
| 16309 Dart_PeerFinalizer callback, | 16294 Dart_PeerFinalizer callback, |
| 16310 Heap::Space space) { | 16295 Heap::Space space) { |
| 16311 ASSERT(Isolate::Current()->object_store()-> | 16296 ASSERT(Isolate::Current()->object_store()-> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 16326 result ^= raw; | 16311 result ^= raw; |
| 16327 result.SetLength(len); | 16312 result.SetLength(len); |
| 16328 result.SetHash(0); | 16313 result.SetHash(0); |
| 16329 SetExternalData(result, external_data); | 16314 SetExternalData(result, external_data); |
| 16330 } | 16315 } |
| 16331 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); | 16316 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); |
| 16332 return ExternalOneByteString::raw(result); | 16317 return ExternalOneByteString::raw(result); |
| 16333 } | 16318 } |
| 16334 | 16319 |
| 16335 | 16320 |
| 16336 void ExternalOneByteString::Finalize(Dart_Isolate isolate, | 16321 void ExternalOneByteString::Finalize(void* isolate_callback_data, |
| 16337 Dart_WeakPersistentHandle handle, | 16322 Dart_WeakPersistentHandle handle, |
| 16338 void* peer) { | 16323 void* peer) { |
| 16339 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | 16324 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 16340 DeleteWeakPersistentHandle(isolate, handle); | |
| 16341 } | 16325 } |
| 16342 | 16326 |
| 16343 | 16327 |
| 16344 RawExternalTwoByteString* ExternalTwoByteString::New( | 16328 RawExternalTwoByteString* ExternalTwoByteString::New( |
| 16345 const uint16_t* data, | 16329 const uint16_t* data, |
| 16346 intptr_t len, | 16330 intptr_t len, |
| 16347 void* peer, | 16331 void* peer, |
| 16348 Dart_PeerFinalizer callback, | 16332 Dart_PeerFinalizer callback, |
| 16349 Heap::Space space) { | 16333 Heap::Space space) { |
| 16350 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != | 16334 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != |
| (...skipping 14 matching lines...) Expand all Loading... |
| 16365 result ^= raw; | 16349 result ^= raw; |
| 16366 result.SetLength(len); | 16350 result.SetLength(len); |
| 16367 result.SetHash(0); | 16351 result.SetHash(0); |
| 16368 SetExternalData(result, external_data); | 16352 SetExternalData(result, external_data); |
| 16369 } | 16353 } |
| 16370 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); | 16354 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); |
| 16371 return ExternalTwoByteString::raw(result); | 16355 return ExternalTwoByteString::raw(result); |
| 16372 } | 16356 } |
| 16373 | 16357 |
| 16374 | 16358 |
| 16375 void ExternalTwoByteString::Finalize(Dart_Isolate isolate, | 16359 void ExternalTwoByteString::Finalize(void* isolate_callback_data, |
| 16376 Dart_WeakPersistentHandle handle, | 16360 Dart_WeakPersistentHandle handle, |
| 16377 void* peer) { | 16361 void* peer) { |
| 16378 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 16362 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 16379 DeleteWeakPersistentHandle(isolate, handle); | |
| 16380 } | 16363 } |
| 16381 | 16364 |
| 16382 | 16365 |
| 16383 RawBool* Bool::New(bool value) { | 16366 RawBool* Bool::New(bool value) { |
| 16384 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); | 16367 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); |
| 16385 Bool& result = Bool::Handle(); | 16368 Bool& result = Bool::Handle(); |
| 16386 { | 16369 { |
| 16387 // Since the two boolean instances are singletons we allocate them straight | 16370 // Since the two boolean instances are singletons we allocate them straight |
| 16388 // in the old generation. | 16371 // in the old generation. |
| 16389 RawObject* raw = Object::Allocate(Bool::kClassId, | 16372 RawObject* raw = Object::Allocate(Bool::kClassId, |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17708 return "_MirrorReference"; | 17691 return "_MirrorReference"; |
| 17709 } | 17692 } |
| 17710 | 17693 |
| 17711 | 17694 |
| 17712 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17695 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17713 Instance::PrintToJSONStream(stream, ref); | 17696 Instance::PrintToJSONStream(stream, ref); |
| 17714 } | 17697 } |
| 17715 | 17698 |
| 17716 | 17699 |
| 17717 } // namespace dart | 17700 } // namespace dart |
| OLD | NEW |