Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: runtime/vm/object.cc

Issue 12335111: Resubmit change 19074. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 12805 matching lines...) Expand 10 before | Expand all | Expand 10 after
12816 return code_array.Length(); 12816 return code_array.Length();
12817 } 12817 }
12818 12818
12819 12819
12820 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const { 12820 RawFunction* Stacktrace::FunctionAtFrame(intptr_t frame_index) const {
12821 const Array& function_array = Array::Handle(raw_ptr()->function_array_); 12821 const Array& function_array = Array::Handle(raw_ptr()->function_array_);
12822 return reinterpret_cast<RawFunction*>(function_array.At(frame_index)); 12822 return reinterpret_cast<RawFunction*>(function_array.At(frame_index));
12823 } 12823 }
12824 12824
12825 12825
12826 void Stacktrace::SetFunctionAtFrame(intptr_t frame_index,
12827 const Function& func) const {
12828 const Array& function_array = Array::Handle(raw_ptr()->function_array_);
12829 function_array.SetAt(frame_index, func);
12830 }
12831
12832
12826 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const { 12833 RawCode* Stacktrace::CodeAtFrame(intptr_t frame_index) const {
12827 const Array& code_array = Array::Handle(raw_ptr()->code_array_); 12834 const Array& code_array = Array::Handle(raw_ptr()->code_array_);
12828 return reinterpret_cast<RawCode*>(code_array.At(frame_index)); 12835 return reinterpret_cast<RawCode*>(code_array.At(frame_index));
12829 } 12836 }
12830 12837
12831 12838
12839 void Stacktrace::SetCodeAtFrame(intptr_t frame_index,
12840 const Code& code) const {
12841 const Array& code_array = Array::Handle(raw_ptr()->code_array_);
12842 code_array.SetAt(frame_index, code);
12843 }
12844
12845
12832 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const { 12846 RawSmi* Stacktrace::PcOffsetAtFrame(intptr_t frame_index) const {
12833 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); 12847 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_);
12834 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index)); 12848 return reinterpret_cast<RawSmi*>(pc_offset_array.At(frame_index));
12835 } 12849 }
12836 12850
12837 12851
12852 void Stacktrace::SetPcOffsetAtFrame(intptr_t frame_index,
12853 const Smi& pc_offset) const {
12854 const Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_);
12855 pc_offset_array.SetAt(frame_index, pc_offset);
12856 }
12857
12858
12838 void Stacktrace::set_function_array(const Array& function_array) const { 12859 void Stacktrace::set_function_array(const Array& function_array) const {
12839 StorePointer(&raw_ptr()->function_array_, function_array.raw()); 12860 StorePointer(&raw_ptr()->function_array_, function_array.raw());
12840 } 12861 }
12841 12862
12842 12863
12843 void Stacktrace::set_code_array(const Array& code_array) const { 12864 void Stacktrace::set_code_array(const Array& code_array) const {
12844 StorePointer(&raw_ptr()->code_array_, code_array.raw()); 12865 StorePointer(&raw_ptr()->code_array_, code_array.raw());
12845 } 12866 }
12846 12867
12847 12868
12848 void Stacktrace::set_pc_offset_array(const Array& pc_offset_array) const { 12869 void Stacktrace::set_pc_offset_array(const Array& pc_offset_array) const {
12849 StorePointer(&raw_ptr()->pc_offset_array_, pc_offset_array.raw()); 12870 StorePointer(&raw_ptr()->pc_offset_array_, pc_offset_array.raw());
12850 } 12871 }
12851 12872
12852 12873
12853 RawStacktrace* Stacktrace::New(const GrowableObjectArray& func_list, 12874 RawStacktrace* Stacktrace::New(const Array& func_array,
12854 const GrowableObjectArray& code_list, 12875 const Array& code_array,
12855 const GrowableObjectArray& pc_offset_list, 12876 const Array& pc_offset_array,
12856 Heap::Space space) { 12877 Heap::Space space) {
12857 ASSERT(Isolate::Current()->object_store()->stacktrace_class() != 12878 ASSERT(Isolate::Current()->object_store()->stacktrace_class() !=
12858 Class::null()); 12879 Class::null());
12859 Stacktrace& result = Stacktrace::Handle(); 12880 Stacktrace& result = Stacktrace::Handle();
12860 { 12881 {
12861 RawObject* raw = Object::Allocate(Stacktrace::kClassId, 12882 RawObject* raw = Object::Allocate(Stacktrace::kClassId,
12862 Stacktrace::InstanceSize(), 12883 Stacktrace::InstanceSize(),
12863 space); 12884 space);
12864 NoGCScope no_gc; 12885 NoGCScope no_gc;
12865 result ^= raw; 12886 result ^= raw;
12866 } 12887 }
12867 // Create arrays for the function, code and pc_offset triplet for each frame. 12888 result.set_function_array(func_array);
12868 const Array& function_array = Array::Handle(Array::MakeArray(func_list));
12869 const Array& code_array = Array::Handle(Array::MakeArray(code_list));
12870 const Array& pc_offset_array =
12871 Array::Handle(Array::MakeArray(pc_offset_list));
12872 result.set_function_array(function_array);
12873 result.set_code_array(code_array); 12889 result.set_code_array(code_array);
12874 result.set_pc_offset_array(pc_offset_array); 12890 result.set_pc_offset_array(pc_offset_array);
12875 return result.raw(); 12891 return result.raw();
12876 } 12892 }
12877 12893
12878 12894
12879 void Stacktrace::Append(const GrowableObjectArray& func_list, 12895 void Stacktrace::Append(const Array& func_list,
12880 const GrowableObjectArray& code_list, 12896 const Array& code_list,
12881 const GrowableObjectArray& pc_offset_list) const { 12897 const Array& pc_offset_list) const {
12882 intptr_t old_length = Length(); 12898 intptr_t old_length = Length();
12883 intptr_t new_length = old_length + pc_offset_list.Length(); 12899 intptr_t new_length = old_length + pc_offset_list.Length();
12884 ASSERT(pc_offset_list.Length() == func_list.Length()); 12900 ASSERT(pc_offset_list.Length() == func_list.Length());
12885 ASSERT(pc_offset_list.Length() == code_list.Length()); 12901 ASSERT(pc_offset_list.Length() == code_list.Length());
12886 12902
12887 // Grow the arrays for function, code and pc_offset triplet to accommodate 12903 // Grow the arrays for function, code and pc_offset triplet to accommodate
12888 // the new stack frames. 12904 // the new stack frames.
12889 Array& function_array = Array::Handle(raw_ptr()->function_array_); 12905 Array& function_array = Array::Handle(raw_ptr()->function_array_);
12890 Array& code_array = Array::Handle(raw_ptr()->code_array_); 12906 Array& code_array = Array::Handle(raw_ptr()->code_array_);
12891 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_); 12907 Array& pc_offset_array = Array::Handle(raw_ptr()->pc_offset_array_);
(...skipping 11 matching lines...) Expand all
12903 function_array.SetAt(i, obj); 12919 function_array.SetAt(i, obj);
12904 obj = code_list.At(j); 12920 obj = code_list.At(j);
12905 code_array.SetAt(i, obj); 12921 code_array.SetAt(i, obj);
12906 obj = pc_offset_list.At(j); 12922 obj = pc_offset_list.At(j);
12907 pc_offset_array.SetAt(i, obj); 12923 pc_offset_array.SetAt(i, obj);
12908 } 12924 }
12909 } 12925 }
12910 12926
12911 12927
12912 const char* Stacktrace::ToCString() const { 12928 const char* Stacktrace::ToCString() const {
12929 Isolate* isolate = Isolate::Current();
12913 Function& function = Function::Handle(); 12930 Function& function = Function::Handle();
12914 Code& code = Code::Handle(); 12931 Code& code = Code::Handle();
12915 Script& script = Script::Handle(); 12932 Script& script = Script::Handle();
12916 String& function_name = String::Handle(); 12933 String& function_name = String::Handle();
12917 String& url = String::Handle(); 12934 String& url = String::Handle();
12918 12935
12919 // Iterate through the stack frames and create C string description 12936 // Iterate through the stack frames and create C string description
12920 // for each frame. 12937 // for each frame.
12921 intptr_t total_len = 0; 12938 intptr_t total_len = 0;
12922 const char* kFormat = "#%-6d %s (%s:%d:%d)\n"; 12939 const char* kFormat = "#%-6d %s (%s:%d:%d)\n";
12923 GrowableArray<char*> frame_strings; 12940 GrowableArray<char*> frame_strings;
12941 char* chars;
12924 for (intptr_t i = 0; i < Length(); i++) { 12942 for (intptr_t i = 0; i < Length(); i++) {
12925 function = FunctionAtFrame(i); 12943 function = FunctionAtFrame(i);
12944 if (function.IsNull()) {
12945 // Check if null function object indicates a stack trace overflow.
12946 if ((i < (Length() - 1)) &&
12947 (FunctionAtFrame(i + 1) != Function::null())) {
12948 const char* kTruncated = "...\n...\n";
12949 intptr_t truncated_len = strlen(kTruncated) + 1;
12950 chars = isolate->current_zone()->Alloc<char>(truncated_len);
12951 OS::SNPrint(chars, truncated_len, "%s", kTruncated);
12952 frame_strings.Add(chars);
12953 }
12954 continue;
12955 }
12926 code = CodeAtFrame(i); 12956 code = CodeAtFrame(i);
12927 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i)); 12957 uword pc = code.EntryPoint() + Smi::Value(PcOffsetAtFrame(i));
12928 intptr_t token_pos = code.GetTokenIndexOfPC(pc); 12958 intptr_t token_pos = code.GetTokenIndexOfPC(pc);
12929 script = function.script(); 12959 script = function.script();
12930 function_name = function.QualifiedUserVisibleName(); 12960 function_name = function.QualifiedUserVisibleName();
12931 url = script.url(); 12961 url = script.url();
12932 intptr_t line = -1; 12962 intptr_t line = -1;
12933 intptr_t column = -1; 12963 intptr_t column = -1;
12934 if (token_pos >= 0) { 12964 if (token_pos >= 0) {
12935 script.GetTokenLocation(token_pos, &line, &column); 12965 script.GetTokenLocation(token_pos, &line, &column);
12936 } 12966 }
12937 intptr_t len = OS::SNPrint(NULL, 0, kFormat, 12967 intptr_t len = OS::SNPrint(NULL, 0, kFormat,
12938 i, 12968 i,
12939 function_name.ToCString(), 12969 function_name.ToCString(),
12940 url.ToCString(), 12970 url.ToCString(),
12941 line, column); 12971 line, column);
12942 total_len += len; 12972 total_len += len;
12943 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 12973 chars = isolate->current_zone()->Alloc<char>(len + 1);
12944 OS::SNPrint(chars, (len + 1), kFormat, 12974 OS::SNPrint(chars, (len + 1), kFormat,
12945 i, 12975 i,
12946 function_name.ToCString(), 12976 function_name.ToCString(),
12947 url.ToCString(), 12977 url.ToCString(),
12948 line, column); 12978 line, column);
12949 frame_strings.Add(chars); 12979 frame_strings.Add(chars);
12950 } 12980 }
12951 12981
12952 // Now concatentate the frame descriptions into a single C string. 12982 // Now concatentate the frame descriptions into a single C string.
12953 char* chars = Isolate::Current()->current_zone()->Alloc<char>(total_len + 1); 12983 chars = isolate->current_zone()->Alloc<char>(total_len + 1);
12954 intptr_t index = 0; 12984 intptr_t index = 0;
12955 for (intptr_t i = 0; i < frame_strings.length(); i++) { 12985 for (intptr_t i = 0; i < frame_strings.length(); i++) {
12956 index += OS::SNPrint((chars + index), 12986 index += OS::SNPrint((chars + index),
12957 (total_len + 1 - index), 12987 (total_len + 1 - index),
12958 "%s", 12988 "%s",
12959 frame_strings[i]); 12989 frame_strings[i]);
12960 } 12990 }
12961 return chars; 12991 return chars;
12962 } 12992 }
12963 12993
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
13073 } 13103 }
13074 return result.raw(); 13104 return result.raw();
13075 } 13105 }
13076 13106
13077 13107
13078 const char* WeakProperty::ToCString() const { 13108 const char* WeakProperty::ToCString() const {
13079 return "_WeakProperty"; 13109 return "_WeakProperty";
13080 } 13110 }
13081 13111
13082 } // namespace dart 13112 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698