OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/isolate.h" | 5 #include "vm/isolate.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 "platform/json.h" | 9 #include "platform/json.h" |
10 #include "lib/mirrors.h" | 10 #include "lib/mirrors.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 ASSERT(isolate == Isolate::Current()); | 266 ASSERT(isolate == Isolate::Current()); |
267 } | 267 } |
268 #endif | 268 #endif |
269 | 269 |
270 | 270 |
271 void DeferredDouble::Materialize() { | 271 void DeferredDouble::Materialize() { |
272 RawDouble** double_slot = reinterpret_cast<RawDouble**>(slot()); | 272 RawDouble** double_slot = reinterpret_cast<RawDouble**>(slot()); |
273 *double_slot = Double::New(value()); | 273 *double_slot = Double::New(value()); |
274 | 274 |
275 if (FLAG_trace_deoptimization_verbose) { | 275 if (FLAG_trace_deoptimization_verbose) { |
276 OS::PrintErr("materializing double at %"Px": %g\n", | 276 OS::PrintErr("materializing double at %" Px ": %g\n", |
277 reinterpret_cast<uword>(slot()), value()); | 277 reinterpret_cast<uword>(slot()), value()); |
278 } | 278 } |
279 } | 279 } |
280 | 280 |
281 | 281 |
282 void DeferredMint::Materialize() { | 282 void DeferredMint::Materialize() { |
283 RawMint** mint_slot = reinterpret_cast<RawMint**>(slot()); | 283 RawMint** mint_slot = reinterpret_cast<RawMint**>(slot()); |
284 ASSERT(!Smi::IsValid64(value())); | 284 ASSERT(!Smi::IsValid64(value())); |
285 Mint& mint = Mint::Handle(); | 285 Mint& mint = Mint::Handle(); |
286 mint ^= Integer::New(value()); | 286 mint ^= Integer::New(value()); |
287 *mint_slot = mint.raw(); | 287 *mint_slot = mint.raw(); |
288 | 288 |
289 if (FLAG_trace_deoptimization_verbose) { | 289 if (FLAG_trace_deoptimization_verbose) { |
290 OS::PrintErr("materializing mint at %"Px": %"Pd64"\n", | 290 OS::PrintErr("materializing mint at %" Px ": %" Pd64 "\n", |
291 reinterpret_cast<uword>(slot()), value()); | 291 reinterpret_cast<uword>(slot()), value()); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 | 295 |
296 void DeferredFloat32x4::Materialize() { | 296 void DeferredFloat32x4::Materialize() { |
297 RawFloat32x4** float32x4_slot = reinterpret_cast<RawFloat32x4**>(slot()); | 297 RawFloat32x4** float32x4_slot = reinterpret_cast<RawFloat32x4**>(slot()); |
298 RawFloat32x4* raw_float32x4 = Float32x4::New(value()); | 298 RawFloat32x4* raw_float32x4 = Float32x4::New(value()); |
299 *float32x4_slot = raw_float32x4; | 299 *float32x4_slot = raw_float32x4; |
300 | 300 |
301 if (FLAG_trace_deoptimization_verbose) { | 301 if (FLAG_trace_deoptimization_verbose) { |
302 float x = raw_float32x4->x(); | 302 float x = raw_float32x4->x(); |
303 float y = raw_float32x4->y(); | 303 float y = raw_float32x4->y(); |
304 float z = raw_float32x4->z(); | 304 float z = raw_float32x4->z(); |
305 float w = raw_float32x4->w(); | 305 float w = raw_float32x4->w(); |
306 OS::PrintErr("materializing Float32x4 at %"Px": %g,%g,%g,%g\n", | 306 OS::PrintErr("materializing Float32x4 at %" Px ": %g,%g,%g,%g\n", |
307 reinterpret_cast<uword>(slot()), x, y, z, w); | 307 reinterpret_cast<uword>(slot()), x, y, z, w); |
308 } | 308 } |
309 } | 309 } |
310 | 310 |
311 | 311 |
312 void DeferredUint32x4::Materialize() { | 312 void DeferredUint32x4::Materialize() { |
313 RawUint32x4** uint32x4_slot = reinterpret_cast<RawUint32x4**>(slot()); | 313 RawUint32x4** uint32x4_slot = reinterpret_cast<RawUint32x4**>(slot()); |
314 RawUint32x4* raw_uint32x4 = Uint32x4::New(value()); | 314 RawUint32x4* raw_uint32x4 = Uint32x4::New(value()); |
315 *uint32x4_slot = raw_uint32x4; | 315 *uint32x4_slot = raw_uint32x4; |
316 | 316 |
317 if (FLAG_trace_deoptimization_verbose) { | 317 if (FLAG_trace_deoptimization_verbose) { |
318 uint32_t x = raw_uint32x4->x(); | 318 uint32_t x = raw_uint32x4->x(); |
319 uint32_t y = raw_uint32x4->y(); | 319 uint32_t y = raw_uint32x4->y(); |
320 uint32_t z = raw_uint32x4->z(); | 320 uint32_t z = raw_uint32x4->z(); |
321 uint32_t w = raw_uint32x4->w(); | 321 uint32_t w = raw_uint32x4->w(); |
322 OS::PrintErr("materializing Uint32x4 at %"Px": %x,%x,%x,%x\n", | 322 OS::PrintErr("materializing Uint32x4 at %" Px ": %x,%x,%x,%x\n", |
323 reinterpret_cast<uword>(slot()), x, y, z, w); | 323 reinterpret_cast<uword>(slot()), x, y, z, w); |
324 } | 324 } |
325 } | 325 } |
326 | 326 |
327 | 327 |
328 void DeferredObjectRef::Materialize() { | 328 void DeferredObjectRef::Materialize() { |
329 DeferredObject* obj = Isolate::Current()->GetDeferredObject(index()); | 329 DeferredObject* obj = Isolate::Current()->GetDeferredObject(index()); |
330 *slot() = obj->object(); | 330 *slot() = obj->object(); |
331 if (FLAG_trace_deoptimization_verbose) { | 331 if (FLAG_trace_deoptimization_verbose) { |
332 OS::PrintErr("writing instance ref at %"Px": %s\n", | 332 OS::PrintErr("writing instance ref at %" Px ": %s\n", |
333 reinterpret_cast<uword>(slot()), | 333 reinterpret_cast<uword>(slot()), |
334 Instance::Handle(obj->object()).ToCString()); | 334 Instance::Handle(obj->object()).ToCString()); |
335 } | 335 } |
336 } | 336 } |
337 | 337 |
338 | 338 |
339 RawInstance* DeferredObject::object() { | 339 RawInstance* DeferredObject::object() { |
340 if (object_ == NULL) { | 340 if (object_ == NULL) { |
341 Materialize(); | 341 Materialize(); |
342 } | 342 } |
343 return object_->raw(); | 343 return object_->raw(); |
344 } | 344 } |
345 | 345 |
346 | 346 |
347 void DeferredObject::Materialize() { | 347 void DeferredObject::Materialize() { |
348 Class& cls = Class::Handle(); | 348 Class& cls = Class::Handle(); |
349 cls ^= GetClass(); | 349 cls ^= GetClass(); |
350 | 350 |
351 if (FLAG_trace_deoptimization_verbose) { | 351 if (FLAG_trace_deoptimization_verbose) { |
352 OS::PrintErr("materializing instance of %s (%"Px", %"Pd" fields)\n", | 352 OS::PrintErr("materializing instance of %s (%" Px ", %" Pd " fields)\n", |
353 cls.ToCString(), | 353 cls.ToCString(), |
354 reinterpret_cast<uword>(args_), | 354 reinterpret_cast<uword>(args_), |
355 field_count_); | 355 field_count_); |
356 } | 356 } |
357 | 357 |
358 const Instance& obj = Instance::ZoneHandle(Instance::New(cls)); | 358 const Instance& obj = Instance::ZoneHandle(Instance::New(cls)); |
359 | 359 |
360 Field& field = Field::Handle(); | 360 Field& field = Field::Handle(); |
361 Object& value = Object::Handle(); | 361 Object& value = Object::Handle(); |
362 for (intptr_t i = 0; i < field_count_; i++) { | 362 for (intptr_t i = 0; i < field_count_; i++) { |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 Class& cls = Class::Handle(); | 723 Class& cls = Class::Handle(); |
724 ClassDictionaryIterator iter(library, | 724 ClassDictionaryIterator iter(library, |
725 ClassDictionaryIterator::kIteratePrivate); | 725 ClassDictionaryIterator::kIteratePrivate); |
726 while (iter.HasNext()) { | 726 while (iter.HasNext()) { |
727 cls = iter.GetNextClass(); | 727 cls = iter.GetNextClass(); |
728 AddFunctionsFromClass(cls, &invoked_functions); | 728 AddFunctionsFromClass(cls, &invoked_functions); |
729 } | 729 } |
730 } | 730 } |
731 invoked_functions.Sort(MostUsedFunctionFirst); | 731 invoked_functions.Sort(MostUsedFunctionFirst); |
732 for (int i = 0; i < invoked_functions.length(); i++) { | 732 for (int i = 0; i < invoked_functions.length(); i++) { |
733 OS::Print("%10"Pd" x %s\n", | 733 OS::Print("%10" Pd " x %s\n", |
734 invoked_functions[i]->usage_counter(), | 734 invoked_functions[i]->usage_counter(), |
735 invoked_functions[i]->ToFullyQualifiedCString()); | 735 invoked_functions[i]->ToFullyQualifiedCString()); |
736 } | 736 } |
737 } | 737 } |
738 | 738 |
739 | 739 |
740 class FinalizeWeakPersistentHandlesVisitor : public HandleVisitor { | 740 class FinalizeWeakPersistentHandlesVisitor : public HandleVisitor { |
741 public: | 741 public: |
742 FinalizeWeakPersistentHandlesVisitor() { | 742 FinalizeWeakPersistentHandlesVisitor() { |
743 } | 743 } |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 | 874 |
875 | 875 |
876 static Monitor* status_sync = NULL; | 876 static Monitor* status_sync = NULL; |
877 | 877 |
878 | 878 |
879 bool Isolate::FetchStacktrace() { | 879 bool Isolate::FetchStacktrace() { |
880 Isolate* isolate = Isolate::Current(); | 880 Isolate* isolate = Isolate::Current(); |
881 MonitorLocker ml(status_sync); | 881 MonitorLocker ml(status_sync); |
882 DebuggerStackTrace* stack = Debugger::CollectStackTrace(); | 882 DebuggerStackTrace* stack = Debugger::CollectStackTrace(); |
883 TextBuffer buffer(256); | 883 TextBuffer buffer(256); |
884 buffer.Printf("{ \"handle\": \"0x%"Px64"\", \"stacktrace\": [ ", | 884 buffer.Printf("{ \"handle\": \"0x%" Px64 "\", \"stacktrace\": [ ", |
885 reinterpret_cast<int64_t>(isolate)); | 885 reinterpret_cast<int64_t>(isolate)); |
886 intptr_t n_frames = stack->Length(); | 886 intptr_t n_frames = stack->Length(); |
887 String& url = String::Handle(); | 887 String& url = String::Handle(); |
888 String& function = String::Handle(); | 888 String& function = String::Handle(); |
889 for (int i = 0; i < n_frames; i++) { | 889 for (int i = 0; i < n_frames; i++) { |
890 if (i > 0) { | 890 if (i > 0) { |
891 buffer.Printf(", "); | 891 buffer.Printf(", "); |
892 } | 892 } |
893 ActivationFrame* frame = stack->ActivationFrameAt(i); | 893 ActivationFrame* frame = stack->ActivationFrameAt(i); |
894 url ^= frame->SourceUrl(); | 894 url ^= frame->SourceUrl(); |
895 function ^= frame->function().UserVisibleName(); | 895 function ^= frame->function().UserVisibleName(); |
896 buffer.Printf("{ \"url\": \"%s\", ", url.ToCString()); | 896 buffer.Printf("{ \"url\": \"%s\", ", url.ToCString()); |
897 buffer.Printf("\"line\": %"Pd", ", frame->LineNumber()); | 897 buffer.Printf("\"line\": %" Pd ", ", frame->LineNumber()); |
898 buffer.Printf("\"function\": \"%s\", ", function.ToCString()); | 898 buffer.Printf("\"function\": \"%s\", ", function.ToCString()); |
899 | 899 |
900 const Code& code = frame->code(); | 900 const Code& code = frame->code(); |
901 buffer.Printf("\"code\": { "); | 901 buffer.Printf("\"code\": { "); |
902 buffer.Printf("\"alive\": %s, ", code.is_alive() ? "false" : "true"); | 902 buffer.Printf("\"alive\": %s, ", code.is_alive() ? "false" : "true"); |
903 buffer.Printf("\"optimized\": %s }}", | 903 buffer.Printf("\"optimized\": %s }}", |
904 code.is_optimized() ? "false" : "true"); | 904 code.is_optimized() ? "false" : "true"); |
905 } | 905 } |
906 buffer.Printf("]}"); | 906 buffer.Printf("]}"); |
907 isolate->stacktrace_ = OS::StrNDup(buffer.buf(), buffer.length()); | 907 isolate->stacktrace_ = OS::StrNDup(buffer.buf(), buffer.length()); |
908 ml.Notify(); | 908 ml.Notify(); |
909 return true; | 909 return true; |
910 } | 910 } |
911 | 911 |
912 | 912 |
913 bool Isolate::FetchStackFrameDetails() { | 913 bool Isolate::FetchStackFrameDetails() { |
914 Isolate* isolate = Isolate::Current(); | 914 Isolate* isolate = Isolate::Current(); |
915 ASSERT(isolate->stack_frame_index_ >= 0); | 915 ASSERT(isolate->stack_frame_index_ >= 0); |
916 MonitorLocker ml(status_sync); | 916 MonitorLocker ml(status_sync); |
917 DebuggerStackTrace* stack = Debugger::CollectStackTrace(); | 917 DebuggerStackTrace* stack = Debugger::CollectStackTrace(); |
918 intptr_t frame_index = isolate->stack_frame_index_; | 918 intptr_t frame_index = isolate->stack_frame_index_; |
919 if (frame_index >= stack->Length()) { | 919 if (frame_index >= stack->Length()) { |
920 // Frame no longer available. | 920 // Frame no longer available. |
921 return NULL; | 921 return NULL; |
922 } | 922 } |
923 ActivationFrame* frame = stack->ActivationFrameAt(frame_index); | 923 ActivationFrame* frame = stack->ActivationFrameAt(frame_index); |
924 TextBuffer buffer(256); | 924 TextBuffer buffer(256); |
925 buffer.Printf("{ \"handle\": \"0x%"Px64"\", \"frame_index\": %"Pd", ", | 925 buffer.Printf("{ \"handle\": \"0x%" Px64 "\", \"frame_index\": %" Pd ", ", |
926 reinterpret_cast<int64_t>(isolate), frame_index); | 926 reinterpret_cast<int64_t>(isolate), frame_index); |
927 | 927 |
928 const Code& code = frame->code(); | 928 const Code& code = frame->code(); |
929 buffer.Printf("\"code\": { \"size\": %"Pd", ", code.Size()); | 929 buffer.Printf("\"code\": { \"size\": %" Pd ", ", code.Size()); |
930 buffer.Printf("\"alive\": %s, ", code.is_alive() ? "false" : "true"); | 930 buffer.Printf("\"alive\": %s, ", code.is_alive() ? "false" : "true"); |
931 buffer.Printf("\"optimized\": %s }, ", | 931 buffer.Printf("\"optimized\": %s }, ", |
932 code.is_optimized() ? "false" : "true"); | 932 code.is_optimized() ? "false" : "true"); |
933 // TODO(tball): add compilation stats (time, etc.), when available. | 933 // TODO(tball): add compilation stats (time, etc.), when available. |
934 | 934 |
935 buffer.Printf("\"local_vars\": [ "); | 935 buffer.Printf("\"local_vars\": [ "); |
936 intptr_t n_local_vars = frame->NumLocalVariables(); | 936 intptr_t n_local_vars = frame->NumLocalVariables(); |
937 String& var_name = String::Handle(); | 937 String& var_name = String::Handle(); |
938 Instance& value = Instance::Handle(); | 938 Instance& value = Instance::Handle(); |
939 for (int i = 0; i < n_local_vars; i++) { | 939 for (int i = 0; i < n_local_vars; i++) { |
940 if (i > 0) { | 940 if (i > 0) { |
941 buffer.Printf(", "); | 941 buffer.Printf(", "); |
942 } | 942 } |
943 intptr_t token_pos, end_pos; | 943 intptr_t token_pos, end_pos; |
944 frame->VariableAt(i, &var_name, &token_pos, &end_pos, &value); | 944 frame->VariableAt(i, &var_name, &token_pos, &end_pos, &value); |
945 buffer.Printf( | 945 buffer.Printf( |
946 "{ \"name\": \"%s\", \"pos\": %"Pd", \"end_pos\": %"Pd", " | 946 "{ \"name\": \"%s\", \"pos\": %" Pd ", \"end_pos\": %" Pd ", " |
947 "\"value\": \"%s\" }", | 947 "\"value\": \"%s\" }", |
948 var_name.ToCString(), token_pos, end_pos, value.ToCString()); | 948 var_name.ToCString(), token_pos, end_pos, value.ToCString()); |
949 } | 949 } |
950 buffer.Printf("]}"); | 950 buffer.Printf("]}"); |
951 isolate->stacktrace_ = OS::StrNDup(buffer.buf(), buffer.length()); | 951 isolate->stacktrace_ = OS::StrNDup(buffer.buf(), buffer.length()); |
952 ml.Notify(); | 952 ml.Notify(); |
953 return true; | 953 return true; |
954 } | 954 } |
955 | 955 |
956 | 956 |
(...skipping 11 matching lines...) Expand all Loading... |
968 ml.Wait(1000); | 968 ml.Wait(1000); |
969 } | 969 } |
970 } | 970 } |
971 SetVmStatsCallback(NULL); | 971 SetVmStatsCallback(NULL); |
972 } | 972 } |
973 char* result = stacktrace_; | 973 char* result = stacktrace_; |
974 stacktrace_ = NULL; | 974 stacktrace_ = NULL; |
975 if (result == NULL) { | 975 if (result == NULL) { |
976 // Return empty stack. | 976 // Return empty stack. |
977 TextBuffer buffer(256); | 977 TextBuffer buffer(256); |
978 buffer.Printf("{ \"handle\": \"0x%"Px64"\", \"stacktrace\": []}", | 978 buffer.Printf("{ \"handle\": \"0x%" Px64 "\", \"stacktrace\": []}", |
979 reinterpret_cast<int64_t>(this)); | 979 reinterpret_cast<int64_t>(this)); |
980 | 980 |
981 result = OS::StrNDup(buffer.buf(), buffer.length()); | 981 result = OS::StrNDup(buffer.buf(), buffer.length()); |
982 } | 982 } |
983 ASSERT(result != NULL); | 983 ASSERT(result != NULL); |
984 // result is freed by VmStats::WebServer(). | 984 // result is freed by VmStats::WebServer(). |
985 return result; | 985 return result; |
986 } | 986 } |
987 | 987 |
988 | 988 |
989 char* Isolate::GetStatusStacktrace() { | 989 char* Isolate::GetStatusStacktrace() { |
990 return DoStacktraceInterrupt(&FetchStacktrace); | 990 return DoStacktraceInterrupt(&FetchStacktrace); |
991 } | 991 } |
992 | 992 |
993 char* Isolate::GetStatusStackFrame(intptr_t index) { | 993 char* Isolate::GetStatusStackFrame(intptr_t index) { |
994 ASSERT(index >= 0); | 994 ASSERT(index >= 0); |
995 stack_frame_index_ = index; | 995 stack_frame_index_ = index; |
996 char* result = DoStacktraceInterrupt(&FetchStackFrameDetails); | 996 char* result = DoStacktraceInterrupt(&FetchStackFrameDetails); |
997 stack_frame_index_ = -1; | 997 stack_frame_index_ = -1; |
998 return result; | 998 return result; |
999 } | 999 } |
1000 | 1000 |
1001 | 1001 |
1002 // Returns the isolate's general detail information. | 1002 // Returns the isolate's general detail information. |
1003 char* Isolate::GetStatusDetails() { | 1003 char* Isolate::GetStatusDetails() { |
1004 const char* format = "{\n" | 1004 const char* format = "{\n" |
1005 " \"handle\": \"0x%"Px64"\",\n" | 1005 " \"handle\": \"0x%" Px64 "\",\n" |
1006 " \"name\": \"%s\",\n" | 1006 " \"name\": \"%s\",\n" |
1007 " \"port\": %"Pd",\n" | 1007 " \"port\": %" Pd ",\n" |
1008 " \"starttime\": %"Pd",\n" | 1008 " \"starttime\": %" Pd ",\n" |
1009 " \"stacklimit\": %"Pd",\n" | 1009 " \"stacklimit\": %" Pd ",\n" |
1010 " \"newspace\": {\n" | 1010 " \"newspace\": {\n" |
1011 " \"used\": %"Pd",\n" | 1011 " \"used\": %" Pd ",\n" |
1012 " \"capacity\": %"Pd"\n" | 1012 " \"capacity\": %" Pd "\n" |
1013 " },\n" | 1013 " },\n" |
1014 " \"oldspace\": {\n" | 1014 " \"oldspace\": {\n" |
1015 " \"used\": %"Pd",\n" | 1015 " \"used\": %" Pd ",\n" |
1016 " \"capacity\": %"Pd"\n" | 1016 " \"capacity\": %" Pd "\n" |
1017 " }\n" | 1017 " }\n" |
1018 "}"; | 1018 "}"; |
1019 char buffer[300]; | 1019 char buffer[300]; |
1020 int64_t address = reinterpret_cast<int64_t>(this); | 1020 int64_t address = reinterpret_cast<int64_t>(this); |
1021 int n = OS::SNPrint(buffer, 300, format, address, name(), main_port(), | 1021 int n = OS::SNPrint(buffer, 300, format, address, name(), main_port(), |
1022 (start_time() / 1000L), saved_stack_limit(), | 1022 (start_time() / 1000L), saved_stack_limit(), |
1023 heap()->Used(Heap::kNew) / KB, | 1023 heap()->Used(Heap::kNew) / KB, |
1024 heap()->Capacity(Heap::kNew) / KB, | 1024 heap()->Capacity(Heap::kNew) / KB, |
1025 heap()->Used(Heap::kOld) / KB, | 1025 heap()->Used(Heap::kOld) / KB, |
1026 heap()->Capacity(Heap::kOld) / KB); | 1026 heap()->Capacity(Heap::kOld) / KB); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 return func.raw(); | 1185 return func.raw(); |
1186 } | 1186 } |
1187 | 1187 |
1188 | 1188 |
1189 void IsolateSpawnState::Cleanup() { | 1189 void IsolateSpawnState::Cleanup() { |
1190 SwitchIsolateScope switch_scope(isolate()); | 1190 SwitchIsolateScope switch_scope(isolate()); |
1191 Dart::ShutdownIsolate(); | 1191 Dart::ShutdownIsolate(); |
1192 } | 1192 } |
1193 | 1193 |
1194 } // namespace dart | 1194 } // namespace dart |
OLD | NEW |