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 "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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 6866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6877 return result.raw(); | 6877 return result.raw(); |
| 6878 } | 6878 } |
| 6879 | 6879 |
| 6880 | 6880 |
| 6881 intptr_t LocalVarDescriptors::Length() const { | 6881 intptr_t LocalVarDescriptors::Length() const { |
| 6882 return raw_ptr()->length_; | 6882 return raw_ptr()->length_; |
| 6883 } | 6883 } |
| 6884 | 6884 |
| 6885 | 6885 |
| 6886 intptr_t ExceptionHandlers::Length() const { | 6886 intptr_t ExceptionHandlers::Length() const { |
| 6887 return Smi::Value(raw_ptr()->length_); | 6887 return raw_ptr()->length_; |
| 6888 } | 6888 } |
| 6889 | 6889 |
| 6890 | 6890 |
| 6891 void ExceptionHandlers::SetLength(intptr_t value) const { | 6891 void ExceptionHandlers::SetHandlerInfo(intptr_t index, |
| 6892 // This is only safe because we create a new Smi, which does not cause | 6892 intptr_t try_index, |
| 6893 // heap allocation. | 6893 intptr_t outer_try_index, |
| 6894 raw_ptr()->length_ = Smi::New(value); | 6894 intptr_t handler_pc) const { |
| 6895 ASSERT(index < Length()); | |
|
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length())
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length())
hausner
2013/01/15 22:44:52
Done.
| |
| 6896 RawExceptionHandlers::HandlerInfo* info = &raw_ptr()->data_[index]; | |
| 6897 info->try_index = try_index; | |
| 6898 info->outer_try_index = outer_try_index; | |
| 6899 info->handler_pc = handler_pc; | |
| 6900 } | |
| 6901 | |
| 6902 void ExceptionHandlers::GetHandlerInfo( | |
| 6903 intptr_t index, | |
| 6904 RawExceptionHandlers::HandlerInfo* info) const { | |
| 6905 ASSERT(index < Length()); | |
|
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length())
hausner
2013/01/15 22:44:52
Done.
| |
| 6906 RawExceptionHandlers::HandlerInfo* data = &raw_ptr()->data_[index]; | |
|
siva
2013/01/15 22:04:12
ASSERT(info != NULL);
hausner
2013/01/15 22:44:52
Done.
| |
| 6907 info->try_index = data->try_index; | |
| 6908 info->outer_try_index = data->outer_try_index; | |
| 6909 info->handler_pc = data->handler_pc; | |
| 6895 } | 6910 } |
| 6896 | 6911 |
| 6897 | 6912 |
| 6898 intptr_t ExceptionHandlers::TryIndex(intptr_t index) const { | 6913 intptr_t ExceptionHandlers::TryIndex(intptr_t index) const { |
| 6899 return *(EntryAddr(index, kTryIndexEntry)); | 6914 ASSERT(index < Length()); |
|
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length())
hausner
2013/01/15 22:44:52
Done.
| |
| 6900 } | 6915 return raw_ptr()->data_[index].try_index; |
| 6901 | |
| 6902 | |
| 6903 void ExceptionHandlers::SetTryIndex(intptr_t index, intptr_t value) const { | |
| 6904 *(EntryAddr(index, kTryIndexEntry)) = value; | |
| 6905 } | 6916 } |
| 6906 | 6917 |
| 6907 | 6918 |
| 6908 intptr_t ExceptionHandlers::HandlerPC(intptr_t index) const { | 6919 intptr_t ExceptionHandlers::HandlerPC(intptr_t index) const { |
| 6909 return *(EntryAddr(index, kHandlerPcEntry)); | 6920 ASSERT(index < Length()); |
|
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length());
hausner
2013/01/15 22:44:52
Done.
| |
| 6921 return raw_ptr()->data_[index].handler_pc; | |
| 6910 } | 6922 } |
| 6911 | 6923 |
| 6912 | 6924 |
| 6913 void ExceptionHandlers::SetHandlerPC(intptr_t index, | 6925 void ExceptionHandlers::SetHandledTypes(intptr_t index, |
| 6914 intptr_t value) const { | 6926 const Array& handled_types) const { |
|
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length());
hausner
2013/01/15 22:44:52
Done.
| |
| 6915 *(EntryAddr(index, kHandlerPcEntry)) = value; | 6927 const Array& handled_types_data = |
| 6928 Array::Handle(raw_ptr()->handled_types_data_); | |
| 6929 handled_types_data.SetAt(index, handled_types); | |
| 6930 } | |
| 6931 | |
| 6932 | |
| 6933 RawArray* ExceptionHandlers::GetHandledTypes(intptr_t index) const { | |
|
siva
2013/01/15 22:04:12
ASSERT(index >= 0 && index < Length());
hausner
2013/01/15 22:44:52
Done.
| |
| 6934 Array& array = Array::Handle(raw_ptr()->handled_types_data_); | |
| 6935 array ^= array.At(index); | |
| 6936 return array.raw(); | |
| 6937 } | |
| 6938 | |
| 6939 | |
| 6940 void ExceptionHandlers::set_handled_types_data(const Array& value) const { | |
| 6941 StorePointer(&raw_ptr()->handled_types_data_, value.raw()); | |
| 6916 } | 6942 } |
| 6917 | 6943 |
| 6918 | 6944 |
| 6919 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { | 6945 RawExceptionHandlers* ExceptionHandlers::New(intptr_t num_handlers) { |
| 6920 ASSERT(Object::exception_handlers_class() != Class::null()); | 6946 ASSERT(Object::exception_handlers_class() != Class::null()); |
|
siva
2013/01/15 22:04:12
You should probably still retain the check as an A
hausner
2013/01/15 22:44:52
Done, but to be an effective security check it has
| |
| 6921 if (num_handlers < 0 || num_handlers > kMaxElements) { | 6947 const Array& handled_types_data = Array::Handle(Array::New(num_handlers)); |
| 6922 // This should be caught before we reach here. | |
| 6923 FATAL1("Fatal error in ExceptionHandlers::New: " | |
| 6924 "invalid num_handlers %"Pd"\n", | |
| 6925 num_handlers); | |
| 6926 } | |
| 6927 ExceptionHandlers& result = ExceptionHandlers::Handle(); | 6948 ExceptionHandlers& result = ExceptionHandlers::Handle(); |
| 6928 { | 6949 { |
| 6929 uword size = ExceptionHandlers::InstanceSize(num_handlers); | 6950 uword size = ExceptionHandlers::InstanceSize(num_handlers); |
| 6930 RawObject* raw = Object::Allocate(ExceptionHandlers::kClassId, | 6951 RawObject* raw = Object::Allocate(ExceptionHandlers::kClassId, |
| 6931 size, | 6952 size, |
| 6932 Heap::kOld); | 6953 Heap::kOld); |
| 6933 NoGCScope no_gc; | 6954 NoGCScope no_gc; |
| 6934 result ^= raw; | 6955 result ^= raw; |
| 6935 result.SetLength(num_handlers); | 6956 result.raw_ptr()->length_ = num_handlers; |
| 6957 result.set_handled_types_data(handled_types_data); | |
|
siva
2013/01/15 22:04:12
Pull the result.set_handled_types_data code outsid
hausner
2013/01/15 22:44:52
Done.
| |
| 6936 } | 6958 } |
| 6937 return result.raw(); | 6959 return result.raw(); |
| 6938 } | 6960 } |
| 6939 | 6961 |
| 6940 | 6962 |
| 6941 const char* ExceptionHandlers::ToCString() const { | 6963 const char* ExceptionHandlers::ToCString() const { |
| 6942 if (Length() == 0) { | 6964 if (Length() == 0) { |
| 6943 return "No exception handlers\n"; | 6965 return "No exception handlers\n"; |
| 6944 } | 6966 } |
| 6967 Array& handled_types = Array::Handle(); | |
| 6968 Type& type = Type::Handle(); | |
| 6969 RawExceptionHandlers::HandlerInfo info; | |
| 6945 // First compute the buffer size required. | 6970 // First compute the buffer size required. |
| 6946 const char* kFormat = "%"Pd" => %#"Px"\n"; | 6971 const char* kFormat = "%"Pd" => %#"Px" (%"Pd" types) (outer %"Pd")\n"; |
| 6972 const char* kFormat2 = " %d. %s\n"; | |
| 6947 intptr_t len = 1; // Trailing '\0'. | 6973 intptr_t len = 1; // Trailing '\0'. |
| 6948 for (intptr_t i = 0; i < Length(); i++) { | 6974 for (intptr_t i = 0; i < Length(); i++) { |
| 6949 len += OS::SNPrint(NULL, 0, kFormat, TryIndex(i), HandlerPC(i)); | 6975 GetHandlerInfo(i, &info); |
| 6976 handled_types = GetHandledTypes(i); | |
| 6977 ASSERT(!handled_types.IsNull()); | |
| 6978 intptr_t num_types = handled_types.Length(); | |
| 6979 len += OS::SNPrint(NULL, 0, kFormat, | |
| 6980 info.try_index, | |
| 6981 info.handler_pc, | |
| 6982 num_types, | |
| 6983 info.outer_try_index); | |
| 6984 for (int k = 0; k < num_types; k++) { | |
| 6985 type ^= handled_types.At(k); | |
| 6986 ASSERT(!type.IsNull()); | |
| 6987 len += OS::SNPrint(NULL, 0, kFormat2, k, type.ToCString()); | |
| 6988 } | |
| 6950 } | 6989 } |
| 6951 // Allocate the buffer. | 6990 // Allocate the buffer. |
| 6952 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); | 6991 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 6953 // Layout the fields in the buffer. | 6992 // Layout the fields in the buffer. |
| 6954 intptr_t index = 0; | 6993 intptr_t num_chars = 0; |
| 6955 for (intptr_t i = 0; i < Length(); i++) { | 6994 for (intptr_t i = 0; i < Length(); i++) { |
| 6956 index += OS::SNPrint((buffer + index), | 6995 GetHandlerInfo(i, &info); |
| 6957 (len - index), | 6996 handled_types = GetHandledTypes(i); |
| 6958 kFormat, | 6997 intptr_t num_types = handled_types.Length(); |
| 6959 TryIndex(i), | 6998 num_chars += OS::SNPrint((buffer + num_chars), |
| 6960 HandlerPC(i)); | 6999 (len - num_chars), |
| 7000 kFormat, | |
| 7001 info.try_index, | |
| 7002 info.handler_pc, | |
| 7003 num_types, | |
| 7004 info.outer_try_index); | |
| 7005 for (int k = 0; k < num_types; k++) { | |
| 7006 type ^= handled_types.At(k); | |
| 7007 num_chars += OS::SNPrint((buffer + num_chars), | |
| 7008 (len - num_chars), | |
| 7009 kFormat2, k, type.ToCString()); | |
| 7010 } | |
| 6961 } | 7011 } |
| 6962 return buffer; | 7012 return buffer; |
| 6963 } | 7013 } |
| 6964 | 7014 |
| 6965 | 7015 |
| 6966 intptr_t DeoptInfo::Length() const { | 7016 intptr_t DeoptInfo::Length() const { |
| 6967 return Smi::Value(raw_ptr()->length_); | 7017 return Smi::Value(raw_ptr()->length_); |
| 6968 } | 7018 } |
| 6969 | 7019 |
| 6970 | 7020 |
| (...skipping 5525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12496 } | 12546 } |
| 12497 return result.raw(); | 12547 return result.raw(); |
| 12498 } | 12548 } |
| 12499 | 12549 |
| 12500 | 12550 |
| 12501 const char* WeakProperty::ToCString() const { | 12551 const char* WeakProperty::ToCString() const { |
| 12502 return "_WeakProperty"; | 12552 return "_WeakProperty"; |
| 12503 } | 12553 } |
| 12504 | 12554 |
| 12505 } // namespace dart | 12555 } // namespace dart |
| OLD | NEW |