Chromium Code Reviews| 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 "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| 11 #include "vm/code_generator.h" | 11 #include "vm/code_generator.h" |
| 12 #include "vm/code_index_table.h" | 12 #include "vm/code_index_table.h" |
| 13 #include "vm/code_patcher.h" | 13 #include "vm/code_patcher.h" |
| 14 #include "vm/compiler.h" | 14 #include "vm/compiler.h" |
| 15 #include "vm/compiler_stats.h" | 15 #include "vm/compiler_stats.h" |
| 16 #include "vm/class_finalizer.h" | 16 #include "vm/class_finalizer.h" |
| 17 #include "vm/dart.h" | 17 #include "vm/dart.h" |
| 18 #include "vm/dart_api_state.h" | |
| 18 #include "vm/dart_entry.h" | 19 #include "vm/dart_entry.h" |
| 19 #include "vm/debuginfo.h" | 20 #include "vm/debuginfo.h" |
| 20 #include "vm/exceptions.h" | 21 #include "vm/exceptions.h" |
| 21 #include "vm/growable_array.h" | 22 #include "vm/growable_array.h" |
| 22 #include "vm/heap.h" | 23 #include "vm/heap.h" |
| 23 #include "vm/ic_data.h" | 24 #include "vm/ic_data.h" |
| 24 #include "vm/object_store.h" | 25 #include "vm/object_store.h" |
| 25 #include "vm/parser.h" | 26 #include "vm/parser.h" |
| 26 #include "vm/runtime_entry.h" | 27 #include "vm/runtime_entry.h" |
| 27 #include "vm/scopes.h" | 28 #include "vm/scopes.h" |
| (...skipping 6511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6539 result ^= FourByteString::New(len, space); | 6540 result ^= FourByteString::New(len, space); |
| 6540 } | 6541 } |
| 6541 String::Copy(result, 0, str, 0, len); | 6542 String::Copy(result, 0, str, 0, len); |
| 6542 return result.raw(); | 6543 return result.raw(); |
| 6543 } | 6544 } |
| 6544 | 6545 |
| 6545 | 6546 |
| 6546 RawString* String::NewExternal(const uint8_t* characters, | 6547 RawString* String::NewExternal(const uint8_t* characters, |
| 6547 intptr_t len, | 6548 intptr_t len, |
| 6548 void* peer, | 6549 void* peer, |
| 6549 PeerFinalizer callback, | 6550 Dart_PeerFinalizer callback, |
| 6550 Heap::Space space) { | 6551 Heap::Space space) { |
| 6551 return ExternalOneByteString::New(characters, len, peer, callback, space); | 6552 return ExternalOneByteString::New(characters, len, peer, callback, space); |
| 6552 } | 6553 } |
| 6553 | 6554 |
| 6554 | 6555 |
| 6555 RawString* String::NewExternal(const uint16_t* characters, | 6556 RawString* String::NewExternal(const uint16_t* characters, |
| 6556 intptr_t len, | 6557 intptr_t len, |
| 6557 void* peer, | 6558 void* peer, |
| 6558 PeerFinalizer callback, | 6559 Dart_PeerFinalizer callback, |
| 6559 Heap::Space space) { | 6560 Heap::Space space) { |
| 6560 return ExternalTwoByteString::New(characters, len, peer, callback, space); | 6561 return ExternalTwoByteString::New(characters, len, peer, callback, space); |
| 6561 } | 6562 } |
| 6562 | 6563 |
| 6563 | 6564 |
| 6564 RawString* String::NewExternal(const uint32_t* characters, | 6565 RawString* String::NewExternal(const uint32_t* characters, |
| 6565 intptr_t len, | 6566 intptr_t len, |
| 6566 void* peer, | 6567 void* peer, |
| 6567 PeerFinalizer callback, | 6568 Dart_PeerFinalizer callback, |
| 6568 Heap::Space space) { | 6569 Heap::Space space) { |
| 6569 return ExternalFourByteString::New(characters, len, peer, callback, space); | 6570 return ExternalFourByteString::New(characters, len, peer, callback, space); |
| 6570 } | 6571 } |
| 6571 | 6572 |
| 6572 | 6573 |
| 6573 void String::Copy(const String& dst, intptr_t dst_offset, | 6574 void String::Copy(const String& dst, intptr_t dst_offset, |
| 6574 const uint8_t* characters, | 6575 const uint8_t* characters, |
| 6575 intptr_t len) { | 6576 intptr_t len) { |
| 6576 ASSERT(dst_offset >= 0); | 6577 ASSERT(dst_offset >= 0); |
| 6577 ASSERT(len >= 0); | 6578 ASSERT(len >= 0); |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7324 } | 7325 } |
| 7325 return result.raw(); | 7326 return result.raw(); |
| 7326 } | 7327 } |
| 7327 | 7328 |
| 7328 | 7329 |
| 7329 const char* FourByteString::ToCString() const { | 7330 const char* FourByteString::ToCString() const { |
| 7330 return String::ToCString(); | 7331 return String::ToCString(); |
| 7331 } | 7332 } |
| 7332 | 7333 |
| 7333 | 7334 |
| 7334 RawExternalOneByteString* ExternalOneByteString::New(const uint8_t* data, | 7335 static void AddFinalizer(const Object& referent, |
| 7335 intptr_t len, | 7336 void* peer, |
| 7336 void* peer, | 7337 Dart_PeerFinalizer callback) { |
| 7337 PeerFinalizer callback, | 7338 ApiState* state = Isolate::Current()->api_state(); |
| 7338 Heap::Space space) { | 7339 ASSERT(state != NULL); |
| 7340 WeakPersistentHandle* weak_ref = | |
| 7341 state->weak_persistent_handles().AllocateHandle(); | |
| 7342 weak_ref->set_raw(referent); | |
| 7343 weak_ref->set_peer(peer); | |
| 7344 weak_ref->set_callback(callback); | |
|
siva
2012/02/11 03:00:58
As discussed offline we need a strategy to delete
cshapiro
2012/02/11 04:11:50
Yes, done. The strategy I chose was to add a new
| |
| 7345 } | |
| 7346 | |
| 7347 | |
| 7348 RawExternalOneByteString* ExternalOneByteString::New( | |
| 7349 const uint8_t* data, | |
| 7350 intptr_t len, | |
| 7351 void* peer, | |
| 7352 Dart_PeerFinalizer callback, | |
| 7353 Heap::Space space) { | |
| 7339 Isolate* isolate = Isolate::Current(); | 7354 Isolate* isolate = Isolate::Current(); |
| 7340 | 7355 |
| 7341 const Class& cls = | 7356 const Class& cls = |
| 7342 Class::Handle(isolate->object_store()->external_one_byte_string_class()); | 7357 Class::Handle(isolate->object_store()->external_one_byte_string_class()); |
| 7343 ExternalOneByteString& result = ExternalOneByteString::Handle(); | 7358 ExternalOneByteString& result = ExternalOneByteString::Handle(); |
| 7359 ExternalStringData<uint8_t>* external_data = | |
| 7360 new ExternalStringData<uint8_t>(data, peer, callback); | |
| 7344 { | 7361 { |
| 7345 ExternalStringData<uint8_t>* external_data = | |
| 7346 new ExternalStringData<uint8_t>(data, peer, callback); | |
| 7347 RawObject* raw = Object::Allocate(cls, | 7362 RawObject* raw = Object::Allocate(cls, |
| 7348 ExternalOneByteString::InstanceSize(), | 7363 ExternalOneByteString::InstanceSize(), |
| 7349 space); | 7364 space); |
| 7350 NoGCScope no_gc; | 7365 NoGCScope no_gc; |
| 7351 result ^= raw; | 7366 result ^= raw; |
| 7352 result.SetLength(len); | 7367 result.SetLength(len); |
| 7353 result.SetHash(0); | 7368 result.SetHash(0); |
| 7354 result.SetExternalData(external_data); | 7369 result.SetExternalData(external_data); |
| 7355 } | 7370 } |
| 7371 AddFinalizer(result, external_data, ExternalOneByteString::Finalize); | |
| 7356 return result.raw(); | 7372 return result.raw(); |
| 7357 } | 7373 } |
| 7358 | 7374 |
| 7359 | 7375 |
| 7376 void ExternalOneByteString::Finalize(Dart_Handle handle, void* peer) { | |
| 7377 ExternalStringData<uint8_t>* external_data = | |
| 7378 reinterpret_cast<ExternalStringData<uint8_t>*>(peer); | |
| 7379 external_data->Finalize(handle); | |
| 7380 delete external_data; | |
| 7381 } | |
| 7382 | |
| 7383 | |
| 7360 const char* ExternalOneByteString::ToCString() const { | 7384 const char* ExternalOneByteString::ToCString() const { |
| 7361 return String::ToCString(); | 7385 return String::ToCString(); |
| 7362 } | 7386 } |
| 7363 | 7387 |
| 7364 | 7388 |
| 7365 RawExternalTwoByteString* ExternalTwoByteString::New(const uint16_t* data, | 7389 RawExternalTwoByteString* ExternalTwoByteString::New( |
| 7366 intptr_t len, | 7390 const uint16_t* data, |
| 7367 void* peer, | 7391 intptr_t len, |
| 7368 PeerFinalizer callback, | 7392 void* peer, |
| 7369 Heap::Space space) { | 7393 Dart_PeerFinalizer callback, |
| 7394 Heap::Space space) { | |
| 7370 Isolate* isolate = Isolate::Current(); | 7395 Isolate* isolate = Isolate::Current(); |
| 7371 | 7396 |
| 7372 const Class& cls = | 7397 const Class& cls = |
| 7373 Class::Handle(isolate->object_store()->external_two_byte_string_class()); | 7398 Class::Handle(isolate->object_store()->external_two_byte_string_class()); |
| 7374 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); | 7399 ExternalTwoByteString& result = ExternalTwoByteString::Handle(); |
| 7400 ExternalStringData<uint16_t>* external_data = | |
| 7401 new ExternalStringData<uint16_t>(data, peer, callback); | |
| 7375 { | 7402 { |
| 7376 ExternalStringData<uint16_t>* external_data = | |
| 7377 new ExternalStringData<uint16_t>(data, peer, callback); | |
| 7378 RawObject* raw = Object::Allocate(cls, | 7403 RawObject* raw = Object::Allocate(cls, |
| 7379 ExternalTwoByteString::InstanceSize(), | 7404 ExternalTwoByteString::InstanceSize(), |
| 7380 space); | 7405 space); |
| 7381 NoGCScope no_gc; | 7406 NoGCScope no_gc; |
| 7382 result ^= raw; | 7407 result ^= raw; |
| 7383 result.SetLength(len); | 7408 result.SetLength(len); |
| 7384 result.SetHash(0); | 7409 result.SetHash(0); |
| 7385 result.SetExternalData(external_data); | 7410 result.SetExternalData(external_data); |
| 7386 } | 7411 } |
| 7412 AddFinalizer(result, external_data, ExternalTwoByteString::Finalize); | |
| 7387 return result.raw(); | 7413 return result.raw(); |
| 7388 } | 7414 } |
| 7389 | 7415 |
| 7390 | 7416 |
| 7417 void ExternalTwoByteString::Finalize(Dart_Handle handle, void* peer) { | |
| 7418 ExternalStringData<uint16_t>* external_data = | |
| 7419 reinterpret_cast<ExternalStringData<uint16_t>*>(peer); | |
| 7420 external_data->Finalize(handle); | |
| 7421 delete external_data; | |
| 7422 } | |
| 7423 | |
| 7424 | |
| 7391 const char* ExternalTwoByteString::ToCString() const { | 7425 const char* ExternalTwoByteString::ToCString() const { |
| 7392 return String::ToCString(); | 7426 return String::ToCString(); |
| 7393 } | 7427 } |
| 7394 | 7428 |
| 7395 | 7429 |
| 7396 RawExternalFourByteString* ExternalFourByteString::New(const uint32_t* data, | 7430 RawExternalFourByteString* ExternalFourByteString::New( |
| 7397 intptr_t len, | 7431 const uint32_t* data, |
| 7398 void* peer, | 7432 intptr_t len, |
| 7399 PeerFinalizer callback, | 7433 void* peer, |
| 7400 Heap::Space space) { | 7434 Dart_PeerFinalizer callback, |
| 7435 Heap::Space space) { | |
| 7401 Isolate* isolate = Isolate::Current(); | 7436 Isolate* isolate = Isolate::Current(); |
| 7402 | 7437 |
| 7403 const Class& cls = | 7438 const Class& cls = |
| 7404 Class::Handle(isolate->object_store()->external_four_byte_string_class()); | 7439 Class::Handle(isolate->object_store()->external_four_byte_string_class()); |
| 7405 ExternalFourByteString& result = ExternalFourByteString::Handle(); | 7440 ExternalFourByteString& result = ExternalFourByteString::Handle(); |
| 7441 ExternalStringData<uint32_t>* external_data = | |
| 7442 new ExternalStringData<uint32_t>(data, peer, callback); | |
| 7406 { | 7443 { |
| 7407 ExternalStringData<uint32_t>* external_data = | |
| 7408 new ExternalStringData<uint32_t>(data, peer, callback); | |
| 7409 RawObject* raw = Object::Allocate(cls, | 7444 RawObject* raw = Object::Allocate(cls, |
| 7410 ExternalFourByteString::InstanceSize(), | 7445 ExternalFourByteString::InstanceSize(), |
| 7411 space); | 7446 space); |
| 7412 NoGCScope no_gc; | 7447 NoGCScope no_gc; |
| 7413 result ^= raw; | 7448 result ^= raw; |
| 7414 result.SetLength(len); | 7449 result.SetLength(len); |
| 7415 result.SetHash(0); | 7450 result.SetHash(0); |
| 7416 result.SetExternalData(external_data); | 7451 result.SetExternalData(external_data); |
| 7417 } | 7452 } |
| 7453 AddFinalizer(result, external_data, ExternalFourByteString::Finalize); | |
| 7418 return result.raw(); | 7454 return result.raw(); |
| 7419 } | 7455 } |
| 7420 | 7456 |
| 7421 | 7457 |
| 7458 void ExternalFourByteString::Finalize(Dart_Handle handle, void* peer) { | |
| 7459 ExternalStringData<uint32_t>* external_data = | |
| 7460 reinterpret_cast<ExternalStringData<uint32_t>*>(peer); | |
| 7461 external_data->Finalize(handle); | |
| 7462 delete external_data; | |
| 7463 } | |
| 7464 | |
| 7465 | |
| 7422 const char* ExternalFourByteString::ToCString() const { | 7466 const char* ExternalFourByteString::ToCString() const { |
| 7423 return String::ToCString(); | 7467 return String::ToCString(); |
| 7424 } | 7468 } |
| 7425 | 7469 |
| 7426 | 7470 |
| 7427 RawBool* Bool::True() { | 7471 RawBool* Bool::True() { |
| 7428 return Isolate::Current()->object_store()->true_value(); | 7472 return Isolate::Current()->object_store()->true_value(); |
| 7429 } | 7473 } |
| 7430 | 7474 |
| 7431 | 7475 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7652 } | 7696 } |
| 7653 return result.raw(); | 7697 return result.raw(); |
| 7654 } | 7698 } |
| 7655 | 7699 |
| 7656 | 7700 |
| 7657 const char* InternalByteArray::ToCString() const { | 7701 const char* InternalByteArray::ToCString() const { |
| 7658 return "_InternalByteArray"; | 7702 return "_InternalByteArray"; |
| 7659 } | 7703 } |
| 7660 | 7704 |
| 7661 | 7705 |
| 7706 void ExternalByteArray::Finalize(Dart_Handle handle, void* peer) { | |
| 7707 ExternalByteArrayData* external_data = | |
| 7708 reinterpret_cast<ExternalByteArrayData*>(peer); | |
| 7709 external_data->Finalize(handle); | |
| 7710 delete external_data; | |
| 7711 } | |
| 7712 | |
| 7713 | |
| 7662 RawExternalByteArray* ExternalByteArray::New(uint8_t* data, | 7714 RawExternalByteArray* ExternalByteArray::New(uint8_t* data, |
| 7663 intptr_t len, | 7715 intptr_t len, |
| 7716 void* peer, | |
| 7717 Dart_PeerFinalizer callback, | |
| 7664 Heap::Space space) { | 7718 Heap::Space space) { |
| 7665 Isolate* isolate = Isolate::Current(); | 7719 Isolate* isolate = Isolate::Current(); |
| 7666 const Class& external_byte_array_class = | 7720 const Class& external_byte_array_class = |
| 7667 Class::Handle(isolate->object_store()->external_byte_array_class()); | 7721 Class::Handle(isolate->object_store()->external_byte_array_class()); |
| 7668 ExternalByteArray& result = ExternalByteArray::Handle(); | 7722 ExternalByteArray& result = ExternalByteArray::Handle(); |
| 7723 ExternalByteArrayData* external_data = | |
| 7724 new ExternalByteArrayData(data, peer, callback); | |
| 7669 { | 7725 { |
| 7670 RawObject* raw = Object::Allocate(external_byte_array_class, | 7726 RawObject* raw = Object::Allocate(external_byte_array_class, |
| 7671 ExternalByteArray::InstanceSize(), | 7727 ExternalByteArray::InstanceSize(), |
| 7672 space); | 7728 space); |
| 7673 NoGCScope no_gc; | 7729 NoGCScope no_gc; |
| 7674 result ^= raw; | 7730 result ^= raw; |
| 7675 result.SetLength(len); | 7731 result.SetLength(len); |
| 7676 result.SetData(data); | 7732 result.SetExternalData(external_data); |
| 7677 } | 7733 } |
| 7734 AddFinalizer(result, external_data, ExternalByteArray::Finalize); | |
| 7678 return result.raw(); | 7735 return result.raw(); |
| 7679 } | 7736 } |
| 7680 | 7737 |
| 7681 | 7738 |
| 7682 const char* ExternalByteArray::ToCString() const { | 7739 const char* ExternalByteArray::ToCString() const { |
| 7683 return "_ExternalByteArray"; | 7740 return "_ExternalByteArray"; |
| 7684 } | 7741 } |
| 7685 | 7742 |
| 7686 | 7743 |
| 7687 RawClosure* Closure::New(const Function& function, | 7744 RawClosure* Closure::New(const Function& function, |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7986 const String& str = String::Handle(pattern()); | 8043 const String& str = String::Handle(pattern()); |
| 7987 const char* format = "JSRegExp: pattern=%s flags=%s"; | 8044 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7988 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 8045 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7989 char* chars = reinterpret_cast<char*>( | 8046 char* chars = reinterpret_cast<char*>( |
| 7990 Isolate::Current()->current_zone()->Allocate(len + 1)); | 8047 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7991 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 8048 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7992 return chars; | 8049 return chars; |
| 7993 } | 8050 } |
| 7994 | 8051 |
| 7995 } // namespace dart | 8052 } // namespace dart |
| OLD | NEW |