| 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 6469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6914 RawExternalTypedData* TokenStream::GetStream() const { | 6902 RawExternalTypedData* TokenStream::GetStream() const { |
| 6915 return raw_ptr()->stream_; | 6903 return raw_ptr()->stream_; |
| 6916 } | 6904 } |
| 6917 | 6905 |
| 6918 | 6906 |
| 6919 void TokenStream::SetStream(const ExternalTypedData& value) const { | 6907 void TokenStream::SetStream(const ExternalTypedData& value) const { |
| 6920 StorePointer(&raw_ptr()->stream_, value.raw()); | 6908 StorePointer(&raw_ptr()->stream_, value.raw()); |
| 6921 } | 6909 } |
| 6922 | 6910 |
| 6923 | 6911 |
| 6924 void TokenStream::DataFinalizer(Dart_Isolate isolate, | 6912 void TokenStream::DataFinalizer(void* isolate_callback_data, |
| 6925 Dart_WeakPersistentHandle handle, | 6913 Dart_WeakPersistentHandle handle, |
| 6926 void *peer) { | 6914 void *peer) { |
| 6927 ASSERT(peer != NULL); | 6915 ASSERT(peer != NULL); |
| 6928 ::free(peer); | 6916 ::free(peer); |
| 6929 DeleteWeakPersistentHandle(isolate, handle); | |
| 6930 } | 6917 } |
| 6931 | 6918 |
| 6932 | 6919 |
| 6933 RawString* TokenStream::PrivateKey() const { | 6920 RawString* TokenStream::PrivateKey() const { |
| 6934 return raw_ptr()->private_key_; | 6921 return raw_ptr()->private_key_; |
| 6935 } | 6922 } |
| 6936 | 6923 |
| 6937 | 6924 |
| 6938 void TokenStream::SetPrivateKey(const String& value) const { | 6925 void TokenStream::SetPrivateKey(const String& value) const { |
| 6939 StorePointer(&raw_ptr()->private_key_, value.raw()); | 6926 StorePointer(&raw_ptr()->private_key_, value.raw()); |
| (...skipping 9418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16358 Dart_PeerFinalizer cback) { | 16345 Dart_PeerFinalizer cback) { |
| 16359 ASSERT(!str.IsNull() && str.IsOneByteString()); | 16346 ASSERT(!str.IsNull() && str.IsOneByteString()); |
| 16360 ASSERT(peer != NULL); | 16347 ASSERT(peer != NULL); |
| 16361 ExternalStringData<uint8_t>* ext_data = | 16348 ExternalStringData<uint8_t>* ext_data = |
| 16362 new ExternalStringData<uint8_t>(NULL, peer, cback); | 16349 new ExternalStringData<uint8_t>(NULL, peer, cback); |
| 16363 AddFinalizer(str, ext_data, OneByteString::Finalize); | 16350 AddFinalizer(str, ext_data, OneByteString::Finalize); |
| 16364 Isolate::Current()->heap()->SetPeer(str.raw(), peer); | 16351 Isolate::Current()->heap()->SetPeer(str.raw(), peer); |
| 16365 } | 16352 } |
| 16366 | 16353 |
| 16367 | 16354 |
| 16368 void OneByteString::Finalize(Dart_Isolate isolate, | 16355 void OneByteString::Finalize(void* isolate_callback_data, |
| 16369 Dart_WeakPersistentHandle handle, | 16356 Dart_WeakPersistentHandle handle, |
| 16370 void* peer) { | 16357 void* peer) { |
| 16371 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | 16358 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 16372 DeleteWeakPersistentHandle(isolate, handle); | |
| 16373 } | 16359 } |
| 16374 | 16360 |
| 16375 | 16361 |
| 16376 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { | 16362 RawTwoByteString* TwoByteString::EscapeSpecialCharacters(const String& str) { |
| 16377 intptr_t len = str.Length(); | 16363 intptr_t len = str.Length(); |
| 16378 if (len > 0) { | 16364 if (len > 0) { |
| 16379 intptr_t num_escapes = 0; | 16365 intptr_t num_escapes = 0; |
| 16380 for (intptr_t i = 0; i < len; i++) { | 16366 for (intptr_t i = 0; i < len; i++) { |
| 16381 if (IsSpecialCharacter(*CharAddr(str, i))) { | 16367 if (IsSpecialCharacter(*CharAddr(str, i))) { |
| 16382 num_escapes += 1; | 16368 num_escapes += 1; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16534 Dart_PeerFinalizer cback) { | 16520 Dart_PeerFinalizer cback) { |
| 16535 ASSERT(!str.IsNull() && str.IsTwoByteString()); | 16521 ASSERT(!str.IsNull() && str.IsTwoByteString()); |
| 16536 ASSERT(peer != NULL); | 16522 ASSERT(peer != NULL); |
| 16537 ExternalStringData<uint16_t>* ext_data = | 16523 ExternalStringData<uint16_t>* ext_data = |
| 16538 new ExternalStringData<uint16_t>(NULL, peer, cback); | 16524 new ExternalStringData<uint16_t>(NULL, peer, cback); |
| 16539 AddFinalizer(str, ext_data, TwoByteString::Finalize); | 16525 AddFinalizer(str, ext_data, TwoByteString::Finalize); |
| 16540 Isolate::Current()->heap()->SetPeer(str.raw(), peer); | 16526 Isolate::Current()->heap()->SetPeer(str.raw(), peer); |
| 16541 } | 16527 } |
| 16542 | 16528 |
| 16543 | 16529 |
| 16544 void TwoByteString::Finalize(Dart_Isolate isolate, | 16530 void TwoByteString::Finalize(void* isolate_callback_data, |
| 16545 Dart_WeakPersistentHandle handle, | 16531 Dart_WeakPersistentHandle handle, |
| 16546 void* peer) { | 16532 void* peer) { |
| 16547 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 16533 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 16548 DeleteWeakPersistentHandle(isolate, handle); | |
| 16549 } | 16534 } |
| 16550 | 16535 |
| 16551 | 16536 |
| 16552 RawExternalOneByteString* ExternalOneByteString::New( | 16537 RawExternalOneByteString* ExternalOneByteString::New( |
| 16553 const uint8_t* data, | 16538 const uint8_t* data, |
| 16554 intptr_t len, | 16539 intptr_t len, |
| 16555 void* peer, | 16540 void* peer, |
| 16556 Dart_PeerFinalizer callback, | 16541 Dart_PeerFinalizer callback, |
| 16557 Heap::Space space) { | 16542 Heap::Space space) { |
| 16558 ASSERT(Isolate::Current()->object_store()-> | 16543 ASSERT(Isolate::Current()->object_store()-> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 16573 result ^= raw; | 16558 result ^= raw; |
| 16574 result.SetLength(len); | 16559 result.SetLength(len); |
| 16575 result.SetHash(0); | 16560 result.SetHash(0); |
| 16576 SetExternalData(result, external_data); | 16561 SetExternalData(result, external_data); |
| 16577 } | 16562 } |
| 16578 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); | 16563 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); |
| 16579 return ExternalOneByteString::raw(result); | 16564 return ExternalOneByteString::raw(result); |
| 16580 } | 16565 } |
| 16581 | 16566 |
| 16582 | 16567 |
| 16583 void ExternalOneByteString::Finalize(Dart_Isolate isolate, | 16568 void ExternalOneByteString::Finalize(void* isolate_callback_data, |
| 16584 Dart_WeakPersistentHandle handle, | 16569 Dart_WeakPersistentHandle handle, |
| 16585 void* peer) { | 16570 void* peer) { |
| 16586 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | 16571 delete reinterpret_cast<ExternalStringData<uint8_t>*>(peer); |
| 16587 DeleteWeakPersistentHandle(isolate, handle); | |
| 16588 } | 16572 } |
| 16589 | 16573 |
| 16590 | 16574 |
| 16591 RawExternalTwoByteString* ExternalTwoByteString::New( | 16575 RawExternalTwoByteString* ExternalTwoByteString::New( |
| 16592 const uint16_t* data, | 16576 const uint16_t* data, |
| 16593 intptr_t len, | 16577 intptr_t len, |
| 16594 void* peer, | 16578 void* peer, |
| 16595 Dart_PeerFinalizer callback, | 16579 Dart_PeerFinalizer callback, |
| 16596 Heap::Space space) { | 16580 Heap::Space space) { |
| 16597 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != | 16581 ASSERT(Isolate::Current()->object_store()->external_two_byte_string_class() != |
| (...skipping 14 matching lines...) Expand all Loading... |
| 16612 result ^= raw; | 16596 result ^= raw; |
| 16613 result.SetLength(len); | 16597 result.SetLength(len); |
| 16614 result.SetHash(0); | 16598 result.SetHash(0); |
| 16615 SetExternalData(result, external_data); | 16599 SetExternalData(result, external_data); |
| 16616 } | 16600 } |
| 16617 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); | 16601 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); |
| 16618 return ExternalTwoByteString::raw(result); | 16602 return ExternalTwoByteString::raw(result); |
| 16619 } | 16603 } |
| 16620 | 16604 |
| 16621 | 16605 |
| 16622 void ExternalTwoByteString::Finalize(Dart_Isolate isolate, | 16606 void ExternalTwoByteString::Finalize(void* isolate_callback_data, |
| 16623 Dart_WeakPersistentHandle handle, | 16607 Dart_WeakPersistentHandle handle, |
| 16624 void* peer) { | 16608 void* peer) { |
| 16625 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | 16609 delete reinterpret_cast<ExternalStringData<uint16_t>*>(peer); |
| 16626 DeleteWeakPersistentHandle(isolate, handle); | |
| 16627 } | 16610 } |
| 16628 | 16611 |
| 16629 | 16612 |
| 16630 RawBool* Bool::New(bool value) { | 16613 RawBool* Bool::New(bool value) { |
| 16631 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); | 16614 ASSERT(Isolate::Current()->object_store()->bool_class() != Class::null()); |
| 16632 Bool& result = Bool::Handle(); | 16615 Bool& result = Bool::Handle(); |
| 16633 { | 16616 { |
| 16634 // Since the two boolean instances are singletons we allocate them straight | 16617 // Since the two boolean instances are singletons we allocate them straight |
| 16635 // in the old generation. | 16618 // in the old generation. |
| 16636 RawObject* raw = Object::Allocate(Bool::kClassId, | 16619 RawObject* raw = Object::Allocate(Bool::kClassId, |
| (...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17955 return "_MirrorReference"; | 17938 return "_MirrorReference"; |
| 17956 } | 17939 } |
| 17957 | 17940 |
| 17958 | 17941 |
| 17959 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17942 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17960 Instance::PrintToJSONStream(stream, ref); | 17943 Instance::PrintToJSONStream(stream, ref); |
| 17961 } | 17944 } |
| 17962 | 17945 |
| 17963 | 17946 |
| 17964 } // namespace dart | 17947 } // namespace dart |
| OLD | NEW |