| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "vm/runtime_entry.h" | 26 #include "vm/runtime_entry.h" |
| 27 #include "vm/scopes.h" | 27 #include "vm/scopes.h" |
| 28 #include "vm/timer.h" | 28 #include "vm/timer.h" |
| 29 #include "vm/unicode.h" | 29 #include "vm/unicode.h" |
| 30 | 30 |
| 31 namespace dart { | 31 namespace dart { |
| 32 | 32 |
| 33 DEFINE_FLAG(bool, generate_gdb_symbols, false, | 33 DEFINE_FLAG(bool, generate_gdb_symbols, false, |
| 34 "Generate symbols of generated dart functions for debugging with GDB"); | 34 "Generate symbols of generated dart functions for debugging with GDB"); |
| 35 | 35 |
| 36 static const char* kGetterPrefix = "get:"; |
| 37 static const intptr_t kGetterPrefixLength = strlen(kGetterPrefix); |
| 38 static const char* kSetterPrefix = "set:"; |
| 39 static const intptr_t kSetterPrefixLength = strlen(kSetterPrefix); |
| 40 |
| 36 cpp_vtable Object::handle_vtable_ = 0; | 41 cpp_vtable Object::handle_vtable_ = 0; |
| 37 cpp_vtable Smi::handle_vtable_ = 0; | 42 cpp_vtable Smi::handle_vtable_ = 0; |
| 38 | 43 |
| 39 // These are initialized to a value that will force a illegal memory access if | 44 // These are initialized to a value that will force a illegal memory access if |
| 40 // they are being used. | 45 // they are being used. |
| 41 #if defined(RAW_NULL) | 46 #if defined(RAW_NULL) |
| 42 #error RAW_NULL should not be defined. | 47 #error RAW_NULL should not be defined. |
| 43 #endif | 48 #endif |
| 44 #define RAW_NULL kHeapObjectTag | 49 #define RAW_NULL kHeapObjectTag |
| 45 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); | 50 RawObject* Object::null_ = reinterpret_cast<RawInstance*>(RAW_NULL); |
| (...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 RawFunction* Class::LookupFactory(const String& name) const { | 1514 RawFunction* Class::LookupFactory(const String& name) const { |
| 1510 Function& function = Function::Handle(LookupFunction(name)); | 1515 Function& function = Function::Handle(LookupFunction(name)); |
| 1511 if (function.IsNull() || !function.IsFactory()) { | 1516 if (function.IsNull() || !function.IsFactory()) { |
| 1512 return Function::null(); | 1517 return Function::null(); |
| 1513 } | 1518 } |
| 1514 ASSERT(function.is_static()); | 1519 ASSERT(function.is_static()); |
| 1515 return function.raw(); | 1520 return function.raw(); |
| 1516 } | 1521 } |
| 1517 | 1522 |
| 1518 | 1523 |
| 1524 static bool MatchesAccessorName(const String& name, |
| 1525 const char* prefix, |
| 1526 intptr_t prefix_length, |
| 1527 const String& accessor_name) { |
| 1528 intptr_t name_len = name.Length(); |
| 1529 intptr_t accessor_name_len = accessor_name.Length(); |
| 1530 |
| 1531 if (name_len != (accessor_name_len + prefix_length)) { |
| 1532 return false; |
| 1533 } |
| 1534 for (intptr_t i = 0; i < prefix_length; i++) { |
| 1535 if (name.CharAt(i) != prefix[i]) { |
| 1536 return false; |
| 1537 } |
| 1538 } |
| 1539 for (intptr_t i = 0, j = prefix_length; i < accessor_name_len; i++, j++) { |
| 1540 if (name.CharAt(j) != accessor_name.CharAt(i)) { |
| 1541 return false; |
| 1542 } |
| 1543 } |
| 1544 return true; |
| 1545 } |
| 1546 |
| 1547 |
| 1519 static bool MatchesPrivateName(const String& name, const String& private_name) { | 1548 static bool MatchesPrivateName(const String& name, const String& private_name) { |
| 1520 intptr_t name_len = name.Length(); | 1549 intptr_t name_len = name.Length(); |
| 1521 intptr_t private_len = private_name.Length(); | 1550 intptr_t private_len = private_name.Length(); |
| 1522 // The private_name must at least have room for the separator and one key | 1551 // The private_name must at least have room for the separator and one key |
| 1523 // character. | 1552 // character. |
| 1524 if ((name_len < (private_len + 2)) || (name_len == 0) || (private_len == 0)) { | 1553 if ((name_len < (private_len + 2)) || (name_len == 0) || (private_len == 0)) { |
| 1525 return false; | 1554 return false; |
| 1526 } | 1555 } |
| 1527 | 1556 |
| 1528 // Check for the private key separator. | 1557 // Check for the private key separator. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1551 if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) { | 1580 if (function_name.Equals(name) || MatchesPrivateName(function_name, name)) { |
| 1552 return function.raw(); | 1581 return function.raw(); |
| 1553 } | 1582 } |
| 1554 } | 1583 } |
| 1555 | 1584 |
| 1556 // No function found. | 1585 // No function found. |
| 1557 return Function::null(); | 1586 return Function::null(); |
| 1558 } | 1587 } |
| 1559 | 1588 |
| 1560 | 1589 |
| 1590 RawFunction* Class::LookupGetterFunction(const String& name) const { |
| 1591 return LookupAccessorFunction(kGetterPrefix, kGetterPrefixLength, name); |
| 1592 } |
| 1593 |
| 1594 |
| 1595 RawFunction* Class::LookupSetterFunction(const String& name) const { |
| 1596 return LookupAccessorFunction(kSetterPrefix, kSetterPrefixLength, name); |
| 1597 } |
| 1598 |
| 1599 |
| 1600 RawFunction* Class::LookupAccessorFunction(const char* prefix, |
| 1601 intptr_t prefix_length, |
| 1602 const String& name) const { |
| 1603 Isolate* isolate = Isolate::Current(); |
| 1604 Array& funcs = Array::Handle(isolate, functions()); |
| 1605 Function& function = Function::Handle(isolate, Function::null()); |
| 1606 String& function_name = String::Handle(isolate, String::null()); |
| 1607 intptr_t len = funcs.Length(); |
| 1608 for (intptr_t i = 0; i < len; i++) { |
| 1609 function ^= funcs.At(i); |
| 1610 function_name ^= function.name(); |
| 1611 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { |
| 1612 return function.raw(); |
| 1613 } |
| 1614 } |
| 1615 |
| 1616 // No function found. |
| 1617 return Function::null(); |
| 1618 } |
| 1619 |
| 1620 |
| 1561 RawFunction* Class::LookupFunctionAtToken(intptr_t token_index) const { | 1621 RawFunction* Class::LookupFunctionAtToken(intptr_t token_index) const { |
| 1562 // TODO(hausner): we can shortcut the negative case if we knew the | 1622 // TODO(hausner): we can shortcut the negative case if we knew the |
| 1563 // beginning and end token position of the class. | 1623 // beginning and end token position of the class. |
| 1564 Array& funcs = Array::Handle(functions()); | 1624 Array& funcs = Array::Handle(functions()); |
| 1565 Function& func = Function::Handle(); | 1625 Function& func = Function::Handle(); |
| 1566 intptr_t len = funcs.Length(); | 1626 intptr_t len = funcs.Length(); |
| 1567 for (intptr_t i = 0; i < len; i++) { | 1627 for (intptr_t i = 0; i < len; i++) { |
| 1568 func ^= funcs.At(i); | 1628 func ^= funcs.At(i); |
| 1569 if ((func.token_index() <= token_index) && | 1629 if ((func.token_index() <= token_index) && |
| 1570 (token_index < func.end_token_index())) { | 1630 (token_index < func.end_token_index())) { |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3487 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, f0, f1, f2) + 1; | 3547 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, f0, f1, f2) + 1; |
| 3488 char* chars = reinterpret_cast<char*>( | 3548 char* chars = reinterpret_cast<char*>( |
| 3489 Isolate::Current()->current_zone()->Allocate(len)); | 3549 Isolate::Current()->current_zone()->Allocate(len)); |
| 3490 OS::SNPrint(chars, len, kFormat, function_name, f0, f1, f2); | 3550 OS::SNPrint(chars, len, kFormat, function_name, f0, f1, f2); |
| 3491 return chars; | 3551 return chars; |
| 3492 } | 3552 } |
| 3493 | 3553 |
| 3494 | 3554 |
| 3495 RawString* Field::GetterName(const String& field_name) { | 3555 RawString* Field::GetterName(const String& field_name) { |
| 3496 String& str = String::Handle(); | 3556 String& str = String::Handle(); |
| 3497 str = String::New("get:"); | 3557 str = String::New(kGetterPrefix); |
| 3498 str = String::Concat(str, field_name); | 3558 str = String::Concat(str, field_name); |
| 3559 return str.raw(); |
| 3560 } |
| 3561 |
| 3562 |
| 3563 RawString* Field::GetterSymbol(const String& field_name) { |
| 3564 String& str = String::Handle(); |
| 3565 str = Field::GetterName(field_name); |
| 3499 return String::NewSymbol(str); | 3566 return String::NewSymbol(str); |
| 3500 } | 3567 } |
| 3501 | 3568 |
| 3502 | 3569 |
| 3503 RawString* Field::SetterName(const String& field_name) { | 3570 RawString* Field::SetterName(const String& field_name) { |
| 3504 String& str = String::Handle(); | 3571 String& str = String::Handle(); |
| 3505 str = String::New("set:"); | 3572 str = String::New(kSetterPrefix); |
| 3506 str = String::Concat(str, field_name); | 3573 str = String::Concat(str, field_name); |
| 3574 return str.raw(); |
| 3575 } |
| 3576 |
| 3577 |
| 3578 RawString* Field::SetterSymbol(const String& field_name) { |
| 3579 String& str = String::Handle(); |
| 3580 str = Field::SetterName(field_name); |
| 3507 return String::NewSymbol(str); | 3581 return String::NewSymbol(str); |
| 3508 } | 3582 } |
| 3509 | 3583 |
| 3510 | 3584 |
| 3511 RawString* Field::NameFromGetter(const String& getter_name) { | 3585 RawString* Field::NameFromGetter(const String& getter_name) { |
| 3512 String& str = String::Handle(); | 3586 String& str = String::Handle(); |
| 3513 str = String::New("get:"); | 3587 str = String::New(kGetterPrefix); |
| 3514 str = String::SubString(getter_name, str.Length()); | 3588 str = String::SubString(getter_name, str.Length()); |
| 3515 return String::NewSymbol(str); | 3589 return str.raw(); |
| 3516 } | 3590 } |
| 3517 | 3591 |
| 3518 | 3592 |
| 3519 RawString* Field::NameFromSetter(const String& setter_name) { | 3593 RawString* Field::NameFromSetter(const String& setter_name) { |
| 3520 String& str = String::Handle(); | 3594 String& str = String::Handle(); |
| 3521 str = String::New("set:"); | 3595 str = String::New(kSetterPrefix); |
| 3522 str = String::SubString(setter_name, str.Length()); | 3596 str = String::SubString(setter_name, str.Length()); |
| 3523 return String::NewSymbol(str); | 3597 return str.raw(); |
| 3524 } | 3598 } |
| 3525 | 3599 |
| 3526 | 3600 |
| 3527 void Field::set_name(const String& value) const { | 3601 void Field::set_name(const String& value) const { |
| 3528 ASSERT(value.IsSymbol()); | 3602 ASSERT(value.IsSymbol()); |
| 3529 StorePointer(&raw_ptr()->name_, value.raw()); | 3603 StorePointer(&raw_ptr()->name_, value.raw()); |
| 3530 } | 3604 } |
| 3531 | 3605 |
| 3532 | 3606 |
| 3533 RawInstance* Field::value() const { | 3607 RawInstance* Field::value() const { |
| (...skipping 3065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6599 | 6673 |
| 6600 | 6674 |
| 6601 template<typename T> | 6675 template<typename T> |
| 6602 RawString* String::NewSymbol(const T* characters, intptr_t len) { | 6676 RawString* String::NewSymbol(const T* characters, intptr_t len) { |
| 6603 Isolate* isolate = Isolate::Current(); | 6677 Isolate* isolate = Isolate::Current(); |
| 6604 | 6678 |
| 6605 // Calculate the String hash for this sequence of characters. | 6679 // Calculate the String hash for this sequence of characters. |
| 6606 intptr_t hash = Hash(characters, len); | 6680 intptr_t hash = Hash(characters, len); |
| 6607 | 6681 |
| 6608 const Array& symbol_table = | 6682 const Array& symbol_table = |
| 6609 Array::Handle(isolate->object_store()->symbol_table()); | 6683 Array::Handle(isolate, isolate->object_store()->symbol_table()); |
| 6610 // Last element of the array is the number of used elements. | 6684 // Last element of the array is the number of used elements. |
| 6611 intptr_t table_size = symbol_table.Length() - 1; | 6685 intptr_t table_size = symbol_table.Length() - 1; |
| 6612 intptr_t index = hash % table_size; | 6686 intptr_t index = hash % table_size; |
| 6613 | 6687 |
| 6614 String& symbol = String::Handle(); | 6688 String& symbol = String::Handle(isolate, String::null()); |
| 6615 symbol ^= symbol_table.At(index); | 6689 symbol ^= symbol_table.At(index); |
| 6616 while (!symbol.IsNull() && !symbol.Equals(characters, len)) { | 6690 while (!symbol.IsNull() && !symbol.Equals(characters, len)) { |
| 6617 index = (index + 1) % table_size; // Move to next element. | 6691 index = (index + 1) % table_size; // Move to next element. |
| 6618 symbol ^= symbol_table.At(index); | 6692 symbol ^= symbol_table.At(index); |
| 6619 } | 6693 } |
| 6620 // Since we leave enough room in the table to guarantee, that we find an | 6694 // Since we leave enough room in the table to guarantee, that we find an |
| 6621 // empty spot, index is the insertion point if symbol is null. | 6695 // empty spot, index is the insertion point if symbol is null. |
| 6622 if (symbol.IsNull()) { | 6696 if (symbol.IsNull()) { |
| 6623 // Allocate new result string. | 6697 // Allocate new result string. |
| 6624 symbol = String::New(characters, len, Heap::kOld); | 6698 symbol = String::New(characters, len, Heap::kOld); |
| (...skipping 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7711 const String& str = String::Handle(pattern()); | 7785 const String& str = String::Handle(pattern()); |
| 7712 const char* format = "JSRegExp: pattern=%s flags=%s"; | 7786 const char* format = "JSRegExp: pattern=%s flags=%s"; |
| 7713 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); | 7787 intptr_t len = OS::SNPrint(NULL, 0, format, str.ToCString(), Flags()); |
| 7714 char* chars = reinterpret_cast<char*>( | 7788 char* chars = reinterpret_cast<char*>( |
| 7715 Isolate::Current()->current_zone()->Allocate(len + 1)); | 7789 Isolate::Current()->current_zone()->Allocate(len + 1)); |
| 7716 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); | 7790 OS::SNPrint(chars, (len + 1), format, str.ToCString(), Flags()); |
| 7717 return chars; | 7791 return chars; |
| 7718 } | 7792 } |
| 7719 | 7793 |
| 7720 } // namespace dart | 7794 } // namespace dart |
| OLD | NEW |